From 8d8f721b3745d863dcf078881e1e5267fe182d05 Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Sat, 6 Jul 2024 13:06:09 -0600 Subject: [PATCH 01/23] implementacion de listas --- app/Http/Controllers/ListaController.php | 65 +++++++++++++++++++ app/Models/Lista.php | 14 ++++ .../2024_07_05_151703_create_listas_table.php | 28 ++++++++ 3 files changed, 107 insertions(+) create mode 100644 app/Http/Controllers/ListaController.php create mode 100644 app/Models/Lista.php create mode 100644 database/migrations/2024_07_05_151703_create_listas_table.php diff --git a/app/Http/Controllers/ListaController.php b/app/Http/Controllers/ListaController.php new file mode 100644 index 0000000..e81b467 --- /dev/null +++ b/app/Http/Controllers/ListaController.php @@ -0,0 +1,65 @@ +id(); + $table->string('nombre'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('listas'); + } +}; -- GitLab From 6b3b52e59aa18ba4be1efe4fbecb1dde18b673df Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Sat, 6 Jul 2024 13:25:10 -0600 Subject: [PATCH 02/23] Relacion de muchos a muchos en modelo de contactos y listas --- app/Models/Contacto.php | 13 ++++++-- app/Models/Lista.php | 6 ++++ ...6_191407_create_listas_contactos_table.php | 32 +++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2024_07_06_191407_create_listas_contactos_table.php diff --git a/app/Models/Contacto.php b/app/Models/Contacto.php index 675b3e8..ebe96dd 100644 --- a/app/Models/Contacto.php +++ b/app/Models/Contacto.php @@ -5,6 +5,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasMany; class Contacto extends Model { @@ -56,18 +58,23 @@ public function cargo(): BelongsTo return $this->belongsTo(cargos::class); } - public function telefonos() + public function telefonos(): HasMany { return $this->hasMany(Telefono::class); } - public function redes() + public function redes(): HasMany { return $this->hasMany(RedesSociales::class); } - public function correos() + public function correos(): HasMany { return $this->hasMany(CorreoContactos::class); } + + public function listas(): BelongsToMany + { + return $this->belongsToMany(Lista::class); + } } diff --git a/app/Models/Lista.php b/app/Models/Lista.php index 0bd4e10..afabb44 100644 --- a/app/Models/Lista.php +++ b/app/Models/Lista.php @@ -4,6 +4,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; class Lista extends Model { @@ -11,4 +12,9 @@ class Lista extends Model protected $fillable = [ 'nombre', ]; + + public function contactos(): BelongsToMany + { + return $this->belongsToMany(Contacto::class); + } } diff --git a/database/migrations/2024_07_06_191407_create_listas_contactos_table.php b/database/migrations/2024_07_06_191407_create_listas_contactos_table.php new file mode 100644 index 0000000..e2c5390 --- /dev/null +++ b/database/migrations/2024_07_06_191407_create_listas_contactos_table.php @@ -0,0 +1,32 @@ +id(); + $table->unsignedBigInteger('lista_id'); + $table->unsignedBigInteger('contacto_id'); + $table->timestamps(); + + $table->foreign('contacto_id')->references('id')->on('contactos')->onDelete('cascade')->onUpdate('cascade'); + $table->foreign('lista_id')->references('id')->on('listas')->onDelete('cascade')->onUpdate('cascade'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('listas_contactos'); + } +}; -- GitLab From 0eb055a75d2057877adc5597d74b2ff56336ed9a Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Sat, 6 Jul 2024 13:50:28 -0600 Subject: [PATCH 03/23] Relacion de grupos y listas --- app/Models/Lista.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Models/Lista.php b/app/Models/Lista.php index afabb44..46b6e3d 100644 --- a/app/Models/Lista.php +++ b/app/Models/Lista.php @@ -17,4 +17,9 @@ public function contactos(): BelongsToMany { return $this->belongsToMany(Contacto::class); } + + public function grupos(): BelongsToMany + { + return $this->belongsToMany(Grupos::class); + } } -- GitLab From 770c3b3bf38341ee1ffaabd97b86279436f7b28f Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Sat, 6 Jul 2024 13:50:43 -0600 Subject: [PATCH 04/23] Migraciones para grupos, subgrupos y listas --- ...7_06_192720_create_listas_grupos_table.php | 32 +++++++++++++++++++ ...6_193217_create_listas_subgrupos_table.php | 32 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 database/migrations/2024_07_06_192720_create_listas_grupos_table.php create mode 100644 database/migrations/2024_07_06_193217_create_listas_subgrupos_table.php diff --git a/database/migrations/2024_07_06_192720_create_listas_grupos_table.php b/database/migrations/2024_07_06_192720_create_listas_grupos_table.php new file mode 100644 index 0000000..d9346c7 --- /dev/null +++ b/database/migrations/2024_07_06_192720_create_listas_grupos_table.php @@ -0,0 +1,32 @@ +id(); + $table->unsignedBigInteger('grupo_id'); + $table->unsignedBigInteger('lista_id'); + $table->timestamps(); + + $table->foreign('grupo_id')->references('id')->on('grupos')->onDelete('cascade')->onUpdate('cascade'); + $table->foreign('lista_id')->references('id')->on('listas')->onDelete('cascade')->onUpdate('cascade'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('listas_grupos'); + } +}; diff --git a/database/migrations/2024_07_06_193217_create_listas_subgrupos_table.php b/database/migrations/2024_07_06_193217_create_listas_subgrupos_table.php new file mode 100644 index 0000000..6b351a6 --- /dev/null +++ b/database/migrations/2024_07_06_193217_create_listas_subgrupos_table.php @@ -0,0 +1,32 @@ +id(); + $table->unsignedBigInteger('subgrupo_id'); + $table->unsignedBigInteger('lista_id'); + $table->timestamps(); + + $table->foreign('subgrupo_id')->references('id')->on('subgrupos')->onDelete('cascade')->onUpdate('cascade'); + $table->foreign('lista_id')->references('id')->on('listas')->onDelete('cascade')->onUpdate('cascade'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('listas_subgrupos'); + } +}; -- GitLab From 4d6feb50bb2b06f40b0701699a1e81e540d7d3ad Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Sat, 6 Jul 2024 13:53:55 -0600 Subject: [PATCH 05/23] Relacion de subgrupos y listas --- app/Models/Lista.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Models/Lista.php b/app/Models/Lista.php index 46b6e3d..e0c28d9 100644 --- a/app/Models/Lista.php +++ b/app/Models/Lista.php @@ -22,4 +22,9 @@ public function grupos(): BelongsToMany { return $this->belongsToMany(Grupos::class); } + + public function subgrupos(): BelongsToMany + { + return $this->belongsToMany(Subgrupo::class); + } } -- GitLab From 125e4eee6de84d45f2c8e8c20ba2e354dded58df Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Sat, 6 Jul 2024 13:55:04 -0600 Subject: [PATCH 06/23] Relacion de listas y subgrupos --- app/Models/Subgrupo.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Models/Subgrupo.php b/app/Models/Subgrupo.php index fe4200a..1f58591 100644 --- a/app/Models/Subgrupo.php +++ b/app/Models/Subgrupo.php @@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; class Subgrupo extends Model { @@ -25,4 +26,9 @@ public function subgrupo(): BelongsTo { return $this->belongsTo(Subgrupo::class); } + + public function listas(): BelongsToMany + { + return $this->belongsToMany(Lista::class); + } } -- GitLab From 1932425bdaac56717233eac503866febb3fdd6ae Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Sat, 6 Jul 2024 13:56:29 -0600 Subject: [PATCH 07/23] Relacion de grupos y listas --- app/Models/Grupos.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Models/Grupos.php b/app/Models/Grupos.php index 57cea9a..d432ebb 100644 --- a/app/Models/Grupos.php +++ b/app/Models/Grupos.php @@ -4,6 +4,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasMany; class Grupos extends Model { @@ -19,6 +21,11 @@ public function users(): HasMany { return $this->hasMany(User::class); } + + public function listas(): BelongsToMany + { + return $this->belongsToMany(Lista::class); + } public $timestamps = false; } -- GitLab From 66877ced69124f3a61dbfc8f830913f074028b6e Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Sat, 6 Jul 2024 14:41:04 -0600 Subject: [PATCH 08/23] Listas en el menu lateral --- .../components/common/sidebaradmin.blade.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/resources/views/components/common/sidebaradmin.blade.php b/resources/views/components/common/sidebaradmin.blade.php index 37d09fd..6a16718 100644 --- a/resources/views/components/common/sidebaradmin.blade.php +++ b/resources/views/components/common/sidebaradmin.blade.php @@ -193,6 +193,24 @@ class="py-3 px-7 flex items-center uppercase font-extrabold bg-white-light/30 da Reportes + -- GitLab From 367c016cb2181300220cd78081ae437bcda5615f Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Sat, 6 Jul 2024 14:47:15 -0600 Subject: [PATCH 09/23] Ruta de listar las listas existentes --- routes/web.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/routes/web.php b/routes/web.php index 4edbc0b..9902315 100644 --- a/routes/web.php +++ b/routes/web.php @@ -11,6 +11,7 @@ use App\Http\Controllers\CaracteristicasController; use App\Http\Controllers\ContactoController; use App\Http\Controllers\GruposController; +use App\Http\Controllers\ListaController; use App\Http\Controllers\SubgrupoController; use App\Http\Controllers\UserController; @@ -91,3 +92,10 @@ Route::put('/contactos/{id}/editar', [ContactoController::class, 'update'])->name('update')->middleware(CheckRoles::class . ':admingen,admin,capturista' ); Route::delete('/contactos/{id}', [ContactoController::class, 'destroy'])->name('destroy')->middleware(CheckRoles::class . ':admingen,admin'); }); + +Route::middleware('auth:sanctum', + config('jetstream.auth_session'), + 'verified', + CheckBanned::class)->name('listas.')->group(function() { + Route::get('/listas', [ListaController::class, 'index'])->name('get')->middleware(CheckRoles::class . ':admingen,admin,capturista'); +}); -- GitLab From c299711050e1981483d9a27e01529c017dba31b4 Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Sun, 7 Jul 2024 22:59:49 -0600 Subject: [PATCH 10/23] Listas --- app/Http/Controllers/ListaController.php | 3 +- ...24_06_23_201805_create_contactos_table.php | 3 +- ...12341_create_contactos_subgrupos_table.php | 32 +++++ ...6_213719_create_contactos_grupos_table.php | 32 +++++ database/seeders/ContactoSeeder.php | 46 +++++++ package-lock.json | 11 +- package.json | 9 +- .../views/adminGen/contactos/create.blade.php | 22 +++- .../views/adminGen/listas/index.blade.php | 117 ++++++++++++++++++ vite.config.js | 1 + 10 files changed, 263 insertions(+), 13 deletions(-) create mode 100644 database/migrations/2024_07_06_212341_create_contactos_subgrupos_table.php create mode 100644 database/migrations/2024_07_06_213719_create_contactos_grupos_table.php create mode 100644 database/seeders/ContactoSeeder.php create mode 100644 resources/views/adminGen/listas/index.blade.php diff --git a/app/Http/Controllers/ListaController.php b/app/Http/Controllers/ListaController.php index e81b467..097237d 100644 --- a/app/Http/Controllers/ListaController.php +++ b/app/Http/Controllers/ListaController.php @@ -12,7 +12,8 @@ class ListaController extends Controller */ public function index() { - // + $listas = Lista::get(); + return view('adminGen.listas.index', compact('listas')); } /** diff --git a/database/migrations/2024_06_23_201805_create_contactos_table.php b/database/migrations/2024_06_23_201805_create_contactos_table.php index f85025d..8a808d8 100644 --- a/database/migrations/2024_06_23_201805_create_contactos_table.php +++ b/database/migrations/2024_06_23_201805_create_contactos_table.php @@ -39,14 +39,13 @@ public function up(): void $table->unsignedBigInteger('cargo_id')->nullable(); $table->unsignedBigInteger('caracteristica_id')->nullable(); //$table->unsignedBigInteger('institucion_id')->nullable(); - $table->unsignedBigInteger('subgrupo_id')->nullable(); $table->foreign('conyuge_id')->references('id')->on('contactos')->nullable(); $table->foreign('profesion_id')->references('id')->on('profesions')->nullable(); //$table->foreign('institucion_id')->references('id')->on('')->nullable(); $table->foreign('cargo_id')->references('id')->on('cargos')->nullable(); $table->foreign('caracteristica_id')->references('id')->on('caracteristicas')->nullable(); - $table->foreign('subgrupo_id')->references('id')->on('subgrupos')->nullable(); + $table->timestamps(); }); } diff --git a/database/migrations/2024_07_06_212341_create_contactos_subgrupos_table.php b/database/migrations/2024_07_06_212341_create_contactos_subgrupos_table.php new file mode 100644 index 0000000..c38554a --- /dev/null +++ b/database/migrations/2024_07_06_212341_create_contactos_subgrupos_table.php @@ -0,0 +1,32 @@ +id(); + $table->unsignedBigInteger('subgrupo_id'); + $table->unsignedBigInteger('contacto_id'); + $table->timestamps(); + + $table->foreign('contacto_id')->references('id')->on('contactos')->onDelete('cascade')->onUpdate('cascade'); + $table->foreign('subgrupo_id')->references('id')->on('subgrupos')->onDelete('cascade')->onUpdate('cascade'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('contactos_subgrupos'); + } +}; diff --git a/database/migrations/2024_07_06_213719_create_contactos_grupos_table.php b/database/migrations/2024_07_06_213719_create_contactos_grupos_table.php new file mode 100644 index 0000000..519440a --- /dev/null +++ b/database/migrations/2024_07_06_213719_create_contactos_grupos_table.php @@ -0,0 +1,32 @@ +id(); + $table->unsignedBigInteger('grupo_id'); + $table->unsignedBigInteger('contacto_id'); + $table->timestamps(); + + $table->foreign('contacto_id')->references('id')->on('contactos')->onDelete('cascade')->onUpdate('cascade'); + $table->foreign('grupo_id')->references('id')->on('grupos')->onDelete('cascade')->onUpdate('cascade'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('contactos_grupos'); + } +}; diff --git a/database/seeders/ContactoSeeder.php b/database/seeders/ContactoSeeder.php new file mode 100644 index 0000000..384224c --- /dev/null +++ b/database/seeders/ContactoSeeder.php @@ -0,0 +1,46 @@ + $faker->firstName, + 'ap_paterno' => $faker->lastName, + 'ap_materno' => $faker->lastName, + 'cargo_desc' => $faker->jobTitle, + 'mes_cump' => $faker->month, + 'dia_cump' => $faker->dayOfMonth, + 'domicilio_oficial' => $faker->address, + 'codigo_postal' => $faker->postcode, + 'localidad_oficial' => $faker->city, + 'municipio_oficial' => $faker->city, + 'estado' => $faker->state, + 'pais' => $faker->country, + 'domicilio_par' => $faker->address, + 'codigo_postal_par' => $faker->postcode, + 'localidad_par' => $faker->city, + 'municipio_par' => $faker->city, + 'estado_par' => $faker->state, + 'pais_par' => $faker->country, + 'finado' => $faker->boolean, + 'foto_perfil' => $faker->imageUrl(), + ]); + } + } +} diff --git a/package-lock.json b/package-lock.json index f8172d6..97c2c52 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,9 +1,12 @@ { - "name": "html", + "name": "agendagobernador", "lockfileVersion": 3, "requires": true, "packages": { "": { + "dependencies": { + "select2": "^4.1.0-rc.0" + }, "devDependencies": { "@tailwindcss/forms": "^0.5.7", "@tailwindcss/typography": "^0.5.10", @@ -2018,6 +2021,12 @@ "queue-microtask": "^1.2.2" } }, + "node_modules/select2": { + "version": "4.1.0-rc.0", + "resolved": "https://registry.npmjs.org/select2/-/select2-4.1.0-rc.0.tgz", + "integrity": "sha512-Hr9TdhyHCZUtwznEH2CBf7967mEM0idtJ5nMtjvk3Up5tPukOLXbHUNmh10oRfeNIhj+3GD3niu+g6sVK+gK0A==", + "license": "MIT" + }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", diff --git a/package.json b/package.json index ff733f9..26faa05 100644 --- a/package.json +++ b/package.json @@ -11,11 +11,14 @@ "autoprefixer": "^10.4.16", "axios": "^1.6.4", "laravel-vite-plugin": "^1.0", + "lodash": "^4.17.19", "postcss": "^8.4.32", - "tailwindcss": "^3.4.0", - "vite": "^5.0", "prettier": "^2.7.1", "prettier-plugin-tailwindcss": "^0.1.13", - "lodash": "^4.17.19" + "tailwindcss": "^3.4.0", + "vite": "^5.0" + }, + "dependencies": { + "select2": "^4.1.0-rc.0" } } diff --git a/resources/views/adminGen/contactos/create.blade.php b/resources/views/adminGen/contactos/create.blade.php index c89c605..08267da 100644 --- a/resources/views/adminGen/contactos/create.blade.php +++ b/resources/views/adminGen/contactos/create.blade.php @@ -131,7 +131,7 @@
- +
@@ -219,14 +219,11 @@
- @foreach($subgrupos as $subgrupo) @endforeach - -
@@ -445,7 +442,20 @@ + + + + + +
+ + +
+ + + + + + + + + + \ No newline at end of file diff --git a/vite.config.js b/vite.config.js index a9578ab..17e692b 100644 --- a/vite.config.js +++ b/vite.config.js @@ -20,6 +20,7 @@ export default defineConfig({ 'resources/css/quill.snow.css', 'resources/css/swiper-bundle.min.css', 'resources/css/tippy.css', + 'resources/js/app.js', ], refresh: true, }), -- GitLab From bf3a07cf6f19bf802d3cb07196fc933d5d88c849 Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Sun, 14 Jul 2024 12:19:32 -0600 Subject: [PATCH 11/23] Menus --- .../views/adminGen/contactos/create.blade.php | 105 ++++++++++-------- 1 file changed, 59 insertions(+), 46 deletions(-) diff --git a/resources/views/adminGen/contactos/create.blade.php b/resources/views/adminGen/contactos/create.blade.php index 08267da..a58c35f 100644 --- a/resources/views/adminGen/contactos/create.blade.php +++ b/resources/views/adminGen/contactos/create.blade.php @@ -24,14 +24,15 @@
-
@@ -217,14 +231,6 @@ @endforeach -
- - -
@@ -232,8 +238,29 @@

