improve editing of evaluation

- an evaluation type can be repeated multiple times on the same action;
- in vue, evaluation are listed by key, not id,
- adding an evaluation make appears directly in "edit" mode;
- ...
This commit is contained in:
Julien Fastré 2021-08-19 10:14:10 +02:00
parent 9447516694
commit bab06796f1
6 changed files with 134 additions and 83 deletions

View File

@ -13,7 +13,7 @@ use Symfony\Component\Validator\Constraints as Assert;
* @ORM\Entity * @ORM\Entity
* @ORM\Table(schema="chill_asideactivity") * @ORM\Table(schema="chill_asideactivity")
*/ */
final class AsideActivity implements TrackUpdateInterface, TrackCreationInterface class AsideActivity implements TrackUpdateInterface, TrackCreationInterface
{ {
/** /**
* @ORM\Id * @ORM\Id

View File

@ -13,15 +13,15 @@
* *
*/ */
const dateToISO = (date) => { const dateToISO = (date) => {
if (null === date) { if (null === date) {
return null; return null;
} }
return [ return [
date.getFullYear(), date.getFullYear(),
(date.getMonth() + 1).toString().padStart(2, '0'), (date.getMonth() + 1).toString().padStart(2, '0'),
date.getDate().toString().padStart(2, '0') date.getDate().toString().padStart(2, '0')
].join('-'); ].join('-');
}; };
/** /**
@ -30,10 +30,10 @@ const dateToISO = (date) => {
* **Experimental** * **Experimental**
*/ */
const ISOToDate = (str) => { const ISOToDate = (str) => {
let let
[year, month, day] = str.split('-'); [year, month, day] = str.split('-');
return new Date(year, month-1, day); return new Date(year, month-1, day);
} }
/** /**
@ -41,53 +41,100 @@ const ISOToDate = (str) => {
* *
*/ */
const ISOToDatetime = (str) => { const ISOToDatetime = (str) => {
if (null === str) { if (null === str) {
return null; return null;
} }
let let
[cal, times] = str.split('T'), [cal, times] = str.split('T'),
[year, month, date] = cal.split('-'), [year, month, date] = cal.split('-'),
[time, timezone] = times.split(times.charAt(8)), [time, timezone] = times.split(times.charAt(8)),
[hours, minutes, seconds] = time.split(':') [hours, minutes, seconds] = time.split(':')
; ;
return new Date(year, month-1, date, hours, minutes, seconds); return new Date(year, month-1, date, hours, minutes, seconds);
} }
/** /**
* Convert a date to ISO8601, valid for usage in api * Convert a date to ISO8601, valid for usage in api
* *
*/ */
const datetimeToISO = (date) => { const datetimeToISO = (date) => {
let cal, time, offset; let cal, time, offset;
cal = [ cal = [
date.getFullYear(), date.getFullYear(),
(date.getMonth() + 1).toString().padStart(2, '0'), (date.getMonth() + 1).toString().padStart(2, '0'),
date.getDate().toString().padStart(2, '0') date.getDate().toString().padStart(2, '0')
].join('-'); ].join('-');
time = [
date.getHours().toString().padStart(2, '0'),
date.getMinutes().toString().padStart(2, '0'),
date.getSeconds().toString().padStart(2, '0')
].join(':');
offset = [ time = [
date.getTimezoneOffset() <= 0 ? '+' : '-', date.getHours().toString().padStart(2, '0'),
Math.abs(Math.floor(date.getTimezoneOffset() / 60)).toString().padStart(2, '0'), date.getMinutes().toString().padStart(2, '0'),
':', date.getSeconds().toString().padStart(2, '0')
Math.abs(date.getTimezoneOffset() % 60).toString().padStart(2, '0'), ].join(':');
].join('');
let x = cal + 'T' + time + offset;
return x; offset = [
date.getTimezoneOffset() <= 0 ? '+' : '-',
Math.abs(Math.floor(date.getTimezoneOffset() / 60)).toString().padStart(2, '0'),
':',
Math.abs(date.getTimezoneOffset() % 60).toString().padStart(2, '0'),
].join('');
let x = cal + 'T' + time + offset;
return x;
}; };
const intervalDaysToISO = (days) => {
if (null === days) {
return null;
}
return `PD${days}`;
}
const intervalISOToDays = (str) => {
if (null === str) {
return null
}
let days = 0;
let isDate = true;
for (let i = 0; i < str.length; i = i + 1) {
// we do not take time into account
if (!isDate) {
continue;
}
switch (str.charAt(i)) {
case 'P':
isDate = true;
break;
case 'Y':
i = i+1;
days = days + Number.parseInt(str.charAt(i)) * 365;
break;
case 'M':
i = i+1;
days = days + Number.parseInt(str.charAt(i)) * 30;
break;
case 'D':
i = i+1;
days = days + Number.parseInt(str.charAt(i));
break;
case 'T':
isDate = false;
break;
}
}
return days;
}
export { export {
dateToISO, dateToISO,
ISOToDate, ISOToDate,
ISOToDatetime, ISOToDatetime,
datetimeToISO datetimeToISO,
intervalISOToDays,
intervalDaysToISO,
}; };

View File

@ -96,7 +96,7 @@
<div v-if="showAddEvaluation"> <div v-if="showAddEvaluation">
<p>{{ $t('available_evaluations_text') }}</p> <p>{{ $t('available_evaluations_text') }}</p>
<ul class="list-evaluations"> <ul class="list-evaluations">
<li v-for="e in availableForCheckEvaluation" class="badge bg-primary" @click="addEvaluation(e)"> <li v-for="e in evaluationsForAction" class="badge bg-primary" @click="addEvaluation(e)">
<i class="fa fa-plus"></i> <i class="fa fa-plus"></i>
{{ e.title.fr }} {{ e.title.fr }}
</li> </li>
@ -349,12 +349,6 @@ export default {
return this.$store.state.goalsForAction.filter(g => !pickedIds.includes(g.id)); return this.$store.state.goalsForAction.filter(g => !pickedIds.includes(g.id));
}, },
availableForCheckEvaluation() {
//console.log('evaluationsPicked', this.$store.state.evaluationsPicked);
//console.log('evaluationsForAction', this.$store.state.evaluationsForAction);
let pickedIds = this.$store.state.evaluationsPicked.map(e => e.evaluation.id);
return this.$store.state.evaluationsForAction.filter(e => !pickedIds.includes(e.id));
},
pickedEvaluations() { pickedEvaluations() {
return this.$store.state.evaluationsPicked; return this.$store.state.evaluationsPicked;
}, },

View File

@ -1,10 +1,10 @@
<template> <template>
<div> <div>
<div class="item-title" @click="removeEvaluation(e)"> <div class="item-title" @click="removeEvaluation(evaluation)">
<i class="fa fa-fw fa-times"></i> <i class="fa fa-fw fa-times"></i>
{{ evaluation.evaluation.title.fr }} {{ evaluation.evaluation.title.fr }}
</div> </div>
<div v-if="!editEvaluation"> <div v-if="!evaluation.editEvaluation">
<dl class="item-details definition-inline"> <dl class="item-details definition-inline">
<dt v-if="evaluation.startDate">{{ $t('startDate') }} :</dt> <dt v-if="evaluation.startDate">{{ $t('startDate') }} :</dt>
@ -26,7 +26,11 @@
<dl class="item-details"> <dl class="item-details">
<dt v-if="evaluation.comment">{{ $t('comment') }} :</dt> <dt v-if="evaluation.comment">{{ $t('comment') }} :</dt>
<dd v-if="evaluation.comment">{{ evaluation.comment }}</dd> <dd v-if="evaluation.comment">
<blockquote class="chill-user-quote">
{{ evaluation.comment }}
</blockquote>
</dd>
</dl> </dl>
<ul class="record_actions"> <ul class="record_actions">
@ -35,8 +39,8 @@
</li> </li>
</ul> </ul>
</div> </div>
<div v-if="editEvaluation"> <div v-if="evaluation.editEvaluation">
<form-evaluation ref="FormEvaluation" :key="evaluation.id" :evaluation="evaluation"></form-evaluation> <form-evaluation ref="FormEvaluation" :key="evaluation.key" :evaluation="evaluation"></form-evaluation>
<ul class="record_actions"> <ul class="record_actions">
<li> <li>
<button class="btn btn-sm btn-update" @click="submitForm">{{ $t('action.save') }}</button> <button class="btn btn-sm btn-update" @click="submitForm">{{ $t('action.save') }}</button>
@ -70,12 +74,10 @@ export default {
components: { components: {
FormEvaluation FormEvaluation
}, },
props: ['evaluation', 'editEvaluation'], props: ['evaluation'],
i18n, i18n,
data() { data() {
return { return {};
editEvaluation: false,
};
}, },
computed: { computed: {
pickedEvaluations() { pickedEvaluations() {
@ -84,11 +86,12 @@ export default {
}, },
methods: { methods: {
removeEvaluation(e) { removeEvaluation(e) {
console.log(e);
this.$store.commit('removeEvaluation', e); this.$store.commit('removeEvaluation', e);
return; return;
}, },
toggleEditEvaluation(e) { toggleEditEvaluation(e) {
this.editEvaluation = !this.editEvaluation; this.$store.commit('toggleEvaluationEdit', { key: this.evaluation.key });
}, },
submitForm() { submitForm() {
this.toggleEditEvaluation(); this.toggleEditEvaluation();

View File

@ -164,22 +164,16 @@ export default {
}, },
warningInterval: { warningInterval: {
get() { return this.evaluation.warningInterval; }, get() { return this.evaluation.warningInterval; },
set(v) { this.evaluation.warningInterval = v; } set(v) { this.$store.commit('setEvaluationWarningInterval', { key: this.evaluation.key, days: v }); }
}, },
comment: { comment: {
get() { return this.evaluation.comment; }, get() { return this.evaluation.comment; },
set(v) { this.evaluation.comment = v; } set(v) { this.$store.commit('setEvaluationComment', { key: this.evaluation.key, comment: v }); }
}, },
template: { template: {
get() { return this.evaluation.template; }, get() { return this.evaluation.template; },
set(v) { this.evaluation.template = v; } set(v) { this.evaluation.template = v; }
}, },
/*
documents: {
get() { return this.evaluation.documents; },
set(v) { this.evaluation.documents = v; }
}
*/
}, },
methods: { methods: {
listAllStatus() { listAllStatus() {

View File

@ -179,31 +179,44 @@ const store = createStore({
type: "accompanying_period_work_evaluation", type: "accompanying_period_work_evaluation",
key: state.evaluationsPicked.length + 1, key: state.evaluationsPicked.length + 1,
evaluation: evaluation, evaluation: evaluation,
"startDate": null, startDate: null,
"endDate": null, endDate: null,
"maxDate": null, maxDate: null,
"warningInterval": null, warningInterval: null,
"comment": "", comment: "",
editEvaluation: true,
}; };
state.evaluationsPicked.push(e); state.evaluationsPicked.push(e);
console.log('ep', state.evaluationsPicked); console.log('ep', state.evaluationsPicked);
}, },
removeEvaluation(state, evaluation) { removeEvaluation(state, evaluation) {
state.evaluationsPicked = state.evaluationsPicked.filter(e => e.id !== evaluation.id); state.evaluationsPicked = state.evaluationsPicked.filter(e => e.key !== evaluation.key);
console.log('ep', state.evaluationsPicked); console.log('ep', state.evaluationsPicked);
}, },
setEvaluationStartDate(state, {key, date}) { setEvaluationStartDate(state, {key, date}) {
state.evaluationsPicked.find(e => e.key == key) state.evaluationsPicked.find(e => e.key === key)
.startDate = date; .startDate = date;
}, },
setEvaluationEndDate(state, {key, date}) { setEvaluationEndDate(state, {key, date}) {
state.evaluationsPicked.find(e => e.key == key) state.evaluationsPicked.find(e => e.key === key)
.endDate = date; .endDate = date;
}, },
setEvaluationMaxDate(state, {key, date}) { setEvaluationMaxDate(state, {key, date}) {
state.evaluationsPicked.find(e => e.key == key) state.evaluationsPicked.find(e => e.key === key)
.maxDate = date; .maxDate = date;
}, },
setEvaluationWarningInterval(state, {key, days}) {
state.evaluationsPicked.find(e => e.key === key)
.warningInterval = days;
},
setEvaluationComment(state, {key, comment}) {
state.evaluationsPicked.find(e => e.key === key)
.comment = comment;
},
toggleEvaluationEdit(state, {key}) {
let evaluation = state.evaluationsPicked.find(e => e.key === key);
evaluation.editEvaluation = !evaluation.editEvaluation;
},
setPersonsPickedIds(state, ids) { setPersonsPickedIds(state, ids) {
//console.log('persons ids', ids); //console.log('persons ids', ids);
state.personsPicked = state.personsReachables state.personsPicked = state.personsReachables