@c8y/ngx-components 1011.0.17 → 1011.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/assets-navigator/asset-node.service.d.ts +7 -3
  2. package/assets-navigator/c8y-ngx-components-assets-navigator.metadata.json +1 -1
  3. package/bundles/c8y-ngx-components-assets-navigator.umd.js +7 -2
  4. package/bundles/c8y-ngx-components-assets-navigator.umd.js.map +1 -1
  5. package/bundles/c8y-ngx-components-assets-navigator.umd.min.js +1 -1
  6. package/bundles/c8y-ngx-components-assets-navigator.umd.min.js.map +1 -1
  7. package/bundles/c8y-ngx-components-child-devices.umd.js +416 -0
  8. package/bundles/c8y-ngx-components-child-devices.umd.js.map +1 -0
  9. package/bundles/c8y-ngx-components-child-devices.umd.min.js +16 -0
  10. package/bundles/c8y-ngx-components-child-devices.umd.min.js.map +1 -0
  11. package/bundles/c8y-ngx-components-device-grid.umd.js +169 -36
  12. package/bundles/c8y-ngx-components-device-grid.umd.js.map +1 -1
  13. package/bundles/c8y-ngx-components-device-grid.umd.min.js +2 -2
  14. package/bundles/c8y-ngx-components-device-grid.umd.min.js.map +1 -1
  15. package/bundles/c8y-ngx-components-sub-assets.umd.js +5 -3
  16. package/bundles/c8y-ngx-components-sub-assets.umd.js.map +1 -1
  17. package/bundles/c8y-ngx-components-sub-assets.umd.min.js +1 -1
  18. package/bundles/c8y-ngx-components-sub-assets.umd.min.js.map +1 -1
  19. package/bundles/c8y-ngx-components.umd.js +2 -7
  20. package/bundles/c8y-ngx-components.umd.js.map +1 -1
  21. package/bundles/c8y-ngx-components.umd.min.js +1 -1
  22. package/bundles/c8y-ngx-components.umd.min.js.map +1 -1
  23. package/c8y-ngx-components.metadata.json +1 -1
  24. package/child-devices/c8y-ngx-components-child-devices.d.ts +5 -0
  25. package/child-devices/c8y-ngx-components-child-devices.metadata.json +1 -0
  26. package/child-devices/child-devices.component.d.ts +9 -0
  27. package/child-devices/child-devices.guard.d.ts +7 -0
  28. package/child-devices/child-devices.module.d.ts +2 -0
  29. package/child-devices/index.d.ts +2 -0
  30. package/child-devices/package.json +11 -0
  31. package/core/login/totp-auth.component.d.ts +1 -1
  32. package/device-grid/c8y-ngx-components-device-grid.metadata.json +1 -1
  33. package/device-grid/device-grid.component.d.ts +18 -4
  34. package/device-grid/device-grid.service.d.ts +8 -3
  35. package/esm2015/assets-navigator/asset-node.service.js +8 -3
  36. package/esm2015/child-devices/c8y-ngx-components-child-devices.js +6 -0
  37. package/esm2015/child-devices/child-devices.component.js +30 -0
  38. package/esm2015/child-devices/child-devices.guard.js +30 -0
  39. package/esm2015/child-devices/child-devices.module.js +36 -0
  40. package/esm2015/child-devices/index.js +3 -0
  41. package/esm2015/core/login/totp-auth.component.js +3 -4
  42. package/esm2015/device-grid/device-grid.component.js +62 -15
  43. package/esm2015/device-grid/device-grid.service.js +59 -22
  44. package/esm2015/sub-assets/sub-assets.service.js +7 -5
  45. package/fesm2015/c8y-ngx-components-assets-navigator.js +7 -2
  46. package/fesm2015/c8y-ngx-components-assets-navigator.js.map +1 -1
  47. package/fesm2015/c8y-ngx-components-child-devices.js +96 -0
  48. package/fesm2015/c8y-ngx-components-child-devices.js.map +1 -0
  49. package/fesm2015/c8y-ngx-components-device-grid.js +118 -35
  50. package/fesm2015/c8y-ngx-components-device-grid.js.map +1 -1
  51. package/fesm2015/c8y-ngx-components-sub-assets.js +6 -4
  52. package/fesm2015/c8y-ngx-components-sub-assets.js.map +1 -1
  53. package/fesm2015/c8y-ngx-components.js +2 -3
  54. package/fesm2015/c8y-ngx-components.js.map +1 -1
  55. package/locales/locales.pot +6 -0
  56. package/package.json +2 -2
  57. package/sub-assets/c8y-ngx-components-sub-assets.metadata.json +1 -1
  58. package/sub-assets/sub-assets.service.d.ts +3 -2
