Commit c242446a8617b5b0eb7c89fa21be3c5f9fea0eb6

Authored by deaflynx
1 parent 3a48b90d

Fixed Edge entity view page

... ... @@ -147,8 +147,9 @@ export class DeviceService {
147 147 return this.http.post<Device>(`/api/edge/${edgeId}/device/${deviceId}`, defaultHttpOptionsFromConfig(config));
148 148 }
149 149
150   - public unassignDeviceFromEdge(deviceId: string, config?: RequestConfig) {
151   - return this.http.delete(`/api/edge/device/${deviceId}`, defaultHttpOptionsFromConfig(config));
  150 + public unassignDeviceFromEdge(edgeId: string, deviceId: string, config?: RequestConfig) {
  151 + return this.http.delete(`/api/edge/${edgeId}/device/${deviceId}`,
  152 + defaultHttpOptionsFromConfig(config));
152 153 }
153 154
154 155 public getEdgeDevices(edgeId: string, pageLink: PageLink, type: string = '',
... ...
... ... @@ -88,8 +88,9 @@ export class EntityViewService {
88 88 defaultHttpOptionsFromConfig(config));
89 89 }
90 90
91   - public unassignEntityViewFromEdge(entityViewId: string, config?: RequestConfig) {
92   - return this.http.delete(`/api/edge/entityView/${entityViewId}`, defaultHttpOptionsFromConfig(config));
  91 + public unassignEntityViewFromEdge(edgeId: string, entityViewId: string, config?: RequestConfig) {
  92 + return this.http.delete(`/api/edge/${edgeId}/entityView/${entityViewId}`,
  93 + defaultHttpOptionsFromConfig(config));
93 94 }
94 95
95 96 public getEdgeEntityViews(edgeId: string, pageLink: PageLink, type: string = '',
... ...
... ... @@ -182,7 +182,6 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
182 182 } else if (assetScope === 'edge') {
183 183 this.config.entitiesFetchFunction = pageLink =>
184 184 this.assetService.getEdgeAssets(this.edgeId, pageLink, this.config.componentsData.assetType);
185   - this.config.deleteEntity = id => this.assetService.deleteAsset(id.id);
186 185 } else {
187 186 this.config.entitiesFetchFunction = pageLink =>
188 187 this.assetService.getCustomerAssetInfos(this.customerId, pageLink, this.config.componentsData.assetType);
... ...
... ... @@ -191,7 +191,6 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
191 191 } else if (deviceScope === 'edge') {
192 192 this.config.entitiesFetchFunction = pageLink =>
193 193 this.deviceService.getEdgeDevices(this.edgeId, pageLink, this.config.componentsData.edgeType);
194   - this.config.deleteEntity = id => this.deviceService.deleteDevice(id.id);
195 194 } else {
196 195 this.config.entitiesFetchFunction = pageLink =>
197 196 this.deviceService.getCustomerDeviceInfos(this.customerId, pageLink, this.config.componentsData.deviceType);
... ... @@ -552,7 +551,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
552 551 true
553 552 ).subscribe((res) => {
554 553 if (res) {
555   - this.deviceService.unassignDeviceFromEdge(device.id.id).subscribe(
  554 + this.deviceService.unassignDeviceFromEdge(this.edgeId, device.id.id).subscribe(
556 555 () => {
557 556 this.config.table.updateData();
558 557 }
... ... @@ -577,7 +576,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
577 576 const tasks: Observable<any>[] = [];
578 577 devices.forEach(
579 578 (device) => {
580   - tasks.push(this.deviceService.unassignDeviceFromEdge(device.id.id));
  579 + tasks.push(this.deviceService.unassignDeviceFromEdge(this.edgeId, device.id.id));
581 580 }
582 581 );
583 582 forkJoin(tasks).subscribe(
... ...
... ... @@ -56,6 +56,11 @@ import { EntityViewComponent } from '@modules/home/pages/entity-view/entity-view
56 56 import { EntityViewTableHeaderComponent } from '@modules/home/pages/entity-view/entity-view-table-header.component';
57 57 import { EntityViewId } from '@shared/models/id/entity-view-id';
58 58 import { EntityViewTabsComponent } from '@home/pages/entity-view/entity-view-tabs.component';
  59 +import { EdgeService } from "@core/http/edge.service";
  60 +import {
  61 + AddEntitiesToEdgeDialogComponent,
  62 + AddEntitiesToEdgeDialogData
  63 +} from "@home/dialogs/add-entities-to-edge-dialog.component";
59 64
60 65 @Injectable()
61 66 export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig<EntityViewInfo>> {
... ... @@ -63,11 +68,13 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
63 68 private readonly config: EntityTableConfig<EntityViewInfo> = new EntityTableConfig<EntityViewInfo>();
64 69
65 70 private customerId: string;
  71 + private edgeId: string;
66 72
67 73 constructor(private store: Store<AppState>,
68 74 private broadcast: BroadcastService,
69 75 private entityViewService: EntityViewService,
70 76 private customerService: CustomerService,
  77 + private edgeService: EdgeService,
71 78 private dialogService: DialogService,
72 79 private translate: TranslateService,
73 80 private datePipe: DatePipe,
... ... @@ -111,6 +118,7 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
111 118 entityViewType: ''
112 119 };
113 120 this.customerId = routeParams.customerId;
  121 + this.edgeId = routeParams.edgeId;
114 122 return this.store.pipe(select(selectAuthUser), take(1)).pipe(
115 123 tap((authUser) => {
116 124 if (authUser.authority === Authority.CUSTOMER_USER) {
... ... @@ -128,7 +136,11 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
128 136 } else {
129 137 this.config.tableTitle = parentCustomer.title + ': ' + this.translate.instant('entity-view.entity-views');
130 138 }
131   - } else {
  139 + } else if (this.config.componentsData.entityViewScope === 'edge') {
  140 + this.edgeService.getEdge(this.edgeId).pipe(map(edge =>
  141 + this.config.tableTitle = edge.name + ': ' + this.translate.instant('entity-view.entity-views'))).subscribe();
  142 + }
  143 + else {
132 144 this.config.tableTitle = this.translate.instant('entity-view.entity-views');
133 145 }
134 146 this.config.columns = this.configureColumns(this.config.componentsData.entityViewScope);
... ... @@ -167,6 +179,9 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
167 179 this.config.entitiesFetchFunction = pageLink =>
168 180 this.entityViewService.getTenantEntityViewInfos(pageLink, this.config.componentsData.entityViewType);
169 181 this.config.deleteEntity = id => this.entityViewService.deleteEntityView(id.id);
  182 + } else if (entityViewScope === 'edge') {
  183 + this.config.entitiesFetchFunction = pageLink =>
  184 + this.entityViewService.getEdgeEntityViews(this.edgeId, pageLink, this.config.componentsData.entityViewType);
170 185 } else {
171 186 this.config.entitiesFetchFunction = pageLink =>
172 187 this.entityViewService.getCustomerEntityViewInfos(this.customerId, pageLink, this.config.componentsData.entityViewType);
... ... @@ -220,6 +235,16 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
220 235 }
221 236 );
222 237 }
  238 + if (entityViewScope === 'edge') {
  239 + actions.push(
  240 + {
  241 + name: this.translate.instant('edge.unassign-from-edge'),
  242 + icon: 'portable_wifi_off',
  243 + isEnabled: (entity) => true,
  244 + onAction: ($event, entity) => this.unassignFromEdge($event, entity)
  245 + }
  246 + );
  247 + }
223 248 return actions;
224 249 }
225 250
... ... @@ -245,6 +270,16 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
245 270 }
246 271 );
247 272 }
  273 + if (entityViewScope === 'edge') {
  274 + actions.push(
  275 + {
  276 + name: this.translate.instant('entity-view.unassign-entity-views-from-edge'),
  277 + icon: 'portable_wifi_off',
  278 + isEnabled: true,
  279 + onAction: ($event, entities) => this.unassignEntityViewsFromEdge($event, entities)
  280 + }
  281 + );
  282 + }
248 283 return actions;
249 284 }
250 285
... ... @@ -260,6 +295,16 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
260 295 }
261 296 );
262 297 }
  298 + if (entityViewScope === 'edge') {
  299 + actions.push(
  300 + {
  301 + name: this.translate.instant('entity-view.assign-new-entity-view'),
  302 + icon: 'add',
  303 + isEnabled: () => true,
  304 + onAction: ($event) => this.addEntityViewsToEdge($event)
  305 + }
  306 + );
  307 + }
