Skip to content

Commit

Permalink
Merge pull request #145 from acrosman/feature/improved-connection-mes…
Browse files Browse the repository at this point in the history
…sages

Improved connection messages
  • Loading branch information
acrosman authored May 7, 2022
2 parents 6e06e0c + 7cc8677 commit 9d56ad3
Show file tree
Hide file tree
Showing 5 changed files with 295 additions and 214 deletions.
14 changes: 7 additions & 7 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ <h5 class="modal-title" id="dbModalLabel">Enter Database Information</h5>
<div class="form-group">
<label for="db-name">Database Name</label>
<input type="text" id="db-name" class="form-control"
aria-describedby="dbNameHelp" placeholder="Enter Database Name">
<small id="dbNameHelp" class="form-text">Database Name</small>
aria-describedby="dbNameHelp" placeholder="Enter Database Name"
required="required">
<small id="dbNameHelp" class="form-text">Database Name is required.</small>
</div>
<div class="form-group">
<label for="db-overwrite" class="form-check-label">Drop and Recreate
Expand Down Expand Up @@ -210,14 +211,13 @@ <h2>Last Response:</h2>
</div>
<span class="loader-message">Idle</span>
</div>
<div class="text-center" id="message-wrapper">
<div id="results-message-only" class="results-message alert alert-primary" role="alert">Welcome
to Sf2Sql</div>
</div>
</div>
</div>
</div>
<div class="row" id="message-wrapper">
<div class="col-md-12" id="results-message-wrapper">
<div id="results-message-only" class="results-message alert alert-primary" role="alert"></div>
</div>
</div>
<div class="row" id="controls-wrapper">
<div class="col-md-12">
<form class="float-lg-end row ms-auto">
Expand Down
86 changes: 68 additions & 18 deletions app/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ $.when($.ready).then(() => {
// Hide the places for handling responses until we have some.
$('#org-status').hide();
$('#results-table-wrapper').hide();
$('#results-message-wrapper').hide();
$('#results-object-viewer-wrapper').hide();

// Setup next buttons.
Expand Down Expand Up @@ -297,10 +296,18 @@ const generateTableCell = (tableRow, content, isText = true, position = -1) => {
const showLoader = (message) => {
$('#loader-indicator .loader-message').text(message);
$('#loader-indicator').show();
$('#message-wrapper').hide();
};

const hideLoader = () => {
$('#loader-indicator').hide();
$('#message-wrapper').show();
};

const updateMessage = (message) => {
$('#message-wrapper').show();
const messageArea = document.getElementById('results-message-only');
messageArea.innerText = message;
};

/**
Expand Down Expand Up @@ -368,12 +375,12 @@ const displayObjectList = (sObjectData, selected, sorted = false, sortedColumn =
'name',
];

updateMessage('Object List Retrieved');

// Display area.
// @todo: remove jquery use.
hideLoader();
$('#results-table-wrapper').show();
$('#results-object-viewer-wrapper').hide();
$('#results-message-wrapper').hide();
$('#results-summary-count').text('Loading objects...');

// Get the table.
Expand Down Expand Up @@ -524,6 +531,9 @@ const displayObjectList = (sObjectData, selected, sorted = false, sortedColumn =

// Enable the button to fetch object list.
$('#btn-fetch-details').prop('disabled', false);

// Interface update complete, hide the loader.
hideLoader();
};

/**
Expand All @@ -532,16 +542,51 @@ const displayObjectList = (sObjectData, selected, sorted = false, sortedColumn =
*/
const displayDraftSchema = (schema) => {
showLoader('All objects loaded, refreshing display');

refreshObjectDisplay({
message: 'Proposed Database Schema',
response: schema,
});

updateMessage('Proposed schema ready for review.');

$('#btn-generate-schema').prop('disabled', false);
$('#btn-save-sf-schema').prop('disabled', false);
$('#nav-schema-tab').tab('show');
hideLoader();
};

/**
* Handles follow up when database creation process completes.
* @param {*} data The result details.
*/
const handleDatabaseFinish = (data) => {
// Check each table to see if it succeeded
const hasResponses = Object.prototype.hasOwnProperty.call(data, 'response');
let fullSuccess = data.status;
let fullFailure = !hasResponses;
const tables = Object.getOwnPropertyNames(data.responses);
tables.forEach((table) => {
fullSuccess = data.responses[table] && fullSuccess;
fullFailure = !data.responses[table] || fullFailure;
});

logMessage('Database', 'Info', 'Database generation complete.', data);

if (fullSuccess) {
updateMessage('Database creation complete, all tables created');
} else if (fullFailure) {
updateMessage('Error creating database tables, all tables failed');
} else {
updateMessage('Database creation process complete, some tables had error. Review logs for more details');
}

// @todo remove jquery.
$('#btn-save-sql-schema').prop('disabled', false);

hideLoader();
};

// ========= Messages to the main process ===============
// Login
document.getElementById('login-trigger').addEventListener('click', () => {
Expand Down Expand Up @@ -603,17 +648,21 @@ document.getElementById('schema-trigger').addEventListener('click', () => {
}
}

showLoader('Creating Database Tables');

window.api.send('knex_schema', {
type: dbType,
host: document.getElementById('db-host').value,
port: document.getElementById('db-port').value,
username: document.getElementById('db-username').value,
password: document.getElementById('db-password').value,
dbname: document.getElementById('db-name').value,
overwrite: document.getElementById('db-overwrite').checked,
});
if (document.getElementById('db-name').value === '') {
updateMessage('Database name is required to attempt creation.');
} else {
showLoader('Creating Database Tables');

window.api.send('knex_schema', {
type: dbType,
host: document.getElementById('db-host').value,
port: document.getElementById('db-port').value,
username: document.getElementById('db-username').value,
password: document.getElementById('db-password').value,
dbname: document.getElementById('db-name').value,
overwrite: document.getElementById('db-overwrite').checked,
});
}
});

// Save the database create statement to a file.
Expand Down Expand Up @@ -649,17 +698,20 @@ document.getElementById('btn-load-sf-schema').addEventListener('click', () => {
window.api.receive('response_login', (data) => {
hideLoader();
if (data.status) {
handleLogin(data);
logMessage('Salesforce', 'Success', data.message, data.response);
updateMessage('Login Successful');
handleLogin(data, data.status);
} else {
logMessage('Salesforce', 'Error', data.message, data.response);
displayRawResponse(data);
updateMessage('Login Error');
}
});

// Logout Response.
window.api.receive('response_logout', (data) => {
logMessage('Salesforce', 'Info', 'Log out complete', data);
updateMessage('Salesforce connection removed.');
});

// Generic Response.
Expand All @@ -670,9 +722,7 @@ window.api.receive('response_error', (data) => {

// Response after building database
window.api.receive('response_db_generated', (data) => {
hideLoader();
logMessage('Database', 'Info', 'Database generation complete.', data);
$('#btn-save-sql-schema').prop('disabled', false);
handleDatabaseFinish(data);
});

window.api.receive('response_schema', (data) => {
Expand Down
Loading

0 comments on commit 9d56ad3

Please sign in to comment.