Browse Source

Fixed Edge devices page

pull/3811/head
deaflynx 6 years ago
parent
commit
3a48b90d84
  1. 8
      ui-ngx/src/app/core/http/asset.service.ts
  2. 10
      ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.ts
  3. 75
      ui-ngx/src/app/modules/home/pages/asset/assets-table-config.resolver.ts
  4. 115
      ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts
  5. 1
      ui-ngx/src/app/shared/models/asset.models.ts
  6. 11
      ui-ngx/src/assets/locale/locale.constant-en_US.json

8
ui-ngx/src/app/core/http/asset.service.ts

@ -90,11 +90,13 @@ export class AssetService {
} }
public assignAssetToEdge(edgeId: string, assetId: string, config?: RequestConfig): Observable<Asset> { public assignAssetToEdge(edgeId: string, assetId: string, config?: RequestConfig): Observable<Asset> {
return this.http.post<Asset>(`/api/edge/${edgeId}/asset/${assetId}`, null, defaultHttpOptionsFromConfig(config)); return this.http.post<Asset>(`/api/edge/${edgeId}/asset/${assetId}`, null,
defaultHttpOptionsFromConfig(config));
} }
public unassignAssetFromEdge(assetId: string, config?: RequestConfig) { public unassignAssetFromEdge(edgeId: string, assetId: string,
return this.http.delete(`/api/edge/asset/${assetId}`, defaultHttpOptionsFromConfig(config)); config?: RequestConfig) {
return this.http.delete(`/api/edge/${edgeId}/asset/${assetId}`, defaultHttpOptionsFromConfig(config));
} }
public getEdgeAssets(edgeId, pageLink: PageLink, type: string = '', public getEdgeAssets(edgeId, pageLink: PageLink, type: string = '',

10
ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.ts

@ -76,23 +76,23 @@ export class AddEntitiesToEdgeDialogComponent extends
}); });
switch (this.data.entityType) { switch (this.data.entityType) {
case EntityType.DEVICE: case EntityType.DEVICE:
this.assignToEdgeTitle = 'device.assign-device-to-edge'; this.assignToEdgeTitle = 'device.assign-device-to-edge-title';
this.assignToEdgeText = 'device.assign-device-to-edge-text'; this.assignToEdgeText = 'device.assign-device-to-edge-text';
break; break;
case EntityType.RULE_CHAIN: case EntityType.RULE_CHAIN:
this.assignToEdgeTitle = 'rulechain.assign-rulechain-to-edge'; this.assignToEdgeTitle = 'rulechain.assign-rulechain-to-edge-title';
this.assignToEdgeText = 'rulechain.assign-rulechain-to-edge-text'; this.assignToEdgeText = 'rulechain.assign-rulechain-to-edge-text';
break; break;
case EntityType.ASSET: case EntityType.ASSET:
this.assignToEdgeTitle = 'asset.assign-asset-to-edge'; this.assignToEdgeTitle = 'asset.assign-asset-to-edge-title';
this.assignToEdgeText = 'asset.assign-asset-to-edge-text'; this.assignToEdgeText = 'asset.assign-asset-to-edge-text';
break; break;
case EntityType.ENTITY_VIEW: case EntityType.ENTITY_VIEW:
this.assignToEdgeTitle = 'entity-view.assign-entity-view-to-edge'; this.assignToEdgeTitle = 'entity-view.assign-entity-view-to-edge-title';
this.assignToEdgeText = 'entity-view.assign-entity-view-to-edge-text'; this.assignToEdgeText = 'entity-view.assign-entity-view-to-edge-text';
break; break;
case EntityType.DASHBOARD: case EntityType.DASHBOARD:
this.assignToEdgeTitle = 'dashboard.assign-dashboard-to-edge'; this.assignToEdgeTitle = 'dashboard.assign-dashboard-to-edge-title';
this.assignToEdgeText = 'dashboard.assign-dashboard-to-edge-text'; this.assignToEdgeText = 'dashboard.assign-dashboard-to-edge-text';
break; break;
} }

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

