Skip to content

Commit

Permalink
remove logs
Browse files Browse the repository at this point in the history
  • Loading branch information
laedanrex committed Oct 23, 2023
1 parent 1e0fb6c commit bfe82a2
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ describe('FilingHoldingSchemeHandler', () => {
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);
Expand Down Expand Up @@ -510,7 +509,7 @@ describe('FilingHoldingSchemeHandler', () => {
const toggleNode = uaNodes[0];
expect(toggleNode.children.length).toEqual(5);
const resturnedUnits = [
newUnit('node-0-2', 'node-0'), // already present
newUnit('node-0-2', 'node-0'), // already present without count
newUnit('new-node-0-5', 'node-0'), // new
newUnit('new-node-0-6', 'node-0'), // new
newUnit('new-node', 'node-0-1'), // wrong parent
Expand All @@ -521,8 +520,8 @@ describe('FilingHoldingSchemeHandler', () => {
expect(matchingNodesNumbers.nodesAddedList.length).toEqual(2);
expect(matchingNodesNumbers.nodesAddedList[0].id).toEqual('new-node-0-5');
expect(matchingNodesNumbers.nodesAddedList[1].id).toEqual('new-node-0-6');
expect(matchingNodesNumbers.nodesUpdated).toEqual(0);
expect(matchingNodesNumbers.nodesFoundButUnchanged).toEqual(1);
expect(matchingNodesNumbers.nodesUpdated).toEqual(1);
expect(matchingNodesNumbers.nodesFoundButUnchanged).toEqual(0);
expect(toggleNode.children[0].count).toEqual(undefined); // unchanged
expect(toggleNode.children[5].count).toEqual(1);
expect(toggleNode.children[6].count).toEqual(1);
Expand Down Expand Up @@ -704,4 +703,49 @@ describe('FilingHoldingSchemeHandler', () => {
});
});

describe('addOrphansNodeFromTree', () => {
it('should add orphans node in empty array', () => {
const parentNodes: FilingHoldingSchemeNode[] = [];
const count = 10;
FilingHoldingSchemeHandler.addOrphansNodeFromTree(parentNodes, 'sans rattachement', count);
expect(parentNodes.length).toBe(1);
expect(parentNodes[0].vitamId).toBe(ORPHANS_NODE_ID);
});
it('should add orphans node in first place of array', () => {
const parentNodes = [newTreeNode('node-1-1', 0)];
const count = 10;
FilingHoldingSchemeHandler.addOrphansNodeFromTree(parentNodes, 'sans rattachement', count);
expect(parentNodes.length).toBe(2);
expect(parentNodes[0].vitamId).toBe(ORPHANS_NODE_ID);
});
it('should not add orphans node if already present', () => {
const parentNodes = [];
const count = 10;
FilingHoldingSchemeHandler.addOrphansNodeFromTree(parentNodes, 'sans rattachement', count);
FilingHoldingSchemeHandler.addOrphansNodeFromTree(parentNodes, 'sans rattachement', count);
expect(parentNodes.length).toBe(1);
expect(parentNodes[0].vitamId).toBe(ORPHANS_NODE_ID);
});
});

describe('removeOrphansNodeFromTree', () => {
it('should not remove orphans node in empty array', () => {
const parentNodes: FilingHoldingSchemeNode[] = [];
FilingHoldingSchemeHandler.removeOrphansNodeFromTree(parentNodes);
expect(parentNodes.length).toBe(0);
});
it('should remove orphans node in first place of array', () => {
const parentNodes = [];
FilingHoldingSchemeHandler.addOrphansNodeFromTree(parentNodes, 'sans rattachement', 10);
expect(parentNodes.length).toBe(1);
FilingHoldingSchemeHandler.removeOrphansNodeFromTree(parentNodes);
expect(parentNodes.length).toBe(0);
});
it('should remove node if not orphans node', () => {
const parentNodes = [newTreeNode('node-1-1', 0)];
FilingHoldingSchemeHandler.removeOrphansNodeFromTree(parentNodes);
expect(parentNodes.length).toBe(1);
});
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ export class FilingHoldingSchemeHandler {
}
}


public static addOrphansNodeFromTree(parentNodes: FilingHoldingSchemeNode[],
nodeTitle: string,
orphansNumber: number) {
Expand All @@ -168,6 +167,13 @@ export class FilingHoldingSchemeHandler {
}
}

public static removeOrphansNodeFromTree(parentNodes: FilingHoldingSchemeNode[]) {
if (isEmpty(parentNodes) || !FilingHoldingSchemeHandler.isOrphansNode(parentNodes[0])) {
return;
}
parentNodes.shift();
}

public static keepEndNodesWithResultsOnly(nodes: FilingHoldingSchemeNode[]): FilingHoldingSchemeNode[] {
if (!nodes) {
return [];
Expand Down Expand Up @@ -289,7 +295,7 @@ export class FilingHoldingSchemeHandler {
}
} else if (initCount && (!child.count || child.count < 1)) {
child.count = 1;
matchingNodes.incrementUpdated();
matchingNodes.updatedNode(child);
} else {
matchingNodes.incrementFoundButUnchanged();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ export class MatchingNodesNumbers {
nodesAdded: number;
nodesAddedList: FilingHoldingSchemeNode[];
nodesUpdated: number;
nodesUpdatedList: FilingHoldingSchemeNode[];
nodesFoundButUnchanged: number;

constructor() {
this.nodesAdded = 0;
this.nodesAddedList = [];
this.nodesUpdated = 0;
this.nodesUpdatedList = [];
this.nodesFoundButUnchanged = 0;
}

Expand All @@ -73,8 +75,9 @@ export class MatchingNodesNumbers {
this.nodesAddedList.push(node);
}

incrementUpdated() {
updatedNode(node: FilingHoldingSchemeNode) {
this.nodesUpdated += 1;
this.nodesUpdatedList.push(node);
}

incrementFoundButUnchanged() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ describe('FilingHoldingSchemeNodeService', () => {
dataType: 'dataType-searchOrphansWithSearchCriterias'
},
{
criteria: '#allunitups',
criteria: '#unitups',
operator: CriteriaOperator.MISSING,
category: SearchCriteriaTypeEnum.FIELDS,
values: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class LeavesTreeApiService {
}
const newCriteriaList = [...searchCriterias.criteriaList];
newCriteriaList.push({
criteria: '#allunitups',
criteria: '#unitups',
operator: CriteriaOperator.MISSING,
category: SearchCriteriaTypeEnum.FIELDS,
values: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,26 @@ describe('LeavesTreeService', () => {
expect(parentNode.children[1].id).toEqual('node-0-2');
expect(parentNode.children[1].count).toEqual(1);
});
it('should not add children if already present but check facets', () => {
leavesTreeService.setSearchRequestResultFacets([
newResultFacet('node-0', 5),
newResultFacet('node-0-1', 5),
newResultFacet('node-0-2', 7)]);
const parentNode = newNode('node-0', [newTreeNode('node-0-1', 1), newTreeNode('node-0-2', 1)]);
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);
});
it('should add children and check facets', () => {
const parentNode = newNode('node-0', []);
leavesTreeService.setSearchRequestResultFacets([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ export class LeavesTreeService {
// ########## AFTER CALLS ####################################################################################################

private compareAddedNodeWithKnownFacets(nodes: FilingHoldingSchemeNode[]) {
console.log('LTS.compareAddedNodeWithKnownFacets');
if (isEmpty(this.searchRequestResultFacets)) {
console.log(' EMPTY FACETS');
return;
}
for (const node of nodes) {
Expand All @@ -72,7 +70,6 @@ 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;
Expand All @@ -81,15 +78,12 @@ export class LeavesTreeService {
// ########## SECONDARY CALLS ####################################################################################################

public loadNodesDetailsFromFacetsIdsAndAddThem(parentNodes: FilingHoldingSchemeNode[], facets: ResultFacet[]): Observable<PagedResult> {
console.log('LTS.loadNodesDetailsFromFacetsIdsAndAddThem');
if (isEmpty(facets)) {
console.log(' EMPTY FACET');
return EMPTY;
}
this.loadingNodesDetails = true;
return this.leavesTreeApiService.loadNodesDetailsFromFacetsIds(facets)
.pipe(map(pagedResult => {
console.log('LTS.loadNodesDetailsFromFacetsIds.PIPE');
FilingHoldingSchemeHandler.addChildrenRecursively(parentNodes, pagedResult.results, true);
FilingHoldingSchemeHandler.setCountRecursively(parentNodes, this.searchRequestResultFacets);
this.loadingNodesDetails = false;
Expand All @@ -100,65 +94,49 @@ export class LeavesTreeService {
// ########## MAIN CALLS ####################################################################################################

public searchUnderNode(parentNode: FilingHoldingSchemeNode): Observable<PagedResult> {
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);
this.compareAddedNodeWithKnownFacets([...matchingNodesNumbers.nodesAddedList, ...matchingNodesNumbers.nodesUpdatedList]);
return pagedResult;
}));
}

public searchUnderNodeWithSearchCriterias(parentNode: FilingHoldingSchemeNode): Observable<PagedResult> {
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);
this.compareAddedNodeWithKnownFacets([...matchingNodesNumbers.nodesAddedList, ...matchingNodesNumbers.nodesUpdatedList]);
return pagedResult;
}));
}

public searchAtNodeWithSearchCriterias(parentNode: FilingHoldingSchemeNode): Observable<PagedResult> {
console.log('LTS.searchAtNodeWithSearchCriterias');
return this.leavesTreeApiService.searchAtNodeWithSearchCriterias(parentNode, this.searchCriterias)
.pipe(map(pagedResult => {
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);
this.compareAddedNodeWithKnownFacets([...matchingNodesNumbers.nodesAddedList, ...matchingNodesNumbers.nodesUpdatedList]);
return pagedResult;
}));
}

public searchOrphans(parentNode: FilingHoldingSchemeNode): Observable<PagedResult> {
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);
this.compareAddedNodeWithKnownFacets([...matchingNodesNumbers.nodesAddedList, ...matchingNodesNumbers.nodesUpdatedList]);
return pagedResult;
}));
}

public searchOrphansWithSearchCriterias(parentNode: FilingHoldingSchemeNode): Observable<PagedResult> {
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);
this.compareAddedNodeWithKnownFacets([...matchingNodesNumbers.nodesAddedList, ...matchingNodesNumbers.nodesUpdatedList]);
return pagedResult;
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,6 @@ export class ArchiveSearchComponent implements OnInit, OnChanges, OnDestroy, Aft
}

onArchiveUnitCountChange(event: number) {
console.log('onArchiveUnitCountChange')
this.totalResults = event;
this.archiveSharedDataService.emitTotalResults(event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
[accessContract]="accessContract"
[nestedDataSourceLeaves]="nestedDataSourceLeaves"
[searchRequestResultFacets]="requestResultFacets"
[searchRequestResultsInFilingPlan]="requestResultsInFilingPlan"
[loadingNodeUnit]="loadingArchiveUnit.LEAVE"
(addToSearchCriteria)="addToSearchCriteria($event)"
(showNodeDetail)="fetchUaFromNodeAndShowDetails($event, 'LEAVE')">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { NestedTreeControl } from '@angular/cdk/tree';
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core';
import { MatTreeNestedDataSource } from '@angular/material/tree';
import { ActivatedRoute } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { Subscription } from 'rxjs';
import {
CriteriaDataType, CriteriaOperator, FilingHoldingSchemeHandler, FilingHoldingSchemeNode, PagedResult, ResultFacet, SearchCriteriaDto,
Expand Down Expand Up @@ -64,12 +65,14 @@ export class FilingHoldingSchemeComponent implements OnInit, OnDestroy {
requestResultFacets: ResultFacet[];
hasMatchesInSearch = false;
requestResultsInFilingPlan: number;
requestTotalResults: number;
loadingArchiveUnit: { [key: string]: boolean } = {
TREE: false,
LEAVE: false,
};

constructor(
private translateService: TranslateService,
private archiveService: ArchiveService,
private route: ActivatedRoute,
private archiveSharedDataService: ArchiveSharedDataService
Expand All @@ -80,6 +83,7 @@ export class FilingHoldingSchemeComponent implements OnInit, OnDestroy {
}

ngOnInit(): void {
this.subscribeOnTotalResultsChange();
this.subscribeResetNodesOnFilingHoldingNodesChanges();
this.subscribeOnNodeSelectionToSetCheck();
this.subscribeOnFacetsChangesToResetCounts();
Expand Down Expand Up @@ -121,11 +125,29 @@ export class FilingHoldingSchemeComponent implements OnInit, OnDestroy {
// fullNodes is a Graph .
// keeps last child with result only
this.nestedDataSourceLeaves.data = FilingHoldingSchemeHandler.keepEndNodesWithResultsOnly(this.fullNodes);
this.addOrRemoveOrphansNode();
this.showEveryNodes = false;
})
);
}

private refreshTreeNodes() {
const data = this.nestedDataSourceLeaves.data;
this.nestedDataSourceLeaves.data = null;
this.nestedDataSourceLeaves.data = data;
}

addOrRemoveOrphansNode() {
const orphans = this.requestTotalResults - this.requestResultsInFilingPlan;
if (orphans > 0) {
FilingHoldingSchemeHandler.addOrphansNodeFromTree(this.nestedDataSourceLeaves.data,
this.translateService.instant('ARCHIVE_SEARCH.FILING_SCHEMA.ORPHANS_NODE'), orphans);
} else {
FilingHoldingSchemeHandler.removeOrphansNodeFromTree(this.nestedDataSourceLeaves.data);
}
this.refreshTreeNodes();
}

private subscribeResetNodesOnFilingHoldingNodesChanges(): void {
this.subscriptions.add(
this.archiveSharedDataService.getFilingHoldingNodes().subscribe((nodes) => {
Expand Down Expand Up @@ -189,4 +211,13 @@ export class FilingHoldingSchemeComponent implements OnInit, OnDestroy {
})
);
}

private subscribeOnTotalResultsChange(): void {
this.subscriptions.add(
this.archiveSharedDataService.getTotalResults().subscribe((totalResults) => {
this.requestTotalResults = totalResults;
this.addOrRemoveOrphansNode();
})
);
}
}
Loading

0 comments on commit bfe82a2

Please sign in to comment.