"use strict";(self.webpackChunkjupS3=self.webpackChunkjupS3||[]).push([[675],{675:(e,t,n)=>{n.r(t),n.d(t,{default:()=>h});var o=n(607),r=n(256),s=n(765),i=n(74),c=n(465);async function a(e="",t={}){const n=c.ServerConnection.makeSettings(),o=i.URLExt.join(n.baseUrl,"jupS3",e);let r;try{r=await c.ServerConnection.makeRequest(o,t,n)}catch(e){throw new c.ServerConnection.NetworkError(e)}let s=await r.text();if(s.length>0)try{s=JSON.parse(s)}catch(e){console.log("Not a JSON response body.",r)}if(!r.ok)throw new c.ServerConnection.ResponseError(r,s.message||s);return s}const l={id:"jupS3:plugin",description:"A JupyterLab extension.",autoStart:!0,optional:[s.ISettingRegistry],activate:(e,t)=>{console.log("JupyterLab extension jupS3 is activated!"),t&&t.load(l.id).then((e=>{console.log("jupS3 settings loaded:",e.composite)})).catch((e=>{console.error("Failed to load settings for jupS3.",e)})),a("get-example").then((e=>{console.log(e)})).catch((e=>{console.error(`The jupS3 server extension appears to be missing.\n${e}`)}));const n=new d,r=new o.MainAreaWidget({content:n});r.title.label="AURIN Data Browser",e.shell.add(r,"left")}};class d extends r.Widget{constructor(){super(),this.addClass("jp-S3BrowserWidget"),this.id="s3-browser-widget",this.title.label="AURIN Data Browser",this.title.closable=!0,this.node.innerHTML='\n      <div>\n        <img src="https://aurin.org.au/wp-content/uploads/2016/12/AURIN-ORG-AU-1.jpg" \n            width="214.4" \n            height="100" \n        />\n        <h2 style="text-align:center;">AURIN Data</h2>\n        <hr>\n        <p style="font-style:italic;text-decoration:underline;">Right click any data file to save it to your home directory on the server:</p>\n        <hr>\n        <ul id="s3-contents"></ul>\n        <ul id="s3-contents" class="jp-DirListing-content"></ul>\n        <hr>\n      </div>\n    ',a("get-bucket-contents").then((e=>{const t=this.node.querySelector("#s3-contents");e.data.forEach((e=>{const n=document.createElement("li");n.classList.add("jp-DirListing-item"),n.addEventListener("contextmenu",this.handleRightClick.bind(this)),n.textContent=e,t.appendChild(n)}))})).catch((e=>{console.error(`Error getting S3 bucket contents.\n${e}`)}))}handleRightClick(e){e.preventDefault();const t=e.target;t&&"LI"===t.tagName&&console.log("Right-clicked item text:",t.textContent);const n=this.createContextMenu(t.textContent);document.body.appendChild(n),n.style.top=`${e.clientY}px`,n.style.left=`${e.clientX}px`;const o=()=>{document.body.removeChild(n),document.removeEventListener("click",o)};document.addEventListener("click",o)}createContextMenu(e){const t=document.createElement("ul");t.classList.add("context-menu");const n=document.createElement("li");return n.textContent="Checkout to your home directory",n.addEventListener("click",(t=>{console.log("clicked:",e),async function(e="",t={},n={}){const o=c.ServerConnection.makeSettings();let r=i.URLExt.join(o.baseUrl,"jupS3",e);const s=new URLSearchParams(n).toString();let a;s&&(r+=`?${s}`);try{a=await c.ServerConnection.makeRequest(r,t,o)}catch(e){throw new c.ServerConnection.NetworkError(e)}let l=await a.text();if(l.length>0)try{l=JSON.parse(l)}catch(e){console.log("Not a JSON response body.",a)}if(!a.ok)throw new c.ServerConnection.ResponseError(a,l.message||l);return l}("create-or-append-to-file",{},{file:e||""}).then((e=>{console.log(e)})).catch((e=>{console.error(`The jupS3 server extension appears to be missing.\n${e}`)}))})),t.appendChild(n),t}}const h=l}}]);