@@ -1,9 +1,9 @@
1
1
  import { __awaiter } from 'tslib';
2
2
  import { Directive, ElementRef, Injector, Input, Component, ViewChild, forwardRef, HostListener, Inject, Injectable, EventEmitter, Output, NgModule } from '@angular/core';
3
3
  import { QueriesUtil, InventoryService } from '@c8y/client';
4
+ import { FilteringFormRendererContext, CellRendererContext, gettext, SendStatus, PushStatus, Status, AlertService, ModalService, FilteringActionType, DataGridComponent, CommonModule, FormsModule, DeviceStatusModule, DataGridModule } from '@c8y/ngx-components';
4
5
  import { TranslateService } from '@ngx-translate/core';
5
6
  import { cloneDeep, get, map, sortBy, remove, transform, identity, assign, forEach } from 'lodash-es';
6
- import { FilteringFormRendererContext, CellRendererContext, gettext, SendStatus, PushStatus, FilteringActionType, DataGridComponent, CommonModule, FormsModule, DeviceStatusModule, DataGridModule } from '@c8y/ngx-components';
7
7
  import { UpgradeComponent } from '@angular/upgrade/static';
8
8
  import { AssetSelectorModule } from '@c8y/ngx-components/assets-navigator';
9
9
 
@@ -887,9 +887,11 @@ class SystemIdDeviceGridColumn extends BaseDeviceGridColumn {
887
887
  }
888
888
 
