Browse Source

Fixed Edge entity view page

pull/3811/head
deaflynx 6 years ago
parent
commit
c242446a86
  1. 5
      ui-ngx/src/app/core/http/device.service.ts
  2. 5
      ui-ngx/src/app/core/http/entity-view.service.ts
  3. 1
      ui-ngx/src/app/modules/home/pages/asset/assets-table-config.resolver.ts
  4. 5
      ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts
  5. 117
      ui-ngx/src/app/modules/home/pages/entity-view/entity-views-table-config.resolver.ts
  6. 4
      ui-ngx/src/assets/locale/locale.constant-en_US.json

5
ui-ngx/src/app/core/http/device.service.ts

@ -147,8 +147,9 @@ export class DeviceService {
return this.http.post<Device>(`/api/edge/${edgeId}/device/${deviceId}`, defaultHttpOptionsFromConfig(config));
}
public unassignDeviceFromEdge(deviceId: string, config?: RequestConfig) {
return this.http.delete(`/api/edge/device/${deviceId}`, defaultHttpOptionsFromConfig(config));
public unassignDeviceFromEdge(edgeId: string, deviceId: string, config?: RequestConfig) {
return this.http.delete(`/api/edge/${edgeId}/device/${deviceId}`,
defaultHttpOptionsFromConfig(config));
}
public getEdgeDevices(edgeId: string, pageLink: PageLink, type: string = '',

5
ui-ngx/src/app/core/http/entity-view.service.ts

@ -88,8 +88,9 @@ export class EntityViewService {
defaultHttpOptionsFromConfig(config));
}
public unassignEntityViewFromEdge(entityViewId: string, config?: RequestConfig) {
return this.http.delete(`/api/edge/entityView/${entityViewId}`, defaultHttpOptionsFromConfig(config));
public unassignEntityViewFromEdge(edgeId: string, entityViewId: string, config?: RequestConfig) {
return this.http.delete(`/api/edge/${edgeId}/entityView/${entityViewId}`,
defaultHttpOptionsFromConfig(config));
}
public getEdgeEntityViews(edgeId: string, pageLink: PageLink, type: string = '',

1
ui-ngx/src/app/modules/home/pages/asset/assets-table-config.resolver.ts

@ -182,7 +182,6 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
} else if (assetScope === 'edge') {
this.config.entitiesFetchFunction = pageLink =>
this.assetService.getEdgeAssets(this.edgeId, pageLink, this.config.componentsData.assetType);
this.config.deleteEntity = id => this.assetService.deleteAsset(id.id);
} else {
this.config.entitiesFetchFunction = pageLink =>
this.assetService.getCustomerAssetInfos(this.customerId, pageLink, this.config.componentsData.assetType);

5
ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts

@ -191,7 +191,6 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
} else if (deviceScope === 'edge') {
this.config.entitiesFetchFunction = pageLink =>
this.deviceService.getEdgeDevices(this.edgeId, pageLink, this.config.componentsData.edgeType);
this.config.deleteEntity = id => this.deviceService.deleteDevice(id.id);
} else {
this.config.entitiesFetchFunction = pageLink =>
this.deviceService.getCustomerDeviceInfos(this.customerId, pageLink, this.config.componentsData.deviceType);
@ -552,7 +551,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
true
).subscribe((res) => {
if (res) {
this.deviceService.unassignDeviceFromEdge(device.id.id).subscribe(
this.deviceService.unassignDeviceFromEdge(this.edgeId, device.id.id).subscribe(
() => {
this.config.table.updateData();
}
@ -577,7 +576,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
const tasks: Observable<any>[] = [];
devices.forEach(
(device) => {
tasks.push(this.deviceService.unassignDeviceFromEdge(device.id.id));
tasks.push(this.deviceService.unassignDeviceFromEdge(this.edgeId, device.id.id));
}
);
forkJoin(tasks).subscribe(

117
ui-ngx/src/app/modules/home/pages/entity-view/entity-views-table-config.resolver.ts

@ -56,6 +56,11 @@ import { EntityViewComponent } from '@modules/home/pages/entity-view/entity-view
import { EntityViewTableHeaderComponent } from '@modules/home/pages/entity-view/entity-view-table-header.component';
import { EntityViewId } from '@shared/models/id/entity-view-id';
import { EntityViewTabsComponent } from '@home/pages/entity-view/entity-view-tabs.component';
import { EdgeService } from "@core/http/edge.service";
import {
AddEntitiesToEdgeDialogComponent,
AddEntitiesToEdgeDialogData
} from "@home/dialogs/add-entities-to-edge-dialog.component";
@Injectable()
export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig<EntityViewInfo>> {
@ -63,11 +68,13 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
private readonly config: EntityTableConfig<EntityViewInfo> = new EntityTableConfig<EntityViewInfo>();
private customerId: string;
private edgeId: string;
constructor(private store: Store<AppState>,
private broadcast: BroadcastService,
private entityViewService: EntityViewService,
private customerService: CustomerService,
private edgeService: EdgeService,
private dialogService: DialogService,
private translate: TranslateService,
private datePipe: DatePipe,
@ -111,6 +118,7 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
entityViewType: ''
};
this.customerId = routeParams.customerId;
this.edgeId = routeParams.edgeId;
return this.store.pipe(select(selectAuthUser), take(1)).pipe(
tap((authUser) => {
if (authUser.authority === Authority.CUSTOMER_USER) {
@ -128,7 +136,11 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
} else {
this.config.tableTitle = parentCustomer.title + ': ' + this.translate.instant('entity-view.entity-views');
}
} else {
} else if (this.config.componentsData.entityViewScope === 'edge') {
this.edgeService.getEdge(this.edgeId).pipe(map(edge =>
this.config.tableTitle = edge.name + ': ' + this.translate.instant('entity-view.entity-views'))).subscribe();
}
else {
this.config.tableTitle = this.translate.instant('entity-view.entity-views');
}
this.config.columns = this.configureColumns(this.config.componentsData.entityViewScope);
@ -167,6 +179,9 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
this.config.entitiesFetchFunction = pageLink =>
this.entityViewService.getTenantEntityViewInfos(pageLink, this.config.componentsData.entityViewType);
this.config.deleteEntity = id => this.entityViewService.deleteEntityView(id.id);
} else if (entityViewScope === 'edge') {
this.config.entitiesFetchFunction = pageLink =>
this.entityViewService.getEdgeEntityViews(this.edgeId, pageLink, this.config.componentsData.entityViewType);
} else {
this.config.entitiesFetchFunction = pageLink =>
this.entityViewService.getCustomerEntityViewInfos(this.customerId, pageLink, this.config.componentsData.entityViewType);
@ -220,6 +235,16 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
}
);
}
if (entityViewScope === 'edge') {
actions.push(
{
name: this.translate.instant('edge.unassign-from-edge'),
icon: 'portable_wifi_off',
isEnabled: (entity) => true,
onAction: ($event, entity) => this.unassignFromEdge($event, entity)
}
);
}
return actions;
}
@ -245,6 +270,16 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
}
);
}
if (entityViewScope === 'edge') {
actions.push(
{
name: this.translate.instant('entity-view.unassign-entity-views-from-edge'),
icon: 'portable_wifi_off',
isEnabled: true,
onAction: ($event, entities) => this.unassignEntityViewsFromEdge($event, entities)
}
);
}
return actions;
}
@ -260,6 +295,16 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
}
);
}
if (entityViewScope === 'edge') {
actions.push(
{
name: this.translate.instant('entity-view.assign-new-entity-view'),
icon: 'add',
isEnabled: () => true,
onAction: ($event) => this.addEntityViewsToEdge($event)
}
);
}
return actions;
}
@ -400,4 +445,74 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
return false;
}
addEntityViewsToEdge($event: Event) {
if ($event) {
$event.stopPropagation();
}
this.dialog.open<AddEntitiesToEdgeDialogComponent, AddEntitiesToEdgeDialogData,
boolean>(AddEntitiesToEdgeDialogComponent, {
disableClose: true,
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
data: {
edgeId: this.edgeId,
entityType: EntityType.ENTITY_VIEW
}
}).afterClosed()
.subscribe((res) => {
if (res) {
this.config.table.updateData();
}
});
}
unassignFromEdge($event: Event, entityView: EntityViewInfo) {
if ($event) {
$event.stopPropagation();
}
this.dialogService.confirm(
this.translate.instant('entity-view.unassign-entity-view-from-edge-title', {entityViewName: entityView.name}),
this.translate.instant('entity-view.unassign-entity-view-from-edge-text'),
this.translate.instant('action.no'),
this.translate.instant('action.yes'),
true
).subscribe((res) => {
if (res) {
this.entityViewService.unassignEntityViewFromEdge(this.edgeId, entityView.id.id).subscribe(
() => {
this.config.table.updateData();
}
);
}
}
);
}
unassignEntityViewsFromEdge($event: Event, entityViews: Array<EntityViewInfo>) {
if ($event) {
$event.stopPropagation();
}
this.dialogService.confirm(
this.translate.instant('entity-view.unassign-entity-views-from-edge-title', {count: entityViews.length}),
this.translate.instant('entity-view.unassign-entity-views-from-edge-text'),
this.translate.instant('action.no'),
this.translate.instant('action.yes'),
true
).subscribe((res) => {
if (res) {
const tasks: Observable<any>[] = [];
entityViews.forEach(
(entityView) => {
tasks.push(this.entityViewService.unassignEntityViewFromEdge(this.edgeId, entityView.id.id));
}
);
forkJoin(tasks).subscribe(
() => {
this.config.table.updateData();
}
);
}
}
);
}
}

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

