From 89e19502d37f545e899d7ee2110f86ac1ddee8fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 16 Nov 2023 11:53:57 +0100 Subject: [PATCH 1/4] Export: in filter "Filter accompanying period work (social action) by type, goal and result", order the items alphabetically or with the defined order --- .../unreleased/Feature-20231116-115315.yaml | 6 +++++ .../vuejs/ExportFormActionGoalResult/App.vue | 27 +++++++++++++++++-- .../Normalizer/SocialIssueNormalizer.php | 1 + 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 .changes/unreleased/Feature-20231116-115315.yaml diff --git a/.changes/unreleased/Feature-20231116-115315.yaml b/.changes/unreleased/Feature-20231116-115315.yaml new file mode 100644 index 000000000..c63dec5f8 --- /dev/null +++ b/.changes/unreleased/Feature-20231116-115315.yaml @@ -0,0 +1,6 @@ +kind: Feature +body: 'Export: in filter "Filter accompanying period work (social action) by type, + goal and result", order the items alphabetically or with the defined order' +time: 2023-11-16T11:53:15.32989153+01:00 +custom: + Issue: "161" diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/App.vue index 322ee3750..235fae90b 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/App.vue @@ -14,7 +14,7 @@ :multiple="true" :close-on-select="false" :placeholder="$t('action.placeholder')" - label="text" + :custom-label="formatSocialAction" track-by="id" :searchable="true" > @@ -161,9 +161,31 @@ export default { }, methods: { async getSocialActionsList() { - this.actions.options = await getSocialActions(); + let actions = await getSocialActions(); + this.actions.options = actions.toSorted(function (a, b) { + console.log(a, b); + if (a.issue.ordering === b.issue.ordering) { + if (a.ordering === b.ordering) { + return 0; + } + if (a.ordering < b.ordering) { + return -1; + } + return 1; + } + + if (a.issue.ordering < b.issue.ordering) { + return -1; + } + + return 1; + }) }, + formatSocialAction({text, issue}) { + return text + ' (' + issue.text + ')'; + }, + /** * Select/unselect in Action Multiselect * @param value @@ -263,6 +285,7 @@ export default { if (dump.length > 0) { //console.log('push ' + dump.length + ' elems in', target, dump); } + data.sort(); }, /** diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialIssueNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialIssueNormalizer.php index a2f69624d..778336d2b 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialIssueNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialIssueNormalizer.php @@ -35,6 +35,7 @@ class SocialIssueNormalizer implements ContextAwareNormalizerInterface, Normaliz 'children_ids' => $socialIssue->getChildren()->map(static fn (SocialIssue $si) => $si->getId()), 'title' => $socialIssue->getTitle(), 'text' => $this->render->renderString($socialIssue, []), + 'ordering' => $socialIssue->getOrdering(), ]; case 'docgen': From 53b47476974e27123c42ec4e43abc14e04108c8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 16 Nov 2023 11:55:15 +0100 Subject: [PATCH 2/4] fixup! Export: in filter "Filter accompanying period work (social action) by type, goal and result", order the items alphabetically or with the defined order --- .../Resources/public/vuejs/ExportFormActionGoalResult/App.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/App.vue index 235fae90b..0d91bbbf0 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/App.vue @@ -163,7 +163,6 @@ export default { async getSocialActionsList() { let actions = await getSocialActions(); this.actions.options = actions.toSorted(function (a, b) { - console.log(a, b); if (a.issue.ordering === b.issue.ordering) { if (a.ordering === b.ordering) { return 0; From eb01c7c203618913fed288d8261b87d48eea9f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 16 Nov 2023 14:22:52 +0100 Subject: [PATCH 3/4] Export: on filter "action by type goals, and results", restore the fields when editing a saved export --- .../unreleased/Fixed-20231116-142207.yaml | 6 ++ .../vuejs/ExportFormActionGoalResult/App.vue | 97 ++++++++++++------- .../vuejs/ExportFormActionGoalResult/api.js | 20 +--- 3 files changed, 71 insertions(+), 52 deletions(-) create mode 100644 .changes/unreleased/Fixed-20231116-142207.yaml diff --git a/.changes/unreleased/Fixed-20231116-142207.yaml b/.changes/unreleased/Fixed-20231116-142207.yaml new file mode 100644 index 000000000..9f3d927ef --- /dev/null +++ b/.changes/unreleased/Fixed-20231116-142207.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: 'Export: on filter "action by type goals, and results", restore the fields when + editing a saved export' +time: 2023-11-16T14:22:07.968973002+01:00 +custom: + Issue: "141" diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/App.vue index 0d91bbbf0..3c91a5f40 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/App.vue @@ -150,14 +150,40 @@ export default { } }, }, - mounted() { - this.getSocialActionsList(); + async mounted() { + await this.getSocialActionsList(); - this.actions.hiddenField.value = ''; - this.goals.hiddenField.value = ''; - this.results.hiddenField.value = ''; + if ('' !== this.actions.hiddenField.value) { + const actionIds = this.actions.hiddenField.value.split(','); + for (const aid of actionIds) { + let action = this.actions.options.find(a => Number.parseInt(aid) === a.id); + if (undefined !== action) { + this.action.push(action); + await this.selectAction(action); + } + } + } - //console.log(this.actions.hiddenField, this.goals.hiddenField, this.results.hiddenField); + if ('' !== this.goals.hiddenField.value) { + const goalsIds = this.goals.hiddenField.value.split(',').map(s => Number.parseInt(s)); + for (const gid of goalsIds) { + let goal = this.goals.options.find(g => gid === g.id); + if (undefined !== goal) { + this.goal.push(goal); + await this.selectGoal(goal); + } + } + } + + if ('' !== this.results.hiddenField.value) { + const resultsIds = this.results.hiddenField.value.split(',').map(s => Number.parseInt(s)); + for (const rid of resultsIds) { + let result = this.results.options.find(r => rid === r.id); + if (undefined !== result) { + this.result.push(result); + } + } + } }, methods: { async getSocialActionsList() { @@ -179,6 +205,8 @@ export default { return 1; }) + + return Promise.resolve(); }, formatSocialAction({text, issue}) { @@ -189,54 +217,51 @@ export default { * Select/unselect in Action Multiselect * @param value */ - selectAction(value) { + async selectAction(value) { //console.log('----'); console.log('select action', value.id); let children = this.getChildrensFromParent(value); this.addSelectedElement('actions', children); let parentAndChildren = [...[value], ...children]; + const promises = []; parentAndChildren.forEach(elem => { - getGoalByAction(elem.id).then(response => new Promise((resolve, reject) => { - this.addElementInData('goals', response.results); - resolve(); - })).catch; - getResultByAction(elem.id).then(response => new Promise((resolve, reject) => { - this.addElementInData('results', response.results); - resolve(); - })).catch; + promises.push(getGoalByAction(elem.id).then(goals => { + this.addElementInData('goals', goals); + return Promise.resolve(); + })); + promises.push(getResultByAction(elem.id).then(results => { + this.addElementInData('results', results); + return Promise.resolve(); + })); }); + + await Promise.all(promises); + return Promise.resolve(); }, unselectAction(value) { - //console.log('----'); console.log('unselect action', value.id); - getGoalByAction(value.id).then(response => new Promise((resolve, reject) => { - [ this.goals.options, this.goals.value ] = this.removeElementInData('goals', response.results); - resolve(); - })).catch; - getResultByAction(value.id).then(response => new Promise((resolve, reject) => { - [ this.results.options, this.results.value ] = this.removeElementInData('results', response.results); - resolve(); - })).catch; + getGoalByAction(value.id).then(goals => { + [this.results.options, this.results.value ] = this.removeElementInData('goals', goals); + }); + getResultByAction(value.id).then(results => { + [this.results.options, this.results.value ] = this.removeElementInData('results', results); + }); }, /** * Select/unselect in Goal Multiselect * @param value */ - selectGoal(value) { - //console.log('----'); console.log('select goal', value.id); - getResultByGoal(value.id).then(response => new Promise((resolve, reject) => { - this.addElementInData('results', response.results); - resolve(); - })).catch; + async selectGoal(value) { + return getResultByGoal(value.id).then(results => { + this.addElementInData('results', results); + }) }, unselectGoal(value) { - //console.log('----'); console.log('unselect goal', value.id); - getResultByGoal(value.id).then(response => new Promise((resolve, reject) => { - [ this.results.options, this.results.value ] = this.removeElementInData('results', response.results); - resolve(); - })).catch; + getResultByGoal(value.id).then(results => { + [ this.results.options, this.results.value ] = this.removeElementInData('results', results); + }).catch; }, /** @@ -284,7 +309,7 @@ export default { if (dump.length > 0) { //console.log('push ' + dump.length + ' elems in', target, dump); } - data.sort(); + data.options.sort(); }, /** diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/api.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/api.js index afcece4f4..0c02c21f0 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/api.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/api.js @@ -8,29 +8,17 @@ const getSocialActions = () => fetchResults( const getGoalByAction = (id) => { let url = `/api/1.0/person/social-work/goal/by-social-action/${id}.json`; - return fetch(url) - .then(response => { - if (response.ok) { return response.json(); } - throw Error('Error with request resource response'); - }); + return fetchResults(url); }; const getResultByAction = (id) => { let url = `/api/1.0/person/social-work/result/by-social-action/${id}.json`; - return fetch(url) - .then(response => { - if (response.ok) { return response.json(); } - throw Error('Error with request resource response'); - }); + return fetchResults(url); }; const getResultByGoal = (id) => { let url = `/api/1.0/person/social-work/result/by-goal/${id}.json`; - return fetch(url) - .then(response => { - if (response.ok) { return response.json(); } - throw Error('Error with request resource response'); - }); + return fetchResults(url); }; export { @@ -38,4 +26,4 @@ export { getGoalByAction, getResultByAction, getResultByGoal, -} \ No newline at end of file +} From 947b7b90e2f38e7f5d461b2729c7dcb8a7d7d6e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 23 Nov 2023 16:02:55 +0100 Subject: [PATCH 4/4] Fix SocialWorkTypeFilter: allow null value in date, and avoid vuejs module ExportFormActionGoal to override the export form content --- .changes/unreleased/Fixed-20231123-144502.yaml | 5 +++++ ...mpanyingPeriodWorkAssociatePersonOnAccompanyingPeriod.php | 5 +++-- .../ListAccompanyingPeriodWorkAssociatePersonOnWork.php | 3 ++- .../Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php | 3 +++ .../public/vuejs/ExportFormActionGoalResult/App.vue | 3 --- .../public/vuejs/ExportFormActionGoalResult/index.js | 4 +++- 6 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 .changes/unreleased/Fixed-20231123-144502.yaml diff --git a/.changes/unreleased/Fixed-20231123-144502.yaml b/.changes/unreleased/Fixed-20231123-144502.yaml new file mode 100644 index 000000000..b48617823 --- /dev/null +++ b/.changes/unreleased/Fixed-20231123-144502.yaml @@ -0,0 +1,5 @@ +kind: Fixed +body: 'Export: fix the list of accompanying period work, when the "calc date" is null' +time: 2023-11-23T14:45:02.839510554+01:00 +custom: + Issue: "219" diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriodWorkAssociatePersonOnAccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriodWorkAssociatePersonOnAccompanyingPeriod.php index 49b21ef69..585df6586 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriodWorkAssociatePersonOnAccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriodWorkAssociatePersonOnAccompanyingPeriod.php @@ -206,6 +206,7 @@ class ListAccompanyingPeriodWorkAssociatePersonOnAccompanyingPeriod implements L public function initiateQuery(array $requiredModifiers, array $acl, array $data = []) { $centers = array_map(static fn ($el) => $el['center'], $acl); + $calcDate = $data['calc_date'] ?? new RollingDate(RollingDate::T_TODAY); $qb = $this->entityManager->createQueryBuilder(); @@ -220,7 +221,7 @@ class ListAccompanyingPeriodWorkAssociatePersonOnAccompanyingPeriod implements L ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') // get participants at the given date ->andWhere('acppart.startDate <= :calc_date AND (acppart.endDate > :calc_date OR acppart.endDate IS NULL)') - ->setParameter('calc_date', $this->rollingDateConverter->convert($data['calc_date'])); + ->setParameter('calc_date', $this->rollingDateConverter->convert($calcDate)); if ($this->filterStatsByCenters) { $qb @@ -236,7 +237,7 @@ class ListAccompanyingPeriodWorkAssociatePersonOnAccompanyingPeriod implements L AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); - $this->addSelectClauses($qb, $this->rollingDateConverter->convert($data['calc_date'])); + $this->addSelectClauses($qb, $this->rollingDateConverter->convert($calcDate)); return $qb; } diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriodWorkAssociatePersonOnWork.php b/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriodWorkAssociatePersonOnWork.php index 4e68d5341..fbde42263 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriodWorkAssociatePersonOnWork.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriodWorkAssociatePersonOnWork.php @@ -206,6 +206,7 @@ class ListAccompanyingPeriodWorkAssociatePersonOnWork implements ListInterface, public function initiateQuery(array $requiredModifiers, array $acl, array $data = []) { $centers = array_map(static fn ($el) => $el['center'], $acl); + $calcDate = $data['calc_date'] ?? new RollingDate(RollingDate::T_TODAY); $qb = $this->entityManager->createQueryBuilder(); @@ -231,7 +232,7 @@ class ListAccompanyingPeriodWorkAssociatePersonOnWork implements ListInterface, AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); - $this->addSelectClauses($qb, $this->rollingDateConverter->convert($data['calc_date'])); + $this->addSelectClauses($qb, $this->rollingDateConverter->convert($calcDate)); return $qb; } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php index 3476bc33e..c84ed7f40 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php @@ -144,6 +144,9 @@ class SocialWorkTypeFilter implements FilterInterface $ids = []; foreach ($asIterable as $value) { + if (null === $value) { + continue; + } $ids[] = $value->getId(); } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/App.vue index 3c91a5f40..3b23ab0ad 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/ExportFormActionGoalResult/App.vue @@ -1,5 +1,4 @@