Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting evidence row #146

Merged
merged 8 commits into from
Oct 23, 2023
14 changes: 5 additions & 9 deletions etc/fixtures/initial-seed/analyses.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,14 @@
]
},
{
"type":"supporting-evidence",
"type":"section-supporting-evidence",
"field":"Veterinary Histology Report",
"value":[

]
"value":[]
},
{
"type":"supporting-evidence",
"field":"Veterinary Pathology Imaging",
"value":[

]
"type":"section-supporting-evidence",
"field":"Veterinary Pathology Imaging",
"value":[]
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ const animalModelSystemSection = {
"value": []
},
{
"type": "supporting-evidence",
"type": "section-supporting-evidence",
"field": "Veterinary Histology Report",
"value": []
},
{
"type": "supporting-evidence",
"type": "section-supporting-evidence",
"field": "Veterinary Pathology Imaging",
"value": []
}
Expand Down
14 changes: 10 additions & 4 deletions frontend/src/components/AnalysisView/SectionBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
:writePermissions="this.writePermissions"
:data-test="contentRow.field"
@update-annotation-image="this.onUpdateImageEmit"
@update:section-text="this.onContentChanged"
@update:section-content="this.onContentChanged"
@download="this.onDownload"
/>
</div>
</div>
Expand All @@ -50,13 +51,15 @@
<script>
import ImagesDataset from '@/components/AnnotationView/ImagesDataset.vue';
import SectionText from '@/components/AnalysisView/SectionText.vue';
import SectionSupportingEvidence from '@/components/AnalysisView/SectionSupportingEvidence.vue';

export default {
name: 'section-box',
emits: ['update:contentRow', 'attach-image', 'update-image'],
emits: ['update:contentRow', 'attach-image', 'update-image', 'download'],
components: {
SectionText,
ImagesDataset,
SectionSupportingEvidence,
},
props: {
analysis_name: {
Expand Down Expand Up @@ -108,16 +111,19 @@ export default {
},
},
methods: {
onContentChanged(sectionText) {
onContentChanged(sectionContent) {
const contentRow = {
header: this.header,
...sectionText,
...sectionContent,
};
this.$emit('update:contentRow', contentRow);
},
onUpdateImageEmit(imageId, field) {
this.$emit('update-image', imageId, this.header, field);
},
onDownload(content) {
this.$emit('download', content);
},
},
};
</script>
Expand Down
140 changes: 140 additions & 0 deletions frontend/src/components/AnalysisView/SectionSupportingEvidence.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<template>
<div class="section-row">
<label class="section-field" v-bind:style="[
value.length === 0 && !this.editable
? 'color: var(--rosalution-grey-300);'
: 'color: var(--rosalution-black);',
]">
{{ field }}
</label>
<div class="section-content" :data-test="`supporting-evidence-${field}`">
<div class="supporting-evidence-content">
<button v-if="isDataUnavailable && this.editable && writePermissions"
@click="onContentChanged('attach', content)"
class="primary-button" :data-test="`attach-button-${field}`">
Attach
</button>
<font-awesome-icon v-if="!isDataUnavailable" :icon="typeIcon" size="lg" />
<div v-if="!isDataUnavailable && content.type == 'file'" @click="$emit('download', content)" target="_blank"
rel="noreferrer noopener" class="attachment-name">
{{ content.name }}
</div>
<a v-if="!isDataUnavailable && content.type == 'link'" :href="content.data" target="_blank"
rel="noreferrer noopener" class="attachment-name">
{{ content.name }}
</a>
</div>
<div class="action-items">
<button v-if="!isDataUnavailable && writePermissions" @click="onContentChanged('delete', content)"
data-test="delete-button">
<font-awesome-icon icon="xmark" size="xl" />
</button>
</div>
</div>
</div>
</template>

<script>
export default {
name: 'section-supporting-evidence',
emits: ['update:sectionContent', 'download'],
props: {
field: {
type: String,
},
value: {
type: Array,
required: false,
},
editable: {
type: Boolean,
default: false,
},
writePermissions: {
type: Boolean,
default: false,
},
},
computed: {
isDataUnavailable: function() {
return this.value == '.' || this.value == 'null' || this.value == null || this.value.length == 0;
},
dataAvailabilityColour: function() {
return this.isDataUnavailable ? 'var(--rosalution-grey-300)' : 'var(--rosalution-black)';
},
typeIcon: function() {
if (this.isDataUnavailable) {
return undefined;
} else if (this.content.type === 'file') {
return ['far', 'file'];
}

return 'link';
},
content: function() {
if (this.isDataUnavailable) {
return {};
}

return this.value[0];
},
},
methods: {
onContentChanged(action, content) {
const contentRow = {
field: this.field,
type: 'supporting-evidence',
operation: action,
value: content,
};
this.$emit('update:sectionContent', contentRow);
},
},
};
</script>

<style scoped>
.section-row {
display: flex;
flex-direction: row;
gap: var(--p-10);
padding: var(--p-1);
}

.section-field {
flex: 0 0 11.25rem;
font-weight: 600;
}

.section-content {
display: flex;
flex-direction: row;
flex: 1 0 0;
justify-content: space-between;
align-items: center;
background-color: var(--rosalution-grey-50);
border-radius: var(--content-border-radius);
padding: var(--p-10);
}

.attachment-name {
color: var(--rosalution-purple-300);
font-weight: bold;
cursor: pointer;
}

.supporting-evidence-content {
display: flex;
align-items: center;
gap: var(--p-10);
}

.action-items svg {
color: var(--rosalution-black);
}

.action-items>button {
border: none;
background: none;
}
</style>
4 changes: 2 additions & 2 deletions frontend/src/components/AnalysisView/SectionText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<script>
export default {
name: 'section-text',
emits: ['update:sectionText'],
emits: ['update:sectionContent'],
props: {
field: {
type: String,
Expand Down Expand Up @@ -62,7 +62,7 @@ export default {
field: this.field,
value: event.target.innerText.split('\n'),
};
this.$emit('update:sectionText', contentRow);
this.$emit('update:sectionContent', contentRow);
},
},
};
Expand Down
56 changes: 56 additions & 0 deletions frontend/src/models/analyses.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,62 @@ export default {
};
return await Requests.putForm(url, attachmentForm);
},

async attachSectionSupportingEvidence(analysisName, section, field, evidence) {
let attachmentForm = null;
let url = `/rosalution/api/analysis/${analysisName}/section/attach`;

if (evidence.type == 'file') {
attachmentForm = {
'section_name': section,
'field_name': field,
'upload_file': evidence.data,
'comments': evidence.comments ? evidence.comments : ' ', /** Required for now, inserting empty string */
};
url += '/file';
} else if ( evidence.type == 'link') {
attachmentForm = {
'section_name': section,
'field_name': field,
'link_name': evidence.name,
'link': evidence.data,
'comments': evidence.comments ? evidence.comments : ' ', /** Required for now, inserting empty string */
};
url += '/link';
}

if (null == attachmentForm) {
throw new Error(`Evidence attachment ${evidence} type is invalid.`);
}

return await Requests.putForm(url, attachmentForm);
},

async removeSectionSupportingEvidenceFile(analysisName, section, field, attachmentId) {
const url = `/rosalution/api/analysis/${analysisName}/section/remove/file`;

const attachmentForm = {
'section_name': section,
'field_name': field,
'attachment_id': attachmentId,
};

const success = await Requests.putForm(url, attachmentForm);
return success;
},

async removeSectionSupportingEvidenceLink(analysisName, section, field) {
const url = `/rosalution/api/analysis/${analysisName}/section/remove/link`;

const attachmentForm = {
'section_name': section,
'field_name': field,
};

const success = await Requests.putForm(url, attachmentForm);
return success;
},

};

const annotationRenderingTemporary = [
Expand Down
Loading