Skip to content
Snippets Groups Projects
Commit 329787c0 authored by Baptiste Toulemonde's avatar Baptiste Toulemonde
Browse files

add feedback dialog

parent 8b65019d
No related branches found
No related tags found
1 merge request!12Fix/mapping
......@@ -35,9 +35,10 @@ import { MappingComponent } from './mapping/mapping.component';
import { NebularModule } from './nebular.module';
import { AppRoutingModule } from './app-routing.module';
import { NbLayoutModule, NbThemeModule, NbTooltipModule, NbSpinnerModule, NbSelectModule, NbTabsetModule, NbAutocompleteModule, NbListModule, NbAccordionModule } from '@nebular/theme';
import { NbLayoutModule, NbThemeModule, NbTooltipModule, NbSpinnerModule, NbSelectModule, NbTabsetModule, NbAutocompleteModule, NbListModule, NbAccordionModule, NbDialogModule } from '@nebular/theme';
import { DashboardComponent } from './dashboard/dashboard.component';
import { FeedbackDialogComponent } from './mapping/dialog/feedback-dialog/feedback-dialog.component';
......@@ -57,6 +58,7 @@ import { DashboardComponent } from './dashboard/dashboard.component';
StatsComponent,
DashboardComponent,
MappingComponent,
FeedbackDialogComponent,
],
imports: [
......@@ -85,7 +87,8 @@ import { DashboardComponent } from './dashboard/dashboard.component';
NbTooltipModule,
NbAutocompleteModule,
NbListModule,
NbAccordionModule
NbAccordionModule,
NbDialogModule.forRoot()
],
providers: [
......
<nb-card>
<nb-card-header>
<h3 style="text-align: center;">Feedback: </h3>
</nb-card-header>
<nb-card-body>
<nb-card>
<nb-card-body>
<p class="error" *ngIf="data.notPostedMetadatas">An error occurred while publishing the following Datasets: </p>
<ul class="error" *ngFor="let data of data.notPostedMetadatas">
<li class="error">{{ data }}</li>
</ul>
</nb-card-body>
</nb-card>
<nb-card>
<nb-card-body>
<p class="success" *ngIf="data.postedMetadatas">Athe following datasets have been published successfully: </p>
<ul *ngFor="let data of data.postedMetadatas">
<li class="success" >{{ data }}</li>
</ul>
</nb-card-body>
</nb-card>
</nb-card-body>
<nb-card-footer>
<div class="row">
<div class="button-center">
<button nbButton status="primary" (click)="close()">Close</button>
</div>
</div>
</nb-card-footer>
</nb-card>
\ No newline at end of file
.error {
color: crimson;
}
.succes {
color: forestgreen;
}
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FeedbackDialogComponent } from './feedback-dialog.component';
describe('FeedbackDialogComponent', () => {
let component: FeedbackDialogComponent;
let fixture: ComponentFixture<FeedbackDialogComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ FeedbackDialogComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(FeedbackDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, Inject, OnInit } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { NbDialogRef } from '@nebular/theme';
@Component({
selector: 'app-feedback-dialog',
templateUrl: './feedback-dialog.component.html',
styleUrls: ['./feedback-dialog.component.scss']
})
export class FeedbackDialogComponent implements OnInit {
constructor(private dialog: MatDialogRef<FeedbackDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: {postedMetadatas: string[], notPostedMetadatas: string[]} ) { }
ngOnInit(): void {
}
close() {
this.dialog.close();
}
}
......@@ -111,8 +111,6 @@
<button nbButton status="primary" (click)=" publishDataset()">Publish</button>
</div>
</div>
<nb-alert status="success" *ngIf="messageOk" closable style="margin-top: 10px;">{{ messageOk }}
</nb-alert>
</nb-card-footer>
</nb-card>
......
import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { Router } from '@angular/router';
import { NbDialogService } from '@nebular/theme';
import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { environment } from 'src/environments/environment.prod';
import { DatasetCrudService } from '../datasets/services/dataset-crud.service';
import { ParseXmlService } from '../services/parse-xml.service';
import { Dataset } from './class/dataset';
import { FeedbackDialogComponent } from './dialog/feedback-dialog/feedback-dialog.component';
@Component({
......@@ -28,12 +32,12 @@ export class MappingComponent implements OnInit {
first: boolean = true;
loading: boolean = false;
FDP_URL = environment.fdpUrl;
messageOk: string;
postedDatastes: string[];
notPostedDatasets: string[];
@ViewChild('autoInput') input;
@Input() catalogId: any;
constructor(private dataSetService: DatasetCrudService, private parserService: ParseXmlService) { }
constructor(private dataSetService: DatasetCrudService, private dialog: MatDialog, private route: Router) { }
ngOnInit() {
this.dataSetService.getLocally('./assets/dataset.json').subscribe(
......@@ -78,13 +82,12 @@ export class MappingComponent implements OnInit {
publishDataset() {
let data: string = '';
let properties: string = '';
let result = '';
this.postedDatastes = [];
this.notPostedDatasets = [];
this.loading = true;
for (let i = 0; i < this.mappedMetadatas.length; i++) {
this.loading = true;
let title = "";
properties = "";
this.messageOk = "";
this.mappedMetadatas[i].forEach((value: string, key: string) => {
if (key === 'dct:title') { title = value };
switch (key) {
......@@ -113,26 +116,68 @@ export class MappingComponent implements OnInit {
a dcat:Dataset, dcat:Resource;\n\
dct:isPartOf c:'+ this.catalogId + ';\n' + properties + '.';
let query = 'query=PREFIX dcat: <http://www.w3.org/ns/dcat#>\n\
/*let query = 'query=PREFIX dcat: <http://www.w3.org/ns/dcat#>\n\
PREFIX dct: <http://purl.org/dc/terms/>\n\
SELECT ?dataset\n\
where {\n\
?dataset a dcat:Dataset;\n\
dct:title "' + title + '" ;\n\
dct:isPartOf <https://f2ds.eosc-pillar.eu/catalog/' + this.catalogId + '>. } '
dct:isPartOf <https://f2ds.eosc-pillar.eu/catalog/' + this.catalogId + '>. } '*/
this.dataSetService.createDataset(data).subscribe(
() => {
this.messageOk = "Dataset published successfully"
this.loading = false;
(error: Error) => {
this.notPostedDatasets.push(title);
if (i === this.mappedMetadatas.length - 1) {
this.loading = false;
}
},
error => {
this.loading = false;
}
)
() => {
this.postedDatastes.push(title);
if (i === this.mappedMetadatas.length - 1) {
this.loading = false;
this.dialog.open(FeedbackDialogComponent, {
data: {
postedMetadatas: this.postedDatastes,
notPostedMetadatas: this.notPostedDatasets
}
}).afterClosed().subscribe(() => this.route.navigateByUrl('/dashboard'))
}
})
}
}
/* function to get recursively all the keys and values from the JSON object */
getKeysFromMetadata(obj: Object, keyParent: string) {
Object.keys(obj).forEach(key => {
if (typeof obj[key] === 'object') {
if (Array.isArray(obj[key])) {
obj[key].forEach(e => {
if (typeof e === 'object') {
this.getKeysFromMetadata(e, keyParent + ' : ' + key + ' : ' + obj[key].indexOf(e));
} else {
this.keys.push(keyParent + ' : ' + key + ' : ' + obj[key].indexOf(e))
}
});
} else {
if (keyParent) {
this.getKeysFromMetadata(obj[key], keyParent + ' : ' + key);
} else {
this.getKeysFromMetadata(obj[key], key);
}
}
} else {
if (keyParent) {
this.keys.push(keyParent + ' : ' + key)
} else {
this.keys.push(key)
}
}
});
}
private getValue(tab: string[], item: Object): string {
let obj: Object
for (let i = 0; i < tab.length; i++) {
......@@ -164,6 +209,8 @@ export class MappingComponent implements OnInit {
} else {
if (obj[table[i]]) {
return obj[table[i]];
} else {
return 'undefined';
}
}
}
......@@ -176,6 +223,8 @@ export class MappingComponent implements OnInit {
}
}
}
mapDataset() {
this.mappedMetadatas = [];
this.itemsdataset.forEach((dataset: Object) => {
......@@ -204,36 +253,6 @@ export class MappingComponent implements OnInit {
this.mappedMetadatas[this.index].delete(key);
}
/* function to get recursively all the keys and values from the JSON object */
getKeysFromMetadata(obj: Object, keyParent: string) {
Object.keys(obj).forEach(key => {
if (typeof obj[key] === 'object') {
if (Array.isArray(obj[key])) {
obj[key].forEach(e => {
if (typeof e === 'object') {
this.getKeysFromMetadata(e, keyParent + ' : ' + key + ' : ' + obj[key].indexOf(e));
} else {
this.keys.push(keyParent + ' : ' + key + ' : ' + obj[key].indexOf(e))
}
});
} else {
if (keyParent) {
this.getKeysFromMetadata(obj[key], keyParent + ' : ' + key);
} else {
this.getKeysFromMetadata(obj[key], key);
}
}
} else {
if (keyParent) {
this.keys.push(keyParent + ' : ' + key)
} else {
this.keys.push(key)
}
}
});
}
trackByIndex(index: number, obj: any): any {
return index;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment