diff --git a/ui/ui-frontend-common/src/app/modules/models/nodes/filing-holding-scheme.handler.spec.ts b/ui/ui-frontend-common/src/app/modules/models/nodes/filing-holding-scheme.handler.spec.ts index 9fa50d68bfe..a030fbc73db 100644 --- a/ui/ui-frontend-common/src/app/modules/models/nodes/filing-holding-scheme.handler.spec.ts +++ b/ui/ui-frontend-common/src/app/modules/models/nodes/filing-holding-scheme.handler.spec.ts @@ -63,6 +63,28 @@ export function newUnit(currentId: string, parentId?: string): Unit { }; } +export function newAttachmentUnit(currentId: string, parentId?: string): Unit { + return { + '#id': currentId, + '#unitups': [parentId], + '#allunitups': [parentId], + '#opi': 'whatever', + '#unitType': UnitType.INGEST, + Title: 'whatever', + DescriptionLevel: DescriptionLevel.ITEM, + '#management': { + AppraisalRule: undefined, + HoldRule: undefined, + StorageRule: undefined, + ReuseRule: undefined, + ClassificationRule: undefined, + DisseminationRule: undefined, + AccessRule: undefined, + UpdateOperation: { SystemId: currentId }, + } + }; +} + export function newResultFacet(id: string, count?: number): ResultFacet { return { node: id, count }; } @@ -192,8 +214,8 @@ describe('FilingHoldingSchemeHandler', () => { expect(uaNodes[3].children[1].id).toEqual('node-3-1'); expect(uaNodes[3].children[1].count).toEqual(1); }); - }); + describe('keepEndNodesWithResultsOnly', () => { it('should keep ends results only', () => { const treePlanNodes: FilingHoldingSchemeNode[] = [ @@ -228,8 +250,8 @@ describe('FilingHoldingSchemeHandler', () => { newTreeNode('node-4', 0), ]; const leaves: FilingHoldingSchemeNode[] = FilingHoldingSchemeHandler.keepEndNodesWithResultsOnly(treePlanNodes); - expect(leaves.length).toEqual(3); + expect(leaves.length).toEqual(3); expect(leaves[0].id).toEqual('node-0-0-1'); expect(leaves[0].count).toEqual(1); expect(leaves[1].id).toEqual('node-0-3'); @@ -269,9 +291,10 @@ describe('FilingHoldingSchemeHandler', () => { newTreeNode('node-3', 0), newTreeNode('node-4', 0), ]; + const leaves: FilingHoldingSchemeNode[] = FilingHoldingSchemeHandler.keepEndNodesWithResultsOnly(treePlanNodes); - expect(leaves.length).toEqual(5); + expect(leaves.length).toEqual(5); expect(leaves[0].id).toEqual('node-0-0'); expect(leaves[0].count).toEqual(18); expect(leaves[1].id).toEqual('node-0-0-0'); @@ -284,6 +307,176 @@ describe('FilingHoldingSchemeHandler', () => { expect(leaves[4].count).toEqual(1); }); }); + + describe('keepEndNodesWithResultsThatAreNOTAttachmentUnitsOnly', () => { + it('should return an empty array if the nodes array is empty', () => { + const attachmentUnits: Unit[] = []; + const treePlanNodes: FilingHoldingSchemeNode[] = []; + + const leaves: FilingHoldingSchemeNode[] = FilingHoldingSchemeHandler.keepEndNodesWithResultsThatAreNOTAttachmentUnitsOnly( + treePlanNodes, attachmentUnits); + + expect(leaves).toEqual([]); + }); + + it('should return an empty array if the attachmentUnits array is empty', () => { + const attachmentUnits: Unit[] = []; + const treePlanNodes: FilingHoldingSchemeNode[] = [ + newTreeNode('node-0', 3, [ + newTreeNode('node-0-0', 1, [ + newTreeNode('node-0-0-0', 0), + newTreeNode('node-0-0-1', 1), + newTreeNode('node-0-0-2', 0), + newTreeNode('node-0-0-3', 0), + newTreeNode('node-0-0-4', 0), + ]), + newTreeNode('node-0-1', 0), + newTreeNode('node-0-2', 0), + newTreeNode('node-0-3', 2), + newTreeNode('node-0-4', 0), + ]), + newTreeNode('node-1', 0, [ + newTreeNode('node-1-0', 0), + newTreeNode('node-1-1', 0), + newTreeNode('node-1-2', 0), + newTreeNode('node-1-3', 0), + newTreeNode('node-1-4', 0), + ]), + newTreeNode('node-2', 1, [ + newTreeNode('node-2-0', 0), + newTreeNode('node-2-1', 0), + newTreeNode('node-2-2', 1), + newTreeNode('node-2-3', 0), + newTreeNode('node-2-4', 0), + ]), + newTreeNode('node-3', 0), + newTreeNode('node-4', 0), + ]; + + const leaves: FilingHoldingSchemeNode[] = FilingHoldingSchemeHandler.keepEndNodesWithResultsThatAreNOTAttachmentUnitsOnly( + treePlanNodes, attachmentUnits); + + console.log(JSON.stringify(leaves)); + expect(leaves.length).toEqual(6); + expect(leaves[0].id).toEqual('node-0'); + expect(leaves[0].count).toEqual(3); + expect(leaves[1].id).toEqual('node-0-0'); + expect(leaves[1].count).toEqual(1); + expect(leaves[2].id).toEqual('node-0-0'); + expect(leaves[2].count).toEqual(1); + expect(leaves[3].id).toEqual('node-0'); + expect(leaves[3].count).toEqual(3); + expect(leaves[4].id).toEqual('node-2'); + expect(leaves[4].count).toEqual(1); + expect(leaves[5].id).toEqual('node-2'); + expect(leaves[5].count).toEqual(1); + }); + + it('should keep ends results only, and only if they are attachment units', () => { + const attachmentUnits: Unit[] = [newAttachmentUnit('node-0-3'), newAttachmentUnit('node-2-2')]; + const treePlanNodes: FilingHoldingSchemeNode[] = [ + newTreeNode('node-0', 3, [ + newTreeNode('node-0-0', 1, [ + newTreeNode('node-0-0-0', 0), + newTreeNode('node-0-0-1', 1), + newTreeNode('node-0-0-2', 0), + newTreeNode('node-0-0-3', 0), + newTreeNode('node-0-0-4', 0), + ]), + newTreeNode('node-0-1', 0), + newTreeNode('node-0-2', 0), + newTreeNode('node-0-3', 2), + newTreeNode('node-0-4', 0), + ]), + newTreeNode('node-1', 0, [ + newTreeNode('node-1-0', 0), + newTreeNode('node-1-1', 0), + newTreeNode('node-1-2', 0), + newTreeNode('node-1-3', 0), + newTreeNode('node-1-4', 0), + ]), + newTreeNode('node-2', 1, [ + newTreeNode('node-2-0', 0), + newTreeNode('node-2-1', 0), + newTreeNode('node-2-2', 1), + newTreeNode('node-2-3', 0), + newTreeNode('node-2-4', 0), + ]), + newTreeNode('node-3', 0), + newTreeNode('node-4', 0), + ]; + + const leaves: FilingHoldingSchemeNode[] = FilingHoldingSchemeHandler.keepEndNodesWithResultsThatAreNOTAttachmentUnitsOnly( + treePlanNodes, attachmentUnits); + + expect(leaves.length).toEqual(6); + expect(leaves[0].id).toEqual('node-0-0'); + expect(leaves[0].count).toEqual(1); + expect(leaves[1].id).toEqual('node-0-0'); + expect(leaves[1].count).toEqual(1); + expect(leaves[2].id).toEqual('node-0-3'); + expect(leaves[2].count).toEqual(2); + expect(leaves[3].id).toEqual('node-0'); + expect(leaves[3].count).toEqual(3); + expect(leaves[4].id).toEqual('node-2-2'); + expect(leaves[4].count).toEqual(1); + expect(leaves[5].id).toEqual('node-2'); + expect(leaves[5].count).toEqual(1); + }); + + it('should keep ends results only and parent if parent has more match ?', () => { + const attachmentUnits: Unit[] = [newAttachmentUnit('node-0-0-1'), newAttachmentUnit('node-0-3'), newAttachmentUnit('node-2-2')]; + const treePlanNodes: FilingHoldingSchemeNode[] = [ + newTreeNode('node-0', 3, [ + newTreeNode('node-0-0', 1, [ + newTreeNode('node-0-0-0', 0), + newTreeNode('node-0-0-1', 1), + newTreeNode('node-0-0-2', 0), + newTreeNode('node-0-0-3', 0), + newTreeNode('node-0-0-4', 0), + ]), + newTreeNode('node-0-1', 0), + newTreeNode('node-0-2', 0), + newTreeNode('node-0-3', 2), + newTreeNode('node-0-4', 0), + ]), + newTreeNode('node-1', 0, [ + newTreeNode('node-1-0', 0), + newTreeNode('node-1-1', 0), + newTreeNode('node-1-2', 0), + newTreeNode('node-1-3', 0), + newTreeNode('node-1-4', 0), + ]), + newTreeNode('node-2', 1, [ + newTreeNode('node-2-0', 0), + newTreeNode('node-2-1', 0), + newTreeNode('node-2-2', 1), + newTreeNode('node-2-3', 0), + newTreeNode('node-2-4', 0), + ]), + newTreeNode('node-3', 0), + newTreeNode('node-4', 0), + ]; + + const leaves: FilingHoldingSchemeNode[] = FilingHoldingSchemeHandler.keepEndNodesWithResultsThatAreNOTAttachmentUnitsOnly( + treePlanNodes, attachmentUnits); + + expect(leaves.length).toEqual(6); + expect(leaves[0].id).toEqual('node-0-0-1'); + expect(leaves[0].count).toEqual(1); + expect(leaves[1].id).toEqual('node-0-0'); + expect(leaves[1].count).toEqual(1); + expect(leaves[2].id).toEqual('node-0-3'); + expect(leaves[2].count).toEqual(2); + expect(leaves[3].id).toEqual('node-0'); + expect(leaves[3].count).toEqual(3); + expect(leaves[4].id).toEqual('node-2-2'); + expect(leaves[4].count).toEqual(1); + expect(leaves[5].id).toEqual('node-2'); + expect(leaves[5].count).toEqual(1); + }); + }); + describe('unitHasDirectParent', () => { it('should be true when unitups does not contains the id', () => { const unit = newUnit('node-2-3', 'node-2'); @@ -335,14 +528,15 @@ describe('FilingHoldingSchemeHandler', () => { expect(toggleNode.children[6].count).toEqual(1); }); }); + describe('filterUnknownFacets', () => { it('should return an empty array if the newFacets array is full of already known facets', () => { - const oldFacets: ResultFacet[] = [{ node: 'node-0', count: 1 }, { node: 'node-1', count: 65 }, ]; - const newFacets: ResultFacet[] = [{ node: 'node-0', count: 5 }, { node: 'node-1', count: 42 }, ]; + const oldFacets: ResultFacet[] = [{ node: 'node-0', count: 1 }, { node: 'node-1', count: 65 }]; + const newFacets: ResultFacet[] = [{ node: 'node-0', count: 5 }, { node: 'node-1', count: 42 }]; expect(FilingHoldingSchemeHandler.filterUnknownFacets(oldFacets, newFacets)).toEqual([]); }); it('should return all the facets in the newFacets array if there are no known facets', () => { - const oldFacets: ResultFacet[] = [{ node: 'node-0', count: 1 }, { node: 'node-1', count: 65 }, ]; + const oldFacets: ResultFacet[] = [{ node: 'node-0', count: 1 }, { node: 'node-1', count: 65 }]; const newFacets = [{ node: 'node-2', count: 5 }]; expect(FilingHoldingSchemeHandler.filterUnknownFacets(oldFacets, newFacets)).toEqual(newFacets); }); @@ -352,7 +546,7 @@ describe('FilingHoldingSchemeHandler', () => { expect(FilingHoldingSchemeHandler.filterUnknownFacets(oldFacets, newFacets)).toEqual(newFacets); }); it('should return an empty array if the newFacets array is empty', () => { - const oldFacets: ResultFacet[] = [{ node: 'node-0', count: 1 }, { node: 'node-1', count: 65 }, ]; + const oldFacets: ResultFacet[] = [{ node: 'node-0', count: 1 }, { node: 'node-1', count: 65 }]; const newFacets: ResultFacet[] = []; expect(FilingHoldingSchemeHandler.filterUnknownFacets(oldFacets, newFacets)).toEqual([]); }); @@ -367,7 +561,7 @@ describe('FilingHoldingSchemeHandler', () => { }); it('should return all the facets in the facets array if there are no known nodes', () => { const nodes: FilingHoldingSchemeNode[] = []; - const facets: ResultFacet[] = [newResultFacet('node-1'), newResultFacet('node-2'), ]; + const facets: ResultFacet[] = [newResultFacet('node-1'), newResultFacet('node-2')]; const unknownFacets: ResultFacet[] = FilingHoldingSchemeHandler.filterUnknownFacetsIds(nodes, facets); expect(unknownFacets).toEqual(facets); }); @@ -379,6 +573,7 @@ describe('FilingHoldingSchemeHandler', () => { expect(unknownFacets).toEqual([unknowFacet]); }); }); + describe('foundChild', () => { it('should return undefined when children is empty', () => { const parentNode = newTreeNode('node-1', 0, []); @@ -393,6 +588,39 @@ describe('FilingHoldingSchemeHandler', () => { expect(FilingHoldingSchemeHandler.foundChild(parentNode, 'node-1-1')).toEqual(nodeToFound); }); }); + + describe('foundNode', () => { + it('should return null if the nodes array is empty', () => { + const nodes: FilingHoldingSchemeNode[] = []; + const nodeId = '12345'; + const actual = FilingHoldingSchemeHandler.foundNode(nodes, nodeId); + expect(actual).toBe(null); + }); + + it('should return false if the node with the specified ID is not found', () => { + const nodes: FilingHoldingSchemeNode[] = [newNode('node-1'), newNode('node-2')]; + const actual = FilingHoldingSchemeHandler.foundNode(nodes, 'bad-id'); + expect(actual).toBe(null); + }); + + it('should set the checked property of the node with the specified ID to true', () => { + const nodes = [newNode('node-1')]; + const actual = FilingHoldingSchemeHandler.foundNode(nodes, 'node-1'); + expect(actual).toBeDefined(); + expect(actual.id).toBe('node-1'); + }); + + it('should recursively search the child nodes if the node with the specified ID is not found', () => { + const nodes: FilingHoldingSchemeNode[] = [ + newTreeNode('node-1', 1, [newNode('node-1-1')]), + newTreeNode('node-2', 1, [newNode('node-2-1')]), + ]; + const actual = FilingHoldingSchemeHandler.foundNode(nodes, 'node-2-1'); + expect(actual).toBeDefined(); + expect(actual.id).toBe('node-2-1'); + }); + }); + describe('foundNodeAndSetCheck', () => { it('should return false if the nodes array is empty', () => { const nodes: FilingHoldingSchemeNode[] = []; @@ -435,6 +663,7 @@ describe('FilingHoldingSchemeHandler', () => { expect(nodes[0].children[0].checked).toBe(checked); }); }); + describe('getCountSum', () => { it('should return 0 if the nodes array is empty', () => { const nodes: FilingHoldingSchemeNode[] = []; @@ -443,7 +672,7 @@ describe('FilingHoldingSchemeHandler', () => { }); it('should return the sum of the counts of all the nodes in the array if the array is not empty', () => { const nodes: FilingHoldingSchemeNode[] = [ - newTreeNode('node-1', 1, [newTreeNode('node-1-1', 1), newTreeNode('node-1-2', 1), ]), + newTreeNode('node-1', 1, [newTreeNode('node-1-1', 1), newTreeNode('node-1-2', 1)]), newTreeNode('node-2', 2), newTreeNode('node-3', 3), newTreeNode('node-4', 1), diff --git a/ui/ui-frontend-common/src/app/modules/models/nodes/filing-holding-scheme.handler.ts b/ui/ui-frontend-common/src/app/modules/models/nodes/filing-holding-scheme.handler.ts index df5726e0587..b98dba6d3ef 100644 --- a/ui/ui-frontend-common/src/app/modules/models/nodes/filing-holding-scheme.handler.ts +++ b/ui/ui-frontend-common/src/app/modules/models/nodes/filing-holding-scheme.handler.ts @@ -35,23 +35,29 @@ export const ORPHANS_NODE_ID = 'ORPHANS_NODE'; export class FilingHoldingSchemeHandler { - public static foundNodeAndSetCheck(nodes: FilingHoldingSchemeNode[], checked: boolean, nodeId: string): boolean { + public static foundNode(nodes: FilingHoldingSchemeNode[], nodeId: string): FilingHoldingSchemeNode { if (isEmpty(nodes)) { - return false; + return null; } - let nodeHasBeenChecked = false; for (const node of nodes) { if (node.id === nodeId) { - node.checked = checked; - nodeHasBeenChecked = true; - } else if (node.children) { - nodeHasBeenChecked = FilingHoldingSchemeHandler.foundNodeAndSetCheck(node.children, checked, nodeId); + return node; } - if (nodeHasBeenChecked) { - break; + const nodeFound = FilingHoldingSchemeHandler.foundNode(node.children, nodeId); + if (nodeFound) { + return nodeFound; } } - return nodeHasBeenChecked; + return null; + } + + public static foundNodeAndSetCheck(nodes: FilingHoldingSchemeNode[], checked: boolean, nodeId: string): boolean { + const node = FilingHoldingSchemeHandler.foundNode(nodes, nodeId); + if (node) { + node.checked = checked; + return true; + } + return false; } public static updateCountOnOrphansNode(parentNodes: FilingHoldingSchemeNode[], count: number): boolean { @@ -201,8 +207,8 @@ export class FilingHoldingSchemeHandler { return !FilingHoldingSchemeHandler.oneUnitHasUpdateOperationId(nodeId, units); } - public static keepEndNodesWithResultsOnlyAndCheckAttach(nodes: FilingHoldingSchemeNode[], - attachmentUnits: Unit[]): FilingHoldingSchemeNode[] { + public static keepEndNodesWithResultsThatAreNOTAttachmentUnitsOnly(nodes: FilingHoldingSchemeNode[], + attachmentUnits: Unit[]): FilingHoldingSchemeNode[] { if (!nodes) { return []; } @@ -212,14 +218,14 @@ export class FilingHoldingSchemeHandler { continue; } if (isEmpty(node.children)) { - if (FilingHoldingSchemeHandler.nodeIsNotAttachmentUnit(node.id, attachmentUnits)) { + if (!attachmentUnits.some((unit) => unit['#management'].UpdateOperation.SystemId === node.id)) { continue; } leaves.push(copyNodeWithoutChildren(node)); continue; } - const childResult: FilingHoldingSchemeNode[] = FilingHoldingSchemeHandler.keepEndNodesWithResultsOnlyAndCheckAttach(node.children, - attachmentUnits); + const childResult: FilingHoldingSchemeNode[] = FilingHoldingSchemeHandler.keepEndNodesWithResultsThatAreNOTAttachmentUnitsOnly( + node.children, attachmentUnits); const addedCount = childResult.reduce((accumulator, schemeNode) => accumulator + schemeNode.count, 0); if (addedCount < node.count) { const nodeCopy = copyNodeWithoutChildren(node); @@ -281,7 +287,7 @@ export class FilingHoldingSchemeHandler { } else { child.count = 0; } - } else if (initCount && child.count < 1) { + } else if (initCount && (!child.count || child.count < 1)) { child.count = 1; matchingNodes.incrementUpdated(); } else { diff --git a/ui/ui-frontend-common/src/app/modules/services/leaves-tree-api.service.spec.ts b/ui/ui-frontend-common/src/app/modules/services/leaves-tree-api.service.spec.ts index a002beebb6d..fd447216d3d 100644 --- a/ui/ui-frontend-common/src/app/modules/services/leaves-tree-api.service.spec.ts +++ b/ui/ui-frontend-common/src/app/modules/services/leaves-tree-api.service.spec.ts @@ -1,7 +1,7 @@ import { of } from 'rxjs'; import { CriteriaDataType, CriteriaOperator, CriteriaValue, DescriptionLevel, FilingHoldingSchemeNode, PagedResult, SearchCriteriaDto, - SearchCriteriaEltDto, SearchCriteriaSort, SearchCriteriaTypeEnum, UnitType + SearchCriteriaEltDto, SearchCriteriaSort, SearchCriteriaTypeEnum, Unit, UnitType } from '../models'; import { newNode } from '../models/nodes/filing-holding-scheme.handler.spec'; import { DEFAULT_UNIT_PAGE_SIZE, LeavesTreeApiService } from './leaves-tree-api.service'; @@ -78,7 +78,7 @@ export function newSearchCriteriaDto( } export function newPagedResult( - results = [], + results: Unit[] = [], totalResults = 0, pageNumbers = 0, ): PagedResult { @@ -493,7 +493,7 @@ describe('FilingHoldingSchemeNodeService', () => { const pagedResult = newPagedResult(); searchArchiveUnitsByCriteriaSpy.searchArchiveUnitsByCriteria.and.returnValue(of(pagedResult)); - const result = leavesTreeApiService.searchOrphansWithSearchCriterias(parentNode, searchCriterias); + const result = leavesTreeApiService.searchUnderNodeWithSearchCriterias(parentNode, searchCriterias); result.subscribe((results) => { expect(results).toEqual(pagedResult); @@ -516,11 +516,77 @@ describe('FilingHoldingSchemeNodeService', () => { }], dataType: 'dataType-searchUnderNodeWithSearchCriterias' }, + { + criteria: '#unitups', + operator: CriteriaOperator.IN, + category: SearchCriteriaTypeEnum.FIELDS, + values: [{ id: 'node-0', value: 'node-0' }], + dataType: CriteriaDataType.STRING, + }, + ], + sortingCriteria: searchCriterias.sortingCriteria, + trackTotalHits: false, + computeFacets: false, + }, undefined); + }); + }); + + describe('searchAtNodeWithSearchCriterias', () => { + it('should return EMPTY observable if can not load more matching children', () => { + const parentNode = newNode('node-0', []); + leavesTreeApiService.firstToggle(parentNode); + const searchCriterias = newSearchCriteriaDto(); + searchArchiveUnitsByCriteriaSpy.searchArchiveUnitsByCriteria.and.returnValue(of(newPagedResult())); + parentNode.canLoadMoreMatchingChildren = false; + + const result = leavesTreeApiService.searchAtNodeWithSearchCriterias(parentNode, searchCriterias); + + result.subscribe((results) => { + throw new Error('should be EMPTY: searchAtNodeWithSearchCriterias'); + }); + }); + + it('should send a search request with the criteria passed', () => { + const parentNode = newNode('node-0', []); + leavesTreeApiService.firstToggle(parentNode); + const searchCriterias = newSearchCriteriaDto([newSearchCriteriaEltDto( + 'criteria-searchAtNodeWithSearchCriterias', + 'operator-searchAtNodeWithSearchCriterias', + 'category-searchAtNodeWithSearchCriterias', + [newCriteriaValue('criteria-value-searchAtNodeWithSearchCriterias')], + 'dataType-searchAtNodeWithSearchCriterias', + )]); + const pagedResult = newPagedResult(); + searchArchiveUnitsByCriteriaSpy.searchArchiveUnitsByCriteria.and.returnValue(of(pagedResult)); + + const result = leavesTreeApiService.searchAtNodeWithSearchCriterias(parentNode, searchCriterias); + + result.subscribe((results) => { + expect(results).toEqual(pagedResult); + }); + expect(searchArchiveUnitsByCriteriaSpy.searchArchiveUnitsByCriteria).toHaveBeenCalledTimes(1); + expect(searchArchiveUnitsByCriteriaSpy.searchArchiveUnitsByCriteria).toHaveBeenCalledWith({ + pageNumber: Math.floor(parentNode.paginatedChildrenLoaded / DEFAULT_UNIT_PAGE_SIZE), + size: DEFAULT_UNIT_PAGE_SIZE, + criteriaList: [ + { + criteria: 'criteria-searchAtNodeWithSearchCriterias', + operator: 'operator-searchAtNodeWithSearchCriterias', + category: 'category-searchAtNodeWithSearchCriterias', + values: [{ + id: 'criteria-value-searchAtNodeWithSearchCriterias', + value: undefined, + label: undefined, + beginInterval: undefined, + endInterval: undefined + }], + dataType: 'dataType-searchAtNodeWithSearchCriterias' + }, { criteria: '#allunitups', - operator: CriteriaOperator.MISSING, + operator: CriteriaOperator.EQ, category: SearchCriteriaTypeEnum.FIELDS, - values: [], + values: [{ id: 'node-0', value: 'node-0' }], dataType: CriteriaDataType.STRING, }, ], @@ -530,4 +596,5 @@ describe('FilingHoldingSchemeNodeService', () => { }, undefined); }); }); + }); diff --git a/ui/ui-frontend-common/src/app/modules/services/leaves-tree-api.service.ts b/ui/ui-frontend-common/src/app/modules/services/leaves-tree-api.service.ts index 993ebab0b4b..2bf002b974c 100644 --- a/ui/ui-frontend-common/src/app/modules/services/leaves-tree-api.service.ts +++ b/ui/ui-frontend-common/src/app/modules/services/leaves-tree-api.service.ts @@ -149,6 +149,33 @@ export class LeavesTreeApiService { } searchUnderNodeWithSearchCriterias(parentNode: FilingHoldingSchemeNode, searchCriterias: SearchCriteriaDto): Observable { + if (!this.prepareSearch(parentNode, true)) { + return EMPTY; + } + const newCriteriaList = [...searchCriterias.criteriaList]; + newCriteriaList.push({ + criteria: '#unitups', + operator: CriteriaOperator.IN, + category: SearchCriteriaTypeEnum.FIELDS, + values: [{ id: parentNode.id, value: parentNode.id }], + dataType: CriteriaDataType.STRING, + }); + const searchCriteria: SearchCriteriaDto = { + pageNumber: Math.floor(parentNode.paginatedMatchingChildrenLoaded / DEFAULT_UNIT_PAGE_SIZE), + size: DEFAULT_UNIT_PAGE_SIZE, + criteriaList: newCriteriaList, + sortingCriteria: searchCriterias.sortingCriteria, + trackTotalHits: false, + computeFacets: false, + }; + return this.sendSearchArchiveUnitsByCriteria(searchCriteria) + .pipe(map(pagedResult => { + this.finishSearch(parentNode, pagedResult, true); + return pagedResult; + })); + } + + searchAtNodeWithSearchCriterias(parentNode: FilingHoldingSchemeNode, searchCriterias: SearchCriteriaDto): Observable { if (!this.prepareSearch(parentNode, true)) { return EMPTY; } diff --git a/ui/ui-frontend-common/src/app/modules/services/leaves-tree.service.spec.ts b/ui/ui-frontend-common/src/app/modules/services/leaves-tree.service.spec.ts index e69de29bb2d..fbaddf2f783 100644 --- a/ui/ui-frontend-common/src/app/modules/services/leaves-tree.service.spec.ts +++ b/ui/ui-frontend-common/src/app/modules/services/leaves-tree.service.spec.ts @@ -0,0 +1,318 @@ +/* + * Copyright French Prime minister Office/SGMAP/DINSIC/Vitam Program (2015-2022) + * + * contact.vitam@culture.gouv.fr + * + * This software is a computer program whose purpose is to implement a digital archiving back-office system managing + * high volumetry securely and efficiently. + * + * This software is governed by the CeCILL 2.1 license under French law and abiding by the rules of distribution of free + * software. You can use, modify and/ or redistribute the software under the terms of the CeCILL 2.1 license as + * circulated by CEA, CNRS and INRIA at the following URL "https://cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, + * users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the + * successive licensors have only limited liability. + * + * In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or + * developing or reproducing the software by the user in light of its specific status of free software, that may mean + * that it is complicated to manipulate, and that also therefore means that it is reserved for developers and + * experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the + * software's suitability as regards their requirements in conditions enabling the security of their systems and/or data + * to be ensured and, more generally, to use and operate it in the same conditions as regards security. + * + * The fact that you are presently reading this means that you have had knowledge of the CeCILL 2.1 license and that you + * accept its terms. + */ +import { of } from 'rxjs'; +import { newNode, newResultFacet, newTreeNode, newUnit } from '../models/nodes/filing-holding-scheme.handler.spec'; +import { LeavesTreeApiService } from './leaves-tree-api.service'; +import { newPagedResult } from './leaves-tree-api.service.spec'; +import { LeavesTreeService } from './leaves-tree.service'; +import { SearchArchiveUnitsInterface } from './search-archive-units.interface'; + +describe('LeavesTreeService', () => { + let leavesTreeService: LeavesTreeService; + const searchArchiveUnitsByCriteriaSpy = jasmine.createSpyObj('SearchArchiveUnitsInterface', ['searchArchiveUnitsByCriteria']); + const leavesTreeApiServiceSpy = jasmine.createSpyObj('LeavesTreeApiService', [ + 'firstToggle', + 'prepareSearch', + 'finishSearch', + 'searchOrphans', + 'searchOrphansWithSearchCriterias', + 'searchUnderNode', + 'searchUnderNodeWithSearchCriterias', + 'loadNodesDetailsFromFacetsIds', + 'searchAttachementUnit', + 'sendSearchArchiveUnitsByCriteria', + 'searchAtNodeWithSearchCriterias', + 'setTransactionId' + ]); + + beforeEach(() => { + leavesTreeApiServiceSpy.firstToggle.calls.reset(); + leavesTreeApiServiceSpy.prepareSearch.calls.reset(); + leavesTreeApiServiceSpy.finishSearch.calls.reset(); + leavesTreeApiServiceSpy.searchOrphans.calls.reset(); + leavesTreeApiServiceSpy.searchOrphansWithSearchCriterias.calls.reset(); + leavesTreeApiServiceSpy.searchUnderNode.calls.reset(); + leavesTreeApiServiceSpy.searchUnderNodeWithSearchCriterias.calls.reset(); + leavesTreeApiServiceSpy.loadNodesDetailsFromFacetsIds.calls.reset(); + leavesTreeApiServiceSpy.searchAttachementUnit.calls.reset(); + leavesTreeApiServiceSpy.sendSearchArchiveUnitsByCriteria.calls.reset(); + leavesTreeApiServiceSpy.searchAtNodeWithSearchCriterias.calls.reset(); + leavesTreeApiServiceSpy.setTransactionId.calls.reset(); + leavesTreeService = new LeavesTreeService(searchArchiveUnitsByCriteriaSpy); + // @ts-ignore + leavesTreeService.leavesTreeApiService = leavesTreeApiServiceSpy; + }); + + describe('searchUnderNode', () => { + it('should not add children if parentId does not match', () => { + const parentNode = newNode('node-0', []); + const pagedResult = newPagedResult([newUnit('node-0-1', 'node-bad'), newUnit('node-0-2')]); + leavesTreeApiServiceSpy.searchUnderNode.and.returnValue(of(pagedResult)); + + const result = leavesTreeService.searchUnderNode(parentNode); + result.subscribe((results) => { + expect(results).toEqual(pagedResult); + }); + + expect(leavesTreeApiServiceSpy.searchUnderNode).toHaveBeenCalledTimes(1); + expect(parentNode.children).toEqual([]); + }); + it('should add children', () => { + const parentNode = newNode('node-0', []); + const pagedResult = newPagedResult([newUnit('node-0-1', 'node-0'), newUnit('node-0-2', 'node-0')]); + leavesTreeApiServiceSpy.searchUnderNode.and.returnValue(of(pagedResult)); + + const result = leavesTreeService.searchUnderNode(parentNode); + result.subscribe((results) => { + expect(results).toEqual(pagedResult); + }); + + expect(leavesTreeApiServiceSpy.searchUnderNode).toHaveBeenCalledTimes(1); + expect(parentNode.children[0].id).toEqual('node-0-1'); + expect(parentNode.children[0].count).toEqual(0); + expect(parentNode.children[1].id).toEqual('node-0-2'); + expect(parentNode.children[1].count).toEqual(0); + }); + it('should not add children if already present', () => { + const parentNode = newNode('node-0', [newTreeNode('node-0-1', 2), newTreeNode('node-0-2', 2)]); + const pagedResult = newPagedResult([newUnit('node-0-1', 'node-0'), newUnit('node-0-2', 'node-0')]); + leavesTreeApiServiceSpy.searchUnderNode.and.returnValue(of(pagedResult)); + + const result = leavesTreeService.searchUnderNode(parentNode); + result.subscribe((results) => { + expect(results).toEqual(pagedResult); + }); + + expect(leavesTreeApiServiceSpy.searchUnderNode).toHaveBeenCalledTimes(1); + expect(parentNode.children[0].id).toEqual('node-0-1'); + expect(parentNode.children[0].count).toEqual(2); + expect(parentNode.children[1].id).toEqual('node-0-2'); + expect(parentNode.children[1].count).toEqual(2); + }); + it('should add children and check facets', () => { + const parentNode = newNode('node-0', []); + leavesTreeService.setSearchRequestResultFacets([ + newResultFacet('node-0', 5), + newResultFacet('node-0-1', 5), + newResultFacet('node-0-2', 7)]); + const pagedResult = newPagedResult([newUnit('node-0-1', 'node-0'), newUnit('node-0-2', 'node-0')]); + leavesTreeApiServiceSpy.searchUnderNode.and.returnValue(of(pagedResult)); + + const result = leavesTreeService.searchUnderNode(parentNode); + result.subscribe((results) => { + expect(results).toEqual(pagedResult); + }); + + expect(leavesTreeApiServiceSpy.searchUnderNode).toHaveBeenCalledTimes(1); + expect(parentNode.children[0].id).toEqual('node-0-1'); + expect(parentNode.children[0].count).toEqual(5); + expect(parentNode.children[1].id).toEqual('node-0-2'); + expect(parentNode.children[1].count).toEqual(7); + }); + }); + + + describe('searchUnderNodeWithSearchCriterias', () => { + it('should not add children if parentId does not match', () => { + const parentNode = newNode('node-0', []); + const pagedResult = newPagedResult([newUnit('node-0-1', 'node-bad'), newUnit('node-0-2')]); + leavesTreeApiServiceSpy.searchUnderNodeWithSearchCriterias.and.returnValue(of(pagedResult)); + + const result = leavesTreeService.searchUnderNodeWithSearchCriterias(parentNode); + result.subscribe((results) => { + expect(results).toEqual(pagedResult); + }); + + expect(leavesTreeApiServiceSpy.searchUnderNodeWithSearchCriterias).toHaveBeenCalledTimes(1); + expect(parentNode.children).toEqual([]); + }); + it('should add children', () => { + const parentNode = newNode('node-0', []); + const pagedResult = newPagedResult([newUnit('node-0-1', 'node-0'), newUnit('node-0-2', 'node-0')]); + leavesTreeApiServiceSpy.searchUnderNodeWithSearchCriterias.and.returnValue(of(pagedResult)); + + const result = leavesTreeService.searchUnderNodeWithSearchCriterias(parentNode); + result.subscribe((results) => { + expect(results).toEqual(pagedResult); + }); + + expect(leavesTreeApiServiceSpy.searchUnderNodeWithSearchCriterias).toHaveBeenCalledTimes(1); + expect(parentNode.children[0].id).toEqual('node-0-1'); + expect(parentNode.children[0].count).toEqual(1); + expect(parentNode.children[1].id).toEqual('node-0-2'); + expect(parentNode.children[1].count).toEqual(1); + }); + it('should not add children if already present', () => { + const parentNode = newNode('node-0', [newTreeNode('node-0-1', 2), newTreeNode('node-0-2', 2)]); + const pagedResult = newPagedResult([newUnit('node-0-1', 'node-0'), newUnit('node-0-2', 'node-0')]); + leavesTreeApiServiceSpy.searchUnderNodeWithSearchCriterias.and.returnValue(of(pagedResult)); + + const result = leavesTreeService.searchUnderNodeWithSearchCriterias(parentNode); + result.subscribe((results) => { + expect(results).toEqual(pagedResult); + }); + + expect(leavesTreeApiServiceSpy.searchUnderNodeWithSearchCriterias).toHaveBeenCalledTimes(1); + expect(parentNode.children[0].id).toEqual('node-0-1'); + expect(parentNode.children[0].count).toEqual(2); + expect(parentNode.children[1].id).toEqual('node-0-2'); + expect(parentNode.children[1].count).toEqual(2); + }); + it('should not add children if already present but init count', () => { + const parentNode = newNode('node-0', [newNode('node-0-1'), newTreeNode('node-0-2', 0)]); + const pagedResult = newPagedResult([newUnit('node-0-1', 'node-0'), newUnit('node-0-2', 'node-0')]); + leavesTreeApiServiceSpy.searchUnderNodeWithSearchCriterias.and.returnValue(of(pagedResult)); + + const result = leavesTreeService.searchUnderNodeWithSearchCriterias(parentNode); + result.subscribe((results) => { + expect(results).toEqual(pagedResult); + }); + + expect(leavesTreeApiServiceSpy.searchUnderNodeWithSearchCriterias).toHaveBeenCalledTimes(1); + expect(parentNode.children[0].id).toEqual('node-0-1'); + expect(parentNode.children[0].count).toEqual(1); + expect(parentNode.children[1].id).toEqual('node-0-2'); + expect(parentNode.children[1].count).toEqual(1); + }); + it('should add children and check facets', () => { + const parentNode = newNode('node-0', []); + leavesTreeService.setSearchRequestResultFacets([ + newResultFacet('node-0', 5), + newResultFacet('node-0-1', 5), + newResultFacet('node-0-2', 7)]); + const pagedResult = newPagedResult([newUnit('node-0-1', 'node-0'), newUnit('node-0-2', 'node-0')]); + leavesTreeApiServiceSpy.searchUnderNodeWithSearchCriterias.and.returnValue(of(pagedResult)); + + const result = leavesTreeService.searchUnderNodeWithSearchCriterias(parentNode); + result.subscribe((results) => { + expect(results).toEqual(pagedResult); + }); + + expect(leavesTreeApiServiceSpy.searchUnderNodeWithSearchCriterias).toHaveBeenCalledTimes(1); + expect(parentNode.children[0].id).toEqual('node-0-1'); + expect(parentNode.children[0].count).toEqual(5); + expect(parentNode.children[1].id).toEqual('node-0-2'); + expect(parentNode.children[1].count).toEqual(7); + }); + }); + + describe('searchAtNodeWithSearchCriterias', () => { + it('should not add children if parentId does not match', () => { + const parentNode = newNode('node-0', []); + const pagedResult = newPagedResult([newUnit('node-0-1', 'node-bad'), newUnit('node-0-2')]); + leavesTreeApiServiceSpy.searchAtNodeWithSearchCriterias.and.returnValue(of(pagedResult)); + + const result = leavesTreeService.searchAtNodeWithSearchCriterias(parentNode); + result.subscribe((results) => { + expect(results).toEqual(pagedResult); + }); + + expect(leavesTreeApiServiceSpy.searchAtNodeWithSearchCriterias).toHaveBeenCalledTimes(1); + expect(parentNode.children).toEqual([]); + }); + it('should add children', () => { + const parentNode = newNode('node-0', []); + const pagedResult = newPagedResult([newUnit('node-0-1', 'node-0'), newUnit('node-0-2', 'node-0')]); + leavesTreeApiServiceSpy.searchAtNodeWithSearchCriterias.and.returnValue(of(pagedResult)); + + const result = leavesTreeService.searchAtNodeWithSearchCriterias(parentNode); + result.subscribe((results) => { + expect(results).toEqual(pagedResult); + }); + + expect(leavesTreeApiServiceSpy.searchAtNodeWithSearchCriterias).toHaveBeenCalledTimes(1); + expect(parentNode.children[0].id).toEqual('node-0-1'); + expect(parentNode.children[0].count).toEqual(1); + expect(parentNode.children[1].id).toEqual('node-0-2'); + expect(parentNode.children[1].count).toEqual(1); + }); + it('should not add children if already present', () => { + const parentNode = newNode('node-0', [newTreeNode('node-0-1', 2), newTreeNode('node-0-2', 2)]); + const pagedResult = newPagedResult([ + newUnit('node-0-1-0', 'node-0-1'), + newUnit('node-0-1-1', 'node-0-1'), + newUnit('node-0-1-2', 'node-0-1'), + newUnit('node-0-1-3', 'node-0-1'), + newUnit('node-0-1-4', 'node-0-1'), + newUnit('node-0-1-5', 'node-0-1'), + newUnit('node-0-1-6', 'node-0-1'), + newUnit('node-0-1-7', 'node-0-1'), + newUnit('node-0-1-8', 'node-0-1'), + newUnit('node-0-1-9', 'node-0-1'), + ]); + leavesTreeApiServiceSpy.searchAtNodeWithSearchCriterias.and.returnValue(of(pagedResult)); + + const result = leavesTreeService.searchAtNodeWithSearchCriterias(parentNode); + result.subscribe((results) => { + expect(results).toEqual(pagedResult); + }); + + expect(leavesTreeApiServiceSpy.searchAtNodeWithSearchCriterias).toHaveBeenCalledTimes(1); + expect(parentNode.children[0].id).toEqual('node-0-1'); + expect(parentNode.children[0].count).toEqual(2); + expect(parentNode.children[1].id).toEqual('node-0-2'); + expect(parentNode.children[1].count).toEqual(2); + }); + it('should not add children if already present but init count', () => { + const parentNode = newNode('node-0', [newNode('node-0-1'), newTreeNode('node-0-2', 0)]); + const pagedResult = newPagedResult([newUnit('node-0-1', 'node-0'), newUnit('node-0-2', 'node-0')]); + leavesTreeApiServiceSpy.searchAtNodeWithSearchCriterias.and.returnValue(of(pagedResult)); + + const result = leavesTreeService.searchAtNodeWithSearchCriterias(parentNode); + result.subscribe((results) => { + expect(results).toEqual(pagedResult); + }); + + expect(leavesTreeApiServiceSpy.searchAtNodeWithSearchCriterias).toHaveBeenCalledTimes(1); + expect(parentNode.children[0].id).toEqual('node-0-1'); + expect(parentNode.children[0].count).toEqual(1); + expect(parentNode.children[1].id).toEqual('node-0-2'); + expect(parentNode.children[1].count).toEqual(1); + }); + it('should add children and check facets', () => { + const parentNode = newNode('node-0', []); + leavesTreeService.setSearchRequestResultFacets([ + newResultFacet('node-0', 5), + newResultFacet('node-0-1', 5), + newResultFacet('node-0-2', 7)]); + const pagedResult = newPagedResult([newUnit('node-0-1', 'node-0'), newUnit('node-0-2', 'node-0')]); + leavesTreeApiServiceSpy.searchAtNodeWithSearchCriterias.and.returnValue(of(pagedResult)); + + const result = leavesTreeService.searchAtNodeWithSearchCriterias(parentNode); + result.subscribe((results) => { + expect(results).toEqual(pagedResult); + }); + + expect(leavesTreeApiServiceSpy.searchAtNodeWithSearchCriterias).toHaveBeenCalledTimes(1); + expect(parentNode.children[0].id).toEqual('node-0-1'); + expect(parentNode.children[0].count).toEqual(5); + expect(parentNode.children[1].id).toEqual('node-0-2'); + expect(parentNode.children[1].count).toEqual(7); + }); + }); + +}); diff --git a/ui/ui-frontend-common/src/app/modules/services/leaves-tree.service.ts b/ui/ui-frontend-common/src/app/modules/services/leaves-tree.service.ts index 91bb7b8e11b..73b458c39cc 100644 --- a/ui/ui-frontend-common/src/app/modules/services/leaves-tree.service.ts +++ b/ui/ui-frontend-common/src/app/modules/services/leaves-tree.service.ts @@ -1,3 +1,29 @@ +/* + * Copyright French Prime minister Office/SGMAP/DINSIC/Vitam Program (2015-2022) + * + * contact.vitam@culture.gouv.fr + * + * This software is a computer program whose purpose is to implement a digital archiving back-office system managing + * high volumetry securely and efficiently. + * + * This software is governed by the CeCILL 2.1 license under French law and abiding by the rules of distribution of free + * software. You can use, modify and/ or redistribute the software under the terms of the CeCILL 2.1 license as + * circulated by CEA, CNRS and INRIA at the following URL "https://cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, + * users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the + * successive licensors have only limited liability. + * + * In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or + * developing or reproducing the software by the user in light of its specific status of free software, that may mean + * that it is complicated to manipulate, and that also therefore means that it is reserved for developers and + * experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the + * software's suitability as regards their requirements in conditions enabling the security of their systems and/or data + * to be ensured and, more generally, to use and operate it in the same conditions as regards security. + * + * The fact that you are presently reading this means that you have had knowledge of the CeCILL 2.1 license and that you + * accept its terms. + */ import { EMPTY, Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { isEmpty } from 'underscore'; @@ -7,35 +33,29 @@ import { LeavesTreeApiService } from './leaves-tree-api.service'; import { SearchArchiveUnitsInterface } from './search-archive-units.interface'; export class LeavesTreeService { - private leavesTreeService: LeavesTreeApiService; + private leavesTreeApiService: LeavesTreeApiService; constructor(private searchArchiveUnitsService: SearchArchiveUnitsInterface) { - this.leavesTreeService = new LeavesTreeApiService(this.searchArchiveUnitsService); + this.leavesTreeApiService = new LeavesTreeApiService(this.searchArchiveUnitsService); } private searchCriterias: SearchCriteriaDto; - private searchRequestResultFacets: ResultFacet[]; + private searchRequestResultFacets: ResultFacet[] = []; loadingNodesDetails: boolean; public firstToggle(node: FilingHoldingSchemeNode): boolean { - if (node.toggled) { - return false; - } - node.toggled = true; - if (!node.children) { - node.children = []; - } - node.paginatedMatchingChildrenLoaded = 0; - node.canLoadMoreMatchingChildren = true; - node.paginatedChildrenLoaded = 0; - node.canLoadMoreChildren = true; - return true; + return this.leavesTreeApiService.firstToggle(node); } // ########## AFTER CALLS #################################################################################################### private compareAddedNodeWithKnownFacets(nodes: FilingHoldingSchemeNode[]) { + console.log('LTS.compareAddedNodeWithKnownFacets'); + if (isEmpty(this.searchRequestResultFacets)) { + console.log(' EMPTY FACETS'); + return; + } for (const node of nodes) { const matchingFacet = this.searchRequestResultFacets.find((resultFacet) => resultFacet.node === node.id); if (!matchingFacet) { @@ -52,6 +72,7 @@ export class LeavesTreeService { const resultFacets: ResultFacet[] = FacetsUtils.extractNodesFacetsResults(pageResult.facets); const newFacets: ResultFacet[] = FilingHoldingSchemeHandler.filterUnknownFacets(this.searchRequestResultFacets, resultFacets); if (newFacets.length > 0) { + console.log('LTS.extractAndAddNewFacets + ', newFacets.length); this.searchRequestResultFacets.push(...newFacets); } return newFacets; @@ -60,14 +81,17 @@ export class LeavesTreeService { // ########## SECONDARY CALLS #################################################################################################### public loadNodesDetailsFromFacetsIdsAndAddThem(parentNodes: FilingHoldingSchemeNode[], facets: ResultFacet[]): Observable { + console.log('LTS.loadNodesDetailsFromFacetsIdsAndAddThem'); if (isEmpty(facets)) { + console.log(' EMPTY FACET'); return EMPTY; } this.loadingNodesDetails = true; - return this.leavesTreeService.loadNodesDetailsFromFacetsIds(facets) + return this.leavesTreeApiService.loadNodesDetailsFromFacetsIds(facets) .pipe(map(pagedResult => { + console.log('LTS.loadNodesDetailsFromFacetsIds.PIPE'); FilingHoldingSchemeHandler.addChildrenRecursively(parentNodes, pagedResult.results, true); - FilingHoldingSchemeHandler.setCountRecursively(parentNodes, facets); + FilingHoldingSchemeHandler.setCountRecursively(parentNodes, this.searchRequestResultFacets); this.loadingNodesDetails = false; return pagedResult; })); @@ -76,45 +100,71 @@ export class LeavesTreeService { // ########## MAIN CALLS #################################################################################################### public searchUnderNode(parentNode: FilingHoldingSchemeNode): Observable { - return this.leavesTreeService.searchUnderNode(parentNode, this.searchCriterias) + console.log('LTS.searchUnderNode'); + return this.leavesTreeApiService.searchUnderNode(parentNode, this.searchCriterias) .pipe(map(pagedResult => { + console.log('LTS.searchUnderNode.PIPE'); const matchingNodesNumbers = FilingHoldingSchemeHandler.addChildren(parentNode, pagedResult.results); + console.log(' matchingNodesNumbers : ' + JSON.stringify(matchingNodesNumbers)); this.compareAddedNodeWithKnownFacets(matchingNodesNumbers.nodesAddedList); return pagedResult; })); } public searchUnderNodeWithSearchCriterias(parentNode: FilingHoldingSchemeNode): Observable { - return this.leavesTreeService.searchUnderNodeWithSearchCriterias(parentNode, this.searchCriterias) + console.log('LTS.searchUnderNodeWithSearchCriterias'); + return this.leavesTreeApiService.searchUnderNodeWithSearchCriterias(parentNode, this.searchCriterias) + .pipe(map(pagedResult => { + console.log('LTS.searchUnderNodeWithSearchCriterias.PIPE'); + this.extractAndAddNewFacets(pagedResult); + const matchingNodesNumbers = FilingHoldingSchemeHandler.addChildren(parentNode, pagedResult.results, true); + console.log(' matchingNodesNumbers : ' + JSON.stringify(matchingNodesNumbers)); + this.compareAddedNodeWithKnownFacets(matchingNodesNumbers.nodesAddedList); + return pagedResult; + })); + } + + public searchAtNodeWithSearchCriterias(parentNode: FilingHoldingSchemeNode): Observable { + console.log('LTS.searchAtNodeWithSearchCriterias'); + return this.leavesTreeApiService.searchAtNodeWithSearchCriterias(parentNode, this.searchCriterias) .pipe(map(pagedResult => { - FilingHoldingSchemeHandler.addChildren(parentNode, pagedResult.results, true); - const newFacets: ResultFacet[] = this.extractAndAddNewFacets(pagedResult); - this.loadNodesDetailsFromFacetsIdsAndAddThem([parentNode], newFacets) - .subscribe(); + console.log('LTS.searchAtNodeWithSearchCriterias.PIPE'); + this.extractAndAddNewFacets(pagedResult); + const matchingNodesNumbers = FilingHoldingSchemeHandler.addChildren(parentNode, pagedResult.results, true); + console.log(' matchingNodesNumbers : ' + JSON.stringify(matchingNodesNumbers)); + this.compareAddedNodeWithKnownFacets(matchingNodesNumbers.nodesAddedList); return pagedResult; })); } public searchOrphans(parentNode: FilingHoldingSchemeNode): Observable { - return this.leavesTreeService.searchOrphans(parentNode, this.searchCriterias) + console.log('LTS.searchOrphans'); + return this.leavesTreeApiService.searchOrphans(parentNode, this.searchCriterias) .pipe(map(pagedResult => { + console.log('LTS.searchOrphans.PIPE'); const matchingNodesNumbers = FilingHoldingSchemeHandler.addOrphans(parentNode, pagedResult.results); + console.log(' matchingNodesNumbers : ' + JSON.stringify(matchingNodesNumbers)); this.compareAddedNodeWithKnownFacets(matchingNodesNumbers.nodesAddedList); return pagedResult; })); } public searchOrphansWithSearchCriterias(parentNode: FilingHoldingSchemeNode): Observable { - return this.leavesTreeService.searchOrphansWithSearchCriterias(parentNode, this.searchCriterias) + console.log('LTS.searchOrphansWithSearchCriterias'); + return this.leavesTreeApiService.searchOrphansWithSearchCriterias(parentNode, this.searchCriterias) .pipe(map(pagedResult => { + console.log('LTS.searchOrphansWithSearchCriterias.PIPE'); + console.log(JSON.stringify(pagedResult)); + this.extractAndAddNewFacets(pagedResult); const matchingNodesNumbers = FilingHoldingSchemeHandler.addOrphans(parentNode, pagedResult.results, true); + console.log(' matchingNodesNumbers : ' + JSON.stringify(matchingNodesNumbers)); this.compareAddedNodeWithKnownFacets(matchingNodesNumbers.nodesAddedList); return pagedResult; })); } searchAttachementUnit(): Observable { - return this.leavesTreeService.searchAttachementUnit(); + return this.leavesTreeApiService.searchAttachementUnit(); } // ########## UPDATES #################################################################################################### @@ -123,9 +173,13 @@ export class LeavesTreeService { this.searchCriterias = searchCriterias; } + setSearchRequestResultFacets(searchRequestResultFacets: ResultFacet[]) { + this.searchRequestResultFacets = [...searchRequestResultFacets]; + } + // Specific to collect setTransactionId(transactionId: string) { - this.leavesTreeService.setTransactionId(transactionId); + this.leavesTreeApiService.setTransactionId(transactionId); } } diff --git a/ui/ui-frontend/projects/archive-search/src/app/archive/filing-holding-scheme/leaves-tree/leaves-tree.component.scss b/ui/ui-frontend/projects/archive-search/src/app/archive/filing-holding-scheme/leaves-tree/leaves-tree.component.scss index 1f826710bdd..577fe693ab0 100644 --- a/ui/ui-frontend/projects/archive-search/src/app/archive/filing-holding-scheme/leaves-tree/leaves-tree.component.scss +++ b/ui/ui-frontend/projects/archive-search/src/app/archive/filing-holding-scheme/leaves-tree/leaves-tree.component.scss @@ -112,7 +112,6 @@ text-decoration: underline; } - .badge { display: inline-block; padding: 0.25em 0; diff --git a/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-collect.component.html b/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-collect.component.html index df48e8750dc..cbcdb8f5e79 100644 --- a/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-collect.component.html +++ b/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-collect.component.html @@ -312,7 +312,8 @@
implements O this.archiveUnits = pagedResult.results; this.searchHasResults = !isEmpty(pagedResult.results); this.archiveSearchResultFacets.nodesFacets = this.archiveFacetsService.extractNodesFacetsResults(pagedResult.facets); - this.archiveExchangeDataService.emitFacets(this.archiveSearchResultFacets.nodesFacets); this.totalResults = pagedResult.totalResults; + this.archiveExchangeDataService.emitTotalResults(this.totalResults) + this.archiveExchangeDataService.emitFacets(this.archiveSearchResultFacets.nodesFacets); } else if (pagedResult.results) { pagedResult.results.forEach((elt) => this.archiveUnits.push(elt)); } @@ -478,6 +458,12 @@ export class ArchiveSearchCollectComponent extends SidenavPage implements O ); } + onArchiveUnitCountChange(event: number) { + console.log('onArchiveUnitCountChange') + this.totalResults = event; + this.archiveExchangeDataService.emitTotalResults(event); + } + // Manage lateral panels showExtendedLateralPanel() { diff --git a/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/components/filing-holding-scheme/filing-holding-scheme.component.ts b/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/components/filing-holding-scheme/filing-holding-scheme.component.ts index c6996bb5622..57a038c51ba 100644 --- a/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/components/filing-holding-scheme/filing-holding-scheme.component.ts +++ b/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/components/filing-holding-scheme/filing-holding-scheme.component.ts @@ -27,6 +27,7 @@ import { NestedTreeControl } from '@angular/cdk/tree'; import { Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, SimpleChanges } from '@angular/core'; import { MatTreeNestedDataSource } from '@angular/material/tree'; +import { TranslateService } from '@ngx-translate/core'; import { Subscription } from 'rxjs'; import { CriteriaDataType, CriteriaOperator, Direction, FilingHoldingSchemeHandler, FilingHoldingSchemeNode, PagedResult, ResultFacet, @@ -35,7 +36,7 @@ import { import { isEmpty } from 'underscore'; import { ArchiveCollectService } from '../../../archive-collect.service'; import { NodeData } from '../../models/nodedata.interface'; -import { Pair, VitamInternalFields } from '../../models/utils'; +import { Pair } from '../../models/utils'; import { ArchiveSharedDataService } from '../../services/archive-shared-data.service'; @Component({ @@ -60,6 +61,7 @@ export class FilingHoldingSchemeComponent implements OnInit, OnChanges, OnDestro nestedDataSourceFull: MatTreeNestedDataSource = new MatTreeNestedDataSource(); nestedDataSourceLeaves: MatTreeNestedDataSource = new MatTreeNestedDataSource(); attachmentUnits: Unit[]; + attachmentNodes: FilingHoldingSchemeNode[] = []; disabled: boolean; loadingHolding = true; node: string; @@ -71,8 +73,11 @@ export class FilingHoldingSchemeComponent implements OnInit, OnChanges, OnDestro TREE: false, LEAVE: false, }; + private filingPlanLoaded = false; + private attachmentUnitsLoaded = false; constructor( + private translateService: TranslateService, private archiveService: ArchiveCollectService, private startupService: StartupService, private archiveSharedDataService: ArchiveSharedDataService @@ -81,10 +86,13 @@ export class FilingHoldingSchemeComponent implements OnInit, OnChanges, OnDestro } ngOnInit(): void { - this.initialNodesState(); + this.nestedDataSourceLeaves.data = []; + console.log('FHSC.ngOnInit') + this.subscribeOnTotalResultsChange(); this.subscribeOnNodeSelectionToSetCheck(); this.subscribeOnFacetsChanges(); this.loadFilingHoldingSchemeTree(); + this.loadAttachementUnits(); } ngOnChanges(_: SimpleChanges): void { @@ -97,6 +105,7 @@ export class FilingHoldingSchemeComponent implements OnInit, OnChanges, OnDestro private subscribeOnNodeSelectionToSetCheck(): void { this.subscriptions.add( this.archiveSharedDataService.getNodesTarget().subscribe((nodeId) => { + console.log('FHSC.subscription.getNodesTarget'); if (nodeId == null) { this.switchViewAllNodes(); } else { @@ -110,15 +119,19 @@ export class FilingHoldingSchemeComponent implements OnInit, OnChanges, OnDestro private subscribeOnFacetsChanges(): void { this.subscriptions.add( this.archiveSharedDataService.getFacets().subscribe((facets) => { - if (facets && facets.length > 0) { - this.requestResultFacets = facets; - // Re-init attachment units to render children by criteria - this.nestedDataSourceLeaves.data.forEach((node) => { - node.toggled = undefined; - node.children = []; - }); - } else { - this.requestResultFacets = []; + console.log('FHSC.subscription.getFacets'); + console.log(JSON.stringify(facets)); + this.requestResultFacets = facets; + if (!this.filingPlanLoaded || !this.attachmentUnitsLoaded) { + return; + } + // Re-init attachment units to render children by criteria + this.nestedDataSourceLeaves.data = [...this.attachmentNodes]; + if (this.searchRequestTotalResults > 0 && isEmpty(this.attachmentNodes)) { + console.log('FHSC.addOrphansNode'); + console.log(' searchRequestTotalResults = ' + this.searchRequestTotalResults) + FilingHoldingSchemeHandler.addOrphansNodeFromTree(this.nestedDataSourceLeaves.data, + this.translateService.instant('ARCHIVE_SEARCH.FILING_SCHEMA.ORPHANS_NODE'), this.searchRequestTotalResults); } }) ); @@ -131,7 +144,8 @@ export class FilingHoldingSchemeComponent implements OnInit, OnChanges, OnDestro this.archiveSharedDataService.emitNode(this.nodeData); } - retrieveAttachementUnits() { + loadAttachementUnits() { + console.log('FHSC.retrieveAttachementUnits'); const sortingCriteria = { criteria: 'Title', sorting: Direction.ASCENDANT }; const criteriaWithId: SearchCriteriaEltDto = { criteria: '#management.UpdateOperation.SystemId', @@ -151,72 +165,43 @@ export class FilingHoldingSchemeComponent implements OnInit, OnChanges, OnDestro this.archiveService .searchArchiveUnitsByCriteria(searchCriteria, this.transactionId) .subscribe((pagedResult: PagedResult) => { + console.log('FHSC.subscription.retrieveAttachementUnits'); this.attachmentUnits = pagedResult.results; - this.filterNodesToLeavesOnly(pagedResult.results); + this.attachmentUnitsLoaded = true; + this.setAttachmentNodes(); }); } - private filterNodesToLeavesOnly(resultUnits: Unit[]) { - const list: any[] = []; - const unflattedNodes = FilingHoldingSchemeHandler.keepEndNodesWithResultsOnlyAndCheckAttach(this.fullNodes, resultUnits); - unflattedNodes.forEach((unflattedNode) => { - const collectAttachmentUnit = FilingHoldingSchemeHandler.getUnitWithUpdateOperationId(resultUnits, unflattedNode.id); - if (collectAttachmentUnit) { - const outNode: FilingHoldingSchemeNode = { - id: collectAttachmentUnit[VitamInternalFields.ID], - vitamId: unflattedNode.id, - title: unflattedNode.title, - unitType: unflattedNode?.unitType, - descriptionLevel: collectAttachmentUnit.DescriptionLevel, - children: [], - checked: false, - hidden: false, - hasObject: unflattedNode?.hasObject, - }; - list.push(outNode); - } - }); - - let orphansNode; - if (!isEmpty(this.nestedDataSourceLeaves.data) && FilingHoldingSchemeHandler.isOrphansNode(this.nestedDataSourceLeaves.data[0])) { - orphansNode = this.nestedDataSourceLeaves.data[0]; + private setAttachmentNodes() { + if (isEmpty(this.fullNodes) || isEmpty(this.attachmentUnits)) { + return; } - if (list.length > 0) { - this.nestedDataSourceLeaves.data = list; - this.showEveryNodes = true; - } else { - this.nestedDataSourceLeaves.data = []; - this.showEveryNodes = false; - } - if (orphansNode) { - this.nestedDataSourceLeaves.data.unshift(orphansNode); - const tmp = this.nestedDataSourceLeaves.data; - this.nestedDataSourceLeaves.data = null; - this.nestedDataSourceLeaves.data = tmp; + this.attachmentNodes = []; + for (const unit of this.attachmentUnits) { + const treeNode = FilingHoldingSchemeHandler.foundNode(this.fullNodes, unit['#management'].UpdateOperation.SystemId); + const node = FilingHoldingSchemeHandler.convertUnitToNode(unit); + node.vitamId = treeNode.id; + node.title = treeNode.title; + node.unitType = treeNode.unitType; + node.hasObject = treeNode.hasObject; + this.attachmentNodes.push(node); } } - private initialNodesState(): void { - this.subscriptions.add( - this.archiveSharedDataService.getFilingHoldingNodes().subscribe((nodes) => { - if (nodes) { - this.fullNodes = nodes; - this.switchViewAllNodes(); - this.retrieveAttachementUnits(); - } - }) - ); - } - loadFilingHoldingSchemeTree() { + console.log('FHSC.loadFilingHoldingSchemeTree'); this.loadingHolding = true; this.archiveService.loadFilingHoldingSchemeTree(this.tenantIdentifier).subscribe((nodes) => { + console.log('FHSC.subscription.loadFilingHoldingSchemeTree'); // Disable checkbox use to prevent add unit to search criteria this.disableNodesRecursive(nodes); this.fullNodes = nodes; + this.filingPlanLoaded = true; this.nestedDataSourceFull.data = nodes; this.nestedTreeControlFull.dataNodes = nodes; this.archiveSharedDataService.emitFilingHoldingNodes(nodes); + this.switchViewAllNodes(); + this.setAttachmentNodes(); this.loadingHolding = false; }); } @@ -259,4 +244,17 @@ export class FilingHoldingSchemeComponent implements OnInit, OnChanges, OnDestro }) ); } + + private subscribeOnTotalResultsChange(): void { + this.subscriptions.add( + this.archiveSharedDataService.getTotalResults().subscribe((totalResults) => { + this.searchRequestTotalResults = totalResults; + console.log('FHSC.getTotalResults.SUBSCRIPTION') + console.log(' searchRequestTotalResults = ' + this.searchRequestTotalResults) + if (this.nestedDataSourceLeaves.data.length === 1 && this.nestedDataSourceLeaves.data[0].count + 1 !== totalResults) { + this.nestedDataSourceLeaves.data[0].count = totalResults; + } + }) + ); + } } diff --git a/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/components/filing-holding-scheme/leaves-tree/leaves-tree.component.html b/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/components/filing-holding-scheme/leaves-tree/leaves-tree.component.html index f33fc0f9ec9..a01f8e7df75 100644 --- a/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/components/filing-holding-scheme/leaves-tree/leaves-tree.component.html +++ b/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/components/filing-holding-scheme/leaves-tree/leaves-tree.component.html @@ -22,7 +22,7 @@ (nodeToggle)="toggleLeave(node)" > - + {{ node.count | number : '1.0' }}
@@ -56,7 +56,7 @@ > - + {{ node.count | number : '1.0' }} @@ -101,7 +101,7 @@ (nodeToggle)="toggleLeave(node)" > - + {{ node.count | number : '1.0' }} diff --git a/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/components/filing-holding-scheme/leaves-tree/leaves-tree.component.scss b/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/components/filing-holding-scheme/leaves-tree/leaves-tree.component.scss index 3c3e8254446..577fe693ab0 100644 --- a/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/components/filing-holding-scheme/leaves-tree/leaves-tree.component.scss +++ b/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/components/filing-holding-scheme/leaves-tree/leaves-tree.component.scss @@ -112,21 +112,27 @@ text-decoration: underline; } - .badge { display: inline-block; - padding: 0.25em 1.5em; + padding: 0.25em 0; font-size: 100%; font-weight: 700; line-height: 1; position: absolute; - top: 14px; + top: 11px; + right: 2px; white-space: nowrap; vertical-align: baseline; border-radius: 1.25rem; - right: 2px; width: 54px; - text-align: right; + text-align: center; +} + +.badge-primary { + // Primary/Primary-500 + color: #9C31B5; + // Primary/Primary-100 + background-color: #E6C3EF; } .badge-secondary { diff --git a/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/components/filing-holding-scheme/leaves-tree/leaves-tree.component.ts b/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/components/filing-holding-scheme/leaves-tree/leaves-tree.component.ts index 545facbc87a..0678039deef 100644 --- a/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/components/filing-holding-scheme/leaves-tree/leaves-tree.component.ts +++ b/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/components/filing-holding-scheme/leaves-tree/leaves-tree.component.ts @@ -28,13 +28,11 @@ import { NestedTreeControl } from '@angular/cdk/tree'; import { Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, SimpleChanges } from '@angular/core'; import { MatTreeNestedDataSource } from '@angular/material/tree'; -import { TranslateService } from '@ngx-translate/core'; import { Subscription } from 'rxjs'; import { DescriptionLevel, FilingHoldingSchemeHandler, FilingHoldingSchemeNode, LeavesTreeService, nodeToVitamuiIcon, PagedResult, ResultFacet, SearchCriteriaDto, UnitType } from 'ui-frontend-common'; -import { isEmpty } from 'underscore'; import { ArchiveCollectService } from '../../../../archive-collect.service'; import { Pair } from '../../../models/utils'; import { ArchiveSharedDataService } from '../../../services/archive-shared-data.service'; @@ -63,55 +61,48 @@ export class LeavesTreeComponent implements OnInit, OnChanges, OnDestroy { (node) => node.children ); showEveryNodes = true; - showFacetsCount = false; + showFacetsCount = true; private searchCriterias: SearchCriteriaDto; private subscriptions: Subscription = new Subscription(); private leavesTreeService: LeavesTreeService; constructor( private archiveSharedDataService: ArchiveSharedDataService, - private translateService: TranslateService, private archiveCollectService: ArchiveCollectService, ) { this.leavesTreeService = new LeavesTreeService(this.archiveCollectService); } ngOnInit(): void { + console.log('LTC.ngOnInit'); this.subscribeOnSearchCriteriasUpdate(); - this.showFacetsCount = false; } ngOnChanges(changes: SimpleChanges): void { + console.log('LTC.ngOnChanges'); if (changes.nestedDataSourceLeaves || changes.searchRequestResultFacets) { + changes.nestedDataSourceLeaves ? console.log(' CHANGE nestedDataSourceLeaves') : console.log(' CHANGE searchRequestResultFacets'); this.nestedTreeControlLeaves.dataNodes = this.nestedDataSourceLeaves.data; - this.addOrphansNode(); - if (changes.searchRequestResultFacets && changes.searchRequestResultFacets.currentValue.length === 0) { - // Render EMPTY attachment units - this.nestedDataSourceLeaves.data.forEach((node) => { - node.toggled = undefined; - node.children = []; - node.count = 0; - node.hidden = true; - }); - this.refreshTreeNodes(); - } else { - if (this.searchCriterias) { - this.loadNodesDetailsFromFacetsIdsAndAddThem(this.nestedDataSourceLeaves.data, this.searchRequestResultFacets); - this.showFacetsCount = true; + if (this.searchCriterias) { + this.loadNodesDetailsFromFacetsIdsAndAddThem(this.nestedDataSourceLeaves.data, this.searchRequestResultFacets); + } + if (changes.searchRequestResultFacets) { + if (changes.searchRequestResultFacets.currentValue.length > 0) { + console.log('changes.searchRequestResultFacets = ' + changes.searchRequestResultFacets.currentValue.length) + this.leavesTreeService.setSearchRequestResultFacets(changes.searchRequestResultFacets.currentValue); + } else { + // @ts-ignore + console.log('EMPTY FACET !!!!!leavesTreeService.searchRequestResultFacets = ' + this.leavesTreeService.searchRequestResultFacets.length) } } + this.refreshTreeNodes(); } if (changes.transactionId) { + console.log(' CHANGE transactionId'); this.leavesTreeService.setTransactionId(this.transactionId); } } - addOrphansNode() { - if (this.searchRequestTotalResults > 0 && isEmpty(this.nestedDataSourceLeaves.data)) { - FilingHoldingSchemeHandler.addOrphansNodeFromTree(this.nestedDataSourceLeaves.data, - this.translateService.instant('ARCHIVE_SEARCH.FILING_SCHEMA.ORPHANS_NODE'), this.searchRequestTotalResults); - } - } ngOnDestroy(): void { this.subscriptions.unsubscribe(); @@ -122,6 +113,7 @@ export class LeavesTreeComponent implements OnInit, OnChanges, OnDestroy { } private searchUnderNode(parentNode: FilingHoldingSchemeNode) { + console.log('LTC.searchUnderNode'); this.leavesTreeService.searchUnderNode(parentNode) .subscribe((_: PagedResult) => { this.refreshTreeNodes(); @@ -129,13 +121,23 @@ export class LeavesTreeComponent implements OnInit, OnChanges, OnDestroy { } private searchUnderNodeWithSearchCriterias(parentNode: FilingHoldingSchemeNode) { + console.log('LTC.searchUnderNodeWithSearchCriterias'); this.leavesTreeService.searchUnderNodeWithSearchCriterias(parentNode) .subscribe((_: PagedResult) => { this.refreshTreeNodes(); }); } + private searchAtNodeWithSearchCriterias(parentNode: FilingHoldingSchemeNode) { + console.log('LTC.searchAtNodeWithSearchCriterias'); + this.leavesTreeService.searchAtNodeWithSearchCriterias(parentNode) + .subscribe((_: PagedResult) => { + this.refreshTreeNodes(); + }); + } + private searchOrphans(parentNode: FilingHoldingSchemeNode) { + console.log('LTC.searchOrphans'); this.leavesTreeService.searchOrphans(parentNode) .subscribe((_: PagedResult) => { this.refreshTreeNodes(); @@ -143,6 +145,7 @@ export class LeavesTreeComponent implements OnInit, OnChanges, OnDestroy { } private searchOrphansWithSearchCriterias(parentNode: FilingHoldingSchemeNode) { + console.log('LTC.searchOrphansWithSearchCriterias'); this.leavesTreeService.searchOrphansWithSearchCriterias(parentNode) .subscribe((_: PagedResult) => { this.refreshTreeNodes(); @@ -150,6 +153,7 @@ export class LeavesTreeComponent implements OnInit, OnChanges, OnDestroy { } private loadNodesDetailsFromFacetsIdsAndAddThem(parentNodes: FilingHoldingSchemeNode[], facets: ResultFacet[]) { + console.log('LTC.loadNodesDetailsFromFacetsIdsAndAddThem'); this.leavesTreeService.loadNodesDetailsFromFacetsIdsAndAddThem(parentNodes, facets) .subscribe((_: PagedResult) => { this.refreshTreeNodes(); @@ -187,6 +191,7 @@ export class LeavesTreeComponent implements OnInit, OnChanges, OnDestroy { if (this.firstToggle(node)) { this.searchUnderNodeWithSearchCriterias(node); this.searchUnderNode(node); + this.searchAtNodeWithSearchCriterias(node); } } @@ -253,6 +258,8 @@ export class LeavesTreeComponent implements OnInit, OnChanges, OnDestroy { this.subscriptions.add( this.archiveSharedDataService.getSearchCriterias() .subscribe((searchCriteriaDto: SearchCriteriaDto) => { + console.log('LTC.subscription.getSearchCriterias'); + this.leavesTreeService.setSearchCriterias(searchCriteriaDto); this.searchCriterias = searchCriteriaDto; }) ); diff --git a/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/services/archive-shared-data.service.ts b/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/services/archive-shared-data.service.ts index bbb28d6d528..74c1bcc797a 100644 --- a/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/services/archive-shared-data.service.ts +++ b/ui/ui-frontend/projects/collect/src/app/collect/archive-search-collect/archive-search-criteria/services/archive-shared-data.service.ts @@ -49,6 +49,7 @@ export class ArchiveSharedDataService { private filingHoldingNodesSubject = new BehaviorSubject(null); private targetNode = new BehaviorSubject(''); private facetsSubject = new BehaviorSubject([]); + private totalResultsSubject = new BehaviorSubject(null); private toggleSubject = new BehaviorSubject(true); private toggleReverseSubject = new BehaviorSubject(true); private archiveUnitTpPreviewSubject = new BehaviorSubject(null); @@ -150,6 +151,14 @@ export class ArchiveSharedDataService { return this.facetsSubject.asObservable(); } + emitTotalResults(result: number) { + this.totalResultsSubject.next(result); + } + + getTotalResults(): Observable { + return this.totalResultsSubject.asObservable(); + } + emitToggle(show: boolean) { this.toggleSubject.next(show); }