220 lines
6.2 KiB
TypeScript
220 lines
6.2 KiB
TypeScript
import { Component, Inject, OnInit, ViewChild } from '@angular/core';
|
|
import { Page, BrowseTerm, Datasource, KeyValue, DsmConf, ProtocolParam } from '../common/is.model';
|
|
import { ISService } from '../common/is.service';
|
|
import { ActivatedRoute, Params } from '@angular/router';
|
|
import { MatDialog, MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
|
import { MatTableDataSource } from '@angular/material/table';
|
|
import { MatSort } from '@angular/material/sort';
|
|
import { combineLatest } from 'rxjs';
|
|
import { Router } from '@angular/router';
|
|
import { PageEvent } from '@angular/material/paginator';
|
|
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
|
import { MatSelectChange } from '@angular/material/select';
|
|
|
|
@Component({
|
|
selector: 'app-dsm-search',
|
|
templateUrl: './dsm-search.component.html',
|
|
styleUrls: ['./dsm.component.css']
|
|
})
|
|
export class DsmSearchComponent implements OnInit {
|
|
searchText:string = '';
|
|
browsableFields:KeyValue[] = [];
|
|
|
|
constructor(public service: ISService, public route: ActivatedRoute, public router: Router, public dialog: MatDialog) {
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.service.dsmBrowsableFields((data: KeyValue[]) => this.browsableFields = data);
|
|
}
|
|
|
|
search() {
|
|
this.router.navigate(['/dsm/results/0/50'], {
|
|
queryParams: { value: this.searchText }
|
|
});
|
|
}
|
|
|
|
browseField(field:string, label:string) {
|
|
const dialogRef = this.dialog.open(DsmBrowseDialog, {
|
|
data: { field: field, label: label },
|
|
width: '80%'
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
@Component({
|
|
selector: 'app-dsm-results',
|
|
templateUrl: './dsm-results.component.html',
|
|
styleUrls: ['./dsm.component.css']
|
|
})
|
|
export class DsmResultsComponent implements OnInit {
|
|
filterText:string = '';
|
|
results:Datasource[] = [];
|
|
nResults:number = 0;
|
|
currPage:number = 0;
|
|
nPages:number = 0;
|
|
pageSize:number = 0;
|
|
field?:string;
|
|
value:string = '';
|
|
|
|
constructor(public service: ISService, public route: ActivatedRoute, public router: Router, public dialog: MatDialog) {
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
combineLatest([ this.route.params, this.route.queryParams ],
|
|
(params: Params, queryParams: Params) => ({ params, queryParams })
|
|
).subscribe((res: { params: Params; queryParams: Params }) => {
|
|
const { params, queryParams} = res;
|
|
this.currPage = parseInt(params['page']);
|
|
this.pageSize = parseInt(params['size']);
|
|
this.field = queryParams['field'];
|
|
this.value = queryParams['value'];
|
|
this.reload();
|
|
});
|
|
}
|
|
|
|
reload() {
|
|
if (this.field) {
|
|
this.service.dsmSearchByField(this.field, this.value, this.currPage, this.pageSize, (page:Page<Datasource>) => {
|
|
this.results = page.content;
|
|
this.nResults = page.totalElements;
|
|
this.nPages = page.totalPages;
|
|
});
|
|
} else {
|
|
this.service.dsmSearch(this.value, this.currPage, this.pageSize, (page:Page<Datasource>) => {
|
|
this.results = page.content;
|
|
this.nResults = page.totalElements;
|
|
this.nPages = page.totalPages;
|
|
});
|
|
}
|
|
}
|
|
|
|
changePage(event: PageEvent) {
|
|
let path = '/dsm/results/' + event.pageIndex + '/' + event.pageSize;
|
|
let qp = this.field ?
|
|
{ field: this.field, value: this.value } :
|
|
{ value: this.value };
|
|
|
|
this.router.navigate([path], {
|
|
queryParams: qp
|
|
});
|
|
}
|
|
|
|
openAddApiDialog(dsId:string, dsName:string) {
|
|
const dialogRef = this.dialog.open(DsmAddApiDialog, {
|
|
data: { dsId: dsId, dsName: dsName },
|
|
width: '80%'
|
|
});
|
|
|
|
dialogRef.afterClosed().subscribe(result => {
|
|
if (result) this.reload();
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
@Component({
|
|
selector: 'app-dsm-api',
|
|
templateUrl: './dsm-api.component.html',
|
|
styleUrls: ['./dsm.component.css']
|
|
})
|
|
export class DsmApiComponent {
|
|
|
|
}
|
|
|
|
@Component({
|
|
selector: 'dsm-browse-dialog',
|
|
templateUrl: 'dsm-browse-dialog.html',
|
|
styleUrls: ['./dsm.component.css']
|
|
})
|
|
export class DsmBrowseDialog implements OnInit {
|
|
|
|
datasource: MatTableDataSource<BrowseTerm> = new MatTableDataSource<BrowseTerm>([]);
|
|
colums: string[] = ['name', 'total'];
|
|
|
|
@ViewChild(MatSort) sort: MatSort | undefined
|
|
|
|
constructor(public dialogRef: MatDialogRef<DsmBrowseDialog>, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService) {
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
this.service.dsmBrowse(this.data.field, (res:BrowseTerm[]) => this.datasource.data = res);
|
|
}
|
|
|
|
ngAfterViewInit() {
|
|
if (this.sort) this.datasource.sort = this.sort;
|
|
}
|
|
|
|
applyFilter(event: Event) {
|
|
const filterValue = (event.target as HTMLInputElement).value.trim().toLowerCase();
|
|
this.datasource.filter = filterValue;
|
|
}
|
|
|
|
onNoClick(): void {
|
|
this.dialogRef.close();
|
|
}
|
|
}
|
|
|
|
|
|
@Component({
|
|
selector: 'dsm-add-api-dialog',
|
|
templateUrl: './dsm-add-api.dialog.html',
|
|
styleUrls: ['./dsm.component.css']
|
|
})
|
|
export class DsmAddApiDialog {
|
|
apiPrefix:string = '';
|
|
|
|
|
|
apiIdControl = new FormControl('');
|
|
|
|
addApiForm = new FormGroup({
|
|
apiId: this.apiIdControl,
|
|
compatibility : new FormControl(''),
|
|
contentdescription : new FormControl(''),
|
|
protocol : new FormControl(''),
|
|
baseurl : new FormControl(''),
|
|
metadataIdentifierPath : new FormControl('')
|
|
});
|
|
|
|
protocols:string[] = [];
|
|
compatibilityLevels:string[] = [];
|
|
contentDescTypes:string[] = [];
|
|
|
|
protocolsMap:any = {};
|
|
selProtParams:ProtocolParam[] = [];
|
|
|
|
|
|
constructor(public dialogRef: MatDialogRef<DsmAddApiDialog>, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService) {
|
|
this.apiPrefix = 'api_________::' + data.dsId + '::';
|
|
this.service.dsmConf((conf:DsmConf) => {
|
|
this.compatibilityLevels = conf.compatibilityLevels;
|
|
this.contentDescTypes = conf.contentDescTypes;
|
|
conf.protocols.forEach((p) => {
|
|
this.protocols.push(p.id);
|
|
this.protocolsMap[p.id] = p.params;
|
|
});
|
|
});
|
|
}
|
|
|
|
onChangeProtocol(e:MatSelectChange):void {
|
|
|
|
if (this.protocolsMap[e.value]) {
|
|
this.selProtParams = this.protocolsMap[e.value];
|
|
} else {
|
|
this.selProtParams = this.protocolsMap[e.value];
|
|
}
|
|
}
|
|
|
|
onSubmit():void {
|
|
//const api = DsmAddApiDialog.value;
|
|
//api.apiId = this.apiPrefix + api.apiId; IMPORTANT
|
|
//this.service.dsmAddApi(api, (data: void) => this.dialogRef.close(1), this.metadataForm);
|
|
|
|
|
|
}
|
|
|
|
onNoClick(): void {
|
|
this.dialogRef.close();
|
|
}
|
|
}
|