From 426a08e33ec8c5481971b66952ff33d0427cbf18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20J=C3=B8rgensen?= Date: Tue, 19 Aug 2014 10:14:55 +0200 Subject: [PATCH 1/5] Added loadLibraries() to interface --- h5p.classes.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/h5p.classes.php b/h5p.classes.php index ea447f7..2266d8f 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -55,6 +55,13 @@ interface H5PFrameworkInterface { * @return string Path to the last uploaded h5p */ public function getUploadedH5pPath(); + + /** + * Get the list of the current installed libraries + * + * @return array Associative array containg one item per machine name. This item contains an array of libraries. + */ + public function loadLibraries(); /** * Get id to an excisting library From 89bacfdb881bb827d4c6af3d1baf5264f2b38491 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 22 Aug 2014 11:34:38 +0200 Subject: [PATCH 2/5] Made sure main content id isn't required. Conflicts: h5p.classes.php --- h5p.classes.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/h5p.classes.php b/h5p.classes.php index 088d4c2..fbcf3f5 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1278,6 +1278,25 @@ class H5PCore { } } + /** + * Save content and clear cache. + * + * @param array $content + * @return int Content ID + */ + public function saveContent($content, $contentMainId = NULL) { + if (isset($content['id'])) { + $this->h5pF->updateContent($content, $contentMainId); + } + else { + $content['id'] = $this->h5pF->insertContent($content, $contentMainId); + } + + $this->h5pF->cacheDel('parameters', $content['id']); + + return $content['id']; + } + /** * Load content. * From 1a1e261dd588a9463ed76be939a05eece7ca8cb7 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 22 Aug 2014 11:33:47 +0200 Subject: [PATCH 3/5] Made it possible to delete libraries without having to load them again. --- h5p.classes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index fbcf3f5..f5fa9ea 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -243,9 +243,9 @@ interface H5PFrameworkInterface { /** * Delete a library from database and file system * - * @param int $libraryId Library Id + * @param mixed $library Library */ - public function deleteLibrary($libraryId); + public function deleteLibrary($library); /** * Load content. From be44d1fac90492b1c2830db4e3c985791da96751 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 22 Aug 2014 11:39:15 +0200 Subject: [PATCH 4/5] Fixed so that filtered params can be stored in the contents table. --- h5p.classes.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index bf1b48d..7bf5cab 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1340,7 +1340,10 @@ class H5PCore { $content['id'] = $this->h5pF->insertContent($content, $contentMainId); } - $this->h5pF->cacheDel('parameters', $content['id']); + if (!isset($content['filtered'])) { + // TODO: Add filtered to all impl. and remove + $this->h5pF->cacheDel('parameters', $content['id']); + } return $content['id']; } @@ -1389,7 +1392,14 @@ class H5PCore { * @return Object NULL on failure. */ public function filterParameters($content) { - $params = $this->h5pF->cacheGet('parameters', $content['id']); + if (isset($content['filtered'])) { + $params = ($content['filtered'] === '' ? NULL : $content['filtered']); + } + else { + // TODO: Add filtered to all impl. and remove + $params = $this->h5pF->cacheGet('parameters', $content['id']); + } + if ($params !== NULL) { return $params; } From 952b6e6368e0aace74da5aba840fc63270e3cccb Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 22 Aug 2014 11:39:45 +0200 Subject: [PATCH 5/5] Made it possible to display the library list in a human readable form. --- js/h5p-library-details.js | 14 -------------- js/h5p-library-list.js | 4 ++-- js/h5p-utils.js | 21 ++++++++++++++------- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/js/h5p-library-details.js b/js/h5p-library-details.js index e274d22..73a996f 100644 --- a/js/h5p-library-details.js +++ b/js/h5p-library-details.js @@ -39,20 +39,6 @@ var H5PLibraryDetails= H5PLibraryDetails || {}; $libraryInfo.append(H5PUtils.createLabeledField(title, value)); }); - var count; - if (H5PLibraryDetails.library.notCached !== undefined) { - count = H5PIntegration.i18n.H5P.NA; - } - else if (H5PLibraryDetails.library.content === undefined) { - count = 0; - } - else { - count = H5PLibraryDetails.library.content.length; - } - - // List counter: - $libraryInfo.append(H5PUtils.createLabeledField(H5PLibraryDetails.library.translations.contentCount, count)); - return $libraryInfo; }; diff --git a/js/h5p-library-list.js b/js/h5p-library-list.js index a238d39..5b485f9 100644 --- a/js/h5p-library-list.js +++ b/js/h5p-library-list.js @@ -38,7 +38,7 @@ var H5PLibraryList= H5PLibraryList || {}; var $libraryRow = H5PUtils.createTableRow([ library.title, library.numContent, - library.numContentDependencies === -1 ? t.NA : library.numContentDependencies, + library.numContentDependencies, library.numLibraryDependencies, '
\ \ @@ -62,7 +62,7 @@ var H5PLibraryList= H5PLibraryList || {}; }); var $deleteButton = $('.h5p-admin-delete-library', $libraryRow); - if (library.numContent !== 0 || library.numContentDependencies !== 0 || library.numLibraryDependencies !== 0) { + if (library.numContent !== '0' || library.numContentDependencies !== '' || library.numLibraryDependencies !== '') { // Disabled delete if content. $deleteButton.attr('disabled', true).attr('title', t.deleteLibrary); } diff --git a/js/h5p-utils.js b/js/h5p-utils.js index d8faf68..3004c95 100644 --- a/js/h5p-utils.js +++ b/js/h5p-utils.js @@ -7,14 +7,20 @@ var H5PUtils = H5PUtils || {}; * @param {array} headers List of headers */ H5PUtils.createTable = function (headers) { - var $table = $('
'); - + var $table = $('
'); + if(headers) { var $thead = $(''); var $tr = $(''); $.each(headers, function (index, value) { - $tr.append('' + value + ''); + if (!(value instanceof Object)) { + value = { + text: value + }; + } + + $('', value).appendTo($tr); }); $table.append($thead.append($tr)); @@ -85,7 +91,7 @@ var H5PUtils = H5PUtils || {}; * @returns {$} */ H5PUtils.getRebuildCache = function (notCached) { - var $container = $('

' + notCached.message + '

'); + var $container = $('

' + notCached.message + '

' + notCached.progress + '

'); var $button = $('').appendTo($container).click(function () { var $spinner = $('
', {class: 'h5p-spinner'}).replaceAll($button); var parts = ['|', '/', '-', '\\']; @@ -96,7 +102,7 @@ var H5PUtils = H5PUtils || {}; if (current === parts.length) current = 0; }, 100); - var $counter = $container.find('.placeholder'); + var $counter = $container.find('.progress'); var build = function () { $.post(notCached.url, function (left) { if (left === '0') { @@ -105,8 +111,9 @@ var H5PUtils = H5PUtils || {}; location.reload(); } else { - var counter = $counter.text().split(' ', 2); - $counter.text(left + ' ' + counter[1]); + var counter = $counter.text().split(' '); + counter[0] = left; + $counter.text(counter.join(' ')); build(); } });