diff options
-rw-r--r-- | appinfo/routes.php | 2 | ||||
-rw-r--r-- | js/app.js | 22 | ||||
-rw-r--r-- | js/gallery.js | 13 | ||||
-rw-r--r-- | js/galleryconfig.js | 42 | ||||
-rw-r--r-- | js/galleryfileaction.js | 16 | ||||
-rw-r--r-- | js/galleryinfobox.js | 4 | ||||
-rw-r--r-- | js/galleryview.js | 8 | ||||
-rw-r--r-- | service/configparser.php | 42 | ||||
-rw-r--r-- | service/configservice.php | 11 |
9 files changed, 103 insertions, 57 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php index c8a743f3..ee8930d2 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -105,7 +105,7 @@ return [ */ [ 'name' => 'public_config#get_config', - 'url' => '/config', + 'url' => '/config.public', 'verb' => 'GET' ], [ @@ -21,15 +21,19 @@ $(document).ready(function () { Gallery.resetContentHeight(); Gallery.showLoading(); - $.getJSON(Gallery.utility.buildGalleryUrl('mediatypes', '', {})) - .then(function (mediaTypes) { - //console.log('mediaTypes', mediaTypes); - Gallery.mediaTypes = mediaTypes; - }) - .then(function () { - Gallery.getFiles().then(function () { - window.onhashchange(); - }); + $.getJSON(Gallery.utility.buildGalleryUrl('config', '', {})) + .then(function (config) { + Gallery.config = new Gallery.Config(config); + $.getJSON(Gallery.utility.buildGalleryUrl('mediatypes', '', {})) + .then(function (mediaTypes) { + //console.log('mediaTypes', mediaTypes); + Gallery.mediaTypes = mediaTypes; + }) + .then(function () { + Gallery.getFiles().then(function () { + window.onhashchange(); + }); + }); }); $('#openAsFileListButton').click(function () { diff --git a/js/gallery.js b/js/gallery.js index 37a928d1..9fbb263a 100644 --- a/js/gallery.js +++ b/js/gallery.js @@ -3,8 +3,7 @@ var Gallery = {}; Gallery.mediaTypes = {}; Gallery.images = []; Gallery.currentAlbum = null; -Gallery.users = []; -Gallery.albumConfig = {}; +Gallery.config = {}; Gallery.albumMap = {}; Gallery.imageMap = {}; Gallery.appName = 'galleryplus'; @@ -77,7 +76,6 @@ Gallery.getFiles = function () { Gallery.images = []; Gallery.albumMap = {}; Gallery.imageMap = {}; - Gallery.albumConfig = null; var currentLocation = window.location.href.split('#')[1] || ''; var params = { location: currentLocation, @@ -93,8 +91,7 @@ Gallery.getFiles = function () { var files = data.files; var albumInfo = data.albuminfo; - Gallery.albumConfig = new Gallery.Config(albumInfo); - + Gallery.config.setAlbumConfig(albumInfo); for (var i = 0; i < files.length; i++) { path = files[i].path; fileId = files[i].fileid; @@ -158,7 +155,7 @@ Gallery.sorter = function () { sortType = 'date'; } - var currentSort = Gallery.albumConfig.sorting; + var currentSort = Gallery.config.albumSorting; if (currentSort.type === sortType && currentSort.order === sortOrder) { sortOrder = 'des'; } @@ -182,7 +179,7 @@ Gallery.sorter = function () { albumSortOrder)); // Save the new settings - Gallery.albumConfig.updateSorting(sortType, sortOrder, albumSortOrder); + Gallery.config.updateAlbumSorting(sortType, sortOrder, albumSortOrder); // Refresh the view Gallery.view.viewAlbum(Gallery.currentAlbum); @@ -212,7 +209,7 @@ Gallery.share = function (event) { }; })(); - var albumPermissions = Gallery.albumConfig.albumPermissions; + var albumPermissions = Gallery.config.albumPermissions; $('a.share').data('item', albumPermissions.fileid).data('link', true) .data('possible-permissions', albumPermissions.permissions). click(); diff --git a/js/galleryconfig.js b/js/galleryconfig.js index ce5a2c83..b7b4933d 100644 --- a/js/galleryconfig.js +++ b/js/galleryconfig.js @@ -1,39 +1,35 @@ /* global $, Gallery */ (function () { /** - * Stores the configuration about the current album + * Stores the gallery configuration * - * @param {Object} albumConfig + * @param {{features: *}} config * @constructor */ - var Config = function (albumConfig) { - this.galleryFeatures = this.setGalleryFeatures(albumConfig); - this.albumPermissions = this.setAlbumPermissions(albumConfig); - this.albumInfo = this.setAlbumInfo(albumConfig); - this.sorting = this.setAlbumSorting(albumConfig); - this.error = albumConfig.error; + var Config = function (config) { + this.galleryFeatures = this.setGalleryFeatures(config); }; Config.prototype = { galleryFeatures: [], albumPermissions: null, albumInfo: null, - sorting: null, - error: false, + albumSorting: null, + albumError: false, infoLoaded: false, /** * Saves the list of features which have been enabled in the app * - * @param albumConfig + * @param config * * @returns {Array} */ - setGalleryFeatures: function (albumConfig) { + setGalleryFeatures: function (config) { var features = []; - if (!$.isEmptyObject(albumConfig.features)) { - for (var i = 0, keys = Object.keys(albumConfig.features); i < keys.length; i++) { - if (albumConfig.features[keys[i]] === 'yes') { + if (!$.isEmptyObject(config.features)) { + for (var i = 0, keys = Object.keys(config.features); i < keys.length; i++) { + if (config.features[keys[i]] === 'yes') { features.push(keys[i]); } } @@ -43,6 +39,18 @@ }, /** + * Stores the configuration about the current album + * + * @param albumConfig + */ + setAlbumConfig: function (albumConfig) { + this.albumPermissions = this.setAlbumPermissions(albumConfig); + this.albumInfo = this.setAlbumInfo(albumConfig); + this.albumSorting = this.setAlbumSorting(albumConfig); + this.albumError = albumConfig.error; + }, + + /** * Saves the permissions for the current album * * @param albumConfig @@ -127,8 +135,8 @@ /** * Updates the sorting order */ - updateSorting: function (sortType, sortOrder, albumSortOrder) { - this.sorting = { + updateAlbumSorting: function (sortType, sortOrder, albumSortOrder) { + this.albumSorting = { type: sortType, order: sortOrder, albumOrder: albumSortOrder diff --git a/js/galleryfileaction.js b/js/galleryfileaction.js index afc040c5..2c1f1752 100644 --- a/js/galleryfileaction.js +++ b/js/galleryfileaction.js @@ -1,6 +1,6 @@ /* global OC ,OCA, $, oc_requesttoken, SlideShow */ var galleryFileAction = { - requestToken: null, + config: null, mediaTypes: {}, /** @@ -107,8 +107,14 @@ $(document).ready(function () { return true; } - var url = galleryFileAction.buildGalleryUrl('mediatypes', '', {slideshow: 1}); - // We're asking for a list of supported media types. - // Media files are retrieved through the Files context - $.getJSON(url, {}, galleryFileAction.register); + var url = galleryFileAction.buildGalleryUrl('config', '', {}); + $.getJSON(url).then(function (config) { + if (config) { + galleryFileAction.config = config; + } + url = galleryFileAction.buildGalleryUrl('mediatypes', '', {slideshow: 1}); + // We're asking for a list of supported media types. + // Media files are retrieved through the Files context + $.getJSON(url, {}, galleryFileAction.register); + }); });
\ No newline at end of file diff --git a/js/galleryinfobox.js b/js/galleryinfobox.js index 50204852..b43ad221 100644 --- a/js/galleryinfobox.js +++ b/js/galleryinfobox.js @@ -15,7 +15,7 @@ if (this.infoContentElement.is(':visible')) { this.infoContentElement.slideUp(); } else { - this.albumInfo = Gallery.albumConfig.albumInfo; + this.albumInfo = Gallery.config.albumInfo; if (!this.albumInfo.infoLoaded) { this.infoContentElement.addClass('icon-loading'); @@ -37,7 +37,7 @@ } else { this._addContent(this.albumInfo.description); } - Gallery.albumConfig.infoLoaded = true; + Gallery.config.infoLoaded = true; } else { this.infoContentElement.slideDown(); } diff --git a/js/galleryview.js b/js/galleryview.js index 0bb61acc..14ce832b 100644 --- a/js/galleryview.js +++ b/js/galleryview.js @@ -106,7 +106,7 @@ this.breadcrumb = new Gallery.Breadcrumb(albumPath); this.breadcrumb.setMaxWidth($(window).width() - 320); - var currentSort = Gallery.albumConfig.sorting; + var currentSort = Gallery.config.albumSorting; this.sortControlsSetup(currentSort.type, currentSort.order); Gallery.albumMap[Gallery.currentAlbum].images.sort(Gallery.utility.sortBy(currentSort.type, currentSort.order)); @@ -137,11 +137,11 @@ var infoContentElement = $('.album-info-content'); infoContentElement.slideUp(); infoContentElement.css('max-height', $(window).height() - 150); - var albumInfo = Gallery.albumConfig.albumInfo; - if (Gallery.albumConfig.error) { + var albumInfo = Gallery.config.albumInfo; + if (Gallery.config.albumError) { infoButton.hide(); var text = '<strong>' + t('gallery', 'Configuration error') + '</strong></br>' + - Gallery.albumConfig.error.message + '</br></br>'; + Gallery.config.albumError.message + '</br></br>'; Gallery.utility.showHtmlNotification(text, 7); } else if ($.isEmptyObject(albumInfo)) { infoButton.hide(); diff --git a/service/configparser.php b/service/configparser.php index 9524de79..a7a25ffe 100644 --- a/service/configparser.php +++ b/service/configparser.php @@ -25,6 +25,25 @@ use OCP\Files\File; class ConfigParser { /** + * Returns a parsed global configuration if one was found in the root folder + * + * @param Folder $folder + * @param string $configName + * + * @return null|array + */ + public function getGlobalConfig($folder, $configName) { + $config = []; + $parsedConfig = $this->parseConfig($folder, $configName); + $key = 'features'; + if (array_key_exists('features', $parsedConfig)) { + $config = [$key => $parsedConfig[$key]]; + } + + return $config; + } + + /** * Returns a parsed configuration if one was found in the current folder * * @param Folder $folder @@ -34,10 +53,26 @@ class ConfigParser { * @param int $level * * @return array <null|array,array<string,bool>> + */ + public function getFolderConfig($folder, $configName, $currentConfig, $configItems, $level) { + $parsedConfig = $this->parseConfig($folder, $configName); + list($config, $configItems) = + $this->buildAlbumConfig($currentConfig, $parsedConfig, $configItems, $level); + + return [$config, $configItems]; + } + + /** + * Returns a parsed configuration + * + * @param Folder $folder + * @param string $configName + * + * @return array <null|array> * * @throws ServiceException */ - public function parseConfig($folder, $configName, $currentConfig, $configItems, $level) { + private function parseConfig($folder, $configName) { /** @type File $configFile */ $configFile = $folder->get($configName); try { @@ -45,14 +80,13 @@ class ConfigParser { $saneConfig = $this->bomFixer($rawConfig); $parsedConfig = Yaml::parse($saneConfig); //\OC::$server->getLogger()->debug("rawConfig : {path}", ['path' => $rawConfig]); - list($config, $configItems) = - $this->buildAlbumConfig($currentConfig, $parsedConfig, $configItems, $level); + } catch (\Exception $exception) { $errorMessage = "Problem while parsing the configuration file"; throw new ServiceException($errorMessage); } - return [$config, $configItems]; + return $parsedConfig; } /** diff --git a/service/configservice.php b/service/configservice.php index b32c2427..1a3d6fe0 100644 --- a/service/configservice.php +++ b/service/configservice.php @@ -73,10 +73,7 @@ class ConfigService extends FilesService { /** @type Folder $rootFolder */ $rootFolder = $this->environment->getNode(''); if ($rootFolder) { - list($featuresList) = - $this->configParser->parseConfig( - $rootFolder, $this->configName, [], ['features' => false], null - ); + $featuresList = $this->configParser->getGlobalConfig($rootFolder, $this->configName); } return $featuresList; @@ -135,7 +132,7 @@ class ConfigService extends FilesService { } $isRootFolder = $this->isRootFolder($folder, $level); if ($folder->nodeExists($configName)) { - list($config) = $this->parseFolderConfig($folder, $configName, $config, $level); + list($config) = $this->buildFolderConfig($folder, $configName, $config, $level); } if (!$isRootFolder) { return $this->getParentConfig( @@ -159,9 +156,9 @@ class ConfigService extends FilesService { * * @return array */ - private function parseFolderConfig($folder, $configName, $config, $level) { + private function buildFolderConfig($folder, $configName, $config, $level) { try { - list($config, $configItems) = $this->configParser->parseConfig( + list($config, $configItems) = $this->configParser->getFolderConfig( $folder, $configName, $config, $this->configItems, $level ); $this->configItems = $configItems; |