@@ -150,7 +201,6 @@
¿Estás seguro de que deseas eliminar este registro?
-
@@ -163,13 +213,14 @@
function app() {
return {
datos: [],
+ submodules: [],
+ selectedIntegIds: [],
loading: false,
limit: 10,
page: 1,
search: '',
totalPages: 0,
paginatedPages: [],
- // modales
viewModal: false,
addModal: false,
editModal: false,
@@ -178,8 +229,7 @@
errors: {},
init() {
this.loadData();
- this.loadProvServidor();
- this.loadTipoServidor();
+ this.loadSubmodules();
},
loadData() {
if (this.search !== '') {
@@ -190,17 +240,17 @@
}
this.setLoading(true);
axios.get('/app/loadprovservidor', {
- params: {
- page: this.page,
- limit: this.limit,
- search: this.search
- }
+ params: { page: this.page, limit: this.limit, search: this.search }
}).then(response => {
this.datos = response.data.registros.map(data => ({
id: data.ID,
nombre: data.nombre,
+ integraciones: (data.integraciones || []).map(s => ({
+ id: s.ID,
+ title: s.title,
+ url: s.url,
+ })),
}));
-
this.totalPages = response.data.totalPages;
this.calculatePaginatedPages();
}).catch(error => {
@@ -209,12 +259,36 @@
this.setLoading(false);
});
},
+ loadSubmodules() {
+ axios.get('/app/loadsubmodules', { params: { limit: 200, page: 1 } })
+ .then(response => {
+ this.submodules = (response.data.registros || response.data.submodules || []).map(s => ({
+ id: s.ID,
+ title: s.title,
+ url: s.url,
+ }));
+ })
+ .catch(err => console.error('Error cargando submodules:', err));
+ },
+ isIntegSelected(id) {
+ return this.selectedIntegIds.includes(id);
+ },
+ toggleInteg(id) {
+ const idx = this.selectedIntegIds.indexOf(id);
+ if (idx >= 0) {
+ this.selectedIntegIds.splice(idx, 1);
+ } else {
+ this.selectedIntegIds.push(id);
+ }
+ },
setSelectedItem(data) {
this.selectedItem = { ...data };
+ this.selectedIntegIds = (data.integraciones || []).map(i => i.id);
this.errors = {};
},
resetSelectedItem() {
this.selectedItem = {};
+ this.selectedIntegIds = [];
this.errors = {};
},
calculatePaginatedPages() {
@@ -230,16 +304,6 @@
setLoading(value) {
this.loading = value;
},
- // validateFields(fields) {
- // this.errors = {};
- // fields.forEach(field => {
- // if (!this.selectedItem[field]) {
- // this.errors[field] = 'Este campo es obligatorio';
- // }
- // });
- // return Object.keys(this.errors).length === 0;
- // },
-
openViewModal(data) {
this.setSelectedItem(data);
this.viewModal = true;
@@ -248,7 +312,6 @@
this.setSelectedItem(data);
this.editModal = true;
},
-
deleteItem() {
this.setLoading(true);
axios.delete(`/app/provservidor/${this.selectedItem.id}`)
@@ -263,7 +326,6 @@
},
openDeleteModal(data) {
this.selectedItem.id = data.id;
-
this.deleteModal = true;
},
closeModals() {
@@ -271,12 +333,10 @@
this.addModal = false;
this.editModal = false;
this.deleteModal = false;
-
this.resetSelectedItem();
},
addItem() {
this.setLoading(true);
-
axios.post('/app/provservidor', this.selectedItem)
.then(response => {
alert("Proveedor añadido exitosamente.");
@@ -285,22 +345,24 @@
this.loadData();
})
.catch(error => {
- console.error("Error al añadir el servidor:", error);
+ console.error("Error al añadir el proveedor:", error);
})
.finally(() => {
this.setLoading(false);
});
},
-
updateItem() {
- const dataToSend = {
- nombre: this.selectedItem.nombre
- };
-
this.setLoading(true);
-
- axios.put(`/app/provservidor/${this.selectedItem.id}`, dataToSend)
- .then(response => {
+ const id = this.selectedItem.id;
+ // Actualizar nombre
+ axios.put(`/app/provservidor/${id}`, { nombre: this.selectedItem.nombre })
+ .then(() => {
+ // Sincronizar integraciones
+ return axios.put(`/app/provservidor/${id}/integraciones`, {
+ submodule_ids: this.selectedIntegIds
+ });
+ })
+ .then(() => {
alert("Proveedor actualizado exitosamente.");
this.resetSelectedItem();
this.editModal = false;
@@ -315,4 +377,4 @@
}
}
}
-
\ No newline at end of file
+
diff --git a/rest/controllers/prov_servidor_controller.go b/rest/controllers/prov_servidor_controller.go
index 8e735df..d12a935 100755
--- a/rest/controllers/prov_servidor_controller.go
+++ b/rest/controllers/prov_servidor_controller.go
@@ -115,3 +115,26 @@ func DeleteProvServidor(c *fiber.Ctx) error {
"message": "Proveedor de servidor eliminado exitosamente",
})
}
+
+func SetProvServidorIntegraciones(c *fiber.Ctx) error {
+ uid, err := strconv.ParseUint(c.Params("id"), 10, 32)
+ if err != nil {
+ return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"message": "ID inválido"})
+ }
+
+ var body struct {
+ SubmoduleIDs []uint `json:"submodule_ids"`
+ }
+ if err := c.BodyParser(&body); err != nil {
+ return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"message": "Error parsing body"})
+ }
+
+ if err := models.SetProvServidorIntegraciones(uint(uid), body.SubmoduleIDs); err != nil {
+ return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
+ "message": "Error actualizando integraciones",
+ "error": err.Error(),
+ })
+ }
+
+ return c.JSON(fiber.Map{"message": "Integraciones actualizadas"})
+}
diff --git a/rest/controllers/submodules_controller.go b/rest/controllers/submodules_controller.go
index 9cc4deb..8fd2104 100755
--- a/rest/controllers/submodules_controller.go
+++ b/rest/controllers/submodules_controller.go
@@ -39,7 +39,11 @@ func GetSubmodules(c *fiber.Ctx) error {
}
searchQuery := c.Query("search", "") // Obtener el término de búsqueda
- limit := 10 // Número de módulos por página
+ limitStr := c.Query("limit", "10")
+ limit, _ := strconv.Atoi(limitStr)
+ if limit <= 0 {
+ limit = 10
+ }
offset := (page - 1) * limit
// Llama a AllModules con el término de búsqueda
diff --git a/rest/routes/user.go b/rest/routes/user.go
index 2d05afc..7b6f5a0 100755
--- a/rest/routes/user.go
+++ b/rest/routes/user.go
@@ -85,6 +85,7 @@ func UserRoutes(app fiber.Router) {
protected.Get("/loadprovservidor", controllers.GetProvServidor)
protected.Post("/provservidor", controllers.CreateProvServidor)
protected.Put("/provservidor/:id", controllers.UpdateProvServidor)
+ protected.Put("/provservidor/:id/integraciones", controllers.SetProvServidorIntegraciones)
protected.Delete("/provservidor/:id", controllers.DeleteProvServidor)
// Rutas de tipos de servidor