create document from evaluation

This commit is contained in:
2021-08-19 19:47:06 +02:00
parent 364346d0aa
commit a797143511
6 changed files with 106 additions and 34 deletions

View File

@@ -378,7 +378,6 @@ export default {
this.$store.commit('removeGoal', g);
},
addEvaluation(e) {
console.log('add Evaluation', e);
this.$store.commit('addEvaluation', e);
},
toggleAddEvaluation() {

View File

@@ -67,19 +67,15 @@
<div class="input-group">
<select class="form-select form-select-sm" v-model="template">
<option disabled value="">{{ $t('evaluation_choose_a_template') }}</option>
<option>A</option>
<template v-for="t in getTemplatesAvailaibleForEvaluation">
<option v-bind:value="t.id">{{ t.name.fr }}</option>
</template>
</select>
<button class="btn btn-update btn-sm change-icon" type="button"><i class="fa fa-fw fa-cog"></i></button>
<button v-if="canGenerate" class="btn btn-update btn-sm change-icon" type="button" @click="generateDocument"><i class="fa fa-fw fa-cog"></i></button>
<button v-else class="btn btn-update btn-sm change-icon" type="button" disabled ><i class="fa fa-fw fa-cog"></i></button>
</div>
</div>
</div>
<!--div class="row mb-3">
<label class="col-sm-4 col-form-label">{{ $t('evaluation_add_a_document') }}</label>
<div class="col-sm-8">
<button class="btn btn-create btn-sm" @click="documents"></button>
</div>
</div-->
</div>
</div>
</template>
@@ -88,6 +84,7 @@
import {dateToISO, ISOToDate, ISOToDatetime} from 'ChillMainAssets/chill/js/date.js';
import CKEditor from '@ckeditor/ckeditor5-vue';
import ClassicEditor from 'ChillMainAssets/module/ckeditor5/index.js';
import { mapGetters, mapState } from 'vuex';
const i18n = {
messages: {
@@ -119,25 +116,19 @@ export default {
data() {
return {
editor: ClassicEditor,
//evaluation: {
// status: null,
// startDate: null,
// endDate: null,
// maxDate: null,
// warningInterval: null,
// comment: null,
// template: null,
// //documents: null
//}
template: null,
}
},
computed: {
/*
status: {
get() { return this.evaluation.status; },
set(v) { this.evaluation.status = v; }
...mapGetters([
'getTemplatesAvailaibleForEvaluation'
]),
...mapState([
'isPosting'
]),
canGenerate() {
return !this.$store.state.isPosting && this.template !== null;
},
*/
startDate: {
get() {
return dateToISO(this.evaluation.startDate);
@@ -171,10 +162,6 @@ export default {
get() { return this.evaluation.comment; },
set(v) { this.$store.commit('setEvaluationComment', { key: this.evaluation.key, comment: v }); }
},
template: {
get() { return this.evaluation.template; },
set(v) { this.evaluation.template = v; }
},
},
methods: {
listAllStatus() {
@@ -189,6 +176,10 @@ export default {
})
;
},
generateDocument() {
console.log('template picked', this.template);
this.$store.dispatch('generateDocument', { key: this.evaluation.key, templateId: this.template})
}
},
mounted() {
//this.listAllStatus();

View File

@@ -4,6 +4,7 @@ import { findSocialActionsBySocialIssue } from 'ChillPersonAssets/vuejs/_api/Soc
import { create } from 'ChillPersonAssets/vuejs/_api/AccompanyingCourseWork.js';
const debug = process.env.NODE_ENV !== 'production';
const evalFQDN = encodeURIComponent("Chill\\PersonBundle\\Entity\\AccompanyingPeriod\\AccompanyingPeriodWorkEvaluation");
const store = createStore({
strict: debug,
@@ -32,6 +33,7 @@ const store = createStore({
return k;
}),
evaluationsForAction: [],
templatesAvailableForEvaluation: [],
personsPicked: window.accompanyingCourseWork.persons,
personsReachables: window.accompanyingCourseWork.accompanyingPeriod.participations.filter(p => p.endDate == null)
.map(p => p.person),
@@ -63,6 +65,9 @@ const store = createStore({
hasThirdParties(state) {
return state.thirdParties.length > 0;
},
getTemplatesAvailaibleForEvaluation(state) {
return state.templatesAvailableForEvaluation;
},
buildPayload(state) {
return {
type: 'accompanying_period_work',
@@ -99,6 +104,7 @@ const store = createStore({
accompanyingPeriodWorkEvaluations: state.evaluationsPicked.map(e => {
let o = {
type: e.type,
key: e.key,
evaluation: {
id: e.evaluation.id,
type: e.evaluation.type
@@ -216,6 +222,11 @@ const store = createStore({
let evaluation = state.evaluationsPicked.find(e => e.key === key);
evaluation.editEvaluation = !evaluation.editEvaluation;
},
setTemplatesAvailableForEvaluation(state, templates) {
for (let i in templates) {
state.templatesAvailableForEvaluation.push(templates[i]);
}
},
setPersonsPickedIds(state, ids) {
state.personsPicked = state.personsReachables
.filter(p => ids.includes(p.id))
@@ -317,7 +328,38 @@ const store = createStore({
commit('setEvaluationsForAction', data.results);
});
},
submit({ getters, state, commit }) {
getReachableTemplatesForEvaluation({commit}) {
const
url = `/fr/doc/gen/templates/for/${evalFQDN}`
;
window.fetch(url).then(r => {
if (r.ok) {
return r.json();
}
throw new Error("not possible to load templates for evaluations")
}).then(data => {
commit('setTemplatesAvailableForEvaluation', data.results);
}).catch(e => {
console.error(e);
})
},
generateDocument({ dispatch }, {key, templateId}) {
const callback = function(data) {
// get the evaluation id from the data
const
evaluationId = data.accompanyingPeriodWorkEvaluations.find(e => e.key === key).id,
returnPath = encodeURIComponent(window.location.pathname + window.location.search + window.location.hash),
url = `/fr/doc/gen/generate/from/${templateId}/for/${evalFQDN}/${evaluationId}?returnPath=${returnPath}`
;
//http://localhost:8001/fr/doc/gen/generate/from/12/for/Chill%5CPersonBundle%5CEntity%5CAccompanyingPeriod%5CAccompanyingPeriodWorkEvaluation/41
console.log('I will generate your doc at', url);
window.location.assign(url);
};
dispatch('submit', callback);
},
submit({ getters, state, commit }, callback) {
let
payload = getters.buildPayload,
url = `/api/1.0/person/accompanying-course/work/${state.work.id}.json`,
@@ -345,6 +387,8 @@ const store = createStore({
}
commit('setErrors', errors);
commit('setIsPosting', false);
} else if (typeof(callback) !== 'undefined') {
callback(data);
} else {
console.info('nothing to do here, bye bye');
window.location.assign(`/fr/person/accompanying-period/${state.work.accompanyingPeriod.id}/work`);
@@ -360,6 +404,7 @@ const store = createStore({
dispatch('getReachablesResultsForAction');
dispatch('getReachablesGoalsForAction');
dispatch('getReachablesEvaluationsForAction');
dispatch('getReachableTemplatesForEvaluation');
},
}
});