Added content upgrade.
parent
05f07e5949
commit
dc2c092bc7
|
@ -300,6 +300,13 @@ interface H5PFrameworkInterface {
|
||||||
* Get content without cache.
|
* Get content without cache.
|
||||||
*/
|
*/
|
||||||
public function getNotCached();
|
public function getNotCached();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get number of contents using library as main library.
|
||||||
|
*
|
||||||
|
* @param int $library_id
|
||||||
|
*/
|
||||||
|
public function getNumContent($library_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1719,6 +1726,35 @@ class H5PCore {
|
||||||
|
|
||||||
return $embedType;
|
return $embedType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the absolute version for the library as a human readable string.
|
||||||
|
*
|
||||||
|
* @param object $library
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function libraryVersion($library) {
|
||||||
|
return $library->major_version . '.' . $library->minor_version . '.' . $library->patch_version;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detemine which versions content with the given library can be upgraded to.
|
||||||
|
*
|
||||||
|
* @param object $library
|
||||||
|
* @param array $versions
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_upgrades($library, $versions) {
|
||||||
|
$upgrades = array();
|
||||||
|
|
||||||
|
foreach ($versions as $upgrade) {
|
||||||
|
if ($upgrade->major_version > $library->major_version || $upgrade->major_version === $library->major_version && $upgrade->minor_version > $library->minor_version) {
|
||||||
|
$upgrades[$upgrade->id] = H5PCore::libraryVersion($upgrade);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $upgrades;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 4.7 KiB |
|
@ -0,0 +1,147 @@
|
||||||
|
(function ($) {
|
||||||
|
var info, outData, $container, $throbber, throbberText, majorVersion, minorVersion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate html for version select.
|
||||||
|
*
|
||||||
|
* @param {Object} versions
|
||||||
|
* @returns {String}
|
||||||
|
*/
|
||||||
|
var getVersionSelect = function (versions) {
|
||||||
|
var html = '';
|
||||||
|
for (var id in versions) {
|
||||||
|
html += '<option value="' + id + '">' + versions[id] + '</option>';
|
||||||
|
}
|
||||||
|
if (html !== '') {
|
||||||
|
html = '<select>' + html + '</select>';
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process the current batch of parameters.
|
||||||
|
*
|
||||||
|
* @param {Object} params
|
||||||
|
*/
|
||||||
|
var processParameters = function (inData) {
|
||||||
|
var upgraded = {};
|
||||||
|
|
||||||
|
var i = 0;
|
||||||
|
for (var id in inData.params) {
|
||||||
|
if (!inData.params.hasOwnProperty(id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var param = JSON.parse(inData.params[id]);
|
||||||
|
for (var major in H5PUpgrades) {
|
||||||
|
if (!H5PUpgrades.hasOwnProperty(major) || major < info.majorVersion || major > majorVersion) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var minor in H5PUpgrades[major]) {
|
||||||
|
if (!H5PUpgrades[major].hasOwnProperty(major) || minor <= info.minorVersion || minor > minorVersion) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
param = H5PUpgrades[major][minor](param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
upgraded[id] = JSON.stringify(param);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
$throbber.text(throbberText + Math.round((info.total - inData.left + i) / (info.total / 100)) + ' %') ;
|
||||||
|
}
|
||||||
|
|
||||||
|
outData.params = JSON.stringify(upgraded);
|
||||||
|
outData.token = inData.token;
|
||||||
|
|
||||||
|
// Get next round of data to process.
|
||||||
|
getParameters();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles errors while processing parameters.
|
||||||
|
*
|
||||||
|
* @param {Object} params
|
||||||
|
*/
|
||||||
|
var process = function (inData) {
|
||||||
|
// Script is loaded. Start processing.
|
||||||
|
try {
|
||||||
|
processParameters(inData);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
$container.html('An error occurred while processing parameters: ' + err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the next batch of parameters.
|
||||||
|
*/
|
||||||
|
var getParameters = function () {
|
||||||
|
$.post(info.url, outData, function (inData) {
|
||||||
|
if (!(inData instanceof Object)) {
|
||||||
|
// Print errors from backend
|
||||||
|
$container.html(inData);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (inData.left === '0') {
|
||||||
|
$container.html(info.done);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inData.script !== undefined) {
|
||||||
|
$.ajax({
|
||||||
|
dataType: 'script',
|
||||||
|
cache: true,
|
||||||
|
url: inData.script
|
||||||
|
}).done(function () {
|
||||||
|
// Start processing
|
||||||
|
process(inData);
|
||||||
|
}).fail(function () {
|
||||||
|
$container.html('Error: Could not load upgrade script.');
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Continue processing
|
||||||
|
process(inData);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Initialize
|
||||||
|
$(document).ready(function () {
|
||||||
|
// Get library info
|
||||||
|
info = H5PIntegration.getLibraryInfo();
|
||||||
|
|
||||||
|
// Get and reset container
|
||||||
|
$container = $('#h5p-admin-container').html('<p>' + info.message + '</p>');
|
||||||
|
|
||||||
|
// Make it possible to select version
|
||||||
|
var $version = $(getVersionSelect(info.versions)).appendTo($container);
|
||||||
|
|
||||||
|
// Add "go" button
|
||||||
|
$('<button/>', {
|
||||||
|
class: 'h5p-admin-upgrade-button',
|
||||||
|
text: info.buttonLabel,
|
||||||
|
click: function () {
|
||||||
|
outData = {
|
||||||
|
libraryId: $version.val(),
|
||||||
|
token: info.token
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get version
|
||||||
|
var version = info.versions[outData.libraryId];
|
||||||
|
var versionLevels = version.split('.', 3);
|
||||||
|
majorVersion = versionLevels[0];
|
||||||
|
minorVersion = versionLevels[1];
|
||||||
|
|
||||||
|
throbberText = 'Upgrading to ' + version + '...';
|
||||||
|
$throbber = H5PUtils.throbber(throbberText);
|
||||||
|
$container.html('').append($throbber);
|
||||||
|
|
||||||
|
// Start upgrade progress
|
||||||
|
getParameters();
|
||||||
|
}
|
||||||
|
}).appendTo($container);
|
||||||
|
});
|
||||||
|
})(H5P.jQuery);
|
|
@ -41,7 +41,7 @@ var H5PLibraryDetails= H5PLibraryDetails || {};
|
||||||
|
|
||||||
var count;
|
var count;
|
||||||
if (H5PLibraryDetails.library.notCached !== undefined) {
|
if (H5PLibraryDetails.library.notCached !== undefined) {
|
||||||
count = -1;
|
count = H5PIntegration.i18n.H5P.NA;
|
||||||
}
|
}
|
||||||
else if (H5PLibraryDetails.library.content === undefined) {
|
else if (H5PLibraryDetails.library.content === undefined) {
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
|
@ -33,25 +33,38 @@ var H5PLibraryList= H5PLibraryList || {};
|
||||||
$table.addClass('libraries');
|
$table.addClass('libraries');
|
||||||
|
|
||||||
// Add libraries
|
// Add libraries
|
||||||
|
var t = H5PIntegration.i18n.H5P;
|
||||||
$.each (libraries.listData, function (index, library) {
|
$.each (libraries.listData, function (index, library) {
|
||||||
var $libraryRow = H5PUtils.createTableRow([
|
var $libraryRow = H5PUtils.createTableRow([
|
||||||
library.name,
|
library.title,
|
||||||
library.machineName,
|
library.numContent,
|
||||||
library.contentCount,
|
library.numContentDependencies === -1 ? t.NA : library.numContentDependencies,
|
||||||
library.libraryDependencyCount,
|
library.numLibraryDependencies,
|
||||||
'<div class="h5p-admin-buttons-wrapper"><button class="h5p-admin-view-library"></button>' +
|
'<div class="h5p-admin-buttons-wrapper">\
|
||||||
'<button class="h5p-admin-delete-library"></button></div>'
|
<button class="h5p-admin-upgrade-library"></button>\
|
||||||
|
<button class="h5p-admin-view-library" title="' + t.viewLibrary + '"></button>\
|
||||||
|
<button class="h5p-admin-delete-library"></button>\
|
||||||
|
</div>'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if (library.upgradeUrl !== null && library.numContent !== '0') {
|
||||||
|
$('.h5p-admin-upgrade-library', $libraryRow).attr('title', t.upgradeLibrary).click(function () {
|
||||||
|
window.location.href = library.upgradeUrl;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$('.h5p-admin-upgrade-library', $libraryRow).attr('disabled', true);
|
||||||
|
}
|
||||||
|
|
||||||
// Open details view when clicked
|
// Open details view when clicked
|
||||||
$('.h5p-admin-view-library', $libraryRow).on('click', function () {
|
$('.h5p-admin-view-library', $libraryRow).on('click', function () {
|
||||||
window.location.href = library.detailsUrl;
|
window.location.href = library.detailsUrl;
|
||||||
});
|
});
|
||||||
|
|
||||||
var $deleteButton = $('.h5p-admin-delete-library', $libraryRow);
|
var $deleteButton = $('.h5p-admin-delete-library', $libraryRow);
|
||||||
if (library.contentCount !== 0 || library.libraryDependencyCount !== 0) {
|
if (library.numContent !== '0' || library.numContentDependencies !== '0' || library.numLibraryDependencies !== '0') {
|
||||||
// Disabled delete if content.
|
// Disabled delete if content.
|
||||||
$deleteButton.attr('disabled', true); //.addClass('disabled');
|
$deleteButton.attr('disabled', true).attr('title', t.deleteLibrary);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Go to delete page om click.
|
// Go to delete page om click.
|
||||||
|
|
|
@ -66,6 +66,19 @@ var H5PUtils = H5PUtils || {};
|
||||||
return template;
|
return template;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get throbber with given text.
|
||||||
|
*
|
||||||
|
* @param {String} text
|
||||||
|
* @returns {$}
|
||||||
|
*/
|
||||||
|
H5PUtils.throbber = function (text) {
|
||||||
|
return $('<div/>', {
|
||||||
|
class: 'h5p-throbber',
|
||||||
|
text: text
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes it possbile to rebuild all content caches from admin UI.
|
* Makes it possbile to rebuild all content caches from admin UI.
|
||||||
* @param {Object} notCached
|
* @param {Object} notCached
|
||||||
|
|
|
@ -47,6 +47,10 @@
|
||||||
text-indent: -0.125em;
|
text-indent: -0.125em;
|
||||||
margin: 0.125em 0.125em 0 0.125em;
|
margin: 0.125em 0.125em 0 0.125em;
|
||||||
}
|
}
|
||||||
|
.h5p-admin-upgrade-library:before {
|
||||||
|
font-family: 'H5P';
|
||||||
|
content: "\2191";
|
||||||
|
}
|
||||||
.h5p-admin-view-library:before {
|
.h5p-admin-view-library:before {
|
||||||
font-family: 'H5P';
|
font-family: 'H5P';
|
||||||
content: "\e888";
|
content: "\e888";
|
||||||
|
@ -56,19 +60,22 @@
|
||||||
content: "\e88e";
|
content: "\e88e";
|
||||||
}
|
}
|
||||||
|
|
||||||
.h5p-admin-table.libraries button:hover,
|
.h5p-admin-table.libraries button:hover {
|
||||||
.h5p-admin-table.libraries .h5p-admin-delete-library:hover {
|
|
||||||
background-color: #d0d0d0;
|
background-color: #d0d0d0;
|
||||||
}
|
}
|
||||||
|
.h5p-admin-table.libraries button:disabled:hover {
|
||||||
.h5p-admin-table.libraries .h5p-admin-delete-library:disabled:hover {
|
|
||||||
background-color: #e0e0e0;
|
background-color: #e0e0e0;
|
||||||
|
cursor: default;
|
||||||
}
|
}
|
||||||
|
|
||||||
.h5p-admin-table.libraries .h5p-admin-delete-library {
|
.h5p-admin-upgrade-library {
|
||||||
|
color: #0f01f9;
|
||||||
|
}
|
||||||
|
.h5p-admin-delete-library {
|
||||||
color: #f9010f;
|
color: #f9010f;
|
||||||
}
|
}
|
||||||
.h5p-admin-table.libraries .h5p-admin-delete-library:disabled {
|
.h5p-admin-delete-library:disabled,
|
||||||
|
.h5p-admin-upgrade-library:disabled {
|
||||||
cursor: default;
|
cursor: default;
|
||||||
color: #c0c0c0;
|
color: #c0c0c0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,3 +313,9 @@ div.h5p-fullscreen {
|
||||||
margin-left: 0.25em;
|
margin-left: 0.25em;
|
||||||
padding-left: 0.25em;
|
padding-left: 0.25em;
|
||||||
}
|
}
|
||||||
|
.h5p-throbber {
|
||||||
|
background: url('../images/throbber.gif') left center no-repeat;
|
||||||
|
padding-left: 38px;
|
||||||
|
min-height: 30px;
|
||||||
|
line-height: 30px;
|
||||||
|
}
|
Loading…
Reference in New Issue