Skip to content

Commit

Permalink
Weekly progress.
Browse files Browse the repository at this point in the history
1). Microhistory added in classes for modular code
2). Code is structured and camel casing of varables is done for removing linter warnings.
3). JQuery plugins are added in some files.
4). jQplot is working for server_status_queries and server_status_monitor.
5). Work started for Dabatase, SQl and Table files.
Some changes are stll left for server_status_monitor and sql.js
Signed-Off-By: Piyush Vijay <piyushvijay.1997@gmail.com>
  • Loading branch information
Piyush3079 committed Aug 10, 2018
1 parent b4237ac commit 8c986d8
Show file tree
Hide file tree
Showing 49 changed files with 5,100 additions and 496 deletions.
4 changes: 2 additions & 2 deletions db_search.php
Expand Up @@ -21,9 +21,9 @@
$response = Response::getInstance();
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('db_search.js');
$scripts->addFile('db_search');
$scripts->addFile('sql.js');
$scripts->addFile('makegrid.js');
// $scripts->addFile('makegrid.js');

require 'libraries/db_common.inc.php';

Expand Down
4 changes: 2 additions & 2 deletions js/src/ajax.js
Expand Up @@ -15,6 +15,7 @@ import { PMA_ensureNaviSettings,
PMA_disableNaviSettings
} from './functions/navigation';
import { isStorageSupported } from './functions/config';
import PMA_MicroHistory from './classes/MicroHistory';
/**
* This object handles ajax requests for pages. It also
* handles the reloading of the main menu and scripts.
Expand Down Expand Up @@ -367,7 +368,6 @@ export let AJAX = {
if (typeof onsubmit !== 'function' || onsubmit.apply(this, [event])) {
AJAX.active = true;
AJAX.$msgbox = PMA_ajaxShowMessage();

$.post(url, params, AJAX.responseHandler);
}
}
Expand Down Expand Up @@ -599,7 +599,7 @@ export let AJAX = {
var fileImports = ['server_privileges', 'server_databases', 'error_report', 'navigation', 'server_status_advisor',
'server_status_processes', 'server_status_variables', 'server_plugins', 'server_status_sorter', 'server_status_queries',
'server_status_monitor', 'server_variables', 'server_user_groups', 'replication', 'export', 'import', 'config',
'page_settings', 'shortcuts_handler'
'page_settings', 'shortcuts_handler', 'db_search', 'sql', 'functions'
];
if ($.inArray(file, fileImports) !== -1) {
// Dynamic import to load the files dynamically
Expand Down
13 changes: 10 additions & 3 deletions js/src/classes/Chart.js
@@ -1,7 +1,14 @@
import { $ } from '../utils/extend_jquery';
import 'updated-jqplot';
import '../../../node_modules/updated-jqplot/dist/plugins/jqplot.pieRenderer';
import '../../../node_modules/updated-jqplot/dist/plugins/jqplot.highlighter';
import '../../../node_modules/updated-jqplot/dist/plugins/jqplot.enhancedPieLegendRenderer';
window.test2 = $;

/**
* Chart type enumerations
*/
var ChartType = {
export var ChartType = {
LINE : 'line',
SPLINE : 'spline',
AREA : 'area',
Expand All @@ -15,7 +22,7 @@ var ChartType = {
/**
* Column type enumeration
*/
var ColumnType = {
export var ColumnType = {
STRING : 'string',
NUMBER : 'number',
BOOLEAN : 'boolean',
Expand Down Expand Up @@ -153,7 +160,7 @@ ScatterChart.prototype.validateColumns = function (dataTable) {
/**
* The data table contains column information and data for the chart.
*/
var DataTable = function () {
export var DataTable = function () {
var columns = [];
var data = null;

Expand Down
59 changes: 59 additions & 0 deletions js/src/classes/CommonActions.js
@@ -0,0 +1,59 @@
import CommonParams from '../variables/common_params';
import { AJAX } from '../ajax';

/**
* Holds common parameters such as server, db, table, etc
*
* The content for this is normally loaded from Header.php or
* Response.php and executed by ajax.js
*/
export var PMA_commonActions = {
/**
* Saves the database name when it's changed
* and reloads the query window, if necessary
*
* @param {string} newDb newDb The name of the new database
*
* @return {void}
*/
setDb: function (newDb) {
if (newDb !== CommonParams.get('db')) {
CommonParams.setAll({ 'db': newDb, 'table': '' });
}
},
/**
* Opens a database in the main part of the page
*
* @param {string} newDb The name of the new database
*
* @return void
*/
openDb: function (newDb) {
CommonParams
.set('db', newDb)
.set('table', '');
this.refreshMain(
CommonParams.get('opendb_url')
);
},
/**
* Refreshes the main frame
*
* @param mixed url Undefined to refresh to the same page
* String to go to a different page, e.g: 'index.php'
*
* @return void
*/
refreshMain: function (url, callback) {
if (! url) {
url = $('#selflink').find('a').attr('href');
url = url.substring(0, url.indexOf('?'));
}
url += CommonParams.getUrlQuery();
$('<a />', { href: url })
.appendTo('body')
.trigger('click')
.remove();
AJAX._callback = callback;
}
};
5 changes: 4 additions & 1 deletion js/src/classes/Console/PMA_ConsoleResizer.js
@@ -1,9 +1,12 @@
/* vim: set expandtab sw=4 ts=4 sts=4: */

/**
* Resizer object
* Careful: this object UI logics highly related with functions under PMA_console
* Resizing min-height is 32, if small than it, console will collapse
* @namespace ConsoleResizer
*/
export default class PMA_consoleResizer {
export default class ConsoleResizer {
constructor (instance) {
this._posY = 0;
this._height = 0;
Expand Down
14 changes: 9 additions & 5 deletions js/src/classes/Console/PMA_consoleBookmarks.js
@@ -1,7 +1,11 @@
/* vim: set expandtab sw=4 ts=4 sts=4: */
import CommonParams from '../../variables/common_params';
import { PMA_Messages as messages } from '../../variables/export_variables';
/**
* @namespace ConsoleBookmarks
* Console bookmarks card, and bookmarks items management object
*/
export default class PMA_consoleBookmarks {
export default class ConsoleBookmarks {
constructor (instance) {
this._bookmarks = [];
this.pmaConsole = null;
Expand All @@ -15,7 +19,7 @@ export default class PMA_consoleBookmarks {
this.pmaConsole = instance;
this.initialize();
}
addBookmark (queryString, targetDb, label, isShared, id) {
addBookmark (queryString, targetDb, label, isShared) {
$('#pma_bookmarks').find('.add [name=shared]').prop('checked', false);
$('#pma_bookmarks').find('.add [name=label]').val('');
$('#pma_bookmarks').find('.add [name=targetdb]').val('');
Expand All @@ -42,7 +46,7 @@ export default class PMA_consoleBookmarks {
refresh () {
$.get('import.php',
{ ajax_request: true,
server: PMA_commonParams.get('server'),
server: CommonParams.get('server'),
console_bookmark_refresh: 'refresh' },
function (data) {
if (data.console_message_bookmark) {
Expand Down Expand Up @@ -71,7 +75,7 @@ export default class PMA_consoleBookmarks {
$('#pma_bookmarks').find('.card.add [name=submit]').click(function () {
if ($('#pma_bookmarks').find('.card.add [name=label]').val().length === 0
|| self.pmaConsole.pmaConsoleInput.getText('bookmark').length === 0) {
alert(PMA_messages.strFormEmpty);
alert(messages.strFormEmpty);
return;
}
$(this).prop('disabled', true);
Expand All @@ -80,7 +84,7 @@ export default class PMA_consoleBookmarks {
ajax_request: true,
console_bookmark_add: 'true',
label: $('#pma_bookmarks').find('.card.add [name=label]').val(),
server: PMA_commonParams.get('server'),
server: CommonParams.get('server'),
db: $('#pma_bookmarks').find('.card.add [name=targetdb]').val(),
bookmark_query: self.pmaConsole.pmaConsoleInput.getText('bookmark'),
shared: $('#pma_bookmarks').find('.card.add [name=shared]').prop('checked') },
Expand Down
31 changes: 22 additions & 9 deletions js/src/classes/Console/PMA_consoleDebug.js
@@ -1,4 +1,17 @@
export default class PMA_consoleDebug {
/* vim: set expandtab sw=4 ts=4 sts=4: */

/**
* Module import
*/
import { PMA_Messages as messages } from '../../variables/export_variables';
import { PMA_sprintf } from '../../utils/sprintf';
import { escapeHtml } from '../../utils/Sanitise';

/**
* Console debug object
* @namespace ConsoleDebug
*/
export default class ConsoleDebug {
constructor (instance) {
this.pmaConsole = null;
this._config = {
Expand Down Expand Up @@ -123,7 +136,7 @@ export default class PMA_consoleDebug {
$('<div class="message welcome">')
.text(
PMA_sprintf(
PMA_messages.strConsoleDebugArgsSummary,
messages.strConsoleDebugArgsSummary,
dbgStep.args.length
)
)
Expand Down Expand Up @@ -186,12 +199,12 @@ export default class PMA_consoleDebug {
$('<div class="action_content">')
.append(
'<span class="action dbg_show_args">' +
PMA_messages.strConsoleDebugShowArgs +
messages.strConsoleDebugShowArgs +
'</span> '
)
.append(
'<span class="action dbg_hide_args">' +
PMA_messages.strConsoleDebugHideArgs +
messages.strConsoleDebugHideArgs +
'</span> '
)
);
Expand Down Expand Up @@ -259,7 +272,7 @@ export default class PMA_consoleDebug {
.text((parseInt(i) + 1) + '.')
.append(
$('<span class="time">').text(
PMA_messages.strConsoleDebugTimeTaken +
messages.strConsoleDebugTimeTaken +
' ' + queryInfo[i].time + 's' +
' (' + ((queryInfo[i].time * 100) / totalTime).toFixed(3) + '%)'
)
Expand Down Expand Up @@ -304,7 +317,7 @@ export default class PMA_consoleDebug {
}
if (debugJson === false) {
$('#debug_console').find('.debug>.welcome').text(
PMA_messages.strConsoleDebugError
messages.strConsoleDebugError
);
return;
}
Expand Down Expand Up @@ -336,7 +349,7 @@ export default class PMA_consoleDebug {
$('#debug_console').find('.debug>.welcome').append(
$('<span class="debug_summary">').text(
PMA_sprintf(
PMA_messages.strConsoleDebugSummary,
messages.strConsoleDebugSummary,
totalUnique,
totalExec,
totalTime
Expand All @@ -351,7 +364,7 @@ export default class PMA_consoleDebug {

// For sorting queries
function sortByTime (a, b) {
var order = ((PMA_console.config.Order === 'asc') ? 1 : -1);
var order = ((this.pmaConsole.config.Order === 'asc') ? 1 : -1);
if (Array.isArray(a) && Array.isArray(b)) {
// It is grouped
var timeA = 0;
Expand All @@ -370,7 +383,7 @@ export default class PMA_consoleDebug {
}

function sortByCount (a, b) {
var order = ((PMA_console.config.Oorder === 'asc') ? 1 : -1);
var order = ((this.pmaConsole.config.Order === 'asc') ? 1 : -1);
return (a.length - b.length) * order;
}

Expand Down
26 changes: 24 additions & 2 deletions js/src/classes/Console/PMA_consoleInput.js
@@ -1,7 +1,14 @@
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Console input object
* @namespace ConsoleInput
*/
export default class PMA_consoleInput {
export default class ConsoleInput {
/**
* @constructor
*
* @param {object} pmaConsoleInstance Instance of pma console
*/
constructor (pmaConsoleInstance) {
/**
* @var array, contains Codemirror objects or input jQuery objects
Expand All @@ -23,9 +30,16 @@ export default class PMA_consoleInput {
* @access private
*/
this._historyPreserveCurrent = null;

/**
* @var object
* @access private
*/
this.pmaConsole = null;

/**
* Bindings for accessing the instance of the class using this
* insde the methods.
*/
this.setPmaConsole = this.setPmaConsole.bind(this);
this.initialize = this.initialize.bind(this);
this._historyNavigate = this._historyNavigate.bind(this);
Expand Down Expand Up @@ -214,6 +228,7 @@ export default class PMA_consoleInput {
*
* @param string text
* @param string target
*
* @return void
*/
setText (text, target) {
Expand All @@ -237,6 +252,13 @@ export default class PMA_consoleInput {
}
}
}
/**
* Used for getting the text of input
*
* @param {string} target
*
* @return {string}
*/
getText (target) {
if (this._codemirror) {
switch (target) {
Expand Down
13 changes: 10 additions & 3 deletions js/src/classes/Console/PMA_consoleMessages.js
@@ -1,7 +1,14 @@
/* vim: set expandtab sw=4 ts=4 sts=4: */

/**
* Module import
*/
import { PMA_Messages as messages } from '../../variables/export_variables';
/**
* Console messages, and message items management object
* @namespace ConsoleMessages
*/
export default class PMA_consoleMessages {
export default class ConsoleMessages {
constructor (instance) {
this.pmaConsole = null;
this.clear = this.clear.bind(this);
Expand Down Expand Up @@ -167,7 +174,7 @@ export default class PMA_consoleMessages {
$targetMessage.find('.action.requery').click(function () {
var query = $(this).parent().siblings('.query').text();
var $message = $(this).closest('.message');
if (confirm(PMA_messages.strConsoleRequeryConfirm + '\n' +
if (confirm(messages.strConsoleRequeryConfirm + '\n' +
(query.length < 100 ? query : query.slice(0, 100) + '...'))
) {
self.pmaConsole.execute(query, { db: $message.attr('targetdb'), table: $message.attr('targettable') });
Expand All @@ -189,7 +196,7 @@ export default class PMA_consoleMessages {
});
$targetMessage.find('.action.delete_bookmark').click(function () {
var $message = $(this).closest('.message');
if (confirm(PMA_messages.strConsoleDeleteBookmarkConfirm + '\n' + $message.find('.bookmark_label').text())) {
if (confirm(messages.strConsoleDeleteBookmarkConfirm + '\n' + $message.find('.bookmark_label').text())) {
$.post('import.php',
{
server: PMA_commonParams.get('server'),
Expand Down
3 changes: 2 additions & 1 deletion js/src/classes/ErrorReport.js
Expand Up @@ -8,7 +8,7 @@ import CommonParams from '../variables/common_params';
import { PMA_ajaxShowMessage } from '../utils/show_ajax_messages';
import { PMA_getImage } from '../functions/get_image';
import TraceKit from 'tracekit';
import { jQuery as $ } from '../utils/JqueryExtended';
import { $ } from '../utils/JqueryExtended';

/**
* This Object uses the library TraceKit to generate the backtrace of the
Expand Down Expand Up @@ -39,6 +39,7 @@ var ErrorReport = {
* @return void
*/
error_handler: function (exception) {
console.error(exception);
if (exception.name === null || typeof(exception.name) === 'undefined') {
exception.name = ErrorReport._extractExceptionName(exception);
}
Expand Down

0 comments on commit 8c986d8

Please sign in to comment.