From 8fa40640972a91078d2eafc31b7386fb5826f578 Mon Sep 17 00:00:00 2001 From: Baptiste Toulemonde <toulemonde@cines.fr> Date: Tue, 22 Feb 2022 11:28:44 +0100 Subject: [PATCH] feature to retieve all the distributions --- src/app/mapping/mapping.component.html | 60 +++++++++++++++----------- src/app/mapping/mapping.component.ts | 34 +++++++++------ 2 files changed, 57 insertions(+), 37 deletions(-) diff --git a/src/app/mapping/mapping.component.html b/src/app/mapping/mapping.component.html index 5d697b338..986828b76 100644 --- a/src/app/mapping/mapping.component.html +++ b/src/app/mapping/mapping.component.html @@ -51,8 +51,8 @@ </div> <div class="col-7"> - <nb-form-field> - <input *ngIf="isMandatory(dataset.card)" required fullWidth + <nb-form-field *ngIf="!isJsonPath; else blockJsonPath"> + <input *ngIf="isMandatory(dataset.card)" required fullWidth name=" data{{index}}" nbInput (ngModelChange)="onModelChange($event)" [nbAutocomplete]="auto" [(ngModel)]="selectedPaths[index]" [value]="selectedPaths[index]? selectedPaths[index] : ''" (focus)="reset()" /> @@ -67,9 +67,20 @@ {{ option }} </nb-option> </nb-autocomplete> + </nb-form-field> + <ng-template #blockJsonPath> + <input *ngIf="isMandatory(dataset.card)" required fullWidth + name=" data{{index}}" nbInput (ngModelChange)="onModelChange($event)" + [(ngModel)]="selectedPaths[index]" [value]="selectedPaths[index]? selectedPaths[index] : ''" + (focus)="reset()" /> + + <input *ngIf="!isMandatory(dataset.card)" fullWidth name=" data{{index}}" + nbInput (ngModelChange)="onModelChange($event)" + [(ngModel)]="selectedPaths[index]" [value]="selectedPaths[index]? selectedPaths[index] : ''" (focus)="reset()" /> - </nb-form-field> + + </ng-template> </div> <div class="col-2" *ngIf="isReplicable(dataset.card) " style="margin-left: 10px;"> <button nbButton ghost (click)="addField(index, datasets, selectedPaths)" *ngIf="dataset.uri !== datasets[index - 1].uri"> @@ -100,7 +111,14 @@ <div class="card-row" *ngIf="addDistribution"> <div class="card-col"> <nb-card size="giant"> - <nb-card-header>Distribution</nb-card-header> + <nb-card-header> + <div class="row"> + Distribution + </div> + <div class="row"> + <input [(ngModel)]="distributionValues" [ngModelOptions]="{standalone: true}"> + </div> + </nb-card-header> <nb-card-body> <ng-container *ngFor="let distribution of distributions; let index = index; trackBy: trackByIndex" > <nb-form-field> @@ -186,7 +204,7 @@ <nb-list> <nb-list-item - *ngFor="let data of datasetMappedMetadatas[index] | keyvalue; trackBy:trackByIndex; "> + *ngFor="let data of datasetMappedMetadatas[index][0] | keyvalue; trackBy:trackByIndex; "> <div class="row"> <div class="col-3"><label for="{{data.key}}">{{datasets[data.key].uri}}</label> @@ -194,12 +212,12 @@ <div class="col-7"> <ng-template #normal> <input nbInput [ngModel]="data.value" - (ngModelChange)="datasetMappedMetadatas[index].set(data.key, $event)" /> + (ngModelChange)="data.set(data.key, $event)" /> </ng-template> <ng-container *ngIf="isArray(data.value) && !isReplicable(datasets[data.key].card); else normal"> <input nbInput [ngModel]="data.value[0]" - (ngModelChange)="datasetMappedMetadatas[index].set(data.key, $event)" /> + (ngModelChange)="data.set(data.key, $event)" /> </ng-container> <ng-container *ngIf="isArray(data.value) && isReplicable(datasets[data.key].card)"> @@ -212,7 +230,7 @@ </div> <div class="col-7"> <input nbInput [ngModel]="val" - (ngModelChange)="datasetMappedMetadatas[index].set(data.key, $event)" /> + (ngModelChange)="data.set(data.key, $event)" /> </div> <div class="col-2"> @@ -226,7 +244,7 @@ <div class="col-2"> <button nbButton ghost> <nb-icon icon="trash-2-outline" status="danger" - (click)="deleteProperty(data.key, datasetMappedMetadatas)"> + (click)="deleteProperty(data.key, data)"> </nb-icon> </button> </div> @@ -235,28 +253,22 @@ </nb-list> </nb-card> - <nb-card> - <nb-card-header>Distribution</nb-card-header> - - <nb-list> + <nb-card *ngFor="let distrib of distributionMappedMetadatas[index]; trackBy:trackByIndex; let i = index"> + <nb-card-header> Distribution {{i + 1}}</nb-card-header> + <nb-list > <nb-list-item - *ngFor="let data of distributionMappedMetadatas[index] | keyvalue; trackBy:trackByIndex; "> + *ngFor="let data of distrib| keyvalue ; trackBy:trackByIndex;"> <div class="row"> <div class="col-3"><label for="{{data.key}}">{{distributions[data.key].uri}}</label> </div> <div class="col-7"> - <ng-template #normal> + <ng-container> <input nbInput [ngModel]="data.value" - (ngModelChange)="distributionMappedMetadatas[index].set(data.key, $event)" /> - </ng-template> - <ng-container - *ngIf="isArray(data.value) && !isReplicable(distributions[data.key].card); else normal"> - <input nbInput [ngModel]="data.value[0]" - (ngModelChange)="distributionMappedMetadatas[index].set(data.key, $event)" /> + (ngModelChange)="data[index].set(data.key, $event)" /> </ng-container> <ng-container - *ngIf="isArray(data.value) && isReplicable(distributions[data.key].card)"> + *ngIf="isArray(data.value) "> <ul *ngFor="let val of data.value" style="margin-left: -100px;"> <li> <div class="row"> @@ -266,7 +278,7 @@ </div> <div class="col-7"> <input nbInput [ngModel]="val" - (ngModelChange)="distributionMappedMetadatas[index].set(data.key, $event)" /> + (ngModelChange)="data[index].set(data.key, $event)" /> </div> <div class="col-2"> @@ -280,7 +292,7 @@ <div class="col-2"> <button nbButton ghost> <nb-icon icon="trash-2-outline" status="danger" - (click)="deleteProperty(data.key, distributionMappedMetadatas)"> + (click)="deleteProperty(data.key, data)"> </nb-icon> </button> </div> diff --git a/src/app/mapping/mapping.component.ts b/src/app/mapping/mapping.component.ts index afaaef818..fc9f429d1 100644 --- a/src/app/mapping/mapping.component.ts +++ b/src/app/mapping/mapping.component.ts @@ -25,6 +25,7 @@ import { JSONPath } from 'jsonpath-plus'; }) export class MappingComponent implements OnInit { + distributionValues: string = ''; addDistribution = false check = false; distributions: Property[] = []; @@ -37,8 +38,8 @@ export class MappingComponent implements OnInit { keys: string[] = []; selectedPaths: string[]; distributionSelectedPaths: string[]; - datasetMappedMetadatas: Map<number, string>[] = []; - distributionMappedMetadatas: Map<number, string>[] = []; + datasetMappedMetadatas: Array<Array<Map<number, string>>>; + distributionMappedMetadatas: Array<Array<Map<number, string>>>; index: number = 0 first: boolean = true; loading = false; @@ -156,7 +157,7 @@ export class MappingComponent implements OnInit { this.loading = true; const requestPromises: Promise<any>[] = []; - let requestPromise = this.mappingService.postToFdpFropSmartharvester(this.catalogId, data, this.isJsonPath).then( resp => { + let requestPromise = this.mappingService.postToFdpFropSmartharvester(this.catalogId, data, this.isJsonPath).then(resp => { if (resp) { console.log(resp); resp.json().then((datas: any) => { @@ -340,7 +341,7 @@ private getValueJsonPath(jsonPath: string, item: Object) { return value; } - private getValueCustom(tab: string[], item: Object){ + private getValueCustom(tab: string[], item: Object) { let obj: Object; if (tab.length == 1) { return item[tab[0]]; @@ -432,18 +433,25 @@ private getValueJsonPath(jsonPath: string, item: Object) { mapDataset() { this.loadingCr = true; - this.datasetMappedMetadatas = []; - this.distributionMappedMetadatas = []; - this.itemsdataset.forEach((dataset: Object) => { - this.datasetMappedMetadatas.push(this.createDataset(dataset, "dataset")); - this.distributionMappedMetadatas.push(this.createDataset(dataset, "distribution")) - }) - console.table(this.datasetMappedMetadatas); - console.log(this.distributionMappedMetadatas); + this.datasetMappedMetadatas = new Array<Array<Map<number, string>>>(); + this.distributionMappedMetadatas = new Array<Array<Map<number, string>>>() + for (let i = 0; i < this.itemsdataset.length; i++) { + this.datasetMappedMetadatas.push([this.createDataset(this.itemsdataset[i], "dataset")]); + if (this.distributionValues !== '') { + let distributionItems: Object[] = (this.isJsonPath) ? this.getValueJsonPath(this.distributionValues, this.itemsdataset[i]) : this.getValueCustom(this.distributionValues.split(' : '), this.itemsdataset[i]); + let distributionArray: Map<number, string>[] = [] + for (let j = 0; j < distributionItems.length; j++) { + distributionArray.push(this.createDataset(distributionItems[j], "distribution")); + } + this.distributionMappedMetadatas.push(distributionArray); + } else { + this.distributionMappedMetadatas.push([this.createDataset(this.itemsdataset[i], "distribution")]) + } + } this.first = false; } next() { - //this.loadingCr = true; + //this.loadingCr = true; if (this.index < this.itemsdataset.length) { this.index += 1; //this.createDataset(this.itemsdataset[this.index]) -- GitLab