From 356c7636d84fdad7333e891b23dc28d48cc6cb00 Mon Sep 17 00:00:00 2001 From: Antoine Beaubien Date: Sat, 30 May 2020 04:20:05 -0400 Subject: [PATCH] Only show the database login fields when necessary (#2615) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * DB login fields visibility controled by CSS The database login field’s visibility is now controled by CSS styling. * Change field name from Database to Database file. Change field name from Database to Database file. * Use full db name as CSS classes Use full db name instead of diminutives for the CSS classes. * Added translation to placeholders Added translation to the Input placeholders. * Undo a change, remerge Database field & File remerge Database field and DatabaseFile Field like before. * Created DatabaseSourceUI._updateDatabaseType(dbType) Created Refine.DatabaseSourceUI.prototype._updateDatabaseType(databaseType) * Make MySQL the default database * Update database-import-form.html Fixed typo. () * New default connection name value New default connection name value, translation of it, changing cssClassName from options to dbtype-options, adding the prefix "dbt-" to the db types and fix the changing of placeholder databaseName/databaseFileName when neccessary. * Fix issue with « saved connections » Fix issue with « saved connections » and added 2 defaults values for dbHost and dbType. * Default DB back to MySQL. * Update extensions/database/module/langs/translation-en.json Co-authored-by: Thad Guidry * Better default with « mysql » * Fix sqlite #databaseHost before calling self._updateDatabaseType() Fix $( "#databaseHost" ).val(self._defaultDatabaseHost) to be set before calling self._updateDatabaseType(self._defaultDatabaseType) that may change it. * Removed field name & fixed default connection name Removed field name text since it's populated from i18n and fixed the default connection name so that it has no space in it. * Little update to placeholder text Co-authored-by: Thad Guidry --- .../database/module/langs/translation-en.json | 12 +- .../module/langs/translation-en_GB.json | 1 + .../database/module/langs/translation-fr.json | 10 ++ .../database/module/langs/translation-it.json | 1 + .../database/module/langs/translation-jp.json | 1 + .../database/module/langs/translation-ko.json | 1 + .../module/langs/translation-nb_NO.json | 1 + .../database/module/langs/translation-sv.json | 1 + .../module/scripts/database-extension.js | 53 ++++----- .../scripts/index/database-import-form.html | 59 +++++----- .../scripts/index/database-source-ui.js | 110 ++++++++++++------ 11 files changed, 154 insertions(+), 96 deletions(-) diff --git a/extensions/database/module/langs/translation-en.json b/extensions/database/module/langs/translation-en.json index b4ffadf48..ac286b651 100644 --- a/extensions/database/module/langs/translation-en.json +++ b/extensions/database/module/langs/translation-en.json @@ -20,8 +20,18 @@ "database-source/databasePortLabel": "Port:", "database-source/databaseUserLabel": "User:", "database-source/databasePasswordLabel": "Password:", - "database-source/databaseNameLabel": "Database:", + "database-source/databaseNameLabel": "Database name:", + "database-source/databaseFileNameLabel": "Database file:", "database-source/databaseSchemaLabel": "Schema:", + "database-source/connectionNamePlaceholder": "Enter a new Connection Name", + "database-source/databaseHostPlaceholder": "Enter the database server domain or IP", + "database-source/databasePortPlaceholder": "Enter the database port e.g. 3306", + "database-source/databaseUserPlaceholder": "Enter the database user", + "database-source/databasePasswordPlaceholder": "Enter the database password", + "database-source/databaseNamePlaceholder": "Enter the name of the database", + "database-source/databaseFileNamePlaceholder": "Enter the full path to the database file", + "database-source/databaseSchemaPlaceholder": "Enter the initial schema of the database", + "database-source/connectionNameDefaultValue": "New_Connection_Name", "database-source/databaseTestButton": "Test", "database-source/databaseSaveButton": "Save", "database-source/databaseConnectButton": "Connect", diff --git a/extensions/database/module/langs/translation-en_GB.json b/extensions/database/module/langs/translation-en_GB.json index e39b68f00..f6c6f421b 100644 --- a/extensions/database/module/langs/translation-en_GB.json +++ b/extensions/database/module/langs/translation-en_GB.json @@ -28,6 +28,7 @@ "database-source/databaseTestButton": "Test", "database-source/databaseSchemaLabel": "Schema:", "database-source/databaseNameLabel": "Database:", + "database-source/databaseFileNameLabel": "Database file:", "database-source/databasePasswordLabel": "Password:", "database-source/databaseUserLabel": "User:", "database-source/databasePortLabel": "Port:", diff --git a/extensions/database/module/langs/translation-fr.json b/extensions/database/module/langs/translation-fr.json index f8d2b9468..ba2384135 100644 --- a/extensions/database/module/langs/translation-fr.json +++ b/extensions/database/module/langs/translation-fr.json @@ -21,7 +21,17 @@ "database-source/databaseUserLabel": "Utilisateur :", "database-source/databasePasswordLabel": "Mot de passe :", "database-source/databaseNameLabel": "Base de données :", + "database-source/databaseFileNameLabel": "Fichier de données :", "database-source/databaseSchemaLabel": "Schéma :", + "database-source/connectionNamePlaceholder": "Entrez le nom de la connexion", + "database-source/databaseHostPlaceholder": "Entrez l’adresse de l’hôte de la base de données", + "database-source/databasePortPlaceholder": "Entrez le port de la base de données e.g. 3306", + "database-source/databaseUserPlaceholder": "Entrez l’utilisateur de la base de données", + "database-source/databasePasswordPlaceholder": "Entrez le mot de passe de l’utilisateur", + "database-source/databaseNamePlaceholder": "Entrez le nom de la base de données", + "database-source/databaseFileNamePlaceholder": "Entrez le chemin du fichier base de données", + "database-source/databaseSchemaPlaceholder": "Entrez le schéma initial", + "database-source/connectionNameDefaultValue": "Nom_nouvelle_connexion", "database-source/databaseTestButton": "Test", "database-source/databaseSaveButton": "Enregistrer", "database-source/databaseConnectButton": "Connexion", diff --git a/extensions/database/module/langs/translation-it.json b/extensions/database/module/langs/translation-it.json index fca8d8507..5d4b4c141 100644 --- a/extensions/database/module/langs/translation-it.json +++ b/extensions/database/module/langs/translation-it.json @@ -20,6 +20,7 @@ "database-source/databaseUserLabel": "Utente:", "database-source/databasePasswordLabel": "Password:", "database-source/databaseNameLabel": "Database:", + "database-source/databaseFileNameLabel": "Database file:", "database-source/databaseSchemaLabel": "Schema:", "database-source/databaseTestButton": "Test", "database-source/databaseSaveButton": "Salva", diff --git a/extensions/database/module/langs/translation-jp.json b/extensions/database/module/langs/translation-jp.json index 8c428b9b6..662a8e98b 100644 --- a/extensions/database/module/langs/translation-jp.json +++ b/extensions/database/module/langs/translation-jp.json @@ -21,6 +21,7 @@ "database-source/databaseUserLabel": "User:", "database-source/databasePasswordLabel": "Password:", "database-source/databaseNameLabel": "Database:", + "database-source/databaseFileNameLabel": "Database file:", "database-source/databaseSchemaLabel": "スキーマ :", "database-source/databaseTestButton": "テスト", "database-source/databaseSaveButton": "保存", diff --git a/extensions/database/module/langs/translation-ko.json b/extensions/database/module/langs/translation-ko.json index 83584429f..52b227021 100644 --- a/extensions/database/module/langs/translation-ko.json +++ b/extensions/database/module/langs/translation-ko.json @@ -21,6 +21,7 @@ "database-source/databaseUserLabel": "사용자:", "database-source/databasePasswordLabel": "비밀번호:", "database-source/databaseNameLabel": "데이터베이스:", + "database-source/databaseFileNameLabel": "데이터베이스:", "database-source/databaseSchemaLabel": "스키마:", "database-source/databaseTestButton": "테스트", "database-source/databaseSaveButton": "저장", diff --git a/extensions/database/module/langs/translation-nb_NO.json b/extensions/database/module/langs/translation-nb_NO.json index ae2520712..f55bf0e02 100644 --- a/extensions/database/module/langs/translation-nb_NO.json +++ b/extensions/database/module/langs/translation-nb_NO.json @@ -19,6 +19,7 @@ "database-source/databaseUserLabel": "Bruker:", "database-source/databasePasswordLabel": "Passord:", "database-source/databaseNameLabel": "Database:", + "database-source/databaseFileNameLabel": "Database file:", "database-source/databaseSchemaLabel": "Skjema:", "database-source/databaseTestButton": "Test", "database-source/databaseSaveButton": "Lagre", diff --git a/extensions/database/module/langs/translation-sv.json b/extensions/database/module/langs/translation-sv.json index fe6a68cd7..677aa882f 100644 --- a/extensions/database/module/langs/translation-sv.json +++ b/extensions/database/module/langs/translation-sv.json @@ -21,6 +21,7 @@ "database-source/databaseUserLabel": "Användare:", "database-source/databasePasswordLabel": "Lösenord:", "database-source/databaseNameLabel": "Databas:", + "database-source/databaseFileNameLabel": "Databas file:", "database-source/databaseSchemaLabel": "Schema:", "database-source/databaseTestButton": "Test", "database-source/databaseSaveButton": "Spara", diff --git a/extensions/database/module/scripts/database-extension.js b/extensions/database/module/scripts/database-extension.js index ab4235945..db871124e 100644 --- a/extensions/database/module/scripts/database-extension.js +++ b/extensions/database/module/scripts/database-extension.js @@ -139,33 +139,30 @@ DatabaseExtension.handleDeleteConnectionClicked = function(connectionName) { } DatabaseExtension.handleEditConnectionClicked = function(connectionName) { - - $.get( - "command/database/saved-connection" + '?' + $.param({"connectionName": connectionName}), - null, - function(savedDatabaseConfig) { - - if(savedDatabaseConfig){ - - var savedConfig = savedDatabaseConfig.savedConnections[0]; - $( "#connectionName" ).val(savedConfig.connectionName); - $( "#databaseTypeSelect" ).val(savedConfig.databaseType); - $( "#databaseHost" ).val(savedConfig.databaseHost); - $( "#databasePort" ).val(savedConfig.databasePort); - $( "#databaseUser" ).val(savedConfig.databaseUser); - $( "#databasePassword" ).val(savedConfig.databasePassword); - $( "#initialDatabase" ).val(savedConfig.databaseName); - $( "#initialSchema" ).val(savedConfig.databaseSchema); - $( "#newConnectionControlDiv" ).hide(); - $( "#editConnectionControlDiv" ).show(); - $( "#newConnectionDiv" ).show(); - $('#sqlEditorDiv').hide(); - $("#connectionName").attr('readonly', 'readonly'); - - } - - }, - "json" - ); + $.get( + "command/database/saved-connection" + '?' + $.param({ "connectionName": connectionName }), + null, + function(savedDatabaseConfig) { + if (savedDatabaseConfig) { + var savedConfig = savedDatabaseConfig.savedConnections[0]; + $( "#connectionName" ).val(savedConfig.connectionName); + $( "select#databaseTypeSelect" ).val(savedConfig.databaseType); + Refine.DatabaseSourceUI.prototype._updateDatabaseType(savedConfig.databaseType); + + $( "#databaseHost" ).val(savedConfig.databaseHost); + $( "#databasePort" ).val(savedConfig.databasePort); + $( "#databaseUser" ).val(savedConfig.databaseUser); + $( "#databasePassword" ).val(savedConfig.databasePassword); + $( "#initialDatabase" ).val(savedConfig.databaseName); + $( "#initialSchema" ).val(savedConfig.databaseSchema); + $( "#newConnectionControlDiv" ).hide(); + $( "#editConnectionControlDiv" ).show(); + $( "#newConnectionDiv" ).show(); + $('#sqlEditorDiv').hide(); + $("#connectionName").attr('readonly', 'readonly'); + } + }, + "json" + ); } diff --git a/extensions/database/module/scripts/index/database-import-form.html b/extensions/database/module/scripts/index/database-import-form.html index cff60ed20..5bd8fe593 100644 --- a/extensions/database/module/scripts/index/database-import-form.html +++ b/extensions/database/module/scripts/index/database-import-form.html @@ -28,45 +28,44 @@ New Connection Editor
- - + +
- +
- -
- - -
- -
- - -
-
- - -
-
- - -
-
- - -
- + +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
diff --git a/extensions/database/module/scripts/index/database-source-ui.js b/extensions/database/module/scripts/index/database-source-ui.js index 84abc1c14..5ab74d9d8 100644 --- a/extensions/database/module/scripts/index/database-source-ui.js +++ b/extensions/database/module/scripts/index/database-source-ui.js @@ -64,6 +64,10 @@ Refine.DatabaseSourceUI.prototype.attachUI = function(body) { this._elmts = DOM.bind(this._body); var self = this; + self._defaultDatabaseHost = "localhost"; + self._defaultDatabaseType = $( "select#databaseTypeSelect" ).val(); + if (self._defaultDatabaseType == "") { self._defaultDatabaseType = "mysql"; } + $('#database-title').text($.i18n('database-import/title')); $('#connectionNameLabel').html($.i18n('database-source/connectionNameLabel')); $('#databaseTypeLabel').html($.i18n('database-source/databaseTypeLabel')); @@ -79,38 +83,33 @@ Refine.DatabaseSourceUI.prototype.attachUI = function(body) { $('#newConnectionButtonDiv').text($.i18n('database-source/newConnectionButtonDiv')); $('#savedConnectionSpan').text($.i18n('database-source/savedConnectionSpan')); - + $('input#connectionName').attr('placeholder', $.i18n('database-source/connectionNamePlaceholder')); + $('input#databaseHost').attr('placeholder', $.i18n('database-source/databaseHostPlaceholder')); + $('input#databasePort').attr('placeholder', $.i18n('database-source/databasePortPlaceholder')); + $('input#databaseUser').attr('placeholder', $.i18n('database-source/databaseUserPlaceholder')); + $('input#databasePassword').attr('placeholder', $.i18n('database-source/databasePasswordPlaceholder')); + $('input#initialDatabase').attr('placeholder', $.i18n('database-source/databaseNamePlaceholder')); + $('input#initialSchema').attr('placeholder', $.i18n('database-source/databaseSchemaPlaceholder')); + + $('input#connectionName').attr('value', $.i18n('database-source/connectionNameDefaultValue')); + this._elmts.newConnectionButton.click(function(evt) { self._resetDatabaseImportForm(); $( "#newConnectionDiv" ).show(); $( "#sqlEditorDiv" ).hide(); // self._body.find('.newConnectionDiv').show(); // self._body.find('.sqlEditorDiv').hide(); - }); - this._elmts.databaseTypeSelect.change(function(event) { - var type = $( "#databaseTypeSelect" ).val(); - if(type === "postgresql"){ - $( "#databaseUser" ).val("postgres"); - $( "#databasePort" ).val("5432"); - }else if(type === "mysql"){ - $( "#databaseUser" ).val("root"); - $( "#databasePort" ).val("3306"); - }else if(type === "mariadb"){ - $( "#databaseUser" ).val("root"); - $( "#databasePort" ).val("3306"); - }else if(type === "sqlite"){ - $( "#databaseUser" ).val("na"); - $( "#databasePort" ).val("0"); - $( "#databaseHost" ).val("na"); - }else{ - $( "#databaseUser" ).val("root"); - $( "#databasePort" ).val("3306"); - } + var type = $( "select#databaseTypeSelect" ).val(); + + self._updateDatabaseType(type); }); + var defaultDatabase = $( "select#databaseTypeSelect" ).val(); + self._updateDatabaseType(defaultDatabase); + this._elmts.testDatabaseButton.click(function(evt) { if(self._validateNewConnectionForm() === true){ @@ -190,7 +189,6 @@ Refine.DatabaseSourceUI.prototype.attachUI = function(body) { Refine.DatabaseSourceUI.prototype.focus = function() { }; - Refine.DatabaseSourceUI.prototype.validateQuery = function(query) { //alert("query::" + query); if(!query || query.length <= 0 ) { @@ -234,6 +232,43 @@ Refine.DatabaseSourceUI.prototype.validateQuery = function(query) { return true; }; +Refine.DatabaseSourceUI.prototype._updateDatabaseType = function(databaseType) { + if(databaseType === "postgresql") { + $( "#databaseUser" ).val("postgres"); + $( "#databasePort" ).val("5432"); + + } else if(databaseType === "mysql") { + $( "#databaseUser" ).val("root"); + $( "#databasePort" ).val("3306"); + + } else if(databaseType === "mariadb") { + $( "#databaseUser" ).val("root"); + $( "#databasePort" ).val("3306"); + + } else if(databaseType === "sqlite") { + $( "#databaseUser" ).val("na"); + $( "#databasePort" ).val("0"); + $( "#databaseHost" ).val("na"); + + } else { + $( "#databaseUser" ).val("root"); + $( "#databasePort" ).val("3306"); + databaseType = "mysql"; + } + + $("div.pure-control-group.dbtype-options").hide(); + $("div.pure-control-group.dbtype-options.dbt-"+databaseType).show(); + + if (databaseType == "sqlite") { + $('#databaseNameLabel').text($.i18n('database-source/databaseFileNameLabel')); + $('input#initialDatabase').attr('placeholder', $.i18n('database-source/databaseFileNamePlaceholder')); + + } else { + $('#databaseNameLabel').text($.i18n('database-source/databaseNameLabel')); + $('input#initialDatabase').attr('placeholder', $.i18n('database-source/databaseNamePlaceholder')); + } +}; + Refine.DatabaseSourceUI.prototype._editConnection = function(connectionInfo) { //alert("database user:" + connectionInfo.databaseUser); var self = this; @@ -473,19 +508,20 @@ Refine.DatabaseSourceUI.prototype._validateNewConnectionForm = function() { return true; }; -Refine.DatabaseSourceUI.prototype._resetDatabaseImportForm = function() { - var self = this; - $( "#connectionName" ).val("127.0.0.1"); - $( "#databaseTypeSelect" ).val("postgresql"); - $( "#databaseHost" ).val("127.0.0.1"); - $( "#databasePort" ).val("5432"); - $( "#databaseUser" ).val("postgres"); - $( "#databasePassword" ).val(""); - $( "#initialDatabase" ).val(""); - $( "#initialSchema" ).val(""); - - $( "#editConnectionControlDiv" ).hide(); - $( "#newConnectionControlDiv" ).show(); - $('#connectionName').removeAttr('readonly'); - +Refine.DatabaseSourceUI.prototype._resetDatabaseImportForm = function() { + var self = this; + + $( "#databaseHost" ).val(self._defaultDatabaseHost); + + $('input#connectionName').attr('value', $.i18n('database-source/connectionNameDefaultValue')); + $( "select#databaseTypeSelect" ).val(self._defaultDatabaseType); + self._updateDatabaseType(self._defaultDatabaseType); + + $( "#databasePassword" ).val(""); + $( "#initialDatabase" ).val(""); + $( "#initialSchema" ).val(""); + + $( "#editConnectionControlDiv" ).hide(); + $( "#newConnectionControlDiv" ).show(); + $('#connectionName').removeAttr('readonly'); };