Commit 3ffa7e359277a22a9dcab3d0d6412f1d1853454c

Authored by Artem Babak
1 parent 04e50696

Added button unassignFromEdge for entities. Added findAssetsByTenantIdAndEdgeIdAndType()

... ... @@ -485,6 +485,7 @@ public class AssetController extends BaseController {
485 485 @PathVariable(EDGE_ID) String strEdgeId,
486 486 @RequestParam int pageSize,
487 487 @RequestParam int page,
  488 + @RequestParam(required = false) String type,
488 489 @RequestParam(required = false) String textSearch,
489 490 @RequestParam(required = false) String sortProperty,
490 491 @RequestParam(required = false) String sortOrder,
... ... @@ -496,7 +497,11 @@ public class AssetController extends BaseController {
496 497 EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
497 498 checkEdgeId(edgeId, Operation.READ);
498 499 TimePageLink pageLink = createTimePageLink(pageSize, page, textSearch, sortProperty, sortOrder, startTime, endTime);
499   - return checkNotNull(assetService.findAssetsByTenantIdAndEdgeId(tenantId, edgeId, pageLink));
  500 + if (type != null && type.trim().length() > 0) {
  501 + return checkNotNull(assetService.findAssetsByTenantIdAndEdgeIdAndType(tenantId, edgeId, type, pageLink));
  502 + } else {
  503 + return checkNotNull(assetService.findAssetsByTenantIdAndEdgeId(tenantId, edgeId, pageLink));
  504 + }
500 505 } catch (Exception e) {
501 506 throw handleException(e);
502 507 }
... ...
... ... @@ -82,4 +82,6 @@ public interface AssetService {
82 82 Asset unassignAssetFromEdge(TenantId tenantId, AssetId assetId, EdgeId edgeId);
83 83
84 84 PageData<Asset> findAssetsByTenantIdAndEdgeId(TenantId tenantId, EdgeId edgeId, TimePageLink pageLink);
  85 +
  86 + PageData<Asset> findAssetsByTenantIdAndEdgeIdAndType(TenantId tenantId, EdgeId edgeId, String type, TimePageLink pageLink);
85 87 }
... ...
... ... @@ -176,4 +176,15 @@ public interface AssetDao extends Dao<Asset> {
176 176 * @return the list of asset objects
177 177 */
178 178 PageData<Asset> findAssetsByTenantIdAndEdgeId(UUID tenantId, UUID edgeId, TimePageLink pageLink);
  179 +
  180 + /**
  181 + * Find assets by tenantId, edgeId, type and page link.
  182 + *
  183 + * @param tenantId the tenantId
  184 + * @param edgeId the edgeId
  185 + * @param type the type
  186 + * @param pageLink the page link
  187 + * @return the list of asset objects
  188 + */
  189 + PageData<Asset> findAssetsByTenantIdAndEdgeIdAndType(UUID tenantId, UUID edgeId, String type, TimePageLink pageLink);
179 190 }
... ...
... ... @@ -364,6 +364,16 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
364 364 return assetDao.findAssetsByTenantIdAndEdgeId(tenantId.getId(), edgeId.getId(), pageLink);
365 365 }
366 366
  367 + @Override
  368 + public PageData<Asset> findAssetsByTenantIdAndEdgeIdAndType(TenantId tenantId, EdgeId edgeId, String type, TimePageLink pageLink) {
  369 + log.trace("Executing findAssetsByTenantIdAndEdgeIdAndType, tenantId [{}], edgeId [{}], type [{}] pageLink [{}]", tenantId, edgeId, type, pageLink);
  370 + validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
  371 + validateId(edgeId, INCORRECT_EDGE_ID + edgeId);
  372 + validateString(type, "Incorrect type " + type);
  373 + validatePageLink(pageLink);
  374 + return assetDao.findAssetsByTenantIdAndEdgeIdAndType(tenantId.getId(), edgeId.getId(), type, pageLink);
  375 + }
  376 +