263 308 return actions;
264 309 }
265 310
... ... @@ -400,4 +445,74 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
400 445 return false;
401 446 }
402 447
  448 + addEntityViewsToEdge($event: Event) {
  449 + if ($event) {
  450 + $event.stopPropagation();
  451 + }
  452 + this.dialog.open<AddEntitiesToEdgeDialogComponent, AddEntitiesToEdgeDialogData,
  453 + boolean>(AddEntitiesToEdgeDialogComponent, {
  454 + disableClose: true,
  455 + panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
  456 + data: {
  457 + edgeId: this.edgeId,
  458 + entityType: EntityType.ENTITY_VIEW
  459 + }
  460 + }).afterClosed()
  461 + .subscribe((res) => {
  462 + if (res) {
  463 + this.config.table.updateData();
  464 + }
  465 + });
  466 + }
  467 +
  468 + unassignFromEdge($event: Event, entityView: EntityViewInfo) {
  469 + if ($event) {
  470 + $event.stopPropagation();
  471 + }
  472 + this.dialogService.confirm(
  473 + this.translate.instant('entity-view.unassign-entity-view-from-edge-title', {entityViewName: entityView.name}),
  474 + this.translate.instant('entity-view.unassign-entity-view-from-edge-text'),
  475 + this.translate.instant('action.no'),
  476 + this.translate.instant('action.yes'),
  477 + true
  478 + ).subscribe((res) => {
  479 + if (res) {
  480 + this.entityViewService.unassignEntityViewFromEdge(this.edgeId, entityView.id.id).subscribe(
  481 + () => {
  482 + this.config.table.updateData();
  483 + }
  484 + );
  485 + }
  486 + }
  487 + );
  488 + }
  489 +
  490 + unassignEntityViewsFromEdge($event: Event, entityViews: Array<EntityViewInfo>) {
  491 + if ($event) {
  492 + $event.stopPropagation();
  493 + }
  494 + this.dialogService.confirm(
  495 + this.translate.instant('entity-view.unassign-entity-views-from-edge-title', {count: entityViews.length}),
  496 + this.translate.instant('entity-view.unassign-entity-views-from-edge-text'),
  497 + this.translate.instant('action.no'),
  498 + this.translate.instant('action.yes'),
  499 + true
  500 + ).subscribe((res) => {
  501 + if (res) {
  502 + const tasks: Observable<any>[] = [];
  503 + entityViews.forEach(
  504 + (entityView) => {
  505 + tasks.push(this.entityViewService.unassignEntityViewFromEdge(this.edgeId, entityView.id.id));
  506 + }
  507 + );
  508 + forkJoin(tasks).subscribe(
  509 + () => {
  510 + this.config.table.updateData();
  511 + }
  512 + );
  513 + }
  514 + }
  515 + );
  516 + }
  517 +
