unifi controler v1 working
This commit is contained in:
parent
8162d367f0
commit
3f2414a415
4 changed files with 138 additions and 1 deletions
|
|
@ -63,6 +63,8 @@ This module allows you to:
|
|||
'unifi_integration/static/src/components/import_site_button/import_site_button.js',
|
||||
'unifi_integration/static/src/components/import_site_button/import_site_button.xml',
|
||||
'unifi_integration/static/src/css/unifi.css',
|
||||
'unifi_integration/static/src/js/network_list_button.js',
|
||||
'unifi_integration/static/src/xml/network_list_button.xml',
|
||||
],
|
||||
},
|
||||
'external_dependencies': {
|
||||
|
|
|
|||
125
unifi_integration/static/src/js/network_list_button.js
Normal file
125
unifi_integration/static/src/js/network_list_button.js
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
/** @odoo-module */
|
||||
import { ListController } from "@web/views/list/list_controller";
|
||||
import { registry } from '@web/core/registry';
|
||||
import { listView } from '@web/views/list/list_view';
|
||||
|
||||
/**
|
||||
* Controller pour la vue liste des réseaux avec un bouton de synchronisation
|
||||
* Cette classe étend le contrôleur de liste standard pour ajouter un bouton de synchronisation
|
||||
* Le bouton est visible uniquement si tous les réseaux appartiennent au même site
|
||||
*/
|
||||
export class NetworkListController extends ListController {
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
static components = {
|
||||
...ListController.components,
|
||||
};
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
static template = "unifi_integration.NetworkListView.Buttons";
|
||||
setup() {
|
||||
super.setup();
|
||||
this.orm = this.env.services.orm;
|
||||
this.notification = this.env.services.notification;
|
||||
this.buttonVisible = false;
|
||||
this.singleSiteId = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Méthode appelée après le rendu du composant
|
||||
* Utilisée pour vérifier si tous les réseaux appartiennent au même site
|
||||
*/
|
||||
mounted() {
|
||||
super.mounted();
|
||||
this.checkSingleSite();
|
||||
}
|
||||
|
||||
/**
|
||||
* Méthode appelée lorsque les données du modèle sont mises à jour
|
||||
*/
|
||||
async onWillStart() {
|
||||
await super.onWillStart();
|
||||
this.checkSingleSite();
|
||||
}
|
||||
|
||||
/**
|
||||
* Méthode appelée lorsque les données du modèle sont mises à jour
|
||||
*/
|
||||
async willUpdateProps() {
|
||||
await super.willUpdateProps();
|
||||
this.checkSingleSite();
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si tous les réseaux affichés appartiennent au même site
|
||||
* Met à jour this.buttonVisible en conséquence
|
||||
*/
|
||||
async checkSingleSite() {
|
||||
console.log('checkSingleSite appelé');
|
||||
console.log('this.model:', this.model);
|
||||
|
||||
if (!this.model.root || !this.model.root.records || !this.model.root.records.length) {
|
||||
console.log('Aucun enregistrement trouvé');
|
||||
this.buttonVisible = false;
|
||||
this.singleSiteId = null;
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Nombre d\'enregistrements:', this.model.root.records.length);
|
||||
|
||||
// Récupérer tous les site_id uniques
|
||||
const siteIds = new Set();
|
||||
for (const record of this.model.root.records) {
|
||||
console.log('Record data:', record.data);
|
||||
if (record.data.site_id && record.data.site_id[0]) {
|
||||
siteIds.add(record.data.site_id[0]);
|
||||
console.log('Ajout du site_id:', record.data.site_id[0]);
|
||||
} else {
|
||||
console.log('Pas de site_id pour cet enregistrement');
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Nombre de sites uniques:', siteIds.size);
|
||||
console.log('Sites IDs:', Array.from(siteIds));
|
||||
|
||||
// Le bouton est visible uniquement s'il y a exactement un site_id
|
||||
this.buttonVisible = siteIds.size === 1;
|
||||
this.singleSiteId = this.buttonVisible ? Array.from(siteIds)[0] : null;
|
||||
|
||||
console.log('buttonVisible:', this.buttonVisible);
|
||||
console.log('singleSiteId:', this.singleSiteId);
|
||||
|
||||
// Forcer la mise à jour du rendu
|
||||
this.render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gestionnaire de clic pour le bouton de synchronisation des réseaux
|
||||
*/
|
||||
async onSyncNetworksClick() {
|
||||
if (!this.buttonVisible) {
|
||||
this.notification.add("Impossible de synchroniser des réseaux de sites différents", {
|
||||
type: "warning",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Afficher une alerte pour tester
|
||||
alert("Ça marche - Synchronisation des réseaux du site " + this.singleSiteId);
|
||||
|
||||
// Notification de succès
|
||||
this.notification.add("Ça marche - Synchronisation des réseaux du site " + this.singleSiteId, {
|
||||
type: "success",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Enregistrement de la vue liste personnalisée
|
||||
registry.category("views").add("unifi_network_list", {
|
||||
...listView,
|
||||
Controller: NetworkListController,
|
||||
buttonTemplate: "unifi_integration.NetworkListView.Buttons",
|
||||
});
|
||||
10
unifi_integration/static/src/xml/network_list_button.xml
Normal file
10
unifi_integration/static/src/xml/network_list_button.xml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<templates>
|
||||
<t t-name="unifi_integration.NetworkListView.Buttons" t-inherit="web.ListView.Buttons">
|
||||
<xpath expr="//div[hasclass('o_list_buttons')]" position="after">
|
||||
<button t-if="buttonVisible" type="button" class="btn btn-primary" style="margin-left: 10px;" t-on-click="onSyncNetworksClick">
|
||||
Synchroniser
|
||||
</button>
|
||||
</xpath>
|
||||
</t>
|
||||
</templates>
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
<field name="name">unifi.network.list</field>
|
||||
<field name="model">unifi.network</field>
|
||||
<field name="arch" type="xml">
|
||||
<list string="Réseaux UniFi" decoration-muted="not enabled">
|
||||
<list string="Réseaux UniFi" decoration-muted="not enabled" js_class="unifi_network_list">
|
||||
<field name="name"/>
|
||||
<field name="purpose"/>
|
||||
<field name="subnet"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue