<commit_before>/* global Album, GalleryImage */
(function ($, OC, t) {
	"use strict";
	var Gallery = {
		currentAlbum: null,
		config: {},
		/** Map of the whole gallery, built as we navigate through folders */
		albumMap: {},
		/** Used to pick an image based on the URL */
		imageMap: {},
		appName: 'gallery',
		token: undefined,
		activeSlideShow: null,
		buttonsWidth: 320,
		browserToolbarHeight: 150,

		/**
		 * Refreshes the view and starts the slideshow if required
		 *
		 * @param {string} path
		 * @param {string} albumPath
		 */
		refresh: function (path, albumPath) {
			if (Gallery.currentAlbum !== albumPath) {
				Gallery.view.init(albumPath);
			}

			// If the path is mapped, that means that it's an albumPath
			if (Gallery.albumMap[path]) {
				if (Gallery.activeSlideShow) {
					Gallery.activeSlideShow.stop();
				}
			} else if (Gallery.imageMap[path] && Gallery.activeSlideShow.active === false) {
				Gallery.view.startSlideshow(path, albumPath);
			}
		},

		/**
		 * Retrieves information about all the images and albums located in the current folder
		 *
		 * @param {string} currentLocation
		 *
		 * @returns {*}
		 */
		getFiles: function (currentLocation) {
			// Cache the sorting order of the current album before loading new files
			if (!$.isEmptyObject(Gallery.albumMap)) {
				Gallery.albumMap[Gallery.currentAlbum].sorting = Gallery.config.albumSorting;
			}
			// Checks if we've visited this location before ands saves the etag to use for
			// comparison later
			var albumEtag;
			var albumCache = Gallery.albumMap[decodeURIComponent(currentLocation)];
			if (!$.isEmptyObject(albumCache)) {
				albumEtag = albumCache.etag;
			}

			// Sends the request to the server
			var params = {
				location: currentLocation,
				mediatypes: Gallery.config.getMediaTypes(),
				features: Gallery.config.getFeatures(),
				etag: albumEtag
			};
			// Only use the folder as a GET parameter and not as part of the URL
			var url = Gallery.utility.buildGalleryUrl('files', '/list', params);
			return $.getJSON(url).then(function (/**{{albuminfo:Object, files:Array}}*/ data) {
				/**@type {{
				 * 	fileid: number,
				 * 	permissions: number,
				 * 	path: string,
				 * 	etag: string
				 * 	information,
				 * 	sorting,
				 * 	error: string
				 * }}*/
				var albumInfo = data.albuminfo;
				Gallery.config.setAlbumConfig(albumInfo);
				// Both the folder and the etag have to match
				if ((decodeURIComponent(currentLocation) === albumInfo.path)
					&& (albumInfo.etag === albumEtag)) {
					Gallery.imageMap = albumCache.imageMap;
				} else {
					Gallery._mapFiles(data);
				}

				// Restore the previous sorting order for this album
				if (!$.isEmptyObject(Gallery.albumMap[albumInfo.path].sorting)) {
					Gallery.config.updateAlbumSorting(Gallery.albumMap[albumInfo.path].sorting);
				}

			}, function () {
				// Triggered if we couldn't find a working folder
				Gallery.view.element.empty();
				Gallery.showEmpty();
				Gallery.currentAlbum = null;
			});
		},

		/**
		 * Sorts albums and images based on user preferences
		 */
		sorter: function () {
			var sortType = 'name';
			var sortOrder = 'asc';
			var albumSortType = 'name';
			var albumSortOrder = 'asc';
			if (this.id === 'sort-date-button') {
				sortType = 'date';

			}
			var currentSort = Gallery.config.albumSorting;
			if (currentSort.type === sortType && currentSort.order === sortOrder) {
				sortOrder = 'des';
			}

			// Update the controls
			Gallery.view.sortControlsSetup(sortType, sortOrder);

			// We can't currently sort by album creation time
			if (sortType === 'name') {
				albumSortOrder = sortOrder;
			}

			// FIXME Rendering is still happening while we're sorting...

			// Clear before sorting
			Gallery.view.clear();

			// Sort the images
			Gallery.albumMap[Gallery.currentAlbum].images.sort(Gallery.utility.sortBy(sortType,
				sortOrder));
			Gallery.albumMap[Gallery.currentAlbum].subAlbums.sort(Gallery.utility.sortBy(albumSortType,
				albumSortOrder));

			// Save the new settings
			var sortConfig = {
				type: sortType,
				order: sortOrder,
				albumOrder: albumSortOrder
			};
			Gallery.config.updateAlbumSorting(sortConfig);

			// Refresh the view
			Gallery.view.viewAlbum(Gallery.currentAlbum);
		},
		
		/**
		 * Switches to the Files view
		 *
		 * @param event
		 */
		switchToFilesView: function (event) {
			event.stopPropagation();
		
			var subUrl = '';
			var params = {path: '/' + Gallery.currentAlbum};
			if (Gallery.token) {
				params.token = Gallery.token;
				subUrl = 's/{token}?path={path}';
			} else {
				subUrl = 'apps/files?dir={path}';
			}
			
			var button = $('#filelist-button');
			button.addClass('loading');
			OC.redirect(OC.generateUrl(subUrl, params));
		},

		/**
		 * Populates the share dialog with the needed information
		 *
		 * @param event
		 */
		share: function (event) {
			// Clicking on share button does not trigger automatic slide-up
			$('.album-info-content').slideUp();

			if (!OC.Share.droppedDown) {
				event.preventDefault();
				event.stopPropagation();

				(function () {
					var target = OC.Share.showLink;
					OC.Share.showLink = function () {
						var r = target.apply(this, arguments);
						$('#linkText').val($('#linkText').val().replace('index.php/s/',
							'index.php/apps/' +
							Gallery.appName + '/s/'));

						return r;
					};
				})();

				var albumPermissions = Gallery.config.albumPermissions;
				$('a.share').data('item', albumPermissions.fileid).data('link', true)
					.data('possible-permissions', albumPermissions.permissions).
					click();
				if (!$('#linkCheckbox').is(':checked')) {
					$('#linkText').hide();
				}
			}
		},

		/**
		 * Sends an archive of the current folder to the browser
		 *
		 * @param event
		 */
		download: function (event) {
			event.preventDefault();

			var path = $('#content').data('albumname');
			var files = Gallery.currentAlbum;
			var downloadUrl = Gallery.utility.buildFilesUrl(path, files);

			OC.redirect(downloadUrl);
		},

		/**
		 * Shows an information box to the user
		 *
		 * @param event
		 */
		showInfo: function (event) {
			event.stopPropagation();
			Gallery.infoBox.showInfo();
		},

		/**
		 * Lets the user add the shared files to his ownCloud
		 */
		showSaveForm: function () {
			$(this).hide();
			$('.save-form').css('display', 'inline');
			$('#remote_address').focus();
		},

		/**
		 * Sends the shared files to the viewer's ownCloud
		 *
		 * @param event
		 */
		saveForm: function (event) {
			event.preventDefault();

			var saveElement = $('#save');
			var remote = $(this).find('input[type="text"]').val();
			var owner = saveElement.data('owner');
			var name = saveElement.data('name');
			var isProtected = saveElement.data('protected');
			Gallery._saveToOwnCloud(remote, Gallery.token, owner, name, isProtected);
		},

		/**
		 * Hide the search button while we wait for core to fix the templates
		 */
		hideSearch: function () {
			$('form.searchbox').hide();
		},

		/**
		 * Shows an empty gallery message
		 */
		showEmpty: function () {
			var emptyContentElement = $('#emptycontent');
			var message = t('gallery',
				"No pictures found! If you upload pictures in the files app, they will be displayed here.");
			emptyContentElement.html(message);
			emptyContentElement.removeClass('hidden');
			$('#controls').addClass('hidden');
			$('#content').removeClass('icon-loading');
		},

		/**
		 * Shows an empty gallery message
		 */
		showEmptyFolder: function () {
			var emptyContentElement = $('#emptycontent');
			var message = t('gallery',
				"I am sorry, but I could not find any media files at this location.");
			emptyContentElement.html(message);
			emptyContentElement.removeClass('hidden');
			$('#content').removeClass('icon-loading');
			$('#album-info-button').hide();
			$('#share-button').hide();
			$('#sort-name-button').hide();
			$('#sort-date-button').hide();
		},

		/**
		 * Shows the infamous loading spinner
		 */
		showLoading: function () {
			$('#emptycontent').addClass('hidden');
			$('#controls').removeClass('hidden');
		},<commit_msg>Hide the loading indicator on empty content...again [ci skip]<commit_after>/* global Album, GalleryImage */
(function ($, OC, t) {
	"use strict";
	var Gallery = {
		currentAlbum: null,
		config: {},
		/** Map of the whole gallery, built as we navigate through folders */
		albumMap: {},
		/** Used to pick an image based on the URL */
		imageMap: {},
		appName: 'gallery',
		token: undefined,
		activeSlideShow: null,
		buttonsWidth: 320,
		browserToolbarHeight: 150,

		/**
		 * Refreshes the view and starts the slideshow if required
		 *
		 * @param {string} path
		 * @param {string} albumPath
		 */
		refresh: function (path, albumPath) {
			if (Gallery.currentAlbum !== albumPath) {
				Gallery.view.init(albumPath);
			}

			// If the path is mapped, that means that it's an albumPath
			if (Gallery.albumMap[path]) {
				if (Gallery.activeSlideShow) {
					Gallery.activeSlideShow.stop();
				}
			} else if (Gallery.imageMap[path] && Gallery.activeSlideShow.active === false) {
				Gallery.view.startSlideshow(path, albumPath);
			}
		},

		/**
		 * Retrieves information about all the images and albums located in the current folder
		 *
		 * @param {string} currentLocation
		 *
		 * @returns {*}
		 */
		getFiles: function (currentLocation) {
			// Cache the sorting order of the current album before loading new files
			if (!$.isEmptyObject(Gallery.albumMap)) {
				Gallery.albumMap[Gallery.currentAlbum].sorting = Gallery.config.albumSorting;
			}
			// Checks if we've visited this location before ands saves the etag to use for
			// comparison later
			var albumEtag;
			var albumCache = Gallery.albumMap[decodeURIComponent(currentLocation)];
			if (!$.isEmptyObject(albumCache)) {
				albumEtag = albumCache.etag;
			}

			// Sends the request to the server
			var params = {
				location: currentLocation,
				mediatypes: Gallery.config.getMediaTypes(),
				features: Gallery.config.getFeatures(),
				etag: albumEtag
			};
			// Only use the folder as a GET parameter and not as part of the URL
			var url = Gallery.utility.buildGalleryUrl('files', '/list', params);
			return $.getJSON(url).then(function (/**{{albuminfo:Object, files:Array}}*/ data) {
				/**@type {{
				 * 	fileid: number,
				 * 	permissions: number,
				 * 	path: string,
				 * 	etag: string
				 * 	information,
				 * 	sorting,
				 * 	error: string
				 * }}*/
				var albumInfo = data.albuminfo;
				Gallery.config.setAlbumConfig(albumInfo);
				// Both the folder and the etag have to match
				if ((decodeURIComponent(currentLocation) === albumInfo.path)
					&& (albumInfo.etag === albumEtag)) {
					Gallery.imageMap = albumCache.imageMap;
				} else {
					Gallery._mapFiles(data);
				}

				// Restore the previous sorting order for this album
				if (!$.isEmptyObject(Gallery.albumMap[albumInfo.path].sorting)) {
					Gallery.config.updateAlbumSorting(Gallery.albumMap[albumInfo.path].sorting);
				}

			}, function () {
				// Triggered if we couldn't find a working folder
				Gallery.view.element.empty();
				Gallery.showEmpty();
				Gallery.currentAlbum = null;
			});
		},

		/**
		 * Sorts albums and images based on user preferences
		 */
		sorter: function () {
			var sortType = 'name';
			var sortOrder = 'asc';
			var albumSortType = 'name';
			var albumSortOrder = 'asc';
			if (this.id === 'sort-date-button') {
				sortType = 'date';

			}
			var currentSort = Gallery.config.albumSorting;
			if (currentSort.type === sortType && currentSort.order === sortOrder) {
				sortOrder = 'des';
			}

			// Update the controls
			Gallery.view.sortControlsSetup(sortType, sortOrder);

			// We can't currently sort by album creation time
			if (sortType === 'name') {
				albumSortOrder = sortOrder;
			}

			// FIXME Rendering is still happening while we're sorting...

			// Clear before sorting
			Gallery.view.clear();

			// Sort the images
			Gallery.albumMap[Gallery.currentAlbum].images.sort(Gallery.utility.sortBy(sortType,
				sortOrder));
			Gallery.albumMap[Gallery.currentAlbum].subAlbums.sort(Gallery.utility.sortBy(albumSortType,
				albumSortOrder));

			// Save the new settings
			var sortConfig = {
				type: sortType,
				order: sortOrder,
				albumOrder: albumSortOrder
			};
			Gallery.config.updateAlbumSorting(sortConfig);

			// Refresh the view
			Gallery.view.viewAlbum(Gallery.currentAlbum);
		},
		
		/**
		 * Switches to the Files view
		 *
		 * @param event
		 */
		switchToFilesView: function (event) {
			event.stopPropagation();
		
			var subUrl = '';
			var params = {path: '/' + Gallery.currentAlbum};
			if (Gallery.token) {
				params.token = Gallery.token;
				subUrl = 's/{token}?path={path}';
			} else {
				subUrl = 'apps/files?dir={path}';
			}
			
			var button = $('#filelist-button');
			button.addClass('loading');
			OC.redirect(OC.generateUrl(subUrl, params));
		},

		/**
		 * Populates the share dialog with the needed information
		 *
		 * @param event
		 */
		share: function (event) {
			// Clicking on share button does not trigger automatic slide-up
			$('.album-info-content').slideUp();

			if (!OC.Share.droppedDown) {
				event.preventDefault();
				event.stopPropagation();

				(function () {
					var target = OC.Share.showLink;
					OC.Share.showLink = function () {
						var r = target.apply(this, arguments);
						$('#linkText').val($('#linkText').val().replace('index.php/s/',
							'index.php/apps/' +
							Gallery.appName + '/s/'));

						return r;
					};
				})();

				var albumPermissions = Gallery.config.albumPermissions;
				$('a.share').data('item', albumPermissions.fileid).data('link', true)
					.data('possible-permissions', albumPermissions.permissions).
					click();
				if (!$('#linkCheckbox').is(':checked')) {
					$('#linkText').hide();
				}
			}
		},

		/**
		 * Sends an archive of the current folder to the browser
		 *
		 * @param event
		 */
		download: function (event) {
			event.preventDefault();

			var path = $('#content').data('albumname');
			var files = Gallery.currentAlbum;
			var downloadUrl = Gallery.utility.buildFilesUrl(path, files);

			OC.redirect(downloadUrl);
		},

		/**
		 * Shows an information box to the user
		 *
		 * @param event
		 */
		showInfo: function (event) {
			event.stopPropagation();
			Gallery.infoBox.showInfo();
		},

		/**
		 * Lets the user add the shared files to his ownCloud
		 */
		showSaveForm: function () {
			$(this).hide();
			$('.save-form').css('display', 'inline');
			$('#remote_address').focus();
		},

		/**
		 * Sends the shared files to the viewer's ownCloud
		 *
		 * @param event
		 */
		saveForm: function (event) {
			event.preventDefault();

			var saveElement = $('#save');
			var remote = $(this).find('input[type="text"]').val();
			var owner = saveElement.data('owner');
			var name = saveElement.data('name');
			var isProtected = saveElement.data('protected');
			Gallery._saveToOwnCloud(remote, Gallery.token, owner, name, isProtected);
		},

		/**
		 * Hide the search button while we wait for core to fix the templates
		 */
		hideSearch: function () {
			$('form.searchbox').hide();
		},

		/**
		 * Shows an empty gallery message
		 */
		showEmpty: function () {
			var emptyContentElement = $('#emptycontent');
			var message = t('gallery',
				"No pictures found! If you upload pictures in the files app, they will be displayed here.");
			emptyContentElement.html(message);
			emptyContentElement.removeClass('hidden');
			$('#controls').addClass('hidden');
			$('#loading-indicator').hide();
		},

		/**
		 * Shows an empty gallery message
		 */
		showEmptyFolder: function () {
			var emptyContentElement = $('#emptycontent');
			var message = t('gallery',
				"I am sorry, but I could not find any media files at this location.");
			emptyContentElement.html(message);
			emptyContentElement.removeClass('hidden');
			$('#loading-indicator').hide();
			$('#album-info-button').hide();
			$('#share-button').hide();
			$('#sort-name-button').hide();
			$('#sort-date-button').hide();
		},

		/**
		 * Shows the infamous loading spinner
		 */
		showLoading: function () {
			$('#emptycontent').addClass('hidden');
			$('#controls').removeClass('hidden');
		},
{'fraction_non_alphanumeric': 0.1487963645295996, 'fraction_numerical': 0.0007369196757553427, 'mean_word_length': 3.116531850353893, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6559845', 'n_tokens_mistral': 6122, 'n_tokens_neox': 4895, 'n_words': 1236}