- added version check to "changelog" dialog

This commit is contained in:
Mark Friedrich
2017-12-15 21:24:46 +01:00
parent 74a9d0fda4
commit 9961e2cbe1
9 changed files with 322 additions and 92 deletions

View File

@@ -52,6 +52,14 @@ class GitHub extends Controller\Controller {
$apiResponse = \Web::instance()->request($apiPath, $options );
if($apiResponse['body']){
$return = (object) [];
$return->releasesData = [];
$return->version = (object) [];
$return->version->current = Config::getPathfinderData('version');
$return->version->last = '';
$return->version->delta = null;
$return->version->dev = false;
// request succeeded -> format "Markdown" to "HTML"
// result is JSON formed
$releasesData = (array)json_decode($apiResponse['body']);
@@ -62,7 +70,24 @@ class GitHub extends Controller\Controller {
}
$md = \Markdown::instance();
foreach($releasesData as &$releaseData){
foreach($releasesData as $key => &$releaseData){
// check version ----------------------------------------------------------------------------------
if($key === 0){
$return->version->last = $releaseData->tag_name;
if(version_compare( $return->version->current, $return->version->last, '>')){
$return->version->dev = true;
}
}
if(
!$return->version->dev &&
version_compare( $releaseData->tag_name, $return->version->current, '>=')
){
$return->version->delta = ($key === count($releasesData) - 1) ? '>= ' . $key : $key;
}
// format body ------------------------------------------------------------------------------------
if(isset($releaseData->body)){
$body = $releaseData->body;
@@ -78,7 +103,10 @@ class GitHub extends Controller\Controller {
$releaseData->body = $md->convert( trim($body) );
}
}
$f3->set($cacheKey, $releasesData, $ttl);
$return->releasesData = $releasesData;
$f3->set($cacheKey, $return, $ttl);
}else{
// request failed -> cache failed result (respect API request limit)
$f3->set($cacheKey, false, 60 * 5);

View File

@@ -16,7 +16,7 @@ define([
'dialog/account_settings',
'dialog/notification',
'dialog/manual',
'dialog/releases',
'dialog/changelog',
'dialog/credit'
], function($, Init, Util, Render, Gallery, bootbox) {
@@ -81,7 +81,7 @@ define([
*/
let setVersionLinkObserver = function(){
$('.' + config.navigationVersionLinkClass).off('click').on('click', function(e){
$.fn.releasesDialog();
$.fn.changelogsDialog();
});
};

View File

@@ -0,0 +1,140 @@
/**
* changelog dialog (GitHub API repository information)
*/
define([
'jquery',
'app/init',
'app/util',
'app/render',
'bootbox'
], ($, Init, Util, Render, bootbox) => {
'use strict';
let config = {
changelogDialogClass: 'pf-changelog-dialog', // class for "changelog" dialog
dynamicMessageContainerClass: 'pf-dynamic-message-container', // class for "dynamic" (JS) message container
timelineClass: 'timeline' // class for "timeline"
};
/**
* show version information
* @param changelogDialog
* @param versionData
*/
let showVersion = (changelogDialog, versionData) => {
let type = 'error';
let title = versionData.current;
let text = 'Installed version check failed';
if(versionData.dev){
// developer version
type = 'info';
title = versionData.current + ' (dev)';
text = 'This installation is ahead of current stable version <kbd>' + versionData.last + '</kbd>.';
}else{
// standard version
if(versionData.delta === 0){
// last stable
type = 'success';
title = versionData.current;
text = 'This installation is up2date.';
}else{
// outdated...
type = 'warning';
title = versionData.current;
text = 'This installation is ' + versionData.delta + ' version behind current stable <kbd>' + versionData.last + '</kbd>.';
}
}
changelogDialog.find('.' + config.dynamicMessageContainerClass).showMessage({
dismissible: false,
type: type,
title: title,
text: text
});
};
/**
* load changelog information in dialog
* @param changelogDialog
*/
let loadDialogData = (changelogDialog) => {
// lock dialog
let dialogContent = changelogDialog.find('.modal-content');
dialogContent.showLoadingAnimation();
$.ajax({
type: 'POST',
url: Init.path.gitHubReleases,
dataType: 'json',
context: {
changelogDialog: changelogDialog
}
}).done(function(data){
let changelogDialog = this.changelogDialog;
let versionData = data.version;
let releasesData = data.releasesData;
showVersion(changelogDialog, versionData);
requirejs(['text!templates/ui/timeline_element.html', 'mustache'], function(template, Mustache) {
for(let i = 0; i < releasesData.length; i++){
let releaseData = releasesData[i];
// template vars
let data = {
isFirst: (i === 0),
isOdd: (i % 2 !== 0),
releaseDate: releaseData.published_at.substr(0, 10),
releaseData: releaseData
};
let content = Mustache.render(template, data);
changelogDialog.find('ul.' + config.timelineClass).append(content);
}
changelogDialog.find('.timeline > li').velocity('transition.expandIn', {
stagger: 300,
duration: 240,
//display: 'auto',
complete: function(){}
});
});
}).fail(function( jqXHR, status, error) {
let reason = status + ' ' + jqXHR.status + ': ' + error;
Util.showNotify({title: jqXHR.status + ': login', text: reason, type: 'error'});
}).always(function() {
dialogContent.hideLoadingAnimation();
});
};
/**
* show changelog dialog
*/
$.fn.changelogsDialog = function(){
let content = $('<div>').append(
$('<div>', {
class: config.dynamicMessageContainerClass
}),
$('<ul>', {
class: config.timelineClass
})
);
let changelogDialog = bootbox.dialog({
className: config.changelogDialogClass,
title: 'Changelog',
size: 'large',
message: content
});
// after modal is shown =======================================================================
changelogDialog.on('shown.bs.modal', function(e) {
loadDialogData(changelogDialog);
});
};
});

View File

@@ -1,84 +0,0 @@
/**
* releases dialog (GitHub API repository information)
*/
define([
'jquery',
'app/init',
'app/util',
'app/render',
'bootbox'
], function($, Init, Util, Render, bootbox) {
'use strict';
let config = {
releasesDialogClass: 'pf-releases-dialog' // class for "Releases" dialog
};
/**
* load release information in dialog
* @param releasesDialog
*/
let loadDialogData = function(releasesDialog){
// lock dialog
let dialogContent = releasesDialog.find('.modal-content');
dialogContent.showLoadingAnimation();
$.ajax({
type: 'POST',
url: Init.path.gitHubReleases,
// data: updatedMapData,
dataType: 'json'
}).done(function(releasesData){
requirejs(['text!templates/ui/timeline_element.html', 'mustache'], function(template, Mustache) {
for(let i = 0; i < releasesData.length; i++){
let releaseData = releasesData[i];
// template vars
let data = {
isFirst: (i === 0),
isOdd: (i % 2 !== 0),
releaseDate: releaseData.published_at.substr(0, 10),
releaseData: releaseData
};
let content = Mustache.render(template, data);
releasesDialog.find('ul.timeline').append(content);
}
$('.timeline > li').velocity('transition.expandIn', {
stagger: 300,
duration: 240,
//display: 'auto',
complete: function(){}
});
});
}).fail(function( jqXHR, status, error) {
let reason = status + ' ' + jqXHR.status + ': ' + error;
Util.showNotify({title: jqXHR.status + ': login', text: reason, type: 'error'});
}).always(function() {
dialogContent.hideLoadingAnimation();
});
};
/**
* show releases dialog
*/
$.fn.releasesDialog = function(){
let content = '<ul class="timeline"></ul>';
let releasesDialog = bootbox.dialog({
className: config.releasesDialogClass,
title: 'Releases',
size: 'large',
message: content
});
// after modal is shown =======================================================================
releasesDialog.on('shown.bs.modal', function(e) {
loadDialogData(releasesDialog);
});
};
});

File diff suppressed because one or more lines are too long

View File

@@ -16,7 +16,7 @@ define([
'dialog/account_settings',
'dialog/notification',
'dialog/manual',
'dialog/releases',
'dialog/changelog',
'dialog/credit'
], function($, Init, Util, Render, Gallery, bootbox) {
@@ -81,7 +81,7 @@ define([
*/
let setVersionLinkObserver = function(){
$('.' + config.navigationVersionLinkClass).off('click').on('click', function(e){
$.fn.releasesDialog();
$.fn.changelogsDialog();
});
};

View File

@@ -0,0 +1,140 @@
/**
* changelog dialog (GitHub API repository information)
*/
define([
'jquery',
'app/init',
'app/util',
'app/render',
'bootbox'
], ($, Init, Util, Render, bootbox) => {
'use strict';
let config = {
changelogDialogClass: 'pf-changelog-dialog', // class for "changelog" dialog
dynamicMessageContainerClass: 'pf-dynamic-message-container', // class for "dynamic" (JS) message container
timelineClass: 'timeline' // class for "timeline"
};
/**
* show version information
* @param changelogDialog
* @param versionData
*/
let showVersion = (changelogDialog, versionData) => {
let type = 'error';
let title = versionData.current;
let text = 'Installed version check failed';
if(versionData.dev){
// developer version
type = 'info';
title = versionData.current + ' (dev)';
text = 'This installation is ahead of current stable version <kbd>' + versionData.last + '</kbd>.';
}else{
// standard version
if(versionData.delta === 0){
// last stable
type = 'success';
title = versionData.current;
text = 'This installation is up2date.';
}else{
// outdated...
type = 'warning';
title = versionData.current;
text = 'This installation is ' + versionData.delta + ' version behind current stable <kbd>' + versionData.last + '</kbd>.';
}
}
changelogDialog.find('.' + config.dynamicMessageContainerClass).showMessage({
dismissible: false,
type: type,
title: title,
text: text
});
};
/**
* load changelog information in dialog
* @param changelogDialog
*/
let loadDialogData = (changelogDialog) => {
// lock dialog
let dialogContent = changelogDialog.find('.modal-content');
dialogContent.showLoadingAnimation();
$.ajax({
type: 'POST',
url: Init.path.gitHubReleases,
dataType: 'json',
context: {
changelogDialog: changelogDialog
}
}).done(function(data){
let changelogDialog = this.changelogDialog;
let versionData = data.version;
let releasesData = data.releasesData;
showVersion(changelogDialog, versionData);
requirejs(['text!templates/ui/timeline_element.html', 'mustache'], function(template, Mustache) {
for(let i = 0; i < releasesData.length; i++){
let releaseData = releasesData[i];
// template vars
let data = {
isFirst: (i === 0),
isOdd: (i % 2 !== 0),
releaseDate: releaseData.published_at.substr(0, 10),
releaseData: releaseData
};
let content = Mustache.render(template, data);
changelogDialog.find('ul.' + config.timelineClass).append(content);
}
changelogDialog.find('.timeline > li').velocity('transition.expandIn', {
stagger: 300,
duration: 240,
//display: 'auto',
complete: function(){}
});
});
}).fail(function( jqXHR, status, error) {
let reason = status + ' ' + jqXHR.status + ': ' + error;
Util.showNotify({title: jqXHR.status + ': login', text: reason, type: 'error'});
}).always(function() {
dialogContent.hideLoadingAnimation();
});
};
/**
* show changelog dialog
*/
$.fn.changelogsDialog = function(){
let content = $('<div>').append(
$('<div>', {
class: config.dynamicMessageContainerClass
}),
$('<ul>', {
class: config.timelineClass
})
);
let changelogDialog = bootbox.dialog({
className: config.changelogDialogClass,
title: 'Changelog',
size: 'large',
message: content
});
// after modal is shown =======================================================================
changelogDialog.on('shown.bs.modal', function(e) {
loadDialogData(changelogDialog);
});
};
});

View File

@@ -3,5 +3,5 @@
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><i class="fa fa-close"></i></button>
{{/dismissible}}
<span class="txt-color {{messageTextClass}}">{{title}}</span>
<small>{{text}}</small>
<small>{{{text}}}</small>
</div>

View File

@@ -219,6 +219,12 @@
margin-bottom: 5px;
}
}
// changelog
.pf-changelog-dialog{
.pf-dynamic-message-container{
margin-bottom: 20px;
}
}
// credits dialog =============================================================
.pf-credits-dialog{