From 776ef80b9353107deb12fbe6e2b8b978a6c8f65a Mon Sep 17 00:00:00 2001 From: Juan Felipe Zapata Moreno Date: Fri, 11 Jul 2025 16:29:49 -0600 Subject: [PATCH] Terminar Habilidades puntuadas --- .../Admin/MainRoleSkillsController.php | 93 ++++--- .../js/Components/App/DepartmentSelector.vue | 4 +- .../js/Components/App/MainRoleSelector.vue | 14 +- .../js/Components/App/SkillAssignment.vue | 95 +++---- resources/js/Components/App/SkillsRole.vue | 90 +++++++ resources/js/Lang/es.js | 1 + resources/js/Pages/Admin/App/Create.vue | 2 +- .../js/Pages/Admin/Departments/Create.vue | 2 +- resources/js/Pages/Admin/MainRole/Create.vue | 2 +- .../js/Pages/Admin/MainRoleSkills/Create.vue | 232 +++++++++--------- .../js/Pages/Admin/MainRoleSkills/Index.vue | 189 +++++--------- resources/js/Pages/Admin/Skills/Create.vue | 2 +- 12 files changed, 384 insertions(+), 342 deletions(-) create mode 100644 resources/js/Components/App/SkillsRole.vue diff --git a/app/Http/Controllers/Admin/MainRoleSkillsController.php b/app/Http/Controllers/Admin/MainRoleSkillsController.php index 9e3634d..915cd63 100644 --- a/app/Http/Controllers/Admin/MainRoleSkillsController.php +++ b/app/Http/Controllers/Admin/MainRoleSkillsController.php @@ -8,6 +8,7 @@ use App\Http\Requests\StoreMainRoleSkills; use App\Http\Requests\UpdateMainRoleSkills; +use App\Models\department; use App\Models\mainRole; use App\Models\MainRoleSkills; use App\Models\Score; @@ -42,57 +43,89 @@ public function index() ->orWhereIn('scored_id', $scores) ->with([ 'mainRole:id,name,department_id', - 'mainRole.department:id,name,description', - 'skill:id,name,department_id', + 'skill:id,name', 'score:id,alias' ]) ->paginate(config('app.pagination')); - return $this->vuew('index', [ - 'mainRoleSkills' => $mainRoleSkills - ]); + $departments = department::select(['id', 'name', 'description'])->orderBy('name', 'ASC')->get(); + $mainRoles = mainRole::with(['department:id,name'])->orderBy('name', 'ASC')->get(); + $skills = Skill::with(['department:id,name'])->orderBy('name', 'ASC')->get(); + $scores = Score::orderBy('alias', 'ASC')->get(); + + + return $this->vuew('index', [ + 'mainRoleSkills' => $mainRoleSkills, + 'departments' => $departments, + 'mainRoles' => $mainRoles, + 'skills' => $skills, + 'scores' => $scores, + ]); } public function create() { - $mainRoles = mainRole::with('department:id,name')->orderBy('name', 'ASC')->get(); - $skills = Skill::with('department:id,name')->orderBy('name', 'ASC')->get(); - $scores = Score::orderBy('alias', 'ASC')->get(); + $roleId = request()->get('role_id'); + $departmentId = request()->get('department_id'); - return $this->vuew('create', [ - 'mainRoles' => $mainRoles, - 'skills' => $skills, - 'scores' => $scores - ]); + // Obtener el rol seleccionado y su departamento + $selectedRole = null; + $selectedDepartment = null; + + if ($roleId) { + $selectedRole = mainRole::with('department:id,name')->find($roleId); + if ($selectedRole && $selectedRole->department) { + $selectedDepartment = $selectedRole->department; + } + } elseif ($departmentId) { + $selectedDepartment = department::find($departmentId); + } + $mainRoles = mainRole::with('department:id,name')->orderBy('name', 'ASC')->get(); + $skills = Skill::with('department:id,name')->orderBy('name', 'ASC')->get(); + $scores = Score::orderBy('alias', 'ASC')->get(); + + return $this->vuew('create', [ + 'mainRoles' => $mainRoles, + 'skills' => $skills, + 'scores' => $scores, + 'selectedRole' => $selectedRole, + 'selectedDepartment' => $selectedDepartment + ]); } public function store(StoreMainRoleSkills $request) { - $create = []; - foreach ($request['skills'] as $skill){ - $create[] = [ - 'main_role_id' => $request['main_role_id'], - 'skill_id' => $skill['skill_id'], - 'scored_id' => $skill['scored_id'], - 'created_at' => now(), - 'updated_at' => now(), - ]; - } + $create = []; + foreach ($request['skills'] as $skill) { + $create[] = [ + 'main_role_id' => $request['main_role_id'], + 'skill_id' => $skill['skill_id'], + 'scored_id' => $skill['scored_id'], + 'created_at' => now(), + 'updated_at' => now(), + ]; + } - MainRoleSkills::insert($create); + MainRoleSkills::insert($create); - return $this->index(); + return $this->index(); } public function update(UpdateMainRoleSkills $request, MainRoleSkills $mainRoleSkills) { - $mainRoleSkills->update($request->all()); + $mainRoleSkills->update($request->all()); } - public function destroy($id) + public function destroy($mainRoleId) { - $mainRoleSkill = MainRoleSkills::findOrFail($id); - $mainRoleSkill->delete(); - } + try { + // Eliminar todas las habilidades asociadas a este rol principal + MainRoleSkills::where('main_role_id', $mainRoleId)->delete(); + return $this->index(); + } catch (\Throwable $th) { + Log::channel('mainRoleSkills')->error($th->getMessage()); + return response()->json(['error' => 'Error al eliminar las habilidades'], 500); + } + } } diff --git a/resources/js/Components/App/DepartmentSelector.vue b/resources/js/Components/App/DepartmentSelector.vue index f5ac7b3..42ee4e9 100644 --- a/resources/js/Components/App/DepartmentSelector.vue +++ b/resources/js/Components/App/DepartmentSelector.vue @@ -4,13 +4,11 @@ defineEmits(['select']); const props = defineProps({ departments: Object, }); - -console.log('Department props:', props.departments);