Skip to content

Commit

Permalink
Merge branch 'filter_field_occurrences' of github.com:SpeciesFileGrou…
Browse files Browse the repository at this point in the history
…p/taxonworks into filter_field_occurrences
  • Loading branch information
mjy committed Feb 24, 2025
2 parents 465d25c + 12bff7a commit 2b42171
Show file tree
Hide file tree
Showing 6 changed files with 298 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import { ref, onBeforeMount, shallowRef } from 'vue'
import { ControlledVocabularyTerm, Confidence } from '@/routes/endpoints'
import { ID_PARAM_FOR } from '@/components/radials/filter/constants/idParams.js'
import { QUERY_PARAM } from '@/components/radials/filter/constants/queryParam'
import { CONFIDENCE_LEVEL } from '@/constants'
import ConfidenceList from './ConfidenceList.vue'
import ConfirmationModal from '@/components/ConfirmationModal.vue'
Expand Down Expand Up @@ -134,7 +135,9 @@ function makePayload(confidence) {
return {
mode: selectedMode.value.mode,
confidence_level_id: confidence.id,
filter_query: props.parameters
filter_query: {
[QUERY_PARAM[props.objectType]]: props.parameters
}
}
}
Expand All @@ -143,7 +146,9 @@ function makeReplacePayload([replace, to]) {
mode: selectedMode.value.mode,
confidence_level_id: to.id,
replace_confidence_level_id: replace.id,
filter_query: props.parameters
filter_query: {
[QUERY_PARAM[props.objectType]]: props.parameters
}
}
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<template>
<div
color="create"
class="flex-wrap-row gap-small margin-large-top"
>
<VBtn
v-for="item in list"
:key="item.id"
:color="color"
medium
@click="() => emit('select', item)"
>
<span v-html="item.object_tag" />
</VBtn>
</div>
</template>

<script setup>
import VBtn from '@/components/ui/VBtn/index.vue'
defineProps({
color: {
type: String,
default: 'primary'
},
list: {
type: Array,
default: () => []
}
})
const emit = defineEmits(['select'])
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<template>
<div class="confidence_annotator">
<VSpinner
v-if="isProcessing"
legend="Updating..."
/>
<h3>Mode</h3>
<ul class="no_bullets">
<li
v-for="(value, key) in MODE"
:key="key"
>
<label>
<input
type="radio"
:value="value"
v-model="selectedMode"
/>
{{ key }}
</label>
</li>
</ul>

<component
:is="selectedMode.component"
:color="selectedMode.color"
:list="list"
@select="makeBatchRequest"
/>

<ConfirmationModal
ref="confirmationModalRef"
:container-style="{ 'min-width': 'auto', width: '300px' }"
/>

<VModal
v-if="isTableVisible"
@close="() => (isTableVisible = false)"
>
<template #header>
<h3>Response</h3>
</template>
<template #body>
<PreviewTable :data="response" />
</template>
</VModal>
</div>
</template>

