Files
productalert/public/build/assets/PostEditor-a50a8942.js
2023-07-30 02:29:23 +08:00

2 lines
9.5 KiB
JavaScript

import x from"./VueEditorJs-a618215f.js";import{r as h,_ as P}from"./NativeImageBlock-49da3dd3.js";import{L as b}from"./bundle-60a987a2.js";import{H as S}from"./bundle-7f656357.js";import{d as V,a as p,_ as A,m as D,b as E,c as r,e as o,w as d,v as y,t as u,f as C,g as M,F as f,r as m,n as I,h as T,i as j,o as c,j as L,k}from"./admin-app-9fc1473b.js";import"./index-8746c87e.js";const w=V("postStore",{state:()=>({data:{defaultLocaleSlug:"my",countryLocales:[],localeCategories:[],authors:[]}}),getters:{defaultLocaleSlug(t){return t.data.defaultLocaleSlug},countryLocales(t){return t.data.countryLocales},localeCategories(t){return t.data.localeCategories},authors(t){return t.data.authors}},actions:{async fetchAuthors(){try{const t=await p.get(h("api.admin.authors"));console.log(t),this.data.authors=t.data.authors}catch(t){console.log(t)}},async fetchCountryLocales(){try{const t=await p.get(h("api.admin.country-locales"));console.log(t),this.data.countryLocales=t.data.country_locales,this.data.defaultLocaleSlug=t.data.default_locale_slug}catch(t){console.log(t)}},async fetchLocaleCategories(t){try{const e=await p.get(h("api.admin.categories",{country_locale_slug:t}));console.log(e),this.data.localeCategories=e.data.categories}catch(e){console.log(e)}}}}),z={components:{VueEditorJs:x,List:b,Header:S},props:{postId:{type:Number,default:null}},data(){return{isSaving:!1,showEditorJs:!1,post:{id:null,title:"",slug:"",excerpt:"",author_id:null,featured:!1,publish_date:null,featured_image:null,body:{time:1591362820044,blocks:[],version:"2.25.0"},locale_slug:null,locale_id:null,status:"draft",categories:null},status:["publish","future","draft","private","trash"],config:{placeholder:"Write something (ノ◕ヮ◕)ノ*:・゚✧",tools:{header:{class:S,config:{placeholder:"Enter a header",levels:[2,3,4],defaultLevel:3}},list:{class:b,inlineToolbar:!0}},onReady:()=>{},onChange:t=>{},data:{time:1591362820044,blocks:[],version:"2.25.0"}}}},watch:{"post.title":{deep:!0,handler(t,e){this.post.slug=this.slugify(t)}}},computed:{...D(w,["countryLocales","localeCategories","defaultLocaleSlug","authors"]),getPostFullUrl(){var t;return((t=this.post.slug)==null?void 0:t.length)>0?"https://productalert.co/"+this.post.locale_slug+"/posts/"+this.post.slug:"https://productalert.co/"+this.post.locale_slug+"/posts/enter-a-post-title-to-autogen-slug"}},methods:{...E(w,["fetchCountryLocales","fetchLocaleCategories","fetchAuthors"]),checkAndSave(){var e,i,a,s,n,g,_;let t=[];((e=this.post.title)==null?void 0:e.length)>0||t.push("post title"),((i=this.post.publish_date)==null?void 0:i.length)>0||t.push("publish date"),((a=this.post.slug)==null?void 0:a.length)>0||t.push("post slug"),((s=this.post.excerpt)==null?void 0:s.length)>0||t.push("post excerpt"),((n=this.post.featured_image)==null?void 0:n.length)>0||t.push("post featured image"),((g=this.post.body.blocks)==null?void 0:g.length)>0||t.push("Post body"),(!(((_=this.post.locale_slug)==null?void 0:_.length)>0)||this.post.locale_id==null)&&t.push("Country locality"),this.post.categories==null&&t.push("Category"),t.length>0?alert("HAIYA many errors! pls fix "+t.join(", ")):this.savePost()},savePost(){this.isSaving=!0;const t=new FormData;for(const[e,i]of Object.entries(this.post))e=="body"?t.append(e,JSON.stringify(i)):t.append(e,i);p.post(h("api.admin.post.upsert"),t,{headers:{"Content-Type":"application/json"}}).then(e=>{console.warn(e)}),setTimeout((function(){this.isSaving=!1}).bind(this),1e3)},onInitialized(t){},imageSaved(t){this.post.featured_image=t},editorSaved(t){this.post.body=t},statusChanged(t){this.post.status=t.target.value},localeChanged(t){this.post.locale_slug=t.target.value,this.post.locale_id=this.getLocaleIdBySlug(t.target.value),this.post.categories=[],setTimeout((function(){this.fetchLocaleCategories(this.post.locale_slug)}).bind(this),100)},setDefaultLocale(){(this.post.locale_slug==null||this.post.locale_slug=="")&&(this.post.locale_slug=this.defaultLocaleSlug,this.post.locale_id=this.getLocaleIdBySlug(this.defaultLocaleSlug))},getLocaleIdBySlug(t){for(const[e,i]of Object.entries(this.countryLocales))if(i.slug==t)return i.id;return null},async fetchPostData(t){var i;const e=await p.get(h("api.admin.post.get",{id:t}));if(((i=e==null?void 0:e.data)==null?void 0:i.post)!=null){let a=this.post,s=e.data.post;a.id=s.id,a.title=s.title,a.slug=s.slug,a.publish_date=s.publish_date,a.excerpt=s.excerpt,a.author_id=s.author_id,a.featured=s.featured,a.featured_image=s.featured_image,a.body=s.body,a.locale_slug=s.post_category.category.country_locale_slug,a.locale_id=s.post_category.category.country_locale_id,a.status=s.status,a.categories=s.post_category.category.id,this.post=a,this.config.data=s.body}console.log(e.data.post)},slugify:function(t){var e="",i=t.toLowerCase();return e=i.replace(/[^a-z0-9\s]/g,""),e=e.replace(/\s+/g," "),e=e.trim(),e=e.replace(/\s+/g,"-"),e}},mounted(){this.fetchCountryLocales().then(()=>{this.setDefaultLocale(),setTimeout((function(){this.fetchLocaleCategories(this.post.locale_slug),this.fetchAuthors(),this.postId!=null?this.fetchPostData(this.postId).then(()=>{setTimeout((function(){this.showEditorJs=!0}).bind(this),1e3)}):setTimeout((function(){this.showEditorJs=!0}).bind(this),1e3)}).bind(this),100)})}},B={class:"row justify-content-center"},U={class:"col-9",style:{"max-width":"700px"}},N={class:"mb-3"},F={class:"form-floating"},J=o("label",null,"Write a SEO post title",-1),O={class:"text-secondary"},H={class:"form-floating mb-3"},W=o("label",null,"Write a simple excerpt to convince & entice users to view this post!",-1),R={key:0,class:"card"},Y={class:"card-body"},q={class:"col-3"},G={class:"d-grid mb-2"},K=["selected","value"],Q=o("div",{class:"fw-bold"},"Publish Date",-1),X={class:"input-icon mb-2"},Z=j('<span class="input-icon-addon"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M4 7a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12z"></path><path d="M16 3v4"></path><path d="M8 3v4"></path><path d="M4 11h16"></path><path d="M11 15h1"></path><path d="M12 15v3"></path></svg></span>',1),$=["disabled"],tt=o("span",{class:"visually-hidden"},"Saving...",-1),et=[tt],st={key:1},ot={class:"card mb-2"},lt=o("div",{class:"card-header fw-bold"},"Country Locality",-1),at={class:"card-body"},it=["value","selected"],nt={class:"card mb-2"},rt=o("div",{class:"card-header fw-bold"},"Categories",-1),ct={class:"card-body"},dt=["id","value"],ut={class:"card mb-2"},ht=o("div",{class:"card-header fw-bold"},"Authors",-1),pt={class:"card-body"},gt=["id","value"],_t={class:"card mb-2"},ft=o("div",{class:"card-header fw-bold"},"Other Settings",-1),mt={class:"card-body"},vt={class:"form-check form-switch"},yt=o("label",{class:"form-check-label"},"Feature this Post",-1);function bt(t,e,i,a,s,n){const g=P,_=x;return c(),r("div",null,[o("div",B,[o("div",U,[o("div",N,[o("div",F,[d(o("input",{"onUpdate:modelValue":e[0]||(e[0]=l=>s.post.title=l),type:"text",class:"form-control",placeholder:"Post title"},null,512),[[y,s.post.title]]),J]),o("small",null,[o("span",O,u(n.getPostFullUrl),1)])]),o("div",H,[d(o("textarea",{"onUpdate:modelValue":e[1]||(e[1]=l=>s.post.excerpt=l),class:"form-control",style:{"min-height":"150px"},placeholder:"Enter a post excerpt/summary"},null,512),[[y,s.post.excerpt]]),W]),C(g,{ref:"imageBlock",class:"mb-3","input-image":s.post.featured_image,onSaved:n.imageSaved},null,8,["input-image","onSaved"]),s.showEditorJs?(c(),r("div",R,[o("div",Y,[C(_,{onSaved:n.editorSaved,config:s.config,initialized:n.onInitialized},null,8,["onSaved","config","initialized"])])])):M("",!0)]),o("div",q,[o("div",G,[o("select",{class:"form-select mb-2","aria-label":"Default select example",onChange:e[2]||(e[2]=(...l)=>n.statusChanged&&n.statusChanged(...l))},[(c(!0),r(f,null,m(s.status,l=>(c(),r("option",{key:l,selected:l==s.post.status,value:l}," Post Status: "+u(l),9,K))),128))],32),Q,o("div",X,[Z,d(o("input",{type:"date","onUpdate:modelValue":e[3]||(e[3]=l=>s.post.publish_date=l),class:"form-control",placeholder:"Select a date",id:"datepicker-icon-prepend"},null,512),[[y,s.post.publish_date]])]),o("button",{onClick:e[4]||(e[4]=(...l)=>n.checkAndSave&&n.checkAndSave(...l)),class:"btn btn-primary",style:{height:"50px"}},[s.isSaving?(c(),r("div",{key:0,class:I(["spinner-border",s.isSaving?"disabled":""]),role:"status",disabled:s.isSaving},et,10,$)):(c(),r("span",st,"Save as "+u(s.post.status),1))])]),o("div",ot,[lt,o("div",at,[o("select",{class:"form-select",onChange:e[5]||(e[5]=(...l)=>n.localeChanged&&n.localeChanged(...l))},[(c(!0),r(f,null,m(t.countryLocales,l=>(c(),r("option",{key:l.id,value:l.slug,selected:l.slug==s.post.locale_slug},u(l.name),9,it))),128))],32)])]),o("div",nt,[rt,o("div",ct,[(c(!0),r(f,null,m(t.localeCategories,l=>(c(),r("div",{class:"py-1",key:l.id},[o("label",null,[d(o("input",{type:"radio",id:l.id,value:l.id,"onUpdate:modelValue":e[6]||(e[6]=v=>s.post.categories=v)},null,8,dt),[[L,s.post.categories]]),k(" "+u(l.name),1)])]))),128))])]),o("div",ut,[ht,o("div",pt,[(c(!0),r(f,null,m(t.authors,l=>(c(),r("div",{class:"py-1",key:l.id},[o("label",null,[d(o("input",{type:"radio",id:l.id,value:l.id,"onUpdate:modelValue":e[7]||(e[7]=v=>s.post.author_id=v)},null,8,gt),[[L,s.post.author_id]]),k(" "+u(l.name),1)])]))),128))])]),o("div",_t,[ft,o("div",mt,[o("div",vt,[d(o("input",{"onUpdate:modelValue":e[8]||(e[8]=l=>s.post.featured=l),class:"form-check-input",type:"checkbox",role:"switch"},null,512),[[T,s.post.featured]]),yt])])])])])])}const Pt=A(z,[["render",bt]]);export{Pt as default};