UNPKG

@nextcloud/vue

Version:
2 lines (1 loc) 3.13 kB
var I=require("../assets/index19.css");const o=require("@nextcloud/axios"),a=require("@nextcloud/router"),l=require("./NcButton.cjs"),t=require("../chunks/l10n-46d0c1c0.cjs"),i=require("../chunks/_plugin-vue2_normalizer-764a4c12.cjs");const n={name:"NcResource",components:{NcButton:l},props:{icon:{type:String,required:!0},name:{type:String,required:!0},url:{type:String,required:!0}},data(){return{labelTranslated:t.t('Open link to "{resourceName}"',{resourceName:this.name})}},methods:{t:t.t}};var u=function(){var e=this,r=e._self._c;return r("li",{staticClass:"resource"},[r("NcButton",{staticClass:"resource__button",attrs:{"aria-label":e.labelTranslated,type:"tertiary",href:e.url},scopedSlots:e._u([{key:"icon",fn:function(){return[r("div",{staticClass:"resource__icon"},[r("img",{attrs:{src:e.icon}})])]},proxy:!0}])},[e._v(" "+e._s(e.name)+" ")])],1)},c=[],d=i.normalizeComponent(n,u,c,!1,null,"1a960bef",null,null);const h=d.exports;const p={name:"NcRelatedResourcesPanel",components:{NcResource:h},props:{providerId:{type:String,default:null},itemId:{type:[String,Number],default:null},fileInfo:{type:Object,default:null}},emits:["has-error","has-resources"],data(){var e;return{appEnabled:((e=OC==null?void 0:OC.appswebroots)==null?void 0:e.related_resources)!==void 0,headerTranslated:t.t("Related resources"),loading:!1,error:null,resources:[]}},computed:{isVisible(){var e;return this.loading?!1:(e=this.error)!=null?e:this.resources.length>0},description(){return this.error?t.t("Error getting related resources. Please contact your system administrator if you have any questions."):t.t("Anything shared with the same group of people will show up here")},hasResourceInfo(){return this.providerId!==null&&this.itemId!==null||this.fileInfo!==null},isFiles(){var e;return((e=this.fileInfo)==null?void 0:e.id)!==void 0},url(){let e=null,r=null;return this.isFiles?(e="files",r=this.fileInfo.id):(e=this.providerId,r=this.itemId),a.generateOcsUrl("/apps/related_resources/related/{providerId}?itemId={itemId}&format=json",{providerId:e,itemId:r})}},watch:{providerId(){this.fetchRelatedResources()},itemId(){this.fetchRelatedResources()},fileInfo(){this.fetchRelatedResources()},error(e){this.$emit("has-error",!!e)},resources(e){this.$emit("has-resources",e.length>0)}},created(){this.fetchRelatedResources()},methods:{t:t.t,async fetchRelatedResources(){var e;if(!(!this.appEnabled||!this.hasResourceInfo)){this.loading=!0,this.error=null,this.resources=[];try{const r=await o.get(this.url);this.resources=(e=r.data.ocs)==null?void 0:e.data}catch(r){this.error=r,console.error(r)}finally{this.loading=!1}}}}};var f=function(){var e=this,r=e._self._c;return e.appEnabled&&e.isVisible?r("div",{staticClass:"related-resources"},[r("div",{staticClass:"related-resources__header"},[r("h5",[e._v(e._s(e.headerTranslated))]),r("p",[e._v(e._s(e.description))])]),e._l(e.resources,function(s){return r("NcResource",{key:s.itemId,staticClass:"related-resources__entry",attrs:{icon:s.icon,name:s.title,url:s.url}})})],2):e._e()},m=[],_=i.normalizeComponent(p,f,m,!1,null,"235fc8aa",null,null);const y=_.exports;module.exports=y;