Merge pull request #13036 from vvlladd28/bug/manage-widget-action/updated
Fixed incorrect update date in widgets action table when switching widgets
This commit is contained in:
		
						commit
						151a087e45
					
				@ -21,11 +21,11 @@ import {
 | 
			
		||||
  widgetActionTypeTranslationMap
 | 
			
		||||
} from '@app/shared/models/widget.models';
 | 
			
		||||
import { CollectionViewer, DataSource } from '@angular/cdk/collections';
 | 
			
		||||
import { BehaviorSubject, Observable, of, ReplaySubject } from 'rxjs';
 | 
			
		||||
import { BehaviorSubject, Observable, of, ReplaySubject, shareReplay } from 'rxjs';
 | 
			
		||||
import { emptyPageData, PageData } from '@shared/models/page/page-data';
 | 
			
		||||
import { TranslateService } from '@ngx-translate/core';
 | 
			
		||||
import { PageLink } from '@shared/models/page/page-link';
 | 
			
		||||
import { catchError, map, publishReplay, refCount } from 'rxjs/operators';
 | 
			
		||||
import { catchError, map } from 'rxjs/operators';
 | 
			
		||||
import { UtilsService } from '@core/services/utils.service';
 | 
			
		||||
import { deepClone } from '@core/utils';
 | 
			
		||||
 | 
			
		||||
