From 4f9f98c12f8248684e66f98f7e2dd640b4fad4ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Wed, 24 Aug 2022 17:41:08 +0200 Subject: [PATCH] Fallback to root if the picker folder doesn't exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- core/src/OC/dialogs.js | 221 ++++++++++++++++++++++------------------- dist/core-login.js | 4 +- dist/core-login.js.map | 2 +- dist/core-main.js | 4 +- dist/core-main.js.map | 2 +- 5 files changed, 125 insertions(+), 108 deletions(-) diff --git a/core/src/OC/dialogs.js b/core/src/OC/dialogs.js index 83f391fc99cd7..55fd239cf22e7 100644 --- a/core/src/OC/dialogs.js +++ b/core/src/OC/dialogs.js @@ -1133,7 +1133,7 @@ const Dialogs = { /** * fills the filepicker with files */ - _fillFilePicker: function(dir) { + _fillFilePicker: async function(dir) { var self = this this.$filelist.empty() this.$filePicker.find('.emptycontent').hide() @@ -1151,126 +1151,143 @@ const Dialogs = { } else { self.$fileListHeader.find('[data-sort=' + self.filepicker.sortField + '] .sort-indicator').addClass('icon-triangle-s') } - self.filepicker.filesClient.getFolderContents(dir).then(function(status, files) { - self.filelist = files - if (filter && filter.length > 0 && filter.indexOf('*') === -1) { - files = files.filter(function(file) { - return file.type === 'dir' || filter.indexOf(file.mimetype) !== -1 + + // Wrap within a method because a promise cannot return multiple values + // But the client impleemntation still does it... + var getFolderContents = async function(dir) { + return self.filepicker.filesClient.getFolderContents(dir) + .then((status, files) => { + return files }) - } + } - if (advancedFilter) { - files = files.filter(advancedFilter) - } + try { + var files = await getFolderContents(dir) + } catch (error) { + // fallback to root if requested dir is non-existent + console.error('Requested path does not exists, falling back to root') + var files = await getFolderContents('/') + this.$filePicker.data('path', '/') + } + + self.filelist = files + if (filter && filter.length > 0 && filter.indexOf('*') === -1) { + files = files.filter(function(file) { + return file.type === 'dir' || filter.indexOf(file.mimetype) !== -1 + }) + } - // Check if the showHidden input field exist and if it exist follow it - // Otherwise just show the hidden files - const showHiddenInput = document.getElementById('showHiddenFiles') - const showHidden = showHiddenInput === null || showHiddenInput.value === "1" - if (!showHidden) { - files = files.filter(function(file) { - return !file.name.startsWith('.') - }) - } + if (advancedFilter) { + files = files.filter(advancedFilter) + } - var Comparators = { - name: function(fileInfo1, fileInfo2) { - if (fileInfo1.type === 'dir' && fileInfo2.type !== 'dir') { - return -1 - } - if (fileInfo1.type !== 'dir' && fileInfo2.type === 'dir') { - return 1 - } - return OC.Util.naturalSortCompare(fileInfo1.name, fileInfo2.name) - }, - size: function(fileInfo1, fileInfo2) { - return fileInfo1.size - fileInfo2.size - }, - mtime: function(fileInfo1, fileInfo2) { - return fileInfo1.mtime - fileInfo2.mtime - } - } - var comparator = Comparators[self.filepicker.sortField] || Comparators.name - files = files.sort(function(file1, file2) { - var isFavorite = function(fileInfo) { - return fileInfo.tags && fileInfo.tags.indexOf(OC.TAG_FAVORITE) >= 0 - } + // Check if the showHidden input field exist and if it exist follow it + // Otherwise just show the hidden files + const showHiddenInput = document.getElementById('showHiddenFiles') + const showHidden = showHiddenInput === null || showHiddenInput.value === "1" + if (!showHidden) { + files = files.filter(function(file) { + return !file.name.startsWith('.') + }) + } - if (isFavorite(file1) && !isFavorite(file2)) { + var Comparators = { + name: function(fileInfo1, fileInfo2) { + if (fileInfo1.type === 'dir' && fileInfo2.type !== 'dir') { return -1 - } else if (!isFavorite(file1) && isFavorite(file2)) { + } + if (fileInfo1.type !== 'dir' && fileInfo2.type === 'dir') { return 1 } + return OC.Util.naturalSortCompare(fileInfo1.name, fileInfo2.name) + }, + size: function(fileInfo1, fileInfo2) { + return fileInfo1.size - fileInfo2.size + }, + mtime: function(fileInfo1, fileInfo2) { + return fileInfo1.mtime - fileInfo2.mtime + } + } + var comparator = Comparators[self.filepicker.sortField] || Comparators.name + files = files.sort(function(file1, file2) { + var isFavorite = function(fileInfo) { + return fileInfo.tags && fileInfo.tags.indexOf(OC.TAG_FAVORITE) >= 0 + } - return self.filepicker.sortOrder === 'asc' ? comparator(file1, file2) : -comparator(file1, file2) - }) + if (isFavorite(file1) && !isFavorite(file2)) { + return -1 + } else if (!isFavorite(file1) && isFavorite(file2)) { + return 1 + } + + return self.filepicker.sortOrder === 'asc' ? comparator(file1, file2) : -comparator(file1, file2) + }) + + self._fillSlug() + + if (files.length === 0) { + self.$filePicker.find('.emptycontent').show() + self.$fileListHeader.hide() + } else { + self.$filePicker.find('.emptycontent').hide() + self.$fileListHeader.show() + } - self._fillSlug() + self.$filelist.empty(); - if (files.length === 0) { - self.$filePicker.find('.emptycontent').show() - self.$fileListHeader.hide() + $.each(files, function(idx, entry) { + entry.icon = OC.MimeType.getIconUrl(entry.mimetype) + var simpleSize, sizeColor + if (typeof (entry.size) !== 'undefined' && entry.size >= 0) { + simpleSize = OC.Util.humanFileSize(parseInt(entry.size, 10), true) + sizeColor = Math.round(160 - Math.pow((entry.size / (1024 * 1024)), 2)) } else { - self.$filePicker.find('.emptycontent').hide() - self.$fileListHeader.show() + simpleSize = t('files', 'Pending') + sizeColor = 80 } - self.$filelist.empty(); - - $.each(files, function(idx, entry) { - entry.icon = OC.MimeType.getIconUrl(entry.mimetype) - var simpleSize, sizeColor - if (typeof (entry.size) !== 'undefined' && entry.size >= 0) { - simpleSize = OC.Util.humanFileSize(parseInt(entry.size, 10), true) - sizeColor = Math.round(160 - Math.pow((entry.size / (1024 * 1024)), 2)) - } else { - simpleSize = t('files', 'Pending') - sizeColor = 80 - } + // split the filename in half if the size is bigger than 20 char + // for ellipsis + if (entry.name.length >= 10) { + // leave maximum 10 letters + var split = Math.min(Math.floor(entry.name.length / 2), 10) + var filename1 = entry.name.substr(0, entry.name.length - split) + var filename2 = entry.name.substr(entry.name.length - split) + } else { + var filename1 = entry.name + var filename2 = '' + } - // split the filename in half if the size is bigger than 20 char - // for ellipsis - if (entry.name.length >= 10) { - // leave maximum 10 letters - var split = Math.min(Math.floor(entry.name.length / 2), 10) - var filename1 = entry.name.substr(0, entry.name.length - split) - var filename2 = entry.name.substr(entry.name.length - split) - } else { - var filename1 = entry.name - var filename2 = '' + var $row = self.$listTmpl.octemplate({ + type: entry.type, + dir: dir, + filename: entry.name, + filename1: filename1, + filename2: filename2, + date: OC.Util.relativeModifiedDate(entry.mtime), + size: simpleSize, + sizeColor: sizeColor, + icon: entry.icon + }) + if (entry.type === 'file') { + var urlSpec = { + file: dir + '/' + entry.name, + x: 100, + y: 100 } - - var $row = self.$listTmpl.octemplate({ - type: entry.type, - dir: dir, - filename: entry.name, - filename1: filename1, - filename2: filename2, - date: OC.Util.relativeModifiedDate(entry.mtime), - size: simpleSize, - sizeColor: sizeColor, - icon: entry.icon - }) - if (entry.type === 'file') { - var urlSpec = { - file: dir + '/' + entry.name, - x: 100, - y: 100 + var img = new Image() + var previewUrl = OC.generateUrl('/core/preview.png?') + $.param(urlSpec) + img.onload = function() { + if (img.width > 5) { + $row.find('td.filename').attr('style', 'background-image:url(' + previewUrl + ')') } - var img = new Image() - var previewUrl = OC.generateUrl('/core/preview.png?') + $.param(urlSpec) - img.onload = function() { - if (img.width > 5) { - $row.find('td.filename').attr('style', 'background-image:url(' + previewUrl + ')') - } - } - img.src = previewUrl } - self.$filelist.append($row) - }) - - self.$filelistContainer.removeClass('icon-loading') + img.src = previewUrl + } + self.$filelist.append($row) }) + + self.$filelistContainer.removeClass('icon-loading') }, /** * fills the tree list with directories diff --git a/dist/core-login.js b/dist/core-login.js index 3646ae6257186..a3b308b61e9ad 100644 --- a/dist/core-login.js +++ b/dist/core-login.js @@ -1,3 +1,3 @@ /*! For license information please see core-login.js.LICENSE.txt */ -!function(){var e,o={97646:function(e,o,r){"use strict";var i=r(20144),a=r(74854),s=r(19755),l=r.n(s),c=r(79753),u={},d=[],p=r(18181),f=r(26932),h={updatableNotification:null,getDefaultNotificationFunction:null,setDefault:function(t){this.getDefaultNotificationFunction=t},hide:function(t,e){p.ZP.isFunction(t)&&(e=t,t=void 0),t?(t.each((function(){l()(this)[0].toastify?l()(this)[0].toastify.hideToast():console.error("cannot hide toast because object is not set"),this===this.updatableNotification&&(this.updatableNotification=null)})),e&&e.call(),this.getDefaultNotificationFunction&&this.getDefaultNotificationFunction()):console.error("Missing argument $row in OC.Notification.hide() call, caller needs to be adjusted to only dismiss its own notification")},showHtml:function(t,e){(e=e||{}).isHTML=!0,e.timeout=e.timeout?e.timeout:f.Rl;var n=(0,f.PV)(t,e);return n.toastElement.toastify=n,l()(n.toastElement)},show:function(t,e){(e=e||{}).timeout=e.timeout?e.timeout:f.Rl;var n=(0,f.PV)(function(t){return t.toString().split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""").split("'").join("'")}(t),e);return n.toastElement.toastify=n,l()(n.toastElement)},showUpdate:function(t){return this.updatableNotification&&this.updatableNotification.hideToast(),this.updatableNotification=(0,f.PV)(t,{timeout:f.Rl}),this.updatableNotification.toastElement.toastify=this.updatableNotification,l()(this.updatableNotification.toastElement)},showTemporary:function(t,e){(e=e||{}).timeout=e.timeout||f.TN;var n=(0,f.PV)(t,e);return n.toastElement.toastify=n,l()(n.toastElement)},isHidden:function(){return!l()("#content").find(".toastify").length}},m=p.ZP.throttle((function(){h.showTemporary(t("core","Connection to server lost"))}),7e3,{trailing:!1}),g={enableDynamicSlideToggle:function(){},showAppSidebar:function(t){(t||l()("#app-sidebar")).removeClass("disappear").show(),l()("#app-content").trigger(new(l().Event)("appresized"))},hideAppSidebar:function(t){(t||l()("#app-sidebar")).hide().addClass("disappear"),l()("#app-content").trigger(new(l().Event)("appresized"))}};function v(t,e,n){"post"!==t&&"delete"!==t||!$t.PasswordConfirmation.requiresPasswordConfirmation()?(n=n||{},l().ajax({type:t.toUpperCase(),url:(0,c.generateOcsUrl)("apps/provisioning_api/api/v1/config/apps")+e,data:n.data||{},success:n.success,error:n.error})):$t.PasswordConfirmation.requirePasswordConfirmation(_.bind(v,this,t,e,n))}var w=window.oc_appconfig||{},y={getValue:function(t,e,n,o){!function(t,e,n,o){(o=o||{}).data={defaultValue:n},v("get","/"+t+"/"+e,o)}(t,e,n,{success:o})},setValue:function(t,e,n){!function(t,e,n,o){(o=o||{}).data={value:n},v("post","/"+t+"/"+e,o)}(t,e,n)},getApps:function(t){!function(t){v("get","",t)}({success:t})},getKeys:function(t,e){!function(t,e){v("get","/"+t,e)}(t,{success:e})},deleteKey:function(t,e){!function(t,e,n){v("delete","/"+t+"/"+e,void 0)}(t,e)}},b=void 0!==window._oc_appswebroots&&window._oc_appswebroots,P=r(72316),C=r.n(P),k=r(87240),x={create:"POST",update:"PROPPATCH",patch:"PROPPATCH",delete:"DELETE",read:"PROPFIND"};function A(t,e){if(p.ZP.isArray(t))return p.ZP.map(t,(function(t){return A(t,e)}));var n={href:t.href};return p.ZP.each(t.propStat,(function(t){if("HTTP/1.1 200 OK"===t.status)for(var o in t.properties){var r=o;o in e&&(r=e[o]),n[r]=t.properties[o]}})),n.id||(n.id=O(n.href)),n}function O(t){var e=t.indexOf("?");e>0&&(t=t.substr(0,e));var n,o=t.split("/");do{n=o[o.length-1],o.pop()}while(!n&&o.length>0);return n}function T(t){return t>=200&&t<=299}function E(t,e,n,o){return t.propPatch(e.url,function(t,e){var n,o={};for(n in t){var r=e[n],i=t[n];r||(console.warn('No matching DAV property for property "'+n),r=n),(p.ZP.isBoolean(i)||p.ZP.isNumber(i))&&(i=""+i),o[r]=i}return o}(n.changed,e.davProperties),o).then((function(t){T(t.status)?p.ZP.isFunction(e.success)&&e.success(n.toJSON()):p.ZP.isFunction(e.error)&&e.error(t)}))}var j=C().noConflict();Object.assign(j,{davCall:function(t,e){var n=new k.dav.Client({baseUrl:t.url,xmlNamespaces:p.ZP.extend({"DAV:":"d","http://owncloud.org/ns":"oc"},t.xmlNamespaces||{})});n.resolveUrl=function(){return t.url};var o=p.ZP.extend({"X-Requested-With":"XMLHttpRequest",requesttoken:OC.requestToken},t.headers);return"PROPFIND"===t.type?function(t,e,n,o){return t.propFind(e.url,p.ZP.values(e.davProperties)||[],e.depth,o).then((function(t){if(T(t.status)){if(p.ZP.isFunction(e.success)){var n=p.ZP.invert(e.davProperties),o=A(t.body,n);e.depth>0&&o.shift(),e.success(o)}}else p.ZP.isFunction(e.error)&&e.error(t)}))}(n,t,0,o):"PROPPATCH"===t.type?E(n,t,e,o):"MKCOL"===t.type?function(t,e,n,o){return t.request(e.type,e.url,o,null).then((function(r){T(r.status)?E(t,e,n,o):p.ZP.isFunction(e.error)&&e.error(r)}))}(n,t,e,o):function(t,e,n,o){return o["Content-Type"]="application/json",t.request(e.type,e.url,o,e.data).then((function(t){if(T(t.status)){if(p.ZP.isFunction(e.success)){if("PUT"===e.type||"POST"===e.type||"MKCOL"===e.type){var o=t.body||n.toJSON(),r=t.xhr.getResponseHeader("Content-Location");return"POST"===e.type&&r&&(o.id=O(r)),void e.success(o)}if(207===t.status){var i=p.ZP.invert(e.davProperties);e.success(A(t.body,i))}else e.success(t.body)}}else p.ZP.isFunction(e.error)&&e.error(t)}))}(n,t,e,o)},davSync:function(t){return function(e,n,o){var r={type:x[e]||e},i=n instanceof t.Collection;if("update"===e&&(n.hasInnerCollection?r.type="MKCOL":(n.usePUT||n.collection&&n.collection.usePUT)&&(r.type="PUT")),o.url||(r.url=p.ZP.result(n,"url")||function(){throw new Error('A "url" property or function must be specified')}()),null!=o.data||!n||"create"!==e&&"update"!==e&&"patch"!==e||(r.data=JSON.stringify(o.attrs||n.toJSON(o))),"PROPFIND"!==r.type&&(r.processData=!1),"PROPFIND"===r.type||"PROPPATCH"===r.type){var a=n.davProperties;!a&&n.model&&(a=n.model.prototype.davProperties),a&&(p.ZP.isFunction(a)?r.davProperties=a.call(n):r.davProperties=a),r.davProperties=p.ZP.extend(r.davProperties||{},o.davProperties),p.ZP.isUndefined(o.depth)&&(o.depth=i?1:0)}var s=o.error;o.error=function(t,e,n){o.textStatus=e,o.errorThrown=n,s&&s.call(o.context,t,e,n)};var l=o.xhr=t.davCall(p.ZP.extend(r,o),n);return n.trigger("request",n,l,o),l}}(j)});var S=j,L=r(65358),I=window._oc_config||{},U=P.Model.extend({defaults:{fullName:"",lastMessage:"",actions:[],hasOneAction:!1,hasTwoActions:!1,hasManyActions:!1},initialize:function(){0===this.get("actions").length?this.set("hasOneAction",!0):1===this.get("actions").length?(this.set("hasTwoActions",!0),this.set("secondAction",this.get("actions")[0])):this.set("hasManyActions",!0)}}),$=P.Collection.extend({model:U}),N=P.View.extend({_collection:void 0,_subViews:[],initialize:function(t){this._collection=t.collection},render:function(){var t=this;return t.$el.html(""),t._subViews=[],t._collection.forEach((function(e){var n=new R({model:e});n.render(),t.$el.append(n.$el),n.on("toggle:actionmenu",t._onChildActionMenuToggle,t),t._subViews.push(n)})),t},_onChildActionMenuToggle:function(t){this._subViews.forEach((function(e){e.trigger("parent:toggle:actionmenu",t)}))}}),R=P.View.extend({className:"contact",_template:void 0,_model:void 0,_actionMenuShown:!1,events:{"click .icon-more":"_onToggleActionsMenu"},contactTemplate:r(10944),template:function(t){return this.contactTemplate(t)},initialize:function(t){this._model=t.model,this.on("parent:toggle:actionmenu",this._onOtherActionMenuOpened,this)},render:function(){return this.$el.html(this.template({contact:this._model.toJSON()})),this.delegateEvents(),this.$("div.avatar").imageplaceholder(this._model.get("fullName")),this.$(".top-action").tooltip({placement:"left"}),this.$(".second-action").tooltip({placement:"left"}),this},_onToggleActionsMenu:function(){this._actionMenuShown=!this._actionMenuShown,this._actionMenuShown?this.$(".menu").show():this.$(".menu").hide(),this.trigger("toggle:actionmenu",this.$el)},_onOtherActionMenuOpened:function(t){this.$el.is(t)||(this._actionMenuShown=!1,this.$(".menu").hide())}}),F=P.View.extend({_loadingTemplate:void 0,_errorTemplate:void 0,_contentTemplate:void 0,_contactsTemplate:void 0,_contacts:void 0,_searchTerm:"",events:{"input #contactsmenu-search":"_onSearch"},templates:{loading:r(95386),error:r(20421),menu:r(66115),list:r(34083)},_onSearch:p.ZP.debounce((function(t){var e=this.$("#contactsmenu-search").val();e!==this._searchTerm&&(this.trigger("search",this.$("#contactsmenu-search").val()),this._searchTerm=e)}),700),loadingTemplate:function(t){return this.templates.loading(t)},errorTemplate:function(e){return this.templates.error(p.ZP.extend({couldNotLoadText:t("core","Could not load your contacts")},e))},contentTemplate:function(e){return this.templates.menu(p.ZP.extend({searchContactsText:t("core","Search contacts …")},e))},contactsTemplate:function(e){return this.templates.list(p.ZP.extend({noContactsFoundText:t("core","No contacts found"),showAllContactsText:t("core","Show all contacts …"),contactsAppMgmtText:t("core","Install the Contacts app")},e))},initialize:function(t){this.options=t},showLoading:function(t){this.render(),this._contacts=void 0,this.$(".content").html(this.loadingTemplate({loadingText:t}))},showError:function(){this.render(),this._contacts=void 0,this.$(".content").html(this.errorTemplate())},showContacts:function(t,e){this._contacts=t.contacts,this.render({contacts:t.contacts});var n=new N({collection:t.contacts});n.render(),this.$(".content").html(this.contactsTemplate({contacts:t.contacts,searchTerm:e,contactsAppEnabled:t.contactsAppEnabled,contactsAppURL:$t.generateUrl("/apps/contacts"),canInstallApp:$t.isUserAdmin(),contactsAppMgmtURL:$t.generateUrl("/settings/apps/social/contacts")})),this.$("#contactsmenu-contacts").html(n.$el)},render:function(t){var e=this.$("#contactsmenu-search").val();return this.$el.html(this.contentTemplate(t)),this.$("#contactsmenu-search").val(e),this.$("#contactsmenu-search").focus(),this}}),M=function(t){this.initialize(t)};M.prototype={$el:void 0,_$trigger:void 0,_view:void 0,_contactsPromise:void 0,initialize:function(t){this.$el=t.el,this._$trigger=t.trigger,this._view=new F({el:this.$el}),this._view.on("search",(function(t){this._loadContacts(t)}),this),$t.registerMenu(this._$trigger,this.$el,function(){this._toggleVisibility(!0)}.bind(this),!0),this.$el.on("beforeHide",function(){this._toggleVisibility(!1)}.bind(this))},_toggleVisibility:function(t){return t?this._loadContacts():(this.$el.html(""),Promise.resolve())},_getContacts:function(t){var e=$t.generateUrl("/contactsmenu/contacts");return Promise.resolve(l().ajax(e,{method:"POST",data:{filter:t}}))},_loadContacts:function(e){var n=this;return n._contactsPromise||(n._contactsPromise=n._getContacts(e)),p.ZP.isUndefined(e)||""===e?n._view.showLoading(t("core","Loading your contacts …")):n._view.showLoading(t("core","Looking for {term} …",{term:e})),n._contactsPromise.then((function(t){t.contacts=new $(t.contacts),n._view.showContacts(t,e)}),(function(t){n._view.showError(),console.error("There was an error loading your contacts",t)})).then((function(){delete n._contactsPromise})).catch(console.error.bind(this))}};var B=M,z=document.getElementsByTagName("head")[0].getAttribute("data-user"),D=document.getElementsByTagName("head")[0].getAttribute("data-user-displayname"),Z=void 0!==z&&z;function H(t,e){for(var n=0;n");f.attr("type",a?"password":"text").attr("id",c+"-input").attr("placeholder",i);var h=l()("