diff --git a/database/seeders/OrganizationSeeder.php b/database/seeders/OrganizationSeeder.php index f7125f6575260dd69a4d4ee371ead9cf993003bc..2746eab2e21efeea9200d58ffad51c933535588f 100644 --- a/database/seeders/OrganizationSeeder.php +++ b/database/seeders/OrganizationSeeder.php @@ -83,7 +83,7 @@ public function run() }); } - private function setEvaluationsData (Organization $org) + private function setEvaluationsData(Organization $org) { foreach ($org->evaluations as $eval) { if ($eval->current_step < Evaluation::STEP_RESULTS) { diff --git a/resources/js/components/Evaluations/List.vue b/resources/js/components/Evaluations/List.vue index be79e7348769acf55cbf07dd7b23adc6f02b1a15..3e07e611670fc02c042efc99a013c481dba79301 100644 --- a/resources/js/components/Evaluations/List.vue +++ b/resources/js/components/Evaluations/List.vue @@ -131,7 +131,7 @@ class="btn btn-light btn-xs" ><i class="fas fa-chart-bar" /> Résultats</router-link> <button - v-if="!isUser() && !previousCompletedEvaluation" + v-if="!isUser() && !nextCompletedEvaluation(props.row)" class="btn btn-light btn-xs" @click.prevent="editRow(props.row)" ><i class="fas fa-pen" /> Modifier</button> @@ -146,7 +146,7 @@ <i class="fas fa-clipboard-list" /> Rapport </a> <button - v-if="!isUser() && !previousCompletedEvaluation" + v-if="!isUser() && !nextCompletedEvaluation(props.row)" class="btn btn-light btn-xs" @click="deleteRow(props.row)" > @@ -297,15 +297,7 @@ export default { user () { return this.$store.state.user }, - previousCompletedEvaluation (evaluation) { - return this.$store.state.evaluations.all.find(e => { - return e.organization_id === evaluation.organization_id - && e.status === 2 - && e.updated_at < evaluation.updated_at - && e.reference === this.$reference - && evaluation.reference === this.$reference - }) - }, + evaluations () { return this.$store.state.evaluations.all .map(u => { @@ -357,6 +349,16 @@ export default { }, }, methods: { + nextCompletedEvaluation (evaluation) { + return this.$store.state.evaluations.all.find(e => { + return e.organization_id === evaluation.organization_id + && e.status === 2 + && new Date(e.updated_at) > new Date(evaluation.updated_at) + && e.reference === this.$reference + && evaluation.reference === this.$reference + && e.id !== evaluation.id + }) + }, resetFilters () { try { this.dateRange.startDate = null diff --git a/tests/Feature/EvaluationsControllerTest.php b/tests/Feature/EvaluationsControllerTest.php index 92522f79d90c7efb1a7b4078a6c742c39b7f21e8..a8924e21415095d5a3299156df9f0b8d56794d66 100644 --- a/tests/Feature/EvaluationsControllerTest.php +++ b/tests/Feature/EvaluationsControllerTest.php @@ -525,8 +525,7 @@ public function testAdminCannotUpdateEvaluationIfDifferentReference() public function testExecutionMaturityLevelWithOneCompletedEvaluationInOrganizationShouldBeZero() { - $orgWithSingleEvaluation = Organization::whereHas('evaluations', function($q) { - + $orgWithSingleEvaluation = Organization::whereHas('evaluations', function ($q) { }, '=', 1)->first(); $evals = Evaluation::where('status', Evaluation::STATUS_DONE) @@ -544,7 +543,7 @@ public function testExecutionMaturityLevelWithOneCompletedEvaluationInOrganizati $eval = $evals->first(); $execLevel = $eval->maturityLevels->first(function (EvaluationMaturityAnswer $ml) { - return $ml->question->title === 'Exécution'; + return 'Exécution' === $ml->question->title; }); $this->assertEquals(0, $execLevel->answer->level);