diff --git a/src/app/authentication/services/auth.service.ts b/src/app/authentication/services/auth.service.ts index 885cddd297ce5d5350caa038a16b0b95bda79bfe..f5d40f6457417891f25df521bde406347b267631 100644 --- a/src/app/authentication/services/auth.service.ts +++ b/src/app/authentication/services/auth.service.ts @@ -44,7 +44,7 @@ export class AuthService { const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json', 'Authorization' : `Baerer ${this.getToken()}` }) }; - + return this.http.post(`${this.baseUrl}/harvester/auth/signup`, { firstName: user.firstName, lastName: user.lastName, @@ -57,6 +57,9 @@ export class AuthService { const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json'}) }; + if (!environment.staging && !environment.production) { + this.FdpBaseUrl = this.FdpBaseUrl.replace(':8080', ''); + } return this.http.post(`${this.FdpBaseUrl}/tokens`, { email: email, password: password @@ -86,11 +89,11 @@ export class AuthService { } isFdpLoggedIn(): boolean { - + return !this.tokenService.getFDPToken(); } - + logout() { return this.http.post(this.baseUrl + '/harvester/logout', this.getToken(), this.httpOptions); diff --git a/src/app/repository/services/publish-repository.service.ts b/src/app/repository/services/publish-repository.service.ts index 8e47736d5167c25ebfb2ea1b6cce9dfd6bdaca24..14e312955c7291ed910521bd1dc6376c76b78ddd 100644 --- a/src/app/repository/services/publish-repository.service.ts +++ b/src/app/repository/services/publish-repository.service.ts @@ -11,7 +11,7 @@ interface PersistentUrlResponse { persistentUrl: string; } -const FDP_URL = environment.fdpUrl; +let FDP_URL = environment.fdpUrl; @Injectable({ providedIn: 'root' }) @@ -26,7 +26,7 @@ export class PublishRepositoryService { ) { } get smartApiUrl(): string { - return environment.smartharvesterUrl + '/harvester/api' + return environment.smartharvesterUrl + '/harvester/api'; } async publishRepository(data: string) { @@ -39,12 +39,15 @@ export class PublishRepositoryService { myHeaders.append('Authorization', 'Bearer ' + this.fds2Token); const myInit = { method: 'POST', body: data, headers: myHeaders }; - const myRequest = new Request(FDP_URL + "/catalog", myInit); + if (!environment.staging && !environment.production) { + FDP_URL = FDP_URL.replace(':8080', ''); + } + const myRequest = new Request(FDP_URL + '/catalog', myInit); const response = await fetch(myRequest, myInit); - const id = await response.headers.get("location"); - const url = id - const catId = id.substring(id.search("catalog/") + 8, id.length); + const id = await response.headers.get('location'); + const url = id; + const catId = id.substring(id.search('catalog/') + 8, id.length); console.log('catalog creaetd with fdp / id = ' + catId); this.publishMetadata(url); return this.addUserCatalog(catId); @@ -58,8 +61,8 @@ export class PublishRepositoryService { const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json', - 'Accept': 'application/json', - 'Authorization': 'Bearer ' + this.fds2Token + Accept: 'application/json', + Authorization: 'Bearer ' + this.fds2Token }) }; @@ -68,7 +71,11 @@ export class PublishRepositoryService { } getPersistentUrl(): Observable<PersistentUrlResponse> { - return this.http.get<PersistentUrlResponse>(environment.fdpUrl + '/configs/bootstrap'); + let url = environment.fdpUrl; + if (!environment.staging && !environment.production) { + url = url.replace(':8080', ''); + } + return this.http.get<PersistentUrlResponse>(url + '/configs/bootstrap'); } async addUserCatalog(catId: string): Promise<any> { diff --git a/src/app/semantic-enrichment/semantic-enrichment.component.html b/src/app/semantic-enrichment/semantic-enrichment.component.html index 3afc771272940d0d17c8998bb6b11f2454103c66..01bb4fee45c69a7b5378dcb77047a7e8beecaa58 100644 --- a/src/app/semantic-enrichment/semantic-enrichment.component.html +++ b/src/app/semantic-enrichment/semantic-enrichment.component.html @@ -9,17 +9,62 @@ </nb-card> </ng-template> +<nb-autocomplete #auto [handleDisplayFn]="viewHandle" (selectedChange)="setIri($event)"> + <nb-option + *ngFor="let option of filteredOptions | async" + [value]="option"> + {{option.source.document.label}} + </nb-option> +</nb-autocomplete> + <ng-template #loading xmlns="http://www.w3.org/1999/html"> <nb-card size="small" [nbSpinner]="true" nbSpinnerStatus="primary" nbSpinnerSize="giant"></nb-card> </ng-template> <ng-container *ngIf="!isLoading; else loading"> - <ng-container *ngFor="let keyword of response; let index = index"> + <ng-container *ngFor="let keyword of response; let i = index" > <nb-accordion> <nb-accordion-item> <nb-accordion-item-header>{{keyword.id}} - <a href="{{keyword.url}}" target="_blank">link to dataset</a></nb-accordion-item-header> <nb-accordion-item-body> + <nb-card size="small"> + <nb-card-body> + <nb-form-field > + <input + type="text" + placeholder="enter a value with at least 4 characters" + [ngModel]="autocompleteMap.get(keyword.id)" + (ngModelChange)="onModelChange($event, keyword.id)" + nbInput + [nbAutocomplete]="auto" + (focusin)="setId(keyword.id)"> + + </nb-form-field> + <div class="mt0-m"> + <table *ngIf="autocompleteMap.get(keyword.id).length > 0"> + <thead style="background-color: #3366ff"> + <th></th> + <th class="text-center">label</th> + <th class="text-center">iri</th> + </thead> + <tbody> + <tr *ngFor="let value of autocompleteMap.get(keyword.id); let i = index "> + <td><button nbButton ghost> + <nb-icon icon="trash-2-outline" status="danger" + (click)="deleteProperty(keyword.id, i)"> + </nb-icon> + </button></td> + <td class="text-center">{{ value.source.document.label }}</td> + <td class="text-center">{{ value.source.document.iri }}</td> + + </tr> + </tbody> + </table> + </div> + </nb-card-body> + </nb-card> + <p *ngIf="myControl.get(keyword.id) !== null">{{ myControl.get(keyword.id) | json }}</p> <table> <thead style="background-color: #3366ff"> <th></th> @@ -45,41 +90,7 @@ </nb-accordion> </ng-container> - <nb-card size="small"> - <nb-card-body> - <nb-form-field> - <input - type="text" - placeholder="enter a value with at least 4 characters" - [formControl]="myControl" - nbInput - [nbAutocomplete]="auto"> - <nb-autocomplete #auto [handleDisplayFn]="viewHandle"> - <nb-option - *ngFor="let option of filteredOptions | async" - [value]="option"> - {{option.source.document.label}} - </nb-option> - </nb-autocomplete> - </nb-form-field> - <!-- <div class="mt0-m"> - <table *ngIf="myControl.value !== null"> - <thead style="background-color: #3366ff"> - <th class="text-center">label</th> - <th class="text-center">iri</th> - </thead> - <tbody> - <tr > - <td class="text-center">{{ myControl.value.source.document.label }}</td> - <td class="text-center">{{ myControl.value.source.document.iri }}</td> - </tr> - </tbody> - </table> - </div>--> - </nb-card-body> - </nb-card> - <p *ngIf="myControl.value !== null">{{ myControl.value | json }}</p> <div class="row"> <div class="button-center" > diff --git a/src/app/semantic-enrichment/semantic-enrichment.component.scss b/src/app/semantic-enrichment/semantic-enrichment.component.scss index 8b137891791fe96927ad78e64b0aad7bded08bdc..e4f89e3fbce8bac5a5b8e2dee1e3b840d055ec21 100644 --- a/src/app/semantic-enrichment/semantic-enrichment.component.scss +++ b/src/app/semantic-enrichment/semantic-enrichment.component.scss @@ -1 +1,4 @@ - +.button-center{ + vertical-align: middle; + margin: auto +} diff --git a/src/app/semantic-enrichment/semantic-enrichment.component.ts b/src/app/semantic-enrichment/semantic-enrichment.component.ts index 9e97a6fe848e8e2a588c3b196f97966ddb2d506c..da6fb67b8565757667cef210c0bd05658f61ff0d 100644 --- a/src/app/semantic-enrichment/semantic-enrichment.component.ts +++ b/src/app/semantic-enrichment/semantic-enrichment.component.ts @@ -9,7 +9,7 @@ import { import {Observable, of} from 'rxjs'; import {debounceTime, distinctUntilChanged, map, startWith, switchMap, tap} from 'rxjs/operators'; import {PostService} from './services/post.service'; -import {FormControl} from '@angular/forms'; +import {FormArray, FormBuilder, FormControl, FormGroup} from '@angular/forms'; import {KeywordResponse} from '../mapping/class/dataset'; import {ESModel, Result} from './ESModel'; import {ConceptsRequest, DataConcept} from './ConceptsRequest'; @@ -39,12 +39,15 @@ export class SemanticEnrichmentComponent implements OnInit { errorMess: string; response: KeywordResponse[]; - myControl = new FormControl(); + myControl: FormArray = new FormArray([]); filteredOptions: Observable<Result[]>; + autocompleteMap: Map<string, Result[]> = new Map<string, Result[]>(); + private loadingPublish: boolean; + private id: string; constructor(private service: PostService, private dialogService: NbDialogService, - private mappingService: MappingService, private matDialog: MatDialog) { + private mappingService: MappingService, private matDialog: MatDialog, private fb: FormBuilder) { this.filteredOptions = this.myControl.valueChanges.pipe( startWith(''), debounceTime(400), @@ -65,6 +68,8 @@ export class SemanticEnrichmentComponent implements OnInit { (response: KeywordResponse[]) => { this.response = response; this.response.forEach((resp: KeywordResponse) => { + this.autocompleteMap.set(resp.id, []); + this.myControl.push(new FormControl('')); resp.concepts.results.forEach((result: Result) => { if (resp.concepts.results.indexOf(result) === 0) { result.checked = true; @@ -119,6 +124,9 @@ export class SemanticEnrichmentComponent implements OnInit { concepts.iris.push(result.source.document.iri); } }); + if (this.autocompleteMap.get(data.id) && this.autocompleteMap.get(data.id).length > 0) { + this.autocompleteMap.get(data.id).forEach((result: Result) => concepts.iris.push(result.source.document.iri)); + } mappingData.dataConcepts.push(concepts); }); @@ -152,8 +160,27 @@ export class SemanticEnrichmentComponent implements OnInit { } + onModelChange(value: string, id: string) { + this.filteredOptions = this.filter(value); + } + setId(id: string) { + this.id = id; + } + setIri(option: Result) { + const iris = this.autocompleteMap.get(this.id); + if (iris) { + iris.push(option); + } + this.autocompleteMap.set(this.id, iris); + console.log(this.autocompleteMap); + } + deleteProperty(datasetKeyword: string, i: number) { + const results: Result[] = this.autocompleteMap.get(datasetKeyword); + results.splice(i, 1); + this.autocompleteMap.set(datasetKeyword, results); + } }