@europeana/portal
Version:
Europeana Portal
2 lines • 4.51 kB
JavaScript
(window.webpackJsonp=window.webpackJsonp||[]).push([[62],{1075:function(e,t,n){"use strict";n.r(t);var o=n(16),l=(n(21),n(22),n(76),n(733)),r=n(24),d=n(256),data=n(83),c={name:"ContentfulImageHarvesterPage",mixins:[l.a],layout:"contentful",head(){return{title:this.$pageHeadTitle("Image harvester - Contentful app"),bodyAttrs:{class:"",style:"background: transparent;"}}},methods:{harvestImage(){var e=this;return Object(o.a)((function*(){var t=yield e.getUrlFromUser();if(t){var n=Object(d.c)(t);if(n){var o;try{o=yield e.$apis.record.$axios.get("".concat(n,".json"))}catch(n){return void e.showError('Unable to harvest "'.concat(t,'". Please make sure the item can be accessed on the Record API. Error: "').concat(n.message,'"'))}try{yield e.populateFields(o.data.object),e.message="Success"}catch(t){e.showError("There was a problem updating the entry. ".concat(t.message))}}else e.showError("Unable to parse URL: ".concat(t," Please make sure the URL conforms to the accepted formats."))}}))()},getUrlFromUser(){var e=this;return Object(o.a)((function*(){return e.contentfulExtensionSdk.dialogs.openPrompt({title:"Harvest",message:"Enter an item page URL, or an item URI or ID.",intent:"positive"})}))()},localiseValue(e){return Object(r.h)(e,this.$i18n.locale).values[0]||null},populateFields(e){var t=this;return Object(o.a)((function*(){var n,o,l,r,d,c,f,v,m,h,y,w=t.$i18n.isoLocale(),E=e.aggregations.find((e=>e.about.startsWith("/aggregation/provider/"))),x=e.proxies.find((e=>e.about.startsWith("/proxy/provider/"))),k=E.edmIsShownBy,R=(E.webResources||[]).find((e=>e.about===k)),S=E.edmDataProvider,A=null===(n=e.organizations)||void 0===n?void 0:n.find((e=>{var t;return e.about===(null===(t=S.def)||void 0===t?void 0:t[0])}));if(!k||null==R||null===(o=R.ebucoreHasMimeType)||void 0===o||!o.startsWith("image/"))throw new Error("No edm:isShownBy image found.");var U=t.localiseValue(x.dcTitle),V=(null==R?void 0:R.dcCreator)||x.dcCreator,I=V?null===(l=e.agents)||void 0===l?void 0:l.find((e=>{var t;return e.about===(null===(t=V.def)||void 0===t?void 0:t[0])})):void 0,_=t.localiseValue((null==I?void 0:I.prefLabel)||V),T=t.localiseValue((null==A?void 0:A.prefLabel)||S),j=(null==R||null===(r=R.webResourceEdmRights)||void 0===r||null===(d=r.def)||void 0===d?void 0:d[0])||(null===(c=E.edmRights.def)||void 0===c?void 0:c[0]),L="".concat(data.a,"/item").concat(e.about);null===(f=t.entry.fields.name)||void 0===f||f.setValue(U,w),null===(v=t.entry.fields.creator)||void 0===v||v.setValue(_,w),null===(m=t.entry.fields.provider)||void 0===m||m.setValue(T,w),null===(h=t.entry.fields.license)||void 0===h||h.setValue(j),null===(y=t.entry.fields.url)||void 0===y||y.setValue(L),yield t.entry.fields.image.removeValue();var O={fields:{title:{},file:{}}};O.fields.title[w]=U||e.about,O.fields.file[w]={contentType:R.ebucoreHasMimeType,fileName:O.fields.title[w],upload:k};var C=yield t.contentfulExtensionSdk.space.createAsset(O);yield t.contentfulExtensionSdk.space.processAsset(C,w);var P=yield t.contentfulExtensionSdk.space.waitUntilAssetProcessed(C.sys.id,w),H=yield t.contentfulExtensionSdk.space.publishAsset(P);yield t.entry.fields.image.setValue({sys:{type:"Link",linkType:"Asset",id:H.sys.id}})}))()}}},f=(n(875),n(40)),component=Object(f.a)(c,(function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{staticClass:"contentful"},[n("b-form-group",[n("b-button",{staticClass:"mb-2",on:{click:e.harvestImage}},[e._v("\n Harvest\n ")])],1),e._v(" "),n("p",[e._v(e._s(e.message))])],1)}),[],!1,null,"e440ae6c",null);t.default=component.exports},733:function(e,t,n){"use strict";t.a={data:()=>({contentfulExtensionSdk:null,entry:null,message:null}),mounted(){window.contentfulExtension.init((e=>{this.contentfulExtensionSdk=e,e.location.is(window.contentfulExtension.locations.LOCATION_ENTRY_SIDEBAR)&&(e.window.startAutoResizer(),this.entry=e.entry)}))},methods:{showError(e){this.contentfulExtensionSdk.dialogs.openAlert({title:"Error",message:e}),this.message="Failed"}}}},777:function(e,t,n){var content=n(876);content.__esModule&&(content=content.default),"string"==typeof content&&(content=[[e.i,content,""]]),content.locals&&(e.exports=content.locals);(0,n(106).default)("7b97da6f",content,!0,{sourceMap:!1})},875:function(e,t,n){"use strict";n(777)},876:function(e,t,n){var o=n(105)(!1);o.push([e.i,".contentful[data-v-e440ae6c]{font-size:11px}.contentful button[data-v-e440ae6c]{margin-right:1rem}",""]),e.exports=o}}]);
//# sourceMappingURL=1e196f5.modern.js.map