-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
1 lines (1 loc) · 17 KB
/
index.js
1
(function(){"use strict";function o(n,e,t,a,s,i,l,c){var r=typeof n=="function"?n.options:n;return e&&(r.render=e,r.staticRenderFns=t,r._compiled=!0),{exports:n,options:r}}const d={props:{queuedKomments:Object,affectedPages:Array,webmentions:Boolean,showMigration:Boolean,storageType:String}};var p=function(){var e=this,t=e._self._c;return t("k-panel-inside",[t("div",{staticClass:"k-komments-view"},[e.showMigration?t("div",[t("k-headline",{attrs:{tag:"h2"}},[e._v("Converter")]),t("Converter",{attrs:{storageType:this.storageType}})],1):t("div",[t("k-headline",{attrs:{tag:"h2"}},[e._v("Comments")]),t("CommentsTable",{attrs:{comments:this.queuedKomments,affectedPages:this.affectedPages,webmentions:this.webmentions,storageType:this.storageType}})],1)])])},u=[],h=o(d,p,u);const v=h.exports,g={mixins:["drawer"],props:{comment:{type:Object,default:{}}}};var b=function(){var e=this,t=e._self._c;return t("k-drawer",e._b({},"k-drawer",e.$props,!1),[t("CommentContent",{attrs:{spamlevel:e.comment.spamlevel,content:e.comment.content}}),t("div",{staticClass:"k-table"},[t("table",{staticStyle:{"table-layout":"auto"}},[t("tbody",[t("tr",[t("th",{attrs:{"data-mobile":"true"}},[e._v("Id")]),t("td",{attrs:{"data-mobile":"true"}},[e._v(e._s(e.comment.id))])]),t("tr",[t("th",{attrs:{"data-mobile":"true"}},[e._v("Type")]),t("td",{attrs:{"data-mobile":"true"}},[e._v(e._s(e.comment.type))])]),t("tr",[t("th",{attrs:{"data-mobile":"true"}},[e._v("Language")]),t("td",{attrs:{"data-mobile":"true"}},[e._v(e._s(e.comment.language))])]),t("tr",[t("th",{attrs:{"data-mobile":"true"}},[e._v("Published")]),t("td",{attrs:{"data-mobile":"true"}},[e._v(e._s(e.comment.published))])]),t("tr",[t("th",{attrs:{"data-mobile":"true"}},[e._v("Verified")]),t("td",{attrs:{"data-mobile":"true"}},[e._v(e._s(e.comment.verified))])]),t("tr",[t("th",{attrs:{"data-mobile":"true"}},[e._v("Reply To")]),t("td",{attrs:{"data-mobile":"true"}},[e._v(e._s(e.comment.parentid))])]),t("tr",[t("th",{attrs:{"data-mobile":"true"}},[e._v("Spam level")]),t("td",{attrs:{"data-mobile":"true"}},[e._v(e._s(e.comment.spamlevel))])]),t("tr",[t("th",{attrs:{"data-mobile":"true"}},[e._v("Upvotes")]),t("td",{attrs:{"data-mobile":"true"}},[e._v(e._s(e.comment.upvotes))])]),t("tr",[t("th",{attrs:{"data-mobile":"true"}},[e._v("Downvotes")]),t("td",{attrs:{"data-mobile":"true"}},[e._v(e._s(e.comment.downvotes))])]),t("tr",[t("th",{attrs:{"data-mobile":"true"}},[e._v("Created at")]),t("td",{attrs:{"data-mobile":"true"}},[e._v(e._s(e.comment.createdat))])]),t("tr",[t("th",{attrs:{"data-mobile":"true"}},[e._v("Updated at")]),t("td",{attrs:{"data-mobile":"true"}},[e._v(e._s(e.comment.updatedat))])]),t("tr",[t("th",{attrs:{"data-mobile":"true"}},[e._v("Permalink")]),t("td",{attrs:{"data-mobile":"true"}},[e._v(e._s(e.comment.permalink))])]),t("tr",[t("th",{attrs:{"data-mobile":"true"}},[e._v("Author")]),t("td",{attrs:{"data-mobile":"true"}},[e._v(e._s(e.comment.authorname))])]),t("tr",[t("th",{attrs:{"data-mobile":"true"}},[e._v("Avatar")]),t("td",{attrs:{"data-mobile":"true"}},[e._v(e._s(e.comment.authoravatar))])]),t("tr",[t("th",{attrs:{"data-mobile":"true"}},[e._v("Email")]),t("td",{attrs:{"data-mobile":"true"}},[e._v(e._s(e.comment.authoremail))])]),t("tr",[t("th",{attrs:{"data-mobile":"true"}},[e._v("Url")]),t("td",{attrs:{"data-mobile":"true"}},[e._v(e._s(e.comment.authorurl))])])])])])],1)},_=[],f=o(g,b,_);const y=f.exports,k={mixins:["drawer"],props:{comment:{type:Object,default:{}}},data(){return{originPublished:this.comment.published,replyCreated:null,isSending:!1}},methods:{sendReply(){this.isSending=!0,panel.api.post(`komments/reply/${this.comment.id}`,{content:this.content,pageUuid:this.comment.pageuuid,language:this.comment.language}).then(n=>{this.originPublished=n.published,this.replyCreated=n.created,this.isSending=!1}).catch(()=>{this.replyCreated=!1,this.isSending=!1})}}};var C=function(){var e=this,t=e._self._c;return t("k-drawer",e._b({},"k-drawer",e.$props,!1),[this.originPublished?e._e():t("k-box",{key:"unpublished",staticStyle:{"margin-bottom":"var(--spacing-6)"},attrs:{theme:"notice",text:"This comment is not published yet. When you reply, it will be published along with your reply."}}),this.replyCreated?t("k-box",{key:"created",staticStyle:{"margin-bottom":"var(--spacing-6)"},attrs:{theme:"positive",text:"Your reply has been published."}}):this.replyCreated===!1?t("k-box",{key:"not-created",staticStyle:{"margin-bottom":"var(--spacing-6)"},attrs:{theme:"negative",text:"Your reply could not be published. Please try again."}}):e._e(),t("CommentContent",{attrs:{spamlevel:e.comment.spamlevel,content:e.comment.content}}),t("k-textarea-field",{staticStyle:{"margin-bottom":"var(--spacing-1)"},attrs:{autofocus:!0,label:`Reply to ${e.comment.authorname}`,value:e.content},on:{input:function(a){e.content=a}}}),t("k-button",{key:"green",attrs:{theme:"green",variant:"filled",icon:e.isSending?e.loader:null,disabled:e.isSending},on:{click:this.sendReply}},[e._v(" Send reply ")])],1)},w=[],x=o(k,C,w);const S=x.exports,$={props:{icon:String,color:String}};var T=function(){var e=this,t=e._self._c;return t("svg",{staticClass:"k-icon",style:`color: var(${this.color})`,attrs:{"aria-hidden":"true","data-type":this.icon}},[t("use",{attrs:{"xlink:href":`#icon-${this.icon}`}})])},P=[],L=o($,T,P);const V=L.exports,R={props:{spamlevel:Number,content:String}};var I=function(){var e=this,t=e._self._c;return t("div",[e.spamlevel>0?t("k-box",{key:"spam",staticStyle:{"margin-bottom":"var(--spacing-6)"},attrs:{theme:"warning",text:"This comment is marked as spam. Its content is shown as plain text to prevent accidental exposure to harmful content."}}):e._e(),t("k-box",{staticStyle:{"margin-bottom":"var(--spacing-6)"},attrs:{theme:"text"}},[e.spamlevel===0?t("k-text",{domProps:{innerHTML:e._s(e.content)}}):t("k-text",[e._v(e._s(e.content))])],1)],1)},U=[],M=o(R,I,U);const D=M.exports,A={props:{comments:Object,affectedPages:Array,columns:Array,webmentions:Boolean,storageType:String},data(){return{pagination:{page:1,limit:20,total:0}}},computed:{index(){return(this.pagination.page-1)*this.pagination.limit+1},visibleColumns(){const n=["author","content","pageTitle","updatedAt","spamlevel","verified","published","type"],t=(this.columns||n).filter(s=>n.includes(s)),a={author:{label:"Author",type:"html"},content:{label:"Comment",type:"text"},pageTitle:{label:"Page",type:"html"},updatedAt:{label:"Last Update",type:"html"},spamlevel:{label:"Spamlevel",type:"html",width:"40px",align:"center"},verified:{label:"Verified",type:"html",width:"40px",align:"center"},published:{label:"Published",type:"html",width:"40px",align:"center"},type:{label:"Type",type:"html",width:"40px",align:"center"}};return Object.fromEntries(t.map(s=>[s,a[s]]))},commentList(){const n={comment:"chat","in-reply-to":"megaphone","repost-of":"indie-repost","mention-of":"indie-mention","like-of":"heart","bookmark-of":"bookmark",rsvp:"calendar",invite:"calendar"},e={"in-reply-to":"Webmention reply","repost-of":"Webmention repost","mention-of":"Webmention mention","like-of":"Webmention like","bookmark-of":"Webmention bookmark",rsvp:"Webmention RSVP",invite:"Webmention invite"},t=[];return this.pagination.total=0,(this.webmentions?this.comments:this.comments.filter(s=>s.type==="comment")).forEach(s=>{const i=this.affectedPages.find(E=>E.uuid===s.pageuuid),l=s.content?s.content.replace(/<[^>]*>/g,""):`(${e[s.type]})`,c=this.$library.dayjs.pattern("YYYY-MM-DD HH:mm").format(this.$library.dayjs(s.updatedat)),r={id:s.id,pageTitle:`<a href="${i.panel}">${i.title}</a>`,author:`<span class="author-entry"><img src="${s.authoravatar}" width="30px" height="30px" />${s.authorname}</span>`,content:l,updatedAt:c,type:this.tableIcon(n[s.type],"--color-blue-700",s.type),spamlevel:s.spamlevel>0?this.tableIcon("flag","--color-red-700"):"",verified:s.verified?this.tableIcon("sparkling","--color-yellow-700"):"",published:s.published?this.tableIcon("preview","--color-green-700"):this.tableIcon("hidden","--color-red-700")};t.push(r),this.pagination.total++}),t.slice(this.index-1,this.pagination.limit*this.pagination.page)},hasSpamComments(){return this.comments.some(n=>n.spamlevel>0)},hasPendingComments(){return this.comments.some(n=>n.published===!1)}},methods:{showCommentDetails(n){const e=this.comments.find(t=>t.id===n);panel.drawer.open({component:"komments-detail-drawer",props:{icon:"info",title:"Comment",comment:e}})},replyToComment(n){const e=this.comments.find(t=>t.id===n);panel.drawer.open({component:"komments-reply-drawer",props:{icon:"chat",title:"Reply to comment",comment:e}})},publishComment(n){panel.api.post(`komments/publish/${n}`).then(e=>{this.comments.find(t=>t.id===n).published=e.published})},publishPendingComments(){panel.dialog.open("comments/publish/pending")},deleteComment(n){panel.dialog.open(`comment/delete/${n}`)},deleteSpamComments(){panel.dialog.open("comments/delete/spam")},deletePendingComments(){panel.dialog.open("comments/delete/pending")},flagComment(n,e){panel.api.post(`komments/flag/${n}/${e}`).then(t=>{this.comments.find(a=>a.id===n)[e]=t[e]})},dropdownOptions(n){const e=this.comments.find(t=>t.id===n.id);return[{label:e.published?"Unpublish":"Publish",icon:e.published?"toggle-on":"toggle-off",click:()=>this.publishComment(n.id)},{label:"Reply to",icon:"chat",click:()=>this.replyToComment(n.id)},"-",{label:e.verified?"Mark as unverified":"Mark as verified",icon:e.verified?"cancel-small":"sparkling",disabled:e.spamlevel>0,click:()=>this.flagComment(n.id,"verified")},{label:e.spamlevel>0?"Remove from spam":"Mark as spam"+n.spamlevel,icon:e.spamlevel>0?"cancel-small":"flag",click:()=>this.flagComment(n.id,"spamlevel")},{label:"View Details",icon:"info",click:()=>this.showCommentDetails(n.id)},"-",{label:"Delete",icon:"trash",click:()=>this.deleteComment(n.id)}]},tableIcon(n,e,t=""){return`<span title="${t}"><svg aria-hidden="true" data-type="${n}" class="k-icon" style="color: var(${e});"><use xlink:href="#icon-${n}"></use></svg></span>`}}};var H=function(){var e=this,t=e._self._c;return t("div",{staticClass:"k-komments-view"},[this.storageType!=="markdown"?t("k-button-group",{staticStyle:{"margin-bottom":"var(--spacing-6)"},attrs:{layout:"collapsed"}},[t("k-button",{attrs:{variant:"filled",icon:"toggle-off",theme:"green-icon",disabled:!this.hasPendingComments,click:this.publishPendingComments}},[e._v(" Publish all ")]),t("k-button",{attrs:{variant:"filled",icon:"flag",theme:"orange-icon",disabled:!this.hasSpamComments,click:this.deleteSpamComments}},[e._v(" Delete spam ")]),t("k-button",{attrs:{variant:"filled",icon:"trash",theme:"red-icon",disabled:!this.hasPendingComments,click:this.deletePendingComments}},[e._v(" Delete all pending ")])],1):e._e(),t("k-table",{attrs:{columns:this.visibleColumns,index:!0,rows:this.commentList,empty:"No comments found",pagination:{page:e.pagination.page,limit:e.pagination.limit,total:e.pagination.total,details:!0}},on:{paginate:function(a){e.pagination.page=a.page}},scopedSlots:e._u([{key:"header",fn:function({columnIndex:a,label:s}){return[t("span",{attrs:{title:s}},[a==="verified"?t("k-icon",{staticStyle:{color:"var(--color-yellow-700)"},attrs:{type:"sparkling"}}):a==="spamlevel"?t("k-icon",{staticStyle:{color:"var(--color-red-700)"},attrs:{type:"flag"}}):a==="published"?t("k-icon",{staticStyle:{color:"var(--color-green-700)"},attrs:{type:"preview"}}):a==="type"?t("k-icon",{staticStyle:{color:"var(--color-blue-700)"},attrs:{type:"box"}}):t("span",[e._v(e._s(s))])],1)]}},{key:"options",fn:function({row:a}){return[t("k-options-dropdown",{attrs:{options:e.dropdownOptions(a)}})]}}])})],1)},O=[],q=o(A,H,O);const m=q.exports,F={props:{storageType:String},data(){return{status:"idle",comments:[],queue:[],processIndex:0,processRunning:!1,progressValue:0}},computed:{conversionList(){return this.comments.map(n=>({conversionStatus:`<span class="status ${n.conversionStatus}">${n.conversionStatus}</span>`,pageUuid:n.pageUuid,pageTitle:n.pageTitle,comments:n.comments,converted:n.converted,failed:n.failed}))}},methods:{getComments(){this.status="in-progress",panel.api.get("komments/converter/get-comments").then(n=>{const e=[];n.forEach(t=>{const a={...t,queueStatus:"idle"};this.queue.push(a);const s=e.find(l=>l.pageUuid===t.pageUuid);if(s){s.comments++;return}const i={conversionStatus:"idle",pageUuid:t.pageUuid,pageTitle:t.pageTitle,comments:1,converted:0,failed:0};e.push(i)}),this.comments=e,this.processQueue()})},processQueue(){if(this.progressValue=100/this.queue.length*this.processIndex,this.processIndex>=this.queue.length){this.processIndex=0,this.processRunning=!1;return}this.processRunning=!0;const e=this.queue[this.processIndex];this.processIndex+=1;const t=this.comments.find(a=>e.pageUuid===a.pageUuid);t.conversionStatus="running",panel.api.post("komments/converter/convert",e).then(a=>{const s=this.comments.find(i=>e.pageUuid===i.pageUuid);a.status==="success"?s.converted++:s.failed++,t.conversionStatus=s.comments.length===s.converted+s.failed?"success":"done"}).then(()=>{this.processQueue()})},convertComment(n){const e=this.comments.find(t=>t.pageUuid===n.pageUuid);e.conversionStatus="running",panel.api.post("komments/converter/convert",n).then(t=>{const a=this.comments.find(s=>s.pageUuid===n.pageUuid);t.status==="success"?a.converted++:a.failed++})}}};var W=function(){var e=this,t=e._self._c;return t("div",[t("k-grid",{attrs:{variant:"fields"}},[e.status==="in-progress"?t("k-box",{key:"inprogress",staticStyle:{"--width":"1/2","margin-bottom":"var(--spacing-6)",padding:"var(--spacing-6)",display:"block"},attrs:{theme:e.progressValue>=100?"positive":"warning",html:!0}},[e.progressValue<100?t("p",[e._v(" Conversion in progress, please wait. "),t("strong",[e._v("DO NOT CLOSE THIS PAGE.")])]):t("div",[t("p",[t("strong",[e._v("Conversion complete!")])]),t("k-checkboxes-field",{attrs:{name:"checkboxes",label:"Please complete the following steps:",options:[{value:1,text:"Check if all comments are converted"},{value:2,text:"Go to your config.php and disable migration"},{value:3,text:"Adapt your theme to the new comment format"},{value:4,text:"Remove old comments from your page files"}]}})],1),e.progressValue<100?t("k-progress",{staticStyle:{"margin-top":"var(--spacing-6)"},attrs:{value:e.progressValue}}):e._e()],1):e._e(),t("div",{staticStyle:{"--width":"1/2","margin-bottom":"var(--spacing-6)"}},[e.status!=="in-progress"?t("k-box",{key:"info",staticStyle:{padding:"var(--spacing-6)"},attrs:{theme:"info",html:!0,text:"It seems like you used an older version of this plugin. We need to convert old comments to the new format. This will take a while. For data safety reasons, <strong>old comments will not be deleted automatically.</strong> You can delete them manually after the conversion.",icon:"bell"}}):e._e(),this.storageType==="markdown"?t("k-box",{key:"markdown",staticStyle:{padding:"var(--spacing-6)","margin-top":"var(--spacing-6)"},attrs:{theme:"error",html:!0,text:"You set the storage type to Markdown. This means that comments will be stored in the page files. This may lead to issues when receiving a lot of comments at the same time. It is recommended to use a database storage type for better performance. Markdown storage also does not support batch operations. If you can, please consider switching to the sqlite storage type.",icon:"bell"}}):e._e()],1),e.status!=="in-progress"?t("k-box",{staticStyle:{"--width":"1/4"},attrs:{align:"center"}},[t("k-button",{attrs:{variant:"filled",icon:"play",theme:"green",size:"lg",click:this.getComments}},[e._v(" Start conversion ")])],1):e._e()],1),t("k-table",{attrs:{columns:{conversionStatus:{label:"Status",width:"160px",type:"html"},pageTitle:{label:"Page",type:"html"},comments:{label:"Comments",type:"text"},converted:{label:"Converted",type:"text"},failed:{label:"Failed",type:"text"}},index:!0,rows:e.conversionList,empty:"No comments found"}})],1)},j=[],Y=o(F,W,j);const B=Y.exports;panel.plugin("mauricerenck/komments",{components:{"k-komments-view":v,CommentContent:D,CommentsTable:m,Converter:B,TableIcon:V,"komments-detail-drawer":y,"komments-reply-drawer":S},fields:{CommentsTable:m},icons:{"indie-mention":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20C13.6418 20 15.1681 19.5054 16.4381 18.6571L17.5476 20.3214C15.9602 21.3818 14.0523 22 12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12V13.5C22 15.433 20.433 17 18.5 17C17.2958 17 16.2336 16.3918 15.6038 15.4659C14.6942 16.4115 13.4158 17 12 17C9.23858 17 7 14.7614 7 12C7 9.23858 9.23858 7 12 7C13.1258 7 14.1647 7.37209 15.0005 8H17V13.5C17 14.3284 17.6716 15 18.5 15C19.3284 15 20 14.3284 20 13.5V12ZM12 9C10.3431 9 9 10.3431 9 12C9 13.6569 10.3431 15 12 15C13.6569 15 15 13.6569 15 12C15 10.3431 13.6569 9 12 9Z"></path></svg>',"indie-repost":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M6 4H21C21.5523 4 22 4.44772 22 5V12H20V6H6V9L1 5L6 1V4ZM18 20H3C2.44772 20 2 19.5523 2 19V12H4V18H18V15L23 19L18 23V20Z"></path></svg>',"indie-sent":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M4.99989 13.9999L4.99976 5L6.99976 4.99997L6.99986 11.9999L17.1717 12L13.222 8.05024L14.6362 6.63603L21.0001 13L14.6362 19.364L13.222 17.9497L17.1717 14L4.99989 13.9999Z"></path></svg>'}})})();