feat: polish alpine shell feedback

This commit is contained in:
a.tolmachev
2026-03-31 12:32:05 +03:00
parent 84f4437ce0
commit 4d91ccf48f
16 changed files with 366 additions and 30 deletions
+72 -1
View File
@@ -1,5 +1,20 @@
var settingsSession = null;
function settingsWorkspaceId() {
var workspace = window.getCurrentWorkspace ? window.getCurrentWorkspace() : null;
return workspace ? workspace.id : null;
}
function downloadSettingsJson(fileName, value) {
var blob = new Blob([JSON.stringify(value, null, 2)], { type: 'application/json;charset=utf-8' });
var url = URL.createObjectURL(blob);
var link = document.createElement('a');
link.href = url;
link.download = fileName;
link.click();
URL.revokeObjectURL(url);
}
function initials(displayName, email) {
var source = displayName || email || 'Crank';
return source
@@ -255,7 +270,9 @@ async function loadWorkspaceSettings() {
saveButton.textContent = 'Saved ✓';
} catch (error) {
alert(error.message || 'Failed to save workspace settings');
if (window.CrankUi) {
window.CrankUi.error(error.message || 'Failed to save workspace settings', 'Workspace save failed');
}
saveButton.textContent = original;
} finally {
setTimeout(function () {
@@ -268,11 +285,65 @@ async function loadWorkspaceSettings() {
}
}
function bindDangerZoneActions() {
var renameButton = document.getElementById('settings-ws-rename-btn');
var exportButton = document.getElementById('settings-ws-export-btn');
var deleteButton = document.getElementById('settings-ws-delete-btn');
if (renameButton && renameButton.dataset.bound !== 'true') {
renameButton.dataset.bound = 'true';
renameButton.addEventListener('click', function() {
document.getElementById('settings-ws-slug').focus();
if (window.CrankUi) {
window.CrankUi.info('Update the workspace slug above and save changes to rename it.', 'Rename workspace');
}
});
}
if (exportButton && exportButton.dataset.bound !== 'true') {
exportButton.dataset.bound = 'true';
exportButton.addEventListener('click', async function() {
var workspaceId = settingsWorkspaceId();
if (!workspaceId || !window.CrankApi) return;
try {
var snapshot = await window.CrankApi.exportWorkspace(workspaceId);
var workspace = window.getCurrentWorkspace ? window.getCurrentWorkspace() : null;
downloadSettingsJson((workspace ? workspace.slug : 'workspace') + '-snapshot.json', snapshot);
if (window.CrankUi) {
window.CrankUi.success('Workspace export downloaded.', 'Export complete');
}
} catch (error) {
if (window.CrankUi) {
window.CrankUi.error(error.message || 'Failed to export workspace', 'Export failed');
}
}
});
}
if (deleteButton && deleteButton.dataset.bound !== 'true') {
deleteButton.dataset.bound = 'true';
deleteButton.addEventListener('click', async function() {
var workspaceId = settingsWorkspaceId();
if (!workspaceId || !window.CrankApi || !window.CrankAuth) return;
if (!window.confirm('Delete workspace? This cannot be undone.')) return;
try {
await window.CrankApi.deleteWorkspace(workspaceId);
await window.CrankAuth.logout();
} catch (error) {
if (window.CrankUi) {
window.CrankUi.error(error.message || 'Failed to delete workspace', 'Delete failed');
}
}
});
}
}
document.addEventListener('DOMContentLoaded', function () {
injectLanguageSwitcher();
bindSectionNavigation();
loadProfile();
bindProfileSave();
bindPasswordSave();
bindDangerZoneActions();
loadWorkspaceSettings();
});