<script setup>
import { ref, onBeforeMount, shallowRef } from 'vue'
import { Protocol, ProtocolRelationship } from '@/routes/endpoints'
import { ID_PARAM_FOR } from '@/components/radials/filter/constants/idParams.js'
import { QUERY_PARAM } from '@/components/radials/filter/constants/queryParam.js'
import ConfidenceList from './ProtocolList.vue'
import ConfirmationModal from '@/components/ConfirmationModal.vue'
import PreviewTable from '@/components/radials/shared/PreviewTable.vue'
import VModal from '@/components/ui/Modal.vue'
import VSpinner from '@/components/ui/VSpinner.vue'
import ConfidenceReplace from './ProtocolReplace.vue'
const props = defineProps({
ids: {
type: Array,
default: () => []
},
objectType: {
type: String,
required: true
},
parameters: {
type: Object,
default: undefined
}
})
const MODE = {
Add: { mode: 'add', component: ConfidenceList, color: 'create' },
Remove: { mode: 'remove', component: ConfidenceList, color: 'destroy' },
Replace: { mode: 'replace', component: ConfidenceReplace, color: 'primary' }
}
const confirmationModalRef = ref(null)
const list = ref([])
const response = ref(null)
const isTableVisible = ref(false)
const isProcessing = ref(false)
const selectedMode = shallowRef(MODE.Add)
onBeforeMount(() => {
Protocol.all().then(({ body }) => {
list.value = body
})
})
async function makeBatchRequest(confidence) {
const ok = await confirmationModalRef.value.show({
title: 'Protocols',
message: 'Are you sure you want to proceed?',
confirmationWord: 'UPDATE',
okButton: 'Create',
cancelButton: 'Cancel',
typeButton: 'submit'
})
if (ok) {
const idParam = ID_PARAM_FOR[props.objectType]
const payload = Array.isArray(confidence)
? makeReplacePayload(confidence)
: makePayload(confidence)
if (props.ids?.length) {
payload.filter_query[idParam] = props.ids
}
isProcessing.value = true
ProtocolRelationship.batchByFilter(payload)
.then(({ body }) => {
response.value = body
isTableVisible.value = true
})
.finally(() => {
isProcessing.value = false
})
}
}
function makePayload(protocol) {
return {
mode: selectedMode.value.mode,
protocol_id: protocol.id,
filter_query: {
[QUERY_PARAM[props.objectType]]: props.parameters
}
}
}
function makeReplacePayload([replace, to]) {
return {
mode: selectedMode.value.mode,
protocol_id: to.id,
replace_protocol_id: replace.id,
filter_query: {
[QUERY_PARAM[props.objectType]]: props.parameters
}
}
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<template>
<div>
<ProtocolList
class="margin-medium-bottom"
:list="protocols"
@select="addItem"
/>

<table class="full_width margin-medium-bottom">
<thead>
<tr>
<th class="half_width">
Change
<VBtn
circle
color="primary"
:disabled="selected.length < 1"
@click="() => selected.splice(0, 1)"
>
<VIcon
name="trash"
x-small
/>
</VBtn>
</th>
<th class="half_width">
To
<VBtn
circle
color="primary"
:disabled="!isFilled"
@click="() => selected.splice(1, 1)"
>
<VIcon
name="trash"
x-small
/>
</VBtn>
</th>
<th class="w-2">
<VBtn
color="primary"
:disabled="!isFilled"
@click="() => selected.reverse()"
>
Flip
</VBtn>
</th>
</tr>
</thead>
<tbody>
<tr>
<td v-html="selected[0]?.object_tag"></td>
<td v-html="selected[1]?.object_tag"></td>
<td />
</tr>
</tbody>
</table>

<VBtn
color="update"
:disabled="!isFilled"
@click="() => emit('select', selected)"
>
Replace
</VBtn>
</div>
</template>

<script setup>
import { computed, ref } from 'vue'
import ProtocolList from './ProtocolList.vue'
import VBtn from '@/components/ui/VBtn/index.vue'
import VIcon from '@/components/ui/VIcon/index.vue'
const props = defineProps({
list: {
type: Array,
default: () => []
}
})
const emit = defineEmits(['select'])
const selected = ref([])
const isFilled = computed(() => selected.value.length === 2)
const protocols = computed(() =>
props.list.filter((item) => !selected.value.some((c) => c.id == item.id))
)
function addItem(item) {
if (selected.value.length < 2) {
selected.value.push(item)
}
}
</script>
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import AnnotatorTag from '../components/Annotator/AnnotatorTag.vue'
import AnnotatorNote from '../components/Annotator/AnnotatorNote.vue'
import AnnotatorConfidence from '../components/Annotator/Confidence/ConfidenceMain.vue'
import AnnotatorVerifier from '../components/Annotator/AnnotatorVerifier.vue'
import AnnotatorAttribution from '../components/Annotator/Attribution/AttributionMain.vue'
import AnnotatorCitation from '../components/Annotator/AnnotatorCitation.vue'
import AnnotatorDataAttribute from '../components/Annotator/DataAttribute/AnnotatorDataAttribute.vue'
import AnnotatorProtocol from '../components/Annotator/Protocol/ProtocolMain.vue'

export const ANNOTATORS = {
all: {
Confidence: AnnotatorConfidence,
'Data attributes': AnnotatorDataAttribute
'Data attributes': AnnotatorDataAttribute,
Protocol: AnnotatorProtocol
},

ids: {
Expand All @@ -18,6 +19,7 @@ export const ANNOTATORS = {
Confidence: AnnotatorConfidence,
'Data attributes': AnnotatorDataAttribute,
Notes: AnnotatorNote,
Protocol: AnnotatorProtocol,
Tags: AnnotatorTag
}
}
7 changes: 6 additions & 1 deletion app/javascript/vue/routes/endpoints/ProtocolRelationship.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ajaxCall } from '@/helpers'
import baseCRUD from './base'

const controller = 'protocol_relationships'
const permitParams = {
protocol_relationship: {
protocol_id: Number,
Expand All @@ -10,5 +12,8 @@ const permitParams = {
}

export const ProtocolRelationship = {
...baseCRUD('protocol_relationships', permitParams),
...baseCRUD(controller, permitParams),

batchByFilter: (params) =>
ajaxCall('post', `/${controller}/batch_by_filter_scope`, params)
}

0 comments on commit 2b42171

Please sign in to comment.