diff --git a/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemManager.php b/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemManager.php index 2ffabdf6..6c5d74f1 100644 --- a/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemManager.php +++ b/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemManager.php @@ -4,6 +4,7 @@ use App\BusinessLogicLayer\CrowdSourcingProject\CrowdSourcingProjectManager; use App\BusinessLogicLayer\CrowdSourcingProject\CrowdSourcingProjectTranslationManager; +use App\BusinessLogicLayer\lkp\CrowdSourcingProjectStatusLkp; use App\Models\CrowdSourcingProject\Problem\CrowdSourcingProjectProblem; use App\Models\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemTranslation; use App\Repository\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemRepository; @@ -11,6 +12,7 @@ use App\Utils\FileUploader; use App\ViewModels\CrowdSourcingProject\Problem\CreateEditProblem; use App\ViewModels\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemsLandingPage; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Str; @@ -113,4 +115,29 @@ public function storeProblem(array $attributes): int { public function deleteProblem(int $id): bool { return $this->crowdSourcingProjectProblemRepository->delete($id); } + + public function getProblemStatusesForManagementPage(): Collection { + $problemStatuses = $this->crowdSourcingProjectProblemStatusManager->getAllCrowdSourcingProjectProblemStatusesLkp(); + foreach ($problemStatuses as $problemStatus) { + switch ($problemStatus->id) { + case CrowdSourcingProjectStatusLkp::DRAFT: + $problemStatus->badgeCSSClass = 'badge-secondary'; + break; + case CrowdSourcingProjectStatusLkp::PUBLISHED: + $problemStatus->badgeCSSClass = 'badge-success'; + break; + case CrowdSourcingProjectStatusLkp::FINALIZED: + $problemStatus->badgeCSSClass = 'badge-info'; + break; + case CrowdSourcingProjectStatusLkp::UNPUBLISHED: + $problemStatus->badgeCSSClass = 'badge-danger'; + break; + default: + $problemStatus->badgeCSSClass = 'badge-dark'; + $problemStatus->description = 'The problem is in an unknown status'; + } + } + + return $problemStatuses; + } } diff --git a/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemStatusManager.php b/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemStatusManager.php index 77baceec..cdc54316 100644 --- a/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemStatusManager.php +++ b/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemStatusManager.php @@ -5,7 +5,7 @@ use App\Repository\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemStatusLkpRepository; class CrowdSourcingProjectProblemStatusManager { - protected $crowdSourcingProjectProblemStatusLkpRepository; + protected CrowdSourcingProjectProblemStatusLkpRepository $crowdSourcingProjectProblemStatusLkpRepository; public function __construct(CrowdSourcingProjectProblemStatusLkpRepository $crowdSourcingProjectProblemStatusLkpRepository) { $this->crowdSourcingProjectProblemStatusLkpRepository = $crowdSourcingProjectProblemStatusLkpRepository; diff --git a/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php b/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php index 34aa1919..53195ddc 100644 --- a/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php +++ b/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php @@ -5,6 +5,7 @@ use App\BusinessLogicLayer\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemManager; use App\Http\Controllers\Controller; use Illuminate\Database\Eloquent\ModelNotFoundException; +use Illuminate\Http\JsonResponse; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Validator; @@ -100,7 +101,10 @@ public function update(Request $request, string $id) { * Remove the specified resource from storage. */ public function destroy(string $id) { - // return $this->crowdSourcingProjectProblemManager->deleteProblem($id); - throw new \Exception('Not implemented yet'); + return $this->crowdSourcingProjectProblemManager->deleteProblem($id); + } + + public function getProblemStatusesForManagementPage(): JsonResponse { + return response()->json($this->crowdSourcingProjectProblemManager->getProblemStatusesForManagementPage()); } } diff --git a/resources/assets/js/vue-components/loggedin-environment/management/crowd-sourcing-project/problem/ProblemsManagement.vue b/resources/assets/js/vue-components/loggedin-environment/management/crowd-sourcing-project/problem/ProblemsManagement.vue index e592bc87..09fe1ca9 100644 --- a/resources/assets/js/vue-components/loggedin-environment/management/crowd-sourcing-project/problem/ProblemsManagement.vue +++ b/resources/assets/js/vue-components/loggedin-environment/management/crowd-sourcing-project/problem/ProblemsManagement.vue @@ -126,6 +126,7 @@ export default { projects: [], selectedProject: "", problems: [], + problemStatuses: [], errorMessage: "", showUnpublishedProblemsOnly: false, filteredProblems: [], @@ -141,10 +142,11 @@ export default { computed: { ...mapState(["loading", "modal"]), }, - mounted() { + async mounted() { this.deleteModal = new Modal(document.getElementById("deleteModal")); - this.getCrowdSourcingProjectsForFiltering(); - this.$nextTick(() => { + await this.getProblemStatusesForManagementPage(); + await this.getCrowdSourcingProjectsForFiltering(); + await this.$nextTick(() => { this.dataTableInstance = $("#problemsTable").DataTable({ pageLength: 5, data: [], @@ -175,8 +177,22 @@ export default { methods: { ...mapActions(["get", "post", "setLoading"]), - getCrowdSourcingProjectsForFiltering() { - this.get({ + async getProblemStatusesForManagementPage() { + return this.get({ + url: window.route("api.problems.statuses.management.get"), + data: {}, + urlRelative: false, + }) + .then((response) => { + this.problemStatuses = response.data; + }) + .catch((error) => { + this.showErrorMessage(error); + }); + }, + + async getCrowdSourcingProjectsForFiltering() { + return this.get({ url: window.route("api.crowd-sourcing-projects.for-problems.get"), data: {}, urlRelative: false, @@ -254,32 +270,13 @@ export default { }, getBadgeClassForProblemStatus(problemStatus) { - switch (problemStatus.id) { - case 1: - return "badge-secondary"; - case 2: - return "badge-success"; - case 3: - return "badge-info"; - case 4: - return "badge-danger"; - default: - return "badge-dark"; - } + // search by id in the problemStatuses array + const status = this.problemStatuses.find((status) => status.id === problemStatus.id); + return status ? status.badgeCSSClass : "badge-secondary"; }, getBadgeTitleForProblemStatus(problemStatus) { - switch (problemStatus.id) { - case 1: - return "The problem is pending"; - case 2: - return "The problem is published"; - case 3: - return "The problem is finalized"; - case 4: - return "The problem is unpublished"; - default: - return "Unknown status"; - } + const status = this.problemStatuses.find((status) => status.id === problemStatus.id); + return status ? status.description : "Unknown status"; }, getProblemEditRoute(problem) { return window.route("problems.edit", problem.id); diff --git a/routes/api.php b/routes/api.php index 59694169..5cdd210c 100644 --- a/routes/api.php +++ b/routes/api.php @@ -14,6 +14,7 @@ use App\Http\Controllers\CrowdSourcingProject\CrowdSourcingProjectColorsController; use App\Http\Controllers\CrowdSourcingProject\CrowdSourcingProjectController; +use App\Http\Controllers\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemController; use App\Http\Controllers\FileController; use App\Http\Controllers\LanguageController; use App\Http\Controllers\Questionnaire\QuestionnaireAnswerAnnotationController; @@ -53,6 +54,7 @@ Route::post('/questionnaire/mark-translations', [QuestionnaireController::class, 'markQuestionnaireTranslations'])->name('api.questionnaire.translations.mark'); Route::get('/crowd-sourcing-projects/for-problems', [CrowdSourcingProjectController::class, 'getCrowdSourcingProjectsForProblems'])->name('api.crowd-sourcing-projects.for-problems.get'); Route::post('/crowd-sourcing-projects/get-problems-for-management', [CrowdSourcingProjectController::class, 'getProblemsForCrowdSourcingProjectForManagement'])->name('api.crowd-sourcing-projects.problems.get-management'); + Route::get('/problems/statuses/management', [CrowdSourcingProjectProblemController::class, 'getProblemStatusesForManagementPage'])->name('api.problems.statuses.management.get'); }); Route::group(['middleware' => ['throttle:api-internal', 'auth', 'can:manage-users']], function () {