@ -136,13 +136,10 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
} else { } else {
this.config.tableTitle = parentCustomer.title + ': ' + this.translate.instant('asset.assets'); this.config.tableTitle = parentCustomer.title + ': ' + this.translate.instant('asset.assets');
} }
} else if (this.edgeId) { // TODO: deaflynx: find better way - out of parentCustomer map } else if (this.config.componentsData.assetScope === 'edge') {
this.edgeService.getEdge(this.edgeId) this.edgeService.getEdge(this.edgeId).pipe(map(edge =>
.pipe(map(edge => this.config.tableTitle = edge.name + ': ' + this.translate.instant('asset.assets'))).subscribe();
this.config.tableTitle = edge.name + ': ' + this.translate.instant('asset.assets') ), } else {
).subscribe();
}
else {
this.config.tableTitle = this.translate.instant('asset.assets'); this.config.tableTitle = this.translate.instant('asset.assets');
} }
this.config.columns = this.configureColumns(this.config.componentsData.assetScope); this.config.columns = this.configureColumns(this.config.componentsData.assetScope);
@ -242,9 +239,9 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
if (assetScope === 'edge') { if (assetScope === 'edge') {
actions.push( actions.push(
{ {
name: this.translate.instant('asset.unassign-from-edge'), name: this.translate.instant('edge.unassign-from-edge'),
icon: 'portable_wifi_off', icon: 'portable_wifi_off',
isEnabled: (entity) => (entity.edgeId && entity.edgeId.id !== NULL_UUID), isEnabled: (entity) => true,
onAction: ($event, entity) => this.unassignFromEdge($event, entity) onAction: ($event, entity) => this.unassignFromEdge($event, entity)
} }
); );
@ -264,23 +261,23 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
} }
); );
} }
if (assetScope === 'edge') { if (assetScope === 'customer') {
actions.push( actions.push(
{ {
name: this.translate.instant('asset.unassign-assets-from-edge'), name: this.translate.instant('asset.unassign-assets'),
icon: 'portable_wifi_off', icon: 'assignment_return',
isEnabled: true, isEnabled: true,
onAction: ($event, entities) => this.unassignAssetsFromEdge($event, entities) onAction: ($event, entities) => this.unassignAssetsFromCustomer($event, entities)
} }
); );
} }
if (assetScope === 'customer') { if (assetScope === 'edge') {
actions.push( actions.push(
{ {
name: this.translate.instant('asset.unassign-assets'), name: this.translate.instant('asset.unassign-assets-from-edge'),
icon: 'assignment_return', icon: 'portable_wifi_off',
isEnabled: true, isEnabled: true,
onAction: ($event, entities) => this.unassignAssetsFromCustomer($event, entities) onAction: ($event, entities) => this.unassignAssetsFromEdge($event, entities)
} }
); );
} }
@ -357,26 +354,6 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
}); });
} }
addAssetsToEdge($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.ASSET
}
}).afterClosed()
.subscribe((res) => {
if (res) {
this.config.table.updateData();
}
});
}
makePublic($event: Event, asset: Asset) { makePublic($event: Event, asset: Asset) {
if ($event) { if ($event) {
$event.stopPropagation(); $event.stopPropagation();
@ -494,6 +471,26 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
return false; return false;
} }
addAssetsToEdge($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.ASSET
}
}).afterClosed()
.subscribe((res) => {
if (res) {
this.config.table.updateData();
}
});
}
unassignFromEdge($event: Event, asset: AssetInfo) { unassignFromEdge($event: Event, asset: AssetInfo) {
if ($event) { if ($event) {
$event.stopPropagation(); $event.stopPropagation();
@ -506,7 +503,7 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
true true
).subscribe((res) => { ).subscribe((res) => {
if (res) { if (res) {
this.assetService.unassignAssetFromEdge(asset.id.id).subscribe( this.assetService.unassignAssetFromEdge(this.edgeId, asset.id.id).subscribe(
() => { () => {
this.config.table.updateData(); this.config.table.updateData();
} }
@ -531,7 +528,7 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
const tasks: Observable<any>[] = []; const tasks: Observable<any>[] = [];
assets.forEach( assets.forEach(
(asset) => { (asset) => {
tasks.push(this.assetService.unassignAssetFromEdge(asset.id.id)); tasks.push(this.assetService.unassignAssetFromEdge(this.edgeId, asset.id.id));
} }
); );
forkJoin(tasks).subscribe( forkJoin(tasks).subscribe(

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

@ -61,6 +61,11 @@ import {
} from '../../dialogs/add-entities-to-customer-dialog.component'; } from '../../dialogs/add-entities-to-customer-dialog.component';
import { DeviceTabsComponent } from '@home/pages/device/device-tabs.component'; import { DeviceTabsComponent } from '@home/pages/device/device-tabs.component';
import { HomeDialogsService } from '@home/dialogs/home-dialogs.service'; import { HomeDialogsService } from '@home/dialogs/home-dialogs.service';
import { EdgeService } from "@core/http/edge.service";
import {
AddEntitiesToEdgeDialogComponent,
AddEntitiesToEdgeDialogData
} from "@home/dialogs/add-entities-to-edge-dialog.component";
@Injectable() @Injectable()
export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<DeviceInfo>> { export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<DeviceInfo>> {
@ -68,12 +73,14 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
private readonly config: EntityTableConfig<DeviceInfo> = new EntityTableConfig<DeviceInfo>(); private readonly config: EntityTableConfig<DeviceInfo> = new EntityTableConfig<DeviceInfo>();
private customerId: string; private customerId: string;
private edgeId: string;
constructor(private store: Store<AppState>, constructor(private store: Store<AppState>,
private broadcast: BroadcastService, private broadcast: BroadcastService,
private deviceService: DeviceService, private deviceService: DeviceService,
private customerService: CustomerService, private customerService: CustomerService,
private dialogService: DialogService, private dialogService: DialogService,
private edgeService: EdgeService,
private homeDialogs: HomeDialogsService, private homeDialogs: HomeDialogsService,
private translate: TranslateService, private translate: TranslateService,
private datePipe: DatePipe, private datePipe: DatePipe,
@ -114,6 +121,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
deviceType: '' deviceType: ''
}; };
this.customerId = routeParams.customerId; this.customerId = routeParams.customerId;
this.edgeId = routeParams.edgeId;
return this.store.pipe(select(selectAuthUser), take(1)).pipe( return this.store.pipe(select(selectAuthUser), take(1)).pipe(
tap((authUser) => { tap((authUser) => {
if (authUser.authority === Authority.CUSTOMER_USER) { if (authUser.authority === Authority.CUSTOMER_USER) {
@ -131,6 +139,9 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
} else { } else {
this.config.tableTitle = parentCustomer.title + ': ' + this.translate.instant('device.devices'); this.config.tableTitle = parentCustomer.title + ': ' + this.translate.instant('device.devices');
} }
} else if (this.config.componentsData.deviceScope === 'edge') {
this.edgeService.getEdge(this.edgeId).pipe(map(edge =>
this.config.tableTitle = edge.name + ': ' + this.translate.instant('device.devices'))).subscribe();
} else { } else {
this.config.tableTitle = this.translate.instant('device.devices'); this.config.tableTitle = this.translate.instant('device.devices');
} }
@ -177,6 +188,10 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
this.config.entitiesFetchFunction = pageLink => this.config.entitiesFetchFunction = pageLink =>
this.deviceService.getTenantDeviceInfos(pageLink, this.config.componentsData.deviceType); this.deviceService.getTenantDeviceInfos(pageLink, this.config.componentsData.deviceType);
this.config.deleteEntity = id => this.deviceService.deleteDevice(id.id); this.config.deleteEntity = id => this.deviceService.deleteDevice(id.id);
} 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 { } else {
this.config.entitiesFetchFunction = pageLink => this.config.entitiesFetchFunction = pageLink =>
this.deviceService.getCustomerDeviceInfos(this.customerId, pageLink, this.config.componentsData.deviceType); this.deviceService.getCustomerDeviceInfos(this.customerId, pageLink, this.config.componentsData.deviceType);
@ -252,6 +267,16 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
} }
); );
} }
if (deviceScope === '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; return actions;
} }
@ -277,6 +302,16 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
} }
); );
} }
if (deviceScope === 'edge') {
actions.push(
{
name: this.translate.instant('asset.unassign-assets-from-edge'),
icon: 'portable_wifi_off',
isEnabled: true,
onAction: ($event, entities) => this.unassignDevicesFromCustomer($event, entities)
}
);
}
return actions; return actions;
} }
@ -308,6 +343,16 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
} }
); );
} }
if (deviceScope === 'edge') {
actions.push(
{
name: this.translate.instant('device.assign-new-device'),
icon: 'add',
isEnabled: () => true,
onAction: ($event) => this.addDevicesToEdge($event)
}
);
}
return actions; return actions;
} }
@ -475,4 +520,74 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
return false; return false;
} }
addDevicesToEdge($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.DEVICE
}
}).afterClosed()
.subscribe((res) => {
if (res) {
this.config.table.updateData();
}
});
}
unassignFromEdge($event: Event, device: DeviceInfo) {
if ($event) {
$event.stopPropagation();
}
this.dialogService.confirm(
this.translate.instant('device.unassign-device-from-edge-title', {deviceName: device.name}),
this.translate.instant('device.unassign-device-from-edge-text'),
this.translate.instant('action.no'),
this.translate.instant('action.yes'),
true
).subscribe((res) => {
if (res) {
this.deviceService.unassignDeviceFromEdge(device.id.id).subscribe(
() => {
this.config.table.updateData();
}
);
}
}
);
}
unassignDevicesFromEdge($event: Event, devices: Array<DeviceInfo>) {
if ($event) {
$event.stopPropagation();
}
this.dialogService.confirm(
this.translate.instant('device.unassign-devices-from-edge-title', {count: devices.length}),
this.translate.instant('device.unassign-devices-from-edge-text'),
this.translate.instant('action.no'),
this.translate.instant('action.yes'),
true
).subscribe((res) => {
if (res) {
const tasks: Observable<any>[] = [];
devices.forEach(
(device) => {
tasks.push(this.deviceService.unassignDeviceFromEdge(device.id.id));
}
);
forkJoin(tasks).subscribe(
() => {
this.config.table.updateData();
}
);
}
}
);
}
} }

