person: suggest entities for requestor

This commit is contained in:
nobohan 2021-11-28 22:32:19 +01:00
parent 0ad7ca6235
commit 4abb1a7a57

View File

@ -133,6 +133,17 @@
<label class="chill-no-data-statement">{{ $t('requestor.counter') }}</label>
</div>
<div v-if="accompanyingCourse.requestor === null && suggestedEntities.length > 0">
<ul class="list-suggest add-items">
<li v-for="p in suggestedEntities" :key="uniqueId(p)" @click="addSuggestedEntity(p)">
<span class="badge bg-primary" style="cursor: pointer;">
<i class="fa fa-plus fa-fw text-success"></i>
{{ p.text }}
</span>
</li>
</ul>
</div>
<div>
<add-persons v-if="accompanyingCourse.requestor === null"
buttonTitle="requestor.add_requestor"
@ -153,6 +164,7 @@ import OnTheFly from 'ChillMainAssets/vuejs/OnTheFly/components/OnTheFly.vue';
import PersonRenderBox from '../../_components/Entity/PersonRenderBox.vue';
import ThirdPartyRenderBox from 'ChillThirdPartyAssets/vuejs/_components/Entity/ThirdPartyRenderBox.vue';
import Confidential from 'ChillMainAssets/vuejs/_components/Confidential.vue';
import { mapState } from 'vuex';
export default {
name: 'Requestor',
@ -177,6 +189,13 @@ export default {
}
},
computed: {
...mapState({
suggestedEntities: state => [
...state.accompanyingCourse.participations.map(p => p.person),
...state.accompanyingCourse.resources.map(r => r.resource)
]
.filter((e) => e !== null)
}),
accompanyingCourse() {
return this.$store.state.accompanyingCourse
},
@ -227,6 +246,19 @@ export default {
this.$toast.open({message: 'An error occurred'})
}
});
},
addSuggestedEntity(e) {
this.$store.dispatch('addRequestor', { result: e, type: e.type }) //TODO check person | thirdparty
.catch(({name, violations}) => {
if (name === 'ValidationException' || name === 'AccessException') {
violations.forEach((violation) => this.$toast.open({message: violation}));
} else {
this.$toast.open({message: 'An error occurred'})
}
})
},
uniqueId(e) {
return `${e.type}-${e.id}`;
}
}
}