Commit 3ffa7e359277a22a9dcab3d0d6412f1d1853454c
1 parent
04e50696
Added button unassignFromEdge for entities. Added findAssetsByTenantIdAndEdgeIdAndType()
Showing
17 changed files
with
104 additions
and
34 deletions
@@ -485,6 +485,7 @@ public class AssetController extends BaseController { | @@ -485,6 +485,7 @@ public class AssetController extends BaseController { | ||
485 | @PathVariable(EDGE_ID) String strEdgeId, | 485 | @PathVariable(EDGE_ID) String strEdgeId, |
486 | @RequestParam int pageSize, | 486 | @RequestParam int pageSize, |
487 | @RequestParam int page, | 487 | @RequestParam int page, |
488 | + @RequestParam(required = false) String type, | ||
488 | @RequestParam(required = false) String textSearch, | 489 | @RequestParam(required = false) String textSearch, |
489 | @RequestParam(required = false) String sortProperty, | 490 | @RequestParam(required = false) String sortProperty, |
490 | @RequestParam(required = false) String sortOrder, | 491 | @RequestParam(required = false) String sortOrder, |
@@ -496,7 +497,11 @@ public class AssetController extends BaseController { | @@ -496,7 +497,11 @@ public class AssetController extends BaseController { | ||
496 | EdgeId edgeId = new EdgeId(toUUID(strEdgeId)); | 497 | EdgeId edgeId = new EdgeId(toUUID(strEdgeId)); |
497 | checkEdgeId(edgeId, Operation.READ); | 498 | checkEdgeId(edgeId, Operation.READ); |
498 | TimePageLink pageLink = createTimePageLink(pageSize, page, textSearch, sortProperty, sortOrder, startTime, endTime); | 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 | } catch (Exception e) { | 505 | } catch (Exception e) { |
501 | throw handleException(e); | 506 | throw handleException(e); |
502 | } | 507 | } |
@@ -82,4 +82,6 @@ public interface AssetService { | @@ -82,4 +82,6 @@ public interface AssetService { | ||
82 | Asset unassignAssetFromEdge(TenantId tenantId, AssetId assetId, EdgeId edgeId); | 82 | Asset unassignAssetFromEdge(TenantId tenantId, AssetId assetId, EdgeId edgeId); |
83 | 83 | ||
84 | PageData<Asset> findAssetsByTenantIdAndEdgeId(TenantId tenantId, EdgeId edgeId, TimePageLink pageLink); | 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,4 +176,15 @@ public interface AssetDao extends Dao<Asset> { | ||
176 | * @return the list of asset objects | 176 | * @return the list of asset objects |
177 | */ | 177 | */ |
178 | PageData<Asset> findAssetsByTenantIdAndEdgeId(UUID tenantId, UUID edgeId, TimePageLink pageLink); | 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,6 +364,16 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ | ||
364 | return assetDao.findAssetsByTenantIdAndEdgeId(tenantId.getId(), edgeId.getId(), pageLink); | 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 | private DataValidator<Asset> assetValidator = | 377 | private DataValidator<Asset> assetValidator = |
368 | new DataValidator<Asset>() { | 378 | new DataValidator<Asset>() { |
369 | 379 |
@@ -132,4 +132,15 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, | @@ -132,4 +132,15 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, | ||
132 | @Param("searchText") String searchText, | 132 | @Param("searchText") String searchText, |
133 | Pageable pageable); | 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,4 +196,16 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im | ||
196 | Objects.toString(pageLink.getTextSearch(), ""), | 196 | Objects.toString(pageLink.getTextSearch(), ""), |
197 | DaoUtil.toPageable(pageLink))); | 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,7 +99,7 @@ export class AssetService { | ||
99 | return this.http.delete(`/api/edge/${edgeId}/asset/${assetId}`, defaultHttpOptionsFromConfig(config)); | 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 | config?: RequestConfig): Observable<PageData<AssetInfo>> { | 103 | config?: RequestConfig): Observable<PageData<AssetInfo>> { |
104 | return this.http.get<PageData<AssetInfo>>(`/api/edge/${edgeId}/assets${pageLink.toQuery()}&type=${type}`, | 104 | return this.http.get<PageData<AssetInfo>>(`/api/edge/${edgeId}/assets${pageLink.toQuery()}&type=${type}`, |
105 | defaultHttpOptionsFromConfig(config)); | 105 | defaultHttpOptionsFromConfig(config)); |
@@ -36,6 +36,12 @@ | @@ -36,6 +36,12 @@ | ||
36 | </button> | 36 | </button> |
37 | <button mat-raised-button color="primary" | 37 | <button mat-raised-button color="primary" |
38 | [disabled]="(isLoading$ | async)" | 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 | (click)="onEntityAction($event, 'delete')" | 45 | (click)="onEntityAction($event, 'delete')" |
40 | [fxShow]="!hideDelete() && !isEdit"> | 46 | [fxShow]="!hideDelete() && !isEdit"> |
41 | {{'asset.delete' | translate }} | 47 | {{'asset.delete' | translate }} |
@@ -466,6 +466,9 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse | @@ -466,6 +466,9 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse | ||
466 | case 'unassignFromCustomer': | 466 | case 'unassignFromCustomer': |
467 | this.unassignFromCustomer(action.event, action.entity); | 467 | this.unassignFromCustomer(action.event, action.entity); |
468 | return true; | 468 | return true; |
469 | + case 'unassignFromEdge': | ||
470 | + this.unassignFromEdge(action.event, action.entity); | ||
471 | + return true; | ||
469 | } | 472 | } |
470 | return false; | 473 | return false; |
471 | } | 474 | } |
@@ -55,6 +55,12 @@ | @@ -55,6 +55,12 @@ | ||
55 | </button> | 55 | </button> |
56 | <button mat-raised-button color="primary" | 56 | <button mat-raised-button color="primary" |
57 | [disabled]="(isLoading$ | async)" | 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 | (click)="onEntityAction($event, 'delete')" | 64 | (click)="onEntityAction($event, 'delete')" |
59 | [fxShow]="!hideDelete() && !isEdit"> | 65 | [fxShow]="!hideDelete() && !isEdit"> |
60 | {{'dashboard.delete' | translate }} | 66 | {{'dashboard.delete' | translate }} |
@@ -543,6 +543,9 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig< | @@ -543,6 +543,9 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig< | ||
543 | case 'unassignFromCustomer': | 543 | case 'unassignFromCustomer': |
544 | this.unassignFromCustomer(action.event, action.entity, this.config.componentsData.customerId); | 544 | this.unassignFromCustomer(action.event, action.entity, this.config.componentsData.customerId); |
545 | return true; | 545 | return true; |
546 | + case 'unassignFromEdge': | ||
547 | + this.unassignFromEdge(action.event, action.entity); | ||
548 | + return true; | ||
546 | } | 549 | } |
547 | return false; | 550 | return false; |
548 | } | 551 | } |
@@ -572,7 +575,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig< | @@ -572,7 +575,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig< | ||
572 | $event.stopPropagation(); | 575 | $event.stopPropagation(); |
573 | } | 576 | } |
574 | this.dialogService.confirm( | 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 | this.translate.instant('dashboard.unassign-dashboard-from-edge-text'), | 579 | this.translate.instant('dashboard.unassign-dashboard-from-edge-text'), |
577 | this.translate.instant('action.no'), | 580 | this.translate.instant('action.no'), |
578 | this.translate.instant('action.yes'), | 581 | this.translate.instant('action.yes'), |
@@ -40,6 +40,12 @@ | @@ -40,6 +40,12 @@ | ||
40 | [fxShow]="!isEdit"> | 40 | [fxShow]="!isEdit"> |
41 | {{ (deviceScope === 'customer_user' ? 'device.view-credentials' : 'device.manage-credentials') | translate }} | 41 | {{ (deviceScope === 'customer_user' ? 'device.view-credentials' : 'device.manage-credentials') | translate }} |
42 | </button> | 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 | <button mat-raised-button color="primary" fxFlex.xs | 49 | <button mat-raised-button color="primary" fxFlex.xs |
44 | [disabled]="(isLoading$ | async)" | 50 | [disabled]="(isLoading$ | async)" |
45 | (click)="onEntityAction($event, 'delete')" | 51 | (click)="onEntityAction($event, 'delete')" |
@@ -519,6 +519,9 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev | @@ -519,6 +519,9 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev | ||
519 | case 'unassignFromCustomer': | 519 | case 'unassignFromCustomer': |
520 | this.unassignFromCustomer(action.event, action.entity); | 520 | this.unassignFromCustomer(action.event, action.entity); |
521 | return true; | 521 | return true; |
522 | + case 'unassignFromEdge': | ||
523 | + this.unassignFromEdge(action.event, action.entity); | ||
524 | + return true; | ||
522 | case 'manageCredentials': | 525 | case 'manageCredentials': |
523 | this.manageCredentials(action.event, action.entity); | 526 | this.manageCredentials(action.event, action.entity); |
524 | return true; | 527 | return true; |
@@ -36,6 +36,12 @@ | @@ -36,6 +36,12 @@ | ||
36 | </button> | 36 | </button> |
37 | <button mat-raised-button color="primary" | 37 | <button mat-raised-button color="primary" |
38 | [disabled]="(isLoading$ | async)" | 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 | (click)="onEntityAction($event, 'delete')" | 45 | (click)="onEntityAction($event, 'delete')" |
40 | [fxShow]="!hideDelete() && !isEdit"> | 46 | [fxShow]="!hideDelete() && !isEdit"> |
41 | {{'entity-view.delete' | translate }} | 47 | {{'entity-view.delete' | translate }} |
@@ -441,6 +441,9 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig | @@ -441,6 +441,9 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig | ||
441 | case 'unassignFromCustomer': | 441 | case 'unassignFromCustomer': |
442 | this.unassignFromCustomer(action.event, action.entity); | 442 | this.unassignFromCustomer(action.event, action.entity); |
443 | return true; | 443 | return true; |
444 | + case 'unassignFromEdge': | ||
445 | + this.unassignFromEdge(action.event, action.entity); | ||
446 | + return true; | ||
444 | } | 447 | } |
445 | return false; | 448 | return false; |
446 | } | 449 | } |
@@ -31,20 +31,20 @@ | @@ -31,20 +31,20 @@ | ||
31 | <button mat-raised-button color="primary" | 31 | <button mat-raised-button color="primary" |
32 | [disabled]="(isLoading$ | async)" | 32 | [disabled]="(isLoading$ | async)" |
33 | (click)="onEntityAction($event, 'setRoot')" | 33 | (click)="onEntityAction($event, 'setRoot')" |
34 | - [fxShow]="!isEdit && !entity?.root && !isEdgeRuleChainScope()"> | 34 | + [fxShow]="!isEdit && !entity?.root && ruleChainScope === 'tenant'"> |
35 | {{'rulechain.set-root' | translate }} | 35 | {{'rulechain.set-root' | translate }} |
36 | </button> | 36 | </button> |
37 | <button mat-raised-button color="primary" | 37 | <button mat-raised-button color="primary" |
38 | [disabled]="(isLoading$ | async)" | 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 | </button> | 42 | </button> |
43 | <button mat-raised-button color="primary" | 43 | <button mat-raised-button color="primary" |
44 | [disabled]="(isLoading$ | async)" | 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 | </button> | 48 | </button> |
49 | <button mat-raised-button color="primary" | 49 | <button mat-raised-button color="primary" |
50 | [disabled]="(isLoading$ | async)" | 50 | [disabled]="(isLoading$ | async)" |
@@ -31,6 +31,8 @@ import { EntityTableConfig } from '@home/models/entity/entities-table-config.mod | @@ -31,6 +31,8 @@ import { EntityTableConfig } from '@home/models/entity/entities-table-config.mod | ||
31 | }) | 31 | }) |
32 | export class RuleChainComponent extends EntityComponent<RuleChain> { | 32 | export class RuleChainComponent extends EntityComponent<RuleChain> { |
33 | 33 | ||
34 | + ruleChainScope: 'tenant' | 'edges' | 'edge'; | ||
35 | + | ||
34 | constructor(protected store: Store<AppState>, | 36 | constructor(protected store: Store<AppState>, |
35 | protected translate: TranslateService, | 37 | protected translate: TranslateService, |
36 | @Inject('entity') protected entityValue: RuleChain, | 38 | @Inject('entity') protected entityValue: RuleChain, |
@@ -39,6 +41,11 @@ export class RuleChainComponent extends EntityComponent<RuleChain> { | @@ -39,6 +41,11 @@ export class RuleChainComponent extends EntityComponent<RuleChain> { | ||
39 | super(store, fb, entityValue, entitiesTableConfigValue); | 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 | hideDelete() { | 49 | hideDelete() { |
43 | if (this.entitiesTableConfig) { | 50 | if (this.entitiesTableConfig) { |
44 | return !this.entitiesTableConfig.deleteEnabled(this.entity); | 51 | return !this.entitiesTableConfig.deleteEnabled(this.entity); |
@@ -79,30 +86,6 @@ export class RuleChainComponent extends EntityComponent<RuleChain> { | @@ -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 | isRootRuleChain() { | 89 | isRootRuleChain() { |
107 | if (this.entitiesTableConfig && this.entityValue) { | 90 | if (this.entitiesTableConfig && this.entityValue) { |
108 | return this.entitiesTableConfig.componentsData.rootRuleChainId == this.entityValue.id.id; | 91 | return this.entitiesTableConfig.componentsData.rootRuleChainId == this.entityValue.id.id; |