2020-02-06 05:46:20 +08:00
|
|
|
export default class LoadResults {
|
2020-01-30 04:38:58 +08:00
|
|
|
constructor(treeCache) {
|
|
|
|
this.treeCache = treeCache;
|
|
|
|
|
2020-01-30 03:14:02 +08:00
|
|
|
this.noteIdToSourceId = {};
|
2020-01-28 05:58:03 +08:00
|
|
|
this.sourceIdToNoteIds = {};
|
2020-01-30 03:14:02 +08:00
|
|
|
|
2020-01-31 05:38:31 +08:00
|
|
|
this.branches = [];
|
|
|
|
|
|
|
|
this.attributes = [];
|
|
|
|
|
|
|
|
this.noteReorderings = [];
|
|
|
|
|
|
|
|
this.noteRevisions = [];
|
2020-02-01 05:32:24 +08:00
|
|
|
|
|
|
|
this.contentNoteIdToSourceId = [];
|
2020-02-06 05:08:45 +08:00
|
|
|
|
|
|
|
this.options = [];
|
2020-01-28 05:58:03 +08:00
|
|
|
}
|
|
|
|
|
2020-01-29 04:54:28 +08:00
|
|
|
addNote(noteId, sourceId) {
|
2020-01-30 03:14:02 +08:00
|
|
|
this.noteIdToSourceId[noteId] = this.noteIdToSourceId[noteId] || [];
|
2020-01-28 05:58:03 +08:00
|
|
|
|
2020-01-30 03:14:02 +08:00
|
|
|
if (!this.noteIdToSourceId[noteId].includes(sourceId)) {
|
|
|
|
this.noteIdToSourceId[noteId].push(sourceId);
|
2020-01-28 05:58:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this.sourceIdToNoteIds[sourceId] = this.sourceIdToNoteIds[sourceId] || [];
|
|
|
|
|
|
|
|
if (!this.sourceIdToNoteIds[sourceId]) {
|
|
|
|
this.sourceIdToNoteIds[sourceId].push(noteId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-30 03:14:02 +08:00
|
|
|
addBranch(branchId, sourceId) {
|
2020-01-31 05:38:31 +08:00
|
|
|
this.branches.push({branchId, sourceId});
|
2020-01-30 03:14:02 +08:00
|
|
|
}
|
|
|
|
|
2020-01-30 04:38:58 +08:00
|
|
|
getBranches() {
|
2020-01-31 05:38:31 +08:00
|
|
|
return this.branches
|
|
|
|
.map(row => this.treeCache.branches[row.branchId])
|
|
|
|
.filter(branch => !!branch);
|
2020-01-30 04:38:58 +08:00
|
|
|
}
|
|
|
|
|
2020-01-30 03:14:02 +08:00
|
|
|
addNoteReordering(parentNoteId, sourceId) {
|
2020-01-31 05:38:31 +08:00
|
|
|
this.noteReorderings.push(parentNoteId);
|
2020-01-30 03:14:02 +08:00
|
|
|
}
|
|
|
|
|
2020-01-30 04:38:58 +08:00
|
|
|
getNoteReorderings() {
|
2020-01-31 05:38:31 +08:00
|
|
|
return this.noteReorderings;
|
2020-01-30 04:38:58 +08:00
|
|
|
}
|
|
|
|
|
2020-01-30 03:14:02 +08:00
|
|
|
addAttribute(attributeId, sourceId) {
|
2020-01-31 05:38:31 +08:00
|
|
|
this.attributes.push({attributeId, sourceId});
|
2020-01-30 03:14:02 +08:00
|
|
|
}
|
|
|
|
|
2020-01-30 04:38:58 +08:00
|
|
|
getAttributes() {
|
2020-01-31 05:38:31 +08:00
|
|
|
return this.attributes
|
|
|
|
.map(row => this.treeCache.attributes[row.attributeId])
|
|
|
|
.filter(attr => !!attr);
|
2020-01-30 04:38:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
addNoteRevision(noteRevisionId, noteId, sourceId) {
|
2020-01-31 05:38:31 +08:00
|
|
|
this.noteRevisions.push({noteRevisionId, noteId, sourceId});
|
2020-01-30 04:38:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
hasNoteRevisionForNote(noteId) {
|
2020-01-31 05:38:31 +08:00
|
|
|
return !!this.noteRevisions.find(nr => nr.noteId === noteId);
|
2020-01-30 04:38:58 +08:00
|
|
|
}
|
|
|
|
|
2020-01-28 05:58:03 +08:00
|
|
|
getNoteIds() {
|
2020-01-30 03:14:02 +08:00
|
|
|
return Object.keys(this.noteIdToSourceId);
|
2020-01-28 05:58:03 +08:00
|
|
|
}
|
|
|
|
|
2020-02-02 02:25:37 +08:00
|
|
|
isNoteReloaded(noteId, sourceId = null) {
|
2020-01-29 04:54:28 +08:00
|
|
|
if (!noteId) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-30 03:14:02 +08:00
|
|
|
const sourceIds = this.noteIdToSourceId[noteId];
|
2020-01-28 05:58:03 +08:00
|
|
|
return sourceIds && !!sourceIds.find(sId => sId !== sourceId);
|
|
|
|
}
|
2020-02-01 05:32:24 +08: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-06 05:08:45 +08:00
|
|
|
|
|
|
|
addOption(name) {
|
|
|
|
this.options.push(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
isOptionReloaded(name) {
|
|
|
|
this.options.includes(name);
|
|
|
|
}
|
2020-03-11 04:33:03 +08:00
|
|
|
|
|
|
|
isEmpty() {
|
|
|
|
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-01-28 05:58:03 +08:00
|
|
|
}
|