UNPKG

@europeana/portal

Version:
2 lines 5.6 kB
(window.webpackJsonp=window.webpackJsonp||[]).push([[63],{1146:function(e,t,n){"use strict";n.r(t);var r=n(23),o=(n(75),n(30),n(10),n(46),n(80),n(104),n(34),n(800)),l=n(31),c=n(322),data=n(109),d={name:"ContentfulImageHarvesterPage",mixins:[o.a],layout:"contentful",head:function(){return{title:this.$pageHeadTitle("Image harvester - Contentful app"),bodyAttrs:{class:"",style:"background: transparent;"}}},methods:{harvestImage:function(){var e=this;return Object(r.a)(regeneratorRuntime.mark((function t(){var n,r,o;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.getUrlFromUser();case 2:if(n=t.sent){t.next=5;break}return t.abrupt("return");case 5:if(r=Object(c.c)(n)){t.next=9;break}return e.showError("Unable to parse URL: ".concat(n," Please make sure the URL conforms to the accepted formats.")),t.abrupt("return");case 9:return t.prev=9,t.next=12,e.$apis.record.$axios.get("".concat(r,".json"));case 12:o=t.sent,t.next=19;break;case 15:return t.prev=15,t.t0=t.catch(9),e.showError('Unable to harvest "'.concat(n,'". Please make sure the item can be accessed on the Record API. Error: "').concat(t.t0.message,'"')),t.abrupt("return");case 19:return t.prev=19,t.next=22,e.populateFields(o.data.object);case 22:e.message="Success",t.next=28;break;case 25:t.prev=25,t.t1=t.catch(19),e.showError("There was a problem updating the entry. ".concat(t.t1.message));case 28:case"end":return t.stop()}}),t,null,[[9,15],[19,25]])})))()},getUrlFromUser:function(){var e=this;return Object(r.a)(regeneratorRuntime.mark((function t(){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e.contentfulExtensionSdk.dialogs.openPrompt({title:"Harvest",message:"Enter an item page URL, or an item URI or ID.",intent:"positive"}));case 1:case"end":return t.stop()}}),t)})))()},localiseValue:function(e){return Object(l.h)(e,this.$i18n.locale).values[0]||null},populateFields:function(e){var t=this;return Object(r.a)(regeneratorRuntime.mark((function n(){var r,o,l,c,d,f,v,m,h,x,w,y,k,E,R,S,A,U,V,I,_,T,j,L,O,C,P,H,$;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(y=t.$i18n.isoLocale(),k=e.aggregations.find((function(e){return e.about.startsWith("/aggregation/provider/")})),E=e.proxies.find((function(e){return e.about.startsWith("/proxy/provider/")})),R=k.edmIsShownBy,S=(k.webResources||[]).find((function(e){return e.about===R})),A=k.edmDataProvider,U=null===(r=e.organizations)||void 0===r?void 0:r.find((function(e){var t;return e.about===(null===(t=A.def)||void 0===t?void 0:t[0])})),R&&null!=S&&null!==(o=S.ebucoreHasMimeType)&&void 0!==o&&o.startsWith("image/")){n.next=9;break}throw new Error("No edm:isShownBy image found.");case 9:return V=t.localiseValue(E.dcTitle),I=(null==S?void 0:S.dcCreator)||E.dcCreator,_=I?null===(l=e.agents)||void 0===l?void 0:l.find((function(e){var t;return e.about===(null===(t=I.def)||void 0===t?void 0:t[0])})):void 0,T=t.localiseValue((null==_?void 0:_.prefLabel)||I),j=t.localiseValue((null==U?void 0:U.prefLabel)||A),L=(null==S||null===(c=S.webResourceEdmRights)||void 0===c||null===(d=c.def)||void 0===d?void 0:d[0])||(null===(f=k.edmRights.def)||void 0===f?void 0:f[0]),O="".concat(data.a,"/item").concat(e.about),null===(v=t.entry.fields.name)||void 0===v||v.setValue(V,y),null===(m=t.entry.fields.creator)||void 0===m||m.setValue(T,y),null===(h=t.entry.fields.provider)||void 0===h||h.setValue(j,y),null===(x=t.entry.fields.license)||void 0===x||x.setValue(L),null===(w=t.entry.fields.url)||void 0===w||w.setValue(O),n.next=23,t.entry.fields.image.removeValue();case 23:return(C={fields:{title:{},file:{}}}).fields.title[y]=V||e.about,C.fields.file[y]={contentType:S.ebucoreHasMimeType,fileName:C.fields.title[y],upload:R},n.next=28,t.contentfulExtensionSdk.space.createAsset(C);case 28:return P=n.sent,n.next=31,t.contentfulExtensionSdk.space.processAsset(P,y);case 31:return n.next=33,t.contentfulExtensionSdk.space.waitUntilAssetProcessed(P.sys.id,y);case 33:return H=n.sent,n.next=36,t.contentfulExtensionSdk.space.publishAsset(H);case 36:return $=n.sent,n.next=39,t.entry.fields.image.setValue({sys:{type:"Link",linkType:"Asset",id:$.sys.id}});case 39:case"end":return n.stop()}}),n)})))()}}},f=(n(948),n(59)),component=Object(f.a)(d,(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},800:function(e,t,n){"use strict";t.a={data:function(){return{contentfulExtensionSdk:null,entry:null,message:null}},mounted:function(){var e=this;window.contentfulExtension.init((function(t){e.contentfulExtensionSdk=t,t.location.is(window.contentfulExtension.locations.LOCATION_ENTRY_SIDEBAR)&&(t.window.startAutoResizer(),e.entry=t.entry)}))},methods:{showError:function(e){this.contentfulExtensionSdk.dialogs.openAlert({title:"Error",message:e}),this.message="Failed"}}}},851:function(e,t,n){var content=n(949);content.__esModule&&(content=content.default),"string"==typeof content&&(content=[[e.i,content,""]]),content.locals&&(e.exports=content.locals);(0,n(138).default)("7b97da6f",content,!0,{sourceMap:!1})},948:function(e,t,n){"use strict";n(851)},949:function(e,t,n){var r=n(137)(!1);r.push([e.i,".contentful[data-v-e440ae6c]{font-size:11px}.contentful button[data-v-e440ae6c]{margin-right:1rem}",""]),e.exports=r}}]); //# sourceMappingURL=cb9f68f.js.map