367 377 private DataValidator<Asset> assetValidator =
368 378 new DataValidator<Asset>() {
369 379
... ...
... ... @@ -132,4 +132,15 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity,
132 132 @Param("searchText") String searchText,
133 133 Pageable pageable);
134 134
  135 + @Query("SELECT a FROM AssetEntity a, RelationEntity re WHERE a.tenantId = :tenantId " +
  136 + "AND a.id = re.toId AND re.toType = 'ASSET' AND re.relationTypeGroup = 'EDGE' " +
  137 + "AND re.relationType = 'Contains' AND re.fromId = :edgeId AND re.fromType = 'EDGE' " +
  138 + "AND a.type = :type " +
  139 + "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:searchText, '%'))")
  140 + Page<AssetEntity> findByTenantIdAndEdgeIdAndType(@Param("tenantId") UUID tenantId,
  141 + @Param("edgeId") UUID edgeId,
  142 + @Param("type") String type,
  143 + @Param("searchText") String searchText,
  144 + Pageable pageable);
  145 +
135 146 }
... ...
... ... @@ -196,4 +196,16 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
196 196 Objects.toString(pageLink.getTextSearch(), ""),
197 197 DaoUtil.toPageable(pageLink)));
198 198 }
  199 +
  200 + @Override
  201 + public PageData<Asset> findAssetsByTenantIdAndEdgeIdAndType(UUID tenantId, UUID edgeId, String type, TimePageLink pageLink) {
  202 + log.debug("Try to find assets by tenantId [{}], edgeId [{}], type [{}] and pageLink [{}]", tenantId, edgeId, type, pageLink);
  203 + return DaoUtil.toPageData(assetRepository
  204 + .findByTenantIdAndEdgeIdAndType(
  205 + tenantId,
  206 + edgeId,
  207 + type,
  208 + Objects.toString(pageLink.getTextSearch(), ""),
  209 + DaoUtil.toPageable(pageLink)));
  210 + }
199 211 }
... ...
... ... @@ -99,7 +99,7 @@ export class AssetService {
99 99 return this.http.delete(`/api/edge/${edgeId}/asset/${assetId}`, defaultHttpOptionsFromConfig(config));
100 100 }
101 101
102   - public getEdgeAssets(edgeId, pageLink: PageLink, type: string = '',
  102 + public getEdgeAssets(edgeId: string, pageLink: PageLink, type: string = '',
103 103 config?: RequestConfig): Observable<PageData<AssetInfo>> {
104 104 return this.http.get<PageData<AssetInfo>>(`/api/edge/${edgeId}/assets${pageLink.toQuery()}&type=${type}`,
105 105 defaultHttpOptionsFromConfig(config));
... ...
... ... @@ -36,6 +36,12 @@
36 36 </button>
37 37 <button mat-raised-button color="primary"
38 38 [disabled]="(isLoading$ | async)"
  39 + (click)="onEntityAction($event, 'unassignFromEdge')"
  40 + [fxShow]="!isEdit && assetScope === 'edge'">
  41 + {{ 'edge.unassign-from-edge' | translate }}
  42 + </button>
  43 + <button mat-raised-button color="primary"
  44 + [disabled]="(isLoading$ | async)"
39 45 (click)="onEntityAction($event, 'delete')"
40 46 [fxShow]="!hideDelete() && !isEdit">
41 47 {{'asset.delete' | translate }}
... ...
... ... @@ -466,6 +466,9 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
466 466 case 'unassignFromCustomer':
467 467 this.unassignFromCustomer(action.event, action.entity);
468 468 return true;
  469 + case 'unassignFromEdge':
  470 + this.unassignFromEdge(action.event, action.entity);
  471 + return true;
469 472 }
470 473 return false;
471 474 }
... ...
... ... @@ -55,6 +55,12 @@
55 55 </button>
56 56 <button mat-raised-button color="primary"
57 57 [disabled]="(isLoading$ | async)"
  58 + (click)="onEntityAction($event, 'unassignFromEdge')"
  59 + [fxShow]="!isEdit && dashboardScope === 'edge'">
  60 + {{ 'edge.unassign-from-edge' | translate }}
  61 + </button>
  62 + <button mat-raised-button color="primary"
  63 + [disabled]="(isLoading$ | async)"