@ -68,11 +68,11 @@ export class WidgetActionsDatasource implements DataSource<WidgetActionDescripto
 | 
			
		||||
  constructor(private translate: TranslateService,
 | 
			
		||||
              private utils: UtilsService) {}
 | 
			
		||||
 | 
			
		||||
  connect(collectionViewer: CollectionViewer): Observable<WidgetActionDescriptorInfo[] | ReadonlyArray<WidgetActionDescriptorInfo>> {
 | 
			
		||||
  connect(_collectionViewer: CollectionViewer): Observable<WidgetActionDescriptorInfo[] | ReadonlyArray<WidgetActionDescriptorInfo>> {
 | 
			
		||||
    return this.actionsSubject.asObservable();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  disconnect(collectionViewer: CollectionViewer): void {
 | 
			
		||||
  disconnect(_collectionViewer: CollectionViewer): void {
 | 
			
		||||
    this.actionsSubject.complete();
 | 
			
		||||
    this.pageDataSubject.complete();
 | 
			
		||||
  }
 | 
			
		||||
@ -115,8 +115,7 @@ export class WidgetActionsDatasource implements DataSource<WidgetActionDescripto
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
      this.allActions = of(actions).pipe(
 | 
			
		||||
        publishReplay(1),
 | 
			
		||||
        refCount()
 | 
			
		||||
        shareReplay(1)
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
    return this.allActions;
 | 
			
		||||
 | 
			
		||||
@ -20,7 +20,8 @@ import {
 | 
			
		||||
  Component,
 | 
			
		||||
  ElementRef,
 | 
			
		||||
  forwardRef,
 | 
			
		||||
  Input, NgZone,
 | 
			
		||||
  Input,
 | 
			
		||||
  NgZone,
 | 
			
		||||
  OnDestroy,
 | 
			
		||||
  OnInit,
 | 
			
		||||
  ViewChild
 | 
			
		||||
@ -28,8 +29,6 @@ import {
 | 
			
		||||
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
 | 
			
		||||
import { TranslateService } from '@ngx-translate/core';
 | 
			
		||||
import { PageComponent } from '@shared/components/page.component';
 | 
			
		||||
import { Store } from '@ngrx/store';
 | 
			
		||||
import { AppState } from '@core/core.state';
 | 
			
		||||
import { MatDialog } from '@angular/material/dialog';
 | 
			
		||||
import { DialogService } from '@core/services/dialog.service';
 | 
			
		||||
import { PageLink } from '@shared/models/page/page-link';
 | 
			
		||||
@ -79,18 +78,16 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni
 | 
			
		||||
 | 
			
		||||
  @Input() additionalWidgetActionTypes: WidgetActionType[];
 | 
			
		||||
 | 
			
		||||
  innerValue: WidgetActionsData;
 | 
			
		||||
 | 
			
		||||
  displayedColumns: string[];
 | 
			
		||||
  pageLink: PageLink;
 | 
			
		||||
  textSearchMode = false;
 | 
			
		||||
  hidePageSize = false;
 | 
			
		||||
  dataSource: WidgetActionsDatasource;
 | 
			
		||||
 | 
			
		||||
  viewsInited = false;
 | 
			
		||||
  dirtyValue = false;
 | 
			
		||||
  dragDisabled = true;
 | 
			
		||||
 | 
			
		||||
  private actionsMap: {[actionSourceId: string]: Array<WidgetActionDescriptor>};
 | 
			
		||||
  private viewsInited = false;
 | 
			
		||||
  private dirtyValue = false;
 | 
			
		||||
  private widgetResize$: ResizeObserver;
 | 
			
		||||
  private destroyed = false;
 | 
			
		||||
 | 
			
		||||
@ -101,15 +98,14 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni
 | 
			
		||||
 | 
			
		||||
  private propagateChange = (_: any) => {};
 | 
			
		||||
 | 
			
		||||
  constructor(protected store: Store<AppState>,
 | 
			
		||||
              private translate: TranslateService,
 | 
			
		||||
  constructor(private translate: TranslateService,
 | 
			
		||||
              private utils: UtilsService,
 | 
			
		||||
              private dialog: MatDialog,
 | 
			
		||||
              private dialogs: DialogService,
 | 
			
		||||
              private cd: ChangeDetectorRef,
 | 
			
		||||
              private elementRef: ElementRef,
 | 
			
		||||
              private zone: NgZone) {
 | 
			
		||||
    super(store);
 | 
			
		||||
    super();
 | 
			
		||||
    const sortOrder: SortOrder = { property: 'actionSourceName', direction: Direction.ASC };
 | 
			
		||||
    this.pageLink = new PageLink(10, 0, null, sortOrder);
 | 
			
		||||
    this.dataSource = new WidgetActionsDatasource(this.translate, this.utils);
 | 
			
		||||
@ -137,7 +133,6 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ngAfterViewInit() {
 | 
			
		||||
 | 
			
		||||
    fromEvent(this.searchInputField.nativeElement, 'keyup')
 | 
			
		||||
      .pipe(
 | 
			
		||||
        debounceTime(150),
 | 
			
		||||
@ -162,10 +157,9 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni
 | 
			
		||||
      this.dirtyValue = false;
 | 
			
		||||
      this.updateData(true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  updateData(reload: boolean = false) {
 | 
			
		||||
  private updateData(reload: boolean = false) {
 | 
			
		||||
    this.pageLink.page = this.paginator.pageIndex;
 | 
			
		||||
    this.pageLink.pageSize = this.paginator.pageSize;
 | 
			
		||||
    this.pageLink.sortOrder.property = this.sort.active;
 | 
			
		||||
@ -198,7 +192,7 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni
 | 
			
		||||
    this.openWidgetActionDialog($event, action);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  openWidgetActionDialog($event: Event, action: WidgetActionDescriptorInfo = null) {
 | 
			
		||||
  private openWidgetActionDialog($event: Event, action: WidgetActionDescriptorInfo = null) {
 | 
			
		||||
    if ($event) {
 | 
			
		||||
      $event.stopPropagation();
 | 
			
		||||
    }
 | 
			
		||||
@ -208,15 +202,15 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni
 | 
			
		||||
      prevActionSourceId = action.actionSourceId;
 | 
			
		||||
    }
 | 
			
		||||
    const availableActionSources: {[actionSourceId: string]: WidgetActionSource} = {};
 | 
			
		||||
    for (const id of Object.keys(this.innerValue.actionSources)) {
 | 
			
		||||
      const actionSource = this.innerValue.actionSources[id];
 | 
			
		||||
    for (const id of Object.keys(this.actionSources)) {
 | 
			
		||||
      const actionSource = this.actionSources[id];
 | 
			
		||||
      if (actionSource.multiple) {
 | 
			
		||||
        availableActionSources[id] = actionSource;
 | 
			
		||||
      } else {
 | 
			
		||||
        if (!isAdd && action.actionSourceId === id) {
 | 
			
		||||
          availableActionSources[id] = actionSource;
 | 
			
		||||
        } else {
 | 
			
		||||
          const existing = this.innerValue.actionsMap[id];
 | 
			
		||||
          const existing = this.actionsMap[id];
 | 
			
		||||
          if (!existing || !existing.length) {
 | 
			
		||||
            availableActionSources[id] = actionSource;
 | 
			
		||||
          }
 | 
			
		||||
@ -225,7 +219,7 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const actionsData: WidgetActionsData = {
 | 
			
		||||
      actionsMap: this.innerValue.actionsMap,
 | 
			
		||||
      actionsMap: this.actionsMap,
 | 
			
		||||
      actionSources: availableActionSources
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
@ -277,7 +271,7 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private getOrCreateTargetActions(actionSourceId: string): Array<WidgetActionDescriptor> {
 | 
			
		||||
    const actionsMap = this.innerValue.actionsMap;
 | 
			
		||||
    const actionsMap = this.actionsMap;
 | 
			
		||||
    let targetActions = actionsMap[actionSourceId];
 | 
			
		||||
    if (!targetActions) {
 | 
			
		||||
      targetActions = [];
 | 
			
		||||
@ -323,7 +317,7 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni
 | 
			
		||||
    this.updateData();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  resetSortAndFilter(update: boolean = true) {
 | 
			
		||||
  private resetSortAndFilter(update: boolean = true) {
 | 
			
		||||
    this.pageLink.textSearch = null;
 | 
			
		||||
    this.paginator.pageIndex = 0;
 | 
			
		||||
    const sortable = this.sort.sortables.get('actionSourceName');
 | 
			
		||||
@ -338,7 +332,7 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni
 | 
			
		||||
    this.propagateChange = fn;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  registerOnTouched(fn: any): void {
 | 
			
		||||
  registerOnTouched(_fn: any): void {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  setDisabledState(isDisabled: boolean): void {
 | 
			
		||||
@ -346,13 +340,14 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  writeValue(actions?: {[actionSourceId: string]: Array<WidgetActionDescriptor>}): void {
 | 
			
		||||
    this.innerValue = {
 | 
			
		||||
      actionsMap: actions || {},
 | 
			
		||||
      actionSources: this.actionSources || {}
 | 
			
		||||
    };
 | 
			
		||||
    this.actionsMap = actions ?? {};
 | 
			
		||||
    setTimeout(() => {
 | 
			
		||||
      if (!this.destroyed) {
 | 
			
		||||
        this.dataSource.setActions(this.innerValue);
 | 
			
		||||
        const actionData: WidgetActionsData = {
 | 
			
		||||
          actionsMap: this.actionsMap,
 | 
			
		||||
          actionSources: this.actionSources
 | 
			
		||||
        };
 | 
			
		||||
        this.dataSource.setActions(actionData);
 | 
			
		||||
        if (this.viewsInited) {
 | 
			
		||||
          this.resetSortAndFilter(true);
 | 
			
		||||
        } else {
 | 
			
		||||
@ -364,6 +359,6 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni
 | 
			
		||||
 | 
			
		||||
  private onActionsUpdated() {
 | 
			
		||||
    this.updateData(true);
 | 
			
		||||
    this.propagateChange(this.innerValue.actionsMap);
 | 
			
		||||
    this.propagateChange(this.actionsMap);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user