Page MenuHomec4science

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

File Metadata

Created
Tue, Jul 9, 19:22

rdf-editor-transaction-component.component.ts

import {Component, EventEmitter, Input, OnChanges, OnInit, Output} from '@angular/core';
import {TlnResource, TlnTransaction} from "../editor-resources";
import {ChangeMgmntDef} from "../statement-handler";
@Component({
selector: 'app-rdf-editor-transaction-component',
templateUrl: './rdf-editor-transaction-component.component.html',
styleUrls: ['./rdf-editor-transaction-component.component.scss']
})
export class RdfEditorTransactionComponentComponent implements OnChanges {
@Input() payLoad: TlnResource[]; // all the resources to be processed/committed
@Input() def: ChangeMgmntDef; // the def on how to check/write triples/metadata
transaction: TlnTransaction; // the transaction to be committed/pushed
@Input() user: string; // committing user. Will be written as triples acc. to the ChangeMgmntDef
@Input() commitMsg: string; // committing user. Will be written as triples acc. to the ChangeMgmntDef
@Output() userChange = new EventEmitter();
@Output() commitMsgChange = new EventEmitter();
constructor() {
}
ngOnChanges() {
if (!this.def) { this.def = new ChangeMgmntDef(); }
console.log('resources', this.payLoad);
console.log('del Resources ', this.payLoad.filter(res => res.isDeleted() && !res.ignore()).map(res => res.iri));
console.log('stored Resources ', this.payLoad.filter(res => res.isInStore()).map( res => res.iri));
console.log('ignored Resources ', this.payLoad.filter(res => res.ignore()).map( res => res.iri));
}
// emits the updated user to the parent component
updateUser(newUser) {
this.userChange.emit(newUser);
}
// emits the updated commitMsg to the parent component
updateCommitMsg(newMsg) {
this.commitMsgChange.emit(newMsg);
}
commit() {
if (!this.requirementsForfilled()) { return; }
this.transaction = new TlnTransaction();
this.transaction.build(this.payLoad, this.user, this.commitMsg, this.def ).then(committed => {
this.transaction.committed = committed;
console.log('committed', committed);
if (committed === false) { window.alert('Nichts zu schreiben. Es wurden keine Änderungen vorgenommen.'); } else {
console.log('committed', committed);
console.log('TRANSACTION', this.transaction);
this.transaction.preview();
}
});
}
push() {
if (!this.transaction.committed) {return; }
this.uploadToWorkStore();
}
// returns whether the basic requirements of a commit are forfilled: Checks if there is a user, and a commit message
requirementsForfilled(): boolean {
return this.user && this.user !== '' && this.commitMsg && this.commitMsg !== '';
}
committed() {
return this.transaction && this.transaction.committed;
}
uploadToWorkStore() {
console.log('uploading to workstore')
}
}

Event Timeline