diff --git a/ui-ngx/src/app/modules/home/pages/dashboard/dashboard-form.component.html b/ui-ngx/src/app/modules/home/pages/dashboard/dashboard-form.component.html index 41c36e9440..b1bb37470a 100644 --- a/ui-ngx/src/app/modules/home/pages/dashboard/dashboard-form.component.html +++ b/ui-ngx/src/app/modules/home/pages/dashboard/dashboard-form.component.html @@ -124,18 +124,26 @@ -
dashboard.mobile-app-settings
- - - - {{ 'dashboard.mobile-hide' | translate }} - - - dashboard.mobile-order - - + + +
+
dashboard.mobile-app-settings
+ + {{ 'dashboard.mobile-hide' | translate }} + + + dashboard.mobile-order + + + + +
diff --git a/ui-ngx/src/app/modules/home/pages/dashboard/dashboard-form.component.ts b/ui-ngx/src/app/modules/home/pages/dashboard/dashboard-form.component.ts index 053ee9326d..3da09f84c8 100644 --- a/ui-ngx/src/app/modules/home/pages/dashboard/dashboard-form.component.ts +++ b/ui-ngx/src/app/modules/home/pages/dashboard/dashboard-form.component.ts @@ -30,6 +30,7 @@ import { import { DashboardService } from '@core/http/dashboard.service'; import { EntityTableConfig } from '@home/models/entity/entities-table-config.models'; import { isEqual } from '@core/utils'; +import { EntityType } from '@shared/models/entity-type.models'; @Component({ selector: 'tb-dashboard-form', @@ -43,6 +44,7 @@ export class DashboardFormComponent extends EntityComponent { publicLink: string; assignedCustomersText: string; + entityType = EntityType; constructor(protected store: Store, protected translate: TranslateService, @@ -78,7 +80,7 @@ export class DashboardFormComponent extends EntityComponent { buildForm(entity: Dashboard): UntypedFormGroup { this.updateFields(entity); - return this.fb.group( + const form = this.fb.group( { title: [entity ? entity.title : '', [Validators.required, Validators.maxLength(255)]], image: [entity ? entity.image : null], @@ -91,6 +93,11 @@ export class DashboardFormComponent extends EntityComponent { ) } ); + if (this.isAdd) { + form.addControl('assignedCustomerIds', this.fb.control([])); + } + + return form; } updateForm(entity: Dashboard) { diff --git a/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts index 70fe58fc1c..6a0b987e5b 100644 --- a/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts @@ -47,6 +47,7 @@ import { import { Dashboard, DashboardInfo, + DashboardSetup, getDashboardAssignedCustomersText, isCurrentPublicDashboardCustomer, isPublicDashboard @@ -109,7 +110,7 @@ export class DashboardsTableConfigResolver implements Resolve this.translate.instant('dashboard.delete-dashboards-text'); this.config.loadEntity = id => this.dashboardService.getDashboard(id.id); - this.config.saveEntity = dashboard => this.dashboardService.saveDashboard(dashboard as Dashboard); + this.config.saveEntity = dashboard => this.saveAndAssignDashboard(dashboard as DashboardSetup); this.config.onEntityAction = action => this.onDashboardAction(action); this.config.detailsReadonly = () => (this.config.componentsData.dashboardScope === 'customer_user' || this.config.componentsData.dashboardScope === 'edge_customer_user'); @@ -675,4 +676,17 @@ export class DashboardsTableConfigResolver implements Resolve { + const {assignedCustomerIds, ...dashboardToCreate} = dashboard; + + return this.dashboardService.saveDashboard(dashboardToCreate as Dashboard).pipe( + mergeMap((createdDashboard) => { + if (assignedCustomerIds?.length) { + return this.dashboardService.addDashboardCustomers(createdDashboard.id.id, assignedCustomerIds); + } + return of(createdDashboard); + }) + ); + } + } diff --git a/ui-ngx/src/app/shared/models/dashboard.models.ts b/ui-ngx/src/app/shared/models/dashboard.models.ts index ce8dc23416..14e8f6b1a8 100644 --- a/ui-ngx/src/app/shared/models/dashboard.models.ts +++ b/ui-ngx/src/app/shared/models/dashboard.models.ts @@ -138,6 +138,10 @@ export interface HomeDashboardInfo { hideDashboardToolbar: boolean; } +export interface DashboardSetup extends Dashboard { + assignedCustomerIds?: Array; +} + export const isPublicDashboard = (dashboard: DashboardInfo): boolean => { if (dashboard && dashboard.assignedCustomers) { return dashboard.assignedCustomers