/* * Copyright (C) 2019 Red Hat, Inc. * SPDX-License-Identifier: LGPL-2.1-or-later */ import '../lib/patternfly/patternfly-6-cockpit.scss'; import 'polyfills'; import 'cockpit-dark-theme'; // once per page import cockpit from "cockpit"; import React from 'react'; import { createRoot } from "react-dom/client"; import { Page, PageSection, PageSectionVariants } from "@patternfly/react-core/dist/esm/components/Page/index.js"; import { Gallery } from "@patternfly/react-core/dist/esm/layouts/Gallery/index.js"; import { Dropdown, DropdownItem, DropdownList } from '@patternfly/react-core/dist/esm/components/Dropdown/index.js'; import { MenuToggle, MenuToggleAction } from "@patternfly/react-core/dist/esm/components/MenuToggle"; import { superuser } from "superuser"; import { SystemInformationCard } from './overview-cards/systemInformationCard.jsx'; import { ConfigurationCard } from './overview-cards/configurationCard.jsx'; import { HealthCard } from './overview-cards/healthCard.jsx'; import { MotdCard } from './overview-cards/motdCard.jsx'; import { UsageCard } from './overview-cards/usageCard.jsx'; import { SuperuserAlert } from './superuser-alert.jsx'; import { superuser_proxy, SuperuserIndicator } from "superuser-dialogs"; import { ShutdownModal } from 'cockpit-components-shutdown.jsx'; import { WithDialogs, DialogsContext } from "dialogs.jsx"; import "./overview.scss"; import { Title, TitleSizes } from '@patternfly/react-core/dist/esm/components/Title'; const _ = cockpit.gettext; class OverviewPage extends React.Component { static contextType = DialogsContext; constructor(props) { super(props); this.state = { actionIsOpen: false, privileged: true, }; this.hostnameMonitor = this.hostnameMonitor.bind(this); this.onPermissionChanged = this.onPermissionChanged.bind(this); this.superuser = superuser_proxy(); } componentDidMount() { this.hostnameMonitor(); superuser.addEventListener("changed", this.onPermissionChanged); this.onPermissionChanged(); } componentWillUnmount() { superuser.removeEventListener("changed", this.onPermissionChanged); } onPermissionChanged() { this.setState({ privileged: superuser.allowed }); } hostname_text() { if (!this.state.hostnameData) return undefined; const pretty_hostname = this.state.hostnameData.PrettyHostname; const static_hostname = this.state.hostnameData.StaticHostname; let str = this.state.hostnameData.Hostname; if (pretty_hostname && static_hostname && static_hostname !== pretty_hostname) str = pretty_hostname + " (" + static_hostname + ")"; else if (static_hostname) str = static_hostname; return str || ''; } hostnameMonitor() { this.client = cockpit.dbus('org.freedesktop.hostname1'); this.hostname_proxy = this.client.proxy('org.freedesktop.hostname1', '/org/freedesktop/hostname1'); this.hostname_proxy.addEventListener("changed", data => { this.setState({ hostnameData: data.detail }); }); } render() { const Dialogs = this.context; const { actionIsOpen } = this.state; const dropdownItems = [ Dialogs.show()} component="button"> {_("Reboot")} , Dialogs.show()} component="button"> {_("Shutdown")} , ]; let headerActions = null; if (this.state.privileged) headerActions = ( this.setState({ actionIsOpen: false })} toggle={(toggleRef) => ( Dialogs.show()} > {_("Reboot")} ]} onClick={() => this.setState({ actionIsOpen: !actionIsOpen })} id="shutdown-group" /> )} isOpen={actionIsOpen} popperProps={{ position: "right" }} > {dropdownItems} ); const show_superuser = ( cockpit.transport.host && cockpit.transport.host !== "localhost" && !(window.parent.name === "cockpit1" && window.parent.features && window.parent.features.navbar_is_for_current_machine)); return ( {this.hostname_text()} {this.state.hostnameData && this.state.hostnameData.OperatingSystemPrettyName && {cockpit.format(_("running $0"), this.state.hostnameData.OperatingSystemPrettyName)}} { show_superuser && } { "\n" } { headerActions } ); } } function init() { cockpit.translate(); const root = createRoot(document.getElementById("overview")); root.render(); } document.addEventListener("DOMContentLoaded", init);