-
+
+
+
+ + + + +
+ +
+
+
+ +
+
+ +
@@ -262,8 +289,7 @@

- -
+
@@ -292,7 +318,7 @@

-
+
@@ -352,7 +378,7 @@
-
+
@@ -383,7 +409,7 @@
-
+
@@ -412,7 +438,7 @@
-
+

Enviar formulario

Por favor, revise toda la información antes de enviar el formulario.

@@ -442,20 +468,7 @@ - - - +
+ +
+
+
Crear nueva lista
+
+
+
+
+
+
+
+ +
+
+
+ @csrf +
+
+
+ + +
+
+
+
+
+
+
+ + +
+
+ +
+
+
+ +
+
+
+
+
+
+ + +
+
+ + +
+
+ +
+
+
+ +
+
+
+
+
+
+ + +
+
+ + +
+
+ +
+
+
+ +
+
+
+
+
+
+ + +
+
+
+
+
+
+ + + + + + + + + + + \ No newline at end of file diff --git a/resources/views/adminGen/listas/index.blade.php b/resources/views/adminGen/listas/index.blade.php index cf2df82..208281d 100644 --- a/resources/views/adminGen/listas/index.blade.php +++ b/resources/views/adminGen/listas/index.blade.php @@ -14,7 +14,7 @@
-
-
-
- - -
+
+
- - + + @foreach($subgrupos as $subgrupo) + + @endforeach
@@ -147,7 +141,7 @@
- +
@@ -214,7 +208,7 @@ NiceSelect.bind(select); }); NiceSelect.bind(document.getElementById("grupo_id"), options); - //NiceSelect.bind(document.getElementById("subgrupo_id"), options); + NiceSelect.bind(document.getElementById("subgrupo_id"), options); document.querySelectorAll('.nice-select .current').forEach(el => { if (el.textContent.trim() === 'Select an option') { @@ -240,21 +234,44 @@ const agregarBtnSubgrupo = document.getElementById('agregarBtnSubgrupo'); const dynamicFormContainerSubgrupos = document.getElementById('dynamicFormContainerSubgrupos'); - // agregarBtnSubgrupo.addEventListener('click', function(){ - // const newFormGroup = document.createElement('div'); - // newFormGroup.innerHTML = ` - //
- // - // - //
- // `; - // dynamicFormContainerSubgrupos.appendChild(newFormGroup); - // }); + // Añadir evento de clic para eliminar a los grupos iniciales + document.querySelectorAll('.removeBtn').forEach(function(btn) { + btn.addEventListener('click', function() { + btn.closest('.form-group').remove(); + }); + }); + + agregarBtnSubgrupo.addEventListener('click', function(){ + const newFormGroup = document.createElement('div'); + newFormGroup.classList.add('grid', 'grid-cols-1', 'md:grid-cols-2', 'gap-5', 'form-group', 'relative'); + + const newSelectSubgrupo = `subgrupo_id_${Date.now()}`; + newFormGroup.innerHTML = ` +
+ + +
+
+ +
+ `; + dynamicFormContainerSubgrupos.appendChild(newFormGroup); + NiceSelect.bind(document.getElementById(newSelectSubgrupo), options); + // Añadir evento de clic para eliminar + newFormGroup.querySelector('.removeBtn').addEventListener('click', function() { + newFormGroup.remove(); + }); + }); agregarBtnGrupo.addEventListener('click', function(){ const newFormGroup = document.createElement('div'); @@ -283,12 +300,9 @@ `; dynamicFormContainerGrupos.appendChild(newFormGroup); NiceSelect.bind(document.getElementById(newSelectId), options); - }); - - // Añadir evento de clic para eliminar a los grupos iniciales - document.querySelectorAll('.removeBtn').forEach(function(btn) { - btn.addEventListener('click', function() { - btn.closest('.form-group').remove(); + // Añadir evento de clic para eliminar + newFormGroup.querySelector('.removeBtn').addEventListener('click', function() { + newFormGroup.remove(); }); }); -- GitLab From a6430ea11de84978dfd87a2a2d5875463e613aa2 Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Thu, 22 Aug 2024 09:36:32 -0600 Subject: [PATCH 16/23] Almacenamiento de las listas --- app/Http/Controllers/ListaController.php | 17 +++- app/Models/Contacto.php | 2 +- app/Models/Grupos.php | 2 +- app/Models/Lista.php | 6 +- app/Models/Subgrupo.php | 2 +- .../views/adminGen/listas/create.blade.php | 96 ++++++++++++++----- routes/web.php | 1 + 7 files changed, 96 insertions(+), 30 deletions(-) diff --git a/app/Http/Controllers/ListaController.php b/app/Http/Controllers/ListaController.php index ac98329..473f833 100644 --- a/app/Http/Controllers/ListaController.php +++ b/app/Http/Controllers/ListaController.php @@ -35,7 +35,22 @@ public function create() */ public function store(Request $request) { - // + $request->validate([ + 'nombre' => 'required|string|max:255', + ]); + + $lista = Lista::create($request->only('nombre')); + + $grupoIds = array_filter($request->input('grupo_id', []), fn($value) => $value !== 'null'); + $subgrupoIds = array_filter($request->input('subgrupo_id', []), fn($value) => $value !== 'null'); + $contactoIds = array_filter($request->input('contacto_id', []), fn($value) => $value !== 'null'); + + // Sincronizar relaciones + $lista->grupos()->sync($grupoIds); + $lista->subgrupos()->sync($subgrupoIds); + $lista->contactos()->sync($contactoIds); + + return redirect()->route('listas.get')->with('success', 'Lista creada correctamente.'); } /** diff --git a/app/Models/Contacto.php b/app/Models/Contacto.php index 98c1c4e..64d6ae5 100644 --- a/app/Models/Contacto.php +++ b/app/Models/Contacto.php @@ -74,7 +74,7 @@ public function correos(): HasMany public function listas(): BelongsToMany { - return $this->belongsToMany(Lista::class); + return $this->belongsToMany(Lista::class, 'listas_contactos', 'contacto_id', 'lista_id'); } public function subgrupos(): BelongsToMany diff --git a/app/Models/Grupos.php b/app/Models/Grupos.php index 2e11e86..4267462 100644 --- a/app/Models/Grupos.php +++ b/app/Models/Grupos.php @@ -24,7 +24,7 @@ public function users(): HasMany { public function listas(): BelongsToMany { - return $this->belongsToMany(Lista::class); + return $this->belongsToMany(Lista::class, 'listas_grupos', 'grupo_id', 'lista_id'); } public function contactos(): BelongsToMany diff --git a/app/Models/Lista.php b/app/Models/Lista.php index e0c28d9..485e14a 100644 --- a/app/Models/Lista.php +++ b/app/Models/Lista.php @@ -15,16 +15,16 @@ class Lista extends Model public function contactos(): BelongsToMany { - return $this->belongsToMany(Contacto::class); + return $this->belongsToMany(Contacto::class, 'listas_contactos', 'lista_id', 'contacto_id'); } public function grupos(): BelongsToMany { - return $this->belongsToMany(Grupos::class); + return $this->belongsToMany(Grupos::class, 'listas_grupos', 'lista_id', 'grupo_id'); } public function subgrupos(): BelongsToMany { - return $this->belongsToMany(Subgrupo::class); + return $this->belongsToMany(Subgrupo::class, 'listas_subgrupos', 'lista_id', 'subgrupo_id'); } } diff --git a/app/Models/Subgrupo.php b/app/Models/Subgrupo.php index 8f2cfe3..0545c6e 100644 --- a/app/Models/Subgrupo.php +++ b/app/Models/Subgrupo.php @@ -29,7 +29,7 @@ public function subgrupo(): BelongsTo public function listas(): BelongsToMany { - return $this->belongsToMany(Lista::class); + return $this->belongsToMany(Lista::class, 'listas_subgrupos', 'subgrupo_id', 'lista_id'); } public function contactos(): BelongsToMany diff --git a/resources/views/adminGen/listas/create.blade.php b/resources/views/adminGen/listas/create.blade.php index 241610e..83622c6 100644 --- a/resources/views/adminGen/listas/create.blade.php +++ b/resources/views/adminGen/listas/create.blade.php @@ -22,13 +22,14 @@
-
+ @csrf
@@ -120,7 +131,7 @@
-
+
@@ -145,21 +156,15 @@
-
-
-
- - -
+
+
- - + + @foreach($contactos as $contacto) + + @endforeach
@@ -172,15 +177,24 @@
- +
+
+

