-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First steps of work in progress to migrate towards using the composit…
…ion API and applying a store to manage the view.
- Loading branch information
1 parent
77efce4
commit aa05564
Showing
3 changed files
with
652 additions
and
527 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import {reactive} from 'vue'; | ||
|
||
import Analyses from '@/models/analyses.js'; | ||
|
||
export const analysisStore = reactive({ | ||
analysis: { | ||
name: '', | ||
sections: [], | ||
}, | ||
updatedContent: {}, | ||
|
||
analysisName() { | ||
return this.analysis.name; | ||
}, | ||
|
||
latestStatus() { | ||
return thisa.analysis.latest_status; | ||
}, | ||
async getAnalysis(analysisName) { | ||
console.log(analysisName) | ||
console.log('getting analysis for things') | ||
this.analysis = await Analyses.getAnalysis(analysisName); | ||
console.log(this.analysis) | ||
}, | ||
|
||
async saveChanges() { | ||
const updatedSections = await Analyses.updateAnalysisSections( | ||
this.analysis.name, | ||
this.updatedContent, | ||
); | ||
this.analysis.sections.splice(0); | ||
this.analysis.sections.push(...updatedSections); | ||
this.updatedContent = {}; | ||
}, | ||
cancelChanges() { | ||
this.updatedContent = {}; | ||
}, | ||
|
||
async attachSectionImage(sectionName, field, attachment) { | ||
const updatedSectionField = await Analyses.attachSectionImage( | ||
this.analysis.name, | ||
sectionName, | ||
field, | ||
attachment.data, | ||
); | ||
|
||
const sectionWithReplacedField = this.replaceFieldInSection(sectionName, updatedSectionField); | ||
this.replaceAnalysisSection(sectionWithReplacedField); | ||
}, | ||
|
||
async updateSectionImage(fileId, sectionName, field, attachment) { | ||
const updatedSectionField = await Analyses.updateSectionImage( | ||
this.analysis.name, | ||
sectionName, | ||
field, | ||
fileId, | ||
attachment.data, | ||
); | ||
|
||
const sectionWithReplacedField = this.replaceFieldInSection(sectionName, updatedSectionField); | ||
this.replaceAnalysisSection(sectionWithReplacedField); | ||
}, | ||
|
||
async removeSectionImage(fileId, sectionName, field) { | ||
const updatedSectionField = await Analyses.removeSectionAttachment(this.analysis.name, sectionName, field, fileId); | ||
|
||
const sectionWithReplacedField = this.replaceFieldInSection(sectionName, updatedSectionField); | ||
this.replaceAnalysisSection(sectionWithReplacedField); | ||
}, | ||
|
||
replaceFieldInSection(sectionName, updatedField) { | ||
const sectionToUpdate = this.analysis.sections.find((section) => { | ||
return section.header == sectionName; | ||
}); | ||
|
||
const fieldToUpdate = sectionToUpdate.content.find((row) => { | ||
return row.field == updatedField['field']; | ||
}); | ||
|
||
fieldToUpdate.value = updatedField.value; | ||
|
||
return sectionToUpdate; | ||
}, | ||
|
||
replaceAnalysisSection(sectionToReplace) { | ||
const originalSectionIndex = this.analysis.sections.findIndex( | ||
(section) => section.header == sectionToReplace.header, | ||
); | ||
this.analysis.sections.splice(originalSectionIndex, 1, sectionToReplace); | ||
}, | ||
|
||
async addAttachment(attachment) { | ||
const updatedAnalysisAttachments = await Analyses.attachSupportingEvidence( | ||
this.analysis.name, | ||
attachment, | ||
); | ||
this.analysis.supporting_evidence_files.splice(0); | ||
this.analysis.supporting_evidence_files.push( | ||
...updatedAnalysisAttachments, | ||
); | ||
}, | ||
|
||
async updateAttachment(updatedAttachment) { | ||
const updatedAnalysisAttachments = await Analyses.updateSupportingEvidence( | ||
this.analysis.name, | ||
updatedAttachment, | ||
); | ||
this.analysis.supporting_evidence_files.splice(0); | ||
this.analysis.supporting_evidence_files.push( | ||
...updatedAnalysisAttachments, | ||
); | ||
}, | ||
|
||
async removeAttachment(attachmentToDelete) { | ||
await Analyses.removeSupportingEvidence( | ||
this.analysis_name, | ||
attachmentToDelete.attachment_id, | ||
); | ||
const attachmentIndex = this.attachments.findIndex((attachment) => { | ||
return attachment.name == attachmentToDelete.name; | ||
}); | ||
this.analysis.supporting_evidence_files.splice(attachmentIndex, 1); | ||
}, | ||
|
||
forceUpdate(updatedAnalysis) { | ||
this.analysis = {...this.analysis, ...updatedAnalysis}; | ||
}, | ||
}); |
Oops, something went wrong.