Skip to content

Commit

Permalink
First steps of work in progress to migrate towards using the composit…
Browse files Browse the repository at this point in the history
…ion API and applying a store to manage the view.
  • Loading branch information
SeriousHorncat committed Oct 11, 2024
1 parent 77efce4 commit aa05564
Show file tree
Hide file tree
Showing 3 changed files with 652 additions and 527 deletions.
128 changes: 128 additions & 0 deletions frontend/src/stores/analysisStore.js
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;

Check failure on line 17 in frontend/src/stores/analysisStore.js

View workflow job for this annotation

GitHub Actions / nodejs-ci (20.8)

'thisa' is not defined
},
async getAnalysis(analysisName) {
console.log(analysisName)

Check failure on line 20 in frontend/src/stores/analysisStore.js

View workflow job for this annotation

GitHub Actions / nodejs-ci (20.8)

Missing semicolon
console.log('getting analysis for things')

Check failure on line 21 in frontend/src/stores/analysisStore.js

View workflow job for this annotation

GitHub Actions / nodejs-ci (20.8)

Missing semicolon
this.analysis = await Analyses.getAnalysis(analysisName);
console.log(this.analysis)

Check failure on line 23 in frontend/src/stores/analysisStore.js

View workflow job for this annotation

GitHub Actions / nodejs-ci (20.8)

Missing semicolon
},

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};
},
});
Loading

0 comments on commit aa05564

Please sign in to comment.