12 |
- /*! third party licenses: dist/vendor.LICENSE.txt */
- var C=Object.defineProperty;var E=(e,i,s)=>i in e?C(e,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[i]=s;var r=(e,i,s)=>E(e,typeof i!="symbol"?i+"":i,s);import{bR as _,C as x,X as A,aV as g,a4 as N,ag as D,bS as d,b as L,B as $,P as R,a1 as k,bW as v,c1 as P,cc as M,c0 as q,cg as z,bZ as U,bQ as h,cf as B}from"./core-common.mjs";import"./chunks/index-PaKKd09k.mjs";import{z as c}from"./chunks/_plugin-vue2_normalizer-VrK6B12S-BQkexw0P.mjs";import{c as W,i as j,k as H,p as V}from"./chunks/index-DG15V7L3.mjs";import{e as Y}from"./chunks/index-CPb3EwrS.mjs";import{T as S}from"./chunks/index-YIotKjSS.mjs";import{n as p,b as K,ae as Q}from"./chunks/icons-TElqpmA8.mjs";import{$ as X}from"./chunks/jquery-BdeSydBb.mjs";import{b as m,e as Z,p as G,l as y,g as F,c as J,f as ee,h as te,d as T}from"./chunks/api-Bu5d7DE4.mjs";import{l as I}from"./chunks/logger-R_K4lHwR.mjs";import"./chunks/index-CiG5J8j_.mjs";import"./chunks/index-tn-fAC9x.mjs";async function ie(e){const i=await _({method:"PROPFIND",url:e,data:W()}),s=OC.Files.getClient()._client.parseMultiStatus(i.data),a=OC.Files.getClient()._parseFileInfo(s[0]);return a.get=o=>a[o],a.isDirectory=()=>a.mimetype==="httpd/unix-directory",a}const se={name:"LegacyView",props:{component:{type:Object,required:!0},fileInfo:{type:Object,default:()=>{},required:!0}},watch:{fileInfo(e){this.setFileInfo(e)}},mounted(){this.component.$el.replaceAll(this.$el),this.setFileInfo(this.fileInfo)},methods:{setFileInfo(e){this.component.setFileInfo(new OCA.Files.FileInfoModel(e))}}};var ae=function(){var e=this,i=e._self._c;return i("div")},oe=[],ne=p(se,ae,oe,!1,null,null);const re=ne.exports,le={name:"SidebarTab",components:{NcAppSidebarTab:x,NcEmptyContent:A},props:{fileInfo:{type:Object,default:()=>{},required:!0},id:{type:String,required:!0},name:{type:String,required:!0},icon:{type:String,required:!1},onMount:{type:Function,required:!0},onUpdate:{type:Function,required:!0},onDestroy:{type:Function,required:!0},onScrollBottomReached:{type:Function,default:()=>{}}},data(){return{loading:!0}},computed:{activeTab(){return this.$parent.activeTab}},watch:{async fileInfo(e,i){e.id!==i.id&&(this.loading=!0,await this.onUpdate(this.fileInfo),this.loading=!1)}},async mounted(){this.loading=!0,await this.onMount(this.$refs.mount,this.fileInfo,this.$refs.tab),this.loading=!1},async beforeDestroy(){await this.onDestroy()}};var de=function(){var e=this,i=e._self._c;return i("NcAppSidebarTab",{ref:"tab",attrs:{id:e.id,name:e.name,icon:e.icon},on:{bottomReached:e.onScrollBottomReached},scopedSlots:e._u([{key:"icon",fn:function(){return[e._t("icon")]},proxy:!0}],null,!0)},[e.loading?i("NcEmptyContent",{attrs:{icon:"icon-loading"}}):e._e(),i("div",{ref:"mount"})],1)},ce=[],he=p(le,de,ce,!1,null,null);const fe=he.exports,ue=async e=>{const i="/systemtags-relations/files/"+e;try{const{data:s}=await m.getDirectoryContents(i,{data:Z,details:!0,glob:"/systemtags-relations/files/*/*"});return G(s)}catch(s){throw y.error(t("systemtags","Failed to load tags for file"),{error:s}),new Error(t("systemtags","Failed to load tags for file"))}},pe=async(e,i)=>{const s=F(e),a=await J(s),o={...s,id:a};return await O(o,i),o.id},O=async(e,i)=>{const s="/systemtags-relations/files/"+i+"/"+e.id,a=F(e);try{await m.customRequest(s,{method:"PUT",data:a})}catch(o){throw y.error(t("systemtags","Failed to set tag for file"),{error:o}),new Error(t("systemtags","Failed to set tag for file"))}},ge=async(e,i)=>{const s="/systemtags-relations/files/"+i+"/"+e.id;try{await m.deleteFile(s)}catch(a){throw y.error(t("systemtags","Failed to delete tag for file"),{error:a}),new Error(t("systemtags","Failed to delete tag for file"))}},me=g.extend({name:"SystemTags",components:{NcLoadingIcon:N,NcSelectTags:D},props:{fileId:{type:Number,required:!0}},data(){return{sortedTags:[],selectedTags:[],loadingTags:!1,loading:!1}},async created(){try{const e=await ee(),i=await te(),s=[],a=[];for(const n of e){if(i.includes(n.id)){s.push(n);continue}a.push(n)}const o=(n,l)=>i.indexOf(n.id)-i.indexOf(l.id);s.sort(o),this.sortedTags=[...s,...a]}catch{c(d("systemtags","Failed to load tags"))}},watch:{fileId:{immediate:!0,async handler(){this.loadingTags=!0;try{this.selectedTags=await ue(this.fileId),this.$emit("has-tags",this.selectedTags.length>0)}catch{c(d("systemtags","Failed to load selected tags"))}this.loadingTags=!1}}},methods:{t:d,createOption(e){for(const i of this.sortedTags){const{id:s,displayName:a,...o}=i;if(a===e&&Object.entries(o).every(([n,l])=>T[n]===l))return i}return{...T,displayName:e}},handleInput(e){this.selectedTags=e.filter(i=>!!i.id)},async handleSelect(e){const i=e[e.length-1];if(!i.id)return;const s=i;this.loading=!0;try{await O(s,this.fileId);const a=(o,n)=>o.id===s.id?-1:n.id===s.id?1:0;this.sortedTags.sort(a)}catch{c(d("systemtags","Failed to select tag"))}this.loading=!1},async handleCreate(e){this.loading=!0;try{const i=await pe(e,this.fileId),s={...e,id:i};this.sortedTags.unshift(s),this.selectedTags.push(s)}catch{c(d("systemtags","Failed to create tag"))}this.loading=!1},async handleDeselect(e){this.loading=!0;try{await ge(e,this.fileId)}catch{c(d("systemtags","Failed to delete tag"))}this.loading=!1}}});var ye=function(){var e=this,i=e._self._c;return e._self._setupProxy,i("div",{staticClass:"system-tags"},[e.loadingTags?i("NcLoadingIcon",{attrs:{name:e.t("systemtags","Loading collaborative tags …"),size:32}}):[i("NcSelectTags",{staticClass:"system-tags__select",attrs:{"input-label":e.t("systemtags","Search or create collaborative tags"),placeholder:e.t("systemtags","Collaborative tags …"),options:e.sortedTags,value:e.selectedTags,"create-option":e.createOption,taggable:!0,passthru:!0,"fetch-tags":!1,loading:e.loading},on:{input:e.handleInput,"option:selected":e.handleSelect,"option:created":e.handleCreate,"option:deselected":e.handleDeselect},scopedSlots:e._u([{key:"no-options",fn:function(){return[e._v(" "+e._s(e.t("systemtags","No tags to select, type to create a new tag"))+" ")]},proxy:!0}])})]],2)},be=[],we=p(me,ye,be,!1,null,"802c099e");const ve=we.exports,Se={name:"Sidebar",components:{LegacyView:re,NcActionButton:L,NcAppSidebar:$,NcDateTime:R,NcEmptyContent:A,NcIconSvgWrapper:k,SidebarTab:fe,SystemTags:ve},setup(){return{currentUser:v(),mdiStar:K,mdiStarOutline:Q}},data(){return{Sidebar:OCA.Files.Sidebar.state,showTags:!1,showTagsDefault:!0,error:null,loading:!0,fileInfo:null,isFullScreen:!1,hasLowHeight:!1}},computed:{file(){return this.Sidebar.file},tabs(){return this.Sidebar.tabs},views(){return this.Sidebar.views},davPath(){const e=this.currentUser.uid;return P("dav/files/".concat(e).concat(Y(this.file)))},activeTab(){return this.Sidebar.activeTab},size(){var e;return j((e=this.fileInfo)==null?void 0:e.size)},background(){return this.getPreviewIfAny(this.fileInfo)},appSidebar(){return this.fileInfo?{"data-mimetype":this.fileInfo.mimetype,active:this.activeTab,background:this.background,class:{"app-sidebar--has-preview":this.fileInfo.hasPreview&&!this.isFullScreen,"app-sidebar--full":this.isFullScreen},compact:this.hasLowHeight||!this.fileInfo.hasPreview||this.isFullScreen,loading:this.loading,name:this.fileInfo.name,title:this.fileInfo.name}:this.error?{key:"error",subname:"",name:"",class:{"app-sidebar--full":this.isFullScreen}}:{loading:this.loading,subname:"",name:"",class:{"app-sidebar--full":this.isFullScreen}}},defaultAction(){return this.fileInfo&&OCA.Files&&OCA.Files.App&&OCA.Files.App.fileList&&OCA.Files.App.fileList.fileActions&&OCA.Files.App.fileList.fileActions.getDefaultFileAction&&OCA.Files.App.fileList.fileActions.getDefaultFileAction(this.fileInfo.mimetype,this.fileInfo.type,OC.PERMISSION_READ)},defaultActionListener(){return this.defaultAction?"figure-click":null},isSystemTagsEnabled(){var e,i;return((i=(e=M())==null?void 0:e.systemtags)==null?void 0:i.enabled)===!0}},created(){q("files:node:deleted",this.onNodeDeleted),window.addEventListener("resize",this.handleWindowResize),this.handleWindowResize()},beforeDestroy(){z("file:node:deleted",this.onNodeDeleted),window.removeEventListener("resize",this.handleWindowResize)},methods:{canDisplay(e){return e.enabled(this.fileInfo)},resetData(){this.error=null,this.fileInfo=null,this.$nextTick(()=>{this.$refs.tabs&&this.$refs.tabs.updateTabs()})},getPreviewIfAny(e){if(e!=null&&e.hasPreview&&!this.isFullScreen){const i=(e==null?void 0:e.etag)||"";return U("/core/preview?fileId=".concat(e.id,"&x=").concat(screen.width,"&y=").concat(screen.height,"&a=true&v=").concat(i.slice(0,6)))}return this.getIconUrl(e)},getIconUrl(e){const i=(e==null?void 0:e.mimetype)||"application/octet-stream";return i==="httpd/unix-directory"?e.mountType==="shared"||e.mountType==="shared-root"?OC.MimeType.getIconUrl("dir-shared"):e.mountType==="external-root"?OC.MimeType.getIconUrl("dir-external"):e.mountType!==void 0&&e.mountType!==""?OC.MimeType.getIconUrl("dir-"+e.mountType):e.shareTypes&&(e.shareTypes.indexOf(S.SHARE_TYPE_LINK)>-1||e.shareTypes.indexOf(S.SHARE_TYPE_EMAIL)>-1)?OC.MimeType.getIconUrl("dir-public"):e.shareTypes&&e.shareTypes.length>0?OC.MimeType.getIconUrl("dir-shared"):OC.MimeType.getIconUrl("dir"):OC.MimeType.getIconUrl(i)},setActiveTab(e){OCA.Files.Sidebar.setActiveTab(e),this.tabs.forEach(i=>{try{i.setIsActive(e===i.id)}catch(s){I.error("Error while setting tab active state",{error:s,id:i.id,tab:i})}})},async toggleStarred(e){try{await _({method:"PROPPATCH",url:this.davPath,data:'<?xml version="1.0"?>\n <d:propertyupdate xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">\n '.concat(e?"<d:set>":"<d:remove>","\n <d:prop>\n <oc:favorite>1</oc:favorite>\n </d:prop>\n ").concat(e?"</d:set>":"</d:remove>","\n </d:propertyupdate>")});const i=this.fileInfo.type==="dir",s=i?H:V;h(e?"files:favorites:added":"files:favorites:removed",new s({fileid:this.fileInfo.id,source:this.davPath,root:"/files/".concat(v().uid),mime:i?void 0:this.fileInfo.mimetype})),this.fileInfo.isFavourited=e}catch(i){c(t("files","Unable to change the favourite state of the file")),I.error("Unable to change favourite state",{error:i})}},onDefaultAction(){this.defaultAction&&this.defaultAction.action(this.fileInfo.name,{fileInfo:this.fileInfo,dir:this.fileInfo.dir,fileList:OCA.Files.App.fileList,$file:X("body")})},toggleTags(){this.showTagsDefault=this.showTags=!this.showTags},async open(e){if(!e||e.trim()==="")throw new Error("Invalid path '".concat(e,"'"));const i=!!this.Sidebar.file;this.Sidebar.file=e,this.error=null,this.loading=!0;try{this.fileInfo=await ie(this.davPath),this.fileInfo.dir=this.file.split("/").slice(0,-1).join("/"),this.views.forEach(s=>{s.setFileInfo(this.fileInfo)}),await this.$nextTick(),this.setActiveTab(this.Sidebar.activeTab||this.tabs[0].id),this.loading=!1,await this.$nextTick(),i&&this.$refs.sidebar.focusActiveTabContent()}catch(s){throw this.loading=!1,this.error=t("files","Error while loading the file data"),console.error("Error while loading the file data",s),new Error(s)}},close(){this.Sidebar.file="",this.showTags=!1,this.resetData()},onNodeDeleted(e){this.fileInfo&&e&&this.fileInfo.id===e.fileid&&this.close()},setFullScreenMode(e){var i,s,a,o;this.isFullScreen=e,e?(i=document.querySelector("#content"))!=null&&i.classList.add("with-sidebar--full")||((s=document.querySelector("#content-vue"))==null||s.classList.add("with-sidebar--full")):(a=document.querySelector("#content"))!=null&&a.classList.remove("with-sidebar--full")||((o=document.querySelector("#content-vue"))==null||o.classList.remove("with-sidebar--full"))},setShowTagsDefault(e){this.showTagsDefault=e},handleOpening(){h("files:sidebar:opening")},handleOpened(){h("files:sidebar:opened")},handleClosing(){h("files:sidebar:closing")},handleClosed(){h("files:sidebar:closed")},handleWindowResize(){this.hasLowHeight=document.documentElement.clientHeight<1024}}};var Te=function(){var e=this,i=e._self._c;return e.file?i("NcAppSidebar",e._b({ref:"sidebar",attrs:{"data-cy-sidebar":"","force-menu":!0},on:e._d({close:e.close,"update:active":e.setActiveTab,opening:e.handleOpening,opened:e.handleOpened,closing:e.handleClosing,closed:e.handleClosed},[e.defaultActionListener,function(s){return s.stopPropagation(),s.preventDefault(),e.onDefaultAction.apply(null,arguments)}]),scopedSlots:e._u([e.fileInfo?{key:"subname",fn:function(){return[e.fileInfo.isFavourited?i("NcIconSvgWrapper",{attrs:{path:e.mdiStar,name:e.t("files","Favorite"),inline:""}}):e._e(),e._v(" "+e._s(e.size)+" "),i("NcDateTime",{attrs:{timestamp:e.fileInfo.mtime}})]},proxy:!0}:null,e.fileInfo?{key:"description",fn:function(){return[i("div",{staticClass:"sidebar__description"},[e.isSystemTagsEnabled&&e.showTagsDefault?i("SystemTags",{directives:[{name:"show",rawName:"v-show",value:e.showTags,expression:"showTags"}],attrs:{"file-id":e.fileInfo.id},on:{"has-tags":s=>e.showTags=s}}):e._e(),e._l(e.views,function(s){return i("LegacyView",{key:s.cid,attrs:{component:s,"file-info":e.fileInfo}})})],2)]},proxy:!0}:null,e.fileInfo?{key:"secondary-actions",fn:function(){return[i("NcActionButton",{attrs:{"close-after-click":!0},on:{click:function(s){return e.toggleStarred(!e.fileInfo.isFavourited)}},scopedSlots:e._u([{key:"icon",fn:function(){return[i("NcIconSvgWrapper",{attrs:{path:e.fileInfo.isFavourited?e.mdiStarOutline:e.mdiStar}})]},proxy:!0}],null,!1,3772937801)},[e._v(" "+e._s(e.fileInfo.isFavourited?e.t("files","Remove from favorites"):e.t("files","Add to favorites"))+" ")]),e.isSystemTagsEnabled?i("NcActionButton",{attrs:{"close-after-click":!0,icon:"icon-tag"},on:{click:e.toggleTags}},[e._v(" "+e._s(e.t("files","Tags"))+" ")]):e._e()]},proxy:!0}:null],null,!0)},"NcAppSidebar",e.appSidebar,!1),[e.error?i("NcEmptyContent",{attrs:{icon:"icon-error"}},[e._v(" "+e._s(e.error)+" ")]):e.fileInfo?e._l(e.tabs,function(s){return[s.enabled(e.fileInfo)?i("SidebarTab",{directives:[{name:"show",rawName:"v-show",value:!e.loading,expression:"!loading"}],key:s.id,attrs:{id:s.id,name:s.name,icon:s.icon,"on-mount":s.mount,"on-update":s.update,"on-destroy":s.destroy,"on-scroll-bottom-reached":s.scrollBottomReached,"file-info":e.fileInfo},scopedSlots:e._u([s.iconSvg!==void 0?{key:"icon",fn:function(){return[i("NcIconSvgWrapper",{attrs:{svg:s.iconSvg,size:20}})]},proxy:!0}:null],null,!0)}):e._e()]}):e._e()],2):e._e()},Ie=[],_e=p(Se,Te,Ie,!1,null,"b4811109");const Ae=_e.exports;class Fe{constructor(){r(this,"_state");this._state={},this._state.tabs=[],this._state.views=[],this._state.file="",this._state.activeTab="",console.debug("OCA.Files.Sidebar initialized")}get state(){return this._state}registerTab(i){return this._state.tabs.findIndex(s=>s.id===i.id)>-1?(console.error("An tab with the same id ".concat(i.id," already exists"),i),!1):(this._state.tabs.push(i),!0)}registerSecondaryView(i){return this._state.views.findIndex(s=>s.id===i.id)>-1?(console.error("A similar view already exists",i),!1):(this._state.views.push(i),!0)}get file(){return this._state.file}setActiveTab(i){this._state.activeTab=i}}class Oe{constructor({id:i,name:s,icon:a,iconSvg:o,mount:n,setIsActive:l,update:b,destroy:w,enabled:f,scrollBottomReached:u}={}){r(this,"_id");r(this,"_name");r(this,"_icon");r(this,"_iconSvgSanitized");r(this,"_mount");r(this,"_setIsActive");r(this,"_update");r(this,"_destroy");r(this,"_enabled");r(this,"_scrollBottomReached");if(f===void 0&&(f=()=>!0),u===void 0&&(u=()=>{}),typeof i!="string"||i.trim()==="")throw new Error("The id argument is not a valid string");if(typeof s!="string"||s.trim()==="")throw new Error("The name argument is not a valid string");if((typeof a!="string"||a.trim()==="")&&typeof o!="string")throw new Error("Missing valid string for icon or iconSvg argument");if(typeof n!="function")throw new Error("The mount argument should be a function");if(l!==void 0&&typeof l!="function")throw new Error("The setIsActive argument should be a function");if(typeof b!="function")throw new Error("The update argument should be a function");if(typeof w!="function")throw new Error("The destroy argument should be a function");if(typeof f!="function")throw new Error("The enabled argument should be a function");if(typeof u!="function")throw new Error("The scrollBottomReached argument should be a function");this._id=i,this._name=s,this._icon=a,this._mount=n,this._setIsActive=l,this._update=b,this._destroy=w,this._enabled=f,this._scrollBottomReached=u,typeof o=="string"&&(this._iconSvgSanitized=B.sanitize(o))}get id(){return this._id}get name(){return this._name}get icon(){return this._icon}get iconSvg(){return this._iconSvgSanitized}get mount(){return this._mount}get setIsActive(){return this._setIsActive||(()=>{})}get update(){return this._update}get destroy(){return this._destroy}get enabled(){return this._enabled}get scrollBottomReached(){return this._scrollBottomReached}}g.prototype.t=d,window.OCA.Files||(window.OCA.Files={}),Object.assign(window.OCA.Files,{Sidebar:new Fe}),Object.assign(window.OCA.Files.Sidebar,{Tab:Oe}),window.addEventListener("DOMContentLoaded",function(){const e=document.querySelector("body > .content")||document.querySelector("body > #content");if(e&&!document.getElementById("app-sidebar")){const a=document.createElement("div");a.id="app-sidebar",e.appendChild(a)}const i=g.extend(Ae),s=new i({name:"SidebarRoot"});s.$mount("#app-sidebar"),window.OCA.Files.Sidebar.open=s.open,window.OCA.Files.Sidebar.close=s.close,window.OCA.Files.Sidebar.setFullScreenMode=s.setFullScreenMode,window.OCA.Files.Sidebar.setShowTagsDefault=s.setShowTagsDefault});
|