<commit_before>/*
 * Copyright (c) 2014
 *
 * This file is licensed under the Affero General Public License version 3
 * or later.
 *
 * See the COPYING-README file.
 *
 */

(function() {
	OC.Update = {
		_started : false,

		/**
		 * Start the update process.
		 *
		 * @param $el progress list element
		 */
		start: function($el, options) {
			if (this._started) {
				return;
			}

			var hasWarnings = false;

			this.$el = $el;

			this._started = true;

			var self = this;

			$(window).on('beforeunload.inprogress', function () {
				return t('core', 'The update is in progress, leaving this page might interrupt the process in some environments.');
			});

			$('#update-progress-title').html(t(
				'core',
				'Update to {version}', {
					version: options.version
				})
			);

			var updateEventSource = new OC.EventSource(OC.webroot+'/core/ajax/update.php');
			updateEventSource.listen('success', function(message) {
				self.setMessage(message);
			});
			updateEventSource.listen('notice', function(message) {
				self.setPermanentMessage(message);
				hasWarnings = true;
			});
			updateEventSource.listen('error', function(message) {
				$('#update-progress-message').hide();
				$('#update-progress-icon')
					.addClass('icon-error-white')
					.removeClass('icon-loading-dark');
				message = message || t('core', 'An error occurred.');
				$(window).off('beforeunload.inprogress');
				self.setErrorMessage(message);
				message = t('core', 'Please reload the page.');
				$('<span>').addClass('error').append('<a href=".">'+message+'</a><br />').appendTo($el);
				updateEventSource.close();
			});
			updateEventSource.listen('failure', function(message) {
				$(window).off('beforeunload.inprogress');
				$('#update-progress-message').hide();
				$('#update-progress-icon')
					.addClass('icon-error-white')
					.removeClass('icon-loading-dark');

				self.setErrorMessage(message);
				var span = $('<span>')
					.addClass('bold');
				if(message === 'Exception: Updates between multiple major versions and downgrades are unsupported.') {
					span.append(t('core', 'The update was unsuccessful. For more information <a href="{url}">check our forum post</a> covering this issue.', {'url': 'https://help.nextcloud.com/t/updates-between-multiple-major-versions-are-unsupported/7094'}));
				} else {
					span.append(t('core', 'The update was unsuccessful. ' +
						'Please report this issue to the ' +
						'<a href="https://github.com/nextcloud/server/issues" target="_blank">Nextcloud community</a>.'));
				}
				span.appendTo($el);
			});
			updateEventSource.listen('done', function() {
				$(window).off('beforeunload.inprogress');

				$('#update-progress-message').hide();

				$('#update-progress-icon')
					.addClass('icon-checkmark-white')
					.removeClass('icon-loading-dark');

				if (hasWarnings) {
					$el.find('.update-show-detailed').before(
						$('<input type="button" class="update-continue" value="'+t('core', 'Continue to Nextcloud')+'">').on('click', function() {
							window.location.reload();
						})
					);
				} else {
					// FIXME: use product name
					$el.find('.update-show-detailed').before(
						$('<p>'+t('core', 'The update was successful. Redirecting you to Nextcloud now.')+'</p>')
					);
					setTimeout(function () {
						OC.redirect(OC.webroot + '/');
					}, 3000);
				}
			});
		},

		setMessage: function(message) {
			$('#update-progress-message').html(message);
			$('#update-progress-detailed')
				.append($('<span>'))
				.append(message)
				.append($('<br>'));
		},

		setPermanentMessage: function(message) {
			$('#update-progress-message').html(message);
			$('#update-progress-message-warnings')
				.show()
				.append($('<ul>').append(message));
			$('#update-progress-detailed')
				.append($('<span>'))
				.append(message)
				.append($('<br>'));
		},

		setErrorMessage: function (message) {
			$('#update-progress-message-error')
				.show()
				.html(message);
			$('#update-progress-detailed')
				.append($('<span>'))
				.append(message)
				.append($('<br>'));
		}
	};

})();

$(document).ready(function() {
	$('.updateButton').on('click', function() {
		var $updateEl = $('.update');
		var $progressEl = $('.update-progress');
		$progressEl.removeClass('hidden');
		$('.updateOverview').addClass('hidden');
		$('#update-progress-message-error').hide();
		$('#update-progress-message-warnings').hide();
		OC.Update.start($progressEl, {
			productName: $updateEl.attr('data-productname'),
			version: $updateEl.attr('data-version')
		});
		return false;
	});
	$('.update-show-detailed').on('click', function() {
		$('#update-progress-detailed').toggleClass('hidden');
		return false;
	});
});
<commit_msg>Update: feedback before redirect<commit_after>/*
 * Copyright (c) 2014
 *
 * This file is licensed under the Affero General Public License version 3
 * or later.
 *
 * See the COPYING-README file.
 *
 */

