diff --git a/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/components/document-tab/document-tab.component.ts b/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/components/document-tab/document-tab.component.ts index c851efac..6b2356f7 100644 --- a/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/components/document-tab/document-tab.component.ts +++ b/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/components/document-tab/document-tab.component.ts @@ -65,6 +65,7 @@ export class DocumentTabComponent implements OnInit, OnDestroy { templateLabels: labelsList = {} as labelsList; actionsImportFn: ActionsImportFunction | null = null; activeFeature: FeaturesKey = {} as FeaturesKey; + endpointData = {} as unknown; constructor( public dialogService: MatDialog, private fb: FormBuilder, @@ -93,8 +94,9 @@ export class DocumentTabComponent implements OnInit, OnDestroy { if (this.activeFeature && this.activeFeature in featureConfig) { this.templateConfigData = featureConfig[FEATURES[featureKey]]( GENERIC_LABELS.DOCUMENT - ) as FeatureData; + ) as unknown as FeatureData; this.templateLabels = this.templateConfigData?.labels; + this.endpointData = this.templateConfigData?.data; this.genericMultiFeatureUtilitiesService.pageTitle.next( this.templateLabels.pageTitle ); @@ -218,18 +220,37 @@ export class DocumentTabComponent implements OnInit, OnDestroy { decodeURIComponent(doc.path) ) : doc.path; - const requestQuery = + const featureEndpointData = this.templateConfigData?.data; + let requestQueryParam = ""; + let requestBodyParam = ""; + if ("queryParam" in featureEndpointData) { + requestQueryParam = + this.genericMultiFeatureUtilitiesService.getRequestQuery( + this.templateConfigData.requestParams as string, + decodedPath + ); + } + + if ("bodyParam" in featureEndpointData) { + requestBodyParam = + this.genericMultiFeatureUtilitiesService.getRequestQuery( + this.templateConfigData.requestParams as string, + decodedPath + ); + } + /* const requestQuery = this.genericMultiFeatureUtilitiesService.getRequestQuery( - this.templateConfigData.requestQuery as string, + this.templateConfigData.requestParams as string, decodedPath - ); + ); */ const featureKey = getFeatureKeyByValue( this.activeFeature ) as FeaturesKey; if (featureKey in FEATURES) { this.store.dispatch( FeatureActions.performDocumentAction({ - requestQuery, + requestQueryParam, + requestBodyParam, featureEndpoint: REST_END_POINTS[featureKey], }) ); diff --git a/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/components/folder-tab/folder-tab.component.ts b/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/components/folder-tab/folder-tab.component.ts index 6ff2e871..a6780e4b 100644 --- a/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/components/folder-tab/folder-tab.component.ts +++ b/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/components/folder-tab/folder-tab.component.ts @@ -73,6 +73,8 @@ export class FolderTabComponent implements OnInit, OnDestroy { templateLabels: labelsList = {} as labelsList; requestQuery = ""; activeFeature: FeaturesKey = {} as FeaturesKey; + requestQueryParam = ""; + requestBodyParam = ""; constructor( public dialogService: MatDialog, @@ -108,7 +110,7 @@ export class FolderTabComponent implements OnInit, OnDestroy { if (this.activeFeature && this.activeFeature in featureConfig) { this.templateConfigData = featureConfig[FEATURES[featureKey]]( GENERIC_LABELS.FOLDER - ) as FeatureData; + ) as unknown as FeatureData; this.templateLabels = this.templateConfigData?.labels; this.genericMultiFeatureUtilitiesService.pageTitle.next( this.templateLabels.pageTitle @@ -209,11 +211,28 @@ export class FolderTabComponent implements OnInit, OnDestroy { decodeURIComponent(this.userInput) ); - this.requestQuery = + const featureEndpointData = this.templateConfigData?.data; + if ("queryParam" in featureEndpointData) { + this.requestQueryParam = + this.genericMultiFeatureUtilitiesService.getRequestQuery( + this.templateConfigData.requestParams as string, + this.decodedUserInput + ); + } + + if ("bodyParam" in featureEndpointData) { + this.requestBodyParam = + this.genericMultiFeatureUtilitiesService.getRequestQuery( + this.templateConfigData.requestParams as string, + this.decodedUserInput + ); + } + + /* this.requestQuery = this.genericMultiFeatureUtilitiesService.getRequestQuery( - this.templateConfigData.requestQuery as string, + this.templateConfigData.requestParams as string, this.decodedUserInput - ); + ); */ this.fetchNoOfDocuments(this.requestQuery as string); } catch (error) { this.showActionErrorModal({ @@ -306,7 +325,8 @@ export class FolderTabComponent implements OnInit, OnDestroy { if (featureKey in FEATURES) { this.store.dispatch( FeatureActions.performFolderAction({ - requestQuery: this.requestQuery, + requestQueryParam: this.requestQueryParam, + requestBodyParam: this.requestBodyParam, featureEndpoint: REST_END_POINTS[featureKey as FeaturesKey], }) ); diff --git a/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/components/nxql-tab/nxql-tab.component.ts b/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/components/nxql-tab/nxql-tab.component.ts index c9786dd8..e52ad714 100644 --- a/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/components/nxql-tab/nxql-tab.component.ts +++ b/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/components/nxql-tab/nxql-tab.component.ts @@ -110,7 +110,7 @@ export class NXQLTabComponent implements OnInit, OnDestroy { if (this.activeFeature && this.activeFeature in featureConfig) { this.templateConfigData = featureConfig[FEATURES[featureKey]]( GENERIC_LABELS.NXQL - ) as FeatureData; + ) as unknown as FeatureData; this.templateLabels = this.templateConfigData?.labels; this.genericMultiFeatureUtilitiesService.pageTitle.next( this.templateLabels.pageTitle diff --git a/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/generic-multi-feature-layout.interface.ts b/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/generic-multi-feature-layout.interface.ts index 183be775..f1416190 100644 --- a/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/generic-multi-feature-layout.interface.ts +++ b/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/generic-multi-feature-layout.interface.ts @@ -38,10 +38,17 @@ export interface GenericModalData { export interface labelsList { pageTitle: string; submitBtnLabel: string; + nxqlQueryDefault?: string; } export interface FeatureData { - requestQuery: string; + requestParams: string; labels: labelsList; + data: RequestParamType; } +export interface RequestParamType { + queryParam: { [key: string]: any }; + bodyParam: { [key: string]: any }; + urlParam: { [key: string]: any }; +} diff --git a/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/generic-multi-feature-layout.mapping.ts b/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/generic-multi-feature-layout.mapping.ts index 3c268ad1..d791b747 100644 --- a/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/generic-multi-feature-layout.mapping.ts +++ b/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/generic-multi-feature-layout.mapping.ts @@ -1,5 +1,6 @@ import { ELASTIC_SEARCH_LABELS } from "../../elastic-search-reindex/elastic-search-reindex.constants"; import { GENERIC_LABELS } from "./generic-multi-feature-layout.constants"; +import { labelsList } from "./generic-multi-feature-layout.interface"; export const FEATURES = { ELASTIC_SEARCH_REINDEX: "elasticsearch-reindex" @@ -20,28 +21,35 @@ export function getFeatureKeyByValue( export const featureMap = () => ({ [FEATURES.ELASTIC_SEARCH_REINDEX]: (tabType: string) => { - let requestQuery: string; - let labels: { pageTitle: string; submitBtnLabel: string }; + let requestParams: string; + let labels: labelsList; + let data = {}; switch (tabType) { case GENERIC_LABELS.DOCUMENT: - (requestQuery = `ecm:path='{queryParam}'`), + (requestParams = `ecm:path='{queryParam}'`), (labels = { pageTitle: ELASTIC_SEARCH_LABELS.DOCUMENT_REINDEX_TITLE, submitBtnLabel: ELASTIC_SEARCH_LABELS.REINDEX_BUTTON_LABEL, }); + (data = { + queryParam: { query: requestParams} + }) break; case GENERIC_LABELS.FOLDER: - (requestQuery = `ecm:uuid='{queryParam}' OR ecm:ancestorId='{queryParam}' ${GENERIC_LABELS.AND} ${GENERIC_LABELS.SELECT_QUERY_CONDITIONS}`), + (requestParams = `ecm:uuid='{queryParam}' OR ecm:ancestorId='{queryParam}' ${GENERIC_LABELS.AND} ${GENERIC_LABELS.SELECT_QUERY_CONDITIONS}`), (labels = { pageTitle: ELASTIC_SEARCH_LABELS.FOLDER_REINDEX_TITLE, submitBtnLabel: ELASTIC_SEARCH_LABELS.REINDEX_BUTTON_LABEL, }); + (data = { + bodyParam: { query: requestParams} + }) break; case GENERIC_LABELS.NXQL: - (requestQuery = `ecm:uuid='{queryParam}' OR ecm:ancestorId='{queryParam}' ${GENERIC_LABELS.AND} ${GENERIC_LABELS.SELECT_QUERY_CONDITIONS}`), + (requestParams = `ecm:uuid='{queryParam}' OR ecm:ancestorId='{queryParam}' ${GENERIC_LABELS.AND} ${GENERIC_LABELS.SELECT_QUERY_CONDITIONS}`), (labels = { pageTitle: ELASTIC_SEARCH_LABELS.NXQL_QUERY_REINDEX_TITLE, submitBtnLabel: ELASTIC_SEARCH_LABELS.REINDEX_BUTTON_LABEL, @@ -53,8 +61,9 @@ export const featureMap = () => ({ } return { - requestQuery, + requestParams, labels, + data }; } }); diff --git a/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/services/generic-multi-feature-endpoints.service.ts b/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/services/generic-multi-feature-endpoints.service.ts index aac066a5..41fdf71e 100644 --- a/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/services/generic-multi-feature-endpoints.service.ts +++ b/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/services/generic-multi-feature-endpoints.service.ts @@ -10,22 +10,24 @@ import { REST_END_POINTS } from "../../../../shared/constants/rest-end-ponts.con export class GenericMultiFeatureEndpointsService { constructor(private networkService: NetworkService) {} performDocumentAction( - requestQuery: string | null, - featureEndpoint: string + requestQueryParam: string | null, + requestBodyParam: string | null, + featureEndpoint: string, ): Observable { return this.networkService.makeHttpRequest( REST_END_POINTS[featureEndpoint as keyof typeof REST_END_POINTS], - { query: requestQuery } + {queryParam: {query: requestQueryParam}, bodyParam: {query: requestBodyParam}} ); } performFolderAction( - requestQuery: string | null, - featureEndpoint: string + requestQueryParam: string | null, + requestBodyParam: string | null, + featureEndpoint: string, ): Observable { return this.networkService.makeHttpRequest( REST_END_POINTS[featureEndpoint as keyof typeof REST_END_POINTS], - { query: requestQuery } + {queryParam: {query: requestQueryParam}, bodyParam: {query: requestBodyParam}} ); } diff --git a/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/store/actions.ts b/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/store/actions.ts index a10907b9..8daeaafd 100644 --- a/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/store/actions.ts +++ b/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/store/actions.ts @@ -4,7 +4,7 @@ import { ActionInfo } from "../generic-multi-feature-layout.interface"; export const performDocumentAction = createAction( "[Admin] Perform Action", - props<{ requestQuery: string | null; featureEndpoint: string }>() + props<{ requestQueryParam: string | null; requestBodyParam: string | null; featureEndpoint: string }>() ); export const onDocumentActionLaunch = createAction( "[Admin] On Action Launch", @@ -19,7 +19,7 @@ export const resetDocumentActionState = createAction( ); export const performFolderAction = createAction( "[Admin] Perform Folder Action", - props<{ requestQuery: string | null; featureEndpoint: string }>() + props<{ requestQueryParam: string | null; requestBodyParam: string | null; featureEndpoint: string }>() ); export const onFolderActionLaunch = createAction( "[Admin] On Folder Action Launch", diff --git a/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/store/effects.ts b/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/store/effects.ts index 85ca82ee..35b1f43e 100644 --- a/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/store/effects.ts +++ b/nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/store/effects.ts @@ -14,7 +14,7 @@ export const loadPerformDocumentActionEffect = createEffect( ofType(FeatureActions.performDocumentAction), switchMap((action) => { return genericMultiFeatureEndpointsService - .performDocumentAction(action?.requestQuery, action?.featureEndpoint) + .performDocumentAction(action?.requestQueryParam, action?.requestBodyParam, action?.featureEndpoint) .pipe( map((data) => { return FeatureActions.onDocumentActionLaunch({ @@ -41,7 +41,7 @@ export const loadPerformFolderActionEffect = createEffect( ofType(FeatureActions.performFolderAction), switchMap((action) => { return genericMultiFeatureEndpointsService - .performFolderAction(action?.requestQuery, action?.featureEndpoint) + .performFolderAction(action?.requestQueryParam, action?.requestBodyParam, action?.featureEndpoint) .pipe( map((data) => { return FeatureActions.onFolderActionLaunch({ diff --git a/nuxeo-admin-console-web/angular-app/src/app/shared/services/network.service.ts b/nuxeo-admin-console-web/angular-app/src/app/shared/services/network.service.ts index 849efe78..5dd14d54 100644 --- a/nuxeo-admin-console-web/angular-app/src/app/shared/services/network.service.ts +++ b/nuxeo-admin-console-web/angular-app/src/app/shared/services/network.service.ts @@ -44,14 +44,41 @@ export class NetworkService { delete data["urlParam"]; } - if (data?.["query"]) { - url += `?query=${data["query"]}`; + // iterate & add + if (data?.["queryParam"]) { + const queryParam = data["queryParam"] as { query: string }; + url += `?query=${queryParam["query"]}`; delete data["query"]; } + /* if (data?.["bodyParam"]) { + const renamedObj = Object.fromEntries( + Object.entries(data).map(([key, value]) => + [`query`, value] + ) + ) + data = renamedObj; + } */ + let bodyParam = {} as { query: string }; + if (data?.["bodyParam"]) { + bodyParam = data["bodyParam"] as { query: string }; + } + + if ( + data?.["bodyParam"] && + typeof data["bodyParam"] === "object" && // Ensure it's an object + "query" in data["bodyParam"] && // Check if "query" exists + typeof (data["bodyParam"] as Record)["query"] === "object" && // Check if 'query' is an object + Object.keys((data["bodyParam"] as Record)["query"]).length > + 0 + ) { + // 'query' is an object and it is not empty + bodyParam = data["bodyParam"] as { query: string }; + } + switch (method) { case "POST": - return this.http.post(url, data || {}); + return this.http.post(url, bodyParam["query"] || {}); break; case "PUT": return this.http.put(url, data || {}); @@ -62,7 +89,7 @@ export class NetworkService { case "GET": if (data) { Object.keys(data).forEach((key) => { - params = params.append(key, String(data[key])); + params = params.append(key, String(data?.[key])); }); } return this.http.get(url, { params }); @@ -71,4 +98,4 @@ export class NetworkService { throw new Error(`Unsupported HTTP method: ${method}`); } } -} \ No newline at end of file +}