889
889
  class DeviceGridService {
890
- constructor(inventoryService, translateService) {
890
+ constructor(inventoryService, translateService, alertService, modal) {
891
891
  this.inventoryService = inventoryService;
892
892
  this.translateService = translateService;
893
+ this.alertService = alertService;
894
+ this.modal = modal;
893
895
  this.GRID_CONFIG_DEFAULT_STORAGE_KEY = 'device-grid-config';
894
896
  this.DEFAULT_PAGE_SIZE = 20;
895
897
  this.queriesUtil = new QueriesUtil();
@@ -904,28 +906,28 @@ class DeviceGridService {
904
906
  new RegistrationDateDeviceGridColumn(),
905
907
  new SystemIdDeviceGridColumn(),
906
908
  new ImeiDeviceGridColumn(),
907
- new AlarmsDeviceGridColumn()
909
+ new AlarmsDeviceGridColumn(),
908
910
  ];
909
911
  return defaultColumns;
910
912
  }
911
913
  getDefaultPagination() {
912
914
  return {
913
915
  pageSize: 10,
914
- currentPage: 1
916
+ currentPage: 1,
915
917
  };
916
918
  }
917
919
  getInfiniteScrollPagination() {
918
920
  return {
919
921
  pageSize: 50,
920
- currentPage: 1
922
+ currentPage: 1,
921
923
  };
922
924
  }
923
925
  getDefaultActionControls() {
924
926
  return [
925
927
  {
926
928
  type: "DELETE" /* Delete */,
927
- callback: (item) => this.delete(item)
928
- }
929
+ callback: (item) => this.delete(item),
930
+ },
929
931
  ];
930
932
  }
931
933
  getDefaultBulkActionControls() {
@@ -968,9 +970,9 @@ class DeviceGridService {
968
970
  const reOrderedColumns = [];
969
971
  let noConfigColumns = [];
970
972
  try {
971
- noConfigColumns = columns.filter(col => !config.columns.includes(col));
973
+ noConfigColumns = columns.filter((col) => !config.columns.includes(col));
972
974
  config.columns.forEach(({ visible, name, sortOrder }) => {
973
- const columnToReorder = columns.find(col => col.name === name);
975
+ const columnToReorder = columns.find((col) => col.name === name);
974
976
  if (columnToReorder) {
975
977
  columnToReorder.visible = visible;
976
978
  columnToReorder.sortOrder = sortOrder;
@@ -986,7 +988,19 @@ class DeviceGridService {
986
988
  return columns;
987
989
  }
988
990
  delete(device) {
989
- console.log('should delete', device);
991
+ return __awaiter(this, void 0, void 0, function* () {
992
+ try {
993
+ yield this.modal.confirm(gettext('Delete device'), this.translateService.instant(gettext(`You are about to delete device: "{{ name }}". Do you want to proceed?`), { name: device.name }), Status.DANGER, { ok: gettext('Delete'), cancel: gettext('Cancel') });
994
+ yield this.inventoryService.delete(device);
995
+ this.alertService.success(gettext('Device deleted.'));
996
+ }
997
+ catch (ex) {
998
+ // only if not cancel from modal
999
+ if (ex) {
1000
+ this.alertService.addServerFailure(ex);
1001
+ }
1002
+ }
1003
+ });
990
1004
  }
991
1005
  getData(columns, pagination, query = {}, withChildren = false) {
992
1006
  return __awaiter(this, void 0, void 0, function* () {
@@ -994,18 +1008,42 @@ class DeviceGridService {
994
1008
  return this.inventoryService.list(filters);
995
1009
  });
996
1010
  }
1011
+ getChildDeviceData(columns, pagination, query = {}, withChildren = false, id) {
1012
+ return __awaiter(this, void 0, void 0, function* () {
1013
+ const childDeviceFilters = true;
1014
+ const filters = Object.assign(Object.assign({}, this.getDevicesFilters(columns, pagination, query, childDeviceFilters)), { withParents: true, withChildren });
1015
+ return this.inventoryService.childDevicesList(id, filters);
1016
+ });
1017
+ }
997
1018
  getCount(columns, pagination, query = {}) {
998
1019
  return __awaiter(this, void 0, void 0, function* () {
999
1020
  const filters = Object.assign(Object.assign({}, this.getDevicesFilters(columns, pagination, query)), { pageSize: 1, currentPage: 1 });
1000
1021
  return (yield this.inventoryService.list(filters)).paging.totalPages;
1001
1022
  });
1002
1023
  }
1024
+ getCountChildDevices(columns, pagination, query = {}, id) {
1025
+ return __awaiter(this, void 0, void 0, function* () {
1026
+ const childDeviceFilters = true;
1027
+ const filters = Object.assign(Object.assign({}, this.getDevicesFilters(columns, pagination, query, childDeviceFilters)), { pageSize: 1, currentPage: 1 });
1028
+ return (yield this.inventoryService.childDevicesList(id, filters)).paging.totalPages;
1029
+ });
1030
+ }
1031
+ getTotalChildDevices(query = {}, id) {
1032
+ return __awaiter(this, void 0, void 0, function* () {
1033
+ const filters = {
1034
+ q: this.queriesUtil.buildQuery(query),
1035
+ pageSize: 1,
1036
+ withTotalPages: true,
1037
+ };
1038
+ return (yield this.inventoryService.childDevicesList(id, filters)).paging.totalPages;
1039
+ });
1040
+ }
1003
1041
  getTotal(query = {}) {
1004
1042
  return __awaiter(this, void 0, void 0, function* () {
1005
1043
  const filters = {
1006
1044
  q: this.queriesUtil.buildQuery(query),
1007
1045
  pageSize: 1,
1008
- withTotalPages: true
1046
+ withTotalPages: true,
1009
1047
  };
1010
1048
  return (yield this.inventoryService.list(filters)).paging.totalPages;
1011
1049
  });
@@ -1040,14 +1078,10 @@ class DeviceGridService {
1040
1078
  isVendme(device) {
1041
1079
  return device.type === 'com_nsn_startups_vendme_VendingMachine';
1042
1080
  }
1043
- getDevicesFilters(columns, pagination, query) {
1044
- return {
1045
- q: this.getDeviceQueryString(columns, query),
1046
- pageSize: pagination.pageSize,
1047
- currentPage: pagination.currentPage,
1048
- withChildren: false,
1049
- withTotalPages: true
1050
- };
1081
+ getDevicesFilters(columns, pagination, query, childDeviceFilters) {
1082
+ return Object.assign(Object.assign({}, (childDeviceFilters
1083
+ ? { query: this.getDeviceQueryString(columns, query) }
1084
+ : { q: this.getDeviceQueryString(columns, query) })), { pageSize: pagination.pageSize, currentPage: pagination.currentPage, withChildren: false, withTotalPages: true });
1051
1085
  }
1052
1086
  extendQueryByColumn(query, column) {
1053
1087
  if (column.filterable && column.externalFilterQuery) {
@@ -1058,7 +1092,7 @@ class DeviceGridService {
1058
1092
  query.__filter.__and.push(queryObj);
1059
1093
  }
1060
1094
  else if (queryObj.__and && get(query, '__filter.__and')) {
1061
- queryObj.__and.map(obj => query.__filter.__and.push(obj));
1095
+ queryObj.__and.map((obj) => query.__filter.__and.push(obj));
1062
1096
  }
1063
1097
  else {
1064
1098
  assign(query.__filter, queryObj);
@@ -1066,7 +1100,7 @@ class DeviceGridService {
1066
1100
  }
1067
1101
  if (column.sortable && column.sortOrder) {
1068
1102
  const cs = {};
1069
- forEach(column.sortingConfig.pathSortingConfigs, pathSortingConfig => {
1103
+ forEach(column.sortingConfig.pathSortingConfigs, (pathSortingConfig) => {
1070
1104
  cs[pathSortingConfig.path] =
1071
1105
  (column.sortOrder === 'asc' ? 1 : -1) * (pathSortingConfig.sortOrderModifier || 1);
1072
1106
  });
@@ -1080,7 +1114,9 @@ DeviceGridService.decorators = [
1080
1114
  ];
1081
1115
  DeviceGridService.ctorParameters = () => [
1082
1116
  { type: InventoryService },
1083
- { type: TranslateService }
1117
+ { type: TranslateService },
1118
+ { type: AlertService },
1119
+ { type: ModalService }
1084
1120
  ];
1085
1121
 
1086
1122
  class DeviceGridComponent {
@@ -1091,14 +1127,20 @@ class DeviceGridComponent {
1091
1127
  this.loadingItemsLabel = gettext('Loading devices…');
1092
1128
  this.selectable = false;
1093
1129
  this.baseQuery = {};
1094
- this.showChildDevices = {};
1130
+ this.childDeviceGrid = false;
1131
+ /**
1132
+ * Determines if additional "Show child devices" toggle should be shown and in what state it should be.
1133
+ * @deprecated It's going to be replaced with a generic hook allowing to easily add custom actions in the grid header.
1134
+ */
1135
+ this.showChildDevices = { show: false, value: false };
1136
+ /** Emits an event when columns configuration changes. */
1095
1137
  this.onColumnsChange = new EventEmitter();
1096
1138
  this.onDeviceQueryStringChange = new EventEmitter();
1097
1139
  this.itemsSelect = new EventEmitter();
1098
1140
  this.onChildDevices = new EventEmitter();
1141
+ this.actionControls = [];
1099
1142
  this.columns = this.deviceGridService.getDefaultColumns();
1100
1143
  this.pagination = this.deviceGridService.getDefaultPagination();
1101
- this.actionControls = this.deviceGridService.getDefaultActionControls();
1102
1144
  this.bulkActionControls = this.deviceGridService.getDefaultBulkActionControls();
1103
1145
  this.withChildren = false;
1104
1146
  this.serverSideDataCallback = this.onDataSourceModifier.bind(this);
@@ -1139,30 +1181,69 @@ class DeviceGridComponent {
1139
1181
  this.bulkActionControls = this.deviceGridService.getDefaultBulkActionControls();
1140
1182
  }
1141
1183
  }
1184
+ ngOnInit() {
1185
+ this.setActionControls();
1186
+ }
1142
1187
  trackByName(_index, column) {
1143
1188
  return column.name;
1144
1189
  }
1145
1190
  onDataSourceModifier(dataSourceModifier) {
1146
1191
  return __awaiter(this, void 0, void 0, function* () {
1147
1192
  let serverSideDataResult;
1148
- const { res, data, paging } = yield this.deviceGridService.getData(dataSourceModifier.columns, dataSourceModifier.pagination, this.baseQuery, this.withChildren);
1149
- const filteredSize = yield this.deviceGridService.getCount(dataSourceModifier.columns, dataSourceModifier.pagination, this.baseQuery);
1150
- const size = yield this.deviceGridService.getTotal(this.baseQuery);
1193
+ let filteredSize;
1194
+ let size;
1195
+ if (this.childDeviceGrid) {
1196
+ const { res, data, paging } = yield this.deviceGridService.getChildDeviceData(dataSourceModifier.columns, dataSourceModifier.pagination, this.baseQuery, this.withChildren, this.parentDeviceId);
1197
+ filteredSize = yield this.deviceGridService.getCountChildDevices(dataSourceModifier.columns, dataSourceModifier.pagination, this.baseQuery, this.parentDeviceId);
1198
+ size = yield this.deviceGridService.getTotalChildDevices(this.baseQuery, this.parentDeviceId);
1199
+ serverSideDataResult = {
1200
+ res,
1201
+ data,
1202
+ paging,
1203
+ filteredSize,
1204
+ size,
1205
+ };
1206
+ }
1207
+ else {
1208
+ const { res, data, paging } = yield this.deviceGridService.getData(dataSourceModifier.columns, dataSourceModifier.pagination, this.baseQuery, this.withChildren);
1209
+ filteredSize = yield this.deviceGridService.getCount(dataSourceModifier.columns, dataSourceModifier.pagination, this.baseQuery);
1210
+ size = yield this.deviceGridService.getTotal(this.baseQuery);
1211
+ serverSideDataResult = {
1212
+ res,
1213
+ data,
1214
+ paging,
1215
+ filteredSize,
1216
+ size,
1217
+ };
1218
+ }
1151
1219
  this.onColumnsChange.emit(dataSourceModifier.columns);
1152
1220
  this.onDeviceQueryStringChange.emit(this.deviceGridService.getDeviceQueryString(dataSourceModifier.columns, this.baseQuery));
1153
- serverSideDataResult = {
1154
- res,
1155
- data,
1156
- paging,
1157
- filteredSize,
1158
- size
1159
- };
1160
1221
  if (this.dataCallback) {
1161
1222
  serverSideDataResult = this.dataCallback(serverSideDataResult);
1162
1223
  }
1163
1224
  return serverSideDataResult;
1164
1225
  });
1165
1226
  }
1227
+ setActionControls() {
1228
+ return __awaiter(this, void 0, void 0, function* () {
1229
+ if (this.childDeviceGrid) {
1230
+ const deleteAction = {
1231
+ type: "DELETE" /* Delete */,
1232
+ callback: (device) => this.onDeleteDevice(device),
1233
+ };
1234
+ this.actionControls.push(deleteAction);
1235
+ }
1236
+ else {
1237
+ this.actionControls = this.deviceGridService.getDefaultActionControls();
1238
+ }
1239
+ });
1240
+ }
1241
+ onDeleteDevice(device) {
1242
+ return __awaiter(this, void 0, void 0, function* () {
1243
+ yield this.deviceGridService.delete(device);
1244
+ this.refresh.emit();
1245
+ });
1246
+ }
1166
1247
  updateFiltering(columnNames, action) {
1167
1248
  const { type } = action;
1168
1249
  if (type === FilteringActionType.ResetFilter) {
@@ -1179,7 +1260,7 @@ class DeviceGridComponent {
1179
1260
  DeviceGridComponent.decorators = [
1180
1261
  { type: Component, args: [{
1181
1262
  selector: 'c8y-device-grid',
1182
- template: "<c8y-data-grid\n [title]=\"title\"\n [loadMoreItemsLabel]=\"loadMoreItemsLabel\"\n [loadingItemsLabel]=\"loadingItemsLabel\"\n [columns]=\"columns\"\n [pagination]=\"pagination\"\n [infiniteScroll]=\"infiniteScroll\"\n [actionControls]=\"actionControls\"\n [selectable]=\"selectable\"\n [bulkActionControls]=\"bulkActionControls\"\n [serverSideDataCallback]=\"serverSideDataCallback\"\n (itemsSelect)=\"itemsSelect.emit($event)\"\n (onConfigChange)=\"configChange($event)\"\n [refresh]=\"refresh\"\n [showChildDevices]=\"showChildDevices\"\n (onChildDevices)=\"withChildren=$event;onChildDevices.emit($event)\"\n>\n <div class=\"c8y-empty-state\">\n <h1 c8yIcon=\"search\"></h1>\n <div>\n <p>\n <strong>{{ 'No matching devices.' | translate }}</strong>\n </p>\n <small>{{ 'Refine your search terms' | translate }}</small>\n </div>\n </div>\n <ng-container *ngFor=\"let column of columns; trackBy: trackByName\">\n <c8y-column [name]=\"column.name\"></c8y-column>\n </ng-container>\n</c8y-data-grid>\n"
1263
+ template: "<c8y-data-grid\n [title]=\"title\"\n [loadMoreItemsLabel]=\"loadMoreItemsLabel\"\n [loadingItemsLabel]=\"loadingItemsLabel\"\n [columns]=\"columns\"\n [pagination]=\"pagination\"\n [infiniteScroll]=\"infiniteScroll\"\n [actionControls]=\"actionControls\"\n [selectable]=\"selectable\"\n [bulkActionControls]=\"bulkActionControls\"\n [serverSideDataCallback]=\"serverSideDataCallback\"\n (itemsSelect)=\"itemsSelect.emit($event)\"\n (onConfigChange)=\"configChange($event)\"\n [refresh]=\"refresh\"\n [showChildDevices]=\"showChildDevices\"\n (onChildDevices)=\"withChildren = $event; onChildDevices.emit($event)\"\n>\n <div class=\"c8y-empty-state\">\n <h1 c8yIcon=\"search\"></h1>\n <div>\n <p>\n <strong>{{ 'No matching devices.' | translate }}</strong>\n </p>\n <small>{{ 'Refine your search terms' | translate }}</small>\n </div>\n </div>\n <ng-container *ngFor=\"let column of columns; trackBy: trackByName\">\n <c8y-column [name]=\"column.name\"></c8y-column>\n </ng-container>\n</c8y-data-grid>\n"
1183
1264
  },] }
1184
1265
  ];
1185
1266
  DeviceGridComponent.ctorParameters = () => [
@@ -1198,6 +1279,8 @@ DeviceGridComponent.propDecorators = {
1198
1279
  selectable: [{ type: Input }],
1199
1280
  baseQuery: [{ type: Input }],
1200
1281
  _bulkActionControls: [{ type: Input, args: ['bulkActionControls',] }],
1282
+ childDeviceGrid: [{ type: Input }],
1283
+ parentDeviceId: [{ type: Input }],
1201
1284
  showChildDevices: [{ type: Input }],
1202
1285
  onColumnsChange: [{ type: Output }],
1203
1286
  onDeviceQueryStringChange: [{ type: Output }],