Browse Source

Merge pull request #9553 from Dmitriymush/enhacements/add-dashboard-dialog

Dashboard form redesign
pull/9782/head
Igor Kulikov 3 years ago
committed by GitHub
parent
commit
20e7f81dee
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 32
      ui-ngx/src/app/modules/home/pages/dashboard/dashboard-form.component.html
  2. 9
      ui-ngx/src/app/modules/home/pages/dashboard/dashboard-form.component.ts
  3. 16
      ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts
  4. 4
      ui-ngx/src/app/shared/models/dashboard.models.ts

32
ui-ngx/src/app/modules/home/pages/dashboard/dashboard-form.component.html

@ -124,18 +124,26 @@
<textarea matInput formControlName="description" rows="2"></textarea> <textarea matInput formControlName="description" rows="2"></textarea>
</mat-form-field> </mat-form-field>
</div> </div>
<div translate>dashboard.mobile-app-settings</div> <tb-entity-list
<tb-gallery-image-input fxFlex *ngIf="isAdd"
label="{{'dashboard.image' | translate}}" formControlName="assignedCustomerIds"
formControlName="image"> labelText="{{ 'dashboard.assigned-customers' | translate }}"
</tb-gallery-image-input> [entityType]="entityType.CUSTOMER">
<mat-checkbox fxFlex formControlName="mobileHide"> </tb-entity-list>
{{ 'dashboard.mobile-hide' | translate }} <div class="tb-form-panel stroked no-gap">
</mat-checkbox> <div class="tb-form-panel-title" translate>dashboard.mobile-app-settings</div>
<mat-form-field class="mat-block"> <mat-slide-toggle formControlName="mobileHide" class="mat-slide margin fixed-title-width">
<mat-label translate>dashboard.mobile-order</mat-label> {{ 'dashboard.mobile-hide' | translate }}
<input matInput formControlName="mobileOrder" type="number" step="1"> </mat-slide-toggle>
</mat-form-field> <mat-form-field class="mat-block">
<mat-label translate>dashboard.mobile-order</mat-label>
<input matInput formControlName="mobileOrder" type="number" step="1">
</mat-form-field>
<tb-gallery-image-input fxFlex
label="{{'dashboard.image' | translate}}"
formControlName="image">
</tb-gallery-image-input>
</div>
</fieldset> </fieldset>
</form> </form>
</div> </div>

9
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 { DashboardService } from '@core/http/dashboard.service';
import { EntityTableConfig } from '@home/models/entity/entities-table-config.models'; import { EntityTableConfig } from '@home/models/entity/entities-table-config.models';
import { isEqual } from '@core/utils'; import { isEqual } from '@core/utils';
import { EntityType } from '@shared/models/entity-type.models';
@Component({ @Component({
selector: 'tb-dashboard-form', selector: 'tb-dashboard-form',
@ -43,6 +44,7 @@ export class DashboardFormComponent extends EntityComponent<Dashboard> {
publicLink: string; publicLink: string;
assignedCustomersText: string; assignedCustomersText: string;
entityType = EntityType;
constructor(protected store: Store<AppState>, constructor(protected store: Store<AppState>,
protected translate: TranslateService, protected translate: TranslateService,
@ -78,7 +80,7 @@ export class DashboardFormComponent extends EntityComponent<Dashboard> {
buildForm(entity: Dashboard): UntypedFormGroup { buildForm(entity: Dashboard): UntypedFormGroup {
this.updateFields(entity); this.updateFields(entity);
return this.fb.group( const form = this.fb.group(
{ {
title: [entity ? entity.title : '', [Validators.required, Validators.maxLength(255)]], title: [entity ? entity.title : '', [Validators.required, Validators.maxLength(255)]],
image: [entity ? entity.image : null], image: [entity ? entity.image : null],
@ -91,6 +93,11 @@ export class DashboardFormComponent extends EntityComponent<Dashboard> {
) )
} }
); );
if (this.isAdd) {
form.addControl('assignedCustomerIds', this.fb.control([]));
}
return form;
} }
updateForm(entity: Dashboard) { updateForm(entity: Dashboard) {

16
ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts

@ -47,6 +47,7 @@ import {
import { import {
Dashboard, Dashboard,
DashboardInfo, DashboardInfo,
DashboardSetup,
getDashboardAssignedCustomersText, getDashboardAssignedCustomersText,
isCurrentPublicDashboardCustomer, isCurrentPublicDashboardCustomer,
isPublicDashboard isPublicDashboard
@ -109,7 +110,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
this.config.deleteEntitiesContent = () => this.translate.instant('dashboard.delete-dashboards-text'); this.config.deleteEntitiesContent = () => this.translate.instant('dashboard.delete-dashboards-text');
this.config.loadEntity = id => this.dashboardService.getDashboard(id.id); 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.onEntityAction = action => this.onDashboardAction(action);
this.config.detailsReadonly = () => (this.config.componentsData.dashboardScope === 'customer_user' || this.config.detailsReadonly = () => (this.config.componentsData.dashboardScope === 'customer_user' ||
this.config.componentsData.dashboardScope === 'edge_customer_user'); this.config.componentsData.dashboardScope === 'edge_customer_user');
@ -675,4 +676,17 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
); );
} }
saveAndAssignDashboard(dashboard: DashboardSetup): Observable<Dashboard> {
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);
})
);
}
} }

4
ui-ngx/src/app/shared/models/dashboard.models.ts

@ -138,6 +138,10 @@ export interface HomeDashboardInfo {
hideDashboardToolbar: boolean; hideDashboardToolbar: boolean;
} }
export interface DashboardSetup extends Dashboard {
assignedCustomerIds?: Array<string>;
}
export const isPublicDashboard = (dashboard: DashboardInfo): boolean => { export const isPublicDashboard = (dashboard: DashboardInfo): boolean => {
if (dashboard && dashboard.assignedCustomers) { if (dashboard && dashboard.assignedCustomers) {
return dashboard.assignedCustomers return dashboard.assignedCustomers

Loading…
Cancel
Save