Page MenuHomec4science

rdf-rsource-editor-component.component.ts
No OneTemporary

File Metadata

Created
Sun, May 5, 19:34

rdf-rsource-editor-component.component.ts

import {Component, EventEmitter, Input, OnInit} from '@angular/core';
import {TlnResource, TlnTransaction} from '../editor-resources';
import {QueryService} from '../../services/query.service';
import {ChangeMgmntDef, TlnPredicate, TlnStatementCollection} from '../statement-handler';
import {Subscription} from 'rxjs';
@Component({
selector: 'app-rdf-rsource-editor-component',
templateUrl: './rdf-rsource-editor-component.component.html',
styleUrls: ['./rdf-rsource-editor-component.component.scss']
})
export class RdfRsourceEditorComponentComponent implements OnInit {
@Input() iri: string;
@Input() def: ChangeMgmntDef;
@Input() user: string;
resource: TlnResource;
transaction: TlnTransaction;
comment: string;
changeHandler: Subscription;
changeEventHandler: EventEmitter<any>;
constructor(public queryService: QueryService) {
this.transaction = new TlnTransaction();
if (!this.iri || this.iri === '') {this.iri = 'http://rdfh.ch/projects/0068#_Mp_XIV_Page418'}
if (!this.def) { this.def = new ChangeMgmntDef(true, true, true, true)}
this.changeHandler = this.changeEventHandler.subscribe(change => {
console.log('change', change);
})
}
ngOnInit() {
//console.log('new resource in editor: ', this.iri);
TlnResource.buildFromStoreAsync(this.queryService, this.iri, '', this.def).then( resource => {
this.resource = resource;
});
}
// Avoiding "ExpressionChangedAfterItHasBeenCheckedError" in the template when iterating over map.entries()
getEntries(statements: Map<string, TlnStatementCollection>): [string, TlnStatementCollection][] {
return Array.from(statements.entries());
}
nodeChangedHandler(pred: TlnPredicate, obj: string, idx: number) {
this.resource._rdfDatasetToEdit.setStatement(pred, obj, idx);
}
deleteResource() {
this.resource.setDeleted();
}
commitChanges() {
this.user = 'FuuuUser';
this.comment = 'I deleted all';
this.transaction.commit([this.resource], this.user, this.comment, this.def ).then(committed => {
this.transaction.committed = committed;
console.log('committed', committed)
if (committed === false) { console.log('Nothing to commit. No changes made.')} else {
this.transaction.preview();
}
});
}
previewChanges() {
}
}

Event Timeline