Commit 6e3f856e authored by EL HAJJIOUI Nabil's avatar EL HAJJIOUI Nabil Committed by Ro3034
Browse files

[VAS] 9063: front sorting trees holding and filling scheme

parent 67597001
......@@ -50,7 +50,7 @@ import { Unit } from './models/unit.interface';
import { VitamUISnackBarComponent } from './shared/vitamui-snack-bar';
@Injectable({
providedIn: 'root',
providedIn: 'root'
})
export class ArchiveService extends SearchService<any> {
constructor(
......@@ -72,7 +72,7 @@ export class ArchiveService extends SearchService<any> {
pageNumbers:
+response.$hits.size !== 0
? Math.floor(+response.$hits.total / +response.$hits.size) + (+response.$hits.total % +response.$hits.size === 0 ? 0 : 1)
: 0,
: 0
};
const resultFacets: ResultFacet[] = [];
if (response.$facetResults && response.$facetResults) {
......@@ -100,7 +100,7 @@ export class ArchiveService extends SearchService<any> {
public loadFilingHoldingSchemeTree(tenantIdentifier: number, accessContractId: string): Observable<FilingHoldingSchemeNode[]> {
const headers = new HttpHeaders({
'X-Tenant-Id': '' + tenantIdentifier,
'X-Access-Contract-Id': accessContractId,
'X-Access-Contract-Id': accessContractId
});
return this.archiveApiService.getFilingHoldingScheme(headers).pipe(
......@@ -129,14 +129,18 @@ export class ArchiveService extends SearchService<any> {
parents: parentNode ? [parentNode] : [],
vitamId: unit['#id'],
checked: false,
hidden: false,
hidden: false
};
outNode.children = this.buildNestedTreeLevels(arr, outNode).sort(byTitle(this.locale));
outNode.children = this.buildNestedTreeLevels(arr, outNode);
out.push(outNode);
}
});
return out;
return this.sortByTitle(out);
}
sortByTitle(data: FilingHoldingSchemeNode[]): FilingHoldingSchemeNode[] {
return data.sort(byTitle(this.locale));
}
exportCsvSearchArchiveUnitsByCriteria(criteriaDto: SearchCriteriaDto, accessContract: string) {
......@@ -160,7 +164,7 @@ export class ArchiveService extends SearchService<any> {
this.snackBar.openFromComponent(VitamUISnackBarComponent, {
panelClass: 'vitamui-snack-bar',
data: { type: 'exportCsvLimitReached' },
duration: 10000,
duration: 10000
});
}
}
......@@ -236,9 +240,9 @@ export class ArchiveService extends SearchService<any> {
data: {
type: 'WorkflowSuccessSnackBar',
message,
serviceUrl,
serviceUrl
},
duration: 100000,
duration: 100000
});
}
......@@ -258,7 +262,7 @@ export class ArchiveService extends SearchService<any> {
if (!allunitups || allunitups.length === 0) {
return of({
fullPath: '',
resumePath: '',
resumePath: ''
});
}
......@@ -268,14 +272,14 @@ export class ArchiveService extends SearchService<any> {
values: allunitups,
operator: CriteriaOperator.EQ,
category: SearchCriteriaTypeEnum[SearchCriteriaTypeEnum.FIELDS],
dataType: CriteriaDataType.STRING,
},
dataType: CriteriaDataType.STRING
}
];
const searchCriteria = {
criteriaList: criteriaSearchList,
pageNumber: 0,
size: archiveUnit['#allunitups'].length,
size: archiveUnit['#allunitups'].length
};
return this.searchArchiveUnitsByCriteria(searchCriteria, accessContract).pipe(
......@@ -302,7 +306,7 @@ export class ArchiveService extends SearchService<any> {
return {
fullPath,
resumePath,
resumePath
};
})
);
......@@ -319,6 +323,6 @@ function byTitle(locale: string): (a: FilingHoldingSchemeNode, b: FilingHoldingS
return 0;
}
return a.title.localeCompare(b.title, locale);
return a.title.localeCompare(b.title, locale, { numeric: true });
};
}
......@@ -34,15 +34,15 @@
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
import { Component, OnInit, Input, OnChanges, SimpleChanges } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { NestedTreeControl } from '@angular/cdk/tree';
import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
import { MatTreeNestedDataSource } from '@angular/material/tree';
import { ArchiveService } from '../archive.service';
import { ActivatedRoute } from '@angular/router';
import { Subscription } from 'rxjs';
import { ArchiveSharedDataServiceService } from '../../core/archive-shared-data-service.service';
import { ArchiveService } from '../archive.service';
import { FilingHoldingSchemeNode } from '../models/node.interface';
import { NodeData } from '../models/nodedata.interface';
import { Subscription } from 'rxjs';
import { ResultFacet } from '../models/search.criteria';
@Component({
......@@ -61,7 +61,6 @@ export class FilingHoldingSchemeComponent implements OnInit, OnChanges {
nestedTreeControlFull: NestedTreeControl<FilingHoldingSchemeNode>;
nestedDataSourceFull: MatTreeNestedDataSource<FilingHoldingSchemeNode>;
nestedTreeControlFiltred: NestedTreeControl<FilingHoldingSchemeNode>;
nestedDataSourceFiltred: MatTreeNestedDataSource<FilingHoldingSchemeNode>;
......@@ -77,36 +76,36 @@ export class FilingHoldingSchemeComponent implements OnInit, OnChanges {
filtered: boolean;
constructor(private archiveService: ArchiveService, private route: ActivatedRoute,
private archiveSharedDataServiceService: ArchiveSharedDataServiceService) {
this.route.params.subscribe(params => {
constructor(
private archiveService: ArchiveService,
private route: ActivatedRoute,
private archiveSharedDataServiceService: ArchiveSharedDataServiceService
) {
this.route.params.subscribe((params) => {
this.tenantIdentifier = params.tenantIdentifier;
});
this.nestedTreeControlFull = new NestedTreeControl<FilingHoldingSchemeNode>((node) => node.children);
this.nestedDataSourceFull = new MatTreeNestedDataSource();
this.nestedTreeControlFiltred = new NestedTreeControl<FilingHoldingSchemeNode>((node) => node.children);
this.nestedDataSourceFiltred = new MatTreeNestedDataSource();
this.subscriptionNodesFull = this.archiveSharedDataServiceService.getNodesTarget().subscribe(nodeId => {
if(nodeId == null){
this.subscriptionNodesFull = this.archiveSharedDataServiceService.getNodesTarget().subscribe((nodeId) => {
if (nodeId == null) {
this.showAllTreeNodes();
}else {
} else {
this.recursiveShowById(this.nestedDataSourceFull.data, false, nodeId);
this.recursiveShowById(this.nestedDataSourceFiltred.data, false, nodeId);
}
});
this.subscriptionFacets = this.archiveSharedDataServiceService.getFacets().subscribe(facets => {
this.hasResults = true;
if (facets && facets.length > 0) {
for(const node of this.nestedDataSourceFull.data) {
this.recursiveByNode(node, facets);
}
this.subscriptionFacets = this.archiveSharedDataServiceService.getFacets().subscribe((facets) => {
this.hasResults = true;
if (facets && facets.length > 0) {
for (const node of this.nestedDataSourceFull.data) {
this.recursiveByNode(node, facets);
}
} else {
for (const node of this.nestedDataSourceFull.data) {
node.count = 0;
......@@ -116,17 +115,17 @@ export class FilingHoldingSchemeComponent implements OnInit, OnChanges {
this.filterNodes();
});
this.archiveSharedDataServiceService.getFilingHoldingNodes().subscribe(nodes => {
this.archiveSharedDataServiceService.getFilingHoldingNodes().subscribe((nodes) => {
if (nodes) {
this.fullNodes = nodes;
this.showAllTreeNodes();
this.fullNodes = nodes;
this.showAllTreeNodes();
}
});
}
}
convertNodesToList(holdingSchemas: FilingHoldingSchemeNode[]): string[] {
let nodeDataList : string[] = [];
for(const node of holdingSchemas) {
if(node && node.id){
let nodeDataList: string[] = [];
for (const node of holdingSchemas) {
if (node && node.id) {
nodeDataList.push(node.id);
}
}
......@@ -134,52 +133,54 @@ export class FilingHoldingSchemeComponent implements OnInit, OnChanges {
}
recursive(nodes: FilingHoldingSchemeNode[], facets: ResultFacet[]): number {
let nodesChecked = 0;
if (nodes.length === 0) {return 0; }
if (nodes.length === 0) {
return 0;
}
for (const node of nodes) {
node.count = -1;
for (const facet of facets) {
if (node.id === facet.node) {
node.count = facet.count;
node.count = facet.count;
node.hidden = false;
nodesChecked++;
}
}
let nodesCheckedChilren = 0;
if(node.children){
let nodesCheckedChilren = 0;
if (node.children) {
nodesCheckedChilren = this.recursive(node.children, facets);
}
node.hidden = (nodesCheckedChilren === 0) && (nodesChecked === 0 );
node.hidden = nodesCheckedChilren === 0 && nodesChecked === 0;
nodesChecked += nodesCheckedChilren;
}
return nodesChecked;
return nodesChecked;
}
recursiveByNode(node: FilingHoldingSchemeNode, facets: ResultFacet[]): number {
let nodesChecked = 0;
if(!node) { return 0; }
let nodesChecked = 0;
if (!node) {
return 0;
}
node.count = 0;
for(const facet of facets) {
if(node.id === facet.node) {
node.count = facet.count;
node.hidden = false;
nodesChecked++;
}
for (const facet of facets) {
if (node.id === facet.node) {
node.count = facet.count;
node.hidden = false;
nodesChecked++;
}
}
let nodesCheckedChilren = 0;
if(node.children) {
for(const child of node.children) {
nodesCheckedChilren += this.recursiveByNode(child, facets);
let nodesCheckedChilren = 0;
if (node.children) {
for (const child of node.children) {
nodesCheckedChilren += this.recursiveByNode(child, facets);
}
}
}
node.hidden = (nodesCheckedChilren === 0) && (nodesChecked === 0);
node.hidden = nodesCheckedChilren === 0 && nodesChecked === 0;
return nodesCheckedChilren;
}
ngOnInit() {
}
ngOnInit() {}
ngOnChanges(changes: SimpleChanges): void {
if (changes.accessContract) {
......@@ -190,51 +191,58 @@ export class FilingHoldingSchemeComponent implements OnInit, OnChanges {
initFilingHoldingSchemeTree() {
this.loadingHolding = true;
this.archiveService
.loadFilingHoldingSchemeTree(this.tenantIdentifier, this.accessContract)
.subscribe(nodes => {
this.fullNodes = nodes;
this.nestedDataSourceFull.data = nodes;
this.nestedTreeControlFull.dataNodes = nodes;
this.loadingHolding = false;
this.filtered = false;
this.archiveSharedDataServiceService.emitEntireNodes(this.convertNodesToList(nodes));
this.archiveSharedDataServiceService.emitFilingHoldingNodes(nodes);
});
this.archiveService.loadFilingHoldingSchemeTree(this.tenantIdentifier, this.accessContract).subscribe((nodes) => {
this.fullNodes = nodes;
this.nestedDataSourceFull.data = nodes;
this.nestedTreeControlFull.dataNodes = nodes;
this.loadingHolding = false;
this.filtered = false;
this.archiveSharedDataServiceService.emitEntireNodes(this.convertNodesToList(nodes));
this.archiveSharedDataServiceService.emitFilingHoldingNodes(nodes);
});
}
filterNodes(){
this.filtredNodes = [];
for(const node of this.fullNodes) {
let filtredNode = this.buildrecursiveTree(node);
if(filtredNode !== null){
this.filtredNodes.push(filtredNode);
}
filterNodes() {
this.filtredNodes = [];
for (const node of this.fullNodes) {
let filtredNode = this.buildrecursiveTree(node);
if (filtredNode !== null) {
this.filtredNodes.push(filtredNode);
}
this.nestedDataSourceFiltred.data = this.filtredNodes;
this.nestedTreeControlFiltred.dataNodes = this.filtredNodes;
this.loadingHolding = false;
this.filtered = true;
}
this.nestedDataSourceFiltred.data = this.filtredNodes;
this.nestedTreeControlFiltred.dataNodes = this.filtredNodes;
this.loadingHolding = false;
this.filtered = true;
}
buildrecursiveTree(node: FilingHoldingSchemeNode){
if(node.count === 0) return null;
buildrecursiveTree(node: FilingHoldingSchemeNode) {
if (node.count === 0) return null;
else {
let filtredNode: FilingHoldingSchemeNode = { count: node.count, id: node.id, label: node.label, title: node.title, type: node.type, children: null, parents: null, vitamId: node.vitamId, checked: node.checked};
if(node.children && node.children.length > 0){
let filtredNode: FilingHoldingSchemeNode = {
count: node.count,
id: node.id,
label: node.label,
title: node.title,
type: node.type,
children: null,
parents: null,
vitamId: node.vitamId,
checked: node.checked
};
if (node.children && node.children.length > 0) {
let filtredChildren = [];
for(const child of node.children) {
for (const child of node.children) {
let childFiltred = this.buildrecursiveTree(child);
if(childFiltred) {
if (childFiltred) {
filtredChildren.push(childFiltred);
}
}
if(filtredChildren && filtredChildren.length > 0){
filtredNode.children = filtredChildren;
}
}
if (filtredChildren && filtredChildren.length > 0) {
filtredNode.children = filtredChildren;
}
}
}
return filtredNode;
}
}
......@@ -245,17 +253,18 @@ export class FilingHoldingSchemeComponent implements OnInit, OnChanges {
this.nodeData = { id: node.id, title: node.title, checked: node.checked, count: node.count };
this.recursiveShowById(this.nestedDataSourceFull.data, node.checked, node.id);
this.archiveSharedDataServiceService.emitNode(this.nodeData);
}
onTouched = () => {
}
onTouched = () => {};
showAllTreeNodes() {
this.filtered = false;
}
recursiveShow(nodes: FilingHoldingSchemeNode[], show: boolean) {
if (nodes.length === 0) { return; }
if (nodes.length === 0) {
return;
}
for (const node of nodes) {
node.hidden = show;
this.recursiveShow(node.children, show);
......@@ -265,23 +274,21 @@ export class FilingHoldingSchemeComponent implements OnInit, OnChanges {
}
recursiveShowById(nodes: FilingHoldingSchemeNode[], checked: boolean, nodeId: string): boolean {
let found = false;
if (nodes.length !== 0){
for (const node of nodes) {
if (node.id === nodeId) {
node.checked = checked;
found= true;
}
if(!found && node.children){
found = this.recursiveShowById(node.children, checked, nodeId);
let found = false;
if (nodes.length !== 0) {
for (const node of nodes) {
if (node.id === nodeId) {
node.checked = checked;
found = true;
}
if (!found && node.children) {
found = this.recursiveShowById(node.children, checked, nodeId);
}
}
}
return found;
}
}
emitClose() {
this.archiveSharedDataServiceService.emitToggle(false);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment