4974-datasources-and-improvements #4
199
src/main.js
199
src/main.js
|
@ -5,15 +5,15 @@ var Conf = {
|
||||||
dsName: 'verdnatura',
|
dsName: 'verdnatura',
|
||||||
dsPath: odbcPath + 'verdnatura',
|
dsPath: odbcPath + 'verdnatura',
|
||||||
regPath: 'HKCU\\SOFTWARE\\Verdnatura\\vn-access',
|
regPath: 'HKCU\\SOFTWARE\\Verdnatura\\vn-access',
|
||||||
remoteUrl: 'https://cdn.verdnatura.es/vn-access',
|
|
||||||
defaultModule: 'vn',
|
defaultModule: 'vn',
|
||||||
defaultLocale: 'es',
|
defaultLocale: 'es',
|
||||||
defaultBranch: 'master',
|
defaultBranch: 'master',
|
||||||
|
defaultDatasource: 'production',
|
||||||
|
defaultRemoteURL: 'https://salix.verdnatura.es',
|
||||||
dbName: 'vn2008',
|
dbName: 'vn2008',
|
||||||
maxCorruptSize: 600,
|
maxCorruptSize: 600,
|
||||||
odbcDriver: 'MySQL ODBC 8.0 Unicode Driver',
|
odbcDriver: 'MySQL ODBC 8.0 Unicode Driver',
|
||||||
driverPath: '\\MySQL\\Connector ODBC 8.0\\myodbc8w.dll',
|
driverPath: '\\MySQL\\Connector ODBC 8.0\\myodbc8w.dll',
|
||||||
defaultDatasource: 'production',
|
|
||||||
version: 4,
|
version: 4,
|
||||||
cdnURL: 'https://cdn.verdnatura.es/vn-access',
|
cdnURL: 'https://cdn.verdnatura.es/vn-access',
|
||||||
datasources: {
|
datasources: {
|
||||||
|
@ -26,8 +26,8 @@ var Conf = {
|
||||||
test: {
|
test: {
|
||||||
DESCRIPTION: 'test',
|
DESCRIPTION: 'test',
|
||||||
SERVER: 'test-db.verdnatura.es',
|
SERVER: 'test-db.verdnatura.es',
|
||||||
PORT: '3307',
|
PORT: '3306',
|
||||||
SSLMODE: 'DISABLED'
|
SSLMODE: 'VERIFY_IDENTITY'
|
||||||
},
|
},
|
||||||
dev: {
|
dev: {
|
||||||
DESCRIPTION: 'dev',
|
DESCRIPTION: 'dev',
|
||||||
|
@ -78,7 +78,7 @@ var App = {
|
||||||
init: function() {
|
init: function() {
|
||||||
// Specify the size of window
|
// Specify the size of window
|
||||||
var width = 420;
|
var width = 420;
|
||||||
var height = 550;
|
var height = 570;
|
||||||
window.resizeTo(width, height);
|
window.resizeTo(width, height);
|
||||||
window.moveTo((screen.width - width) / 2, (screen.height - height) / 2);
|
window.moveTo((screen.width - width) / 2, (screen.height - height) / 2);
|
||||||
},
|
},
|
||||||
|
@ -104,7 +104,6 @@ var App = {
|
||||||
this.certFile = this.appDir +'\\cacert.pem';
|
this.certFile = this.appDir +'\\cacert.pem';
|
||||||
|
|
||||||
// Creates the necessary registry entries
|
// Creates the necessary registry entries
|
||||||
|
|
||||||
var myVersion = this.regRead(Conf.regPath, 'version');
|
var myVersion = this.regRead(Conf.regPath, 'version');
|
||||||
|
|
||||||
if (!myVersion || myVersion != Conf.version) {
|
if (!myVersion || myVersion != Conf.version) {
|
||||||
|
@ -180,14 +179,19 @@ var App = {
|
||||||
|
|
||||||
createODBC: function(path, dsName, driverName) {
|
createODBC: function(path, dsName, driverName) {
|
||||||
var driverPath = this.getEnv('ProgramFiles') + Conf.driverPath;
|
var driverPath = this.getEnv('ProgramFiles') + Conf.driverPath;
|
||||||
|
var datasource = Conf.defaultDatasource;
|
||||||
|
var serverURL, sslMode;
|
||||||
|
|
||||||
|
serverURL = Conf.datasources[datasource].SERVER
|
||||||
|
sslMode = Conf.datasources[datasource].SSLMODE
|
||||||
|
|
||||||
var params = {
|
var params = {
|
||||||
Driver: driverPath,
|
Driver: driverPath,
|
||||||
DESCRIPTION: Conf.appName,
|
DESCRIPTION: Conf.appName,
|
||||||
SERVER: Conf.datasources.production.SERVER,
|
SERVER: serverURL,
|
||||||
DATABASE: Conf.dbName,
|
DATABASE: Conf.dbName,
|
||||||
SSLCA: this.certFile,
|
SSLCA: this.certFile,
|
||||||
SSLMODE: 'VERIFY_IDENTITY',
|
SSLMODE: sslMode,
|
||||||
SSLCIPHER: 'AES256-SHA',
|
SSLCIPHER: 'AES256-SHA',
|
||||||
AUTO_RECONNECT: 1,
|
AUTO_RECONNECT: 1,
|
||||||
NO_PROMPT: 1,
|
NO_PROMPT: 1,
|
||||||
|
@ -199,20 +203,16 @@ var App = {
|
||||||
},
|
},
|
||||||
|
|
||||||
updateODBC: function(path, dsName, datasource) {
|
updateODBC: function(path, dsName, datasource) {
|
||||||
var params;
|
var params = Conf.datasources[datasource]
|
||||||
|
|
||||||
// ToDo → Transform variable to property
|
var datasourcePath = this.getDatasourcePath();
|
||||||
if (datasource == 'production')
|
var myUID = this.regRead(datasourcePath, 'UID');
|
||||||
params = Conf.datasources.production
|
var myPWD = this.regRead(datasourcePath, 'PWD');
|
||||||
|
|
||||||
if (datasource == 'test')
|
if (myUID && myPWD) {
|
||||||
params = Conf.datasources.test
|
params['UID'] = myUID;
|
||||||
|
params['PWD'] = myPWD;
|
||||||
if (datasource == 'dev')
|
}
|
||||||
params = Conf.datasources.dev
|
|
||||||
|
|
||||||
if (datasource == 'localhost')
|
|
||||||
params = Conf.datasources.localhost
|
|
||||||
|
|
||||||
this.regWrites(path + dsName, params);
|
this.regWrites(path + dsName, params);
|
||||||
},
|
},
|
||||||
|
@ -288,8 +288,7 @@ var App = {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var curDatasource = this.regRead(Conf.regPath, 'currentDatasource');
|
var datasourcePath = this.getDatasourcePath();
|
||||||
var datasourcePath = Conf.regPath + '\\datasources\\' + curDatasource;
|
|
||||||
var myUID = this.regRead(datasourcePath, 'UID');
|
var myUID = this.regRead(datasourcePath, 'UID');
|
||||||
var myPWD = this.regRead(datasourcePath, 'PWD');
|
var myPWD = this.regRead(datasourcePath, 'PWD');
|
||||||
|
|
||||||
|
@ -356,7 +355,10 @@ var App = {
|
||||||
this.regWrite(Conf.dsPath, 'UID', user);
|
this.regWrite(Conf.dsPath, 'UID', user);
|
||||||
this.regWrite(Conf.dsPath, 'PWD', password);
|
this.regWrite(Conf.dsPath, 'PWD', password);
|
||||||
|
|
||||||
|
// Check the cretentials and return the last version number
|
||||||
var version = this.fetchVersion();
|
var version = this.fetchVersion();
|
||||||
|
|
||||||
|
// Check if there is a new version, and if there is, download it
|
||||||
if (version !== null) {
|
if (version !== null) {
|
||||||
this.disableUi(true, _('Updating'));
|
this.disableUi(true, _('Updating'));
|
||||||
var remoteFile = version
|
var remoteFile = version
|
||||||
|
@ -383,37 +385,27 @@ var App = {
|
||||||
* fetch or %null if local is up-to-date
|
* fetch or %null if local is up-to-date
|
||||||
*/
|
*/
|
||||||
fetchVersion: function() {
|
fetchVersion: function() {
|
||||||
// Gets the last version number using the MySQL ODBC connection
|
var mysqlConn = new ActiveXObject('ADODB.Connection');
|
||||||
|
|
||||||
var mysqlConn = new ActiveXObject('ADODB.Connection');;
|
|
||||||
var datasource = this.getDatasource();
|
var datasource = this.getDatasource();
|
||||||
var serverURL;
|
var user = this.$('user').value;
|
||||||
var sslMode;
|
var password = this.$('password').value;
|
||||||
|
var serverURL = Conf.datasources[datasource].SERVER;
|
||||||
|
var sslMode = Conf.datasources[datasource].SSLMODE;
|
||||||
|
|
||||||
// ToDo → Transform variable to property
|
// ToDo: Can't login to dev-db
|
||||||
if (datasource == 'production')
|
if (datasource == 'dev') {
|
||||||
serverURL = Conf.datasources.production.SERVER
|
serverURL = Conf.datasources.production.SERVER
|
||||||
sslMode = Conf.datasources.production.SSLMODE
|
sslMode = Conf.datasources.production.SERVER
|
||||||
|
};
|
||||||
if (datasource == 'test')
|
|
||||||
serverURL = Conf.datasources.test.SERVER
|
|
||||||
sslMode = Conf.datasources.test.SSLMODE
|
|
||||||
|
|
||||||
if (datasource == 'dev')
|
|
||||||
serverURL = Conf.datasources.dev.SERVER
|
|
||||||
sslMode = Conf.datasources.dev.SSLMODE
|
|
||||||
|
|
||||||
if (datasource == 'localhost')
|
|
||||||
serverURL = Conf.datasources.localhost.SERVER
|
|
||||||
sslMode = Conf.datasources.localhost.SSLMODE
|
|
||||||
|
|
||||||
|
// Check credentials
|
||||||
try {
|
try {
|
||||||
mysqlConn.open(this.getODBCString({
|
mysqlConn.open(this.getODBCString({
|
||||||
Driver: '{'+ Conf.odbcDriver +'}',
|
Driver: '{'+ Conf.odbcDriver +'}',
|
||||||
SERVER: serverURL,
|
SERVER: serverURL,
|
||||||
DATABASE: Conf.dbName,
|
DATABASE: Conf.dbName,
|
||||||
UID: this.$('user').value,
|
UID: user,
|
||||||
PWD: this.$('password').value,
|
PWD: password,
|
||||||
SSLCA: this.certFile,
|
SSLCA: this.certFile,
|
||||||
SSLMODE: sslMode,
|
SSLMODE: sslMode,
|
||||||
SSLCIPHER: 'AES256-SHA',
|
SSLCIPHER: 'AES256-SHA',
|
||||||
|
@ -424,7 +416,6 @@ var App = {
|
||||||
|
|
||||||
if (dbErrors && dbErrors.count > 0) {
|
if (dbErrors && dbErrors.count > 0) {
|
||||||
var dbError = dbErrors.item(0);
|
var dbError = dbErrors.item(0);
|
||||||
|
|
||||||
switch (dbError.NativeError) {
|
switch (dbError.NativeError) {
|
||||||
case 1045: // Access denied
|
case 1045: // Access denied
|
||||||
clearPassword = true;
|
clearPassword = true;
|
||||||
|
@ -437,41 +428,48 @@ var App = {
|
||||||
default:
|
default:
|
||||||
err = new Error(dbError.description);
|
err = new Error(dbError.description);
|
||||||
}
|
}
|
||||||
|
|
||||||
dbErrors.clear();
|
dbErrors.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
var sql = "SELECT version " +
|
|
||||||
" FROM vn.mdbVersion " +
|
|
||||||
" WHERE app = '"+ this.module +"' " +
|
|
||||||
" AND branchFk = '" + this.$('branch').value + "'";
|
|
||||||
var rs = mysqlConn.execute(sql);
|
|
||||||
var version = rs.EOF ? false : parseInt(rs.fields(0).value);
|
|
||||||
|
|
||||||
rs.close();
|
|
||||||
mysqlConn.close();
|
mysqlConn.close();
|
||||||
|
|
||||||
|
// Request to obtain the token and lastest version of this module
|
||||||
|
try {
|
||||||
|
var request = new ActiveXObject("MSXML2.ServerXMLHTTP");
|
||||||
|
urlLoginMethod = this.getRemoteURL() + '/api/Accounts/login'
|
||||||
|
request.open('POST', urlLoginMethod, false);
|
||||||
|
request.setRequestHeader('Content-Type', 'application/json')
|
||||||
|
var params = JSON.stringify({
|
||||||
|
"user": user,
|
||||||
|
"password": password
|
||||||
|
});
|
||||||
|
request.onreadystatechange = function() {
|
||||||
|
App.onRequestTokenReady(request);
|
||||||
|
}
|
||||||
|
request.send(params);
|
||||||
|
} catch (err) {
|
||||||
|
throw err;
|
||||||
|
};
|
||||||
|
|
||||||
// Checks if it's already open
|
// Checks if it's already open
|
||||||
if (this.fso.fileExists(this.lockFile))
|
if (this.fso.fileExists(this.lockFile))
|
||||||
try {
|
try {
|
||||||
this.fso.deleteFile(this.lockFile);
|
this.fso.deleteFile(this.lockFile);
|
||||||
return version;
|
return this.lastVersion;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(_('Application it\'s already open'));
|
throw new Error(_('Application it\'s already open'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks if MDB exists
|
// Checks if MDB exists
|
||||||
if (!this.fso.fileExists(this.mdbFile))
|
if (!this.fso.fileExists(this.mdbFile))
|
||||||
return version;
|
return this.lastVersion;
|
||||||
|
|
||||||
// If it's abnormaly bigger, maybe is corrupted, so force download
|
// If it's abnormaly bigger, maybe is corrupted, so force download
|
||||||
var file = this.fso.getFile(this.mdbFile);
|
var file = this.fso.getFile(this.mdbFile);
|
||||||
|
|
||||||
if (file.size > Conf.maxCorruptSize * 1024 * 1024)
|
if (file.size > Conf.maxCorruptSize * 1024 * 1024)
|
||||||
return version;
|
return this.lastVersion;
|
||||||
|
|
||||||
// Obtains the local version number from the MDB file
|
// Obtains the local version number from the MDB file
|
||||||
var localVersion = this.mdbGetValue(
|
var localVersion = this.mdbGetValue(
|
||||||
|
@ -482,8 +480,8 @@ var App = {
|
||||||
localVersion = false;
|
localVersion = false;
|
||||||
|
|
||||||
// Determines if should download
|
// Determines if should download
|
||||||
return !localVersion || version === false || localVersion != version
|
return !localVersion || this.lastVersion === false || localVersion != this.lastVersion
|
||||||
? version
|
? this.lastVersion
|
||||||
: null;
|
: null;
|
||||||
},
|
},
|
||||||
mdbGetValue: function(query, field, parseFn) {
|
mdbGetValue: function(query, field, parseFn) {
|
||||||
|
@ -553,6 +551,50 @@ var App = {
|
||||||
this.catchError(e);
|
this.catchError(e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onRequestTokenReady: function(request) {
|
||||||
|
if (request.readyState !== 4)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (request.status !== 200 )
|
||||||
|
throw new Error('HTTP: '+ request.statusText + ' ' + request.status);
|
||||||
|
|
||||||
|
this.response = JSON.parse(request.responseText)
|
||||||
|
|
||||||
|
if (this.response) {
|
||||||
|
var request = new ActiveXObject("MSXML2.ServerXMLHTTP");
|
||||||
|
var filter = '&filter=' + JSON.stringify({
|
||||||
|
"fields":["version"],
|
||||||
|
"where":{
|
||||||
|
"app": this.module,
|
||||||
|
"branchFk": this.$('branch').value
|
||||||
|
},
|
||||||
|
});
|
||||||
|
var urlVersionMethod = this.getRemoteURL() + '/api/MdbVersions?access_token=' + this.response.token + filter
|
||||||
|
request.open('GET', urlVersionMethod, false);
|
||||||
|
request.onreadystatechange = function() {
|
||||||
|
App.onRequestVersionReady(request);
|
||||||
|
};
|
||||||
|
request.send();
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onRequestVersionReady: function(request) {
|
||||||
|
if (request.readyState !== 4)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (request.status !== 200 )
|
||||||
|
throw new Error('HTTP: '+ request.statusText + ' .' + request.status + '.');
|
||||||
|
|
||||||
|
var response = JSON.parse(request.responseText);
|
||||||
|
this.lastVersion = response[0].version
|
||||||
|
} catch (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
openMdb: function() {
|
openMdb: function() {
|
||||||
var notSignOut = !!this.$('notSignOut').checked;
|
var notSignOut = !!this.$('notSignOut').checked;
|
||||||
this.regWrite(Conf.regPath, 'notSignOut', notSignOut);
|
this.regWrite(Conf.regPath, 'notSignOut', notSignOut);
|
||||||
|
@ -678,6 +720,11 @@ var App = {
|
||||||
);
|
);
|
||||||
return branch || Conf.defaultBranch;
|
return branch || Conf.defaultBranch;
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Get the current datasource used
|
||||||
|
*
|
||||||
|
* @return {string} Datasource name
|
||||||
|
*/
|
||||||
getDatasource: function() {
|
getDatasource: function() {
|
||||||
var datasource = this.regRead(
|
var datasource = this.regRead(
|
||||||
'HKCU\\SOFTWARE\\Verdnatura\\vn-access',
|
'HKCU\\SOFTWARE\\Verdnatura\\vn-access',
|
||||||
|
@ -685,9 +732,39 @@ var App = {
|
||||||
);
|
);
|
||||||
return datasource || Conf.defaultDatasource;
|
return datasource || Conf.defaultDatasource;
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Get the remote URL
|
||||||
|
*
|
||||||
|
* @return {string} Remote server
|
||||||
|
*/
|
||||||
|
getRemoteURL: function() {
|
||||||
|
var datasource = this.regRead(
|
||||||
|
'HKCU\\SOFTWARE\\Verdnatura\\vn-access',
|
||||||
|
'remoteURL'
|
||||||
|
);
|
||||||
|
return datasource || Conf.defaultRemoteURL;
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Get the current datasource path
|
||||||
|
*
|
||||||
|
* @return {string} Datasource path
|
||||||
|
*/
|
||||||
|
getDatasourcePath: function() {
|
||||||
|
var datasourcePath = Conf.regPath + '\\datasources\\' + this.getDatasource();
|
||||||
|
|
||||||
|
return datasourcePath;
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Update the datasource
|
||||||
|
*
|
||||||
|
* @param {String} datasource The datasource
|
||||||
|
*/
|
||||||
updateDatasource: function(datasource) {
|
updateDatasource: function(datasource) {
|
||||||
this.regWrite(Conf.regPath, 'currentDatasource', datasource);
|
this.regWrite(Conf.regPath, 'currentDatasource', datasource);
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Create all datasources structure
|
||||||
|
*/
|
||||||
createDatasources: function() {
|
createDatasources: function() {
|
||||||
var params = {
|
var params = {
|
||||||
'UID': null,
|
'UID': null,
|
||||||
|
|
|
@ -103,7 +103,7 @@ button:hover {
|
||||||
/* Branch */
|
/* Branch */
|
||||||
|
|
||||||
#branchOptions {
|
#branchOptions {
|
||||||
margin-top: 1em;
|
margin-top: 2em;
|
||||||
}
|
}
|
||||||
#branchLogo {
|
#branchLogo {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
@ -156,7 +156,7 @@ select.dev {
|
||||||
/* Datasource */
|
/* Datasource */
|
||||||
|
|
||||||
#datasourceOptions {
|
#datasourceOptions {
|
||||||
margin-top: 1em;
|
margin-top: 2em;
|
||||||
margin-left: 17.3em;
|
margin-left: 17.3em;
|
||||||
}
|
}
|
||||||
#datasourceLogo {
|
#datasourceLogo {
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
<button id="enter" onclick="App.onEnterClick()">Iniciar sesión</button>
|
<button id="enter" onclick="App.onEnterClick()">Iniciar sesión</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="cleanDiv">
|
<div id="cleanDiv">
|
||||||
<a id="clean" href="#" onclick="App.onCleanCacheClick()">Limpiar caché </a>
|
<a id="clean" href="#" onclick="App.onCleanCacheClick()">Limpiar caché</a>
|
||||||
</div>
|
</div>
|
||||||
<div id="branchOptions">
|
<div id="branchOptions">
|
||||||
<div id="branchButton">
|
<div id="branchButton">
|
||||||
|
|
Loading…
Reference in New Issue