403 518 }
... ...
... ... @@ -984,6 +984,8 @@
984 984 "assign-to-customer": "Assign to customer",
985 985 "assign-entity-view-to-customer": "Assign Entity View(s) To Customer",
986 986 "assign-entity-view-to-customer-text": "Please select the entity views to assign to the customer",
  987 + "assign-entity-view-to-edge-title": "Assign Entity View(s) To Edge",
  988 + "assign-entity-view-to-edge-text":"Please select the entity views to assign to the edge",
987 989 "no-entity-views-text": "No entity views found",
988 990 "assign-to-customer-text": "Please select the customer to assign the entity view(s)",
989 991 "entity-view-details": "Entity view details",
... ... @@ -995,6 +997,8 @@
995 997 "unassign-from-customer": "Unassign from customer",
996 998 "unassign-entity-views": "Unassign entity views",
997 999 "unassign-entity-views-action-title": "Unassign { count, plural, 1 {1 entity view} other {# entity views} } from customer",
  1000 + "unassign-entity-view-from-edge-title": "Are you sure you want to unassign the entity view '{{entityViewName}}'?",
  1001 + "unassign-entity-view-from-edge-text": "After the confirmation the entity view will be unassigned and won't be accessible by the edge.",
998 1002 "assign-new-entity-view": "Assign new entity view",
999 1003 "delete-entity-view-title": "Are you sure you want to delete the entity view '{{entityViewName}}'?",
1000 1004 "delete-entity-view-text": "Be careful, after the confirmation the entity view and all related data will become unrecoverable.",
... ...