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

FO identifier and other changes #4202

Merged
merged 9 commits into from
Feb 13, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<label>Total</label>
<input
type="number"
min="0"
v-model="fieldOccurence.total"
@change="() => { fieldOccurence.isUnsaved = true }"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
others.</span
>
</div>
<NamespaceForm v-model="store.namespace" />
<NamespaceForm
v-model="store.namespace"
@selected="namespaceSelected"
/>
</div>
<div class="separate-top">
<label>Identifier</label>
Expand All @@ -27,7 +30,7 @@
existingIdentifier && !isCreatedIdentifierCurrent
}"
type="text"
@input="checkIdentifier"
@input="findExistingIdentifier"
@change="() => (store.identifier.isUnsaved = true)"
v-model="store.identifier.identifier"
/>
Expand All @@ -46,7 +49,7 @@
/>
</div>
<span
v-if="!store.namespace && store.identifier.identifier?.length"
v-if="!store.namespace && store.identifier.identifier"
style="color: red"
>Namespace is needed.</span
>
Expand Down Expand Up @@ -102,7 +105,7 @@ function findExistingIdentifier() {
if (timeOut) {
clearTimeout(timeOut)
}
if (store.identifier.identifier) {
if (store.identifier.identifier && store.namespace) {
timeOut = setTimeout(() => {
Identifier.where({
type: IDENTIFIER_LOCAL_CATALOG_NUMBER,
Expand All @@ -117,9 +120,8 @@ function findExistingIdentifier() {
}
}

function setNamespace(namespace) {
store.namespace = namespace
store.isUnsaved = true
function namespaceSelected() {
store.identifier.isUnsaved = true
findExistingIdentifier()
}
function unsetNamespace() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
pin-section="Namespaces"
pin-type="Namespace"
v-model="namespace"
@selected="(item) => (namespace = item)"
@selected="(item) => (updateNamespace(item))"
>
<template #tabs-right>
<VLock v-model="settings.locked.namespace" />

<WidgetNamespace @create="(item) => (namespace = item)" />
<WidgetNamespace @create="(item) => (updateNamespace(item))" />
</template>
</SmartSelector>
<template v-if="namespace">
<hr />
<SmartSelectorItem
:item="namespace"
label="name"
@click="() => (namespace = undefined)"
@click="() => (updateNamespace(undefined))"
/>
</template>
</fieldset>
Expand All @@ -37,10 +37,17 @@ import SmartSelectorItem from '@/components/ui/SmartSelectorItem.vue'
import VLock from '@/components/ui/VLock/index.vue'
import useSettingStore from '../../../store/settings.js'

const emit = defineEmits(['selected'])

const namespace = defineModel({
type: Object,
default: undefined
})

const settings = useSettingStore()

function updateNamespace(newNamespace) {
namespace.value = newNamespace
emit('selected')
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ import useDeterminationStore from '../store/determinations.js'
import useSettingStore from '../store/settings.js'
import useBiocurationStore from '../store/biocurations.js'
import useBiologicalAssociationStore from '../store/biologicalAssociations.js'
import useIdentifierStore from '../store/identifier.js'
import useDepictionStore from '../store/depictions.js'
import VBtn from '@/components/ui/VBtn/index.vue'
import VRecent from './Recent.vue'
Expand All @@ -106,7 +105,6 @@ const determinationStore = useDeterminationStore()
const biologicalAssociationStore = useBiologicalAssociationStore()
const ceStore = useCEStore()
const biocurationStore = useBiocurationStore()
const identifierStore = useIdentifierStore()
const depictionStore = useDepictionStore()
const fieldOccurrenceId = computed(() => foStore.fieldOccurrence.id)
const isUnsaved = computed(
Expand All @@ -115,8 +113,7 @@ const isUnsaved = computed(
determinationStore.hasUnsaved ||
biocurationStore.hasUnsaved ||
foStore.fieldOccurrence.isUnsaved ||
ceStore.isUnsaved ||
identifierStore.isUnsaved
ceStore.isUnsaved
)

const validateSave = computed(() => {
Expand Down Expand Up @@ -144,7 +141,6 @@ async function save() {
citationStore.save(args),
determinationStore.load(args),
biocurationStore.save(args),
identifierStore.save(args),
biologicalAssociationStore.save(args)
]

Expand Down Expand Up @@ -180,7 +176,6 @@ function reset() {
}

depictionStore.$reset()
identifierStore.reset({ keepNamespace: locked.namespace })
determinationStore.reset({ keepRecords: locked.taxonDeterminations })
citationStore.reset({ keepRecords: locked.citations })
biologicalAssociationStore.reset({
Expand Down Expand Up @@ -237,7 +232,6 @@ async function loadForms(id) {
determinationStore.load(args),
biocurationStore.load(args),
citationStore.load(args),
identifierStore.load(args),
biologicalAssociationStore.load(args),
depictionStore.load(args)
]
Expand Down
kleintom marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
:key="item.id"
@click="selectFO(item)"
>
<td v-html="item.object_tag" />
<td
v-html="item.object_tag"
class="cursor-pointer"
/>
</tr>
</tbody>
</table>
Expand Down
20 changes: 13 additions & 7 deletions app/javascript/vue/tasks/field_occurrences/new/store/identifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,25 @@ export default defineStore('identifiers', {
},

reset({ keepNamespace }) {
this.identifier.id = null
const newIdentifierId = this.increment
? incrementIdentifier(this.identifier.identifier)
: null
this.identifier = {
...makeIdentifier(),
identifier: newIdentifierId,
}

if (!keepNamespace) {
this.namespace = null
}

this.identifier.identifier = this.increment
? incrementIdentifier(this.identifier.identifier)
: null
},

save({ objectId, objectType }) {
if (!this.identifier.isUnsaved) return
if (!this.identifier.isUnsaved ||
!this.identifier.identifier || !this.namespace?.id
) {
return
}

const payload = {
identifier: {
Expand All @@ -74,7 +80,7 @@ export default defineStore('identifiers', {
.then(({ body }) => {
this.identifier = body
})
.catch({})
.catch(() => {})

return request
}
Expand Down
5 changes: 5 additions & 0 deletions app/models/field_occurrence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class FieldOccurrence < ApplicationRecord
validate :check_that_either_total_or_ranged_lot_category_id_is_present
validate :check_that_both_of_category_and_total_are_not_present
validate :total_zero_when_absent
validate :total_positive_when_present

accepts_nested_attributes_for :collecting_event, allow_destroy: true, reject_if: :reject_collecting_event

Expand All @@ -76,6 +77,10 @@ def total_zero_when_absent
errors.add(:total, 'Must be zero when absent.') if (total != 0) && is_absent
end

def total_positive_when_present
errors.add(:total, 'Must be positive when not absent.') if !is_absent && total.present? && total <= 0
end

def check_that_both_of_category_and_total_are_not_present
errors.add(:ranged_lot_category_id, 'Both ranged_lot_category and total can not be set') if ranged_lot_category_id.present? && total.present?
end
Expand Down
12 changes: 9 additions & 3 deletions app/models/identifier/local/catalog_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ def dwc_occurrences
private

def assigned_to_valid_object
# TODO: unkludge
if (identifier_object_type && !(TARGETS.include?(identifier_object_type))) || ( identifier_object && !identifier_object.kind_of?(CollectionObject) && !identifier_object.kind_of?(Container) && !identifier_object.kind_of?(Extract) )
errors.add(:identifier_object_type, "only assignable to #{TARGETS.join(', ')}")
type_issue =
identifier_object_type && !TARGETS.include?(identifier_object_type)

object_issue = identifier_object &&
TARGETS.none? { |c| identifier_object.kind_of?(c.constantize) }

if type_issue || object_issue
errors.add(:identifier_object_type, "only assignable to #{TARGETS.join(', ')}
")
end
end

Expand Down
Loading