Skip to content

Commit

Permalink
WIP - "create ptable" and "erase" are different dialogs now
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer committed Oct 26, 2023
1 parent c170edc commit 7080a08
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 27 deletions.
52 changes: 35 additions & 17 deletions pkg/storaged/content-views.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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: [
Expand All @@ -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 = {
Expand All @@ -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);
}
Expand Down
29 changes: 19 additions & 10 deletions pkg/storaged/pages/drive.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 }
Expand Down

0 comments on commit 7080a08

Please sign in to comment.