45 changed files with 2061 additions and 687 deletions
@ -0,0 +1,94 @@ |
|||
///
|
|||
/// Copyright © 2016-2020 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 { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils'; |
|||
import { Observable } from 'rxjs'; |
|||
import { HttpClient } from '@angular/common/http'; |
|||
import { PageLink } from '@shared/models/page/page-link'; |
|||
import { PageData } from '@shared/models/page/page-data'; |
|||
import { EntitySubtype } from '@app/shared/models/entity-type.models'; |
|||
import {Edge, EdgeInfo, EdgeSearchQuery } from "@shared/models/edge.models"; |
|||
|
|||
@Injectable({ |
|||
providedIn: 'root' |
|||
}) |
|||
export class EdgeService { |
|||
|
|||
constructor( |
|||
private http: HttpClient |
|||
) { } |
|||
|
|||
public getEdges(edgeIds: Array<string>, config?: RequestConfig): Observable<Array<Edge>> { |
|||
return this.http.get<Array<Edge>>(`/api/edges?edgeIds=${edgeIds.join(',')}`, |
|||
defaultHttpOptionsFromConfig(config)); |
|||
} |
|||
|
|||
public getEdge(edgeId: string, config?: RequestConfig): Observable<EdgeInfo> { |
|||
return this.http.get<EdgeInfo>(`/api/edge/${edgeId}`, defaultHttpOptionsFromConfig(config)); |
|||
} |
|||
|
|||
public saveEdge(edge: Edge, config?: RequestConfig): Observable<Edge> { |
|||
return this.http.post<Edge>('/api/edge', edge, defaultHttpOptionsFromConfig(config)); |
|||
} |
|||
|
|||
public deleteEdge(edgeId: string, config?: RequestConfig) { |
|||
return this.http.delete(`/api/edge/${edgeId}`, defaultHttpOptionsFromConfig(config)); |
|||
} |
|||
|
|||
public getEdgeTypes(config?: RequestConfig): Observable<Array<EntitySubtype>> { |
|||
return this.http.get<Array<EntitySubtype>>('/api/edge/types', defaultHttpOptionsFromConfig(config)); |
|||
} |
|||
|
|||
public getTenantEdges(pageLink: PageLink, type: string = '', |
|||
config?: RequestConfig): Observable<PageData<EdgeInfo>> { |
|||
return this.http.get<PageData<EdgeInfo>>(`/api/tenant/edges${pageLink.toQuery()}&type=${type}`, |
|||
defaultHttpOptionsFromConfig(config)); |
|||
} |
|||
|
|||
public getCustomerEdges(customerId: string, pageLink: PageLink, type: string = '', |
|||
config?: RequestConfig): Observable<PageData<EdgeInfo>> { |
|||
return this.http.get<PageData<EdgeInfo>>(`/api/customer/${customerId}/edges${pageLink.toQuery()}&type=${type}`, |
|||
defaultHttpOptionsFromConfig(config)); |
|||
} |
|||
|
|||
public assignEdgeToCustomer(customerId: string, edgeId: string, config?: RequestConfig): Observable<Edge> { |
|||
return this.http.post<Edge>(`/api/customer/${customerId}/edge/${edgeId}`, null, defaultHttpOptionsFromConfig(config)); |
|||
} |
|||
|
|||
public unassignEdgeFromCustomer(edgeId: string, config?: RequestConfig) { |
|||
return this.http.delete(`/api/customer/edge/${edgeId}`, defaultHttpOptionsFromConfig(config)); |
|||
} |
|||
|
|||
public makeEdgePublic(edgeId: string, config?: RequestConfig): Observable<Edge> { |
|||
return this.http.post<Edge>(`/api/customer/public/edge/${edgeId}`, null, defaultHttpOptionsFromConfig(config)); |
|||
} |
|||
|
|||
public setRootRuleChain(edgeId: string, ruleChainId: string, config?: RequestConfig): Observable<Edge> { |
|||
return this.http.post<Edge>(`/api/edge/${edgeId}/${ruleChainId}/root`, null, defaultHttpOptionsFromConfig(config)); |
|||
} |
|||
|
|||
public getTenantEdgeInfos(pageLink: PageLink, type: string = '', |
|||
config?: RequestConfig): Observable<PageData<EdgeInfo>> { |
|||
return this.http.get<PageData<EdgeInfo>>(`/api/tenant/edgeInfos${pageLink.toQuery()}&type=${type}`, |
|||
defaultHttpOptionsFromConfig(config)); |
|||
} |
|||
|
|||
public findByQuery(query: EdgeSearchQuery, config?: RequestConfig): Observable<Array<Edge>> { |
|||
return this.http.post<Array<Edge>>('/api/edges', query, defaultHttpOptionsFromConfig(config)); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,57 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2020 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. |
|||
|
|||
--> |
|||
<form [formGroup]="addEntitiesToEdgeFormGroup" (ngSubmit)="assign()"> |
|||
<mat-toolbar fxLayout="row" color="primary"> |
|||
<h2>{{ assignToEdgeTitle | translate }}</h2> |
|||
<span fxFlex></span> |
|||
<button mat-button mat-icon-button |
|||
(click)="cancel()" |
|||
type="button"> |
|||
<mat-icon class="material-icons">close</mat-icon> |
|||
</button> |
|||
</mat-toolbar> |
|||
<mat-progress-bar color="warn" mode="indeterminate" *ngIf="isLoading$ | async"> |
|||
</mat-progress-bar> |
|||
<div style="height: 4px;" *ngIf="!(isLoading$ | async)"></div> |
|||
<div mat-dialog-content> |
|||
<fieldset [disabled]="isLoading$ | async"> |
|||
<span>{{ assignToEdgeText | translate }}</span> |
|||
<tb-entity-list |
|||
formControlName="entityIds" |
|||
required |
|||
[entityType]="entityType" |
|||
> |
|||
</tb-entity-list> |
|||
</fieldset> |
|||
</div> |
|||
<div mat-dialog-actions fxLayoutAlign="end center"> |
|||
<button mat-raised-button color="primary" |
|||
type="submit" |
|||
[disabled]="(isLoading$ | async) || addEntitiesToEdgeFormGroup.invalid |
|||
|| !addEntitiesToEdgeFormGroup.dirty"> |
|||
{{ 'action.assign' | translate }} |
|||
</button> |
|||
<button mat-button color="primary" |
|||
style="margin-right: 20px;" |
|||
type="button" |
|||
[disabled]="(isLoading$ | async)" |
|||
(click)="cancel()" cdkFocusInitial> |
|||
{{ 'action.cancel' | translate }} |
|||
</button> |
|||
</div> |
|||
</form> |
|||
@ -0,0 +1,142 @@ |
|||
///
|
|||
/// Copyright © 2016-2020 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, Inject, OnInit, SkipSelf } from '@angular/core'; |
|||
import { ErrorStateMatcher } from '@angular/material/core'; |
|||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { FormBuilder, FormControl, FormGroup, FormGroupDirective, NgForm, Validators } from '@angular/forms'; |
|||
import { DeviceService } from '@core/http/device.service'; |
|||
import { EdgeService } from "@core/http/edge.service"; |
|||
import { EntityType } from '@shared/models/entity-type.models'; |
|||
import { forkJoin, Observable } from 'rxjs'; |
|||
import { AssetService } from '@core/http/asset.service'; |
|||
import { EntityViewService } from '@core/http/entity-view.service'; |
|||
import { DashboardService } from '@core/http/dashboard.service'; |
|||
import { DialogComponent } from '@shared/components/dialog.component'; |
|||
import { Router } from '@angular/router'; |
|||
import { RuleChainService } from "@core/http/rule-chain.service"; |
|||
|
|||
export interface AddEntitiesToEdgeDialogData { |
|||
edgeId: string; |
|||
entityType: EntityType; |
|||
} |
|||
|
|||
@Component({ |
|||
selector: 'tb-add-entities-to-edge-dialog', |
|||
templateUrl: './add-entities-to-edge-dialog.component.html', |
|||
providers: [{provide: ErrorStateMatcher, useExisting: AddEntitiesToEdgeDialogComponent}], |
|||
styleUrls: [] |
|||
}) |
|||
export class AddEntitiesToEdgeDialogComponent extends |
|||
DialogComponent<AddEntitiesToEdgeDialogComponent, boolean> implements OnInit, ErrorStateMatcher { |
|||
|
|||
addEntitiesToEdgeFormGroup: FormGroup; |
|||
|
|||
submitted = false; |
|||
|
|||
entityType: EntityType; |
|||
|
|||
assignToEdgeTitle: string; |
|||
assignToEdgeText: string; |
|||
|
|||
constructor(protected store: Store<AppState>, |
|||
protected router: Router, |
|||
@Inject(MAT_DIALOG_DATA) public data: AddEntitiesToEdgeDialogData, |
|||
private deviceService: DeviceService, |
|||
private edgeService: EdgeService, |
|||
private assetService: AssetService, |
|||
private entityViewService: EntityViewService, |
|||
private dashboardService: DashboardService, |
|||
private ruleChainService: RuleChainService, |
|||
@SkipSelf() private errorStateMatcher: ErrorStateMatcher, |
|||
public dialogRef: MatDialogRef<AddEntitiesToEdgeDialogComponent, boolean>, |
|||
public fb: FormBuilder) { |
|||
super(store, router, dialogRef); |
|||
this.entityType = data.entityType; |
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
this.addEntitiesToEdgeFormGroup = this.fb.group({ |
|||
entityIds: [null, [Validators.required]] |
|||
}); |
|||
switch (this.data.entityType) { |
|||
case EntityType.DEVICE: |
|||
this.assignToEdgeTitle = 'device.assign-device-to-edge'; |
|||
this.assignToEdgeText = 'device.assign-device-to-edge-text'; |
|||
break; |
|||
case EntityType.RULE_CHAIN: |
|||
this.assignToEdgeTitle = 'rulechain.assign-rulechain-to-edge'; |
|||
this.assignToEdgeText = 'rulechain.assign-rulechain-to-edge-text'; |
|||
break; |
|||
case EntityType.ASSET: |
|||
this.assignToEdgeTitle = 'asset.assign-asset-to-edge'; |
|||
this.assignToEdgeText = 'asset.assign-asset-to-edge-text'; |
|||
break; |
|||
case EntityType.ENTITY_VIEW: |
|||
this.assignToEdgeTitle = 'entity-view.assign-entity-view-to-edge'; |
|||
this.assignToEdgeText = 'entity-view.assign-entity-view-to-edge-text'; |
|||
break; |
|||
case EntityType.DASHBOARD: |
|||
this.assignToEdgeTitle = 'dashboard.assign-dashboard-to-edge'; |
|||
this.assignToEdgeText = 'dashboard.assign-dashboard-to-edge-text'; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean { |
|||
const originalErrorState = this.errorStateMatcher.isErrorState(control, form); |
|||
const customErrorState = !!(control && control.invalid && this.submitted); |
|||
return originalErrorState || customErrorState; |
|||
} |
|||
|
|||
cancel(): void { |
|||
this.dialogRef.close(false); |
|||
} |
|||
|
|||
assign(): void { |
|||
this.submitted = true; |
|||
const entityIds: Array<string> = this.addEntitiesToEdgeFormGroup.get('entityIds').value; |
|||
const tasks: Observable<any>[] = []; |
|||
entityIds.forEach( |
|||
(entityId) => { |
|||
tasks.push(this.getAssignToEdgeTask(this.data.edgeId, entityId)); |
|||
} |
|||
); |
|||
forkJoin(tasks).subscribe( |
|||
() => { |
|||
this.dialogRef.close(true); |
|||
} |
|||
); |
|||
} |
|||
|
|||
private getAssignToEdgeTask(edgeId: string, entityId: string): Observable<any> { |
|||
switch (this.data.entityType) { |
|||
case EntityType.DEVICE: |
|||
return this.deviceService.assignDeviceToEdge(edgeId, entityId); |
|||
case EntityType.ASSET: |
|||
return this.assetService.assignAssetToEdge(edgeId, entityId); |
|||
case EntityType.ENTITY_VIEW: |
|||
return this.entityViewService.assignEntityViewToEdge(edgeId, entityId); |
|||
case EntityType.DASHBOARD: |
|||
return this.dashboardService.assignDashboardToEdge(edgeId, entityId); |
|||
case EntityType.RULE_CHAIN: |
|||
return this.ruleChainService.assignRuleChainToEdge(edgeId, entityId); |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,139 @@ |
|||
///
|
|||
/// Copyright © 2016-2020 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 { NgModule } from '@angular/core'; |
|||
import { RouterModule, Routes } from "@angular/router"; |
|||
import { EntitiesTableComponent } from "@home/components/entity/entities-table.component"; |
|||
import { Authority } from "@shared/models/authority.enum"; |
|||
import { EdgesTableConfigResolver } from "@home/pages/edge/edges-table-config.resolver" |
|||
import { AssetsTableConfigResolver } from "@home/pages/asset/assets-table-config.resolver"; |
|||
import { DevicesTableConfigResolver } from "@home/pages/device/devices-table-config.resolver"; |
|||
import { EntityViewsTableConfigResolver } from "@home/pages/entity-view/entity-views-table-config.resolver"; |
|||
import { DashboardsTableConfigResolver } from "@home/pages/dashboard/dashboards-table-config.resolver"; |
|||
import { RuleChainsTableConfigResolver } from "@home/pages/rulechain/rulechains-table-config.resolver"; |
|||
|
|||
const routes: Routes = [ |
|||
{ |
|||
path: 'edges', |
|||
data: { |
|||
breadcrumb: { |
|||
label: 'edge.edges', |
|||
icon: 'router' |
|||
} |
|||
}, |
|||
children: [ |
|||
{ |
|||
path: '', |
|||
component: EntitiesTableComponent, |
|||
data: { |
|||
auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER], |
|||
title: 'edge.edges', |
|||
edgeScope: 'tenant' |
|||
}, |
|||
resolve: { |
|||
entitiesTableConfig: EdgesTableConfigResolver |
|||
} |
|||
}, |
|||
{ |
|||
path: ':edgeId/ruleChains', |
|||
component: EntitiesTableComponent, |
|||
data: { |
|||
auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER], |
|||
title: 'edge.rulechains', |
|||
ruleChainScope: 'edge', |
|||
breadcrumb: { |
|||
label: 'edge.rulechains', |
|||
icon: 'settings_ethernet' |
|||
}, |
|||
}, |
|||
resolve: { |
|||
entitiesTableConfig: RuleChainsTableConfigResolver |
|||
} |
|||
}, |
|||
{ |
|||
path: ':edgeId/assets', |
|||
component: EntitiesTableComponent, |
|||
data: { |
|||
auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER], |
|||
title: 'edge.assets', |
|||
assetsType: 'edge', |
|||
breadcrumb: { |
|||
label: 'edge.assets', |
|||
icon: 'domain' |
|||
} |
|||
}, |
|||
resolve: { |
|||
entitiesTableConfig: AssetsTableConfigResolver |
|||
} |
|||
}, |
|||
{ |
|||
path: ':edgeId/devices', |
|||
component: EntitiesTableComponent, |
|||
data: { |
|||
auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER], |
|||
title: 'edge.devices', |
|||
devicesType: 'edge', |
|||
breadcrumb: { |
|||
label: 'edge.devices', |
|||
icon: 'devices_other' |
|||
} |
|||
}, |
|||
resolve: { |
|||
entitiesTableConfig: DevicesTableConfigResolver |
|||
} |
|||
}, |
|||
{ |
|||
path: ':edgeId/entityViews', |
|||
component: EntitiesTableComponent, |
|||
data: { |
|||
auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER], |
|||
title: 'edge.entity-views', |
|||
entityViewsType: 'edge', |
|||
breadcrumb: { |
|||
label: 'edge.entity-views', |
|||
icon: 'view_quilt' |
|||
}, |
|||
}, |
|||
resolve: { |
|||
entitiesTableConfig: EntityViewsTableConfigResolver |
|||
} |
|||
}, |
|||
{ |
|||
path: ':edgeId/dashboards', |
|||
component: EntitiesTableComponent, |
|||
data: { |
|||
auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER], |
|||
title: 'edge.dashboards', |
|||
dashboardsType: 'edge', |
|||
breadcrumb: { |
|||
label: 'edge.dashboards', |
|||
icon: 'dashboard' |
|||
} |
|||
}, |
|||
resolve: { |
|||
entitiesTableConfig: DashboardsTableConfigResolver |
|||
} |
|||
}] |
|||
}] |
|||
|
|||
@NgModule({ |
|||
imports: [RouterModule.forChild(routes)], |
|||
exports: [RouterModule], |
|||
providers: [ |
|||
EdgesTableConfigResolver |
|||
] |
|||
}) |
|||
export class EdgeRoutingModule { } |
|||
@ -0,0 +1,23 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2020 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. |
|||
|
|||
--> |
|||
<tb-entity-subtype-select |
|||
[showLabel]="true" |
|||
[entityType]="entityType.EDGE" |
|||
[ngModel]="entitiesTableConfig.componentsData.edgeType" |
|||
(ngModelChange)="edgeTypeChanged($event)"> |
|||
</tb-entity-subtype-select> |
|||
@ -0,0 +1,49 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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 '../../../../../scss/constants'; |
|||
|
|||
:host { |
|||
flex: 1; |
|||
display: flex; |
|||
justify-content: flex-start; |
|||
min-width: 150px; |
|||
} |
|||
|
|||
:host ::ng-deep { |
|||
tb-entity-subtype-select { |
|||
width: 100%; |
|||
|
|||
mat-form-field { |
|||
font-size: 16px; |
|||
|
|||
.mat-form-field-wrapper { |
|||
padding-bottom: 0; |
|||
} |
|||
|
|||
.mat-form-field-underline { |
|||
bottom: 0; |
|||
} |
|||
|
|||
@media #{$mat-xs} { |
|||
width: 100%; |
|||
|
|||
.mat-form-field-infix { |
|||
width: auto !important; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
///
|
|||
/// Copyright © 2016-2020 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 { EntityTableHeaderComponent } from "@home/components/entity/entity-table-header.component"; |
|||
import { EntityType } from "@shared/models/entity-type.models"; |
|||
import { Store } from "@ngrx/store"; |
|||
import { AppState } from "@core/core.state"; |
|||
import { EdgeInfo } from "@shared/models/edge.models"; |
|||
|
|||
@Component({ |
|||
selector: 'tb-edge-table-header', |
|||
templateUrl: './edge-table-header.component.html', |
|||
styleUrls: ['./edge-table-header.component.scss'] |
|||
}) |
|||
export class EdgeTableHeaderComponent extends EntityTableHeaderComponent<EdgeInfo> { |
|||
|
|||
entityType = EntityType; |
|||
|
|||
constructor(protected store: Store<AppState>) { |
|||
super(store); |
|||
} |
|||
|
|||
edgeTypeChanged(edgeType: string) { |
|||
this.entitiesTableConfig.componentsData.edgeType = edgeType; |
|||
this.entitiesTableConfig.table.resetSortAndFilter(true); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2020 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" |
|||
label="{{ 'attribute.attributes' | translate }}" #attributesTab="matTab"> |
|||
<tb-attribute-table [defaultAttributeScope]="attributeScopes.CLIENT_SCOPE" |
|||
[active]="attributesTab.isActive" |
|||
[entityId]="entity.id" |
|||
[entityName]="entity.name"> |
|||
</tb-attribute-table> |
|||
</mat-tab> |
|||
<mat-tab *ngIf="entity" |
|||
label="{{ 'attribute.latest-telemetry' | translate }}" #telemetryTab="matTab"> |
|||
<tb-attribute-table [defaultAttributeScope]="latestTelemetryTypes.LATEST_TELEMETRY" |
|||
disableAttributeScopeSelection |
|||
[active]="telemetryTab.isActive" |
|||
[entityId]="entity.id" |
|||
[entityName]="entity.name"> |
|||
</tb-attribute-table> |
|||
</mat-tab> |
|||
<mat-tab *ngIf="entity" |
|||
label="{{ 'alarm.alarms' | translate }}" #alarmsTab="matTab"> |
|||
<tb-alarm-table [active]="alarmsTab.isActive" [entityId]="entity.id"></tb-alarm-table> |
|||
</mat-tab> |
|||
<mat-tab *ngIf="entity" |
|||
label="{{ 'edge.events' | translate }}" #eventsTab="matTab"> |
|||
<tb-event-table [defaultEventType]="eventTypes.ERROR" [active]="eventsTab.isActive" [tenantId]="entity.tenantId.id" |
|||
[entityId]="entity.id"></tb-event-table> |
|||
</mat-tab> |
|||
<mat-tab *ngIf="entity" |
|||
label="{{ 'relation.relations' | translate }}" #relationsTab="matTab"> |
|||
<tb-relation-table [active]="relationsTab.isActive" [entityId]="entity.id"></tb-relation-table> |
|||
</mat-tab> |
|||
<mat-tab *ngIf="entity && authUser.authority === authorities.TENANT_ADMIN" |
|||
label="{{ 'audit-log.audit-logs' | translate }}" #auditLogsTab="matTab"> |
|||
<tb-audit-log-table detailsMode="true" [active]="auditLogsTab.isActive" [auditLogMode]="auditLogModes.ENTITY" [entityId]="entity.id"></tb-audit-log-table> |
|||
</mat-tab> |
|||
@ -0,0 +1,38 @@ |
|||
///
|
|||
/// Copyright © 2016-2020 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 {EdgeInfo} from "@shared/models/edge.models"; |
|||
import {EntityTabsComponent} from "@home/components/entity/entity-tabs.component"; |
|||
|
|||
@Component({ |
|||
selector: 'tb-edge-tabs', |
|||
templateUrl: './edge-tabs.component.html', |
|||
styleUrls: [] |
|||
}) |
|||
export class EdgeTabsComponent extends EntityTabsComponent<EdgeInfo> { |
|||
|
|||
constructor(protected store: Store<AppState>) { |
|||
super(store); |
|||
} |
|||
|
|||
ngOnInit() { |
|||
super.ngOnInit(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,124 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2020 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, 'makePublic')" |
|||
[fxShow]="!isEdit && edgeScope === 'tenant' && !isAssignedToCustomer(entity) && !entity?.customerIsPublic"> |
|||
{{'edge.make-public' | translate }} |
|||
</button> |
|||
<button mat-raised-button color="primary" |
|||
[disabled]="(isLoading$ | async)" |
|||
(click)="onEntityAction($event, 'assignToCustomer')" |
|||
[fxShow]="!isEdit && edgeScope === 'tenant' && !isAssignedToCustomer(entity)"> |
|||
{{'edge.assign-to-customer' | translate }} |
|||
</button> |
|||
<button mat-raised-button color="primary" |
|||
[disabled]="(isLoading$ | async)" |
|||
(click)="onEntityAction($event, 'unassignFromCustomer')" |
|||
[fxShow]="!isEdit && (edgeScope === 'customer' || edgeScope === 'tenant') && isAssignedToCustomer(entity)"> |
|||
{{ (entity?.customerIsPublic ? 'edge.make-private' : 'edge.unassign-from-customer') | translate }} |
|||
</button> |
|||
<button mat-raised-button color="primary" fxFlex.xs |
|||
[disabled]="(isLoading$ | async)" |
|||
(click)="onEntityAction($event, 'delete')" |
|||
[fxShow]="!hideDelete() && !isEdit"> |
|||
{{'edge.delete' | translate }} |
|||
</button> |
|||
<div fxLayout="row" fxLayout.xs="column"> |
|||
<button mat-raised-button |
|||
ngxClipboard |
|||
(cbOnSuccess)="onEdgeIdCopied($event)" |
|||
[cbContent]="entity?.id?.id" |
|||
[fxShow]="!isEdit"> |
|||
<mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon> |
|||
<span translate>edge.copy-id</span> |
|||
</button> |
|||
</div> |
|||
</div> |
|||
<div class="mat-padding" fxLayout="column"> |
|||
<mat-form-field class="mat-block" |
|||
[fxShow]="!isEdit && isAssignedToCustomer(entity) |
|||
&& !entity?.customerIsPublic && edgeScope === 'tenant'"> |
|||
<mat-label translate>edge.assigned-to-customer</mat-label> |
|||
<input matInput disabled [ngModel]="entity?.customerTitle"> |
|||
</mat-form-field> |
|||
<div class="tb-small" style="padding-bottom: 10px; padding-left: 2px;" |
|||
[fxShow]="!isEdit && entity?.customerIsPublic && (edgeScope === 'customer' || edgeScope === 'tenant')"> |
|||
{{ 'edge.public' | translate }} |
|||
</div> |
|||
<form [formGroup]="entityForm"> |
|||
<fieldset [disabled]="(isLoading$ | async) || !isEdit"> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>edge.name</mat-label> |
|||
<input matInput formControlName="name" required> |
|||
<mat-error *ngIf="entityForm.get('name').hasError('required')"> |
|||
{{ 'edge.name-required' | translate }} |
|||
</mat-error> |
|||
</mat-form-field> |
|||
<tb-entity-subtype-autocomplete |
|||
formControlName="type" |
|||
[required]="true" |
|||
[entityType]="entityType.EDGE"> |
|||
</tb-entity-subtype-autocomplete> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>edge.label</mat-label> |
|||
<input matInput formControlName="label"> |
|||
</mat-form-field> |
|||
|
|||
<div formGroupName="additionalInfo" fxLayout="column"> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>edge.description</mat-label> |
|||
<textarea matInput formControlName="description" rows="2"></textarea> |
|||
</mat-form-field> |
|||
</div> |
|||
</fieldset> |
|||
<div fxLayout="row"> |
|||
<fieldset fxFlex disabled> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>edge.edge-key</mat-label> |
|||
<input matInput formControlName="routingKey"> |
|||
</mat-form-field> |
|||
</fieldset> |
|||
<button mat-button mat-icon-button |
|||
style="margin-top: 14px" |
|||
ngxClipboard |
|||
(cbOnSuccess)="onEdgeKeyCopied($event)" |
|||
[cbContent]="entity?.routingKey" |
|||
[fxShow]="!isEdit"> |
|||
<mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon> |
|||
</button> |
|||
</div> |
|||
<div fxLayout="row"> |
|||
<fieldset fxFlex disabled> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>edge.edge-secret</mat-label> |
|||
<input matInput formControlName="secret"> |
|||
</mat-form-field> |
|||
</fieldset> |
|||
<button mat-button mat-icon-button |
|||
style="margin-top: 14px" |
|||
ngxClipboard |
|||
(cbOnSuccess)="onEdgeSecretCopied($event)" |
|||
[cbContent]="entity?.secret" |
|||
[fxShow]="!isEdit"> |
|||
<mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon> |
|||
</button> |
|||
</div> |
|||
</form> |
|||
</div> |
|||
@ -0,0 +1,18 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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. |
|||
*/ |
|||
:host { |
|||
|
|||
} |
|||
@ -0,0 +1,138 @@ |
|||
///
|
|||
/// Copyright © 2016-2020 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, Inject } from '@angular/core'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from "@core/core.state"; |
|||
import { EntityComponent } from "@home/components/entity/entity.component"; |
|||
import {FormBuilder, FormControl, FormGroup, NgModel, Validators} from "@angular/forms"; |
|||
import { EntityType } from "@shared/models/entity-type.models"; |
|||
import { EdgeInfo } from "@shared/models/edge.models"; |
|||
import { TranslateService } from "@ngx-translate/core"; |
|||
import { NULL_UUID } from "@shared/models/id/has-uuid"; |
|||
import { ActionNotificationShow } from "@core/notification/notification.actions"; |
|||
import { guid, isUndefined } from "@core/utils"; |
|||
import { EntityTableConfig } from "@home/models/entity/entities-table-config.models"; |
|||
|
|||
@Component({ |
|||
selector: 'tb-edge', |
|||
templateUrl: './edge.component.html', |
|||
styleUrls: ['./edge.component.scss'] |
|||
}) |
|||
|
|||
export class EdgeComponent extends EntityComponent<EdgeInfo>{ |
|||
|
|||
entityType = EntityType; |
|||
edgeScope: 'tenant' | 'customer' | 'customer_user'; |
|||
|
|||
constructor(protected store: Store<AppState>, |
|||
protected translate: TranslateService, |
|||
@Inject('entity') protected entityValue: EdgeInfo, |
|||
@Inject('entitiesTableConfig') protected entitiesTableConfigValue: EntityTableConfig<EdgeInfo>, |
|||
public fb: FormBuilder) { |
|||
super(store, fb, entityValue, entitiesTableConfigValue); |
|||
} |
|||
|
|||
ngOnInit() { |
|||
this.edgeScope = this.entitiesTableConfig.componentsData.edgeScope; |
|||
super.ngOnInit() |
|||
} |
|||
|
|||
hideDelete() { |
|||
if (this.entitiesTableConfig) { |
|||
return !this.entitiesTableConfig.deleteEnabled(this.entity); |
|||
} else { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
isAssignedToCustomer(entity: EdgeInfo): boolean { |
|||
return entity && entity.customerId && entity.customerId.id !== NULL_UUID; |
|||
} |
|||
|
|||
buildForm(entity: EdgeInfo): FormGroup { |
|||
return this.fb.group( |
|||
{ |
|||
name: [entity ? entity.name : '', [Validators.required]], |
|||
type: [entity ? entity.type : null, [Validators.required]], |
|||
label: [entity ? entity.label : ''], |
|||
routingKey: guid(), |
|||
secret: this.generateSecret(20), |
|||
additionalInfo: this.fb.group( |
|||
{ |
|||
description: [entity && entity.additionalInfo ? entity.additionalInfo.description : ''] |
|||
} |
|||
) |
|||
} |
|||
); |
|||
} |
|||
|
|||
updateForm(entity: EdgeInfo) { |
|||
this.entityForm.patchValue({name: entity.name}); |
|||
this.entityForm.patchValue({type: entity.type}); |
|||
this.entityForm.patchValue({label: entity.label}); |
|||
this.entityForm.patchValue({routingKey: entity.routingKey}); |
|||
this.entityForm.patchValue({secret: entity.secret}); |
|||
this.entityForm.patchValue({additionalInfo: { |
|||
description: entity.additionalInfo ? entity.additionalInfo.description : ''}}); |
|||
} |
|||
|
|||
onEdgeIdCopied($event) { |
|||
this.store.dispatch(new ActionNotificationShow( |
|||
{ |
|||
message: this.translate.instant('edge.id-copied-message'), |
|||
type: 'success', |
|||
duration: 750, |
|||
verticalPosition: 'bottom', |
|||
horizontalPosition: 'left' |
|||
})); |
|||
} |
|||
|
|||
onEdgeKeyCopied($event) { |
|||
this.store.dispatch(new ActionNotificationShow( |
|||
{ |
|||
message: this.translate.instant('edge.edge-key-copied-message'), |
|||
type: 'success', |
|||
duration: 750, |
|||
verticalPosition: 'bottom', |
|||
horizontalPosition: 'left' |
|||
})); |
|||
} |
|||
|
|||
onEdgeSecretCopied($event) { |
|||
this.store.dispatch(new ActionNotificationShow( |
|||
{ |
|||
message: this.translate.instant('edge.edge-secret-copied-message'), |
|||
type: 'success', |
|||
duration: 750, |
|||
verticalPosition: 'bottom', |
|||
horizontalPosition: 'left' |
|||
})); |
|||
} |
|||
|
|||
generateSecret(length): string { |
|||
if (isUndefined(length) || length == null) { |
|||
length = 1; |
|||
} |
|||
var l = length > 10 ? 10 : length; |
|||
var str = Math.random().toString(36).substr(2, l); |
|||
if (str.length >= length) { |
|||
return str; |
|||
} |
|||
return str.concat(this.generateSecret(length - str.length)); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
///
|
|||
/// Copyright © 2016-2020 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 { NgModule } from '@angular/core'; |
|||
import { CommonModule } from '@angular/common'; |
|||
import { SharedModule } from '@shared/shared.module'; |
|||
import { HomeDialogsModule } from "@home/dialogs/home-dialogs.module"; |
|||
import { HomeComponentsModule } from "@home/components/home-components.module"; |
|||
import { EdgeRoutingModule } from "@home/pages/edge/edge-routing.module"; |
|||
import { EdgeComponent } from '@modules/home/pages/edge/edge.component'; |
|||
import { EdgeTableHeaderComponent } from "@home/pages/edge/edge-table-header.component"; |
|||
import { EdgeTabsComponent } from "@home/pages/edge/edge-tabs.component"; |
|||
|
|||
@NgModule({ |
|||
declarations: [ |
|||
EdgeComponent, |
|||
EdgeTableHeaderComponent, |
|||
EdgeTabsComponent |
|||
], |
|||
imports: [ |
|||
CommonModule, |
|||
SharedModule, |
|||
HomeDialogsModule, |
|||
HomeComponentsModule, |
|||
EdgeRoutingModule |
|||
] |
|||
}) |
|||
|
|||
export class EdgeModule { } |
|||
@ -0,0 +1,509 @@ |
|||
///
|
|||
/// Copyright © 2016-2020 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 { ActivatedRouteSnapshot, Resolve, Router } from '@angular/router'; |
|||
import { |
|||
CellActionDescriptor, |
|||
checkBoxCell, |
|||
DateEntityTableColumn, |
|||
EntityTableColumn, |
|||
EntityTableConfig, |
|||
GroupActionDescriptor, |
|||
HeaderActionDescriptor |
|||
} 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 { forkJoin, Observable, of } from 'rxjs'; |
|||
import { select, Store } from '@ngrx/store'; |
|||
import { selectAuthUser } from '@core/auth/auth.selectors'; |
|||
import { map, mergeMap, take, tap } from 'rxjs/operators'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { Authority } from '@app/shared/models/authority.enum'; |
|||
import { CustomerService } from '@core/http/customer.service'; |
|||
import { Customer } from '@app/shared/models/customer.model'; |
|||
import { NULL_UUID } from '@shared/models/id/has-uuid'; |
|||
import { BroadcastService } from '@core/services/broadcast.service'; |
|||
import { MatDialog } from '@angular/material/dialog'; |
|||
import { DialogService } from '@core/services/dialog.service'; |
|||
import { |
|||
AssignToCustomerDialogComponent, |
|||
AssignToCustomerDialogData |
|||
} from '@modules/home/dialogs/assign-to-customer-dialog.component'; |
|||
import { |
|||
AddEntitiesToCustomerDialogComponent, |
|||
AddEntitiesToCustomerDialogData |
|||
} from '../../dialogs/add-entities-to-customer-dialog.component'; |
|||
import { HomeDialogsService } from '@home/dialogs/home-dialogs.service'; |
|||
|
|||
import { Edge, EdgeInfo } from "@shared/models/edge.models"; |
|||
import { EdgeService } from "@core/http/edge.service"; |
|||
import { EdgeComponent } from "@home/pages/edge/edge.component"; |
|||
import { EdgeTableHeaderComponent } from "@home/pages/edge/edge-table-header.component"; |
|||
import { EdgeId } from "@shared/models/id/edge-id"; |
|||
import { EdgeTabsComponent } from "@home/pages/edge/edge-tabs.component"; |
|||
|
|||
@Injectable() |
|||
export class EdgesTableConfigResolver implements Resolve<EntityTableConfig<EdgeInfo>> { |
|||
|
|||
private readonly config: EntityTableConfig<EdgeInfo> = new EntityTableConfig<EdgeInfo>(); |
|||
private customerId: string; |
|||
|
|||
constructor(private store: Store<AppState>, |
|||
private broadcast: BroadcastService, |
|||
private edgeService: EdgeService, |
|||
private customerService: CustomerService, |
|||
private dialogService: DialogService, |
|||
private homeDialogs: HomeDialogsService, |
|||
private translate: TranslateService, |
|||
private datePipe: DatePipe, |
|||
private router: Router, |
|||
private dialog: MatDialog) { |
|||
|
|||
this.config.entityType = EntityType.EDGE; |
|||
this.config.entityComponent = EdgeComponent; |
|||
this.config.entityTabsComponent = EdgeTabsComponent; |
|||
this.config.entityTranslations = entityTypeTranslations.get(EntityType.EDGE); |
|||
this.config.entityResources = entityTypeResources.get(EntityType.EDGE); |
|||
|
|||
this.config.deleteEntityTitle = edge => this.translate.instant('edge.delete-edge-title', {edgeName: edge.name}); |
|||
this.config.deleteEntityContent = () => this.translate.instant('edge.delete-edge-text'); |
|||
this.config.deleteEntitiesTitle = count => this.translate.instant('edge.delete-edges-title', {count}); |
|||
this.config.deleteEntitiesContent = () => this.translate.instant('edge.delete-edges-text'); |
|||
|
|||
this.config.loadEntity = id => this.edgeService.getEdge(id.id); |
|||
this.config.saveEntity = edge => { |
|||
return this.edgeService.saveEdge(edge).pipe( |
|||
tap(() => { |
|||
this.broadcast.broadcast('edgeSaved'); |
|||
}), |
|||
mergeMap((savedEdge) => this.edgeService.getEdge(savedEdge.id.id) |
|||
)); |
|||
}; |
|||
|
|||
this.config.onEntityAction = action => this.onEdgeAction(action); |
|||
this.config.detailsReadonly = () => this.config.componentsData.edgeScope === 'customer_user'; |
|||
|
|||
this.config.headerComponent = EdgeTableHeaderComponent; |
|||
|
|||
} |
|||
|
|||
resolve(route: ActivatedRouteSnapshot): Observable<EntityTableConfig<EdgeInfo>> { |
|||
const routeParams = route.params; |
|||
this.config.componentsData = { |
|||
edgeScope: route.data.edgeScope, |
|||
edgeType: '' |
|||
}; |
|||
this.customerId = routeParams.customerId; |
|||
return this.store.pipe(select(selectAuthUser), take(1)).pipe( |
|||
tap((authUser) => { |
|||
if (authUser.authority === Authority.CUSTOMER_USER) { |
|||
this.config.componentsData.edgeScope = 'customer_user'; |
|||
this.customerId = authUser.customerId; |
|||
} |
|||
}), |
|||
mergeMap(() => |
|||
this.customerId ? this.customerService.getCustomer(this.customerId) : of(null as Customer) |
|||
), |
|||
map((parentCustomer) => { |
|||
if (parentCustomer) { |
|||
if (parentCustomer.additionalInfo && parentCustomer.additionalInfo.isPublic) { |
|||
this.config.tableTitle = this.translate.instant('customer.public-edges'); |
|||
} else { |
|||
this.config.tableTitle = parentCustomer.title + ': ' + this.translate.instant('edge.edges'); |
|||
} |
|||
} else { |
|||
this.config.tableTitle = this.translate.instant('edge.edges'); |
|||
} |
|||
this.config.columns = this.configureColumns(this.config.componentsData.edgeScope); |
|||
this.configureEntityFunctions(this.config.componentsData.edgeScope); |
|||
this.config.cellActionDescriptors = this.configureCellActions(this.config.componentsData.edgeScope); |
|||
this.config.groupActionDescriptors = this.configureGroupActions(this.config.componentsData.edgeScope); |
|||
this.config.addActionDescriptors = this.configureAddActions(this.config.componentsData.edgeScope); |
|||
this.config.addEnabled = this.config.componentsData.edgeScope !== 'customer_user'; |
|||
this.config.entitiesDeleteEnabled = this.config.componentsData.edgeScope === 'tenant'; |
|||
this.config.deleteEnabled = () => this.config.componentsData.edgeScope === 'tenant'; |
|||
return this.config; |
|||
}) |
|||
); |
|||
} |
|||
|
|||
configureColumns(edgeScope: string): Array<EntityTableColumn<EdgeInfo>> { |
|||
const columns: Array<EntityTableColumn<EdgeInfo>> = [ |
|||
new DateEntityTableColumn<EdgeInfo>('createdTime', 'common.created-time', this.datePipe, '150px'), |
|||
new EntityTableColumn<EdgeInfo>('name', 'edge.name', '25%'), |
|||
new EntityTableColumn<EdgeInfo>('type', 'edge.edge-type', '25%'), |
|||
new EntityTableColumn<EdgeInfo>('label', 'edge.label', '25%') |
|||
]; |
|||
if (edgeScope === 'tenant') { |
|||
columns.push( |
|||
new EntityTableColumn<EdgeInfo>('customerTitle', 'customer.customer', '25%'), |
|||
new EntityTableColumn<EdgeInfo>('customerIsPublic', 'edge.public', '60px', |
|||
entity => { |
|||
return checkBoxCell(entity.customerIsPublic); |
|||
}, () => ({}), false), |
|||
); |
|||
} |
|||
return columns; |
|||
} |
|||
|
|||
configureEntityFunctions(edgeScope: string): void { |
|||
if (edgeScope === 'tenant') { |
|||
this.config.entitiesFetchFunction = pageLink => |
|||
this.edgeService.getTenantEdgeInfos(pageLink, this.config.componentsData.edgeType); |
|||
this.config.deleteEntity = id => this.edgeService.deleteEdge(id.id); |
|||
} |
|||
if (edgeScope === 'customer') { |
|||
this.config.entitiesFetchFunction = pageLink => |
|||
this.edgeService.getCustomerEdges(this.customerId, pageLink, this.config.componentsData.edgeType); |
|||
this.config.deleteEntity = id => this.edgeService.unassignEdgeFromCustomer(id.id); |
|||
} |
|||
} |
|||
|
|||
configureCellActions(edgeScope: string): Array<CellActionDescriptor<EdgeInfo>> { |
|||
const actions: Array<CellActionDescriptor<EdgeInfo>> = []; |
|||
if (edgeScope === 'tenant') { |
|||
actions.push( |
|||
{ |
|||
name: this.translate.instant('edge.make-public'), |
|||
icon: 'share', |
|||
isEnabled: (entity) => (!entity.customerId || entity.customerId.id === NULL_UUID), |
|||
onAction: ($event, entity) => this.makePublic($event, entity) |
|||
}, |
|||
{ |
|||
name: this.translate.instant('edge.assign-to-customer'), |
|||
icon: 'assignment_ind', |
|||
isEnabled: (entity) => (!entity.customerId || entity.customerId.id === NULL_UUID), |
|||
onAction: ($event, entity) => this.assignToCustomer($event, [entity.id]) |
|||
}, |
|||
{ |
|||
name: this.translate.instant('edge.unassign-from-customer'), |
|||
icon: 'assignment_return', |
|||
isEnabled: (entity) => (entity.customerId && entity.customerId.id !== NULL_UUID && !entity.customerIsPublic), |
|||
onAction: ($event, entity) => this.unassignFromCustomer($event, entity) |
|||
}, |
|||
{ |
|||
name: this.translate.instant('edge.make-private'), |
|||
icon: 'reply', |
|||
isEnabled: (entity) => (entity.customerId && entity.customerId.id !== NULL_UUID && entity.customerIsPublic), |
|||
onAction: ($event, entity) => this.unassignFromCustomer($event, entity) |
|||
}, |
|||
{ |
|||
name: this.translate.instant('edge.manage-edge-assets'), |
|||
icon: 'domain', |
|||
isEnabled: (entity) => true, |
|||
onAction: ($event, entity) => this.openEdgeAssets($event, entity) |
|||
}, |
|||
{ |
|||
name: this.translate.instant('edge.manage-edge-devices'), |
|||
icon: 'devices_other', |
|||
isEnabled: (entity) => true, |
|||
onAction: ($event, entity) => this.openEdgeDevices($event, entity) |
|||
}, |
|||
{ |
|||
name: this.translate.instant('edge.manage-edge-entity-views'), |
|||
icon: 'view_quilt', |
|||
isEnabled: (entity) => true, |
|||
onAction: ($event, entity) => this.openEdgeEntityViews($event, entity) |
|||
}, |
|||
{ |
|||
name: this.translate.instant('edge.manage-edge-dashboards'), |
|||
icon: 'dashboard', |
|||
isEnabled: (entity) => true, |
|||
onAction: ($event, entity) => this.openEdgeDashboards($event, entity) |
|||
}, |
|||
{ |
|||
name: this.translate.instant('edge.manage-edge-rulechains'), |
|||
icon: 'settings_ethernet', |
|||
isEnabled: (entity) => true, |
|||
onAction: ($event, entity) => this.openEdgeRuleChains($event, entity) |
|||
} |
|||
); |
|||
} |
|||
if (edgeScope === 'customer') { |
|||
actions.push( |
|||
{ |
|||
name: this.translate.instant('edge.unassign-from-customer'), |
|||
icon: 'assignment_return', |
|||
isEnabled: (entity) => (entity.customerId && entity.customerId.id !== NULL_UUID && !entity.customerIsPublic), |
|||
onAction: ($event, entity) => this.unassignFromCustomer($event, entity) |
|||
}, |
|||
{ |
|||
name: this.translate.instant('edge.make-private'), |
|||
icon: 'reply', |
|||
isEnabled: (entity) => (entity.customerId && entity.customerId.id !== NULL_UUID && entity.customerIsPublic), |
|||
onAction: ($event, entity) => this.unassignFromCustomer($event, entity) |
|||
}, |
|||
); |
|||
} |
|||
return actions; |
|||
} |
|||
|
|||
configureGroupActions(edgeScope: string): Array<GroupActionDescriptor<EdgeInfo>> { |
|||
const actions: Array<GroupActionDescriptor<EdgeInfo>> = []; |
|||
if (edgeScope === 'tenant') { |
|||
actions.push( |
|||
{ |
|||
name: this.translate.instant('edge.assign-edge-to-customer-text'), |
|||
icon: 'assignment_ind', |
|||
isEnabled: true, |
|||
onAction: ($event, entities) => this.assignToCustomer($event, entities.map((entity) => entity.id)) |
|||
} |
|||
); |
|||
} |
|||
if (edgeScope === 'customer') { |
|||
actions.push( |
|||
{ |
|||
name: this.translate.instant('edge.unassign-from-customer'), |
|||
icon: 'assignment_return', |
|||
isEnabled: true, |
|||
onAction: ($event, entities) => this.unassignEdgesFromCustomer($event, entities) |
|||
} |
|||
); |
|||
} |
|||
return actions; |
|||
} |
|||
|
|||
configureAddActions(edgeScope: string): Array<HeaderActionDescriptor> { |
|||
const actions: Array<HeaderActionDescriptor> = []; |
|||
if (edgeScope === 'tenant') { |
|||
actions.push( |
|||
{ |
|||
name: this.translate.instant('edge.add-edge-text'), |
|||
icon: 'insert_drive_file', |
|||
isEnabled: () => true, |
|||
onAction: ($event) => this.config.table.addEntity($event) |
|||
}, |
|||
{ |
|||
name: this.translate.instant('edge.import'), |
|||
icon: 'file_upload', |
|||
isEnabled: () => true, |
|||
onAction: ($event) => this.importEdges($event) |
|||
} |
|||
); |
|||
} |
|||
if (edgeScope === 'customer') { |
|||
actions.push( |
|||
{ |
|||
name: this.translate.instant('edge.assign-new-edge'), |
|||
icon: 'add', |
|||
isEnabled: () => true, |
|||
onAction: ($event) => this.addEdgesToCustomer($event) |
|||
} |
|||
); |
|||
} |
|||
return actions; |
|||
} |
|||
|
|||
importEdges($event: Event) { |
|||
this.homeDialogs.importEntities(EntityType.EDGE).subscribe((res) => { |
|||
if (res) { |
|||
this.broadcast.broadcast('edgeSaved'); |
|||
this.config.table.updateData(); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
addEdgesToCustomer($event: Event) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
this.dialog.open<AddEntitiesToCustomerDialogComponent, AddEntitiesToCustomerDialogData, |
|||
boolean>(AddEntitiesToCustomerDialogComponent, { |
|||
disableClose: true, |
|||
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], |
|||
data: { |
|||
customerId: this.customerId, |
|||
entityType: EntityType.EDGE |
|||
} |
|||
}).afterClosed() |
|||
.subscribe((res) => { |
|||
if (res) { |
|||
this.config.table.updateData(); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
makePublic($event: Event, edge: Edge) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
this.dialogService.confirm( |
|||
this.translate.instant('edge.make-public-edge-title', {edgeName: edge.name}), |
|||
this.translate.instant('edge.make-public-edge-text'), |
|||
this.translate.instant('action.no'), |
|||
this.translate.instant('action.yes'), |
|||
true |
|||
).subscribe((res) => { |
|||
if (res) { |
|||
this.edgeService.makeEdgePublic(edge.id.id).subscribe( |
|||
() => { |
|||
this.config.table.updateData(); |
|||
} |
|||
); |
|||
} |
|||
} |
|||
); |
|||
} |
|||
|
|||
openEdgeDashboards($event, edge) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
this.router.navigateByUrl(`edges/${edge.id.id}/dashboards`); |
|||
} |
|||
|
|||
openEdgeRuleChains($event, edge) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
this.router.navigateByUrl(`edges/${edge.id.id}/ruleChains`); |
|||
} |
|||
|
|||
openEdgeAssets($event: Event, edge: Edge) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
this.router.navigateByUrl(`edges/${edge.id.id}/assets`); |
|||
} |
|||
|
|||
openEdgeDevices($event, edge) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
this.router.navigateByUrl(`edges/${edge.id.id}/devices`); |
|||
} |
|||
|
|||
openEdgeEntityViews($event, edge) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
this.router.navigateByUrl(`edges/${edge.id.id}/entityViews`); |
|||
} |
|||
|
|||
assignToCustomer($event: Event, edgesIds: Array<EdgeId>) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
this.dialog.open<AssignToCustomerDialogComponent, AssignToCustomerDialogData, |
|||
boolean>(AssignToCustomerDialogComponent, { |
|||
disableClose: true, |
|||
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], |
|||
data: { |
|||
entityIds: edgesIds, |
|||
entityType: EntityType.EDGE |
|||
} |
|||
}).afterClosed() |
|||
.subscribe((res) => { |
|||
if (res) { |
|||
this.config.table.updateData(); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
unassignFromCustomer($event: Event, edge: EdgeInfo) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
const isPublic = edge.customerIsPublic; |
|||
let title; |
|||
let content; |
|||
if (isPublic) { |
|||
title = this.translate.instant('edge.make-private-edge-title', {edgeName: edge.name}); |
|||
content = this.translate.instant('edge.make-private-edge-text'); |
|||
} else { |
|||
title = this.translate.instant('edge.unassign-edge-title', {edgeName: edge.name}); |
|||
content = this.translate.instant('edge.unassign-edge-text'); |
|||
} |
|||
this.dialogService.confirm( |
|||
title, |
|||
content, |
|||
this.translate.instant('action.no'), |
|||
this.translate.instant('action.yes'), |
|||
true |
|||
).subscribe((res) => { |
|||
if (res) { |
|||
this.edgeService.unassignEdgeFromCustomer(edge.id.id).subscribe( |
|||
() => { |
|||
this.config.table.updateData(); |
|||
} |
|||
); |
|||
} |
|||
} |
|||
); |
|||
} |
|||
|
|||
unassignEdgesFromCustomer($event: Event, edges: Array<EdgeInfo>) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
this.dialogService.confirm( |
|||
this.translate.instant('edge.unassign-edge-title', {count: edges.length}), |
|||
this.translate.instant('edge.unassign-edge-text'), |
|||
this.translate.instant('action.no'), |
|||
this.translate.instant('action.yes'), |
|||
true |
|||
).subscribe((res) => { |
|||
if (res) { |
|||
const tasks: Observable<any>[] = []; |
|||
edges.forEach( |
|||
(edge) => { |
|||
tasks.push(this.edgeService.unassignEdgeFromCustomer(edge.id.id)); |
|||
} |
|||
); |
|||
forkJoin(tasks).subscribe( |
|||
() => { |
|||
this.config.table.updateData(); |
|||
} |
|||
); |
|||
} |
|||
} |
|||
); |
|||
} |
|||
|
|||
onEdgeAction(action: EntityAction<EdgeInfo>): boolean { |
|||
switch (action.action) { |
|||
case 'makePublic': |
|||
this.makePublic(action.event, action.entity); |
|||
return true; |
|||
case 'assignToCustomer': |
|||
this.assignToCustomer(action.event, [action.entity.id]); |
|||
return true; |
|||
case 'unassignFromCustomer': |
|||
this.unassignFromCustomer(action.event, action.entity); |
|||
return true; |
|||
case 'openEdgeAssets': |
|||
this.openEdgeAssets(action.event, action.entity); |
|||
return true; |
|||
case 'openEdgeDevices': |
|||
this.openEdgeDevices(action.event, action.entity); |
|||
return true; |
|||
case 'openEdgeEntityViews': |
|||
this.openEdgeEntityViews(action.event, action.entity); |
|||
return true; |
|||
case 'openEdgeDashboards': |
|||
this.openEdgeDashboards(action.event, action.entity); |
|||
return true; |
|||
case 'openEdgeRuleChains': |
|||
this.openEdgeRuleChains(action.event, action.entity); |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
///
|
|||
/// Copyright © 2016-2020 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 { CustomerId } from '@shared/models/id/customer-id'; |
|||
import { EdgeId } from '@shared/models/id/edge-id'; |
|||
import { EntitySearchQuery } from '@shared/models/relation.models'; |
|||
|
|||
export interface Edge extends BaseData<EdgeId> { |
|||
tenantId?: TenantId; |
|||
customerId?: CustomerId; |
|||
name: string; |
|||
type: string; |
|||
secret: string; |
|||
routingKey: string; |
|||
label?: string; |
|||
additionalInfo?: any; |
|||
} |
|||
|
|||
export interface EdgeInfo extends Edge { |
|||
customerTitle: string; |
|||
customerIsPublic: boolean; |
|||
// assignedCustomers?: Array<ShortCustomerInfo> //TODO: deaflynx check usage
|
|||
} |
|||
|
|||
export interface EdgeSearchQuery extends EntitySearchQuery { |
|||
edgeTypes: Array<string>; |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
///
|
|||
/// Copyright © 2016-2020 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 EdgeId implements EntityId { |
|||
entityType = EntityType.EDGE; |
|||
id: string; |
|||
constructor(id: string) { |
|||
this.id = id; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue