mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2024-11-16 02:18:22 +01:00
1 line
5.4 KiB
JavaScript
1 line
5.4 KiB
JavaScript
(function(){var t;t=class extends this.OS.application.BaseApplication{constructor(t){super("Dockman",t)}main(){var t,e,i,s;for(this.setting.hosts||(this.setting.hosts=[]),this.treeview=this.find("obj-view"),this.currenthost=void 0,this.tabbar=this.find("host-tab-bar"),this.tabbar.ontabselect=t=>(this.currenthost=t.data.item.data,this.loadHost()),this.tabbar.ontabclose=t=>{var e,i;return(e=this.setting.hosts.indexOf(t.data.item.data))>=0&&(this.tabbar.selected===e&&(i=e+1,e>=this.setting.hosts.length-1&&(i=e-1),this.tabbar.selected=i),this.setting.hosts.splice(e,1),!0)},this.find("add").onbtclick=t=>this.openDialog("MultiInputDialog",{title:"__(Add new Docker host)",model:{text:"__(Name)",url:"__(Host url)"},allow_empty:!1}).then(t=>this.addTab(t,!0)),this.imglist=this.find("img-list"),this.imglist.onlistselect=t=>{var e;return this.loadContainer(t.data.item.data.text,!1),e={text:t.data.item.data.text,nodes:this.getTreeData(t.data.item.data)},this.treeview.data=e,this.treeview.expandAll()},this.ctnlist=this.find("container-list"),this.ctnlist.onlistselect=t=>{var e;return e={text:t.data.item.data.text,nodes:this.getTreeData(t.data.item.data)},this.treeview.data=e,this.treeview.expandAll(),this.imglist.selected=-1},this.imglist.buttons=[{text:"",iconclass:"fa fa-arrow-down",onbtclick:()=>{var t,e;return t="",(e=this.imglist.selectedItem)&&(t=e.data.text),this.openDialog("PromptDialog",{title:__("Pull image"),label:__("Pull image:"),value:t}).then(t=>{if(""!==t)return this.exec("pull_image",{host:this.currenthost.url,image:t}).then(t=>t.error?this.error(t.error):this.openDialog("TextDialog",{title:__("Command output"),disable:!0,value:atob(t.result)}).then(t=>this.loadHost()))})}},{text:"",iconclass:"fa fa-refresh",onbtclick:()=>this.loadHost()},{text:"",iconclass:"fa fa-minus",onbtclick:()=>{var t;if(t=this.imglist.selectedItem)return this.ask({title:__("Comfirm delete"),text:__("Are you sure?")}).then(e=>{if(e)return this.exec("rm_image",{host:this.currenthost.url,id:t.data.ID}).then(t=>t.error?this.error(t.error):this.openDialog("TextDialog",{title:__("Command output"),disable:!0,value:t.result}).then(t=>this.loadHost()))})}}],this.ctnlist.buttons=[{text:"",iconclass:"fa fa-play",onbtclick:()=>{var t,e;if((e=this.ctnlist.selectedItem)&&e.data&&!(t=e.data).Detail.State.Running)return this.exec("run_container",{host:this.currenthost.url,id:t.ID}).then(e=>e.error?this.error(e.error):(this.notify(__("Container {0} started",t.ID)),this.loadContainer(t.Image,!0)))}},{text:"",iconclass:"fa fa-stop",onbtclick:()=>{var t,e;if((e=this.ctnlist.selectedItem)&&e.data&&(t=e.data).Detail.State.Running)return this.exec("stop_container",{host:this.currenthost.url,id:t.ID}).then(e=>e.error?this.error(e.error):(this.notify(__("Container {0} stopped",t.ID)),this.loadContainer(t.Image,!0)))}},{text:"",iconclass:"fa fa-refresh",onbtclick:()=>{var t,e,i;if(t=this.ctnlist.data[0])e=t.Image;else{if(!(i=this.imglist.selectedItem))return;e=i.data.text}return this.loadContainer(e,!0)}},{text:"",iconclass:"fa fa-plus",onbtclick:()=>{var t;if(this.ctnlist.data[0])t=this.ctnlist.data[0].Image;else{if(!this.imglist.selectedItem)return;t=this.imglist.selectedItem.data.text}return console.log(t),this.openDialog("KeyValueDialog",{title:__("Container parameters"),data:{p:"8080:80",restart:"always",name:"Container_Name",memory:"200m",cpus:"1",hostname:"Container_HostNamed"}}).then(e=>this.exec("create_container",{host:this.currenthost.url,image:t,parameters:e}).then(e=>e.error?this.error(e.error):this.openDialog("TextDialog",{title:__("Command output"),disable:!0,value:e.result}).then(e=>this.loadContainer(t,!0))))}},{text:"",iconclass:"fa fa-minus",onbtclick:()=>{var t,e;if((e=this.ctnlist.selectedItem)&&e.data)return t=e.data,this.ask({title:__("Comfirm delete"),text:__("Are you sure?")}).then(e=>{if(e)return this.exec("rm_container",{host:this.currenthost.url,id:t.ID}).then(e=>e.error?this.error(e.error):(this.notify(__("Container {0} removed",t.ID)),this.loadContainer(t.Image,!0)))})}},{text:"",iconclass:"bi bi-bootstrap-reboot",onbtclick:()=>{var t,e;if((e=this.ctnlist.selectedItem)&&e.data)return t=e.data,this.exec("restart_container",{host:this.currenthost.url,id:t.ID}).then(e=>e.error?this.error(e.error):(this.notify(__("Container {0} restarted",t.ID)),this.loadContainer(t.Image,!0)))}}],t=0,e=(i=this.setting.hosts).length;t<e;t++)s=i[t],this.tabbar.push(s);return this.tabbar.selected=this.setting.hosts.length-1}addTab(t,e){var i;if(i=this.setting.hosts.length,this.setting.hosts.push(t),this.tabbar.push(t),e)return this.tabbar.selected=i}exec(t,e){var i;return i={path:this.path()+"/api.lua",parameters:{action:t,args:e}},this.call(i)}loadHost(){if(this.currenthost)return this.resetView(),this.exec("list_image",{host:this.currenthost.url}).then(t=>t.error?this.notify(t.error):this.imglist.data=t.result).catch(t=>this.error(t.toString(),t))}loadContainer(t,e){return this.exec("list_container",{host:this.currenthost.url,image:t}).then(t=>t.error?this.notify(t.error):(e&&(this.treeview.data={},this.ctnlist.data=[]),this.ctnlist.data=t.result)).catch(t=>this.error(t.toString(),t))}getTreeData(t){var e,i,s;switch(i=[],typeof t){case"object":for(e in t)s=t[e],"selected"!==e&&"domel"!==e&&("object"!=typeof s?i.push({text:`${e}: ${s}`}):i.push({text:e,nodes:this.getTreeData(s)}));return i;default:return[]}}resetView(){return this.imglist.data=[],this.ctnlist.data=[],this.treeview.data={}}},this.OS.register("Dockman",t)}).call(this); |