files_reminders-init.mjs 8.8 KB

12
  1. /*! third party licenses: dist/vendor.LICENSE.txt */
  2. import{F as o,j as L,r as a}from"./chunks/index-DG15V7L3.mjs";import{c4 as _,b$ as S,bR as N,aV as n,F as H,P as Y,R as B,T as R,a7 as V,bS as i,bQ as m}from"./core-common.mjs";import{n as E,az as v,aA as M,aB as W}from"./chunks/icons-TElqpmA8.mjs";import"./chunks/index-PaKKd09k.mjs";import{z as s,B as D}from"./chunks/_plugin-vue2_normalizer-VrK6B12S-BQkexw0P.mjs";import{g as z}from"./chunks/index-CiG5J8j_.mjs";import"./chunks/index-CPb3EwrS.mjs";import"./chunks/index-tn-fAC9x.mjs";var d=(e=>(e.LaterToday="later-today",e.Tomorrow="tomorrow",e.ThisWeekend="this-weekend",e.NextWeek="next-week",e))(d||{});const w=()=>{const e=new Date;return e.setHours(0,0,0,0),e.setDate(e.getDate()-e.getDay()+1),new Date(e)},b=e=>{new Date(e).setHours(0,0,0,0);const t=new Date(e.getFullYear(),0,1,0,0,0,0),r=(e.getTime()-t.getTime())/864e5;return Math.ceil((r+t.getDay()+1)/7)},A=(e,t)=>b(e)===b(t)&&e.getFullYear()===t.getFullYear(),O=(e,t)=>e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getFullYear()===t.getFullYear(),c=e=>({"later-today":()=>{const t=new Date,r=new Date;r.setHours(18,0,0,0);const l=new Date;return l.setHours(17,0,0,0),t>=l?null:r},tomorrow:()=>{const t=new Date,r=new Date;return r.setDate(t.getDate()+1),r.setHours(8,0,0,0),r},"this-weekend":()=>{const t=new Date;if([5,6,0].includes(t.getDay()))return null;const r=new Date,l=w();return r.setDate(l.getDate()+5),r.setHours(8,0,0,0),r},"next-week":()=>{if(new Date().getDay()===0)return null;const t=new Date,r=w();return t.setDate(r.getDate()+7),t.setHours(8,0,0,0),t}})[e](),$=()=>{const e=new Date,t=new Date;return t.setHours(e.getHours()+2,0,0,0),t},g=e=>{let t={hour:"numeric",minute:"2-digit"};const r=new Date;return O(e,r)||(t={...t,weekday:"short"}),A(e,r)||(t={...t,month:"short",day:"numeric"}),e.getFullYear()!==r.getFullYear()&&(t={...t,year:"numeric"}),e.toLocaleString(_(),t)},u=e=>{let t={month:"long",day:"numeric",weekday:"long",hour:"numeric",minute:"2-digit"};const r=new Date;return e.getFullYear()!==r.getFullYear()&&(t={...t,year:"numeric"}),e.toLocaleString(_(),t)},f=z().setApp("files_reminders").detectUser().build(),T=async(e,t)=>{const r=S("/apps/files_reminders/api/v1/{fileId}",{fileId:e});return(await N.put(r,{dueDate:t.toISOString()})).data.ocs.data},k=async e=>{const t=S("/apps/files_reminders/api/v1/{fileId}",{fileId:e});return(await N.delete(t)).data.ocs.data},j=n.extend({name:"SetCustomReminderModal",components:{NcButton:H,NcDateTime:Y,NcDateTimePickerNative:B,NcDialog:R,NcNoteCard:V},data(){return{node:void 0,hasDueDate:!1,opened:!1,isValid:!0,customDueDate:null,nowDate:new Date}},computed:{fileId(){return this.node.fileid},fileName(){return this.node.basename},name(){return i("files_reminders",'Set reminder for "{fileName}"',{fileName:this.fileName})},label(){return i("files_reminders","Set reminder at custom date & time")},clearAriaLabel(){return i("files_reminders","Clear reminder")}},methods:{t:i,getDateString:g,open(e){const t=e.attributes["reminder-due-date"]?new Date(e.attributes["reminder-due-date"]):null;this.node=e,this.hasDueDate=!!t,this.isValid=!0,this.opened=!0,this.customDueDate=t!=null?t:$(),this.nowDate=new Date,setTimeout(()=>{const r=document.getElementById("set-custom-reminder");r.focus(),this.hasDueDate||r.showPicker()},300)},async setCustom(){if(!(this.customDueDate instanceof Date)||isNaN(this.customDueDate)){s(i("files_reminders","Please choose a valid date & time"));return}try{await T(this.fileId,this.customDueDate),n.set(this.node.attributes,"reminder-due-date",this.customDueDate.toISOString()),m("files:node:updated",this.node),D(i("files_reminders",'Reminder set for "{fileName}"',{fileName:this.fileName})),this.onClose()}catch(e){f.error("Failed to set reminder",{error:e}),s(i("files_reminders","Failed to set reminder"))}},async clear(){try{await k(this.fileId),n.set(this.node.attributes,"reminder-due-date",""),m("files:node:updated",this.node),D(i("files_reminders",'Reminder cleared for "{fileName}"',{fileName:this.fileName})),this.onClose()}catch(e){f.error("Failed to clear reminder",{error:e}),s(i("files_reminders","Failed to clear reminder"))}},onClose(){this.opened=!1,this.$emit("close")},onInput(){const e=document.getElementById("set-custom-reminder");this.isValid=e.checkValidity()}}});var q=function(){var e=this,t=e._self._c;return e._self._setupProxy,e.opened?t("NcDialog",{attrs:{name:e.name,"out-transition":!0,size:"small","close-on-click-outside":""},on:{closing:e.onClose},scopedSlots:e._u([{key:"actions",fn:function(){return[t("NcButton",{attrs:{type:"tertiary"},on:{click:e.onClose}},[e._v(" "+e._s(e.t("files_reminders","Cancel"))+" ")]),e.hasDueDate?t("NcButton",{on:{click:e.clear}},[e._v(" "+e._s(e.t("files_reminders","Clear reminder"))+" ")]):e._e(),t("NcButton",{attrs:{disabled:!e.isValid,type:"primary",form:"set-custom-reminder-form","native-type":"submit"}},[e._v(" "+e._s(e.t("files_reminders","Set reminder"))+" ")])]},proxy:!0}],null,!1,3614870414)},[t("form",{staticClass:"custom-reminder-modal",attrs:{id:"set-custom-reminder-form"},on:{submit:function(r){return r.preventDefault(),e.setCustom.apply(null,arguments)}}},[t("NcDateTimePickerNative",{attrs:{id:"set-custom-reminder",label:e.label,min:e.nowDate,required:!0,type:"datetime-local"},on:{input:e.onInput},model:{value:e.customDueDate,callback:function(r){e.customDueDate=r},expression:"customDueDate"}}),e.isValid?t("NcNoteCard",{attrs:{type:"info"}},[e._v(" "+e._s(e.t("files_reminders","We will remind you of this file"))+" "),t("NcDateTime",{attrs:{timestamp:e.customDueDate}})],1):t("NcNoteCard",{attrs:{type:"error"}},[e._v(" "+e._s(e.t("files_reminders","Please choose a valid date & time"))+" ")])],1)]):e._e()},Q=[],U=E(j,q,Q,!1,null,"f215d559");const G=U.exports,J=n.extend(G),h=document.createElement("div");h.id="set-custom-reminder-modal",document.body.appendChild(h);const y=new J({name:"SetCustomReminderModal",el:h}),I=e=>(y.open(e),new Promise(t=>{y.$once("close",t)})),K=new o({id:"reminder-status",inline:()=>!0,displayName:()=>"",title:e=>{const t=e.at(0),r=new Date(t.attributes["reminder-due-date"]);return"".concat(i("files_reminders","Reminder set")," – ").concat(u(r))},iconSvgInline:()=>v,enabled:e=>e.length!==1?!1:!!e.at(0).attributes["reminder-due-date"],async exec(e){return I(e),null},order:-15}),X=new o({id:"clear-reminder",displayName:()=>i("files_reminders","Clear reminder"),title:e=>{const t=e.at(0),r=new Date(t.attributes["reminder-due-date"]);return"".concat(i("files_reminders","Clear reminder")," – ").concat(u(r))},iconSvgInline:()=>M,enabled:e=>e.length!==1?!1:!!e.at(0).attributes["reminder-due-date"],async exec(e){if(e.fileid)try{return await k(e.fileid),n.set(e.attributes,"reminder-due-date",""),m("files:node:updated",e),!0}catch{return!1}return null},order:19}),p="set-reminder-menu",Z=new o({id:p,displayName:()=>i("files_reminders","Set reminder"),iconSvgInline:()=>v,enabled:(e,t)=>t.id!=="trashbin",async exec(){return null},order:20}),x={dateTimePreset:d.LaterToday,label:i("files_reminders","Later today"),ariaLabel:i("files_reminders","Set reminder for later today"),dateString:"",verboseDateString:""},C={dateTimePreset:d.Tomorrow,label:i("files_reminders","Tomorrow"),ariaLabel:i("files_reminders","Set reminder for tomorrow"),dateString:"",verboseDateString:""},F={dateTimePreset:d.ThisWeekend,label:i("files_reminders","This weekend"),ariaLabel:i("files_reminders","Set reminder for this weekend"),dateString:"",verboseDateString:""},P={dateTimePreset:d.NextWeek,label:i("files_reminders","Next week"),ariaLabel:i("files_reminders","Set reminder for next week"),dateString:"",verboseDateString:""},ee=e=>new o({id:"set-reminder-".concat(e.dateTimePreset),displayName:()=>"".concat(e.label," – ").concat(e.dateString),title:()=>"".concat(e.ariaLabel," – ").concat(e.verboseDateString),iconSvgInline:()=>"<svg></svg>",enabled:(t,r)=>r.id==="trashbin"?!1:!!c(e.dateTimePreset),parent:p,async exec(t){if(!t.fileid)return f.error("Failed to set reminder, missing file id"),s(i("files_reminders","Failed to set reminder")),null;try{const r=c(e.dateTimePreset);await T(t.fileid,r),n.set(t.attributes,"reminder-due-date",r.toISOString()),m("files:node:updated",t),D(i("files_reminders",'Reminder set for "{fileName}"',{fileName:t.basename}))}catch(r){f.error("Failed to set reminder",{error:r}),s(i("files_reminders","Failed to set reminder"))}return null},order:21});[x,C,F,P].forEach(e=>{const t=c(e.dateTimePreset);t&&(e.dateString=g(t),e.verboseDateString=u(t),setInterval(()=>{const r=c(e.dateTimePreset);r&&(e.dateString=g(r),e.verboseDateString=u(r))},1e3*30*60))});const te=[x,C,F,P].map(ee),re=new o({id:"set-reminder-custom",displayName:()=>i("files_reminders","Set custom reminder"),title:()=>i("files_reminders","Set reminder at custom date & time"),iconSvgInline:()=>W,enabled:(e,t)=>t.id!=="trashbin",parent:p,async exec(e){return I(e),null},order:22});L("nc:reminder-due-date",{nc:"http://nextcloud.org/ns"}),a(K),a(X),a(Z),a(re),te.forEach(e=>a(e));