feat: polish alpine settings and wizard feedback
This commit is contained in:
+33
-64
@@ -5,16 +5,6 @@ function settingsWorkspaceId() {
|
||||
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
|
||||
@@ -34,6 +24,37 @@ function setStatus(id, text, isError) {
|
||||
: 'var(--text-muted)';
|
||||
}
|
||||
|
||||
function titleCaseRole(role) {
|
||||
return String(role || 'viewer').replace(/^\w/, function(character) {
|
||||
return character.toUpperCase();
|
||||
});
|
||||
}
|
||||
|
||||
function populateCurrentSession(session) {
|
||||
var summary = document.getElementById('settings-session-summary');
|
||||
if (!summary) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(session && session.user)) {
|
||||
summary.textContent = 'Session details are unavailable. Use Log out to revoke the current browser session.';
|
||||
return;
|
||||
}
|
||||
|
||||
var membership = null;
|
||||
if (Array.isArray(session.memberships)) {
|
||||
membership = session.memberships.find(function(item) {
|
||||
return item.workspace && item.workspace.id === session.current_workspace_id;
|
||||
}) || session.memberships[0] || null;
|
||||
}
|
||||
|
||||
var workspaceLabel = membership && membership.workspace
|
||||
? (membership.workspace.display_name || membership.workspace.slug || membership.workspace.id)
|
||||
: 'current workspace';
|
||||
var roleLabel = membership ? titleCaseRole(membership.role) : 'Viewer';
|
||||
summary.textContent = session.user.email + ' · ' + roleLabel + ' in ' + workspaceLabel + '. Use Log out to revoke the current browser session.';
|
||||
}
|
||||
|
||||
function populateProfile(session) {
|
||||
if (!session || !session.user) {
|
||||
return;
|
||||
@@ -52,6 +73,8 @@ function populateProfile(session) {
|
||||
if (email) {
|
||||
email.value = user.email || '';
|
||||
}
|
||||
|
||||
populateCurrentSession(session);
|
||||
}
|
||||
|
||||
async function loadProfile() {
|
||||
@@ -285,65 +308,11 @@ 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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user