2020-02-05 22:46:20 +01:00
|
|
|
export default class LoadResults {
|
2021-04-16 22:57:37 +02:00
|
|
|
constructor(froca) {
|
|
|
|
this.froca = froca;
|
2020-01-29 21:38:58 +01:00
|
|
|
|
2020-01-29 20:14:02 +01:00
|
|
|
this.noteIdToSourceId = {};
|
2020-01-27 22:58:03 +01:00
|
|
|
this.sourceIdToNoteIds = {};
|
2020-05-14 13:08:06 +02:00
|
|
|
|
2020-01-30 22:38:31 +01:00
|
|
|
this.branches = [];
|
|
|
|
|
|
|
|
this.attributes = [];
|
|
|
|
|
|
|
|
this.noteReorderings = [];
|
|
|
|
|
|
|
|
this.noteRevisions = [];
|
2020-01-31 22:32:24 +01:00
|
|
|
|
|
|
|
this.contentNoteIdToSourceId = [];
|
2020-02-05 22:08:45 +01:00
|
|
|
|
|
|
|
this.options = [];
|
2020-01-27 22:58:03 +01:00
|
|
|
}
|
|
|
|
|
2020-03-17 21:39:26 +01:00
|
|
|
addNote(noteId, sourceId) {
|
2020-01-29 20:14:02 +01:00
|
|
|
this.noteIdToSourceId[noteId] = this.noteIdToSourceId[noteId] || [];
|
2020-01-27 22:58:03 +01:00
|
|
|
|
2020-01-29 20:14:02 +01:00
|
|
|
if (!this.noteIdToSourceId[noteId].includes(sourceId)) {
|
|
|
|
this.noteIdToSourceId[noteId].push(sourceId);
|
2020-01-27 22:58:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.sourceIdToNoteIds[sourceId] = this.sourceIdToNoteIds[sourceId] || [];
|
|
|
|
|
|
|
|
if (!this.sourceIdToNoteIds[sourceId]) {
|
|
|
|
this.sourceIdToNoteIds[sourceId].push(noteId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-29 20:14:02 +01:00
|
|
|
addBranch(branchId, sourceId) {
|
2020-01-30 22:38:31 +01:00
|
|
|
this.branches.push({branchId, sourceId});
|
2020-01-29 20:14:02 +01:00
|
|
|
}
|
|
|
|
|
2020-01-29 21:38:58 +01:00
|
|
|
getBranches() {
|
2020-01-30 22:38:31 +01:00
|
|
|
return this.branches
|
2021-04-16 22:57:37 +02:00
|
|
|
.map(row => this.froca.branches[row.branchId])
|
2020-01-30 22:38:31 +01:00
|
|
|
.filter(branch => !!branch);
|
2020-01-29 21:38:58 +01:00
|
|
|
}
|
|
|
|
|
2020-01-29 20:14:02 +01:00
|
|
|
addNoteReordering(parentNoteId, sourceId) {
|
2020-01-30 22:38:31 +01:00
|
|
|
this.noteReorderings.push(parentNoteId);
|
2020-01-29 20:14:02 +01:00
|
|
|
}
|
|
|
|
|
2020-01-29 21:38:58 +01:00
|
|
|
getNoteReorderings() {
|
2020-01-30 22:38:31 +01:00
|
|
|
return this.noteReorderings;
|
2020-01-29 21:38:58 +01:00
|
|
|
}
|
|
|
|
|
2020-01-29 20:14:02 +01:00
|
|
|
addAttribute(attributeId, sourceId) {
|
2020-01-30 22:38:31 +01:00
|
|
|
this.attributes.push({attributeId, sourceId});
|
2020-01-29 20:14:02 +01:00
|
|
|
}
|
|
|
|
|
2021-02-07 20:55:49 +01:00
|
|
|
/** @return {Attribute[]} */
|
2020-06-08 00:29:52 +02:00
|
|
|
getAttributes(sourceId = 'none') {
|
2020-01-30 22:38:31 +01:00
|
|
|
return this.attributes
|
2020-06-08 00:29:52 +02:00
|
|
|
.filter(row => row.sourceId !== sourceId)
|
2021-04-16 22:57:37 +02:00
|
|
|
.map(row => this.froca.attributes[row.attributeId])
|
2020-01-30 22:38:31 +01:00
|
|
|
.filter(attr => !!attr);
|
2020-01-29 21:38:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
addNoteRevision(noteRevisionId, noteId, sourceId) {
|
2020-01-30 22:38:31 +01:00
|
|
|
this.noteRevisions.push({noteRevisionId, noteId, sourceId});
|
2020-01-29 21:38:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
hasNoteRevisionForNote(noteId) {
|
2020-01-30 22:38:31 +01:00
|
|
|
return !!this.noteRevisions.find(nr => nr.noteId === noteId);
|
2020-01-29 21:38:58 +01:00
|
|
|
}
|
|
|
|
|
2020-01-27 22:58:03 +01:00
|
|
|
getNoteIds() {
|
2020-01-29 20:14:02 +01:00
|
|
|
return Object.keys(this.noteIdToSourceId);
|
2020-01-27 22:58:03 +01:00
|
|
|
}
|
|
|
|
|
2020-02-01 19:25:37 +01:00
|
|
|
isNoteReloaded(noteId, sourceId = null) {
|
2020-01-28 21:54:28 +01:00
|
|
|
if (!noteId) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-29 20:14:02 +01:00
|
|
|
const sourceIds = this.noteIdToSourceId[noteId];
|
2020-01-27 22:58:03 +01:00
|
|
|
return sourceIds && !!sourceIds.find(sId => sId !== sourceId);
|
|
|
|
}
|
2020-01-31 22:32:24 +01:00
|
|
|
|
|
|
|
addNoteContent(noteId, sourceId) {
|
|
|
|
this.contentNoteIdToSourceId.push({noteId, sourceId});
|
|
|
|
}
|
|
|
|
|
|
|
|
isNoteContentReloaded(noteId, sourceId) {
|
|
|
|
if (!noteId) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.contentNoteIdToSourceId.find(l => l.noteId === noteId && l.sourceId !== sourceId);
|
|
|
|
}
|
2020-02-05 22:08:45 +01:00
|
|
|
|
|
|
|
addOption(name) {
|
|
|
|
this.options.push(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
isOptionReloaded(name) {
|
2021-05-22 21:35:25 +02:00
|
|
|
return this.options.includes(name);
|
2020-02-05 22:08:45 +01:00
|
|
|
}
|
2020-03-10 21:33:03 +01:00
|
|
|
|
2020-05-02 18:19:41 +02:00
|
|
|
/**
|
|
|
|
* @return {boolean} true if there are changes which could affect the attributes (including inherited ones)
|
2020-05-14 13:08:06 +02:00
|
|
|
* notably changes in note itself should not have any effect on attributes
|
2020-05-02 18:19:41 +02:00
|
|
|
*/
|
|
|
|
hasAttributeRelatedChanges() {
|
2020-08-12 23:58:32 +02:00
|
|
|
return this.branches.length > 0
|
|
|
|
|| this.attributes.length > 0;
|
2020-05-02 18:19:41 +02:00
|
|
|
}
|
|
|
|
|
2020-03-10 21:33:03 +01:00
|
|
|
isEmpty() {
|
2020-03-15 17:18:50 +01:00
|
|
|
return Object.keys(this.noteIdToSourceId).length === 0
|
|
|
|
&& this.branches.length === 0
|
|
|
|
&& this.attributes.length === 0
|
|
|
|
&& this.noteReorderings.length === 0
|
|
|
|
&& this.noteRevisions.length === 0
|
|
|
|
&& this.contentNoteIdToSourceId.length === 0
|
|
|
|
&& this.options.length === 0;
|
2020-03-10 21:33:03 +01:00
|
|
|
}
|
2020-08-16 22:57:48 +02:00
|
|
|
|
|
|
|
isEmptyForTree() {
|
|
|
|
return Object.keys(this.noteIdToSourceId).length === 0
|
|
|
|
&& this.branches.length === 0
|
|
|
|
&& this.attributes.length === 0
|
|
|
|
&& this.noteReorderings.length === 0;
|
|
|
|
}
|
2020-05-14 13:08:06 +02:00
|
|
|
}
|