ui: gate settings workspace capabilities
This commit is contained in:
+53
-1
@@ -75,6 +75,55 @@ function capabilityLabel(key) {
|
||||
return tKey('settings.capability.' + key);
|
||||
}
|
||||
|
||||
function renderWorkspaceProtocolOptions(capabilities, selectedProtocol) {
|
||||
var select = document.getElementById('settings-ws-protocol');
|
||||
if (!select) {
|
||||
return;
|
||||
}
|
||||
|
||||
var supportedProtocols = capabilities && Array.isArray(capabilities.supported_protocols) && capabilities.supported_protocols.length
|
||||
? capabilities.supported_protocols
|
||||
: ['rest', 'graphql', 'grpc'];
|
||||
var fallbackProtocol = supportedProtocols.indexOf('rest') !== -1 ? 'rest' : supportedProtocols[0];
|
||||
var effectiveSelection = supportedProtocols.indexOf(selectedProtocol) !== -1
|
||||
? selectedProtocol
|
||||
: fallbackProtocol;
|
||||
|
||||
select.innerHTML = '';
|
||||
supportedProtocols.forEach(function (protocol) {
|
||||
var option = document.createElement('option');
|
||||
option.value = protocol;
|
||||
option.textContent = capabilityLabel(protocol);
|
||||
option.selected = protocol === effectiveSelection;
|
||||
select.appendChild(option);
|
||||
});
|
||||
}
|
||||
|
||||
function populateWorkspaceCapabilityHint(capabilities) {
|
||||
var body = document.getElementById('settings-ws-protocol-hint');
|
||||
if (!body || !capabilities) {
|
||||
return;
|
||||
}
|
||||
|
||||
var protocols = (capabilities.supported_protocols || []).map(capabilityLabel).join(', ');
|
||||
body.textContent = tfKey('settings.ws.protocol_hint_capabilities', {
|
||||
protocols: protocols || capabilityLabel('none'),
|
||||
});
|
||||
}
|
||||
|
||||
function populateNotificationsCapabilityHint(capabilities) {
|
||||
var title = document.getElementById('settings-notifications-capability-title');
|
||||
var body = document.getElementById('settings-notifications-capability-body');
|
||||
if (!title || !body || !capabilities) {
|
||||
return;
|
||||
}
|
||||
|
||||
title.textContent = tKey('settings.notifications.capability_title_' + capabilities.edition);
|
||||
body.textContent = tfKey('settings.notifications.capability_body_' + capabilities.edition, {
|
||||
edition: capabilities.edition,
|
||||
});
|
||||
}
|
||||
|
||||
function populateCapabilities(capabilities) {
|
||||
var title = document.getElementById('settings-security-capability-title');
|
||||
var body = document.getElementById('settings-security-capability-body');
|
||||
@@ -96,6 +145,9 @@ function populateCapabilities(capabilities) {
|
||||
max_users: limits.max_users_per_workspace == null ? capabilityLabel('unlimited') : String(limits.max_users_per_workspace),
|
||||
max_agents: limits.max_agents_per_workspace == null ? capabilityLabel('unlimited') : String(limits.max_agents_per_workspace),
|
||||
});
|
||||
populateWorkspaceCapabilityHint(capabilities);
|
||||
populateNotificationsCapabilityHint(capabilities);
|
||||
renderWorkspaceProtocolOptions(capabilities, document.getElementById('settings-ws-protocol').value || 'rest');
|
||||
}
|
||||
|
||||
function populateProfile(session) {
|
||||
@@ -310,7 +362,7 @@ async function loadWorkspaceSettings() {
|
||||
document.getElementById('settings-ws-display-name').value = item.display_name || '';
|
||||
document.getElementById('settings-ws-description').value = settings.description || '';
|
||||
document.getElementById('settings-ws-timezone').value = settings.timezone || 'UTC';
|
||||
document.getElementById('settings-ws-protocol').value = settings.default_protocol || 'rest';
|
||||
renderWorkspaceProtocolOptions(settingsCapabilities, settings.default_protocol || 'rest');
|
||||
|
||||
document.querySelectorAll('#section-workspace .lang-btn').forEach(function (button) {
|
||||
button.classList.toggle('active', button.dataset.lang === (settings.language || (localStorage.getItem('crank_lang') || 'en')));
|
||||
|
||||
Reference in New Issue
Block a user