Commit 28a0031c authored by Florent POITTEVIN's avatar Florent POITTEVIN
Browse files

fix: remove observable on all data table action and fix problem refresh action to display

parent fc8490c1
......@@ -80,7 +80,7 @@ export class DepositCollectionRoutable extends SharedAbstractDetailEditRoutable<
logo: "delete",
callback: (aip: Aip) => this.deleteAip(this._resId, aip),
placeholder: TRANSLATE("crud.list.action.delete"),
displayOnCondition: (aip: Aip) => this.canEditObs,
displayOnCondition: (aip: Aip) => MemoizedUtil.selectSnapshot(this._store, DepositState, state => state.canEdit),
},
{
logo: "forward",
......
......@@ -61,6 +61,7 @@ import {StatusHistory} from "@shared/models/status-history.model";
import {SecurityService} from "@shared/services/security.service";
import {Observable} from "rxjs";
import {
distinctUntilChanged,
take,
tap,
} from "rxjs/operators";
......@@ -92,7 +93,10 @@ export class DepositFileRoutable extends SharedAbstractDetailEditRoutable<Deposi
intermediateFoldersObs: Observable<string[]> = MemoizedUtil.select(this._store, DepositDataFileState, state => state.intermediateFolders);
foldersWithIntermediateFoldersObs: Observable<string[]> = MemoizedUtil.select(this._store, DepositDataFileState, state => state.foldersWithIntermediateFolders);
currentFolderObs: Observable<string> = MemoizedUtil.select(this._store, DepositDataFileState, state => state.currentFolder);
canEditObs: Observable<boolean> = MemoizedUtil.select(this._store, DepositState, state => state.canEdit);
canEditObs: Observable<boolean> = MemoizedUtil.select(this._store, DepositState, state => state.canEdit).pipe(
distinctUntilChanged(),
tap(canEdit => this.actions = [...this.actions]), // Force method computeContext on datatable
);
isLoadingHistoryObs: Observable<boolean> = MemoizedUtil.isLoading(this._store, DepositDataFileStatusHistoryState);
dataFileHistoryObs: Observable<StatusHistory[]> = MemoizedUtil.select(this._store, DepositDataFileStatusHistoryState, state => state.history);
......@@ -130,13 +134,13 @@ export class DepositFileRoutable extends SharedAbstractDetailEditRoutable<Deposi
logo: "delete",
callback: (depositDataFile: DepositDataFile) => this.deleteDataFile(this._resId, depositDataFile),
placeholder: TRANSLATE("crud.list.action.delete"),
displayOnCondition: (depositDataFile: DepositDataFile) => this.canEditObs, // TODO FIX : CAUSE SLOW RENDER, PREFER CALLBACK
displayOnCondition: (depositDataFile: DepositDataFile) => MemoizedUtil.selectSnapshot(this._store, DepositState, state => state.canEdit),
},
{
logo: "redo",
callback: (depositDataFile: DepositDataFile) => this.moveDataFileWithDialog(depositDataFile),
placeholder: TRANSLATE("crud.list.action.move"),
displayOnCondition: (depositDataFile: DepositDataFile) => this.canEditObs, // TODO FIX : CAUSE SLOW RENDER, PREFER CALLBACK
displayOnCondition: (depositDataFile: DepositDataFile) => MemoizedUtil.selectSnapshot(this._store, DepositState, state => state.canEdit),
},
{
logo: "history",
......
......@@ -121,7 +121,7 @@ export class HomeSearchRoutable extends SharedAbstractPresentational implements
logo: "add_shopping_cart",
callback: current => this.addToCart(current.archiveMetadata),
placeholder: TRANSLATE("home.list.action.addToCart"),
displayOnCondition: current => this.isLoggedInObs,
displayOnCondition: current => MemoizedUtil.selectSnapshot(this.store, AppState, state => state.isLoggedIn),
},
{
logo: "file_download",
......
......@@ -17,10 +17,6 @@ import {
} from "@ngxs/store";
import {DataTableActions} from "@shared/models/data-table-actions.model";
import {SecurityService} from "@shared/services/security.service";
import {
Observable,
of,
} from "rxjs";
import {
isNullOrUndefined,
OrderEnum,
......@@ -69,11 +65,11 @@ export class OrgunitListRoutable extends SharedAbstractListRoutable<Organization
];
}
conditionDisplayEditButton(model: OrganizationalUnit | undefined): Observable<boolean> {
conditionDisplayEditButton(model: OrganizationalUnit | undefined): boolean {
if (isNullOrUndefined(model)) {
return of(true);
return true;
}
return of(this._securityService.isRootOrAdmin());
return this._securityService.isRootOrAdmin();
}
conditionDisplayDeleteButton(model: OrganizationalUnit | undefined): boolean {
......
......@@ -272,7 +272,8 @@
[ngIfElse]="noComponent"
>
<ng-template [ngTemplateOutlet]="colComponentTemplate"
[ngTemplateOutletContext]="{rowData: rowData, col: col}">
[ngTemplateOutletContext]="{rowData: rowData, col: col}"
>
</ng-template>
</ng-template>
......@@ -280,7 +281,8 @@
<ng-template #noComponent>
<ng-template [ngTemplateOutlet]="colNoComponentTemplate"
[ngTemplateOutletContext]="{rowData: rowData, col: col}">
[ngTemplateOutletContext]="{rowData: rowData, col: col}"
>
</ng-template>
</ng-template>
......@@ -349,7 +351,8 @@
<ng-template #colComponentTemplate
let-rowData="rowData"
let-col="col">
let-col="col"
>
<ng-container [ngSwitch]="col.component">
<dlcm-aip-status-summary *ngSwitchCase="dataTableComponentEnum.aipStatusSummaryPresentational"
......@@ -400,7 +403,8 @@
<ng-template #colNoComponentTemplate
let-rowData="rowData"
let-col="col">
let-col="col"
>
<ng-template [ngIf]="col.type === fieldTypeEnum.size"
[ngIfElse]="normal"
......
......@@ -278,10 +278,17 @@ export class SharedDataTablePresentational<TResource extends BaseResource> exten
return;
}
this.actions.forEach(action => {
this.context.mapAtLeastOneActionToDisplay.set(action, this._datas.some(data => action.displayOnCondition && action.displayOnCondition(data)));
this.context.mapAtLeastOneActionToDisplay.set(action, this._shouldDisplayActionColumns(action));
});
}
private _shouldDisplayActionColumns(action: DataTableActions): boolean {
if (isNullOrUndefined(action.displayOnCondition)) {
return true;
}
return this._datas.some(data => isTrue(action.displayOnCondition(data)));
}
private computeDatasForPage(): void {
const count = this.queryParameters && this.queryParameters.paging ? this.queryParameters.paging.pageSize : 0;
const defaultValue = this._getEmptyData();
......@@ -513,28 +520,21 @@ export class SharedDataTablePresentational<TResource extends BaseResource> exten
return this.listHighlightingId.includes(rowData.resId) || this.multiSelectionValueOnAllPages.includes(rowData.resId);
}
displayActionOnCondition(action: DataTableActions<TResource>, resource: TResource = undefined): boolean | Observable<boolean> {
// console.error("TEST");
// return true;
displayActionOnCondition(action: DataTableActions<TResource>, resource: TResource = undefined): boolean {
if (!resource || !action.displayOnCondition) {
return this.atLeastOneActionRowDisplayed(action);
}
return action.displayOnCondition(resource);
}
private atLeastOneActionRowDisplayed(action: DataTableActions<TResource>): boolean | Observable<boolean> {
private atLeastOneActionRowDisplayed(action: DataTableActions<TResource>): boolean {
if (!isNonEmptyArray(this._datas)) {
return false;
}
if (isNullOrUndefined(action.displayOnCondition)) {
return true;
}
const atLeastOnActionToDisplay = this.context.mapAtLeastOneActionToDisplay.get(action);
if (atLeastOnActionToDisplay) {
return true;
}
// TODO Find a way to merge all observable
return action.displayOnCondition(this._datas[0]);
return this.context.mapAtLeastOneActionToDisplay.get(action);
}
getWidth(column: DataTableColumns<TResource>): string {
......
......@@ -2,7 +2,6 @@ import {ComponentType} from "@angular/cdk/overlay";
import {
ChangeDetectorRef,
ElementRef,
NgZone,
OnInit,
} from "@angular/core";
import {MatDialog} from "@angular/material/dialog";
......@@ -104,9 +103,9 @@ export abstract class SharedAbstractListRoutable<TResourceModel extends BaseReso
];
}
abstract conditionDisplayEditButton(model: TResourceModel | undefined): boolean | Observable<boolean>;
abstract conditionDisplayEditButton(model: TResourceModel | undefined): boolean;
abstract conditionDisplayDeleteButton(model: TResourceModel | undefined): boolean | Observable<boolean>;
abstract conditionDisplayDeleteButton(model: TResourceModel | undefined): boolean;
goToEdit(model: TResourceModel): void {
this._store.dispatch(new Navigate([StoreRouteLocalUtil.getEditRoute(this._state, model.resId)]));
......
import {Observable} from "rxjs";
import {BaseResource} from "solidify-frontend";
export interface DataTableActions<TResource extends BaseResource = any> {
logo: string;
callback: (current: TResource) => void;
placeholder: string;
displayOnCondition?: (current: TResource) => boolean | Observable<boolean> | undefined;
disableCondition?: (current: TResource) => boolean | Observable<boolean> | undefined;
displayOnCondition?: (current: TResource) => boolean | undefined;
disableCondition?: (current: TResource) => boolean | undefined;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment