Cleanup some code warnings.

This commit is contained in:
Dave Page 2021-03-12 15:20:57 +00:00
parent 47e9ef070e
commit 7780cbfb83
5 changed files with 57 additions and 59 deletions

View File

@ -10,14 +10,14 @@
const misc = require('../js/misc.js'); const misc = require('../js/misc.js');
// Get the window object of view log window // Get the window object of view log window
var gui = require('nw.gui'); let gui = require('nw.gui');
var configWindow = gui.Window.get(); let configWindow = gui.Window.get();
function checkConfiguration() { function checkConfiguration() {
var configData = misc.ConfigureStore.getConfigData(); let configData = misc.ConfigureStore.getConfigData();
if (document.getElementById('fixedPortCheck').checked && configData['portNo'] != document.getElementById('portNo').value) { if (document.getElementById('fixedPortCheck').checked && configData['portNo'] !== document.getElementById('portNo').value) {
var fixedPort = parseInt(document.getElementById('portNo').value); let fixedPort = parseInt(document.getElementById('portNo').value);
// get the available TCP port // get the available TCP port
misc.getAvailablePort(fixedPort) misc.getAvailablePort(fixedPort)
.then(() => { .then(() => {
@ -40,7 +40,7 @@ function saveConfiguration() {
document.getElementById('status-text').innerHTML = 'Configuration Saved'; document.getElementById('status-text').innerHTML = 'Configuration Saved';
if (confirm('pgAdmin 4 must be restarted for changes to take effect.\n\n Do you want to quit the application?') == true) { if (confirm('pgAdmin 4 must be restarted for changes to take effect.\n\n Do you want to quit the application?') === true) {
misc.cleanupAndQuitApp(); misc.cleanupAndQuitApp();
} }
configWindow.close(); configWindow.close();
@ -58,11 +58,11 @@ function onCheckChange() {
} }
function enableDisableSaveButton() { function enableDisableSaveButton() {
var configData = misc.ConfigureStore.getConfigData(); let configData = misc.ConfigureStore.getConfigData();
if (configData['fixedPort'] != document.getElementById('fixedPortCheck').checked || if (configData['fixedPort'] !== document.getElementById('fixedPortCheck').checked ||
configData['portNo'] != document.getElementById('portNo').value || configData['portNo'] !== document.getElementById('portNo').value ||
configData['connectionTimeout'] != document.getElementById('timeOut').value) { configData['connectionTimeout'] !== document.getElementById('timeOut').value) {
document.getElementById('btnSave').removeAttribute('disabled'); document.getElementById('btnSave').removeAttribute('disabled');
} else { } else {
document.getElementById('btnSave').setAttribute('disabled', 'disabled'); document.getElementById('btnSave').setAttribute('disabled', 'disabled');
@ -72,7 +72,7 @@ function enableDisableSaveButton() {
configWindow.on('loaded', function() { configWindow.on('loaded', function() {
document.getElementById('status-text').innerHTML = ''; document.getElementById('status-text').innerHTML = '';
// Get the config data from the file. // Get the config data from the file.
var configData = misc.ConfigureStore.getConfigData(); let configData = misc.ConfigureStore.getConfigData();
// Set the GUI value as per configuration. // Set the GUI value as per configuration.
if (configData['fixedPort']) { if (configData['fixedPort']) {

View File

@ -11,8 +11,8 @@ const fs = require('fs');
const path = require('path'); const path = require('path');
const net = require('net'); const net = require('net');
const {platform, homedir} = require('os'); const {platform, homedir} = require('os');
var pgadminServerProcess = null; let pgadminServerProcess = null;
var pgAdminWindowObject = null; let pgAdminWindowObject = null;
// This function is used to check whether directory is present or not // This function is used to check whether directory is present or not
// if not present then create it recursively // if not present then create it recursively
@ -25,7 +25,7 @@ const createDir = (dirName) => {
// This function is used to get the python executable path // This function is used to get the python executable path
// based on the platform. Use this for deployment. // based on the platform. Use this for deployment.
const getPythonPath = () => { const getPythonPath = () => {
var pythonPath = ''; let pythonPath;
switch (platform()) { switch (platform()) {
case 'win32': case 'win32':
pythonPath = '../python/python.exe'; pythonPath = '../python/python.exe';
@ -50,7 +50,7 @@ const getPythonPath = () => {
// This function is used to get the [roaming] app data path // This function is used to get the [roaming] app data path
// based on the platform. Use this for config etc. // based on the platform. Use this for config etc.
const getAppDataPath = () => { const getAppDataPath = () => {
var appDataPath = ''; let appDataPath;
switch (platform()) { switch (platform()) {
case 'win32': case 'win32':
appDataPath = path.join(process.env.APPDATA, 'pgadmin'); appDataPath = path.join(process.env.APPDATA, 'pgadmin');
@ -86,7 +86,7 @@ const getAppDataPath = () => {
// This function is used to get the [local] app data path // This function is used to get the [local] app data path
// based on the platform. Use this for logs etc. // based on the platform. Use this for logs etc.
const getLocalAppDataPath = () => { const getLocalAppDataPath = () => {
var localAppDataPath = ''; let localAppDataPath;
switch (platform()) { switch (platform()) {
case 'win32': case 'win32':
localAppDataPath = path.join(process.env.LOCALAPPDATA, 'pgadmin'); localAppDataPath = path.join(process.env.LOCALAPPDATA, 'pgadmin');
@ -132,7 +132,7 @@ const getAvailablePort = (fixedPort) => {
}); });
server.on('listening', () => { server.on('listening', () => {
var serverPort = server.address().port; let serverPort = server.address().port;
server.close(); server.close();
resolve(serverPort); resolve(serverPort);
}); });
@ -147,12 +147,12 @@ const DEFAULT_CONFIG_DATA = {'fixedPort': false, 'portNo': 5050, 'connectionTime
// This function is used to read the file and return the content // This function is used to read the file and return the content
const readServerLog = () => { const readServerLog = () => {
var data = null; let data = null;
if (fs.existsSync(serverLogFile)) { if (fs.existsSync(serverLogFile)) {
data = fs.readFileSync(serverLogFile, 'utf8'); data = fs.readFileSync(serverLogFile, 'utf8');
} else { } else {
var errMsg = 'Unable to read file ' + serverLogFile + '.'; let errMsg = 'Unable to read file ' + serverLogFile + '.';
console.warn(errMsg); console.warn(errMsg);
return errMsg; return errMsg;
} }
@ -237,7 +237,7 @@ const cleanupAndQuitApp = () => {
} }
}; };
var ConfigureStore = { let ConfigureStore = {
fileName: configFileName, fileName: configFileName,
jsonData: {}, jsonData: {},
@ -263,7 +263,7 @@ var ConfigureStore = {
this.jsonData = {}; this.jsonData = {};
} }
} else { } else {
var errMsg = 'Unable to read file ' + this.fileName + ' not found.'; let errMsg = 'Unable to read file ' + this.fileName + ' not found.';
console.warn(errMsg); console.warn(errMsg);
return false; return false;
} }
@ -276,7 +276,7 @@ var ConfigureStore = {
}, },
get: function(key, if_not_value) { get: function(key, if_not_value) {
if(this.jsonData[key] != undefined) { if(this.jsonData[key] !== undefined) {
return this.jsonData[key]; return this.jsonData[key];
} else { } else {
return if_not_value; return if_not_value;
@ -291,7 +291,7 @@ var ConfigureStore = {
}; };
} else { } else {
if(value === '' || value == null || typeof(value) == 'undefined') { if(value === '' || value == null || typeof(value) == 'undefined') {
if(this.jsonData[key] != undefined) { if(this.jsonData[key] !== undefined) {
delete this.jsonData[key]; delete this.jsonData[key];
} }
} else { } else {

View File

@ -13,21 +13,21 @@ const path = require('path');
const misc = require('../js/misc.js'); const misc = require('../js/misc.js');
const spawn = require('child_process').spawn; const spawn = require('child_process').spawn;
var pgadminServerProcess = null; let pgadminServerProcess = null;
var startPageUrl = null; let startPageUrl = null;
var serverCheckUrl = null; let serverCheckUrl = null;
var serverPort = 5050; let serverPort = 5050;
// Paths to the rest of the app // Paths to the rest of the app
var pythonPath = misc.getPythonPath(); let pythonPath = misc.getPythonPath();
var pgadminFile = '../web/pgAdmin4.py'; let pgadminFile = '../web/pgAdmin4.py';
var configFile = '../web/config.py'; let configFile = '../web/config.py';
// Override the paths above, if a developer needs to // Override the paths above, if a developer needs to
if (fs.existsSync('dev_config.json')) { if (fs.existsSync('dev_config.json')) {
try { try {
var dev_config = JSON.parse(fs.readFileSync('dev_config.json')); let dev_config = JSON.parse(fs.readFileSync('dev_config.json'));
pythonPath = dev_config['pythonPath']; pythonPath = dev_config['pythonPath'];
pgadminFile = dev_config['pgadminFile']; pgadminFile = dev_config['pgadminFile'];
} catch (error) { } catch (error) {
@ -37,14 +37,12 @@ if (fs.existsSync('dev_config.json')) {
// This function is used to create UUID // This function is used to create UUID
function createUUID() { function createUUID() {
var dt = new Date().getTime(); let dt = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (dt + Math.random()*16)%16 | 0; let r = (dt + Math.random()*16)%16 | 0;
dt = Math.floor(dt/16); dt = Math.floor(dt/16);
return (c=='x' ? r :(r&0x3|0x8)).toString(16); return (c==='x' ? r :(r&0x3|0x8)).toString(16);
}); });
return uuid;
} }
// This functions is used to start the pgAdmin4 server by spawning a // This functions is used to start the pgAdmin4 server by spawning a
@ -55,7 +53,7 @@ function startDesktopMode() {
if (pgadminServerProcess != null) if (pgadminServerProcess != null)
return; return;
var UUID = createUUID(); let UUID = createUUID();
// Set the environment variables so that pgAdmin 4 server // Set the environment variables so that pgAdmin 4 server
// starts listening on the appropriate port. // starts listening on the appropriate port.
process.env.PGADMIN_INT_PORT = serverPort; process.env.PGADMIN_INT_PORT = serverPort;
@ -71,7 +69,7 @@ function startDesktopMode() {
// Write Python Path, pgAdmin file path and command in log file. // Write Python Path, pgAdmin file path and command in log file.
misc.writeServerLog('pgAdmin Runtime Environment'); misc.writeServerLog('pgAdmin Runtime Environment');
misc.writeServerLog('--------------------------------------------------------'); misc.writeServerLog('--------------------------------------------------------');
var command = path.resolve(pythonPath) + ' ' + path.resolve(pgadminFile); let command = path.resolve(pythonPath) + ' ' + path.resolve(pgadminFile);
misc.writeServerLog('Python Path: "' + path.resolve(pythonPath) + '"'); misc.writeServerLog('Python Path: "' + path.resolve(pythonPath) + '"');
misc.writeServerLog('Runtime Config File: "' + path.resolve(misc.getRunTimeConfigFile()) + '"'); misc.writeServerLog('Runtime Config File: "' + path.resolve(misc.getRunTimeConfigFile()) + '"');
misc.writeServerLog('pgAdmin Config File: "' + path.resolve(configFile) + '"'); misc.writeServerLog('pgAdmin Config File: "' + path.resolve(configFile) + '"');
@ -131,15 +129,15 @@ function startDesktopMode() {
return axios.get(serverCheckUrl); return axios.get(serverCheckUrl);
} }
var connectionTimeout = misc.ConfigureStore.get('connectionTimeout', 90) * 1000; let connectionTimeout = misc.ConfigureStore.get('connectionTimeout', 90) * 1000;
var currentTime = (new Date).getTime(); let currentTime = (new Date).getTime();
var endTime = currentTime + connectionTimeout; let endTime = currentTime + connectionTimeout;
var midTime1 = currentTime + (connectionTimeout/2); let midTime1 = currentTime + (connectionTimeout/2);
var midTime2 = currentTime + (connectionTimeout*2/3); let midTime2 = currentTime + (connectionTimeout*2/3);
var pingInProgress = false; let pingInProgress = false;
// ping pgAdmin server every 1 second. // ping pgAdmin server every 1 second.
var intervalID = setInterval(function() { let intervalID = setInterval(function() {
// If ping request is already send and response is not // If ping request is already send and response is not
// received no need to send another request. // received no need to send another request.
if (pingInProgress) if (pingInProgress)
@ -155,7 +153,7 @@ function startDesktopMode() {
launchPgAdminWindow(); launchPgAdminWindow();
}).catch(() => { }).catch(() => {
pingInProgress = false; pingInProgress = false;
var curTime = (new Date).getTime(); let curTime = (new Date).getTime();
// if the connection timeout has lapsed then throw an error // if the connection timeout has lapsed then throw an error
// and stop pinging the server. // and stop pinging the server.
if (curTime >= endTime) { if (curTime >= endTime) {
@ -193,8 +191,8 @@ function startDesktopMode() {
function launchPgAdminWindow() { function launchPgAdminWindow() {
// Create and launch new window and open pgAdmin url // Create and launch new window and open pgAdmin url
misc.writeServerLog('Application Server URL: ' + startPageUrl); misc.writeServerLog('Application Server URL: ' + startPageUrl);
var winWidth = misc.ConfigureStore.get('windowWidth', 1300); let winWidth = misc.ConfigureStore.get('windowWidth', 1300);
var winHeight = misc.ConfigureStore.get('windowHeight', 900); let winHeight = misc.ConfigureStore.get('windowHeight', 900);
nw.Window.open(startPageUrl, { nw.Window.open(startPageUrl, {
'icon': '../../assets/pgAdmin4.png', 'icon': '../../assets/pgAdmin4.png',
@ -262,15 +260,15 @@ function launchPgAdminWindow() {
} }
// Get the gui object of NW.js // Get the gui object of NW.js
var gui = require('nw.gui'); let gui = require('nw.gui');
var splashWindow = gui.Window.get(); let splashWindow = gui.Window.get();
// Always clear the cache before starting the application. // Always clear the cache before starting the application.
nw.App.clearCache(); nw.App.clearCache();
// Create Mac Builtin Menu // Create Mac Builtin Menu
if (platform() == 'darwin') { if (platform() === 'darwin') {
var macMenu = new gui.Menu({type: 'menubar'}); let macMenu = new gui.Menu({type: 'menubar'});
macMenu.createMacBuiltin('pgAdmin 4'); macMenu.createMacBuiltin('pgAdmin 4');
splashWindow.menu = macMenu; splashWindow.menu = macMenu;
} }
@ -279,7 +277,7 @@ splashWindow.on('loaded', function() {
// Initialize the ConfigureStore // Initialize the ConfigureStore
misc.ConfigureStore.init(); misc.ConfigureStore.init();
var fixedPortCheck = misc.ConfigureStore.get('fixedPort', false); let fixedPortCheck = misc.ConfigureStore.get('fixedPort', false);
if (fixedPortCheck) { if (fixedPortCheck) {
serverPort = misc.ConfigureStore.get('portNo'); serverPort = misc.ConfigureStore.get('portNo');
//Start the pgAdmin in Desktop mode. //Start the pgAdmin in Desktop mode.
@ -293,7 +291,7 @@ splashWindow.on('loaded', function() {
startDesktopMode(); startDesktopMode();
}) })
.catch((errCode) => { .catch((errCode) => {
if (errCode == 'EADDRINUSE') { if (errCode === 'EADDRINUSE') {
alert('The port specified is already in use. Please enter a free port number.'); alert('The port specified is already in use. Please enter a free port number.');
} else { } else {
alert(errCode); alert(errCode);

View File

@ -10,8 +10,8 @@
const misc = require('../js/misc.js'); const misc = require('../js/misc.js');
// Get the window object of server error window // Get the window object of server error window
var gui = require('nw.gui'); let gui = require('nw.gui');
var errorWindow = gui.Window.get(); let errorWindow = gui.Window.get();
errorWindow.on('loaded', function() { errorWindow.on('loaded', function() {
document.getElementById('server_error_label').innerHTML = 'The pgAdmin 4 server could not be contacted:'; document.getElementById('server_error_label').innerHTML = 'The pgAdmin 4 server could not be contacted:';

View File

@ -10,8 +10,8 @@
const misc = require('../js/misc.js'); const misc = require('../js/misc.js');
// Get the window object of view log window // Get the window object of view log window
var gui = require('nw.gui'); let gui = require('nw.gui');
var logWindow = gui.Window.get(); let logWindow = gui.Window.get();
logWindow.on('loaded', function() { logWindow.on('loaded', function() {
document.getElementById('status-text').innerHTML = ''; document.getElementById('status-text').innerHTML = '';