58 64 (click)="onEntityAction($event, 'delete')"
59 65 [fxShow]="!hideDelete() && !isEdit">
60 66 {{'dashboard.delete' | translate }}
... ...
... ... @@ -543,6 +543,9 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
543 543 case 'unassignFromCustomer':
544 544 this.unassignFromCustomer(action.event, action.entity, this.config.componentsData.customerId);
545 545 return true;
  546 + case 'unassignFromEdge':
  547 + this.unassignFromEdge(action.event, action.entity);
  548 + return true;
546 549 }
547 550 return false;
548 551 }
... ... @@ -572,7 +575,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
572 575 $event.stopPropagation();
573 576 }
574 577 this.dialogService.confirm(
575   - this.translate.instant('dashboard.unassign-dashboard-from-edge-title', {dashboardName: dashboard.name}),
  578 + this.translate.instant('dashboard.unassign-dashboard-title', {dashboardTitle: dashboard.title}),
576 579 this.translate.instant('dashboard.unassign-dashboard-from-edge-text'),
577 580 this.translate.instant('action.no'),
578 581 this.translate.instant('action.yes'),
... ...
... ... @@ -40,6 +40,12 @@
40 40 [fxShow]="!isEdit">
41 41 {{ (deviceScope === 'customer_user' ? 'device.view-credentials' : 'device.manage-credentials') | translate }}
42 42 </button>
  43 + <button mat-raised-button color="primary"
  44 + [disabled]="(isLoading$ | async)"
  45 + (click)="onEntityAction($event, 'unassignFromEdge')"
  46 + [fxShow]="!isEdit && deviceScope === 'edge'">
  47 + {{ 'edge.unassign-from-edge' | translate }}
  48 + </button>
43 49 <button mat-raised-button color="primary" fxFlex.xs
44 50 [disabled]="(isLoading$ | async)"
45 51 (click)="onEntityAction($event, 'delete')"
... ...
... ... @@ -519,6 +519,9 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
519 519 case 'unassignFromCustomer':
520 520 this.unassignFromCustomer(action.event, action.entity);
521 521 return true;
  522 + case 'unassignFromEdge':
  523 + this.unassignFromEdge(action.event, action.entity);
  524 + return true;
522 525 case 'manageCredentials':
523 526 this.manageCredentials(action.event, action.entity);
524 527 return true;
... ...
... ... @@ -36,6 +36,12 @@
36 36 </button>
37 37 <button mat-raised-button color="primary"
38 38 [disabled]="(isLoading$ | async)"
  39 + (click)="onEntityAction($event, 'unassignFromEdge')"
  40 + [fxShow]="!isEdit && entityViewScope === 'edge'">
  41 + {{ 'edge.unassign-from-edge' | translate }}
  42 + </button>
  43 + <button mat-raised-button color="primary"
  44 + [disabled]="(isLoading$ | async)"
39 45 (click)="onEntityAction($event, 'delete')"
40 46 [fxShow]="!hideDelete() && !isEdit">
41 47 {{'entity-view.delete' | translate }}
... ...
... ... @@ -441,6 +441,9 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
441 441 case 'unassignFromCustomer':
442 442 this.unassignFromCustomer(action.event, action.entity);
443 443 return true;
  444 + case 'unassignFromEdge':
  445 + this.unassignFromEdge(action.event, action.entity);
  446 + return true;
444 447 }
445 448 return false;
446 449 }
... ...
... ... @@ -31,20 +31,20 @@
31 31 <button mat-raised-button color="primary"
32 32 [disabled]="(isLoading$ | async)"
33 33 (click)="onEntityAction($event, 'setRoot')"
34   - [fxShow]="!isEdit && !entity?.root && !isEdgeRuleChainScope()">
  34 + [fxShow]="!isEdit && !entity?.root && ruleChainScope === 'tenant'">
