antosdk-apps/SQLiteDB/build/debug/main.js

1 line
9.6 KiB
JavaScript
Raw Normal View History

var OS;!function(t){let e;!function(e){class i extends e.BaseApplication{constructor(t){super("SQLiteDBBrowser",t)}menu(){return[{text:"__(File)",nodes:[{text:"__(New database)",dataid:"new",shortcut:"A-N"},{text:"__(Open database)",dataid:"open",shortcut:"A-O"}],onchildselect:t=>{switch(t.data.item.data.dataid){case"new":return this.newFile();case"open":return this.openFile()}}}]}list_tables(){this.filehandle.read().then(t=>{const e=[];for(let i in t)e.push({text:i,name:i,handle:t[i]});this.tbl_list.data=e,e.length>0&&(this.tbl_list.selected=e.length-1)})}async openFile(){try{let t;t=this.args&&this.args.length>0?this.args[0].path.asFileHandle():(await this.openDialog("FileDialog",{title:__("Open file"),mimes:this.meta().mimes})).file.path.asFileHandle(),this.filehandle=("sqlite://"+t.genealogy.join("/")).asFileHandle(),await this.filehandle.onready(),this.list_tables()}catch(t){this.error(__("Unable to open database file: {0}",t.toString()),t)}}async newFile(){try{const e=await this.openDialog("FileDialog",{title:__("Save as"),file:"Untitled.db"});var t=e.file.path.asFileHandle();"file"===e.file.type&&(t=t.parent());const i=`${t.path}/${e.name}`.asFileHandle();this.filehandle=("sqlite://"+i.genealogy.join("/")).asFileHandle(),await this.filehandle.onready(),this.list_tables()}catch(t){this.error(__("Unable to init database file: {0}",t.toString()),t)}}main(){this.filehandle=void 0,this.tbl_list=this.find("tbl-list"),this.grid_table=this.find("tb-browser"),this.grid_scheme=this.find("sch-browser"),this.grid_table.resizable=!0,this.grid_scheme.resizable=!0,this.grid_scheme.header=[{text:__("Field name")},{text:__("Field type")}],this.btn_loadmore=this.find("bt-load-next"),this.container=this.find("container"),this.bindKey("ALT-N",()=>this.newFile()),this.bindKey("ALT-O",()=>this.openFile()),this.container.ontabselect=t=>{if(0==this.container.selectedIndex){if(!this.tbl_list.selectedItem)return;const t=this.tbl_list.selectedItem.data.handle.info.schema;if(!t)return;const e=[];for(let i in t.types)e.push([{text:i},{text:t.types[i]}]);this.grid_scheme.rows=e}},this.find("bt-rm-table").onbtclick=async t=>{try{if(!this.filehandle)return this.notify(__("Please open a database file"));if(null==this.tbl_list.selectedItem)return;const t=this.tbl_list.selectedItem.data.name;await this.openDialog("YesNoDialog",{title:__("Confirm delete?"),text:__("Do you realy want to delete table: {0}",t)})&&(await this.filehandle.remove(t),this.list_tables())}catch(t){this.error(__("Unable to execute action table delete: {0}",t.toString()),t)}},this.find("bt-add-table").onbtclick=async t=>{try{if(!this.filehandle)return this.notify(__("Please open a database file"));const t=await this.openDialog(new a,{title:__("Create new table")});this.filehandle.cache=t.schema,await this.filehandle.write(t.name),this.list_tables()}catch(t){this.error(__("Unable to create table: {0}",t.toString()),t)}},this.find("btn-edit-record").onbtclick=async t=>{this.edit_record()},this.find("btn-add-record").onbtclick=async t=>{this.add_record()},this.find("btn-delete-record").onbtclick=async t=>{this.remove_record()},this.btn_loadmore.onbtclick=async t=>{try{await this.load_table()}catch(t){this.error(__("Error reading table: {0}",t.toString()),t)}},this.find("bt-refresh").onbtclick=async t=>{try{this.last_max_id=0;const t=this.tbl_list.selectedItem.data.handle,e=await t.read({fields:["COUNT(*)"]});this.n_records=e[0]["COUNT(*)"],this.grid_table.rows=[],await this.load_table()}catch(t){this.error(__("Error reload table: {0}",t.toString()),t)}},this.tbl_list.onlistselect=async t=>{try{if(!this.tbl_list.selectedItem)return;const t=this.tbl_list.selectedItem.data.handle;await t.onready(),this.last_max_id=0;const e=t.info.schema.fields.map(t=>({text:t}));this.grid_table.header=e,this.grid_table.rows=[];const i=await t.read({fields:["COUNT(*)"]});this.n_records=i[0]["COUNT(*)"],this.btn_loadmore.text="0/"+this.n_records,await this.load_table(),this.container.selectedIndex=1}catch(t){this.error(__("Error reading table: {0}",t.toString()),t)}},this.grid_table.oncelldbclick=asy