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> {
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) {
return this.http.delete(`/api/edge/asset/${assetId}`, defaultHttpOptionsFromConfig(config));
public unassignAssetFromEdge(edgeId: string, assetId: string,
config?: RequestConfig) {
return this.http.delete(`/api/edge/${edgeId}/asset/${assetId}`, defaultHttpOptionsFromConfig(config));
}
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) {
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';
break;
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';
break;
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';
break;
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';
break;
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';
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 {
this.config.tableTitle = parentCustomer.title + ': ' + this.translate.instant('asset.assets');
}
} else if (this.edgeId) { // TODO: deaflynx: find better way - out of parentCustomer map
this.edgeService.getEdge(this.edgeId)
.pipe(map(edge =>
this.config.tableTitle = edge.name + ': ' + this.translate.instant('asset.assets') ),
).subscribe();
}
else {
} else if (this.config.componentsData.assetScope === 'edge') {
this.edgeService.getEdge(this.edgeId).pipe(map(edge =>
this.config.tableTitle = edge.name + ': ' + this.translate.instant('asset.assets'))).subscribe();
} else {
this.config.tableTitle = this.translate.instant('asset.assets');
}
this.config.columns = this.configureColumns(this.config.componentsData.assetScope);
@ -242,9 +239,9 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
if (assetScope === 'edge') {
actions.push(
{
name: this.translate.instant('asset.unassign-from-edge'),
name: this.translate.instant('edge.unassign-from-edge'),
icon: 'portable_wifi_off',
isEnabled: (entity) => (entity.edgeId && entity.edgeId.id !== NULL_UUID),
isEnabled: (entity) => true,
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(
{
name: this.translate.instant('asset.unassign-assets-from-edge'),
icon: 'portable_wifi_off',
name: this.translate.instant('asset.unassign-assets'),
icon: 'assignment_return',
isEnabled: true,
onAction: ($event, entities) => this.unassignAssetsFromEdge($event, entities)
onAction: ($event, entities) => this.unassignAssetsFromCustomer($event, entities)
}
);
}
if (assetScope === 'customer') {
if (assetScope === 'edge') {
actions.push(
{
name: this.translate.instant('asset.unassign-assets'),
icon: 'assignment_return',
name: this.translate.instant('asset.unassign-assets-from-edge'),
icon: 'portable_wifi_off',
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) {
if ($event) {
$event.stopPropagation();
@ -494,6 +471,26 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
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) {
if ($event) {
$event.stopPropagation();
@ -506,7 +503,7 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
true
).subscribe((res) => {
if (res) {
this.assetService.unassignAssetFromEdge(asset.id.id).subscribe(
this.assetService.unassignAssetFromEdge(this.edgeId, asset.id.id).subscribe(
() => {
this.config.table.updateData();
}
@ -531,7 +528,7 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
const tasks: Observable<any>[] = [];
assets.forEach(
(asset) => {
tasks.push(this.assetService.unassignAssetFromEdge(asset.id.id));
tasks.push(this.assetService.unassignAssetFromEdge(this.edgeId, asset.id.id));
}
);
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';
import { DeviceTabsComponent } from '@home/pages/device/device-tabs.component';
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()
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 customerId: string;
private edgeId: string;
constructor(private store: Store<AppState>,
private broadcast: BroadcastService,
private deviceService: DeviceService,
private customerService: CustomerService,
private dialogService: DialogService,
private edgeService: EdgeService,
private homeDialogs: HomeDialogsService,
private translate: TranslateService,
private datePipe: DatePipe,
@ -114,6 +121,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
deviceType: ''
};
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) {
@ -131,6 +139,9 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
} else {
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 {
this.config.tableTitle = this.translate.instant('device.devices');
}
@ -177,6 +188,10 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
this.config.entitiesFetchFunction = pageLink =>
this.deviceService.getTenantDeviceInfos(pageLink, this.config.componentsData.deviceType);
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 {
this.config.entitiesFetchFunction = pageLink =>
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;
}
@ -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;
}
@ -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;
}
@ -475,4 +520,74 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
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> {
tenantId?: TenantId;
customerId?: CustomerId;
edgeId?: EdgeId; //TODO: deaflynx: "edgeId?" ?
name: string;
type: string;
label: string;

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

@ -266,6 +266,8 @@
"asset-details": "Asset details",
"assign-assets": "Assign assets",
"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",
"unassign-assets": "Unassign assets",
"unassign-assets-action-title": "Unassign { count, plural, 1 {1 asset} other {# assets} } from customer",
@ -284,6 +286,11 @@
"unassign-asset": "Unassign asset",
"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-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",
"idCopiedMessage": "Asset Id has been copied to clipboard",
"select-asset": "Select asset",
@ -669,6 +676,8 @@
"assign-to-customer": "Assign 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-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-private": "Make device private",
"no-devices-text": "No devices found",
@ -684,6 +693,8 @@
"unassign-from-customer": "Unassign from customer",
"unassign-devices": "Unassign devices",
"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",
"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.",

Loading…
Cancel
Save