156 lines
4.3 KiB
JavaScript
156 lines
4.3 KiB
JavaScript
// ui/metricEditDialog.js - Dialogue d'édition pour une métrique de télémétrie
|
|
|
|
import GObject from 'gi://GObject';
|
|
import Gtk from 'gi://Gtk';
|
|
import Adw from 'gi://Adw';
|
|
|
|
/**
|
|
* Dialogue pour éditer les propriétés d'une métrique
|
|
*/
|
|
export const MetricEditDialog = GObject.registerClass(
|
|
class MetricEditDialog extends Adw.MessageDialog {
|
|
_init(parent, metricKey, currentConfig) {
|
|
super._init({
|
|
transient_for: parent,
|
|
modal: true,
|
|
heading: `Edit Metric: ${metricKey}`,
|
|
});
|
|
|
|
this._metricKey = metricKey;
|
|
this._currentConfig = currentConfig;
|
|
|
|
this.add_response('cancel', 'Cancel');
|
|
this.add_response('ok', 'Save');
|
|
this.set_default_response('ok');
|
|
this.set_close_response('cancel');
|
|
|
|
this._buildForm();
|
|
}
|
|
|
|
/**
|
|
* Construit le formulaire d'édition
|
|
*/
|
|
_buildForm() {
|
|
const contentBox = new Gtk.Box({
|
|
orientation: Gtk.Orientation.VERTICAL,
|
|
spacing: 12,
|
|
margin_top: 12,
|
|
margin_bottom: 12,
|
|
margin_start: 12,
|
|
margin_end: 12,
|
|
});
|
|
|
|
// Enabled switch
|
|
const enabledBox = new Gtk.Box({
|
|
orientation: Gtk.Orientation.HORIZONTAL,
|
|
spacing: 12,
|
|
});
|
|
|
|
const enabledLabel = new Gtk.Label({
|
|
label: 'Enabled:',
|
|
xalign: 0,
|
|
hexpand: true,
|
|
});
|
|
|
|
this._enabledSwitch = new Gtk.Switch({
|
|
active: this._currentConfig.enabled || false,
|
|
valign: Gtk.Align.CENTER,
|
|
});
|
|
|
|
enabledBox.append(enabledLabel);
|
|
enabledBox.append(this._enabledSwitch);
|
|
contentBox.append(enabledBox);
|
|
|
|
// Name entry
|
|
const nameBox = new Gtk.Box({
|
|
orientation: Gtk.Orientation.VERTICAL,
|
|
spacing: 6,
|
|
});
|
|
|
|
const nameLabel = new Gtk.Label({
|
|
label: 'Display Name:',
|
|
xalign: 0,
|
|
});
|
|
|
|
this._nameEntry = new Gtk.Entry({
|
|
text: this._currentConfig.name || '',
|
|
placeholder_text: 'Enter metric display name',
|
|
});
|
|
|
|
nameBox.append(nameLabel);
|
|
nameBox.append(this._nameEntry);
|
|
contentBox.append(nameBox);
|
|
|
|
// Unique ID entry
|
|
const uniqueIdBox = new Gtk.Box({
|
|
orientation: Gtk.Orientation.VERTICAL,
|
|
spacing: 6,
|
|
});
|
|
|
|
const uniqueIdLabel = new Gtk.Label({
|
|
label: 'Unique ID:',
|
|
xalign: 0,
|
|
});
|
|
|
|
this._uniqueIdEntry = new Gtk.Entry({
|
|
text: this._currentConfig.unique_id || '',
|
|
placeholder_text: 'Enter unique identifier',
|
|
});
|
|
|
|
uniqueIdBox.append(uniqueIdLabel);
|
|
uniqueIdBox.append(this._uniqueIdEntry);
|
|
contentBox.append(uniqueIdBox);
|
|
|
|
// Interval spin button
|
|
const intervalBox = new Gtk.Box({
|
|
orientation: Gtk.Orientation.VERTICAL,
|
|
spacing: 6,
|
|
});
|
|
|
|
const intervalLabel = new Gtk.Label({
|
|
label: 'Update Interval (seconds):',
|
|
xalign: 0,
|
|
});
|
|
|
|
this._intervalSpin = new Gtk.SpinButton({
|
|
adjustment: new Gtk.Adjustment({
|
|
lower: 1,
|
|
upper: 3600,
|
|
step_increment: 1,
|
|
page_increment: 10,
|
|
value: this._currentConfig.interval_s || 30,
|
|
}),
|
|
climb_rate: 1,
|
|
digits: 0,
|
|
});
|
|
|
|
intervalBox.append(intervalLabel);
|
|
intervalBox.append(this._intervalSpin);
|
|
contentBox.append(intervalBox);
|
|
|
|
// Info label
|
|
const infoLabel = new Gtk.Label({
|
|
label: 'Note: Changes require service restart to take effect',
|
|
wrap: true,
|
|
xalign: 0,
|
|
});
|
|
infoLabel.add_css_class('dim-label');
|
|
|
|
contentBox.append(infoLabel);
|
|
|
|
this.set_extra_child(contentBox);
|
|
}
|
|
|
|
/**
|
|
* Récupère les modifications effectuées
|
|
*/
|
|
getUpdates() {
|
|
return {
|
|
enabled: this._enabledSwitch.active,
|
|
name: this._nameEntry.text.trim() || this._currentConfig.name,
|
|
unique_id: this._uniqueIdEntry.text.trim() || this._currentConfig.unique_id,
|
|
interval_s: this._intervalSpin.value,
|
|
};
|
|
}
|
|
});
|