@dbp-topics/authentic-document
Version:
[GitLab Repository](https://gitlab.tugraz.at/dbp/authentic-documents/authenticdocument) | [npmjs package](https://www.npmjs.com/package/@dbp-topics/authentic-document) | [Unpkg CDN](https://unpkg.com/browse/@dbp-topics/authentic-document/) | [Authentic Do
186 lines (172 loc) • 14.3 kB
JavaScript
let e,t,i,a,s,n,r,o,u=e=>e;function c(){return c=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var a in i)Object.prototype.hasOwnProperty.call(i,a)&&(e[a]=i[a])}return e},c.apply(this,arguments)}
/*!
* License: LGPL-2.1-or-later
* Dependencies:
*
* @webcomponents/scoped-custom-element-registry: BSD-3-Clause
* @dbp-toolkit/app-shell: LGPL-2.1-or-later
* @dbp-toolkit/language-select: LGPL-2.1-or-later
* @dbp-toolkit/common: LGPL-2.1-or-later
* lit-html: BSD-3-Clause
* @dbp-toolkit/auth: LGPL-2.1-or-later
* event-target-shim: MIT
* @dbp-toolkit/notification: LGPL-2.1-or-later
* @dbp-toolkit/theme-switcher: LGPL-2.1-or-later
* path-to-regexp: MIT
* universal-router: MIT
* generateUrls: MIT
* @dbp-toolkit/matomo: LGPL-2.1-or-later
* @tugraz/web-components: LGPL-2.1-or-later
* @babel/runtime: MIT
* i18next: MIT
* @lit/reactive-element: BSD-3-Clause
* lit-element: BSD-3-Clause
* @open-wc/dedupe-mixin: MIT
* @open-wc/scoped-elements: MIT
*/import{c as l,l as h,a as d,g as m,j as p,y as b,S as g,A as f,I as y,M as v,B as k,s as q,d as $,f as _,m as S}from"./shared/notification.f784a17e.es.js";var w={"authentic-image-request":{"available-documents":"Verfügbare Dokumente für","available-text":"Für die Verwendung an der Hochschule freigeben",description:"Erlaubt es offizielle Dokumente von einem staatlichen Register anzufordern und diese an Dritte freizugeben.","not-available-text":"Nicht verfügbar. Bitte wenden Sie sich an den IT-Support","request-button":"Dokument laden","request-document":"Dokument freigeben","request-success-body":"Das angeforderte Dokument ('{{name}}') wird abgerufen, sobald es verfügbar ist. Sie werden per E-Mail über den weiteren Verlauf verständigt.","request-success-title":"Erfolgreich angefordert","request-text":"Anfordern und für die Verwendung an der Hochschule freigeben","retrieve-token":"Verfügbare Dokumente anzeigen","show-document":"Dokument anzeigen",title:"Dokumente aus offiziellen Quellen übernehmen"}},A={"authentic-image-request":{"available-documents":"Available documents for","available-text":"Approve for use at the university",description:"Allows requesting an official document from a state authority and share it with a third party.","not-available-text":"Not available. Please contact the IT support","request-button":"Load document","request-document":"Share Document","request-success-body":"The requested document ('{{name}}') will be retrieved as soon as it is available. You will be informed by e-mail about the further process.","request-success-title":"Successful requested","request-text":"Request and release for use at the university","retrieve-token":"Show available Documents","show-document":"Show Document",title:"Load documents from authentic sources"}};class x extends h{constructor(){super(),this.value1="",this.value2="",this.name1="",this.name2="",this.name="",this.disabled=!1,this._active="button1"}static get properties(){return{value1:{type:String},value2:{type:String},name1:{type:String},name2:{type:String},name:{type:String,reflect:!0},disabled:{type:Boolean},_active:{type:Boolean}}}static get styles(){return d(e||(e=u`
${0}
${0}
div {
white-space: nowrap;
display: flex;
}
#button1 {
border-right-width: 0;
}
.active {
background-color: var(--dbp-secondary-surface) !important;
color: var(--dbp-on-secondary-surface) !important;
}
.button {
flex-grow: 1;
}
.button:hover {
background-color: var(--dbp-secondary-surface) !important;
}
`),m(),p())}update(e){e.forEach(((e,t)=>{"name"===t&&(this[t]===this.name1?this._active="button1":this[t]===this.name2&&(this._active="button2"))})),super.update(e)}render(){const e=function(e){this._active=e.target.id,this.name="button1"===this._active?this.name1:this.name2;const t=new CustomEvent("change",{bubbles:!0,cancelable:!1});this.dispatchEvent(t)};return b(t||(t=u`
<div>
<button
="${0}"
class="button ${0}"
id="${0}"
?disabled="${0}">
${0}
</button>
<button
="${0}"
class="button ${0}"
id="${0}"
?disabled="${0}">
${0}
</button>
</div>
`),e,"button1"===this._active?"active":"","button1",this.disabled,this.value1,e,"button2"===this._active?"active":"","button2",this.disabled,this.value2)}}class D{constructor(e){this._data=e}getName(e){var t;let i=this._data.name;return null!=(t=i[e])?t:i.en}getDescription(e){var t;let i=this._data.description;return null!=(t=i[e])?t:i.en}}var z={element:"dbp-authentic-image-request",module_src:"dbp-authentic-image-request.js",routing_name:"authentic-image-request",name:{de:"Dokumente aus offiziellen Quellen freigeben",en:"Share documents from authentic sources"},short_name:{de:"Offizielle Dokumente freigeben",en:"Share official documents"},description:{de:"Lädt ein offizielles Dokument von einem staatlichen Register herunter",en:"Loads an official document from a state authority"},subscribe:"lang:lang,entry-point-url:entry-point-url,auth:auth"};class R extends(g(f)){constructor(){super(),this._i18n=l({en:A,de:w},"de","en"),this.auth={},this.lang=this._i18n.language,this.entryPointUrl="",this.access_token="",this.given_name="",this.family_name="",this.fullResponse="",this.responseFromServer="",this.itemsAvailable=[],this.itemsRequested=[],this.itemsNotAvailable=[],this.gridContainer="display:none",this.imageSrc=null}static get scopedElements(){return{"dbp-icon":y,"dbp-mini-spinner":v,"dbp-button":k,"dbp-textswitch":x}}static get properties(){return c({},super.properties,{lang:{type:String},entryPointUrl:{type:String,attribute:"entry-point-url"},access_token:{type:String,attribute:!1},given_name:{type:String,attribute:!1},family_name:{type:String,attribute:!1},fullResponse:{type:String,attribute:!1},responseFromServer:{type:String,attribute:!1},itemsAvailable:{type:Array,attribute:!1},itemsRequested:{type:Array,attribute:!1},itemsNotAvailable:{type:Array,attribute:!1},gridContainer:{type:String,attribute:!1},imageSrc:{type:String,attribute:!1},auth:{type:Object}})}connectedCallback(){super.connectedCallback()}update(e){e.forEach(((e,t)=>{if("lang"===t)this._i18n.changeLanguage(this.lang)})),super.update(e)}parseAvailableDocumentTypes(){let e=parseInt(this.responseFromServer["hydra:totalItems"]);isNaN(e)&&(e=0);for(let t=0;t<e;t++){let e=this.responseFromServer["hydra:member"][t];"available"===e.availabilityStatus?this.itemsAvailable[t]=e:"requested"===e.availabilityStatus?this.itemsRequested[t]=e:this.itemsNotAvailable[t]=e}}async httpGetAsync(e,t){return await fetch(e,t).then((e=>{if(!e.ok)throw e;return e.json()}))}parseJwt(e){var t=e.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"),i=decodeURIComponent(atob(t).split("").map((function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})).join(""));return JSON.parse(i)}async retrieveToken(){let e;const t={headers:{Authorization:"Bearer "+this.auth.token}};e=await this.httpGetAsync("https://auth-dev.tugraz.at/auth/realms/tugraz-vpu/broker/eid-oidc/token",t),e&&e.access_token&&(e.access_token="photo-jpeg-available-token",this.access_token=e.access_token,this.fullResponse=this.parseJwt(e.id_token),this.family_name=this.fullResponse.family_name,this.given_name=this.fullResponse.given_name),console.log(this.access_token);const i={method:"GET",headers:{"Content-Type":"application/ld+json",Authorization:"Bearer "+this.auth.token,Token:this.access_token}},a=this.entryPointUrl+"/authentic_document_types?page=1";if(""!==this.access_token)try{this.responseFromServer=await this.httpGetAsync(a,i)}catch(e){throw 403==e.status&&q({body:"eid token expired",type:"danger",timeout:10}),e}this.parseAvailableDocumentTypes(),this.gridContainer="display:flex"}async buttonPressSuccessMessage(e,t){this.shadowRoot.getElementById("btn-"+t.identifier).setAttribute("disabled","");let i=this.entryPointUrl+"/authentic_document_requests",a={typeId:t.identifier,token:this.access_token},s=await fetch(i,{method:"POST",headers:{Authorization:"Bearer "+this.auth.token,"Content-Type":"application/json",Token:this.access_token},body:JSON.stringify(a)});if(!s.ok)return void this.shadowRoot.getElementById("btn-"+t.identifier).removeAttribute("disabled");let n=await s.json(),r=new Date(n.estimatedTimeOfArrival);console.log(r.toLocaleString()),q({summary:this._i18n.t("authentic-image-request.request-success-title"),body:this._i18n.t("authentic-image-request.request-success-body",{name:t.name}),type:"success",timeout:10})}async buttonPressShowDocument(e,t){const i={headers:{Authorization:"Bearer "+this.auth.token,Accept:"application/ld+json",Token:this.access_token}};this.imageSrc=null;let a=this.entryPointUrl+"/authentic_documents/"+t.identifier,s=await this.httpGetAsync(a,i);this.imageSrc=s.contentUrl}static get styles(){return d(i||(i=u`
${0}
${0}
${0}
${0}
#documents {
display: grid;
grid-template-columns: repeat(3, max-content);
column-gap: 15px;
row-gap: 1.5em;
align-items: center;
margin-top: 2em;
margin-bottom: 2em;
}
.header {
display: grid;
align-items: center;
grid-template-columns: 1fr auto;
gap: 10px;
}
.border {
border-top: var(--dbp-border);
}
#grid-container {
margin-top: 2rem;
padding-top: 2rem;
display: flex;
flex-flow: column;
}
h2:first-child {
margin-top: 0px;
margin-bottom: 0px;
}
h2 {
margin-bottom: 10px;
}
.subheadline {
font-style: italic;
padding-left: 2em;
margin-top: -1px;
/*line-height: 1.8;*/
margin-bottom: 1.2em;
}
`),m(),$(!1),p(),_())}render(){const e=new D(z),t=this._i18n;return b(a||(a=u`
<h2>${0}</h2>
<p class="subheadline">${0}</p>
<p>${0}</p>
<button
class="button is-primary"
="${0}"
title="${0}">
${0}
</button>
<div id="grid-container" class="border" style="${0}">
<h3 id="doc-headline">
${0} ${0}
${0}:
</h3>
<div id="documents">
${0}
${0}
${0}
</div>
</div>
${0}
`),t.t("authentic-image-request.title"),e.getDescription(this.lang),t.t("authentic-image-request.description"),this.retrieveToken,t.t("authentic-image-request.request-button"),t.t("authentic-image-request.retrieve-token"),this.gridContainer,t.t("authentic-image-request.available-documents"),this.given_name,this.family_name,this.itemsRequested.map((e=>b(s||(s=u`
<span class="header">
<strong>${0}</strong>
${0}.
</span>
<button
id="btn-${0}"
class="button is-primary"
="${0}">
${0}
</button>
<button class="button is-primary" disabled>
${0}
</button>
`),e.name,t.t("authentic-image-request.request-text"),e.identifier,(t=>this.buttonPressSuccessMessage(t,e)),t.t("authentic-image-request.request-document"),t.t("authentic-image-request.show-document")))),this.itemsAvailable.map((e=>b(n||(n=u`
<span class="header">
<strong>${0}</strong>
${0}.
</span>
<button
id="btn-${0}"
class="button is-primary"
="${0}">
${0}
</button>
<button
class="button is-primary"
="${0}">
${0}
</button>
`),e.name,t.t("authentic-image-request.available-text"),e.identifier,(t=>this.buttonPressSuccessMessage(t,e)),t.t("authentic-image-request.request-document"),(t=>this.buttonPressShowDocument(t,e)),t.t("authentic-image-request.show-document")))),this.itemsNotAvailable.map((e=>b(r||(r=u`
<span class="header">
<strong>${0}</strong>
${0}.
</span>
<button id="btn-${0}" class="button is-primary" disabled>
${0}
</button>
<button class="button is-primary" disabled>
${0}
</button>
`),e.name,t.t("authentic-image-request.not-available-text"),e.identifier,t.t("authentic-image-request.request-document"),t.t("authentic-image-request.show-document")))),this.imageSrc?b(o||(o=u`
<img src="${0}" />
`),this.imageSrc):"")}}S("dbp-authentic-image-request",R);
//# sourceMappingURL=dbp-authentic-image-request.js.map