@ -984,6 +984,8 @@
"assign-to-customer": "Assign to customer",
"assign-entity-view-to-customer": "Assign Entity View(s) To Customer",
"assign-entity-view-to-customer-text": "Please select the entity views to assign to the customer",
"assign-entity-view-to-edge-title": "Assign Entity View(s) To Edge",
"assign-entity-view-to-edge-text":"Please select the entity views to assign to the edge",
"no-entity-views-text": "No entity views found",
"assign-to-customer-text": "Please select the customer to assign the entity view(s)",
"entity-view-details": "Entity view details",
@ -995,6 +997,8 @@
"unassign-from-customer": "Unassign from customer",
"unassign-entity-views": "Unassign entity views",
"unassign-entity-views-action-title": "Unassign { count, plural, 1 {1 entity view} other {# entity views} } from customer",
"unassign-entity-view-from-edge-title": "Are you sure you want to unassign the entity view '{{entityViewName}}'?",
"unassign-entity-view-from-edge-text": "After the confirmation the entity view will be unassigned and won't be accessible by the edge.",
"assign-new-entity-view": "Assign new entity view",
"delete-entity-view-title": "Are you sure you want to delete the entity view '{{entityViewName}}'?",
"delete-entity-view-text": "Be careful, after the confirmation the entity view and all related data will become unrecoverable.",

Loading…
Cancel
Save