178 lines
5.1 KiB
TypeScript
178 lines
5.1 KiB
TypeScript
import { Component, Inject, OnInit } from '@angular/core';
|
|
import { ISService } from '../common/is.service';
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
import { MatDialog, MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
|
import { MDStore, MDStoreRecord, MDStoreVersion } from '../common/is.model';
|
|
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
|
|
|
@Component({
|
|
selector: 'app-mdstores',
|
|
templateUrl: './mdstores.component.html',
|
|
styleUrls: ['./mdstores.component.css']
|
|
})
|
|
export class MdstoresComponent implements OnInit {
|
|
|
|
mdstores: MDStore[] = [];
|
|
searchText: string = '';
|
|
|
|
constructor(public service: ISService, public route: ActivatedRoute, public dialog: MatDialog) { }
|
|
|
|
ngOnInit() { this.reload() }
|
|
reload() { this.service.loadMDStores((data: MDStore[]) => this.mdstores = data); }
|
|
|
|
openVersionsDialog(md: MDStore): void {
|
|
const dialogRef = this.dialog.open(MDStoreVersionsDialog, {
|
|
data: md,
|
|
width: '80%'
|
|
});
|
|
|
|
dialogRef.afterClosed().subscribe(result => {
|
|
if (result) this.reload();
|
|
});
|
|
}
|
|
|
|
openAddMdstoreDialog(): void {
|
|
const dialogRef = this.dialog.open(AddMDStoreDialog, {
|
|
data: {},
|
|
width: '80%'
|
|
});
|
|
|
|
dialogRef.afterClosed().subscribe(result => {
|
|
if (result) this.reload();
|
|
});
|
|
}
|
|
|
|
createNewVersion(md: MDStore): void {
|
|
this.service.prepareNewMDStoreVersion(md.id, (data: MDStoreVersion) => {
|
|
md.numberOfVersions = md.numberOfVersions + 1;
|
|
this.openVersionsDialog(md);
|
|
});
|
|
}
|
|
|
|
deleteMdstore(md: MDStore) {
|
|
if (confirm('Are you sure?')) {
|
|
this.service.deleteMDStore(md.id, (data: void) => this.reload());
|
|
}
|
|
}
|
|
}
|
|
|
|
@Component({
|
|
selector: 'app-mdstore-inspector',
|
|
templateUrl: './mdstore-inspector.component.html',
|
|
styleUrls: ['./mdstores.component.css']
|
|
})
|
|
export class MdstoreInspectorComponent implements OnInit {
|
|
|
|
mdstore?: MDStore = undefined;
|
|
version?: MDStoreVersion = undefined;
|
|
records: MDStoreRecord[] = [];
|
|
|
|
limit: number = 0;
|
|
|
|
constructor(public service: ISService, public route: ActivatedRoute, public dialog: MatDialog) {
|
|
}
|
|
ngOnInit() {
|
|
this.route.params.subscribe(params => {
|
|
const versionId = params['versionId'];
|
|
this.limit = params['limit'];
|
|
|
|
this.service.loadMDStoreVersion(versionId, (data: MDStoreVersion) => {
|
|
this.version = data;
|
|
this.service.loadMDStore(this.version.mdstore, (data: MDStore) => {
|
|
this.mdstore = data;
|
|
this.service.loadMDStoreVersionRecords(versionId, this.limit, (data: MDStoreRecord[]) => {
|
|
this.records = data;
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
@Component({
|
|
selector: 'mdstores-versions-dialog',
|
|
templateUrl: './mdstores-versions-dialog.html',
|
|
styleUrls: ['./mdstores.component.css']
|
|
})
|
|
export class MDStoreVersionsDialog {
|
|
|
|
versions: MDStoreVersion[] = [];
|
|
|
|
constructor(public dialogRef: MatDialogRef<MDStoreVersionsDialog>, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService, public router: Router) {
|
|
this.reload();
|
|
}
|
|
|
|
reload() {
|
|
this.service.loadMDStoreVersions(this.data.id, (res: MDStoreVersion[]) => this.versions = res);
|
|
}
|
|
|
|
openInspectorPage(version: MDStoreVersion): void {
|
|
const url = this.router.serializeUrl(
|
|
this.router.createUrlTree(['/mdrecords/' + encodeURIComponent(version.id) + '/50'])
|
|
);
|
|
window.open(url, '_blank');
|
|
}
|
|
|
|
resetReading(version: MDStoreVersion): void {
|
|
this.service.resetReadingMDStoreVersion(version.id, (data: void) => version.readCount = 0);
|
|
}
|
|
|
|
commitVersion(version: MDStoreVersion): void {
|
|
let size: number = parseInt(prompt("New Size", "0") || "0");
|
|
if (size >= 0) {
|
|
this.service.commitMDStoreVersion(version.id, size, (data: void) => {
|
|
this.data.currentVersion = version.id;
|
|
this.reload();
|
|
});
|
|
}
|
|
}
|
|
|
|
abortVersion(version: MDStoreVersion): void {
|
|
this.service.abortMDStoreVersion(version.id, (data: void) => this.reload());
|
|
}
|
|
|
|
deleteVersion(version: MDStoreVersion): void {
|
|
this.service.deleteMDStoreVersion(version.id, (data: void) => this.reload());
|
|
}
|
|
|
|
onNoClick(): void {
|
|
this.dialogRef.close();
|
|
}
|
|
}
|
|
|
|
@Component({
|
|
selector: 'add-mdstore-dialog',
|
|
templateUrl: './add-mdstore-dialog.html',
|
|
styleUrls: ['./mdstores.component.css']
|
|
})
|
|
export class AddMDStoreDialog {
|
|
|
|
newMdstoreForm = new FormGroup({
|
|
format: new FormControl('', [Validators.required]),
|
|
layout: new FormControl('', [Validators.required]),
|
|
interpretation: new FormControl('', [Validators.required]),
|
|
dsName: new FormControl(''),
|
|
dsId: new FormControl(''),
|
|
apiId: new FormControl(''),
|
|
});
|
|
|
|
constructor(public dialogRef: MatDialogRef<MDStoreVersionsDialog>, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService) {
|
|
|
|
}
|
|
|
|
onSubmit(): void {
|
|
let format: string = this.newMdstoreForm.get('format')?.value!;
|
|
let layout: string = this.newMdstoreForm.get('layout')?.value!;
|
|
let interpretation: string = this.newMdstoreForm.get('interpretation')?.value!;
|
|
let dsName: string = this.newMdstoreForm.get('dsName')?.value!;
|
|
let dsId: string = this.newMdstoreForm.get('dsId')?.value!;
|
|
let apiId: string = this.newMdstoreForm.get('apiId')?.value!;
|
|
|
|
this.service.addMDStore(format, layout, interpretation, dsName, dsId, apiId, (data: void) => this.dialogRef.close(1), this.newMdstoreForm);
|
|
}
|
|
|
|
onNoClick(): void {
|
|
this.dialogRef.close();
|
|
}
|
|
}
|