(function() {
	OC.Update = {
		_started : false,

		/**
		 * Start the update process.
		 *
		 * @param $el progress list element
		 */
		start: function($el, options) {
			if (this._started) {
				return;
			}

			var hasWarnings = false;

			this.$el = $el;

			this._started = true;

			var self = this;

			$(window).on('beforeunload.inprogress', function () {
				return t('core', 'The update is in progress, leaving this page might interrupt the process in some environments.');
			});

			$('#update-progress-title').html(t(
				'core',
				'Update to {version}', {
					version: options.version
				})
			);

			var updateEventSource = new OC.EventSource(OC.webroot+'/core/ajax/update.php');
			updateEventSource.listen('success', function(message) {
				self.setMessage(message);
			});
			updateEventSource.listen('notice', function(message) {
				self.setPermanentMessage(message);
				hasWarnings = true;
			});
			updateEventSource.listen('error', function(message) {
				$('#update-progress-message').hide();
				$('#update-progress-icon')
					.addClass('icon-error-white')
					.removeClass('icon-loading-dark');
				message = message || t('core', 'An error occurred.');
				$(window).off('beforeunload.inprogress');
				self.setErrorMessage(message);
				message = t('core', 'Please reload the page.');
				$('<span>').addClass('error').append('<a href=".">'+message+'</a><br />').appendTo($el);
				updateEventSource.close();
			});
			updateEventSource.listen('failure', function(message) {
				$(window).off('beforeunload.inprogress');
				$('#update-progress-message').hide();
				$('#update-progress-icon')
					.addClass('icon-error-white')
					.removeClass('icon-loading-dark');

				self.setErrorMessage(message);
				var span = $('<span>')
					.addClass('bold');
				if(message === 'Exception: Updates between multiple major versions and downgrades are unsupported.') {
					span.append(t('core', 'The update was unsuccessful. For more information <a href="{url}">check our forum post</a> covering this issue.', {'url': 'https://help.nextcloud.com/t/updates-between-multiple-major-versions-are-unsupported/7094'}));
				} else {
					span.append(t('core', 'The update was unsuccessful. ' +
						'Please report this issue to the ' +
						'<a href="https://github.com/nextcloud/server/issues" target="_blank">Nextcloud community</a>.'));
				}
				span.appendTo($el);
			});
			updateEventSource.listen('done', function() {
				$(window).off('beforeunload.inprogress');

				$('#update-progress-message').hide();

				$('#update-progress-icon')
					.addClass('icon-checkmark-white')
				  	.removeClass('icon-loading-dark');

				if (hasWarnings) {
					$el.find('.update-show-detailed').before(
						$('<input type="button" class="update-continue" value="'+t('core', 'Continue to Nextcloud')+'">').on('click', function() {
							window.location.reload();
						})
					);
				} else {
					// FIXME: use product name
					$el.find('.update-show-detailed').before(
						$('<p>'+t('core', 'The update was successful. Redirecting you to Nextcloud in ')+'<span id="countdown"></span></p>')
					);

					for(var i = 4; i >= 0; i--) {
						self.updateCountdown(i);
					}

					setTimeout(function () {
						OC.redirect(OC.webroot + '/');
					}, 3000);
				}
			});
		},

		updateCountdown: function (i) {
			setTimeout(function(){
				 $("#countdown").html(i + " second");
				 if(i > 1) {  $("#countdown").append("s");  }
			}, (4 - i) * 1000);
		},

		setMessage: function(message) {
			$('#update-progress-message').html(message);
			$('#update-progress-detailed')
				.append($('<span>'))
				.append(message)
				.append($('<br>'));
		},

		setPermanentMessage: function(message) {
			$('#update-progress-message').html(message);
			$('#update-progress-message-warnings')
				.show()
				.append($('<ul>').append(message));
			$('#update-progress-detailed')
				.append($('<span>'))
				.append(message)
				.append($('<br>'));
		},

		setErrorMessage: function (message) {
			$('#update-progress-message-error')
				.show()
				.html(message);
			$('#update-progress-detailed')
				.append($('<span>'))
				.append(message)
				.append($('<br>'));
		}
	};

})();

$(document).ready(function() {
	$('.updateButton').on('click', function() {
		var $updateEl = $('.update');
		var $progressEl = $('.update-progress');
		$progressEl.removeClass('hidden');
		$('.updateOverview').addClass('hidden');
		$('#update-progress-message-error').hide();
		$('#update-progress-message-warnings').hide();
		OC.Update.start($progressEl, {
			productName: $updateEl.attr('data-productname'),
			version: $updateEl.attr('data-version')
		});
		return false;
	});
	$('.update-show-detailed').on('click', function() {
		$('#update-progress-detailed').toggleClass('hidden');
		return false;
	});
});

{'fraction_non_alphanumeric': 0.2068788501026694, 'fraction_numerical': 0.003490759753593429, 'mean_word_length': 3.5561272217025257, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 45, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4693009', 'n_tokens_mistral': 3731, 'n_tokens_neox': 3025, 'n_words': 546}