fix: align live flow contracts and preserve existing result state
Closes #9
This commit is contained in:
@@ -16,6 +16,8 @@ let collectionJobPollTimer = null;
|
||||
let collectionJobScenario = [];
|
||||
let collectionJobScenarioIndex = 0;
|
||||
let collectionJobLogCounter = 0;
|
||||
let apiPortTouchedByUser = false;
|
||||
let isAutoUpdatingApiPort = false;
|
||||
|
||||
function initSourceType() {
|
||||
const sourceButtons = document.querySelectorAll('.source-switch-btn');
|
||||
@@ -49,7 +51,7 @@ function initApiSource() {
|
||||
|
||||
const authTypeField = document.getElementById('api-auth-type');
|
||||
const cancelJobButton = document.getElementById('cancel-job-btn');
|
||||
const fieldNames = ['host', 'protocol', 'port', 'username', 'authType', 'password', 'token'];
|
||||
const fieldNames = ['host', 'protocol', 'port', 'username', 'auth_type', 'tls_mode', 'password', 'token'];
|
||||
|
||||
apiForm.addEventListener('submit', (event) => {
|
||||
event.preventDefault();
|
||||
@@ -65,7 +67,6 @@ function initApiSource() {
|
||||
apiConnectPayload = payload;
|
||||
renderApiConnectStatus(true, payload);
|
||||
startCollectionJob(payload);
|
||||
console.log('API payload prepared:', apiConnectPayload);
|
||||
});
|
||||
|
||||
if (cancelJobButton) {
|
||||
@@ -82,9 +83,15 @@ function initApiSource() {
|
||||
|
||||
const eventName = field.tagName.toLowerCase() === 'select' ? 'change' : 'input';
|
||||
field.addEventListener(eventName, () => {
|
||||
if (fieldName === 'authType') {
|
||||
if (fieldName === 'auth_type') {
|
||||
toggleApiAuthFields(authTypeField.value);
|
||||
}
|
||||
if (fieldName === 'protocol') {
|
||||
applyProtocolDefaultPort(field.value);
|
||||
}
|
||||
if (fieldName === 'port') {
|
||||
handleApiPortInput(field.value);
|
||||
}
|
||||
|
||||
const { errors } = validateCollectForm();
|
||||
renderFormErrors(errors);
|
||||
@@ -96,6 +103,7 @@ function initApiSource() {
|
||||
});
|
||||
});
|
||||
|
||||
applyProtocolDefaultPort(getApiValue('protocol'));
|
||||
toggleApiAuthFields(authTypeField.value);
|
||||
renderCollectionJob();
|
||||
}
|
||||
@@ -105,7 +113,8 @@ function validateCollectForm() {
|
||||
const protocol = getApiValue('protocol');
|
||||
const portRaw = getApiValue('port');
|
||||
const username = getApiValue('username');
|
||||
const authType = getApiValue('authType');
|
||||
const authType = getApiValue('auth_type');
|
||||
const tlsMode = getApiValue('tls_mode');
|
||||
const password = getApiValue('password');
|
||||
const token = getApiValue('token');
|
||||
|
||||
@@ -132,7 +141,10 @@ function validateCollectForm() {
|
||||
}
|
||||
|
||||
if (!['password', 'token'].includes(authType)) {
|
||||
errors.authType = 'Выберите тип авторизации.';
|
||||
errors.auth_type = 'Выберите тип авторизации.';
|
||||
}
|
||||
if (!['strict', 'insecure'].includes(tlsMode)) {
|
||||
errors.tls_mode = 'Выберите TLS режим.';
|
||||
}
|
||||
|
||||
if (authType === 'password' && !password) {
|
||||
@@ -148,20 +160,18 @@ function validateCollectForm() {
|
||||
}
|
||||
|
||||
const payload = {
|
||||
sourceType: 'api',
|
||||
connection: {
|
||||
host,
|
||||
protocol,
|
||||
port,
|
||||
username,
|
||||
authType
|
||||
}
|
||||
host,
|
||||
protocol,
|
||||
port,
|
||||
username,
|
||||
auth_type: authType,
|
||||
tls_mode: tlsMode
|
||||
};
|
||||
|
||||
if (authType === 'password') {
|
||||
payload.connection.password = password;
|
||||
payload.password = password;
|
||||
} else {
|
||||
payload.connection.token = token;
|
||||
payload.token = token;
|
||||
}
|
||||
|
||||
return { isValid: true, errors: {}, payload };
|
||||
@@ -174,7 +184,7 @@ function renderFormErrors(errors) {
|
||||
return;
|
||||
}
|
||||
|
||||
const errorFields = ['host', 'protocol', 'port', 'username', 'authType', 'password', 'token'];
|
||||
const errorFields = ['host', 'protocol', 'port', 'username', 'auth_type', 'tls_mode', 'password', 'token'];
|
||||
errorFields.forEach((fieldName) => {
|
||||
const errorNode = apiForm.querySelector(`[data-error-for="${fieldName}"]`);
|
||||
if (!errorNode) {
|
||||
@@ -212,12 +222,12 @@ function renderApiConnectStatus(isValid, payload) {
|
||||
return;
|
||||
}
|
||||
|
||||
const payloadPreview = { ...payload, connection: { ...payload.connection } };
|
||||
if (payloadPreview.connection.password) {
|
||||
payloadPreview.connection.password = '***';
|
||||
const payloadPreview = { ...payload };
|
||||
if (payloadPreview.password) {
|
||||
payloadPreview.password = '***';
|
||||
}
|
||||
if (payloadPreview.connection.token) {
|
||||
payloadPreview.connection.token = '***';
|
||||
if (payloadPreview.token) {
|
||||
payloadPreview.token = '***';
|
||||
}
|
||||
|
||||
status.textContent = `Payload сформирован: ${JSON.stringify(payloadPreview)}`;
|
||||
@@ -408,6 +418,43 @@ function toggleApiAuthFields(authType) {
|
||||
tokenField.classList.toggle('hidden', !useToken);
|
||||
}
|
||||
|
||||
function applyProtocolDefaultPort(protocol) {
|
||||
const defaults = {
|
||||
redfish: '443',
|
||||
ipmi: '623'
|
||||
};
|
||||
const defaultPort = defaults[protocol];
|
||||
if (!defaultPort) {
|
||||
return;
|
||||
}
|
||||
|
||||
const apiForm = document.getElementById('api-connect-form');
|
||||
if (!apiForm) {
|
||||
return;
|
||||
}
|
||||
|
||||
const portField = apiForm.elements.namedItem('port');
|
||||
if (!portField || typeof portField.value !== 'string') {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentValue = portField.value.trim();
|
||||
if (apiPortTouchedByUser && currentValue !== '') {
|
||||
return;
|
||||
}
|
||||
|
||||
isAutoUpdatingApiPort = true;
|
||||
portField.value = defaultPort;
|
||||
isAutoUpdatingApiPort = false;
|
||||
}
|
||||
|
||||
function handleApiPortInput(value) {
|
||||
if (isAutoUpdatingApiPort) {
|
||||
return;
|
||||
}
|
||||
apiPortTouchedByUser = value.trim() !== '';
|
||||
}
|
||||
|
||||
function getApiValue(fieldName) {
|
||||
const apiForm = document.getElementById('api-connect-form');
|
||||
if (!apiForm) {
|
||||
|
||||
Reference in New Issue
Block a user