"use strict";(self.webpackChunkmakana_model=self.webpackChunkmakana_model||[]).push([[568],{568:(e,t,n)=>{n.r(t),n.d(t,{ButtonExtension:()=>s,default:()=>h});var a=n(129),o=n(940),l=n(706);const d={activate:function(e){e.docRegistry.addWidgetExtension("Notebook",new s)},id:"makana-model",autoStart:!0};let r=null;var i;let p,c;class s{createNew(e,t){const n=e.translator.load("jupyterlab"),l=o.Dialog.okButton({label:n.__("Save")});var d=new URLSearchParams;d.append("client_id","makana_api"),d.append("grant_type","client_credentials"),d.append("scope","makanaapp_api"),d.append("client_secret","TAxhx@9tH(l^MgQ9FWE8}T@NWUT9U)"),fetch("https://makana-app-staging-wa.azurewebsites.net/connect/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:d}).then((e=>e.json())).then((e=>{fetch("https://makana-app-staging-wa.azurewebsites.net/api/makana/modelframeworks",{method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer "+e.access_token}}).then((e=>e.json())).then((e=>{i=e}))})).catch((e=>{console.error("Error:",e)}));const r=new o.ToolbarButton({className:"clear-output-button",label:"Register New Model",onClick:()=>{(0,o.showDialog)({title:"Register New Model",body:new m,buttons:[o.Dialog.cancelButton(),l]}).catch((e=>console.log(e)))},tooltip:"Register a New Model"});return e.toolbar.insertItem(10,"registermodel",r),new a.DisposableDelegate((()=>{r.dispose()}))}}class m extends l.Widget{constructor(){super({node:u()})}getValue(){var e,t=document.getElementById("model").value,n=document.getElementById("desinput").value,a=document.getElementById("framework").value,o=document.getElementById("framever").value,l=new FormData;return l.append("id",""),l.append("name",t),l.append("description",n),l.append("modelFrameworkId",a),p?l.append("frameworkName",p):(e=document.getElementById("framename").value,l.append("frameworkName",e)),l.append("frameworkVersion",o),l.append("modelFileName",c[0].name),l.append("modelFileUri",""),l.append("modelFile",c[0]),console.log(l),fetch("https://localhost:44350/api/makana/models",{method:"POST",headers:{Authorization:"Bearer "+r},body:l}).then((e=>e.json())).then((e=>{console.log(e)})).catch((e=>{console.error("Error",e)})),this.node.value}}function u(){var e=new URLSearchParams;e.append("client_id","makana_api"),e.append("grant_type","client_credentials"),e.append("scope","makanaapp_api"),e.append("client_secret","TAxhx@9tH(l^MgQ9FWE8}T@NWUT9U)"),fetch("https://localhost:44350/connect/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:e}).then((e=>e.json())).then((e=>{r=e.access_token}));const t=document.createElement("select");t.setAttribute("id","framework"),t.className="framework";const n=document.createElement("div");n.id="div",n.setAttribute("class","form-group row has-feedback-icon"),n.style.lineHeight="10px";const a=document.createElement("label");a.append("Model Name: ");const o=document.createElement("input");o.placeholder="Enter Model Name",o.id="model";const l=document.createElement("label");l.append("Description: ");const d=document.createElement("input");d.id="desinput",d.placeholder="Enter Description";const s=document.createElement("label");s.append("Model Framework: "),i.forEach((function(e){var n=document.createElement("option");n.value=e.id,n.text=e.name,t.appendChild(n)}));const m=document.createElement("label");m.append("Framework Name: "),m.setAttribute("class","d-none form-group row");const u=document.createElement("input");u.id="framename",u.setAttribute("class","d-none form-group row"),u.placeholder="Enter Framework Name";const h=document.createElement("label");h.append("Framework Version: ");const w=document.createElement("input");w.id="framever",w.placeholder="Enter Framework Version";const k=document.createElement("label");k.append("Upload Model File: ");const g=document.createElement("INPUT");return g.setAttribute("type","file"),g.id="file",n.appendChild(a),n.appendChild(o),n.appendChild(l),n.appendChild(d),n.appendChild(s),n.appendChild(t),n.appendChild(m).appendChild(u),n.appendChild(h),n.appendChild(w),n.appendChild(k),n.appendChild(g),t.onchange=function(){var e=document.getElementById("framework").value,t=i.find((t=>t.id==e));"Other"==t.name?(p="",m.style.visibility="visible",u.style.visibility="visible"):(p=t.name,m.style.visibility="hidden",u.style.visibility="hidden")},g.onchange=function(e){const t=e.target;c=t.files},n}const h=d}}]);