From adff75d559f660dfa7c088ab0846829fd586ab4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Sun, 25 Jun 2023 11:46:53 +0200 Subject: [PATCH] fix: restore AppsSlideToggle feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ Signed-off-by: nextcloud-command --- core/src/OC/apps.js | 135 +++++++++++++++++++++++++++++++++ core/src/OC/index.js | 3 +- core/src/main.js | 2 + dist/core-login.js | 4 +- dist/core-login.js.LICENSE.txt | 23 ++++++ dist/core-login.js.map | 2 +- dist/core-main.js | 4 +- dist/core-main.js.LICENSE.txt | 23 ++++++ dist/core-main.js.map | 2 +- 9 files changed, 191 insertions(+), 7 deletions(-) create mode 100644 core/src/OC/apps.js diff --git a/core/src/OC/apps.js b/core/src/OC/apps.js new file mode 100644 index 0000000000000..bbda177409ea8 --- /dev/null +++ b/core/src/OC/apps.js @@ -0,0 +1,135 @@ +/** + * @copyright Bernhard Posselt 2014 + * + * @author Christoph Wurst + * @author John Molakvoæ + * + * @license AGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +import $ from 'jquery' + +let dynamicSlideToggleEnabled = false + +const Apps = { + enableDynamicSlideToggle() { + dynamicSlideToggleEnabled = true + }, +} + +/** + * Shows the #app-sidebar and add .with-app-sidebar to subsequent siblings + * + * @param {object} [$el] sidebar element to show, defaults to $('#app-sidebar') + */ +Apps.showAppSidebar = function($el) { + const $appSidebar = $el || $('#app-sidebar') + $appSidebar.removeClass('disappear').show() + $('#app-content').trigger(new $.Event('appresized')) +} + +/** + * Shows the #app-sidebar and removes .with-app-sidebar from subsequent + * siblings + * + * @param {object} [$el] sidebar element to hide, defaults to $('#app-sidebar') + */ +Apps.hideAppSidebar = function($el) { + const $appSidebar = $el || $('#app-sidebar') + $appSidebar.hide().addClass('disappear') + $('#app-content').trigger(new $.Event('appresized')) +} + +/** + * Provides a way to slide down a target area through a button and slide it + * up if the user clicks somewhere else. Used for the news app settings and + * add new field. + * + * Usage: + * + *
I'm sliding up
+ */ +export const registerAppsSlideToggle = () => { + let buttons = $('[data-apps-slide-toggle]') + + if (buttons.length === 0) { + $('#app-navigation').addClass('without-app-settings') + } + + $(document).click(function(event) { + + if (dynamicSlideToggleEnabled) { + buttons = $('[data-apps-slide-toggle]') + } + + buttons.each(function(index, button) { + + const areaSelector = $(button).data('apps-slide-toggle') + const area = $(areaSelector) + + /** + * + */ + function hideArea() { + area.slideUp(OC.menuSpeed * 4, function() { + area.trigger(new $.Event('hide')) + }) + area.removeClass('opened') + $(button).removeClass('opened') + } + + /** + * + */ + function showArea() { + area.slideDown(OC.menuSpeed * 4, function() { + area.trigger(new $.Event('show')) + }) + area.addClass('opened') + $(button).addClass('opened') + const input = $(areaSelector + ' [autofocus]') + if (input.length === 1) { + input.focus() + } + } + + // do nothing if the area is animated + if (!area.is(':animated')) { + + // button toggles the area + if ($(button).is($(event.target).closest('[data-apps-slide-toggle]'))) { + if (area.is(':visible')) { + hideArea() + } else { + showArea() + } + + // all other areas that have not been clicked but are open + // should be slid up + } else { + const closest = $(event.target).closest(areaSelector) + if (area.is(':visible') && closest[0] !== area[0]) { + hideArea() + } + } + } + }) + + }) +} + +export default Apps diff --git a/core/src/OC/index.js b/core/src/OC/index.js index 18fec8af8ed36..becaabe6e211f 100644 --- a/core/src/OC/index.js +++ b/core/src/OC/index.js @@ -29,6 +29,7 @@ import { processAjaxError, registerXHRForErrorProcessing, } from './xhr-error.js' +import Apps from './apps.js' import { AppConfig, appConfig } from './appconfig.js' import appswebroots from './appswebroots.js' import Backbone from './backbone.js' @@ -135,7 +136,7 @@ export default { * @deprecated 17.0.0 */ fileIsBlacklisted: file => !!(file.match(Config.blacklist_files_regex)), - + Apps, AppConfig, appConfig, appswebroots, diff --git a/core/src/main.js b/core/src/main.js index 11a7ece611413..9c7e150bee3c1 100644 --- a/core/src/main.js +++ b/core/src/main.js @@ -23,6 +23,7 @@ * */ +import { registerAppsSlideToggle } from './OC/apps.js' import $ from 'jquery' import 'core-js/stable/index.js' import 'regenerator-runtime/runtime.js' @@ -38,6 +39,7 @@ import { initCore } from './init.js' window.addEventListener('DOMContentLoaded', function() { initCore() + registerAppsSlideToggle() // fallback to hashchange when no history support if (window.history.pushState) { diff --git a/dist/core-login.js b/dist/core-login.js index 14bd56421e08a..5a2fb8fa5bc88 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 */ -(()=>{var e,r={65358:(t,e,n)=>{"use strict";function r(){for(var t=arguments.length,e=new Array(t),n=0;n0}));if(r.length<1)return"";var i=r[r.length-1],o="/"===r[0].charAt(0),s="/"===i.charAt(i.length-1),a=r.reduce((function(t,e){return t.concat(e.split("/"))}),[]),l=!o,c=a.reduce((function(t,e){return""===e?t:l?(l=!1,t+e):t+"/"+e}),"");return s?c+"/":c}e.Ec=function(t){return t?t.split("/").map(encodeURIComponent).join("/"):t},e.EZ=function(t){return t.replace(/\\/g,"/").replace(/.*\//,"")},e.XX=function(t){return t.replace(/\\/g,"/").replace(/\/[^\/]*$/,"")},e.RQ=r,e.Mg=function(t,e){var n=(t||"").split("/").filter((function(t){return"."!==t})),i=(e||"").split("/").filter((function(t){return"."!==t}));return(t=r.apply(void 0,n))===(e=r.apply(void 0,i))},n(21249),n(74916),n(23123),n(15306),n(57327),n(85827),n(92222)},57469:(e,r,i)=>{"use strict";var o={};i.r(o),i.d(o,{exclude:()=>re,extract:()=>Jt,parse:()=>Xt,parseUrl:()=>te,pick:()=>ne,stringify:()=>Qt,stringifyUrl:()=>ee});var s=i(20144),a=i(69183),l=i(59050),c=i(19755),u=i.n(c),d=i(64024),f=i(25108);const h={updatableNotification:null,getDefaultNotificationFunction:null,setDefault(t){this.getDefaultNotificationFunction=t},hide(t,e){l.default.isFunction(t)&&(e=t,t=void 0),t?(t.each((function(){u()(this)[0].toastify?u()(this)[0].toastify.hideToast():f.error("cannot hide toast because object is not set"),this===this.updatableNotification&&(this.updatableNotification=null)})),e&&e.call(),this.getDefaultNotificationFunction&&this.getDefaultNotificationFunction()):f.error("Missing argument $row in OC.Notification.hide() call, caller needs to be adjusted to only dismiss its own notification")},showHtml(t,e){(e=e||{}).isHTML=!0,e.timeout=e.timeout?e.timeout:d.Rl;const n=(0,d.PV)(t,e);return n.toastElement.toastify=n,u()(n.toastElement)},show(t,e){(e=e||{}).timeout=e.timeout?e.timeout:d.Rl;const n=(0,d.PV)(function(t){return t.toString().split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""").split("'").join("'")}(t),e);return n.toastElement.toastify=n,u()(n.toastElement)},showUpdate(t){return this.updatableNotification&&this.updatableNotification.hideToast(),this.updatableNotification=(0,d.PV)(t,{timeout:d.Rl}),this.updatableNotification.toastElement.toastify=this.updatableNotification,u()(this.updatableNotification.toastElement)},showTemporary(t,e){(e=e||{}).timeout=e.timeout||d.TN;const n=(0,d.PV)(t,e);return n.toastElement.toastify=n,u()(n.toastElement)},isHidden:()=>!u()("#content").find(".toastify").length},p=l.default.throttle((()=>{h.showTemporary(t("core","Connection to server lost"))}),7e3,{trailing:!1});var m=i(79753);function g(t,e,n){"post"!==t&&"delete"!==t||!Nt.PasswordConfirmation.requiresPasswordConfirmation()?(n=n||{},u().ajax({type:t.toUpperCase(),url:(0,m.generateOcsUrl)("apps/provisioning_api/api/v1/config/apps")+e,data:n.data||{},success:n.success,error:n.error})):Nt.PasswordConfirmation.requirePasswordConfirmation(_.bind(g,this,t,e,n))}const v=window.oc_appconfig||{},y={getValue:function(t,e,n,r){!function(t,e,n,r){(r=r||{}).data={defaultValue:n},g("get","/"+t+"/"+e,r)}(t,e,n,{success:r})},setValue:function(t,e,n){!function(t,e,n,r){(r=r||{}).data={value:n},g("post","/"+t+"/"+e,r)}(t,e,n)},getApps:function(t){!function(t){g("get","",t)}({success:t})},getKeys:function(t,e){!function(t,e){g("get","/"+t,e)}(t,{success:e})},deleteKey:function(t,e){!function(t,e,n){g("delete","/"+t+"/"+e,void 0)}(t,e)}},b=void 0!==window._oc_appswebroots&&window._oc_appswebroots;var w=i(72316),A=i.n(w),x=i(76591),C=i(25108);const k={create:"POST",update:"PROPPATCH",patch:"PROPPATCH",delete:"DELETE",read:"PROPFIND"};function P(t,e){if(l.default.isArray(t))return l.default.map(t,(function(t){return P(t,e)}));var n={href:t.href};return l.default.each(t.propStat,(function(t){if("HTTP/1.1 200 OK"===t.status)for(var r in t.properties){var i=r;r in e&&(i=e[r]),n[i]=t.properties[r]}})),n.id||(n.id=E(n.href)),n}function E(t){var e=t.indexOf("?");e>0&&(t=t.substr(0,e));var n,r=t.split("/");do{n=r[r.length-1],r.pop()}while(!n&&r.length>0);return n}function T(t){return t>=200&&t<=299}function j(t,e,n,r){return t.propPatch(e.url,function(t,e){var n,r={};for(n in t){var i=e[n],o=t[n];i||(C.warn('No matching DAV property for property "'+n),i=n),(l.default.isBoolean(o)||l.default.isNumber(o))&&(o=""+o),r[i]=o}return r}(n.changed,e.davProperties),r).then((function(t){T(t.status)?l.default.isFunction(e.success)&&e.success(n.toJSON()):l.default.isFunction(e.error)&&e.error(t)}))}const O=A().noConflict();Object.assign(O,{davCall:(t,e)=>{var n=new x.dav.Client({baseUrl:t.url,xmlNamespaces:l.default.extend({"DAV:":"d","http://owncloud.org/ns":"oc"},t.xmlNamespaces||{})});n.resolveUrl=function(){return t.url};var r=l.default.extend({"X-Requested-With":"XMLHttpRequest",requesttoken:OC.requestToken},t.headers);return"PROPFIND"===t.type?function(t,e,n,r){return t.propFind(e.url,l.default.values(e.davProperties)||[],e.depth,r).then((function(t){if(T(t.status)){if(l.default.isFunction(e.success)){var n=l.default.invert(e.davProperties),r=P(t.body,n);e.depth>0&&r.shift(),e.success(r)}}else l.default.isFunction(e.error)&&e.error(t)}))}(n,t,0,r):"PROPPATCH"===t.type?j(n,t,e,r):"MKCOL"===t.type?function(t,e,n,r){return t.request(e.type,e.url,r,null).then((function(i){T(i.status)?j(t,e,n,r):l.default.isFunction(e.error)&&e.error(i)}))}(n,t,e,r):function(t,e,n,r){return r["Content-Type"]="application/json",t.request(e.type,e.url,r,e.data).then((function(t){if(T(t.status)){if(l.default.isFunction(e.success)){if("PUT"===e.type||"POST"===e.type||"MKCOL"===e.type){var r=t.body||n.toJSON(),i=t.xhr.getResponseHeader("Content-Location");return"POST"===e.type&&i&&(r.id=E(i)),void e.success(r)}if(207===t.status){var o=l.default.invert(e.davProperties);e.success(P(t.body,o))}else e.success(t.body)}}else l.default.isFunction(e.error)&&e.error(t)}))}(n,t,e,r)},davSync:(t=>(e,n,r)=>{var i={type:k[e]||e},o=n instanceof t.Collection;if("update"===e&&(n.hasInnerCollection?i.type="MKCOL":(n.usePUT||n.collection&&n.collection.usePUT)&&(i.type="PUT")),r.url||(i.url=l.default.result(n,"url")||function(){throw new Error('A "url" property or function must be specified')}()),null!=r.data||!n||"create"!==e&&"update"!==e&&"patch"!==e||(i.data=JSON.stringify(r.attrs||n.toJSON(r))),"PROPFIND"!==i.type&&(i.processData=!1),"PROPFIND"===i.type||"PROPPATCH"===i.type){var s=n.davProperties;!s&&n.model&&(s=n.model.prototype.davProperties),s&&(l.default.isFunction(s)?i.davProperties=s.call(n):i.davProperties=s),i.davProperties=l.default.extend(i.davProperties||{},r.davProperties),l.default.isUndefined(r.depth)&&(r.depth=o?1:0)}var a=r.error;r.error=function(t,e,n){r.textStatus=e,r.errorThrown=n,a&&a.call(r.context,t,e,n)};var c=r.xhr=t.davCall(l.default.extend(i,r),n);return n.trigger("request",n,c,r),c})(O)});const S=O;var N=i(65358);const I=window._oc_config||{};var L=i(25108);const F=w.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);const e=this.get("fullName");this.get("avatar")&&e&&this.set("avatarLabel",t("core","Avatar of {fullName}",{fullName:e}))}}),R=w.Collection.extend({model:F}),U=w.View.extend({_collection:void 0,_subViews:[],tagName:"ul",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 $({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)}))}}),$=w.View.extend({className:"contact",tagName:"li",_template:void 0,_model:void 0,_actionMenuShown:!1,events:{"click .icon-more":"_onToggleActionsMenu"},contactTemplate:i(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},_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())}}),M=w.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:i(95386),error:i(20421),menu:i(66115),list:i(34083)},_onSearch:l.default.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(l.default.extend({couldNotLoadText:t("core","Could not load your contacts")},e))},contentTemplate:function(e){return this.templates.menu(l.default.extend({searchContactsText:t("core","Search contacts …")},e))},contactsTemplate:function(e){return this.templates.list(l.default.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 U({collection:t.contacts});n.render(),this.$(".content").html(this.contactsTemplate({contacts:t.contacts,searchTerm:e,contactsAppEnabled:t.contactsAppEnabled,contactsAppURL:Nt.generateUrl("/apps/contacts"),canInstallApp:Nt.isUserAdmin(),contactsAppMgmtURL:Nt.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}}),B=function(t){this.initialize(t)};B.prototype={$el:void 0,_view:void 0,_contactsPromise:void 0,initialize:function(t){this.$el=u()(t.el),this._view=new M({el:this.$el}),this._view.on("search",(function(t){this.loadContacts(t)}),this)},_getContacts:function(t){var e=Nt.generateUrl("/contactsmenu/contacts");return Promise.resolve(u().ajax(e,{method:"POST",data:{filter:t}}))},loadContacts:function(e){var n=this;return n._contactsPromise||(n._contactsPromise=n._getContacts(e)),l.default.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 R(t.contacts),n._view.showContacts(t,e)}),(function(t){n._view.showError(),L.error("There was an error loading your contacts",t)})).then((function(){delete n._contactsPromise})).catch(L.error.bind(this))}};const z=B,D=document.getElementsByTagName("head")[0].getAttribute("data-user"),H=document.getElementsByTagName("head")[0].getAttribute("data-user-displayname"),q=void 0!==D&&D;var Y=i(25108);const V={Search:class{constructor(){OC.debug&&Y.warn("OCA.Search is deprecated. Please use the unified search API instead")}}},K=t=>"click"===t.type||"keydown"===t.type&&"Enter"===t.key;var Z=i(25108);const G={YES_NO_BUTTONS:70,OK_BUTTONS:71,FILEPICKER_TYPE_CHOOSE:1,FILEPICKER_TYPE_MOVE:2,FILEPICKER_TYPE_COPY:3,FILEPICKER_TYPE_COPY_MOVE:4,FILEPICKER_TYPE_CUSTOM:5,dialogsCounter:0,alert:function(t,e,n,r){this.message(t,e,"alert",G.OK_BUTTON,n,r)},info:function(t,e,n,r){this.message(t,e,"info",G.OK_BUTTON,n,r)},confirm:function(t,e,n,r){return this.message(t,e,"notice",G.YES_NO_BUTTONS,n,r)},confirmDestructive:function(t,e,n,r,i){return this.message(t,e,"none",n,r,void 0===i||i)},confirmHtml:function(t,e,n,r){return this.message(t,e,"notice",G.YES_NO_BUTTONS,n,r,!0)},prompt:function(e,n,r,i,o,s){return u().when(this._getMessageTemplate()).then((function(a){var c="oc-dialog-"+G.dialogsCounter+"-content",d="#"+c,f=a.octemplate({dialog_name:c,title:n,message:e,type:"notice"}),h=u()("");h.attr("type",s?"password":"text").attr("id",c+"-input").attr("placeholder",o);var p=u()("