1
ui-ngx/src/app/shared/models/asset.models.ts

@ -24,7 +24,6 @@ import { EdgeId } from "@shared/models/id/edge-id";
export interface Asset extends BaseData<AssetId> { export interface Asset extends BaseData<AssetId> {
tenantId?: TenantId; tenantId?: TenantId;
customerId?: CustomerId; customerId?: CustomerId;
edgeId?: EdgeId; //TODO: deaflynx: "edgeId?" ?
name: string; name: string;
type: string; type: string;
label: string; label: string;

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

@ -266,6 +266,8 @@
"asset-details": "Asset details", "asset-details": "Asset details",
"assign-assets": "Assign assets", "assign-assets": "Assign assets",
"assign-assets-text": "Assign { count, plural, 1 {1 asset} other {# assets} } to customer", "assign-assets-text": "Assign { count, plural, 1 {1 asset} other {# assets} } to customer",
"assign-asset-to-edge-title": "Assign Asset(s) To Edge",
"assign-asset-to-edge-text":"Please select the assets to assign to the edge",
"delete-assets": "Delete assets", "delete-assets": "Delete assets",
"unassign-assets": "Unassign assets", "unassign-assets": "Unassign assets",
"unassign-assets-action-title": "Unassign { count, plural, 1 {1 asset} other {# assets} } from customer", "unassign-assets-action-title": "Unassign { count, plural, 1 {1 asset} other {# assets} } from customer",
@ -284,6 +286,11 @@
"unassign-asset": "Unassign asset", "unassign-asset": "Unassign asset",
"unassign-assets-title": "Are you sure you want to unassign { count, plural, 1 {1 asset} other {# assets} }?", "unassign-assets-title": "Are you sure you want to unassign { count, plural, 1 {1 asset} other {# assets} }?",
"unassign-assets-text": "After the confirmation all selected assets will be unassigned and won't be accessible by the customer.", "unassign-assets-text": "After the confirmation all selected assets will be unassigned and won't be accessible by the customer.",
"unassign-asset-from-edge-title": "Are you sure you want to unassign the asset '{{assetName}}'?",
"unassign-asset-from-edge-text": "After the confirmation the asset will be unassigned and won't be accessible by the edge.",
"unassign-assets-from-edge": "Unassign assets from edge",
"unassign-assets-from-edge-title": "Are you sure you want to unassign { count, plural, 1 {1 asset} other {# assets} }?",
"unassign-assets-from-edge-text": "After the confirmation all selected assets will be unassigned and won't be accessible by the edge.",
"copyId": "Copy asset Id", "copyId": "Copy asset Id",
"idCopiedMessage": "Asset Id has been copied to clipboard", "idCopiedMessage": "Asset Id has been copied to clipboard",
"select-asset": "Select asset", "select-asset": "Select asset",
@ -669,6 +676,8 @@
"assign-to-customer": "Assign to customer", "assign-to-customer": "Assign to customer",
"assign-device-to-customer": "Assign Device(s) To Customer", "assign-device-to-customer": "Assign Device(s) To Customer",
"assign-device-to-customer-text": "Please select the devices to assign to the customer", "assign-device-to-customer-text": "Please select the devices to assign to the customer",
"assign-device-to-edge-title": "Assign Device(s) To Edge",
"assign-device-to-edge-text":"Please select the devices to assign to the edge",
"make-public": "Make device public", "make-public": "Make device public",
"make-private": "Make device private", "make-private": "Make device private",
"no-devices-text": "No devices found", "no-devices-text": "No devices found",
@ -684,6 +693,8 @@
"unassign-from-customer": "Unassign from customer", "unassign-from-customer": "Unassign from customer",
"unassign-devices": "Unassign devices", "unassign-devices": "Unassign devices",
"unassign-devices-action-title": "Unassign { count, plural, 1 {1 device} other {# devices} } from customer", "unassign-devices-action-title": "Unassign { count, plural, 1 {1 device} other {# devices} } from customer",
"unassign-device-from-edge-title": "Are you sure you want to unassign the device '{{deviceName}}'?",
"unassign-device-from-edge-text": "After the confirmation the device will be unassigned and won't be accessible by the edge.",
"assign-new-device": "Assign new device", "assign-new-device": "Assign new device",
"make-public-device-title": "Are you sure you want to make the device '{{deviceName}}' public?", "make-public-device-title": "Are you sure you want to make the device '{{deviceName}}' public?",
"make-public-device-text": "After the confirmation the device and all its data will be made public and accessible by others.", "make-public-device-text": "After the confirmation the device and all its data will be made public and accessible by others.",

Loading…
Cancel
Save