diff --git a/src/app/datasets/datasets.component.ts b/src/app/datasets/datasets.component.ts index f7db5d4bd21a71d1b3d53007cd34a46c2d880634..a3990d466ffe18016f8deab25a6d77b004d6b5e8 100644 --- a/src/app/datasets/datasets.component.ts +++ b/src/app/datasets/datasets.component.ts @@ -227,7 +227,7 @@ export class DatasetsComponent implements OnInit, OnChanges { continue; } - return content.example.split(':'); + return content.example.split('#'); } } } diff --git a/src/app/mapping/class/dataset.ts b/src/app/mapping/class/dataset.ts index 67c5bf82c9ee1bbffdda75b945d198c5e9f931a0..d4f2f6499b23d8608265d2e3ea7a7ce25e098516 100644 --- a/src/app/mapping/class/dataset.ts +++ b/src/app/mapping/class/dataset.ts @@ -4,4 +4,14 @@ export class Dataset { public usageNote: string; } +export class DatasetPath { + public dcatProperty: string; + public path: string + + constructor(dcatProperty: string, path: string) { + this.dcatProperty = dcatProperty; + this.path = path; + } +} + diff --git a/src/app/mapping/mapping.component.html b/src/app/mapping/mapping.component.html index eea8261a50e724c521a6a8658b5f7837edaea0ac..06db8c7672e015667c7aac231b4bc261b49b5bdf 100644 --- a/src/app/mapping/mapping.component.html +++ b/src/app/mapping/mapping.component.html @@ -1,9 +1,17 @@ <form #form="ngForm"> <div class="card-row"> <div class="card-col"> - <nb-card size="giant" > + <nb-card size="giant"> <nb-card-header>Dataset metadata</nb-card-header> <nb-card-body> + <div class="row"> + <p>Upload Or fill out the form with the path corresponding to the dcat property and save a new + file for next mappings:</p> + <button class="button-center" nbButton status="primary" (click)="openFileInputDialog()"> + <nb-icon icon="upload-outline"></nb-icon>Import file + </button> + <input type="file" id="file" (change)="importJson($event)" accept=".json" /> + </div> <ng-container *ngFor="let dataset of datasetModel; let index = index;trackBy:trackByIndex;"> <nb-form-field> @@ -43,7 +51,7 @@ #autoInput #{{dataset.identifier}}="ngModel" fullWidth id="{{dataset.identifier}}" name="{{dataset.identifier}}" nbInput (input)="onChange()" placeholder="Enter value" [nbAutocomplete]="auto" - [(ngModel)]="selectedPaths[index]" autocomplete="false" (focus)="reset()" /> + [(ngModel)]="selectedPaths[index]" autocomplete="false" (focus)="reset()" /> <nb-autocomplete #auto> @@ -63,6 +71,9 @@ </nb-card> </div> </div> + <div class="row"> + <button class="button-center" nbButton status="primary" (click)="downloadJson()">Save locally</button> + </div> <div class="row"> <button class="button-center" nbButton status="primary" (click)="mapDataset()" [disabled]="!form.valid">Check mapping</button> @@ -70,7 +81,7 @@ </form> <div class="card-row"> <div class="card-col"> - <nb-card [nbSpinner]="loadingCr" nbSpinnerStatus="primary" nbSpinnerSize="large" nbSpinnerMessage="loading"> + <nb-card [nbSpinner]="loadingCr" nbSpinnerStatus="primary" nbSpinnerSize="giant" nbSpinnerMessage="loading"> <nb-card-header>Map</nb-card-header> <nb-card-body> <nb-list> @@ -78,7 +89,7 @@ <nb-list-item *ngFor="let data of mappedMetadatas[index] | keyvalue; trackBy:trackByIndex; "> <div class="row"> <div class="col-5"><label for="{{data.key}}">{{data.key}}</label></div> - <div class="col-5"> <input nbInput [ngModel]="data.value" + <div class="col-5"> <input nbInput [ngModel]="data.value" (ngModelChange)="mappedMetadatas[index].set(data.key, $event)" /> </div> <div class="col-2"><button nbButton ghost> <nb-icon icon="trash-2-outline" status="danger" (click)="deleteProperty(data.key)"> @@ -107,7 +118,8 @@ </div> <div class="row"> <div class="button-center" *ngIf="!first "> - <button nbButton status="primary" (click)=" publishDataset()" [nbSpinner]="loading" nbSpinnerStatus="basic" >Publish</button> + <button nbButton status="primary" (click)=" publishDataset()" [nbSpinner]="loading" + nbSpinnerStatus="basic">Publish</button> </div> </div> diff --git a/src/app/mapping/mapping.component.scss b/src/app/mapping/mapping.component.scss index 9a0e2643936659799adea87b351a84d6e9554564..289b1adb30bc1c8f8318a28430e4f59d1f7a397b 100644 --- a/src/app/mapping/mapping.component.scss +++ b/src/app/mapping/mapping.component.scss @@ -7,7 +7,8 @@ .row { display: flex; flex: 1 0 calc(100%); - margin: 0 -0.5rem; + margin: 5px -0.5rem; + } .card-col { @@ -53,4 +54,9 @@ .button-center{ vertical-align: middle; margin: auto - } \ No newline at end of file + } + + #file { + display: none; + } + diff --git a/src/app/mapping/mapping.component.ts b/src/app/mapping/mapping.component.ts index 0b54724dd06582b84f18413325ae0824ed56f5af..5e76bf221cb38851c10b5103764d39485a77386a 100644 --- a/src/app/mapping/mapping.component.ts +++ b/src/app/mapping/mapping.component.ts @@ -4,13 +4,14 @@ import { HttpResponse } from '@angular/common/http'; import { Component, Input, OnInit, ViewChild } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; import { Router } from '@angular/router'; +import { FileSaverService } from 'ngx-filesaver'; import { Observable, of, Subscription } from 'rxjs'; import { map } from 'rxjs/operators'; import { environment } from 'src/environments/environment.prod'; import { DatasetCrudService } from '../datasets/services/dataset-crud.service'; -import { Dataset } from './class/dataset'; +import { Dataset, DatasetPath } from './class/dataset'; import { FeedbackDialogComponent } from './dialog/feedback-dialog/feedback-dialog.component'; @@ -40,7 +41,7 @@ export class MappingComponent implements OnInit { @ViewChild('autoInput') input; @Input() catalogId: any; - constructor(private dataSetService: DatasetCrudService, private dialog: MatDialog, private route: Router) { } + constructor(private dataSetService: DatasetCrudService, private dialog: MatDialog, private route: Router, private fileSaverService: FileSaverService) { } ngOnInit() { this.dataSetService.getLocally('./assets/dataset.json').subscribe( @@ -70,7 +71,6 @@ export class MappingComponent implements OnInit { } createDataset(item: Object): Map<string, string> { - this.loadingCr = true; let mappedMetadata: Map<string, string> = new Map() for (let i = 0; i < this.selectedPaths.length; i++) { if (this.selectedPaths[i]) { @@ -78,7 +78,7 @@ export class MappingComponent implements OnInit { mappedMetadata.set(this.datasetModel[i].identifier, this.getValue(tab, item)); } } - this.loadingCr = false + this.loadingCr = false; return mappedMetadata; } @@ -105,6 +105,9 @@ export class MappingComponent implements OnInit { case 'dcat:contactPoint': properties += key + ' <' + value + '>;\n'; break; + case 'dct:language': + properties += key + ' <' + value + '>;\n'; + break; default: properties += key + ' "' + value + '";\n'; break; @@ -192,12 +195,12 @@ export class MappingComponent implements OnInit { } else if (i < tab.length - 1 && obj[tab[i]]) { obj = obj[tab[i]]; } else { - if (obj[tab[i]]) { + if (obj[tab[i]] && typeof obj[tab[i]] !== 'object') { return obj[tab[i]]; } else { if (i == tab.length - 2) { this.getKeysFromMetadata(item, ""); - console.log(tab[i]) + console.log(tab[i] + " " + i) this.keys.forEach(k => { let table = k.split(" : "); if (table[table.length - 2] === tab[i]) { @@ -210,7 +213,7 @@ export class MappingComponent implements OnInit { } else if (i < table.length - 1 && obj[table[i]]) { obj = obj[table[i]]; } else { - if (obj[table[i]]) { + if (obj[table[i]] && typeof obj[tab[i]] !== 'object') { return obj[table[i]]; } else { return 'undefined'; @@ -229,13 +232,13 @@ export class MappingComponent implements OnInit { mapDataset() { + this.loadingCr = true; this.mappedMetadatas = []; this.itemsdataset.forEach((dataset: Object) => { - this.mappedMetadatas.push(this.createDataset(dataset)) + this.mappedMetadatas.push(this.createDataset(dataset)); }) - console.log(this.mappedMetadatas) - this.first = false; - } + console.log(this.mappedMetadatas); + this.first = false; } next() { this.loadingCr = true; if (this.index < this.itemsdataset.length) { @@ -253,6 +256,42 @@ export class MappingComponent implements OnInit { console.log('index = ' + this.index); } + downloadJson() { + let datasetPathArray: DatasetPath[] = []; + for (let i = 0; i < this.datasetModel.length; i++){ + if (this.selectedPaths[i]) { + datasetPathArray.push(new DatasetPath(this.datasetModel[i].identifier, this.selectedPaths[i])); + } else { + datasetPathArray.push(new DatasetPath(this.datasetModel[i].identifier, "")); + } + + } + + const fileName = 'paths.json'; + const fileType = this.fileSaverService.genType(fileName); + const txtBlob = new Blob([(JSON.stringify(datasetPathArray)).toString()], {type: fileName}); + this.fileSaverService.save(txtBlob, fileName); + } + + openFileInputDialog(): void { + document.getElementById('file').click(); + } + + importJson(event: Event) { + const files: FileList = (event.target as HTMLInputElement).files; + const jsonFile = files[0]; + console.log(jsonFile) + let reader = new FileReader(); + let datasetPath: DatasetPath[] = []; + reader.onloadend = () => { + + datasetPath = <DatasetPath[]> JSON.parse(reader.result as string); + datasetPath.forEach(e => { + this.selectedPaths[datasetPath.indexOf(e)] = e.path; + }) + } + reader.readAsText(jsonFile); + } // to delete a property of dcat dataset mapped deleteProperty(key: string) { this.mappedMetadatas[this.index].delete(key); diff --git a/src/app/publishapi/publishapi.component.html b/src/app/publishapi/publishapi.component.html index f667a81740fa052fed859e80b1a99fd0e046db3f..0faee30e90e69dcf393c3644eae036efddf1809b 100644 --- a/src/app/publishapi/publishapi.component.html +++ b/src/app/publishapi/publishapi.component.html @@ -250,7 +250,7 @@ <div *ngFor="let content of response.contents"> <nb-form-field> <nb-icon nbSuffix icon="question-mark-circle-outline" pack="eva" - nbTooltip="Example: key1:key2:key3" nbTooltipPlacement="right"> + nbTooltip="Example: key1#key2#key3" nbTooltipPlacement="right"> </nb-icon> <input name="default" [(ngModel)]="content.example" nbInput /> </nb-form-field>