D2: Remote Host browser, compare and sync preview in the UI; docs and G17
Remote Host tool window (server select, tree, read-only viewer with Edit and Upload, rename, new folder, delete after its question), server tabs in the diff viewer, sync preview (uploads preselected, deletions never, extra confirmation before deleting on the server), Compare with Server in the tree menu and Tools › Deployment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7601ce12f6
commit
1c6c67194a
16 changed files with 1813 additions and 19 deletions
|
|
@ -21,7 +21,7 @@
|
|||
* are exclusive modals too. So is the branches popup (M4.5), and so are
|
||||
* "Clone Repository…" and "Manage Remotes…" (M4.10), the merge
|
||||
* dialog (M4.8) and the stash dialog (M4.9), the deployment servers
|
||||
* dialog (G17) and the theme picker (C9 T1).
|
||||
* dialog (G17), the sync preview (C9 D2) and the theme picker (C9 T1).
|
||||
*/
|
||||
import { defineStore } from "pinia";
|
||||
import { ref, watch } from "vue";
|
||||
|
|
@ -40,6 +40,7 @@ export type ModalId =
|
|||
| "clone"
|
||||
| "remotes"
|
||||
| "deployment"
|
||||
| "deploySync"
|
||||
| "merge"
|
||||
| "stash"
|
||||
| "themes";
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ export interface UiCommandSpec {
|
|||
|
||||
/** The frontend's UI commands. */
|
||||
export const UI_COMMANDS: readonly UiCommandSpec[] = [
|
||||
{ id: "deployment.browse", labelKey: "command.deployment.browse", menuPath: "Tools/Deployment/Remote Host" },
|
||||
{ id: "deployment.compare", labelKey: "command.deployment.compare", menuPath: "Tools/Deployment/Compare Current File with Server" },
|
||||
{ id: "deployment.sync", labelKey: "command.deployment.sync", menuPath: "Tools/Deployment/Sync Project with Server…" },
|
||||
{ id: "deployment.download", labelKey: "command.deployment.download", menuPath: "Tools/Deployment/Download Current File" },
|
||||
{ id: "deployment.servers", labelKey: "command.deployment.servers", menuPath: "Tools/Deployment/Servers…" },
|
||||
{ id: "deployment.showLog", labelKey: "command.deployment.showLog", menuPath: "Tools/Deployment/Deployment Log" },
|
||||
|
|
|
|||
|
|
@ -14,25 +14,43 @@
|
|||
* - `deployment.uploadProject`: the whole project;
|
||||
* - `deployment.testConnection`: opens the servers dialog and tests the
|
||||
* default server, so a host key can be checked there;
|
||||
* - `deployment.servers`: opens the servers dialog.
|
||||
* - `deployment.servers`: opens the servers dialog;
|
||||
* - `deployment.compare {path?, kind?}` (C9 D2): a file (the active one by
|
||||
* default) opens a server tab in the diff viewer; `kind: "dir"` compares
|
||||
* the folder and opens the sync preview;
|
||||
* - `deployment.sync`: compares the whole project and opens the sync
|
||||
* preview.
|
||||
* All are enabled with a project and while no job runs. It also mounts
|
||||
* the dialog.
|
||||
* the dialog and the sync preview, and resets the remote browser when the
|
||||
* project closes.
|
||||
*/
|
||||
import { LoaderCircle, X } from "@lucide/vue";
|
||||
import { computed, onBeforeUnmount, onMounted } from "vue";
|
||||
import { computed, onBeforeUnmount, onMounted, watch } from "vue";
|
||||
import { useCommandsStore } from "../../commands/store";
|
||||
import { t } from "../../i18n";
|
||||
import { useEditorStore } from "../../stores/editor";
|
||||
import { useNotificationsStore } from "../../stores/notifications";
|
||||
import { useProjectStore } from "../../stores/project";
|
||||
import DeploymentDialog from "./DeploymentDialog.vue";
|
||||
import SyncDialog from "./SyncDialog.vue";
|
||||
import { useDeployStore } from "./deploy";
|
||||
import { useRemoteBrowserStore } from "./remoteBrowser";
|
||||
|
||||
const deploy = useDeployStore();
|
||||
const commands = useCommandsStore();
|
||||
const editor = useEditorStore();
|
||||
const project = useProjectStore();
|
||||
const notifications = useNotificationsStore();
|
||||
const remoteBrowser = useRemoteBrowserStore();
|
||||
|
||||
watch(
|
||||
() => project.root,
|
||||
(root) => {
|
||||
if (root === null) {
|
||||
remoteBrowser.reset();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
/** The running job's text, or null while none runs. */
|
||||
const progressText = computed(() => {
|
||||
|
|
@ -130,6 +148,23 @@ onMounted(() => {
|
|||
},
|
||||
enabled: idle,
|
||||
}),
|
||||
commands.provide("deployment.compare", {
|
||||
run: async (params) => {
|
||||
const path = pathOf(params);
|
||||
const kind = (params as { kind?: unknown } | null)?.kind;
|
||||
if (path === null) {
|
||||
return;
|
||||
}
|
||||
await withTarget(() =>
|
||||
kind === "dir" ? remoteBrowser.compareFolders([path]) : remoteBrowser.compareFile(path),
|
||||
);
|
||||
},
|
||||
enabled: idle,
|
||||
}),
|
||||
commands.provide("deployment.sync", {
|
||||
run: () => withTarget(() => remoteBrowser.compareFolders([""])),
|
||||
enabled: idle,
|
||||
}),
|
||||
commands.provide("deployment.servers", {
|
||||
run: () => deploy.showDialog(),
|
||||
enabled: () => project.root !== null,
|
||||
|
|
@ -175,6 +210,7 @@ onBeforeUnmount(() => {
|
|||
</button>
|
||||
</span>
|
||||
<DeploymentDialog />
|
||||
<SyncDialog />
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
|
|
|||
561
ui/src/components/deploy/RemoteBrowserToolWindow.vue
Normal file
561
ui/src/components/deploy/RemoteBrowserToolWindow.vue
Normal file
|
|
@ -0,0 +1,561 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* The Remote Host tool window (C9 D2), shown in the bottom panel: the
|
||||
* chosen deployment server's folders as a tree on the left, the opened
|
||||
* file on the right.
|
||||
*
|
||||
* - **Toolbar:** the server (default first), Refresh, New Folder (in the
|
||||
* selected folder, else the root), and Compare Project (the sync
|
||||
* preview).
|
||||
* - **Rows:** a click expands a folder or opens a file. Each row offers
|
||||
* Rename and Delete; both show their own inline form, and Delete runs
|
||||
* only after its question was answered with the red button.
|
||||
* - **Viewer:** read-only first; Edit makes it editable, Upload writes it
|
||||
* back, Close drops it. Binary, missing and too large files show a
|
||||
* notice instead.
|
||||
* State lives in the remote browser store (`remoteBrowser.ts`).
|
||||
*/
|
||||
import { ChevronDown, ChevronRight, File, Folder, Pencil, RefreshCw, Trash2 } from "@lucide/vue";
|
||||
import { computed, nextTick, ref } from "vue";
|
||||
import { t } from "../../i18n";
|
||||
import { useDeployStore } from "./deploy";
|
||||
import { childPath, parentPath, useRemoteBrowserStore, type RemoteEntry } from "./remoteBrowser";
|
||||
|
||||
const browser = useRemoteBrowserStore();
|
||||
const deploy = useDeployStore();
|
||||
|
||||
/** One visible row of the tree. */
|
||||
interface Row {
|
||||
/** Browser path. */
|
||||
path: string;
|
||||
/** The entry. */
|
||||
entry: RemoteEntry;
|
||||
/** Nesting depth. */
|
||||
depth: number;
|
||||
}
|
||||
|
||||
/** The open inline form: rename, new folder or the delete question. */
|
||||
const form = ref<{ kind: "rename" | "newFolder" | "delete"; path: string; name: string } | null>(null);
|
||||
/** The inline name field. */
|
||||
const nameInput = ref<HTMLInputElement | null>(null);
|
||||
|
||||
/** The tree's rows in display order. */
|
||||
const rows = computed<Row[]>(() => {
|
||||
const out: Row[] = [];
|
||||
const walk = (dir: string, depth: number): void => {
|
||||
for (const entry of browser.dirs[dir]?.entries ?? []) {
|
||||
const path = childPath(dir, entry.name);
|
||||
out.push({ path, entry, depth });
|
||||
if (entry.isDir && browser.open.includes(path)) {
|
||||
walk(path, depth + 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
walk("", 0);
|
||||
return out;
|
||||
});
|
||||
|
||||
/** The root's listing state. */
|
||||
const root = computed(() => browser.dirs[""]);
|
||||
|
||||
/** The viewer's notice text, or null. */
|
||||
const notice = computed(() => {
|
||||
switch (browser.file?.notice) {
|
||||
case "binary":
|
||||
return t("deploy.remote.binary");
|
||||
case "tooLarge":
|
||||
return t("deploy.remote.tooLarge");
|
||||
case "missing":
|
||||
return t("deploy.remote.missing");
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Opens an inline form.
|
||||
*
|
||||
* @param kind - which form.
|
||||
* @param path - the row (or, for a new folder, the parent folder).
|
||||
* @param name - the starting name.
|
||||
*/
|
||||
async function startForm(kind: "rename" | "newFolder" | "delete", path: string, name: string): Promise<void> {
|
||||
form.value = { kind, path, name };
|
||||
await nextTick();
|
||||
nameInput.value?.focus();
|
||||
}
|
||||
|
||||
/** The folder a new folder goes in: the selected folder, else the root. */
|
||||
function newFolderParent(): string {
|
||||
const sel = browser.selected;
|
||||
if (sel === null) {
|
||||
return "";
|
||||
}
|
||||
const row = rows.value.find((r) => r.path === sel);
|
||||
return row?.entry.isDir ? sel : parentPath(sel);
|
||||
}
|
||||
|
||||
/** Submits the open form. */
|
||||
async function submit(): Promise<void> {
|
||||
const f = form.value;
|
||||
if (f === null) {
|
||||
return;
|
||||
}
|
||||
const done =
|
||||
f.kind === "rename"
|
||||
? await browser.rename(f.path, f.name)
|
||||
: f.kind === "newFolder"
|
||||
? await browser.newFolder(f.path, f.name)
|
||||
: await browser.remove(f.path);
|
||||
if (done) {
|
||||
form.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates a row: expands a folder or opens a file.
|
||||
*
|
||||
* @param row - the row.
|
||||
*/
|
||||
async function activate(row: Row): Promise<void> {
|
||||
if (row.entry.isDir) {
|
||||
await browser.toggle(row.path);
|
||||
} else {
|
||||
await browser.openFile(row.path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Chooses the server from the select.
|
||||
*
|
||||
* @param event - the change event.
|
||||
*/
|
||||
async function chooseServer(event: Event): Promise<void> {
|
||||
const value = (event.target as HTMLSelectElement).value;
|
||||
await browser.setServer(value === "" ? null : value);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section
|
||||
class="remote"
|
||||
:aria-label="t('deploy.remote.title')"
|
||||
data-test="remote-browser"
|
||||
>
|
||||
<header class="remote__toolbar">
|
||||
<select
|
||||
class="remote__select"
|
||||
:value="browser.serverId ?? ''"
|
||||
:aria-label="t('deploy.remote.server')"
|
||||
data-test="remote-server"
|
||||
@change="chooseServer"
|
||||
>
|
||||
<option value="">
|
||||
{{ t("deploy.remote.defaultServer", { name: deploy.target?.name ?? "" }) }}
|
||||
</option>
|
||||
<option
|
||||
v-for="server in deploy.servers"
|
||||
:key="server.id"
|
||||
:value="server.id"
|
||||
>
|
||||
{{ server.name }}
|
||||
</option>
|
||||
</select>
|
||||
<button
|
||||
type="button"
|
||||
class="remote__button"
|
||||
:title="t('deploy.remote.refresh')"
|
||||
:aria-label="t('deploy.remote.refresh')"
|
||||
data-test="remote-refresh"
|
||||
@click="browser.refresh()"
|
||||
>
|
||||
<RefreshCw
|
||||
:size="12"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="remote__button"
|
||||
data-test="remote-new-folder"
|
||||
@click="startForm('newFolder', newFolderParent(), '')"
|
||||
>
|
||||
{{ t("deploy.remote.newFolder") }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="remote__button"
|
||||
data-test="remote-compare"
|
||||
@click="browser.compareFolders([''])"
|
||||
>
|
||||
{{ t("deploy.remote.compareProject") }}
|
||||
</button>
|
||||
</header>
|
||||
<p
|
||||
v-if="browser.error !== null"
|
||||
class="remote__error"
|
||||
role="alert"
|
||||
data-test="remote-error"
|
||||
>
|
||||
{{ browser.error }}
|
||||
</p>
|
||||
<form
|
||||
v-if="form !== null"
|
||||
class="remote__form"
|
||||
:class="{ 'remote__form--danger': form.kind === 'delete' }"
|
||||
data-test="remote-form"
|
||||
@submit.prevent="submit"
|
||||
>
|
||||
<template v-if="form.kind === 'delete'">
|
||||
<span>{{ t("deploy.remote.deleteQuestion", { path: form.path }) }}</span>
|
||||
<button
|
||||
type="submit"
|
||||
class="remote__button remote__button--danger"
|
||||
data-test="remote-delete-confirm"
|
||||
>
|
||||
{{ t("deploy.remote.delete") }}
|
||||
</button>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span>{{ form.kind === "rename" ? t("deploy.remote.renameTo") : t("deploy.remote.newFolderIn", { path: form.path || "/" }) }}</span>
|
||||
<input
|
||||
ref="nameInput"
|
||||
v-model="form.name"
|
||||
class="remote__input"
|
||||
type="text"
|
||||
spellcheck="false"
|
||||
data-test="remote-form-name"
|
||||
>
|
||||
<button
|
||||
type="submit"
|
||||
class="remote__button"
|
||||
data-test="remote-form-ok"
|
||||
>
|
||||
{{ t("deploy.remote.ok") }}
|
||||
</button>
|
||||
</template>
|
||||
<button
|
||||
type="button"
|
||||
class="remote__button"
|
||||
@click="form = null"
|
||||
>
|
||||
{{ t("deploy.remote.cancel") }}
|
||||
</button>
|
||||
</form>
|
||||
<div class="remote__body">
|
||||
<ul
|
||||
class="remote__tree"
|
||||
role="tree"
|
||||
:aria-label="browser.serverName"
|
||||
>
|
||||
<li
|
||||
v-if="root?.loading"
|
||||
class="remote__note"
|
||||
>
|
||||
{{ t("deploy.remote.loading") }}
|
||||
</li>
|
||||
<li
|
||||
v-else-if="root?.error"
|
||||
class="remote__note remote__note--error"
|
||||
>
|
||||
{{ root.error }}
|
||||
</li>
|
||||
<li
|
||||
v-for="row in rows"
|
||||
:key="row.path"
|
||||
class="remote__row"
|
||||
:class="{ 'remote__row--selected': browser.selected === row.path }"
|
||||
role="treeitem"
|
||||
:aria-expanded="row.entry.isDir ? browser.open.includes(row.path) : undefined"
|
||||
:style="{ '--remote-depth': row.depth }"
|
||||
:data-path="row.path"
|
||||
data-test="remote-row"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="remote__name"
|
||||
@click="activate(row)"
|
||||
>
|
||||
<template v-if="row.entry.isDir">
|
||||
<ChevronDown
|
||||
v-if="browser.open.includes(row.path)"
|
||||
:size="12"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<ChevronRight
|
||||
v-else
|
||||
:size="12"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<Folder
|
||||
:size="12"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</template>
|
||||
<File
|
||||
v-else
|
||||
:size="12"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span>{{ row.entry.name }}</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="remote__action"
|
||||
:title="t('deploy.remote.rename')"
|
||||
:aria-label="t('deploy.remote.rename')"
|
||||
data-test="remote-rename"
|
||||
@click="startForm('rename', row.path, row.entry.name)"
|
||||
>
|
||||
<Pencil
|
||||
:size="12"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="remote__action"
|
||||
:title="t('deploy.remote.delete')"
|
||||
:aria-label="t('deploy.remote.delete')"
|
||||
data-test="remote-delete"
|
||||
@click="startForm('delete', row.path, '')"
|
||||
>
|
||||
<Trash2
|
||||
:size="12"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
<div
|
||||
v-if="browser.file !== null"
|
||||
class="remote__viewer"
|
||||
data-test="remote-viewer"
|
||||
>
|
||||
<header class="remote__viewer-head">
|
||||
<span class="remote__viewer-path">{{ browser.file.path }}</span>
|
||||
<span
|
||||
v-if="!browser.file.editing"
|
||||
class="remote__badge"
|
||||
>{{ t("deploy.remote.readOnly") }}</span>
|
||||
<button
|
||||
v-if="!browser.file.editing && notice === null"
|
||||
type="button"
|
||||
class="remote__button"
|
||||
data-test="remote-edit"
|
||||
@click="browser.edit()"
|
||||
>
|
||||
{{ t("deploy.remote.edit") }}
|
||||
</button>
|
||||
<button
|
||||
v-if="browser.file.editing"
|
||||
type="button"
|
||||
class="remote__button remote__button--primary"
|
||||
:disabled="browser.file.text === browser.file.original"
|
||||
data-test="remote-upload"
|
||||
@click="browser.upload()"
|
||||
>
|
||||
{{ t("deploy.remote.upload") }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="remote__button"
|
||||
data-test="remote-close-file"
|
||||
@click="browser.closeFile()"
|
||||
>
|
||||
{{ t("deploy.remote.close") }}
|
||||
</button>
|
||||
</header>
|
||||
<p
|
||||
v-if="notice !== null"
|
||||
class="remote__note"
|
||||
>
|
||||
{{ notice }}
|
||||
</p>
|
||||
<textarea
|
||||
v-else
|
||||
class="remote__text"
|
||||
:value="browser.file.text"
|
||||
:readonly="!browser.file.editing"
|
||||
spellcheck="false"
|
||||
:aria-label="browser.file.path"
|
||||
data-test="remote-text"
|
||||
@input="browser.setText(($event.target as HTMLTextAreaElement).value)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.remote {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.remote__toolbar,
|
||||
.remote__form {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex: none;
|
||||
padding: 2px 8px;
|
||||
border-bottom: 1px solid var(--lt-border);
|
||||
}
|
||||
|
||||
.remote__form--danger {
|
||||
color: var(--lt-error);
|
||||
}
|
||||
|
||||
.remote__select,
|
||||
.remote__input {
|
||||
min-width: 0;
|
||||
padding: 1px 4px;
|
||||
font: inherit;
|
||||
color: var(--lt-fg);
|
||||
background: var(--lt-editor-bg);
|
||||
border: 1px solid var(--lt-border);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.remote__button,
|
||||
.remote__action {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 1px 8px;
|
||||
font: inherit;
|
||||
color: var(--lt-fg);
|
||||
background: transparent;
|
||||
border: 1px solid var(--lt-border);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.remote__button--primary {
|
||||
border-color: var(--lt-accent);
|
||||
}
|
||||
|
||||
.remote__button--danger {
|
||||
color: var(--lt-error);
|
||||
border-color: var(--lt-error);
|
||||
}
|
||||
|
||||
.remote__button:disabled {
|
||||
color: var(--lt-fg-muted);
|
||||
}
|
||||
|
||||
.remote__action {
|
||||
padding: 1px 4px;
|
||||
border-color: transparent;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.remote__row:hover .remote__action,
|
||||
.remote__row--selected .remote__action,
|
||||
.remote__action:focus-visible {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.remote__button:focus-visible,
|
||||
.remote__action:focus-visible,
|
||||
.remote__name:focus-visible {
|
||||
outline: 1px solid var(--lt-accent);
|
||||
}
|
||||
|
||||
.remote__error,
|
||||
.remote__note--error {
|
||||
margin: 0;
|
||||
padding: 2px 8px;
|
||||
color: var(--lt-error);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.remote__body {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.remote__tree {
|
||||
flex: 0 0 40%;
|
||||
margin: 0;
|
||||
padding: 2px 0;
|
||||
list-style: none;
|
||||
overflow-y: auto;
|
||||
border-right: 1px solid var(--lt-border);
|
||||
}
|
||||
|
||||
.remote__row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding-left: calc(var(--remote-depth) * 14px + 4px);
|
||||
}
|
||||
|
||||
.remote__row--selected {
|
||||
background: var(--lt-editor-selection-bg);
|
||||
}
|
||||
|
||||
.remote__name {
|
||||
display: inline-flex;
|
||||
flex: 1;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
min-width: 0;
|
||||
padding: 1px 4px;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
color: var(--lt-fg);
|
||||
background: transparent;
|
||||
border: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.remote__note {
|
||||
margin: 0;
|
||||
padding: 2px 8px;
|
||||
color: var(--lt-fg-muted);
|
||||
}
|
||||
|
||||
.remote__viewer {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.remote__viewer-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 2px 8px;
|
||||
border-bottom: 1px solid var(--lt-border);
|
||||
}
|
||||
|
||||
.remote__viewer-path {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.remote__badge {
|
||||
color: var(--lt-fg-muted);
|
||||
font-size: var(--lt-font-size-small);
|
||||
}
|
||||
|
||||
.remote__text {
|
||||
flex: 1;
|
||||
margin: 0;
|
||||
padding: 4px 8px;
|
||||
resize: none;
|
||||
font-family: var(--lt-font-mono);
|
||||
font-size: var(--lt-font-size-editor);
|
||||
color: var(--lt-fg);
|
||||
background: var(--lt-editor-bg);
|
||||
border: none;
|
||||
outline: none;
|
||||
}
|
||||
</style>
|
||||
295
ui/src/components/deploy/SyncDialog.vue
Normal file
295
ui/src/components/deploy/SyncDialog.vue
Normal file
|
|
@ -0,0 +1,295 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* The sync preview (C9 D2): every file that differs between the compared
|
||||
* project folders and the server, with what Sync would do.
|
||||
*
|
||||
* - Only in the project, or different: upload; selected by default.
|
||||
* Different files offer Show Diff (a server tab in the diff viewer).
|
||||
* - Only on the server: delete on the server; never selected by default.
|
||||
* As soon as one is selected, a red confirmation checkbox appears and
|
||||
* Sync stays disabled until it is ticked.
|
||||
* - Escape or Close closes the preview. The dialog is an exclusive modal
|
||||
* (`deploySync`).
|
||||
*/
|
||||
import { computed, watch } from "vue";
|
||||
import { useModalsStore } from "../../commands/modals";
|
||||
import { t } from "../../i18n";
|
||||
import { useRemoteBrowserStore, type SyncItem } from "./remoteBrowser";
|
||||
|
||||
const browser = useRemoteBrowserStore();
|
||||
const modals = useModalsStore();
|
||||
|
||||
/** Whether the preview is open. */
|
||||
const isOpen = computed(() => browser.syncItems !== null);
|
||||
|
||||
/**
|
||||
* What Sync does with an item, for people.
|
||||
*
|
||||
* @param item - the item.
|
||||
*/
|
||||
function action(item: SyncItem): string {
|
||||
return item.status === "localOnly"
|
||||
? t("deploy.sync.uploadNew")
|
||||
: item.status === "different"
|
||||
? t("deploy.sync.uploadChanged")
|
||||
: t("deploy.sync.deleteOnServer");
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects or clears an item.
|
||||
*
|
||||
* @param item - the item.
|
||||
* @param event - the checkbox change.
|
||||
*/
|
||||
function toggle(item: SyncItem, event: Event): void {
|
||||
item.selected = (event.target as HTMLInputElement).checked;
|
||||
if (browser.deletions.length === 0) {
|
||||
browser.confirmDelete = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Closes the preview. */
|
||||
function close(): void {
|
||||
browser.closeSync();
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape closes.
|
||||
*
|
||||
* @param event - the key.
|
||||
*/
|
||||
function onKeydown(event: KeyboardEvent): void {
|
||||
if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
watch(isOpen, (open) => {
|
||||
if (open) {
|
||||
modals.opened("deploySync", close);
|
||||
} else {
|
||||
modals.closed("deploySync");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="isOpen"
|
||||
class="sync-dialog"
|
||||
data-test="sync-dialog"
|
||||
@mousedown.self="close"
|
||||
>
|
||||
<div
|
||||
class="sync-dialog__box"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="lt-sync-title"
|
||||
@keydown="onKeydown"
|
||||
>
|
||||
<h2
|
||||
id="lt-sync-title"
|
||||
class="sync-dialog__title"
|
||||
>
|
||||
{{ t("deploy.sync.title", { server: browser.serverName }) }}
|
||||
</h2>
|
||||
<p
|
||||
v-if="browser.syncing && (browser.syncItems ?? []).length === 0"
|
||||
class="sync-dialog__note"
|
||||
>
|
||||
{{ t("deploy.sync.comparing") }}
|
||||
</p>
|
||||
<p
|
||||
v-else-if="(browser.syncItems ?? []).length === 0 && browser.error === null"
|
||||
class="sync-dialog__note"
|
||||
data-test="sync-equal"
|
||||
>
|
||||
{{ t("deploy.sync.equal") }}
|
||||
</p>
|
||||
<ul
|
||||
v-else
|
||||
class="sync-dialog__list"
|
||||
>
|
||||
<li
|
||||
v-for="item in browser.syncItems ?? []"
|
||||
:key="item.path"
|
||||
class="sync-dialog__item"
|
||||
:class="{ 'sync-dialog__item--delete': item.status === 'remoteOnly' }"
|
||||
data-test="sync-item"
|
||||
>
|
||||
<label class="sync-dialog__check">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="item.selected"
|
||||
:data-path="item.path"
|
||||
@change="toggle(item, $event)"
|
||||
>
|
||||
<span class="sync-dialog__path">{{ item.path }}</span>
|
||||
</label>
|
||||
<span class="sync-dialog__action">{{ action(item) }}</span>
|
||||
<button
|
||||
v-if="item.status === 'different'"
|
||||
type="button"
|
||||
class="sync-dialog__button"
|
||||
data-test="sync-diff"
|
||||
@click="browser.compareFile(item.path)"
|
||||
>
|
||||
{{ t("deploy.sync.showDiff") }}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
<label
|
||||
v-if="browser.deletions.length > 0"
|
||||
class="sync-dialog__confirm"
|
||||
data-test="sync-confirm"
|
||||
>
|
||||
<input
|
||||
v-model="browser.confirmDelete"
|
||||
type="checkbox"
|
||||
>
|
||||
{{ t("deploy.sync.confirmDelete", { count: browser.deletions.length }) }}
|
||||
</label>
|
||||
<p
|
||||
v-if="browser.error !== null"
|
||||
class="sync-dialog__error"
|
||||
role="alert"
|
||||
>
|
||||
{{ browser.error }}
|
||||
</p>
|
||||
<div class="sync-dialog__buttons">
|
||||
<button
|
||||
type="button"
|
||||
class="sync-dialog__button sync-dialog__button--primary"
|
||||
:disabled="!browser.canSync"
|
||||
data-test="sync-run"
|
||||
@click="browser.runSync()"
|
||||
>
|
||||
{{ t("deploy.sync.run") }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="sync-dialog__button"
|
||||
data-test="sync-close"
|
||||
@click="close"
|
||||
>
|
||||
{{ t("deploy.dialog.close") }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.sync-dialog {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: center;
|
||||
padding-top: 8vh;
|
||||
background: color-mix(in srgb, var(--lt-bg) 50%, transparent);
|
||||
z-index: 20;
|
||||
}
|
||||
|
||||
.sync-dialog__box {
|
||||
width: min(720px, 92vw);
|
||||
max-height: 80vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
padding: 16px;
|
||||
color: var(--lt-fg);
|
||||
background: var(--lt-bg);
|
||||
border: 1px solid var(--lt-border);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.sync-dialog__title {
|
||||
margin: 0;
|
||||
font-size: var(--lt-font-size-ui);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.sync-dialog__note {
|
||||
margin: 0;
|
||||
color: var(--lt-fg-muted);
|
||||
}
|
||||
|
||||
.sync-dialog__list {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.sync-dialog__item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 3px 0;
|
||||
border-bottom: 1px solid var(--lt-border);
|
||||
}
|
||||
|
||||
.sync-dialog__item--delete .sync-dialog__action {
|
||||
color: var(--lt-error);
|
||||
}
|
||||
|
||||
.sync-dialog__check {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.sync-dialog__path {
|
||||
overflow-wrap: anywhere;
|
||||
font-family: var(--lt-font-mono);
|
||||
}
|
||||
|
||||
.sync-dialog__action {
|
||||
color: var(--lt-fg-muted);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.sync-dialog__confirm {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
color: var(--lt-error);
|
||||
}
|
||||
|
||||
.sync-dialog__error {
|
||||
margin: 0;
|
||||
color: var(--lt-error);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.sync-dialog__buttons {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.sync-dialog__button {
|
||||
padding: 4px 12px;
|
||||
font: inherit;
|
||||
color: var(--lt-fg);
|
||||
background: var(--lt-editor-bg);
|
||||
border: 1px solid var(--lt-border);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.sync-dialog__button--primary {
|
||||
border-color: var(--lt-accent);
|
||||
}
|
||||
|
||||
.sync-dialog__button:disabled {
|
||||
color: var(--lt-fg-muted);
|
||||
}
|
||||
|
||||
.sync-dialog__button:focus-visible {
|
||||
outline: 1px solid var(--lt-accent);
|
||||
}
|
||||
</style>
|
||||
549
ui/src/components/deploy/remoteBrowser.ts
Normal file
549
ui/src/components/deploy/remoteBrowser.ts
Normal file
|
|
@ -0,0 +1,549 @@
|
|||
/**
|
||||
* The remote browser, compare and sync (C9 D2), through the engine's
|
||||
* `deploy.browse`, `readRemote`, `writeRemote`, `renameRemote`,
|
||||
* `mkdirRemote`, `deleteRemote`, `compare` and `sync` commands.
|
||||
*
|
||||
* - **Tree:** folders load when expanded; paths are relative to the
|
||||
* server's root (`""` is the root). The server is the default one unless
|
||||
* one is chosen.
|
||||
* - **Files** open in the tool window's viewer, read-only first; Edit
|
||||
* makes the text editable and Upload writes it back to the server.
|
||||
* - **Delete** happens only after the row's own question was answered;
|
||||
* only then is `confirm: true` sent.
|
||||
* - **Compare:** a file opens a server tab in the diff viewer; a folder (or
|
||||
* the project) opens the sync preview with every differing file.
|
||||
* Uploads are preselected; deletions on the server never are, and Sync
|
||||
* with deletions needs the extra confirmation checkbox, which is what
|
||||
* sends `confirmDelete: true`.
|
||||
*/
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref, shallowRef } from "vue";
|
||||
import { runWaiting, type JsonValue } from "../../ipc";
|
||||
import { useNotificationsStore } from "../../stores/notifications";
|
||||
import { useDiffStore } from "../vcs/diff/diff";
|
||||
import { filesText, useDeployStore } from "./deploy";
|
||||
|
||||
/** Most entries kept from one listing. */
|
||||
export const MAX_ENTRIES = 5000;
|
||||
|
||||
/** One entry of a server folder. */
|
||||
export interface RemoteEntry {
|
||||
/** The name. */
|
||||
name: string;
|
||||
/** Whether it is a folder. */
|
||||
isDir: boolean;
|
||||
/** Its size, when known. */
|
||||
size: number | null;
|
||||
}
|
||||
|
||||
/** A loaded (or loading) server folder. */
|
||||
export interface DirState {
|
||||
/** Its entries, folders first. */
|
||||
entries: RemoteEntry[];
|
||||
/** Whether the listing runs. */
|
||||
loading: boolean;
|
||||
/** Why it failed, or null. */
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
/** The file shown in the viewer. */
|
||||
export interface RemoteFile {
|
||||
/** Its browser path. */
|
||||
path: string;
|
||||
/** The text being shown or edited. */
|
||||
text: string;
|
||||
/** The text as read from the server. */
|
||||
original: string;
|
||||
/** Whether the text can be edited. */
|
||||
editing: boolean;
|
||||
/** Why it cannot be shown, or null. */
|
||||
notice: string | null;
|
||||
}
|
||||
|
||||
/** One differing file of the sync preview. */
|
||||
export interface SyncItem {
|
||||
/** Project-relative path. */
|
||||
path: string;
|
||||
/** How it differs. */
|
||||
status: "localOnly" | "remoteOnly" | "different";
|
||||
/** Its local size. */
|
||||
localSize: number | null;
|
||||
/** Its size on the server. */
|
||||
remoteSize: number | null;
|
||||
/** Whether Sync acts on it (upload, or delete for `remoteOnly`). */
|
||||
selected: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Joins a browser folder and a name.
|
||||
*
|
||||
* @param dir - the folder, "" for the root.
|
||||
* @param name - the entry's name.
|
||||
*/
|
||||
export function childPath(dir: string, name: string): string {
|
||||
return dir === "" ? name : `${dir}/${name}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* The folder part of a browser path.
|
||||
*
|
||||
* @param path - the path.
|
||||
*/
|
||||
export function parentPath(path: string): string {
|
||||
const slash = path.lastIndexOf("/");
|
||||
return slash < 0 ? "" : path.slice(0, slash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a name typed for a new entry is usable.
|
||||
*
|
||||
* @param name - the typed name.
|
||||
*/
|
||||
export function validName(name: string): boolean {
|
||||
const n = name.trim();
|
||||
if (n === "" || n === "." || n === ".." || n.includes("/") || n.includes("\\")) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < n.length; i += 1) {
|
||||
if (n.charCodeAt(i) < 0x20) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a `deploy.browse` answer; malformed entries are dropped.
|
||||
*
|
||||
* @param raw - untrusted.
|
||||
*/
|
||||
export function toEntries(raw: unknown): RemoteEntry[] {
|
||||
const list = typeof raw === "object" && raw !== null ? (raw as Record<string, unknown>).entries : null;
|
||||
if (!Array.isArray(list)) {
|
||||
return [];
|
||||
}
|
||||
const out: RemoteEntry[] = [];
|
||||
for (const item of (list as unknown[]).slice(0, MAX_ENTRIES)) {
|
||||
const e = typeof item === "object" && item !== null ? (item as Record<string, unknown>) : {};
|
||||
if (typeof e.name !== "string" || !validName(e.name)) {
|
||||
continue;
|
||||
}
|
||||
out.push({
|
||||
name: e.name,
|
||||
isDir: e.isDir === true,
|
||||
size: typeof e.size === "number" && Number.isFinite(e.size) ? e.size : null,
|
||||
});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a `deploy.compare` answer into preview items: uploads selected,
|
||||
* deletions not.
|
||||
*
|
||||
* @param raw - untrusted.
|
||||
*/
|
||||
export function toSyncItems(raw: unknown): SyncItem[] {
|
||||
const list = typeof raw === "object" && raw !== null ? (raw as Record<string, unknown>).differences : null;
|
||||
if (!Array.isArray(list)) {
|
||||
return [];
|
||||
}
|
||||
const out: SyncItem[] = [];
|
||||
for (const item of (list as unknown[]).slice(0, MAX_ENTRIES)) {
|
||||
const d = typeof item === "object" && item !== null ? (item as Record<string, unknown>) : {};
|
||||
const status = d.status;
|
||||
if (typeof d.path !== "string" || (status !== "localOnly" && status !== "remoteOnly" && status !== "different")) {
|
||||
continue;
|
||||
}
|
||||
out.push({
|
||||
path: d.path,
|
||||
status,
|
||||
localSize: typeof d.localSize === "number" ? d.localSize : null,
|
||||
remoteSize: typeof d.remoteSize === "number" ? d.remoteSize : null,
|
||||
selected: status !== "remoteOnly",
|
||||
});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** The remote browser store. */
|
||||
export const useRemoteBrowserStore = defineStore("remoteBrowser", () => {
|
||||
const notifications = useNotificationsStore();
|
||||
const deploy = useDeployStore();
|
||||
|
||||
/** Whether the tool window is shown. */
|
||||
const visible = ref(false);
|
||||
/** Whether the bottom panel is expanded while it is shown. */
|
||||
const expanded = ref(true);
|
||||
/** The chosen server, or null for the default one. */
|
||||
const serverId = ref<string | null>(null);
|
||||
/** Loaded folders by browser path. */
|
||||
const dirs = ref<Record<string, DirState>>({});
|
||||
/** Expanded folders. */
|
||||
const open = ref<string[]>([]);
|
||||
/** The selected path, or null. */
|
||||
const selected = ref<string | null>(null);
|
||||
/** The file in the viewer, or null. */
|
||||
const file = shallowRef<RemoteFile | null>(null);
|
||||
/** The sync preview's items; null while the preview is closed. */
|
||||
const syncItems = ref<SyncItem[] | null>(null);
|
||||
/** The paths the preview compared. */
|
||||
const syncPaths = ref<string[]>([]);
|
||||
/** Whether the user confirmed the deletions of the preview. */
|
||||
const confirmDelete = ref(false);
|
||||
/** Whether compare or sync runs. */
|
||||
const syncing = ref(false);
|
||||
/** Why the last browser or preview action failed, or null. */
|
||||
const error = ref<string | null>(null);
|
||||
|
||||
/** The server's name as shown. */
|
||||
const serverName = computed(() => {
|
||||
const id = serverId.value ?? deploy.defaultServer;
|
||||
return deploy.servers.find((s) => s.id === id)?.name ?? "";
|
||||
});
|
||||
/** Deletions the preview would make. */
|
||||
const deletions = computed(() => (syncItems.value ?? []).filter((i) => i.selected && i.status === "remoteOnly"));
|
||||
/** Whether Sync may run now. */
|
||||
const canSync = computed(
|
||||
() =>
|
||||
(syncItems.value ?? []).some((i) => i.selected) &&
|
||||
(deletions.value.length === 0 || confirmDelete.value) &&
|
||||
!syncing.value,
|
||||
);
|
||||
|
||||
/** The params every command gets: the chosen server. */
|
||||
function base(): Record<string, JsonValue> {
|
||||
return serverId.value === null ? {} : { id: serverId.value };
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs one browser command; a failure lands in {@link error}.
|
||||
*
|
||||
* @param command - the command.
|
||||
* @param params - its params (the server is added).
|
||||
* @returns its value, or null when it failed.
|
||||
*/
|
||||
async function call(command: string, params: Record<string, JsonValue>): Promise<JsonValue | null> {
|
||||
const result = await runWaiting(command, { ...base(), ...params });
|
||||
if (!result.ok) {
|
||||
error.value = result.error.message;
|
||||
return null;
|
||||
}
|
||||
error.value = null;
|
||||
return result.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads (or reloads) a folder.
|
||||
*
|
||||
* @param path - the browser folder.
|
||||
*/
|
||||
async function loadDir(path: string): Promise<void> {
|
||||
dirs.value = { ...dirs.value, [path]: { entries: dirs.value[path]?.entries ?? [], loading: true, error: null } };
|
||||
const result = await runWaiting("deploy.browse", { ...base(), path });
|
||||
dirs.value = {
|
||||
...dirs.value,
|
||||
[path]: result.ok
|
||||
? { entries: toEntries(result.value), loading: false, error: null }
|
||||
: { entries: [], loading: false, error: result.error.message },
|
||||
};
|
||||
}
|
||||
|
||||
/** Shows the tool window and reads the root. */
|
||||
async function show(): Promise<void> {
|
||||
visible.value = true;
|
||||
expanded.value = true;
|
||||
if (deploy.servers.length === 0) {
|
||||
await deploy.load();
|
||||
}
|
||||
if (dirs.value[""] === undefined) {
|
||||
await loadDir("");
|
||||
}
|
||||
}
|
||||
|
||||
/** Hides the tool window. */
|
||||
function hide(): void {
|
||||
visible.value = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Chooses the server and reads its root.
|
||||
*
|
||||
* @param id - the server, or null for the default one.
|
||||
*/
|
||||
async function setServer(id: string | null): Promise<void> {
|
||||
serverId.value = id;
|
||||
dirs.value = {};
|
||||
open.value = [];
|
||||
file.value = null;
|
||||
selected.value = null;
|
||||
await loadDir("");
|
||||
}
|
||||
|
||||
/** Reads every loaded folder again. */
|
||||
async function refresh(): Promise<void> {
|
||||
const loaded = ["", ...open.value];
|
||||
dirs.value = {};
|
||||
for (const path of loaded) {
|
||||
await loadDir(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Expands or collapses a folder.
|
||||
*
|
||||
* @param path - the browser folder.
|
||||
*/
|
||||
async function toggle(path: string): Promise<void> {
|
||||
selected.value = path;
|
||||
if (open.value.includes(path)) {
|
||||
open.value = open.value.filter((p) => p !== path && !p.startsWith(`${path}/`));
|
||||
return;
|
||||
}
|
||||
open.value = [...open.value, path];
|
||||
if (dirs.value[path] === undefined) {
|
||||
await loadDir(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a server file in the viewer, read-only.
|
||||
*
|
||||
* @param path - the browser path.
|
||||
*/
|
||||
async function openFile(path: string): Promise<void> {
|
||||
selected.value = path;
|
||||
const value = await call("deploy.readRemote", { remotePath: path });
|
||||
if (value === null) {
|
||||
return;
|
||||
}
|
||||
const v = typeof value === "object" && !Array.isArray(value) ? value : {};
|
||||
const text = typeof v.text === "string" ? v.text : null;
|
||||
const notice = v.tooLarge === true ? "tooLarge" : v.binary === true ? "binary" : text === null ? "missing" : null;
|
||||
file.value = { path, text: text ?? "", original: text ?? "", editing: false, notice };
|
||||
}
|
||||
|
||||
/** Makes the viewer's text editable. */
|
||||
function edit(): void {
|
||||
if (file.value && file.value.notice === null) {
|
||||
file.value = { ...file.value, editing: true };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the viewer's text while editing.
|
||||
*
|
||||
* @param text - the new text.
|
||||
*/
|
||||
function setText(text: string): void {
|
||||
if (file.value?.editing) {
|
||||
file.value = { ...file.value, text };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the edited text to the server.
|
||||
*
|
||||
* @returns whether it was uploaded.
|
||||
*/
|
||||
async function upload(): Promise<boolean> {
|
||||
const f = file.value;
|
||||
if (!f?.editing) {
|
||||
return false;
|
||||
}
|
||||
const value = await call("deploy.writeRemote", { remotePath: f.path, text: f.text });
|
||||
if (value === null) {
|
||||
return false;
|
||||
}
|
||||
file.value = { ...f, original: f.text, editing: false };
|
||||
notifications.notify({ level: "info", messageKey: "notification.deploy.remoteSaved", params: { path: f.path } });
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Closes the viewer (an unsaved edit is dropped). */
|
||||
function closeFile(): void {
|
||||
file.value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renames an entry within its folder.
|
||||
*
|
||||
* @param path - the browser path.
|
||||
* @param name - the new name.
|
||||
*/
|
||||
async function rename(path: string, name: string): Promise<boolean> {
|
||||
if (!validName(name)) {
|
||||
return false;
|
||||
}
|
||||
const to = childPath(parentPath(path), name.trim());
|
||||
const value = await call("deploy.renameRemote", { from: path, to });
|
||||
if (value === null) {
|
||||
return false;
|
||||
}
|
||||
await loadDir(parentPath(path));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a folder.
|
||||
*
|
||||
* @param parent - the browser folder it goes in.
|
||||
* @param name - its name.
|
||||
*/
|
||||
async function newFolder(parent: string, name: string): Promise<boolean> {
|
||||
if (!validName(name)) {
|
||||
return false;
|
||||
}
|
||||
const value = await call("deploy.mkdirRemote", { path: childPath(parent, name.trim()) });
|
||||
if (value === null) {
|
||||
return false;
|
||||
}
|
||||
await loadDir(parent);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an entry on the server; callers ask first.
|
||||
*
|
||||
* @param path - the browser path.
|
||||
*/
|
||||
async function remove(path: string): Promise<boolean> {
|
||||
const value = await call("deploy.deleteRemote", { path, confirm: true });
|
||||
if (value === null) {
|
||||
return false;
|
||||
}
|
||||
if (file.value?.path === path || file.value?.path.startsWith(`${path}/`)) {
|
||||
file.value = null;
|
||||
}
|
||||
open.value = open.value.filter((p) => p !== path && !p.startsWith(`${path}/`));
|
||||
await loadDir(parentPath(path));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares one project file with the server in the diff viewer.
|
||||
*
|
||||
* @param path - project-relative path.
|
||||
*/
|
||||
async function compareFile(path: string): Promise<void> {
|
||||
await useDiffStore().openRemote(path, { serverId: serverId.value, server: serverName.value });
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares project folders with the server and opens the sync preview.
|
||||
*
|
||||
* @param paths - project-relative folders, "" for the whole project.
|
||||
*/
|
||||
async function compareFolders(paths: string[]): Promise<void> {
|
||||
if (deploy.servers.length === 0) {
|
||||
await deploy.load();
|
||||
}
|
||||
syncPaths.value = paths;
|
||||
confirmDelete.value = false;
|
||||
syncItems.value = [];
|
||||
syncing.value = true;
|
||||
try {
|
||||
const value = await call("deploy.compare", { paths });
|
||||
syncItems.value = value === null ? [] : toSyncItems(value);
|
||||
} finally {
|
||||
syncing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Closes the sync preview. */
|
||||
function closeSync(): void {
|
||||
syncItems.value = null;
|
||||
error.value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the previewed sync: uploads the selected local and differing
|
||||
* files and, only with {@link confirmDelete}, deletes the selected
|
||||
* server-only files.
|
||||
*
|
||||
* @returns whether it ran without failures.
|
||||
*/
|
||||
async function runSync(): Promise<boolean> {
|
||||
const items = syncItems.value ?? [];
|
||||
const upload = items.filter((i) => i.selected && i.status !== "remoteOnly").map((i) => i.path);
|
||||
const del = deletions.value.map((i) => i.path);
|
||||
if (!canSync.value) {
|
||||
return false;
|
||||
}
|
||||
syncing.value = true;
|
||||
try {
|
||||
const params: Record<string, JsonValue> = { upload, delete: del };
|
||||
if (del.length > 0) {
|
||||
params.confirmDelete = true;
|
||||
}
|
||||
const value = await call("deploy.sync", params);
|
||||
if (value === null) {
|
||||
return false;
|
||||
}
|
||||
const v = typeof value === "object" && !Array.isArray(value) ? value : {};
|
||||
const count = (key: string): number => {
|
||||
const n = v[key];
|
||||
return typeof n === "number" ? n : 0;
|
||||
};
|
||||
notifications.notify({
|
||||
level: count("failed") > 0 ? "warning" : "info",
|
||||
messageKey: "notification.deploy.synced",
|
||||
params: { files: filesText(count("files")), deleted: filesText(count("deleted")), server: serverName.value },
|
||||
});
|
||||
syncItems.value = null;
|
||||
if (visible.value) {
|
||||
await refresh();
|
||||
}
|
||||
return count("failed") === 0;
|
||||
} finally {
|
||||
syncing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Forgets everything when the project closes. */
|
||||
function reset(): void {
|
||||
dirs.value = {};
|
||||
open.value = [];
|
||||
file.value = null;
|
||||
selected.value = null;
|
||||
syncItems.value = null;
|
||||
serverId.value = null;
|
||||
}
|
||||
|
||||
return {
|
||||
visible,
|
||||
expanded,
|
||||
serverId,
|
||||
dirs,
|
||||
open,
|
||||
selected,
|
||||
file,
|
||||
syncItems,
|
||||
syncPaths,
|
||||
confirmDelete,
|
||||
syncing,
|
||||
error,
|
||||
serverName,
|
||||
deletions,
|
||||
canSync,
|
||||
loadDir,
|
||||
show,
|
||||
hide,
|
||||
setServer,
|
||||
refresh,
|
||||
toggle,
|
||||
openFile,
|
||||
edit,
|
||||
setText,
|
||||
upload,
|
||||
closeFile,
|
||||
rename,
|
||||
newFolder,
|
||||
remove,
|
||||
compareFile,
|
||||
compareFolders,
|
||||
closeSync,
|
||||
runSync,
|
||||
reset,
|
||||
};
|
||||
});
|
||||
|
|
@ -17,7 +17,8 @@
|
|||
*
|
||||
* The bottom panel ({@link BottomPanel}) holds the Find, Terminal and
|
||||
* Problems tool windows (and the Deployment log, G17, which appears with
|
||||
* `deployment.showLog`), as tabs in its header while more than one is
|
||||
* `deployment.showLog`, and the Remote Host browser, C9 D2, with
|
||||
* `deployment.browse`), as tabs in its header while more than one is
|
||||
* shown. Find appears with the UI command `find.open` (`Mod+Alt+F`),
|
||||
* Terminal with `terminal.open` (`Mod+Shift+T`, M3.6), Problems with
|
||||
* `problems.open` (`Mod+Alt+P`, M3.3); all are supplied here so they work
|
||||
|
|
@ -62,6 +63,8 @@ import LogToolWindow from "../vcs/log/LogToolWindow.vue";
|
|||
import { SHOW_HISTORY_COMMAND, SHOW_LOG_COMMAND, useLogStore } from "../vcs/log/log";
|
||||
import StashDialog from "../vcs/stash/StashDialog.vue";
|
||||
import DeploymentLogToolWindow from "../deploy/DeploymentLogToolWindow.vue";
|
||||
import RemoteBrowserToolWindow from "../deploy/RemoteBrowserToolWindow.vue";
|
||||
import { useRemoteBrowserStore } from "../deploy/remoteBrowser";
|
||||
import { useDeployStore } from "../deploy/deploy";
|
||||
import { SHOW_COMMIT_COMMAND, TOGGLE_BLAME_COMMAND, setCommitOpener, toggleBlame } from "../editor/blame";
|
||||
import { SHOW_CHUNK_COMMAND, openChunkPopup } from "../editor/chunkPopup";
|
||||
|
|
@ -117,11 +120,12 @@ const nav = useNavStore();
|
|||
const changes = useChangesStore();
|
||||
const vcsLog = useLogStore();
|
||||
const deploy = useDeployStore();
|
||||
const remoteBrowser = useRemoteBrowserStore();
|
||||
const editor = useEditorStore();
|
||||
const project = useProjectStore();
|
||||
|
||||
/** Tool windows of the bottom panel. */
|
||||
type BottomTool = "find" | "terminal" | "problems" | "references" | "changes" | "log" | "deployment";
|
||||
type BottomTool = "find" | "terminal" | "problems" | "references" | "changes" | "log" | "deployment" | "remote";
|
||||
/** The bottom tool window last chosen. */
|
||||
const bottomTool = ref<BottomTool>("find");
|
||||
/** Bottom tool windows that are shown, in tab order. */
|
||||
|
|
@ -134,6 +138,7 @@ const bottomTools = computed(() => {
|
|||
if (changes.visible) tools.push({ id: "changes", title: t("vcs.changes.toolWindow.title") });
|
||||
if (vcsLog.visible) tools.push({ id: "log", title: t("vcs.log.toolWindow.title") });
|
||||
if (deploy.visible) tools.push({ id: "deployment", title: t("deploy.log.title") });
|
||||
if (remoteBrowser.visible) tools.push({ id: "remote", title: t("deploy.remote.title") });
|
||||
return tools;
|
||||
});
|
||||
/** The active bottom tool window: the chosen one if shown, else the first. */
|
||||
|
|
@ -155,7 +160,9 @@ const bottomStore = computed(() =>
|
|||
? vcsLog
|
||||
: bottomActive.value === "deployment"
|
||||
? deploy
|
||||
: find,
|
||||
: bottomActive.value === "remote"
|
||||
? remoteBrowser
|
||||
: find,
|
||||
);
|
||||
/** Expansion of the panel, kept per tool window by its store. */
|
||||
const bottomOpen = computed({
|
||||
|
|
@ -178,7 +185,8 @@ function chooseBottom(id: string): void {
|
|||
id === "references" ||
|
||||
id === "changes" ||
|
||||
id === "log" ||
|
||||
id === "deployment"
|
||||
id === "deployment" ||
|
||||
id === "remote"
|
||||
) {
|
||||
bottomTool.value = id;
|
||||
}
|
||||
|
|
@ -288,6 +296,13 @@ onMounted(() => {
|
|||
},
|
||||
enabled: () => project.root !== null && activeView() !== null,
|
||||
}),
|
||||
commands.provide("deployment.browse", {
|
||||
run: () => {
|
||||
bottomTool.value = "remote";
|
||||
return remoteBrowser.show();
|
||||
},
|
||||
enabled: () => project.root !== null,
|
||||
}),
|
||||
commands.provide("deployment.showLog", {
|
||||
run: () => {
|
||||
bottomTool.value = "deployment";
|
||||
|
|
@ -395,6 +410,10 @@ onBeforeUnmount(() => {
|
|||
v-if="deploy.visible"
|
||||
v-show="bottomActive === 'deployment'"
|
||||
/>
|
||||
<RemoteBrowserToolWindow
|
||||
v-if="remoteBrowser.visible"
|
||||
v-show="bottomActive === 'remote'"
|
||||
/>
|
||||
</BottomPanel>
|
||||
<StatusBar />
|
||||
<StashDialog />
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@
|
|||
* The project tree's context menu (M4.3). For a file: Open, Show Diff
|
||||
* (`vcs.showDiff {path}`) and Show History (`vcs.showHistory {path}`,
|
||||
* M4.6), the Git items dimmed while their command is disabled. For a file
|
||||
* and a folder: Upload to Server and Download from Server
|
||||
* (`deployment.upload` / `deployment.download {path}`, G17), dimmed while
|
||||
* and a folder: Upload to Server, Compare with Server (a diff for a file,
|
||||
* the sync preview for a folder, C9 D2) and Download from Server
|
||||
* (`deployment.upload` / `deployment.compare` / `deployment.download
|
||||
* {path}`, G17), dimmed while
|
||||
* no project is open or a deployment job runs.
|
||||
*
|
||||
* Follows the WAI-ARIA menu pattern: it takes the focus when it opens,
|
||||
|
|
@ -65,6 +67,12 @@ const deployItems = computed<MenuItem[]>(() => [
|
|||
enabled: commands.isEnabled("deployment.upload"),
|
||||
run: () => commands.execute("deployment.upload", { path: props.path }),
|
||||
},
|
||||
{
|
||||
id: "compareServer",
|
||||
label: t("project.tree.menu.compareServer"),
|
||||
enabled: commands.isEnabled("deployment.compare"),
|
||||
run: () => commands.execute("deployment.compare", { path: props.path, kind: props.kind ?? "file" }),
|
||||
},
|
||||
{
|
||||
id: "download",
|
||||
label: t("project.tree.menu.download"),
|
||||
|
|
|
|||
|
|
@ -99,6 +99,9 @@ const caption = computed(() => {
|
|||
if (tab.commit) {
|
||||
return t("vcs.diff.captionCommit", { path: tab.path, hash: tab.commit.hash.slice(0, SHORT_HASH) });
|
||||
}
|
||||
if (tab.remote) {
|
||||
return t("vcs.diff.captionRemote", { path: tab.path, server: tab.remote.server });
|
||||
}
|
||||
return refFor(tab.staged) === "HEAD"
|
||||
? t("vcs.diff.captionHead", { path: tab.path })
|
||||
: t("vcs.diff.captionIndex", { path: tab.path });
|
||||
|
|
@ -275,7 +278,7 @@ onBeforeUnmount(() => {
|
|||
{{ caption }}
|
||||
</div>
|
||||
<div
|
||||
v-if="diff.activeTab && !diff.activeTab.commit && diff.activeContent?.phase === 'ready' && diff.activeContent.bufferId !== null"
|
||||
v-if="diff.activeTab && !diff.activeTab.commit && !diff.activeTab.remote && diff.activeContent?.phase === 'ready' && diff.activeContent.bufferId !== null"
|
||||
class="diff-view__hint"
|
||||
data-test="diff-chunk-hint"
|
||||
>
|
||||
|
|
|
|||
|
|
@ -31,6 +31,11 @@
|
|||
* (right, `git.showAt {path, rev: hash}`) with its first parent (left, the
|
||||
* old path of a rename). Both sides are read-only texts; nothing is
|
||||
* re-read on `gitChanged` (commits do not change).
|
||||
* - **Server tabs (C9 D2):** {@link openRemote} compares a file on a
|
||||
* deployment server (left, read-only, `deploy.readRemote {path, id?}`,
|
||||
* which answers like `git.show`) with the working copy (right, the
|
||||
* ordinary buffer). Nothing is re-read on `gitChanged`; reopening the
|
||||
* tab reads the server again.
|
||||
* - **Untrusted input:** `git.show` results are checked field by field.
|
||||
*/
|
||||
import { defineStore } from "pinia";
|
||||
|
|
@ -83,6 +88,26 @@ export interface DiffTab {
|
|||
name: string;
|
||||
/** For a commit tab: what it compares; absent for working-copy diffs. */
|
||||
commit?: DiffCommit;
|
||||
/** For a server tab: the deployment server compared with. */
|
||||
remote?: DiffRemote;
|
||||
}
|
||||
|
||||
/** The server a server tab compares the working copy with. */
|
||||
export interface DiffRemote {
|
||||
/** The server's id, or null for the default server. */
|
||||
serverId: string | null;
|
||||
/** Its name, for the caption. */
|
||||
server: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* The key of a server tab.
|
||||
*
|
||||
* @param path - project-relative path.
|
||||
* @param serverId - the server, or null for the default one.
|
||||
*/
|
||||
export function remoteDiffKey(path: string, serverId: string | null): string {
|
||||
return `remote:${serverId ?? ""}:${path}`;
|
||||
}
|
||||
|
||||
/** What a diff tab shows. */
|
||||
|
|
@ -282,6 +307,17 @@ export const useDiffStore = defineStore("diff", () => {
|
|||
* @returns the checked result, or the error text.
|
||||
*/
|
||||
async function readLeft(tab: DiffTab): Promise<ShowResult | string> {
|
||||
if (tab.remote) {
|
||||
const params: Record<string, JsonValue> = { path: tab.path };
|
||||
if (tab.remote.serverId !== null) {
|
||||
params.id = tab.remote.serverId;
|
||||
}
|
||||
const remote = await runWaiting("deploy.readRemote", params);
|
||||
if (!remote.ok) {
|
||||
return remote.error.message;
|
||||
}
|
||||
return toShowResult(remote.value) ?? t("common.error.unexpectedResult", { command: "deploy.readRemote" });
|
||||
}
|
||||
const result = await runWaiting("git.show", { path: tab.path, ref: refFor(tab.staged) });
|
||||
if (!result.ok) {
|
||||
return result.error.message;
|
||||
|
|
@ -448,6 +484,24 @@ export const useDiffStore = defineStore("diff", () => {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens (or activates and reloads) the comparison of a file with its
|
||||
* copy on a deployment server.
|
||||
*
|
||||
* @param path - project-relative path.
|
||||
* @param remote - the server.
|
||||
*/
|
||||
async function openRemote(path: string, remote: DiffRemote): Promise<void> {
|
||||
const key = remoteDiffKey(path, remote.serverId);
|
||||
let tab = tabs.value.find((t) => t.key === key);
|
||||
if (!tab) {
|
||||
tab = { key, path, staged: false, name: baseName(path), remote };
|
||||
tabs.value.push(tab);
|
||||
}
|
||||
activate(key);
|
||||
await load(tab);
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-reads the left side of every loaded text tab; a changed text
|
||||
* replaces the left document (`gitChanged`).
|
||||
|
|
@ -456,7 +510,7 @@ export const useDiffStore = defineStore("diff", () => {
|
|||
await Promise.all(
|
||||
tabs.value.map(async (tab) => {
|
||||
const before = contents.value[tab.key];
|
||||
if (before?.phase !== "ready" || tab.commit) {
|
||||
if (before?.phase !== "ready" || tab.commit || tab.remote) {
|
||||
return;
|
||||
}
|
||||
const generation = generations.get(tab.key);
|
||||
|
|
@ -569,6 +623,7 @@ export const useDiffStore = defineStore("diff", () => {
|
|||
deactivate,
|
||||
open,
|
||||
openAtCommit,
|
||||
openRemote,
|
||||
showDiff,
|
||||
refreshLeft,
|
||||
close,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
{
|
||||
"app.statusBar.version": "{name} {version}",
|
||||
"command.deployment.browse": "Remote Host",
|
||||
"command.deployment.compare": "Compare Current File with Server",
|
||||
"command.deployment.download": "Download Current File from Server",
|
||||
"command.deployment.servers": "Deployment Servers…",
|
||||
"command.deployment.showLog": "Deployment Log",
|
||||
"command.deployment.sync": "Sync Project with Server…",
|
||||
"command.deployment.testConnection": "Test Deployment Connection",
|
||||
"command.deployment.upload": "Upload Current File to Server",
|
||||
"command.deployment.uploadProject": "Upload Project to Server",
|
||||
|
|
@ -135,6 +138,36 @@
|
|||
"deploy.operation.upload": "Uploading",
|
||||
"deploy.progress.files": "{operation} {done}/{total} · {server}",
|
||||
"deploy.progress.short": "{operation} · {server}",
|
||||
"deploy.remote.binary": "This file is not text, so it is not shown.",
|
||||
"deploy.remote.cancel": "Cancel",
|
||||
"deploy.remote.close": "Close",
|
||||
"deploy.remote.compareProject": "Compare Project…",
|
||||
"deploy.remote.defaultServer": "Default server ({name})",
|
||||
"deploy.remote.delete": "Delete on Server",
|
||||
"deploy.remote.deleteQuestion": "Delete {path} on the server, with everything inside it? This cannot be undone.",
|
||||
"deploy.remote.edit": "Edit",
|
||||
"deploy.remote.loading": "Loading…",
|
||||
"deploy.remote.missing": "This file no longer exists on the server.",
|
||||
"deploy.remote.newFolder": "New Folder",
|
||||
"deploy.remote.newFolderIn": "New folder in {path}:",
|
||||
"deploy.remote.ok": "OK",
|
||||
"deploy.remote.readOnly": "read-only",
|
||||
"deploy.remote.refresh": "Refresh",
|
||||
"deploy.remote.rename": "Rename",
|
||||
"deploy.remote.renameTo": "New name:",
|
||||
"deploy.remote.server": "Server",
|
||||
"deploy.remote.title": "Remote Host",
|
||||
"deploy.remote.tooLarge": "This file is larger than 4 MiB, so it is not shown.",
|
||||
"deploy.remote.upload": "Upload",
|
||||
"deploy.sync.comparing": "Comparing with the server…",
|
||||
"deploy.sync.confirmDelete": "I understand that {count} files will be deleted on the server.",
|
||||
"deploy.sync.deleteOnServer": "delete on the server",
|
||||
"deploy.sync.equal": "The project and the server are the same.",
|
||||
"deploy.sync.run": "Sync",
|
||||
"deploy.sync.showDiff": "Show Diff",
|
||||
"deploy.sync.title": "Sync with {server}",
|
||||
"deploy.sync.uploadChanged": "upload (changed)",
|
||||
"deploy.sync.uploadNew": "upload (new)",
|
||||
"editor.assist.kind.class": "Class",
|
||||
"editor.assist.kind.color": "Colour",
|
||||
"editor.assist.kind.constant": "Constant",
|
||||
|
|
@ -258,6 +291,8 @@
|
|||
"notification.deploy.downloaded": "Downloaded {files} from {server}.",
|
||||
"notification.deploy.noServer": "No default deployment server yet. Add one, or choose the default.",
|
||||
"notification.deploy.partly": "Transferred {files}, but {failed} failed ({server}); see the Deployment log.",
|
||||
"notification.deploy.remoteSaved": "Uploaded {path}.",
|
||||
"notification.deploy.synced": "Synced with {server}: uploaded {files}, deleted {deleted}.",
|
||||
"notification.deploy.uploadFailed": "Upload failed: {reason}",
|
||||
"notification.deploy.uploadOnSaveFailed": "Upload on save to {server} failed: {error}",
|
||||
"notification.deploy.uploaded": "Uploaded {files} to {server}.",
|
||||
|
|
@ -344,6 +379,7 @@
|
|||
"project.openFolder": "Open Folder…",
|
||||
"project.toolWindow.title": "Project",
|
||||
"project.tree.loading": "Loading…",
|
||||
"project.tree.menu.compareServer": "Compare with Server",
|
||||
"project.tree.menu.download": "Download from Server",
|
||||
"project.tree.menu.label": "Actions for {name}",
|
||||
"project.tree.menu.open": "Open",
|
||||
|
|
@ -521,6 +557,7 @@
|
|||
"vcs.diff.captionCommit": "{path}: before (left) and after (right) commit {hash}",
|
||||
"vcs.diff.captionHead": "{path}: last commit (left) and working copy (right)",
|
||||
"vcs.diff.captionIndex": "{path}: staged version (left) and working copy (right)",
|
||||
"vcs.diff.captionRemote": "{path}: on {server} (left) and working copy (right)",
|
||||
"vcs.diff.chunkHint": "Click a change marker in the gutter to stage, unstage or revert that chunk.",
|
||||
"vcs.diff.closeTab": "Close the diff of {name}",
|
||||
"vcs.diff.failed": "The diff cannot be shown: {reason}",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue