From 7080a089c50c1ed1ee81a37d03d96db82bf52942 Mon Sep 17 00:00:00 2001 From: Marius Vollmer Date: Thu, 26 Oct 2023 13:30:41 +0300 Subject: [PATCH] WIP - "create ptable" and "erase" are different dialogs now --- pkg/storaged/content-views.jsx | 52 +++++++++++++++++++++++----------- pkg/storaged/pages/drive.jsx | 29 ++++++++++++------- 2 files changed, 54 insertions(+), 27 deletions(-) diff --git a/pkg/storaged/content-views.jsx b/pkg/storaged/content-views.jsx index 33d6e92735cb..5b4206291cee 100644 --- a/pkg/storaged/content-views.jsx +++ b/pkg/storaged/content-views.jsx @@ -715,21 +715,10 @@ export function block_content_rows(client, block, options) { } export function format_disk(client, block) { - const usage = utils.get_active_usage(client, block.path, _("initialize"), _("delete")); - - if (usage.Blocking) { - dialog_open({ - Title: cockpit.format(_("$0 is in use"), utils.block_name(block)), - Body: BlockingMessage(usage), - }); - return; - } - dialog_open({ - Title: cockpit.format(_("Initialize disk $0"), utils.block_name(block)), - Teardown: TeardownMessage(usage), + Title: cockpit.format(_("Create partition table on disk $0"), utils.block_name(block)), Fields: [ - SelectOne("type", _("Partitioning"), + SelectOneRadioVertical("type", _("Partitioning"), { value: "gpt", choices: [ @@ -738,9 +727,38 @@ export function format_disk(client, block) { value: "gpt", title: _("Compatible with modern system and hard disks > 2TB (GPT)") }, - { value: "empty", title: _("No partitioning") } ] }), + ], + Action: { + Title: _("Create"), + wrapper: job_progress_wrapper(client, block.path), + action: async function (vals) { + const options = { + 'tear-down': { t: 'b', v: true } + }; + await block.Format(vals.type, options); + await utils.reload_systemd(); + } + } + }); +} + +export function erase_disk(client, block) { + const usage = utils.get_active_usage(client, block.path, _("erase"), _("delete")); + + if (usage.Blocking) { + dialog_open({ + Title: cockpit.format(_("$0 is in use"), utils.block_name(block)), + Body: BlockingMessage(usage), + }); + return; + } + + dialog_open({ + Title: cockpit.format(_("Erase disk $0"), utils.block_name(block)), + Teardown: TeardownMessage(usage), + Fields: [ CheckBoxes("erase", _("Overwrite"), { fields: [ @@ -749,8 +767,8 @@ export function format_disk(client, block) { }), ], Action: { - Title: _("Initialize"), - Danger: _("Initializing erases all data on a disk."), + Title: _("Erase"), + Danger: _("This erases all data on a disk."), wrapper: job_progress_wrapper(client, block.path), action: function (vals) { const options = { @@ -760,7 +778,7 @@ export function format_disk(client, block) { options.erase = { t: 's', v: "zero" }; return utils.teardown_active_usage(client, usage) .then(function () { - return block.Format(vals.type, options); + return block.Format("empty", options); }) .then(utils.reload_systemd); } diff --git a/pkg/storaged/pages/drive.jsx b/pkg/storaged/pages/drive.jsx index 5e6d4ee6ae61..85b747ceb839 100644 --- a/pkg/storaged/pages/drive.jsx +++ b/pkg/storaged/pages/drive.jsx @@ -30,7 +30,7 @@ import { SCard } from "../utils/card.jsx"; import { SDesc } from "../utils/desc.jsx"; import { PageChildrenCard, ParentPageLink, ActionButtons, new_page, page_type, block_location } from "../pages.jsx"; import { block_name, drive_name, format_temperature, fmt_size, fmt_size_long } from "../utils.js"; -import { format_disk } from "../content-views.jsx"; // XXX +import { format_disk, erase_disk } from "../content-views.jsx"; // XXX import { format_dialog } from "../format-dialog.jsx"; import { make_block_pages } from "../create-pages.jsx"; @@ -63,22 +63,31 @@ export function make_drive_page(parent, drive) { block.Size > 0 ? fmt_size(block.Size) : null ], actions: [ - (!is_formatted + (is_formatted && block.Size > 0 + ? { + title: _("Erase"), + action: () => erase_disk(client, block), + danger: true, + excuse: block.ReadOnly ? _("Device is read-only") : null, + tag: "content", + } + : null), + (!is_formatted && block.Size > 0 ? { title: _("Format as filesystem"), action: () => format_dialog(client, block.path), + excuse: block.ReadOnly ? _("Device is read-only") : null, tag: "content" } : null), - (block.Size > 0 - ? { - title: _("Create partition table"), - action: () => format_disk(client, block), - danger: is_formatted, - excuse: block.ReadOnly ? _("Device is read-only") : null, + (!is_formatted && block.Size > 0 + ? { + title: _("Create partition table"), + action: () => format_disk(client, block), + excuse: block.ReadOnly ? _("Device is read-only") : null, tag: "content" - } - : null) + } + : null) ], component: DrivePage, props: { drive }