-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
15 lines (15 loc) · 18.9 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
(function(){"use strict";/**
* @module deep-freeze
* @description Provides function to deep freeze objects.
* @version 1.1.3
* @author Anatoliy Gatt [[email protected]]
* @copyright Copyright (c) 2015-2016 Anatoliy Gatt
* @license MIT
*/function d(t){if(t){var s,e;t=Object.freeze(t);for(e in t)if(t.hasOwnProperty(e)){if(s=t[e],typeof s!="object"||!(s instanceof Object)||Object.isFrozen(s))continue;d(s)}}return t}var S=function(t){return d(t)};/**
* @module index
* @description Entry point for deep-freeze-node module.
* @version 1.1.3
* @author Anatoliy Gatt [[email protected]]
* @copyright Copyright (c) 2015-2016 Anatoliy Gatt
* @license MIT
*/var u=S;let y={namespaced:!0,state:{historyDate:new Date,export:null,screen:null},mutations:{SET_EXPORT:(t,s)=>{t.export=u(s)},SET_SCREEN(t,s){t.screen==="History"&&(t.historyDate=new Date),t.screen=s,localStorage.memsourceScreen=s}}};var j=function(){var t=this,s=t.$createElement,e=t._self._c||s;return e("k-grid",{attrs:{gutter:"medium"}},[e("k-column",{attrs:{width:"1/2"}},[e("k-radio-field",{attrs:{label:"Site",options:[{value:!0,text:"On"},{value:!1,text:"Off"}],columns:2,help:t.exportSiteHelp},model:{value:t.exportSite,callback:function(o){t.exportSite=o},expression:"exportSite"}})],1),e("k-column",{attrs:{width:"1/2"}},[e("k-radio-field",{attrs:{label:"Files",options:t.filesOptions,columns:t.filesOptions.length,help:t.activeFilesOption.help},on:{input:t.input},model:{value:t.exportFiles,callback:function(o){t.exportFiles=o},expression:"exportFiles"}})],1),e("k-column",[e("k-pages-field",{attrs:{label:"Pages",search:!0,multiple:!0,endpoints:{field:"memsource/picker/pages"}},model:{value:t.exportPages,callback:function(o){t.exportPages=o},expression:"exportPages"}})],1),e("k-column",{attrs:{align:"center"}},[e("k-button-group",[e("k-button",{attrs:{icon:"upload",disabled:!t.isCanExport},on:{click:t.doExport}},[t._v(" Export ")])],1)],1)],1)},w=[];function c(t,s,e,o,r,n,b,mt){var i=typeof t=="function"?t.options:t;s&&(i.render=s,i.staticRenderFns=e,i._compiled=!0),o&&(i.functional=!0),n&&(i._scopeId="data-v-"+n);var l;if(b?(l=function(a){a=a||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!a&&typeof __VUE_SSR_CONTEXT__!="undefined"&&(a=__VUE_SSR_CONTEXT__),r&&r.call(this,a),a&&a._registeredComponents&&a._registeredComponents.add(b)},i._ssrRegister=l):r&&(l=mt?function(){r.call(this,(i.functional?this.parent:this).$root.$options.shadowRoot)}:r),l)if(i.functional){i._injectStyles=l;var ht=i.render;i.render=function(_t,$){return l.call($),ht(_t,$)}}else{var x=i.beforeCreate;i.beforeCreate=x?[].concat(x,l):[l]}return{exports:t,options:i}}const L={data:()=>({exportSite:!1,exportFiles:"off",exportPages:[]}),computed:{exportSiteHelp(){return this.exportSite===!0?"Export global site content.":"Do not export global site content."},filesOptions(){return[{value:"only",text:"Only",help:"Export only site and page files, without their content."},{value:"include",text:"Include",help:"Include all translatable content in files."},{value:"off",text:"Off",help:"Do not export file fields, such as alt texts."}]},activeFilesOption(){return this.filesOptions.find(t=>t.value===this.exportFiles)},isCanExport(){return this.exportSite||this.exportPages.length}},methods:{doExport(){this.$api.get("memsource/export",{site:this.exportSite?"1":null,files:this.exportFiles,pages:this.exportPages.map(t=>t.id)}).then(t=>{this.$store.commit("memsource/SET_EXPORT",t),this.$store.commit("memsource/SET_SCREEN","Upload")}).catch(t=>{this.$store.dispatch("notification/error",t)})},storeSettings(){const{exportSite:t,exportPages:s,exportFiles:e}=this;localStorage.memsourceExportSettings=JSON.stringify({exportSite:t,exportPages:s,exportFiles:e})}},watch:{exportSite(){this.storeSettings()},exportPages(){this.storeSettings()},exportFiles(){this.storeSettings()}},created(){if(!localStorage.memsourceExportSettings)return;const t=JSON.parse(localStorage.memsourceExportSettings);this.exportSite=t.exportSite,this.exportPages=t.exportPages,this.exportFiles=t.exportFiles}},p={};var E=c(L,j,w,!1,C,null,null,null);function C(t){for(let s in p)this[s]=p[s]}var O=function(){return E.exports}(),T=function(){var t=this,s=t.$createElement,e=t._self._c||s;return e("table",{staticClass:"k-structure-table ms-results-table"},[t._m(0),t._l(t.data,function(o,r,n){return[e("tr",[e("td",{staticClass:"k-structure-table-index",attrs:{rowspan:"2"}},[e("span",{staticClass:"k-structure-table-index-number"},[t._v(" "+t._s(n+1)+" ")])]),e("td",{staticClass:"k-structure-table-column",attrs:{rowspan:"2"}},[e("p",{staticClass:"k-structure-table-text"},[t._v(" "+t._s(r)+" ")])]),e("td",{staticClass:"k-structure-table-column ms-results-table-old"},[e("p",{staticClass:"k-structure-table-text"},[t.isChangeEmpty(o.$old)?[e("i",[t._v("empty")])]:[t._v(" "+t._s(o.$old)+" ")]],2)])]),e("tr",[e("td",{staticClass:"k-structure-table-column ms-results-table-new"},[e("p",{staticClass:"k-structure-table-text"},[t.isChangeEmpty(o.$new)?[e("i",[t._v("empty")])]:[t._v(" "+t._s(o.$new)+" ")]],2)])])]})],2)},D=[function(){var t=this,s=t.$createElement,e=t._self._c||s;return e("thead",[e("tr",[e("th",{staticClass:"k-structure-table-index"},[t._v("#")]),e("th",{staticClass:"k-structure-table-column"},[t._v("Field")]),e("th",{staticClass:"k-structure-table-column"},[t._v("Change")])])])}],gt="";const P={props:{data:Object},methods:{isChangeEmpty(t){return!(typeof t=="string"?t.trim():t)}}},m={};var N=c(P,T,D,!1,F,null,null,null);function F(t){for(let s in m)this[s]=m[s]}var R=function(){return N.exports}(),M=function(){var t=this,s=t.$createElement,e=t._self._c||s;return e("k-dialog",t._g({ref:"dialog",staticClass:"ms-results-dialog",attrs:{size:"large",cancelButton:!1}},t.$listeners),[e("k-grid",{attrs:{gutter:"medium"}},[e("k-column",[e("ul",{staticClass:"k-system-info-box"},[e("li",[e("dl",[e("dt",[t._v("Date")]),e("dd",[t._v(t._s(t.statsDateText))])])]),e("li",[e("dl",[e("dt",[t._v("Time")]),e("dd",[t._v(t._s(t.statsTimeText))])])]),e("li",[e("dl",[e("dt",[t._v("Language")]),e("dd",[t._v(t._s(t.statsLang))])])]),e("li",[e("dl",[e("dt",[t._v("Models")]),e("dd",[t._v(t._s(t.statsModels))])])]),e("li",[e("dl",[e("dt",[t._v("Changes")]),e("dd",[t._v(t._s(t.statsChanges))])])]),e("li",[e("dl",[e("dt",[t._v("Dry")]),e("dd",{staticClass:"ms-results-dialog-stats-icon"},[e("k-icon",{attrs:{type:t.statsDryIcon}}),t._v(" \u200C ")],1)])])])]),t.modelsOptions.length>0?[e("k-column",[e("k-select-field",{attrs:{label:"Model",options:t.modelsOptions,empty:!1},model:{value:t.selectedModel,callback:function(o){t.selectedModel=o},expression:"selectedModel"}})],1),e("k-column",[e("results-table",{attrs:{data:t.models[t.selectedModel]}})],1)]:e("k-column",[t.data.importChanges===0?e("k-box",{attrs:{theme:"info"}},[t._v(" No differences in the content. ")]):t.data.importChanges>0?e("k-box",{attrs:{theme:"notice"}},[t._v(" Couldn't load import changes. ")]):e("k-box",{attrs:{theme:"negative",text:t.error||"Unknown error."}})],1)],2)],1)},I=[],ft="";const U={components:{ResultsTable:R},props:{data:Object},data(){return{selectedModel:null}},computed:{error(){let t=this.data.importError;return(t==null?void 0:t.errorDescription)||t},models(){let t={},s=this.data.importDiff;if(s&&typeof s=="object"){for(let e of["site","pages","files"])if(s[e]){if(e==="site")t[e]=this.flatten(s[e]);else if(typeof s[e]=="object")for(let o in s[e])t[`${e}/${o}`]=this.flatten(s[e][o])}}return t},modelsOptions(){let t=[];for(let s in this.models){let e=Object.keys(this.models[s]).length;e>0&&t.push({value:s,text:`${s} (${e})`})}return t},statsDate(){return new Date(this.data.importDate)},statsDateText(){return this.statsDate.toLocaleDateString(void 0,{dateStyle:"medium"})},statsTimeText(){return this.statsDate.toLocaleTimeString(void 0,{timeStyle:"short"})},statsLang(){var t;return((t=this.data.jobLang)==null?void 0:t.toUpperCase())||"?"},statsModels(){return this.modelsOptions.length},statsChanges(){let t=this.data.importChanges;return typeof t=="number"?t.toLocaleString():"?"},statsDryIcon(){return this.data.isDry===!0?"check":"cancel"}},methods:{open(){this.$refs.dialog.open()},close(){this.$refs.dialog.close()},flatten(t){let s={};for(let e in t){let o=t[e];if(!(!o||!t.hasOwnProperty(e)))if(typeof o=="object"&&!o.$new&&!o.$old){let r=this.flatten(o);for(let n in r)s[`${e}/${n}`]=r[n]}else o.$new&&o.$old&&(s[e]=o)}return s}},watch:{modelsOptions:{immediate:!0,handler(t){t.length>0&&(this.selectedModel=t[0].value)}}}},h={};var z=c(U,M,I,!1,H,null,null,null);function H(t){for(let s in h)this[s]=h[s]}var J=function(){return z.exports}(),W=function(){var t=this,s=t.$createElement,e=t._self._c||s;return e("k-grid",{attrs:{gutter:"medium"}},[t.importListItems.length?e("k-column",[e("k-list",{attrs:{items:t.importListItems}}),e("k-pagination",t._b({attrs:{align:"center",details:!0},on:{paginate:function(o){return t.fetch(o.page)}}},"k-pagination",t.pagination,!1)),t.importData?e("results-dialog",{ref:"dialog",attrs:{data:t.importData},on:{submit:function(o){return t.$refs.dialog.close()}}}):t._e()],1):t.isLoaded?e("k-column",[e("k-box",{attrs:{theme:"info"}},[t._v("No imports recorded.")])],1):t._e()],1)},X=[],vt="";const A={components:{ResultsDialog:J},data(){return{isLoaded:!1,importEntries:[],pagination:void 0,importData:null}},computed:{importListItems(){return this.importEntries.map(t=>{let s=new Date(t.importDate),e=this.$store.state.memsource.historyDate<s,o=`${t.jobFile} (${t.jobLang})`;t.isDry&&(o+=" (dry)");let r;return e?r="new":r=s.toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"}),{text:o,info:r,image:!0,class:e?"ms-list-item-new":"",icon:{type:t.isSuccess?"check":"cancel",color:t.isSuccess?"green":"red",back:"white"},link:()=>{this.openImportResults(t.importFile)}}})}},methods:{fetch(t){this.$api.get("memsource/imports",{page:t,limit:15}).then(s=>{this.importEntries=s.data,this.pagination=s.pagination}).catch(s=>{this.$store.dispatch("notification/error",s)}).then(()=>{this.isLoaded=!0})},openImportResults(t){this.$api.get(`memsource/imports/${t}`).then(s=>{this.importData=u(s),this.$nextTick(()=>{this.$refs.dialog.open()})}).catch(s=>{this.$store.dispatch("notification/error",s)})}},mounted(){this.fetch(1)}},_={};var B=c(A,W,X,!1,V,null,null,null);function V(t){for(let s in _)this[s]=_[s]}var Y=function(){return B.exports}(),q=function(){var t=this,s=t.$createElement,e=t._self._c||s;return e("k-grid",{attrs:{gutter:"medium"}},[e("k-column",[e("k-pages-field",{attrs:{label:"Project",empty:"No project selected yet",search:!0,endpoints:{field:"memsource/picker/projects"}},model:{value:t.project,callback:function(o){t.project=o},expression:"project"}})],1),t.selectedProject?e("k-column",[e("k-pages-field",{attrs:{label:"Workflow step",empty:"No workflow step selected yet",endpoints:{field:"memsource/picker/projects/"+t.selectedProject.id+"/workflowSteps"}},model:{value:t.workflowStep,callback:function(o){t.workflowStep=o},expression:"workflowStep"}})],1):t._e(),t.selectedProject&&t.selectedWorkflowStep?e("k-column",[e("k-pages-field",{attrs:{label:"Jobs",empty:"No jobs selected yet",search:!0,multiple:!0,endpoints:{field:"memsource/picker/projects/"+t.selectedProject.id+"/workflows/"+t.selectedWorkflowStep.workflowLevel+"/jobs"}},model:{value:t.jobs,callback:function(o){t.jobs=o},expression:"jobs"}})],1):t._e(),t.jobs.length?[e("k-column",[e("k-toggle-field",{attrs:{label:"Dry run",help:"Test import without updating the content?"},model:{value:t.dry,callback:function(o){t.dry=o},expression:"dry"}})],1),e("k-column",[e("k-button-group",{attrs:{align:"center"}},[e("k-button",{attrs:{icon:"download",theme:"positive"},on:{click:t.doImport}},[t._v(" Import jobs ")])],1)],1)]:t._e()],2)},G=[];const Q={data(){return{project:[],workflowStep:[],jobs:[],dry:!1}},computed:{selectedProject(){var t;return(t=this.project)==null?void 0:t[0]},selectedWorkflowStep(){var t;return(t=this.workflowStep)==null?void 0:t[0]}},methods:{doImport(){let t=this.jobs.map(s=>this.$api.post("memsource/import",{projectId:this.selectedProject.id,jobId:s.id,dry:this.dry}));Promise.allSettled(t).then(s=>{s.filter(o=>o.status==="rejected").length>0?this.$store.dispatch("notification/error","Some jobs have failed to import..."):this.$store.dispatch("notification/success","Successfully imported all jobs!"),this.$store.state.memsource.screen==="Import"&&this.$store.commit("memsource/SET_SCREEN","History")})}},watch:{selectedProject(){this.workflowStep=[]},selectedWorkflowStep(){this.jobs=[]}}},g={};var Z=c(Q,q,G,!1,K,null,null,null);function K(t){for(let s in g)this[s]=g[s]}var tt=function(){return Z.exports}(),et=function(){var t=this,s=t.$createElement,e=t._self._c||s;return e("k-grid",{attrs:{gutter:"medium"}},[e("k-column",[e("k-text-field",{attrs:{after:".json",label:t.$t("memsource.label.job")},model:{value:t.jobName,callback:function(o){t.jobName=o},expression:"jobName"}})],1),t.stats?e("k-column",[e("ul",{staticClass:"k-system-info-box"},[e("li",[e("dl",[e("dt",[t._v("Models")]),e("dd",[t._v(t._s(t.modelsCount.toLocaleString()))])])]),e("li",[e("dl",[e("dt",[t._v(t._s(t.$t("strings")))]),e("dd",[t._v(t._s(t.stats.strings.toLocaleString()))])])]),e("li",[e("dl",[e("dt",[t._v(t._s(t.$t("words")))]),e("dd",[t._v(t._s(t.stats.words.toLocaleString()))])])]),e("li",[e("k-button-group",[e("k-button",{attrs:{icon:"edit"},on:{click:t.editorOpen}},[t._v(" Edit ")]),e("k-button",{attrs:{icon:"download"},on:{click:t.downloadExport}},[t._v(" "+t._s(t.$t("file"))+" ")]),e("k-dialog",{ref:"editDialog",staticClass:"ms-edit-dialog",on:{submit:t.editorSubmit}},[e("k-textarea-field",{attrs:{label:"JSON",font:"monospace",buttons:!1,counter:!1},model:{value:t.dataString,callback:function(o){t.dataString=o},expression:"dataString"}})],1)],1)],1)])]):t._e(),t.checkDataEmpty(t.data)?e("k-column",[e("k-box",{attrs:{theme:"notice"}},[t._v(" The upload data is currently empty. You should export something first. ")])],1):t._e(),e("k-column",[e("k-pages-field",{attrs:{label:"Project",empty:"No project selected yet",search:!0,endpoints:{field:"memsource/picker/projects"}},model:{value:t.project,callback:function(o){t.project=o},expression:"project"}})],1),t.selectedProject?[t.missingProjectLangs.length?e("k-column",[e("k-box",{attrs:{theme:"notice"}},[t._v(" The selected project does not target the following site languages: "),e("strong",[t._v(" "+t._s(t.missingProjectLangs.join(", ").toUpperCase())+" ")])])],1):t._e(),t.missingSiteLangs.length?e("k-column",[e("k-box",{attrs:{theme:"notice"}},[t._v(" The selected project targets languages not yet added to the site: "),e("strong",[t._v(" "+t._s(t.missingSiteLangs.join(", ").toUpperCase())+" ")])])],1):t._e(),t.validTargetLangsOptions.length?[e("k-column",[e("k-checkboxes-field",{attrs:{label:t.$t("memsource.label.target_langs"),options:t.validTargetLangsOptions,columns:Math.min(t.validTargetLangsOptions.length,6)},model:{value:t.selectedTargetLangs,callback:function(o){t.selectedTargetLangs=o},expression:"selectedTargetLangs"}})],1),e("k-column",[e("k-button-group",{attrs:{align:"center"}},[e("k-button",{attrs:{theme:"positive",icon:"upload",disabled:!t.selectedTargetLangs.length||t.isUploading},on:{click:t.upload}},[t._v(" "+t._s(t.$t("upload"))+" ")])],1)],1)]:t.isLoadingLangs?t._e():e("k-column",[e("k-box",{attrs:{theme:"negative"}},[t._v("No valid target langs.")])],1)]:t._e()],2)},st=[],kt="";function f(t){let s={strings:0,words:0};for(let e in t){let o=t[e];if(typeof o=="object"&&o!==null){let r=f(o);s.strings+=r.strings,s.words+=r.words}else t.hasOwnProperty(e)&&e!=="id"&&(s.strings++,typeof o=="string"&&(s.words+=o.trim().split(/\s+/).length))}return s}const ot={data(){let t=window.location.hostname.replace(".","-"),s=new Date().toLocaleDateString("en",{day:"2-digit",month:"short",year:"2-digit"}),e=`${t}-${s}`.toLowerCase().replace(/[^a-z0-9]+/g,"-");return{isLoadingLangs:!1,isUploading:!1,dataString:null,project:[],validTargetLangs:[],missingSiteLangs:[],missingProjectLangs:[],selectedTargetLangs:[],jobName:e}},computed:{data(){return this.$store.state.memsource.export},stats(){return f(this.data)},modelsCount(){var o,r,n;let t=0,s=(o=this.data)==null?void 0:o.pages,e=(r=this.data)==null?void 0:r.files;return(n=this.data)!=null&&n.site&&t++,s&&(t+=Object.keys(s).length),e&&(t+=Object.keys(e).length),t},selectedProject(){var t;return(t=this.project)==null?void 0:t[0]},validTargetLangsOptions(){return this.validTargetLangs.map(t=>({text:t.toUpperCase(),value:t}))}},methods:{editorOpen(){this.dataString=this.checkDataEmpty(this.data)?"":JSON.stringify(this.data,void 0,2),this.$refs.editDialog.open()},editorSubmit(){let t=null;try{t=JSON.parse(this.dataString)}catch{this.$refs.editDialog.error("Invalid JSON.");return}this.$store.commit("memsource/SET_EXPORT",t),this.$refs.editDialog.close()},checkDataEmpty(t){return!t||Object.keys(t).length===0},upload(){this.isUploading=!0,this.$api.post("memsource/upload",{projectId:this.selectedProject.id,targetLangs:this.selectedTargetLangs,jobName:this.jobName,jobData:this.data}).then(t=>{this.$store.dispatch("notification/success",`Successfully created ${t.jobs.length} jobs!`)}).catch(t=>{this.$store.dispatch("notification/error",t)}).then(()=>{this.isUploading=!1})},downloadExport(){let t=JSON.stringify(this.data,null,2),s=new Blob([t],{type:"application/json"}),e=URL.createObjectURL(s),o=document.createElement("a");o.download=this.jobName,o.href=e,o.click()}},watch:{selectedProject(t){this.validTargetLangs=[],this.missingSiteLangs=[],this.missingProjectLangs=[],t&&(this.isLoadingLangs=!0,this.$api.get("memsource/verify-languages",{targetLangs:t.targetLangs}).then(s=>{this.validTargetLangs=s.validTargetLangs,this.missingSiteLangs=s.missingSiteLangs,this.missingProjectLangs=s.missingProjectLangs}).catch(s=>{this.$store.dispatch("notification/error",s)}).then(()=>{this.isLoadingLangs=!1}))},validTargetLangs(t){this.selectedTargetLangs=[...t]}}},v={};var rt=c(ot,et,st,!1,it,null,null,null);function it(t){for(let s in v)this[s]=v[s]}var nt=function(){return rt.exports}(),at=function(){var t=this,s=t.$createElement,e=t._self._c||s;return e("k-view",[e("div",{staticClass:"k-header"},[e("div",{staticClass:"k-tabs"},[e("nav",t._l(t.tabs,function(o){return e("k-button",{key:o.component,staticClass:"k-tab-button",attrs:{current:t.screen===o.component,icon:o.icon},on:{click:function(r){t.screen=o.component}}},[t._v(" "+t._s(o.text)+" ")])}),1)])]),e(t.screen,{tag:"component"})],1)},lt=[],bt="";const ct={components:{Export:O,History:Y,Import:tt,Upload:nt},data(){return{tabs:[{icon:"share",text:"Export",component:"Export"},{icon:"upload",text:"Upload",component:"Upload"},{icon:"download",text:"Import",component:"Import"},{icon:"clock",text:"History",component:"History"}]}},computed:{screen:{get(){return this.$store.state.memsource.screen},set(t){return this.$store.commit("memsource/SET_SCREEN",t)}}},beforeCreate(){this.$store.registerModule("memsource",y)},created(){this.screen=localStorage.memsourceScreen||"Export"}},k={};var dt=c(ct,at,lt,!1,ut,"7ab56af6",null,null);function ut(t){for(let s in k)this[s]=k[s]}var pt=function(){return dt.exports}();panel.plugin("oblik/memsource",{views:{memsource:{icon:"globe",label:"Memsource",component:pt}}})})();