Skip to content

Commit

Permalink
Improvements for type material. Added actions, mutations and getters #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jlpereira committed Sep 11, 2018
1 parent c0fef70 commit 1756d6f
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import DepictionsComponent from '../shared/depictions.vue'
import RepositoryComponent from './repository.vue'
import { GetterNames } from '../../store/getters/getters'
import { MutationNames } from '../../store/mutations/mutations'
import { ActionNames } from '../../store/actions/actions'
import BlockLayout from '../../../../components/blockLayout.vue'
import RadialAnnotator from '../../../../components/annotator/annotator.vue'
import { GetCollectionObjectDepictions } from '../../request/resources.js'
Expand Down Expand Up @@ -78,7 +78,7 @@
},
methods: {
newCO() {
this.$store.commit(MutationNames.NewCollectionObject)
this.$store.dispatch(ActionNames.NewCollectionObject)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@
<div slot="body">
<div>
<label>Taxon name</label>
<div
v-if="taxon"
class="horizontal-left-content">
<span v-html="taxon.object_tag"/>
<span
class="button circle-button btn-delete"
@click="taxon = undefined"/>
</div>
<autocomplete
v-else
url="/taxon_names/autocomplete"
min="2"
param="term"
Expand Down Expand Up @@ -75,8 +84,13 @@
checkForTypeList () {
return this.types && this.taxon
},
taxon() {
return this.$store.getters[GetterNames.GetTypeMaterial].taxon
taxon: {
get() {
return this.$store.getters[GetterNames.GetTypeMaterial].taxon
},
set(value) {
this.$store.commit(MutationNames.SetTypeMaterialTaxon)
}
},
type: {
get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const ActionNames = {
SaveDetermination: 'saveDetermination',
SaveContainerItem: 'saveContainerItem',
SaveContainer: 'saveContainer',
RemoveCollectionObject: 'removeCollectionObject'
RemoveCollectionObject: 'removeCollectionObject',
NewCollectionObject: 'newCollectionObject'
}

export default ActionNames
4 changes: 3 additions & 1 deletion app/javascript/vue/tasks/digitize/store/actions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import saveDetermination from './saveDetermination'
import saveContainerItem from './saveContainerItem'
import saveContainer from './saveContainer'
import removeCollectionObject from './removeCollectionObject'
import newCollectionObject from './newCollectionObject'

const ActionFunctions = {
[ActionNames.GetTaxon]: getTaxon,
Expand All @@ -20,7 +21,8 @@ const ActionFunctions = {
[ActionNames.SaveDetermination]: saveDetermination,
[ActionNames.SaveContainerItem]: saveContainerItem,
[ActionNames.SaveContainer]: saveContainer,
[ActionNames.RemoveCollectionObject]: removeCollectionObject
[ActionNames.RemoveCollectionObject]: removeCollectionObject,
[ActionNames.NewCollectionObject]: newCollectionObject
}

export { ActionNames, ActionFunctions }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { MutationNames } from '../mutations/mutations'

export default function ({ commit, state }) {
console.log("asdfasdf")
commit(MutationNames.NewCollectionObject)
commit(MutationNames.NewTypeMaterial)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ export default function ({ commit, dispatch, state }) {
return new Promise((resolve, reject) => {
dispatch(ActionNames.SaveCollectionEvent).then(() => {
dispatch(ActionNames.SaveCollectionObject).then(() => {
if(!state.container) {
dispatch(ActionNames.SaveContainer).then(() => {
dispatch(ActionNames.SaveTypeMaterial).then(() => {
if(!state.container) {
dispatch(ActionNames.SaveContainer).then(() => {
dispatch(ActionNames.SaveContainerItem)
})
}
else {
dispatch(ActionNames.SaveContainerItem)
})
}
else {
dispatch(ActionNames.SaveContainerItem)
}
dispatch(ActionNames.SaveIdentifier)
dispatch(ActionNames.SaveTypeMaterial)
dispatch(ActionNames.SaveDetermination)
}
dispatch(ActionNames.SaveIdentifier)
dispatch(ActionNames.SaveDetermination)
})
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function ({ commit, state }) {
UpdateTypeMaterial(type_material).then(response => {
TW.workbench.alert.create('Taxon determination was successfully updated.', 'notice')
commit(MutationNames.SetTypeMaterial, response)
commit(MutationNames.AddTypeMaterial, response)
return resolve(response)
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function(state) {
return state.materialTypes
}
7 changes: 5 additions & 2 deletions app/javascript/vue/tasks/digitize/store/getters/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import getCollectionObjectTypes from './getCollectionObjectTypes'
import getPreferences from './getPreferences'
import getBiocurations from './getBiocurations'
import getPreparationType from './getPreparationType'
import getMaterialTypes from './getMaterialTypes'

const GetterNames = {
GetTaxonDetermination: 'getTaxonDetermination',
Expand All @@ -27,7 +28,8 @@ const GetterNames = {
GetCollectionObjectTypes: 'getCollectionObjectTypes',
GetPreferences: 'getPreferences',
GetBiocurations: 'getBiocurations',
GetPreparationType: 'getPreparationType'
GetPreparationType: 'getPreparationType',
GetMaterialTypes: 'getMaterialTypes'
}

const GetterFunctions = {
Expand All @@ -44,7 +46,8 @@ const GetterFunctions = {
[GetterNames.GetCollectionObjectTypes]: getCollectionObjectTypes,
[GetterNames.GetPreferences]: getPreferences,
[GetterNames.GetBiocurations]: getBiocurations,
[GetterNames.GetPreparationType]: getPreparationType
[GetterNames.GetPreparationType]: getPreparationType,
[GetterNames.GetMaterialTypes]: getMaterialTypes
}

export {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function(state, value) {
state.materialTypes.push(value)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default function(state) {
state.type_material = {
id: undefined,
global_id: undefined,
protonym_id: undefined,
taxon: undefined,
biological_object_id: undefined,
type_type: undefined,
roles_attributes: [],
collection_object: undefined,
origin_citation_attributes: undefined,
type_designator_roles: []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ import setTypeMaterialProtonymId from './TypeMaterial/setTypeMaterialProtonymId'
import setTypeMaterialRoles from './TypeMaterial/setTypeMaterialRoles'
import setTypeMaterialType from './TypeMaterial/setTypeMaterialType'
import setTypeMaterialTaxon from './TypeMaterial/setTypeMaterialTaxon'
import addTypeMaterial from './TypeMaterial/addMaterialTypes'
import newTypeMaterial from './TypeMaterial/newTypeMaterial'

import setIdentifier from './Identifier/setIdentifier'
import setIdentifierIdentifier from './Identifier/setIdentifierIdentifier'
Expand Down Expand Up @@ -117,6 +119,8 @@ const MutationNames = {
SetTypeMaterialRoles: 'setTypeMaterialRoles',
SetTypeMaterialType: 'setTypeMaterialType',
SetTypeMaterialTaxon: 'setTypeMaterialTaxon',
AddTypeMaterial: 'addTypeMaterial',
NewTypeMaterial: 'newTypeMaterial',

SetCollectionEvent: 'setCollectionEvent',
SetCollectionEventPrintLabel: 'setCollectionEventPrintLabel',
Expand Down Expand Up @@ -204,6 +208,8 @@ const MutationFunctions = {
[MutationNames.SetTypeMaterialRoles]: setTypeMaterialRoles,
[MutationNames.SetTypeMaterialType]: setTypeMaterialType,
[MutationNames.SetTypeMaterialTaxon]: setTypeMaterialTaxon,
[MutationNames.AddTypeMaterial]: addTypeMaterial,
[MutationNames.NewTypeMaterial]: newTypeMaterial,

[MutationNames.SetCollectionEvent]: setCollectionEvent,
[MutationNames.SetCollectionEventDocumentLabel]: setCollectionEventDocumentLabel,
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/vue/tasks/digitize/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ function makeInitialState () {
origin_citation_attributes: undefined,
type_designator_roles: []
},
materialTypes: [],
determinations: [],
preferences: {},
container: undefined,
containerItems: [],
Expand Down

0 comments on commit 1756d6f

Please sign in to comment.