Browse Source

UI: Router tabs component improvements. Remove alarm rules page.

pull/8247/head
Igor Kulikov 4 years ago
parent
commit
926c364575
  1. 20
      ui-ngx/src/app/core/services/menu.service.ts
  2. 8
      ui-ngx/src/app/modules/home/components/route-tabs.component.scss
  3. 7
      ui-ngx/src/app/modules/home/components/router-tabs.component.html
  4. 86
      ui-ngx/src/app/modules/home/pages/alarm/alarm-routing.module.ts
  5. 21
      ui-ngx/src/app/modules/home/pages/alarm/alarm-rule-tabs.component.html
  6. 38
      ui-ngx/src/app/modules/home/pages/alarm/alarm-rule-tabs.component.ts
  7. 47
      ui-ngx/src/app/modules/home/pages/alarm/alarm-rule.component.html
  8. 63
      ui-ngx/src/app/modules/home/pages/alarm/alarm-rule.component.ts
  9. 100
      ui-ngx/src/app/modules/home/pages/alarm/alarm-rules-table-config.resolver.ts
  10. 7
      ui-ngx/src/app/modules/home/pages/alarm/alarm.module.ts
  11. 24
      ui-ngx/src/app/shared/models/alarm-rule.models.ts
  12. 20
      ui-ngx/src/app/shared/models/entity-type.models.ts
  13. 26
      ui-ngx/src/app/shared/models/id/alarm-rule-id.ts
  14. 1
      ui-ngx/src/app/shared/models/id/public-api.ts
  15. 1
      ui-ngx/src/app/shared/models/public-api.ts
  16. 21
      ui-ngx/src/assets/locale/locale.constant-en_US.json

20
ui-ngx/src/app/core/services/menu.service.ts