35 35 {{'rulechain.set-root' | translate }}
36 36 </button>
37 37 <button mat-raised-button color="primary"
38 38 [disabled]="(isLoading$ | async)"
39   - (click)="onEntityAction($event, 'setRoot')"
40   - [fxShow]="!isEdit && isEdgeRuleChainScope() && !isRootRuleChain()">
41   - {{'rulechain.set-root' | translate }}
  39 + (click)="onEntityAction($event, 'setDefaultRoot')"
  40 + [fxShow]="!isEdit && !entity?.root && ruleChainScope === 'edges'">
  41 + {{'rulechain.set-default-root-edge' | translate }}
42 42 </button>
43 43 <button mat-raised-button color="primary"
44 44 [disabled]="(isLoading$ | async)"
45   - (click)="onEntityAction($event, 'setDefaultRoot')"
46   - [fxShow]="!isEdit && !entity?.root && isEdgesRuleChainScope()">
47   - {{'rulechain.set-default-root-edge' | translate }}
  45 + (click)="onEntityAction($event, 'setRoot')"
  46 + [fxShow]="!isEdit && !isRootRuleChain() && ruleChainScope === 'edge'">
  47 + {{'rulechain.set-root' | translate }}
48 48 </button>
49 49 <button mat-raised-button color="primary"
50 50 [disabled]="(isLoading$ | async)"
... ...
... ... @@ -31,6 +31,8 @@ import { EntityTableConfig } from '@home/models/entity/entities-table-config.mod
31 31 })
32 32 export class RuleChainComponent extends EntityComponent<RuleChain> {
33 33
  34 + ruleChainScope: 'tenant' | 'edges' | 'edge';
  35 +
34 36 constructor(protected store: Store<AppState>,
35 37 protected translate: TranslateService,
36 38 @Inject('entity') protected entityValue: RuleChain,
... ... @@ -39,6 +41,11 @@ export class RuleChainComponent extends EntityComponent<RuleChain> {
39 41 super(store, fb, entityValue, entitiesTableConfigValue);
40 42 }
41 43
  44 + ngOnInit() {
  45 + this.ruleChainScope = this.entitiesTableConfig.componentsData.ruleChainScope;
  46 + super.ngOnInit();
  47 + }
  48 +
42 49 hideDelete() {
43 50 if (this.entitiesTableConfig) {
44 51 return !this.entitiesTableConfig.deleteEnabled(this.entity);
... ... @@ -79,30 +86,6 @@ export class RuleChainComponent extends EntityComponent<RuleChain> {
79 86 }));
80 87 }
81 88
82   - isTenantRuleChainScope() {
83   - if (this.entitiesTableConfig) {
84   - return this.entitiesTableConfig.componentsData.ruleChainScope == 'tenant';
85   - } else {
86   - return false;
87   - }
88   - }
89   -
90   - isEdgesRuleChainScope() {
91   - if (this.entitiesTableConfig) {
92   - return this.entitiesTableConfig.componentsData.ruleChainScope == 'edges';
93   - } else {
94   - return false;
95   - }
96   - }
97   -
98   - isEdgeRuleChainScope() {
99   - if (this.entitiesTableConfig) {
100   - return this.entitiesTableConfig.componentsData.ruleChainScope == 'edge';
101   - } else {
102   - return false;
103   - }
104   - }
105   -
106 89 isRootRuleChain() {
107 90 if (this.entitiesTableConfig && this.entityValue) {
108 91 return this.entitiesTableConfig.componentsData.rootRuleChainId == this.entityValue.id.id;
... ...