/*
 * Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
 *
 * This file is licensed under the Affero General Public License version 3
 * or later.
 *
 * See the COPYING-README file.
 *
 */

(function ($) {

	var Drop = {
		/** @type {Function} **/
		_template: undefined,

		/** @type {boolean} */
		_uploading: false,

		addFileToUpload: function(e, data) {
			var errors = [];
			var output = this.template();

			var filesClient = new OC.Files.Client({
				host: OC.getHost(),
				port: OC.getPort(),
				userName: $('#sharingToken').val(),
				// note: password not be required, the endpoint
				// will recognize previous validation from the session
				root: OC.getRootPath() + '/public.php/webdav',
				useHTTPS: OC.getProtocol() === 'https'
			});

			// We only process one file at a time 🤷‍♀️
			var name = data.files[0].name;
			// removing unwanted characters
			name = name.replace(/["'#%`]/gm, '');

			try {
				// FIXME: not so elegant... need to refactor that method to return a value
				Files.isFileNameValid(name);
			}
			catch (errorMessage) {
				OC.Notification.show(errorMessage, {type: 'error'});
				return false;
			}
			var base = OC.getProtocol() + '://' + OC.getHost();
			data.url = base + OC.getRootPath() + '/public.php/webdav/' + encodeURI(name);

			data.multipart = false;

			if (!data.headers) {
				data.headers = {};
			}

			var userName = filesClient.getUserName();
			var password = filesClient.getPassword();
			if (userName) {
				// copy username/password from DAV client
				data.headers['Authorization'] =
					'Basic ' + btoa(userName + ':' + (password || ''));
			}

			$('#drop-upload-done-indicator').addClass('hidden');
			$('#drop-upload-progress-indicator').removeClass('hidden');

			$('#drop-uploaded-files').append(output({isUploading: true, name: data.files[0].name}));
			data.submit();

			return true;
		},

		updateFileItem: function (fileName, fileItem) {
			$('#drop-uploaded-files li[data-name="' + fileName + '"]').replaceWith(fileItem);
		},

		initialize: function () {
			$(document).bind('drop dragover', function (e) {
				// Prevent the default browser drop action:
				e.preventDefault();
			});
			var output = this.template();
			var self = this;
			$('#public-upload').fileupload({
				type: 'PUT',
				dropZone: $('#public-upload'),
				sequentialUploads: true,
				start: function(e) {
					self._uploading = true;
				},
				stop: function(e) {
					self._uploading = false;
				},
				add: function(e, data) {
					Drop.addFileToUpload(e, data);
					$('#drop-upload-status').text(t('files_sharing', 'Waiting…'));
					//we return true to keep trying to upload next file even
					//if addFileToUpload did not like the previous one
					return true;
				},
				done: function(e, data) {
					// Created
					var mimeTypeUrl = OC.MimeType.getIconUrl(data.files[0].type);
					var fileItem = output({isUploading: false, iconSrc: mimeTypeUrl, name: data.files[0].name});
					Drop.updateFileItem(data.files[0].name, fileItem);
				},
				fail: function(e, data) {
					OC.Notification.showTemporary(OC.L10N.translate(
							'files_sharing',
							'Could not upload "{filename}"',
							{filename: data.files[0].name}
							));
					$('#drop-upload-status').text(t('files_sharing', 'error'));
					var errorIconSrc = OC.imagePath('core', 'actions/error.svg');
					var fileItem = output({isUploading: false, iconSrc: errorIconSrc, name: data.files[0].name});
					Drop.updateFileItem(data.files[0].name, fileItem);
				},
				progressall: function (e, data) {
					var progress = parseInt(data.loaded / data.total * 100, 10);
					if(progress === 100) {
						$('#drop-upload-done-indicator').removeClass('hidden');
						$('#drop-upload-progress-indicator').addClass('hidden');
					} else {
						$('#drop-upload-done-indicator').addClass('hidden');
						$('#drop-upload-progress-indicator').removeClass('hidden');
					}
				},
				progress: function (e, data) {
					var progress = parseInt(data.loaded / data.total * 100, 10);
					if(progress === 100) {
						$('#drop-upload-progress-bar').val(100);
						$('#drop-upload-status').text(t('files_sharing', 'finished'));
					} else {
						$('#drop-upload-progress-bar').val(progress);
						$('#drop-upload-status').text(progress + '%');
					}
				},
			});
			$('#public-upload .button.icon-upload').click(function(e) {
				e.preventDefault();
				$('#public-upload .emptycontent input').focus().trigger('click');
			});
			window.onbeforeunload = function() {
				return self.confirmBeforeUnload();
			}
		},

		/**
		 * @returns {Function} from Handlebars
		 * @private
		 */
		template: function () {
			return OCA.Sharing.Templates['files_drop'];
		},

		confirmBeforeUnload: function() {
			if (this._uploading) {
				return t('files', 'This will stop your current uploads.')
			}
		},
	};

	OCA.FilesSharingDrop = Drop;

	window.addEventListener('DOMContentLoaded', function() {
		if($('#upload-only-interface').val() === "1") {
			$('.avatardiv').avatar($('#sharingUserId').val(), 128, true);
		}

		OCA.FilesSharingDrop.initialize();
	});
})(jQuery);
a href='/sonarqube.git/about/?h=9.9.8.100196'>about</a><a href='/sonarqube.git/?h=9.9.8.100196'>summary</a><a href='/sonarqube.git/refs/?h=9.9.8.100196&amp;id=6a0b24f31a59a7170e651ae23f299243ca4df679'>refs</a><a href='/sonarqube.git/log/server/sonar-web/src/main/js/components/hoc/withCurrentUser.tsx?h=9.9.8.100196'>log</a><a class='active' href='/sonarqube.git/tree/server/sonar-web/src/main/js/components/hoc/withCurrentUser.tsx?h=9.9.8.100196&amp;id=6a0b24f31a59a7170e651ae23f299243ca4df679'>tree</a><a href='/sonarqube.git/commit/server/sonar-web/src/main/js/components/hoc/withCurrentUser.tsx?h=9.9.8.100196&amp;id=6a0b24f31a59a7170e651ae23f299243ca4df679'>commit</a><a href='/sonarqube.git/diff/server/sonar-web/src/main/js/components/hoc/withCurrentUser.tsx?h=9.9.8.100196&amp;id=6a0b24f31a59a7170e651ae23f299243ca4df679'>diff</a><a href='/sonarqube.git/stats/server/sonar-web/src/main/js/components/hoc/withCurrentUser.tsx?h=9.9.8.100196'>stats</a></td><td class='form'><form class='right' method='get' action='/sonarqube.git/log/server/sonar-web/src/main/js/components/hoc/withCurrentUser.tsx'>
<input type='hidden' name='h' value='9.9.8.100196'/><input type='hidden' name='id' value='6a0b24f31a59a7170e651ae23f299243ca4df679'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/sonarqube.git/tree/?h=9.9.8.100196&amp;id=6a0b24f31a59a7170e651ae23f299243ca4df679'>root</a>/<a href='/sonarqube.git/tree/server?h=9.9.8.100196&amp;id=6a0b24f31a59a7170e651ae23f299243ca4df679'>server</a>/<a href='/sonarqube.git/tree/server/sonar-web?h=9.9.8.100196&amp;id=6a0b24f31a59a7170e651ae23f299243ca4df679'>sonar-web</a>/<a href='/sonarqube.git/tree/server/sonar-web/src?h=9.9.8.100196&amp;id=6a0b24f31a59a7170e651ae23f299243ca4df679'>src</a>/<a href='/sonarqube.git/tree/server/sonar-web/src/main?h=9.9.8.100196&amp;id=6a0b24f31a59a7170e651ae23f299243ca4df679'>main</a>/<a href='/sonarqube.git/tree/server/sonar-web/src/main/js?h=9.9.8.100196&amp;id=6a0b24f31a59a7170e651ae23f299243ca4df679'>js</a>/<a href='/sonarqube.git/tree/server/sonar-web/src/main/js/components?h=9.9.8.100196&amp;id=6a0b24f31a59a7170e651ae23f299243ca4df679'>components</a>/<a href='/sonarqube.git/tree/server/sonar-web/src/main/js/components/hoc?h=9.9.8.100196&amp;id=6a0b24f31a59a7170e651ae23f299243ca4df679'>hoc</a>/<a href='/sonarqube.git/tree/server/sonar-web/src/main/js/components/hoc/withCurrentUser.tsx?h=9.9.8.100196&amp;id=6a0b24f31a59a7170e651ae23f299243ca4df679'>withCurrentUser.tsx</a></div><div class='content'>blob: db12d3da800e7a80b97967b9520714dd741fb439 (<a href='/sonarqube.git/plain/server/sonar-web/src/main/js/components/hoc/withCurrentUser.tsx?h=9.9.8.100196&amp;id=6a0b24f31a59a7170e651ae23f299243ca4df679'>plain</a>)
<table summary='blob content' class='blob'>
<tr><td class='linenumbers'><pre><a id='n1' href='#n1'>1</a>
<a id='n2' href='#n2'>2</a>
<a id='n3' href='#n3'>3</a>
<a id='n4' href='#n4'>4</a>
<a id='n5' href='#n5'>5</a>
<a id='n6' href='#n6'>6</a>
<a id='n7' href='#n7'>7</a>
<a id='n8' href='#n8'>8</a>
<a id='n9' href='#n9'>9</a>
<a id='n10' href='#n10'>10</a>
<a id='n11' href='#n11'>11</a>
<a id='n12' href='#n12'>12</a>
<a id='n13' href='#n13'>13</a>
<a id='n14' href='#n14'>14</a>
<a id='n15' href='#n15'>15</a>
<a id='n16' href='#n16'>16</a>
<a id='n17' href='#n17'>17</a>
<a id='n18' href='#n18'>18</a>
<a id='n19' href='#n19'>19</a>
<a id='n20' href='#n20'>20</a>
<a id='n21' href='#n21'>21</a>
<a id='n22' href='#n22'>22</a>
<a id='n23' href='#n23'>23</a>
<a id='n24' href='#n24'>24</a>
<a id='n25' href='#n25'>25</a>
<a id='n26' href='#n26'>26</a>
<a id='n27' href='#n27'>27</a>
<a id='n28' href='#n28'>28</a>
<a id='n29' href='#n29'>29</a>
<a id='n30' href='#n30'>30</a>
<a id='n31' href='#n31'>31</a>
<a id='n32' href='#n32'>32</a>
<a id='n33' href='#n33'>33</a>
<a id='n34' href='#n34'>34</a>
<a id='n35' href='#n35'>35</a>
<a id='n36' href='#n36'>36</a>
<a id='n37' href='#n37'>37</a>
<a id='n38' href='#n38'>38</a>
<a id='n39' href='#n39'>39</a>
<a id='n40' href='#n40'>40</a>
<a id='n41' href='#n41'>41</a>
</pre></td>
<td class='lines'><pre><code><style>pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */</style><div class="highlight"><pre><span></span>/*
 * SonarQube
 * Copyright (C) 2009-2020 SonarSource SA
 * mailto:info AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
import * as React from &#39;react&#39;;
import { connect } from &#39;react-redux&#39;;
import { getCurrentUser, Store } from &#39;../../store/rootReducer&#39;;
import { getWrappedDisplayName } from &#39;./utils&#39;;

export function withCurrentUser&lt;P&gt;(
  WrappedComponent: React.ComponentType&lt;P &amp; { currentUser: T.CurrentUser }&gt;
) {
  class Wrapper extends React.Component&lt;P &amp; { currentUser: T.CurrentUser }&gt; {
    static displayName = getWrappedDisplayName(WrappedComponent, &#39;withCurrentUser&#39;);

    render() {
      return &lt;WrappedComponent {...this.props} /&gt;;
    }
  }

  function mapStateToProps(state: Store) {
    return { currentUser: getCurrentUser(state) };
  }

  return connect(mapStateToProps)(Wrapper);
}
</pre></div>
</code></pre></td></tr></table>
</div> <!-- class=content -->
<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit v1.2.3</a> (<a href='https://git-scm.com/'>git 2.39.1</a>) at 2024-12-29 10:08:19 +0000</div>
</div> <!-- id=cgit -->
</body>
</html>