Enviar formulario

+
+

Por favor, revise toda la información antes de enviar el formulario.

+

Si encuentra algún error, puede regresar y editar la información antes de enviar.

+
+
+ +

- +
@@ -209,6 +223,7 @@ }); NiceSelect.bind(document.getElementById("grupo_id"), options); NiceSelect.bind(document.getElementById("subgrupo_id"), options); + NiceSelect.bind(document.getElementById("contacto_id"), options); document.querySelectorAll('.nice-select .current').forEach(el => { if (el.textContent.trim() === 'Select an option') { @@ -234,6 +249,9 @@ const agregarBtnSubgrupo = document.getElementById('agregarBtnSubgrupo'); const dynamicFormContainerSubgrupos = document.getElementById('dynamicFormContainerSubgrupos'); + const agregarBtnContacto = document.getElementById('agregarBtnContacto'); + const dynamicFormContainerContactos = document.getElementById('dynamicFormContainerContactos'); + // Añadir evento de clic para eliminar a los grupos iniciales document.querySelectorAll('.removeBtn').forEach(function(btn) { btn.addEventListener('click', function() { @@ -306,6 +324,38 @@ }); }); + agregarBtnContacto.addEventListener('click', function(){ + const newFormGroup = document.createElement('div'); + newFormGroup.classList.add('grid', 'grid-cols-1', 'md:grid-cols-2', 'gap-5', 'form-group', 'relative'); + const newSelectId = `grupo_id_${Date.now()}`; + + newFormGroup.innerHTML = ` +
+ + +
+
+ +
+ `; + dynamicFormContainerContactos.appendChild(newFormGroup); + NiceSelect.bind(document.getElementById(newSelectId), options); + // Añadir evento de clic para eliminar + newFormGroup.querySelector('.removeBtn').addEventListener('click', function() { + newFormGroup.remove(); + }); + }); + document.addEventListener("alpine:init", () => { Alpine.data("crearListas", () => ({ // highlightjs diff --git a/routes/web.php b/routes/web.php index a2933bf..adcf67c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -99,4 +99,5 @@ CheckBanned::class)->name('listas.')->group(function() { Route::get('/listas', [ListaController::class, 'index'])->name('get')->middleware(CheckRoles::class . ':admingen,admin,capturista'); Route::get('/listas/crear', [ListaController::class, 'create'])->name('create')->middleware(CheckRoles::class . ':admingen,admin,capturista'); + Route::post('/listas/crear', [ListaController::class, 'store'])->name('store')->middleware(CheckRoles::class . ':admingen,admin,capturista'); }); -- GitLab From c04dd50d047f4cd949971abce286054487caeb5e Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Thu, 22 Aug 2024 09:39:43 -0600 Subject: [PATCH 17/23] Eliminar logs --- resources/views/adminGen/contactos/index.blade.php | 1 - resources/views/adminGen/listas/index.blade.php | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/resources/views/adminGen/contactos/index.blade.php b/resources/views/adminGen/contactos/index.blade.php index 8bbbaa6..13e9910 100644 --- a/resources/views/adminGen/contactos/index.blade.php +++ b/resources/views/adminGen/contactos/index.blade.php @@ -40,7 +40,6 @@ -
+
  • Dashboard @@ -46,26 +46,25 @@ +
    + +
    +
    +
    Crear nueva lista
    +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    + @method('PUT') + @csrf +
    +
    +
    + + +
    +
    +
    +
    +
    + @foreach($lista->grupos as $grupo) +
    +
    + + +
    +
    + +
    +
    + @endforeach +
    + +
    +
    +
    +
    + @foreach($lista->subgrupos as $subgrupo) +
    +
    + + +
    +
    + +
    +
    + @endforeach +
    + +
    +
    +
    +
    + @foreach($lista->contactos as $contacto) +
    +
    + + +
    +
    + +
    +
    + @endforeach +
    + +
    +
    +
    +

    Enviar formulario

    +
    +

    Por favor, revise toda la información antes de enviar el formulario.

    +

    Si encuentra algún error, puede regresar y editar la información antes de enviar.

    +
    +
    + +
    +
    + +
    +
    + + +
    +
    +
    +
    +
    +
    + + + + + + + + + + + \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 9b7d2b5..d32e1c5 100644 --- a/routes/web.php +++ b/routes/web.php @@ -102,5 +102,6 @@ Route::post('/listas/crear', [ListaController::class, 'store'])->name('store')->middleware(CheckRoles::class . ':admingen,admin,capturista'); route::get('/listas/{id}/ver', [ListaController::class, 'show'])->name('show')->middleware(CheckRoles::class . ':admingen,admin,capturista'); Route::get('/listas/{id}/editar', [ListaController::class, 'edit'])->name('edit')->middleware(CheckRoles::class . ':admingen,admin,capturista' ); + Route::put('/listas/{id}/editar', [ListaController::class, 'update'])->name('update')->middleware(CheckRoles::class . ':admingen,admin,capturista' ); Route::delete('/listas/{id}', [ListaController::class, 'destroy'])->name('destroy')->middleware(CheckRoles::class . ':admingen,admin,capturista'); }); -- GitLab From 04824d8f206231a40e61662ff85db9427cf34d2f Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Fri, 23 Aug 2024 19:52:01 -0600 Subject: [PATCH 23/23] Correcciones al html --- .../views/adminGen/listas/edit.blade.php | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/resources/views/adminGen/listas/edit.blade.php b/resources/views/adminGen/listas/edit.blade.php index 7061a17..f4ae0eb 100644 --- a/resources/views/adminGen/listas/edit.blade.php +++ b/resources/views/adminGen/listas/edit.blade.php @@ -10,12 +10,12 @@ Listas
  • - Crear lista + Actualizar lista
-
Crear nueva lista
+
Actualizar lista: {{$lista->nombre}}
@@ -90,7 +90,7 @@ - Guardar contacto + Guardar lista
@@ -104,6 +104,7 @@
+
@@ -121,7 +122,10 @@
@@ -145,7 +149,10 @@
@@ -169,7 +176,10 @@
@@ -185,8 +195,9 @@

Si encuentra algún error, puede regresar y editar la información antes de enviar.


- +
+
-- GitLab