/* * Copyright (C) 2017 Red Hat, Inc. * SPDX-License-Identifier: LGPL-2.1-or-later */ import cockpit from "cockpit"; import React from "react"; import { Button } from "@patternfly/react-core/dist/esm/components/Button/index.js"; import { Breadcrumb, BreadcrumbItem } from "@patternfly/react-core/dist/esm/components/Breadcrumb/index.js"; import { Card, CardBody, CardHeader, CardTitle } from '@patternfly/react-core/dist/esm/components/Card/index.js'; import { Flex } from "@patternfly/react-core/dist/esm/layouts/Flex/index.js"; import { Page, PageBreadcrumb, PageSection } from "@patternfly/react-core/dist/esm/components/Page/index.js"; import { Stack } from "@patternfly/react-core/dist/esm/layouts/Stack/index.js"; import { ExternalLinkAltIcon } from '@patternfly/react-icons'; import { icon_url, launch, ProgressBar, CancelButton, reload_bridge_packages, ProgressReporter } from "./utils"; import "./application.scss"; import { getPackageManager } from "packagemanager.js"; const _ = cockpit.gettext; async function install_package(pkgname, progress_cb) { const packagemanager = await getPackageManager(); await packagemanager.install_packages([pkgname], progress_cb); await reload_bridge_packages(); } async function remove_package(filename, progress_cb) { const progress = new ProgressReporter(0, 1, progress_cb); const packagemanager = await getPackageManager(); const pkgnames = await packagemanager.find_file_packages([filename], progress.progress_reporter); progress.base = 1; progress.range = 99; await packagemanager.remove_packages(pkgnames, progress.progress_reporter); await reload_bridge_packages(); } export const ActionButton = ({ comp, progress, action }) => { function install(comp) { action(install_package, comp.pkgname, _("Installing"), comp.id); } function remove(comp) { action(remove_package, comp.file, _("Removing"), comp.id); } if (progress) { return ; } else if (comp.installed) { return ; } else { return ; } }; export const Application = ({ metainfo_db, id, progress, action }) => { if (!id) return null; const comp = metainfo_db.components[id]; function render_homepage_link(urls) { return urls.map((url, index) => { if (url.type === 'homepage') { return ( ); } else { return null; } }); } // Render a description in the form returned by the AppStream // parser, which is a list of paragraphs and lists. function render_description(description) { if (!description) return

{_("No description provided.")}

; return description.map((paragraph, index) => { if (paragraph.tag === 'ul') { return ; } else if (paragraph.tag === 'ol') { return
    {paragraph.items.map(item =>
  1. {item}
  2. )}
; } else { return

{paragraph}

; } }); } // Render the icon, name, homepage link, summary, description, and screenshots of the component, // plus the UI for installing and removing it. function render_comp() { if (!comp) return
{_("Unknown application")}
; let progress_or_launch; if (progress) { progress_or_launch = ; } else if (comp.installed) { progress_or_launch = ; } else { progress_or_launch = null; } return ( {progress_or_launch}, }}> {comp.summary} {render_homepage_link(comp.urls)}
{render_description(comp.description)}
{comp.screenshots.length ?
{ comp.screenshots.map((s, index) => ) }
: null}
); } return ( {_("Applications")} {comp ? comp.name : id} {render_comp()} ); };