@ -306,24 +306,8 @@ export class MenuService {
id: guid(),
name: 'alarm.alarms',
type: 'link',
path: '/alarm',
icon: 'notifications',
pages: [
{
id: guid(),
name: 'alarm.all-alarms',
type: 'link',
path: '/alarm/alarms',
icon: 'notifications'
},
{
id: guid(),
name: 'alarm-rule.rules',
type: 'link',
path: '/alarm/rules',
icon: 'edit_notifications'
}
]
path: '/alarms',
icon: 'notifications'
},
{
id: guid(),

8
ui-ngx/src/app/modules/home/components/route-tabs.component.scss

@ -18,15 +18,13 @@
width: 100%;
height: 100%;
.mat-tab-nav-bar.tb-router-tabs {
a.mat-tab-link {
.mat-mdc-tab-nav-bar.tb-router-tabs {
a.mat-mdc-tab-link {
display: inline-flex;
align-items: center;
overflow: hidden;
line-height: 40px;
&.tb-active {
opacity: 1;
}
min-width: 200px;
mat-icon {
margin-right: 8px;
margin-left: 0;

7
ui-ngx/src/app/modules/home/components/router-tabs.component.html

@ -16,20 +16,19 @@
-->
<div fxFlex fxLayout="column" style="width: 100%;">
<nav mat-tab-nav-bar class="tb-router-tabs">
<nav mat-tab-nav-bar mat-stretch-tabs="false" class="tb-router-tabs" [tabPanel]="tabPanel">
<a *ngFor="let tab of tabs$ | async"
routerLink="{{tab.path}}"
routerLinkActive
#rla="routerLinkActive"
mat-tab-link
[ngClass]="{'tb-active': rla.isActive}"
[active]="rla.isActive">
<mat-icon *ngIf="!tab.isMdiIcon && tab.icon !== null" class="tb-mat-18">{{tab.icon}}</mat-icon>
<mat-icon *ngIf="tab.isMdiIcon && tab.icon !== null" [svgIcon]="tab.icon" class="tb-mat-18"></mat-icon>
<span>{{tab.name | translate}}</span>
</a>
</nav>
<div fxFlex fxLayout="column" class="tb-router-tabs-content">
<mat-tab-nav-panel #tabPanel fxFlex fxLayout="column" class="tb-router-tabs-content">
<router-outlet (activate)="activeComponentChanged($event)"></router-outlet>
</div>
</mat-tab-nav-panel>
</div>

86
ui-ngx/src/app/modules/home/pages/alarm/alarm-routing.module.ts

@ -16,17 +16,10 @@
import { Injectable, NgModule } from '@angular/core';
import { Resolve, RouterModule, Routes } from '@angular/router';
import { ConfirmOnExitGuard } from '@core/guards/confirm-on-exit.guard';
import { Authority } from '@shared/models/authority.enum';
import { Observable } from 'rxjs';
import { OAuth2Service } from '@core/http/oauth2.service';
import { EntitiesTableComponent } from '@home/components/entity/entities-table.component';
import { EntityDetailsPageComponent } from '@home/components/entity/entity-details-page.component';
import { entityDetailsPageBreadcrumbLabelFunction } from '@home/pages/home-pages.models';
import { BreadCrumbConfig } from '@shared/components/breadcrumb';
import { RouterTabsComponent } from '@home/components/router-tabs.component';
import { AlarmTableComponent } from '@home/components/alarm/alarm-table.component';
import { AlarmRulesTableConfigResolver } from '@home/pages/alarm/alarm-rules-table-config.resolver';
import { AlarmsMode } from '@shared/models/alarm.models';
@Injectable()
@ -41,84 +34,11 @@ export class OAuth2LoginProcessingUrlResolver implements Resolve<string> {
}
const routes: Routes = [
{
path: 'alarm',
component: RouterTabsComponent,
data: {
auth: [Authority.TENANT_ADMIN],
breadcrumb: {
label: 'alarm.alarms',
icon: 'notifications'
}
},
children: [
{
path: '',
children: [],
data: {
auth: [Authority.TENANT_ADMIN],
redirectTo: '/alarm/alarms'
}
},
{
path: 'alarms',
component: AlarmTableComponent,
data: {
auth: [Authority.TENANT_ADMIN],
title: 'alarm.all-alarms',
breadcrumb: {
label: 'alarm.all-alarms',
icon: 'notifications'
},
isPage: true,
alarmsMode: AlarmsMode.ALL
}
},
{
path: 'rules',
data: {
breadcrumb: {
label: 'alarm-rule.rules',
icon: 'edit_notifications'
}
},
children: [
{
path: '',
component: EntitiesTableComponent,
data: {
auth: [Authority.TENANT_ADMIN],
title: 'alarm-rule.alarm-rules'
},
resolve: {
entitiesTableConfig: AlarmRulesTableConfigResolver
}
},
{
path: ':entityId',
component: EntityDetailsPageComponent,
canDeactivate: [ConfirmOnExitGuard],
data: {
breadcrumb: {
labelFunction: entityDetailsPageBreadcrumbLabelFunction,
icon: 'domain'
} as BreadCrumbConfig<EntityDetailsPageComponent>,
auth: [Authority.TENANT_ADMIN],
title: 'alarm-rule.alarm-rules'
},
resolve: {
entitiesTableConfig: AlarmRulesTableConfigResolver
}
}
]
}
]
},
{
path: 'alarms',
component: AlarmTableComponent,
data: {
auth: [Authority.CUSTOMER_USER],
auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
title: 'alarm.alarms',
breadcrumb: {
label: 'alarm.alarms',
@ -133,8 +53,6 @@ const routes: Routes = [
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
providers: [
AlarmRulesTableConfigResolver
]
providers: []
})
export class AlarmRoutingModule { }

21
ui-ngx/src/app/modules/home/pages/alarm/alarm-rule-tabs.component.html

@ -1,21 +0,0 @@
<!--
Copyright © 2016-2023 The Thingsboard Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<mat-tab *ngIf="entity && !isEdit" #auditLogsTab="matTab"
label="{{ 'audit-log.audit-logs' | translate }}">
<tb-audit-log-table detailsMode="true" [active]="auditLogsTab.isActive" [auditLogMode]="auditLogModes.ENTITY" [entityId]="entity.id"></tb-audit-log-table>
</mat-tab>

38
ui-ngx/src/app/modules/home/pages/alarm/alarm-rule-tabs.component.ts

@ -1,38 +0,0 @@
///
/// Copyright © 2016-2023 The Thingsboard Authors
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
import { Component } from '@angular/core';
import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
import { EntityTabsComponent } from '../../components/entity/entity-tabs.component';
import { AlarmRule } from '@shared/models/alarm-rule.models';
@Component({
selector: 'tb-alarm-rule-tabs',
templateUrl: './alarm-rule-tabs.component.html',
styleUrls: []
})
export class AlarmRuleTabsComponent extends EntityTabsComponent<AlarmRule> {
constructor(protected store: Store<AppState>) {
super(store);
}
ngOnInit() {
super.ngOnInit();
}
}

47
ui-ngx/src/app/modules/home/pages/alarm/alarm-rule.component.html

@ -1,47 +0,0 @@
<!--
Copyright © 2016-2023 The Thingsboard Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<div class="tb-details-buttons" fxLayout.xs="column">
<button mat-raised-button color="primary"
[disabled]="(isLoading$ | async)"
(click)="onEntityAction($event, 'open')"
[fxShow]="!isEdit && !isDetailsPage">
{{'common.open-details-page' | translate }}
</button>
<button mat-raised-button color="primary"
[disabled]="(isLoading$ | async)"
(click)="onEntityAction($event, 'delete')"
[fxShow]="!hideDelete() && !isEdit">
{{'alarm-rule.delete' | translate }}
</button>
</div>
<div class="mat-padding" fxLayout="column">
<form [formGroup]="entityForm">
<fieldset [disabled]="(isLoading$ | async) || !isEdit" style="min-width: 0;">
<mat-form-field class="mat-block">
<mat-label translate>alarm-rule.name</mat-label>
<input matInput formControlName="name" required/>
<mat-error *ngIf="entityForm.get('name').hasError('required')">
{{ 'alarm-rule.name-required' | translate }}
</mat-error>
<mat-error *ngIf="entityForm.get('name').hasError('maxlength')">
{{ 'alarm-rule.name-max-length' | translate }}
</mat-error>
</mat-form-field>
</fieldset>
</form>
</div>

63
ui-ngx/src/app/modules/home/pages/alarm/alarm-rule.component.ts

@ -1,63 +0,0 @@
///
/// Copyright © 2016-2023 The Thingsboard Authors
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
import { ChangeDetectorRef, Component, Inject, Optional } from '@angular/core';
import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
import { TranslateService } from '@ngx-translate/core';
import { EntityTableConfig } from '@home/models/entity/entities-table-config.models';
import { EntityComponent } from '@home/components/entity/entity.component';
import { AlarmRule } from '@shared/models/alarm-rule.models';
@Component({
selector: 'tb-alarm-rule',
templateUrl: './alarm-rule.component.html',
styleUrls: []
})
export class AlarmRuleComponent extends EntityComponent<AlarmRule> {
constructor(protected store: Store<AppState>,
protected translate: TranslateService,
@Optional() @Inject('entity') protected entityValue: AlarmRule,
@Optional() @Inject('entitiesTableConfig') protected entitiesTableConfigValue: EntityTableConfig<AlarmRule>,
protected fb: UntypedFormBuilder,
protected cd: ChangeDetectorRef) {
super(store, fb, entityValue, entitiesTableConfigValue, cd);
}
hideDelete() {
if (this.entitiesTableConfig) {
return !this.entitiesTableConfig.deleteEnabled(this.entity);
} else {
return false;
}
}
buildForm(entity: AlarmRule): UntypedFormGroup {
const form = this.fb.group(
{
name: [entity ? entity.name : '', [Validators.required, Validators.maxLength(255)]]
}
);
return form;
}
updateForm(entity: AlarmRule) {
this.entityForm.patchValue({name: entity.name});
}
}

100
ui-ngx/src/app/modules/home/pages/alarm/alarm-rules-table-config.resolver.ts

@ -1,100 +0,0 @@
///
/// Copyright © 2016-2023 The Thingsboard Authors
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
import { Injectable } from '@angular/core';
import { Resolve, Router } from '@angular/router';
import {
DateEntityTableColumn,
EntityTableColumn,
EntityTableConfig
} from '@home/models/entity/entities-table-config.models';
import { TranslateService } from '@ngx-translate/core';
import { DatePipe } from '@angular/common';
import { EntityType, entityTypeResources, entityTypeTranslations } from '@shared/models/entity-type.models';
import { EntityAction } from '@home/models/entity/entity-component.models';
import { DialogService } from '@core/services/dialog.service';
import { MatDialog } from '@angular/material/dialog';
import { ImportExportService } from '@home/components/import-export/import-export.service';
import { HomeDialogsService } from '@home/dialogs/home-dialogs.service';
import { AlarmRuleComponent } from '@home/pages/alarm/alarm-rule.component';
import { AlarmRuleTabsComponent } from '@home/pages/alarm/alarm-rule-tabs.component';
import { AlarmRule } from '@shared/models/alarm-rule.models';
import { emptyPageData } from '@shared/models/page/page-data';
import { of } from 'rxjs';
@Injectable()
export class AlarmRulesTableConfigResolver implements Resolve<EntityTableConfig<AlarmRule>> {
private readonly config: EntityTableConfig<AlarmRule> = new EntityTableConfig<AlarmRule>();
constructor(private importExport: ImportExportService,
private homeDialogs: HomeDialogsService,
private translate: TranslateService,
private datePipe: DatePipe,
private dialogService: DialogService,
private router: Router,
private dialog: MatDialog) {
this.config.entityType = EntityType.ALARM_RULE;
this.config.entityComponent = AlarmRuleComponent;
this.config.entityTabsComponent = AlarmRuleTabsComponent;
this.config.entityTranslations = entityTypeTranslations.get(EntityType.ALARM_RULE);
this.config.entityResources = entityTypeResources.get(EntityType.ALARM_RULE);
this.config.hideDetailsTabsOnEdit = false;
this.config.columns.push(
new DateEntityTableColumn<AlarmRule>('createdTime', 'common.created-time', this.datePipe, '150px'),
new EntityTableColumn<AlarmRule>('name', 'alarm-rule.name', '50%')
);
this.config.deleteEntityTitle = alarmRule => this.translate.instant('alarm-rule.delete-alarm-rule-title',
{ alarmRuleName: alarmRule.name });
this.config.deleteEntityContent = () => this.translate.instant('alarm-rule.delete-alarm-rule-text');
this.config.deleteEntitiesTitle = count => this.translate.instant('alarm-rule.delete-alarm-rules-title', {count});
this.config.deleteEntitiesContent = () => this.translate.instant('alarm-rule.delete-alarm-rules-text');
this.config.entitiesFetchFunction = pageLink => of(emptyPageData<AlarmRule>()); // TODO
this.config.loadEntity = id => of(null); // TODO
this.config.saveEntity = alarmRule => of(alarmRule); // TODO
this.config.deleteEntity = id => of(null); // TODO
this.config.onEntityAction = action => this.onAlarmRuleAction(action);
}
resolve(): EntityTableConfig<AlarmRule> {
this.config.tableTitle = this.translate.instant('alarm-rule.alarm-rules');
return this.config;
}
private openAlarmRule($event: Event, alarmRule: AlarmRule) {
if ($event) {
$event.stopPropagation();
}
const url = this.router.createUrlTree(['alarm', 'rules', alarmRule.id.id]);
this.router.navigateByUrl(url);
}
onAlarmRuleAction(action: EntityAction<AlarmRule>): boolean {
switch (action.action) {
case 'open':
this.openAlarmRule(action.event, action.entity);
return true;
}
return false;
}
}

7
ui-ngx/src/app/modules/home/pages/alarm/alarm.module.ts

@ -20,14 +20,9 @@ import { SharedModule } from '@shared/shared.module';
import { HomeDialogsModule } from '../../dialogs/home-dialogs.module';
import { HomeComponentsModule } from '@modules/home/components/home-components.module';
import { AlarmRoutingModule } from '@home/pages/alarm/alarm-routing.module';
import { AlarmRuleComponent } from '@home/pages/alarm/alarm-rule.component';
import { AlarmRuleTabsComponent } from '@home/pages/alarm/alarm-rule-tabs.component';
@NgModule({
declarations: [
AlarmRuleComponent,
AlarmRuleTabsComponent
],
declarations: [],
imports: [
CommonModule,
SharedModule,

24
ui-ngx/src/app/shared/models/alarm-rule.models.ts

@ -1,24 +0,0 @@
///
/// Copyright © 2016-2023 The Thingsboard Authors
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
import { BaseData } from '@shared/models/base-data';
import { TenantId } from '@shared/models/id/tenant-id';
import { AlarmRuleId } from '@shared/models/id/alarm-rule-id';
export interface AlarmRule extends BaseData<AlarmRuleId> {
tenantId: TenantId;
name: string;
}

20
ui-ngx/src/app/shared/models/entity-type.models.ts

@ -28,7 +28,6 @@ export enum EntityType {
DEVICE_PROFILE = 'DEVICE_PROFILE',
ASSET_PROFILE = 'ASSET_PROFILE',
ALARM = 'ALARM',
ALARM_RULE = 'ALARM_RULE',
RULE_CHAIN = 'RULE_CHAIN',
RULE_NODE = 'RULE_NODE',
EDGE = 'EDGE',
@ -258,19 +257,6 @@ export const entityTypeTranslations = new Map<EntityType | AliasEntityType, Enti
selectedEntities: 'alarm.selected-alarms'
}
],
[
EntityType.ALARM_RULE,
{
type: 'entity.type-alarm-rule',
typePlural: 'entity.type-alarm-rules',
list: 'entity.list-of-alarm-rules',
nameStartsWith: 'entity.alarm-rule-name-starts-with',
details: 'alarm-rule.alarm-rule-details',
noEntities: 'alarm-rule.no-alarm-rules-prompt',
search: 'alarm-rule.search',
selectedEntities: 'alarm-rule.selected-alarm-rules'
}
],
[
EntityType.API_USAGE_STATE,
{
@ -402,12 +388,6 @@ export const entityTypeResources = new Map<EntityType, EntityTypeResource<BaseDa
helpLinkId: 'assets'
}
],
[
EntityType.ALARM_RULE,
{
helpLinkId: 'alarmRules'
}
],
[
EntityType.EDGE,
{

26
ui-ngx/src/app/shared/models/id/alarm-rule-id.ts

@ -1,26 +0,0 @@
///
/// Copyright © 2016-2023 The Thingsboard Authors
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
import { EntityId } from './entity-id';
import { EntityType } from '@shared/models/entity-type.models';
export class AlarmRuleId implements EntityId {
entityType = EntityType.ALARM_RULE;
id: string;
constructor(id: string) {
this.id = id;
}
}

1
ui-ngx/src/app/shared/models/id/public-api.ts

@ -15,7 +15,6 @@
///
export * from './alarm-id';
export * from './alarm-rule-id';
export * from './asset-id';
export * from './audit-log-id';
export * from './customer-id';

1
ui-ngx/src/app/shared/models/public-api.ts

@ -19,7 +19,6 @@ export * from './page/public-api';
export * from './telemetry/telemetry.models';
export * from './time/time.models';
export * from './alarm.models';
export * from './alarm-rule.models';
export * from './alias.models';
export * from './asset.models';
export * from './audit-log.models';

21
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -504,23 +504,6 @@
"refresh": "Refresh",
"sort-direction": "Sort direction"
},
"alarm-rule": {
"rules": "Rules",
"alarm-rule": "Alarm rule",
"alarm-rules": "Alarm rules",
"name": "Name",
"name-required": "Name is required.",
"name-max-length": "Name should be less than 256",
"delete": "Delete",
"alarm-rule-details": "Alarm rule details",
"no-alarm-rules-prompt": "No alarm rules found",
"search": "Search alarm rules",
"selected-alarm-rules": "{ count, plural, 1 {1 alarm rule} other {# alarm rules} } selected",
"delete-alarm-rule-title": "Are you sure you want to delete the alarm rule '{{alarmRuleName}}'?",
"delete-alarm-rule-text": "Be careful, after the confirmation the alarm rule and all related data will become unrecoverable.",
"delete-alarm-rules-title": "Are you sure you want to delete { count, plural, 1 {1 alarm rule} other {# alarm rules} }?",
"delete-alarm-rules-text": "Be careful, after the confirmation all selected alarm rules will be removed and all related data will become unrecoverable."
},
"alias": {
"add": "Add alias",
"edit": "Edit alias",
@ -1980,10 +1963,6 @@
"type-alarms": "Alarms",
"list-of-alarms": "{ count, plural, =1 {One alarm} other {List of # alarms} }",
"alarm-name-starts-with": "Alarms whose names start with '{{prefix}}'",
"type-alarm-rule": "Alarm rule",
"type-alarm-rules": "Alarm rules",
"list-of-alarm-rules": "{ count, plural, 1 {One alarm rule} other {List of # alarm rules} }",
"alarm-rule-name-starts-with": "Alarm rules whose names start with '{{prefix}}'",
"type-rulechain": "Rule chain",
"type-rulechains": "Rule chains",
"list-of-rulechains": "{ count, plural, =1 {One rule chain} other {List of # rule chains} }",

Loading…
Cancel
Save