Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tmushayahama committed Jan 22, 2021
1 parent c0f774a commit fe4f0bc
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Inject, OnInit, OnDestroy } from '@angular/core';
import { Component, Inject, OnInit, OnDestroy, NgZone } from '@angular/core';
import { FormControl, FormGroup, FormArray } from '@angular/forms';
import { Subscription, Subject } from 'rxjs';
import {
Expand All @@ -8,6 +8,7 @@ import {
CamService,
Entity,
noctuaFormConfig,
CamsService,
} from 'noctua-form-base';

import { Cam } from 'noctua-form-base';
Expand Down Expand Up @@ -52,9 +53,12 @@ export class NoctuaEditorDropdownComponent implements OnInit, OnDestroy {
with: false,
};

constructor(public dialogRef: EditorDropdownOverlayRef,
constructor(
private zone: NgZone,
public dialogRef: EditorDropdownOverlayRef,
@Inject(editorDropdownData) public data: any,
private noctuaFormDialogService: NoctuaFormDialogService,
private camsService: CamsService,
private camService: CamService,
private noctuaAnnotonEntityService: NoctuaAnnotonEntityService,
private inlineReferenceService: InlineReferenceService,
Expand Down Expand Up @@ -96,11 +100,25 @@ export class NoctuaEditorDropdownComponent implements OnInit, OnDestroy {

save() {
const self = this;

self.noctuaAnnotonEntityService.saveAnnoton().then(() => {
this.close();
self.noctuaFormDialogService.openSuccessfulSaveToast('Activity successfully updated.', 'OK');
});
switch (self.category) {
case EditorCategory.term:
case EditorCategory.evidence:
self.noctuaAnnotonEntityService.saveAnnotonReplace(self.cam).subscribe(() => {
this.close();
// self.noctuaFormDialogService.openSuccessfulSaveToast('Activity successfully updated.', 'OK');
self.camsService.getStoredModel(self.cam).subscribe(() => {
self.zone.run(() => {
self.camsService.reviewChanges();
})
});
});
break;
default:
self.noctuaAnnotonEntityService.saveAnnoton().then(() => {
this.close();
self.noctuaFormDialogService.openSuccessfulSaveToast('Activity successfully updated.', 'OK');
});
}
}

addEvidence() {
Expand Down
52 changes: 51 additions & 1 deletion src/@noctua.form/models/annoton/annoton-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Annoton } from './annoton';
import { Entity } from './entity';
import { EntityLookup } from './entity-lookup';
import { Contributor } from './../contributor';
import { Predicate } from '.';
import { CamStats, Predicate } from '.';
import { each, find, some } from 'lodash';
import { NoctuaFormUtils } from './../../utils/noctua-form-utils';

Expand Down Expand Up @@ -55,6 +55,7 @@ export interface AnnotonNodeDisplay {
}

export class AnnotonNode implements AnnotonNodeDisplay {

type: AnnotonNodeType;
label: string;
uuid: string;
Expand Down Expand Up @@ -204,6 +205,55 @@ export class AnnotonNode implements AnnotonNodeDisplay {
return result;
}

reviewTermChanges(stat: CamStats, modifiedStats: CamStats): boolean {
const self = this;
let modified = false;

if (self.term.modified) {
//result.push(self.term);
modifiedStats.termsCount++;
stat.termsCount++;
modified = true;
}

each(self.predicate.evidence, (evidence: Evidence, key) => {
const evidenceModified = evidence.reviewEvidenceChanges(stat, modifiedStats);
modified = modified || evidenceModified;
});

modifiedStats.updateTotal();
return modified;
}

checkStored(oldNode: AnnotonNode) {
const self = this;

if (oldNode && self.term.id !== oldNode.term.id) {
self.term.termHistory.unshift(new Entity(oldNode.term.id, oldNode.term.label));
self.term.modified = true;
}

each(self.predicate.evidence, (evidence: Evidence, key) => {
const oldEvidence = oldNode.predicate.getEvidenceById(evidence.uuid)
evidence.checkStored(oldEvidence)
});
}

addPendingChanges(oldNode: AnnotonNode) {
const self = this;

self.pendingChangeEntity = new Entity(self.term.id, self.term.label);
self.pendingChangeEntity.uuid = self.uuid;

each(self.predicate.evidence, (evidence: Evidence, key) => {
const oldEvidence = oldNode.predicate.getEvidenceById(evidence.uuid)
evidence.addPendingChanges(oldEvidence);
});

//this is temporary swap back into old
self.term = oldNode.term
}

enableSubmit(errors) {
const self = this;
let result = true;
Expand Down
21 changes: 7 additions & 14 deletions src/@noctua.form/models/annoton/cam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,8 @@ export class Cam {
each(self._annotons, (annoton: Annoton) => {
each(annoton.nodes, (node: AnnotonNode) => {
// node.term.highlight = false;
const found: AnnotonNode = self.findNodeById(node.uuid, self.storedAnnotons)
if (found && node.term.id !== found.term.id) {
node.term.termHistory.unshift(new Entity(found.term.id, found.term.label));
node.term.modified = true;
}
const oldNode: AnnotonNode = self.findNodeById(node.uuid, self.storedAnnotons)
node.checkStored(oldNode)
});
});
}
Expand Down Expand Up @@ -298,25 +295,21 @@ export class Cam {
});
}

reviewTermChanges(stat: CamStats): Entity[] {
reviewCamChanges(stat: CamStats): boolean {
const self = this;
const result = [];
let modified = false;

self.modifiedStats = new CamStats();

each(self._annotons, (annoton: Annoton) => {
each(annoton.nodes, (node: AnnotonNode) => {
if (node.term.modified) {
result.push(node.term);
self.modifiedStats.termsCount++;
stat.termsCount++;
annoton.modified = true;
}
annoton.modified = node.reviewTermChanges(stat, self.modifiedStats);
modified = modified || annoton.modified;
});
});

self.modifiedStats.updateTotal();
return result;
return modified;
}

getAnnotonByConnectionId(connectionId) {
Expand Down
37 changes: 37 additions & 0 deletions src/@noctua.form/models/annoton/evidence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { AnnotonNode } from './annoton-node';
import { includes, isEqual } from 'lodash';

import { noctuaFormConfig } from './../../noctua-form-config';
import { CamStats } from "./cam";

export class Evidence {

edge: Entity;
evidence: Entity = new Entity('', '');
reference: string;
Expand All @@ -18,6 +20,8 @@ export class Evidence {
referenceRequired = false;
ontologyClass = [];

pendingChangeEntity: Entity;

constructor() {

}
Expand Down Expand Up @@ -69,6 +73,39 @@ export class Evidence {
return result;
}

reviewEvidenceChanges(stat: CamStats, modifiedStats: CamStats): boolean {
const self = this;
let modified = false;

if (self.evidence.modified) {
modifiedStats.evidenceCount++;
stat.evidenceCount++;
modified = true;
}

modifiedStats.updateTotal();
return modified;
}

checkStored(oldEvidence: Evidence) {
const self = this;

if (oldEvidence && self.evidence.id !== oldEvidence.evidence.id) {
self.evidence.termHistory.unshift(new Entity(oldEvidence.evidence.id, oldEvidence.evidence.label));
self.evidence.modified = true;
}
}

addPendingChanges(oldEvidence: Evidence) {
const self = this;

self.pendingChangeEntity = new Entity(self.evidence.id, self.evidence.label);
self.pendingChangeEntity.uuid = self.uuid;

//this is temporary swap back into old
self.evidence = oldEvidence.evidence
}

enableSubmit(errors, node: AnnotonNode, position) {
const self = this;
let result = true;
Expand Down
12 changes: 12 additions & 0 deletions src/@noctua.form/services/annoton-entity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ export class NoctuaAnnotonEntityService {
saveData.removeTriples);
}

saveAnnotonReplace(cam: Cam): Observable<any> {
const self = this;

const oldEntity = cloneDeep(self.entity);
self.annotonEntityFormToAnnoton();

self.entity.addPendingChanges(oldEntity);

return self.camService.bulkEdit(cam);

}

saveAnnotonInternal() {
const self = this;

Expand Down
23 changes: 12 additions & 11 deletions src/@noctua.form/services/cam.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { environment } from '../../environments/environment';
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { BehaviorSubject, Observable } from 'rxjs';
import { BehaviorSubject, forkJoin, Observable } from 'rxjs';
import { FormGroup, FormBuilder } from '@angular/forms';
import { CurieService } from './../../@noctua.curie/services/curie.service';
import { NoctuaGraphService } from './../services/graph.service';
Expand Down Expand Up @@ -111,6 +111,15 @@ export class CamService {
this.cam = cam;
}

bulkEdit(cam: Cam): Observable<any> {
const self = this;
const promises = [];

promises.push(self._noctuaGraphService.bulkEditAnnoton(cam));

return forkJoin(promises);
}

deleteAnnoton(annoton: Annoton) {
const self = this;
const deleteData = annoton.createDelete();
Expand Down Expand Up @@ -167,15 +176,7 @@ export class CamService {
return self._noctuaGraphService.resetModel(cam);
}

reviewChanges(cam: Cam, stats: CamStats) {
const terms = cam.reviewTermChanges(stats);

if (terms.length > 0) {
return {
terms: terms
};
}

return null;
reviewChanges(cam: Cam, stats: CamStats): boolean {
return cam.reviewCamChanges(stats);
}
}
16 changes: 2 additions & 14 deletions src/@noctua.form/services/cams.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,25 +228,19 @@ export class CamsService {

reviewChanges() {
const self = this;
const details = [];
const stats = new CamStats();

each(this.cams, (cam: Cam) => {
const changes = self.camService.reviewChanges(cam, stats);
if (changes) {
details.push({
cam: cam,
changes: changes
});
stats.camsCount++;
}
});

stats.camsCount = details.length;
stats.updateTotal();

const result = {
stats: stats,
details: details
};

console.log(result)
Expand All @@ -257,23 +251,17 @@ export class CamsService {

reviewCamChanges(cam: Cam) {
const self = this;
const details = [];
const stats = new CamStats();

const changes = self.camService.reviewChanges(cam, stats);
if (changes) {
details.push({
cam: cam,
changes: changes
});
stats.camsCount++;
}

stats.camsCount = details.length;
stats.updateTotal();

const result = {
stats: stats,
details: details
};

return result
Expand Down
22 changes: 21 additions & 1 deletion src/@noctua.form/services/graph.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,10 @@ export class NoctuaGraphService {
each(cam.annotons, (annoton: Annoton) => {
each(annoton.nodes, (node: AnnotonNode) => {
self.bulkEditIndividual(reqs, cam, node);
each(node.predicate.evidence, (evidence: Evidence, key) => {
self.bulkEditEvidence(reqs, cam, evidence);
});

//self.bulkEditFact(reqs, cam, srcTriples, destTriples);
// self.bulkAddFact(reqs, destTriples);

Expand Down Expand Up @@ -916,7 +920,7 @@ export class NoctuaGraphService {
bulkEditIndividual(reqs, cam: Cam, node: AnnotonNode) {
if (node.hasValue() && node.pendingChangeEntity) {
reqs.remove_type_from_individual(
node.classExpression,
class_expression.cls(node.term.id),
node.uuid,
cam.id,
);
Expand All @@ -929,6 +933,22 @@ export class NoctuaGraphService {
}
}

bulkEditEvidence(reqs, cam: Cam, evidence: Evidence) {
if (evidence.hasValue() && evidence.pendingChangeEntity) {
reqs.remove_type_from_individual(
class_expression.cls(evidence.evidence.id),
evidence.uuid,
cam.id,
);

reqs.add_type_to_individual(
class_expression.cls(evidence.pendingChangeEntity.id),
evidence.pendingChangeEntity.uuid,
cam.id,
);
}
}

replaceIndividual(reqs, modelId: string, entity: Entity, replaceWithTerm: Entity) {
reqs.remove_type_from_individual(
class_expression.cls(entity.id),
Expand Down
Loading

0 comments on commit fe4f0bc

Please sign in to comment.