citadel-realms/js/RealmInfo.js

132 lines
3.9 KiB
JavaScript
Raw Permalink Normal View History

2024-11-12 17:12:37 -05:00
var _a;
import GObject from 'gi://GObject';
import Gtk from 'gi://Gtk?version=4.0';
import { Realm } from "./model/Realm.js";
import { RealmInfoEntry } from './RealmInfoEntry.js';
const Sections = {
STATUS: 'Status',
OPTIONS: 'Options',
REALMFS: 'RealmFS',
MOUNTPOINT: 'RealmFS Mountpoint',
};
export class RealmInfo extends Gtk.ScrolledWindow {
constructor() {
super();
this._buffer = "";
this._changeId = 0;
this._realm = null;
this._entries = new Map();
this._addEntries({
left: [
Sections.STATUS,
Sections.REALMFS,
Sections.MOUNTPOINT,
Sections.OPTIONS,
],
right: []
});
}
_addEntries(labels) {
let addSectionEntries = (section, entries) => {
entries.forEach(name => {
let entry = new RealmInfoEntry(name);
this._entries.set(name, entry);
section.append(entry);
});
};
addSectionEntries(this._column, labels['left']);
}
get realm() {
return this._realm;
}
set realm(value) {
if (this.realm === value) {
return;
}
if (this._realm) {
this._realm.disconnect(this._changeId);
}
this._realm = value;
if (this._realm) {
this._changeId = this._realm.connect('changed', () => {
this.displayRealm();
});
this.displayRealm();
}
}
setEntry(name, value) {
let entry = this._entries.get(name);
if (entry) {
entry.setValue(value);
}
}
setEntryVisible(name, isVisible = true) {
let entry = this._entries.get(name);
if (entry) {
entry.set_visible(isVisible);
}
}
displayConfig() {
var _b;
let config = (_b = this._realm) === null || _b === void 0 ? void 0 : _b.config;
if (config) {
let enabled_default = config.enabled_bool_option_labels(true);
let enabled = config.enabled_bool_option_labels(false);
let buffer = enabled_default.join(' ');
buffer += '\n';
buffer += enabled.map(s => `<u>${s}</u>`)
.join(' ');
this.setEntry(Sections.OPTIONS, buffer);
}
else {
this.setEntry(Sections.OPTIONS, '');
}
}
displayRealmFS() {
var _b;
let realmfs = (_b = this._realm) === null || _b === void 0 ? void 0 : _b.realmfs;
if (realmfs) {
this.setEntryVisible(Sections.REALMFS);
this.setEntry(Sections.REALMFS, `${realmfs.name}-realmfs.img`);
if (realmfs.activated) {
this.setEntryVisible(Sections.MOUNTPOINT);
this.setEntry(Sections.MOUNTPOINT, realmfs.mountpoint);
}
else {
this.setEntryVisible(Sections.MOUNTPOINT, false);
}
}
else {
this.setEntryVisible(Sections.REALMFS, false);
this.setEntryVisible(Sections.MOUNTPOINT, false);
}
}
displayRealm() {
if (this._realm) {
this._columnTitle.label = `Realm ${this._realm.name}`;
if (this._realm.is_running()) {
this.setEntry("Status", "Running");
}
else {
this.setEntry("Status", "Stopped");
}
this.displayConfig();
this.displayRealmFS();
}
}
}
_a = RealmInfo;
(() => {
GObject.registerClass({
GTypeName: "RealmInfo",
Template: 'resource:///com/subgraph/citadel/Realms/ui/RealmInfo.ui',
Properties: {
'realm': GObject.ParamSpec.object('realm', '', '', GObject.ParamFlags.READWRITE, Realm),
},
InternalChildren: [
'column',
'columnTitle',
]
}, _a);
})();