Skip to content

Commit

Permalink
Refactor home.js file
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Feb 6, 2022
1 parent 11c9458 commit 2889205
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"esversion" : 6,

// Show more errors
"maxerr" : 1000,

Expand Down
58 changes: 38 additions & 20 deletions js/src/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const GitInfo = {
* @param {string} str
* @return {number | false}
*/
parseVersionString: function (str) {
parseVersionString: str => {
if (typeof(str) !== 'string') {
return false;
}
Expand Down Expand Up @@ -37,7 +37,7 @@ const GitInfo = {
* Indicates current available version on main page.
* @param {object} data
*/
currentVersion: function (data) {
currentVersion: data => {
if (data && data.version && data.date) {
const current = GitInfo.parseVersionString($('span.version').text());
const latest = GitInfo.parseVersionString(data.version);
Expand Down Expand Up @@ -96,7 +96,7 @@ const GitInfo = {
/**
* Loads Git revision data from ajax for index.php
*/
displayGitRevision: function () {
displayGitRevision: () => {
$('#is_git_revision').remove();
$('#li_pma_version_git').remove();
$.get(
Expand All @@ -106,30 +106,22 @@ const GitInfo = {
'ajax_request': true,
'no_debug': true
},
function (data) {
data => {
if (typeof data !== 'undefined' && data.success === true) {
$(data.message).insertAfter('#li_pma_version');
}
}
);
}
};

AJAX.registerTeardown('home.js', function () {
$('#themesModal').off('show.bs.modal');
});

AJAX.registerOnload('home.js', function () {
$('#themesModal').on('show.bs.modal', function () {
$.get('index.php?route=/themes', function (data) {
$('#themesModal .modal-body').html(data.themes);
});
});
},

/**
* Load version information asynchronously.
*/
if ($('li.jsversioncheck').length > 0) {
loadVersion: () => {
if ($('li.jsversioncheck').length === 0) {
return;
}

$.ajax({
dataType: 'json',
url: 'index.php?route=/version-check',
Expand All @@ -139,9 +131,35 @@ AJAX.registerOnload('home.js', function () {
},
success: GitInfo.currentVersion
});
}
},

showVersion: () => {
GitInfo.loadVersion();
if ($('#is_git_revision').length === 0) {
return;
}

if ($('#is_git_revision').length > 0) {
setTimeout(GitInfo.displayGitRevision, 10);
}
};

/**
* @implements EventListener
*/
const ThemesManager = {
handleEvent: () => {
$.get('index.php?route=/themes', data => {
$('#themesModal .modal-body').html(data.themes);
});
}
};

AJAX.registerTeardown('home.js', () => {
$('#themesModal').off('show.bs.modal');
});

AJAX.registerOnload('home.js', () => {
$('#themesModal').on('show.bs.modal', ThemesManager.handleEvent);

GitInfo.showVersion();
});

0 comments on commit 2889205

Please sign in to comment.