mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Cfg: Save items when changed
This commit is contained in:
parent
2cc39bf6bc
commit
d216562fba
@ -21,13 +21,14 @@ import gplx.xowa.addons.apps.cfgs.specials.lists.*; import gplx.xowa.addons.apps
|
||||
public class Xoa_cfg_addon implements Xoax_addon_itm, Xoax_addon_itm__special, Xoax_addon_itm__json {
|
||||
public Xow_special_page[] Special_pages() {
|
||||
return new Xow_special_page[]
|
||||
{ Xocfg_list_special.Prototype
|
||||
, Xocfg_item_special.Prototype
|
||||
{ Xocfg_item_special.Prototype
|
||||
, Xocfg_list_special.Prototype
|
||||
};
|
||||
}
|
||||
public Bridge_cmd_itm[] Json_cmds() {
|
||||
return new Bridge_cmd_itm[]
|
||||
{ Xocfg_item_bridge.Prototype
|
||||
, Xocfg_list_bridge.Prototype
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,11 @@ public class Xocfg_db_mgr {
|
||||
public void Set_str(String ctx, String key, String val) {
|
||||
Xoitm_meta_itm meta_itm = tbl__itm_meta.Select_by_key_or_null(key);
|
||||
if (meta_itm == null) throw Err_.new_wo_type("cfg not defined", "ctx", ctx, "key", key);
|
||||
tbl__itm_data.Update(meta_itm.Id(), ctx, val, Datetime_now.Get().XtoUtc().XtoStr_fmt_iso_8561());
|
||||
tbl__itm_data.Upsert(meta_itm.Id(), ctx, val, Datetime_now.Get().XtoUtc().XtoStr_fmt_iso_8561());
|
||||
}
|
||||
public void Del(String ctx, String key) {
|
||||
Xoitm_meta_itm meta_itm = tbl__itm_meta.Select_by_key_or_null(key);
|
||||
if (meta_itm == null) throw Err_.new_wo_type("cfg not defined", "ctx", ctx, "key", key);
|
||||
tbl__itm_data.Delete(meta_itm.Id(), ctx);
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,11 @@ public class Xoitm_data_tbl implements Db_tbl {
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public void Update(int itm_id, String ctx, String itm_val, String itm_date) {
|
||||
Db_tbl__crud_.Upsert(conn, tbl_name, flds, String_.Ary(fld__itm_id), itm_id, itm_date, itm_val);
|
||||
public void Upsert(int itm_id, String ctx, String itm_val, String itm_date) {
|
||||
Db_tbl__crud_.Upsert(conn, tbl_name, flds, String_.Ary(fld__itm_id), itm_id, ctx, itm_val, itm_date);
|
||||
}
|
||||
public void Delete(int id, String ctx) {
|
||||
conn.Stmt_delete(tbl_name, fld__itm_id, fld__itm_ctx).Crt_int(fld__itm_id, id).Crt_str(fld__itm_ctx, ctx).Exec_delete();
|
||||
}
|
||||
public Xoitm_data_itm Select_by_id_or_null(int id) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld__itm_id).Exec_select__rls_auto();
|
||||
|
@ -38,7 +38,7 @@ public class Xoitm_meta_tbl implements Db_tbl {
|
||||
Db_tbl__crud_.Upsert(conn, tbl_name, flds, String_.Ary(fld__itm_id), itm_id, itm_key, scope_id, gui_type, gui_args, itm_dflt);
|
||||
}
|
||||
public Xoitm_meta_itm Select_by_key_or_null(String key) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld__itm_key).Exec_select__rls_auto();
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld__itm_key).Crt_str(fld__itm_key, key).Exec_select__rls_auto();
|
||||
try {return rdr.Move_next() ? Load(rdr) : null;}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
|
@ -46,7 +46,9 @@ public class Xogui_grp implements Xogui_nde, Mustache_doc_itm {
|
||||
public boolean Mustache__write(String k, Mustache_bfr bfr) {
|
||||
if (String_.Eq(k, "id")) bfr.Add_int(id);
|
||||
else if (String_.Eq(k, "key")) bfr.Add_str_u8(key);
|
||||
else if (String_.Eq(k, "name")) bfr.Add_str_u8_safe(name);
|
||||
else if (String_.Eq(k, "lang")) bfr.Add_str_u8(name);
|
||||
else if (String_.Eq(k, "name")) bfr.Add_str_u8(name);
|
||||
else if (String_.Eq(k, "help")) bfr.Add_str_u8(help);
|
||||
return false;
|
||||
}
|
||||
public Mustache_doc_itm[] Mustache__subs(String key) {
|
||||
|
@ -56,15 +56,24 @@ public class Xogui_itm implements Xogui_nde, Mustache_doc_itm {
|
||||
this.date = date;
|
||||
}
|
||||
public void Set_data_by_dflt() {
|
||||
this.ctx = String_.Empty;
|
||||
this.ctx = Ctx__app;
|
||||
this.val = dflt;
|
||||
this.date = String_.Empty;
|
||||
}
|
||||
public boolean Mustache__write(String k, Mustache_bfr bfr) {
|
||||
if (String_.Eq(k, "name")) bfr.Add_str_u8(name);
|
||||
if (String_.Eq(k, "id")) bfr.Add_int(id);
|
||||
else if (String_.Eq(k, "key")) bfr.Add_str_u8(key);
|
||||
else if (String_.Eq(k, "dflt")) bfr.Add_str_u8(dflt);
|
||||
else if (String_.Eq(k, "lang")) bfr.Add_str_u8(name);
|
||||
else if (String_.Eq(k, "name")) bfr.Add_str_u8(name);
|
||||
else if (String_.Eq(k, "help")) bfr.Add_str_u8(help);
|
||||
else if (String_.Eq(k, "ctx")) bfr.Add_str_u8(ctx);
|
||||
else if (String_.Eq(k, "val")) bfr.Add_str_u8(val);
|
||||
else if (String_.Eq(k, "date")) bfr.Add_str_u8(date);
|
||||
else if (String_.Eq(k, "html")) new Xogui_itm_html().Build_html(bfr.Bfr(), key, name, gui_type, gui_args, val);
|
||||
return true;
|
||||
}
|
||||
public static String Ctx__app = "app";
|
||||
public Mustache_doc_itm[] Mustache__subs(String key) {
|
||||
return Mustache_doc_itm_.Ary__empty;
|
||||
}
|
||||
|
@ -21,26 +21,26 @@ public class Xogui_itm_html {
|
||||
public void Build_html(Bry_bfr bfr, String key, String name, int gui_type, String gui_args, String data) {
|
||||
switch (gui_type) {
|
||||
case Xoitm_gui_tid.Tid__checkbox:
|
||||
bfr.Add_str_u8_fmt("<input id='{0}' data-xocfg='0' type='checkbox' class='xocfg_checkbox'{1}></input>", key, String_.Eq(data, "true") ? " checked='checked'" : "");
|
||||
bfr.Add_str_u8_fmt("<input id='{0}' data-xocfg='0' type='checkbox' accesskey='d' class='xocfg_checkbox'{1}></input>", key, String_.Eq(data, "true") ? " checked='checked'" : "");
|
||||
break;
|
||||
case Xoitm_gui_tid.Tid__numeric:
|
||||
bfr.Add_str_u8_fmt("<input id='{0}' data-xocfg='0' type='text' class='xocfg_numeric' value='{1}'></input>", key, data);
|
||||
bfr.Add_str_u8_fmt("<input id='{0}' data-xocfg='0' type='text' accesskey='d' class='xocfg_numeric' value='{1}'></input>", key, data);
|
||||
break;
|
||||
case Xoitm_gui_tid.Tid__textbox:
|
||||
bfr.Add_str_u8_fmt("<input id='{0}' data-xocfg='0' type='text' class='xocfg_textbox' value='{1}'></input>", key, data);
|
||||
bfr.Add_str_u8_fmt("<input id='{0}' data-xocfg='0' type='text' accesskey='d' class='xocfg_textbox' value='{1}'></input>", key, data);
|
||||
break;
|
||||
case Xoitm_gui_tid.Tid__memo:
|
||||
bfr.Add_str_u8_fmt("<textarea id='{0}' data-xocfg='0' type='text' class='xocfg_memo'>{1}</textarea>", key, data);
|
||||
bfr.Add_str_u8_fmt("<textarea id='{0}' data-xocfg='0' type='text' accesskey='d' class='xocfg_memo'>{1}</textarea>", key, data);
|
||||
break;
|
||||
case Xoitm_gui_tid.Tid__select:
|
||||
bfr.Add_str_u8_fmt("<select id='{0}' data-xocfg='0' type='text' class='xocfg_select' size='3'>", key);
|
||||
bfr.Add_str_u8_fmt("<select id='{0}' data-xocfg='0' type='text' accesskey='d' class='xocfg_select' size='3'>", key);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
bfr.Add_str_u8_fmt("<option value='{0}'{2}>{1}</option>", i, i, i == 2 ? " selected='selected'" : "");
|
||||
}
|
||||
bfr.Add_str_u8_fmt("</select>");
|
||||
break;
|
||||
case Xoitm_gui_tid.Tid__fs_file:
|
||||
bfr.Add_str_u8_fmt("<input id='{0}' data-xocfg='0' type='text' class='xocfg_fs_file' value='{1}'></input>", key, data);
|
||||
bfr.Add_str_u8_fmt("<input id='{0}' data-xocfg='0' type='text' accesskey='d' class='xocfg_fs_file' value='{1}'></input>", key, data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -16,16 +16,16 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.items; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*;
|
||||
import gplx.dbs.sys.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Xocfg_item_bridge implements gplx.xowa.htmls.bridges.Bridge_cmd_itm {
|
||||
import gplx.xowa.htmls.bridges.*;
|
||||
public class Xocfg_item_bridge implements Bridge_cmd_itm {
|
||||
private Xoa_app app;
|
||||
public void Init_by_app(Xoa_app app) {
|
||||
this.app = app;
|
||||
}
|
||||
public String Exec(Json_nde data) {
|
||||
byte proc_id = proc_hash.Get_as_byte_or(data.Get_as_bry_or(Msg__proc, null), Byte_ascii.Max_7_bit);
|
||||
Json_nde args = data.Get_kv(Msg__args).Val_as_nde();
|
||||
byte proc_id = proc_hash.Get_as_byte_or(data.Get_as_bry_or(Bridge_cmd_mgr.Msg__proc, null), Byte_ascii.Max_7_bit);
|
||||
Json_nde args = data.Get_kv(Bridge_cmd_mgr.Msg__args).Val_as_nde();
|
||||
switch (proc_id) {
|
||||
case Proc__upsert: Save(args); break;
|
||||
default: throw Err_.new_unhandled_default(proc_id);
|
||||
@ -48,7 +48,6 @@ public class Xocfg_item_bridge implements gplx.xowa.htmls.bridges.Bridge_cmd_itm
|
||||
}
|
||||
}
|
||||
|
||||
private static final byte[] Msg__proc = Bry_.new_a7("proc"), Msg__args = Bry_.new_a7("args");
|
||||
private static final byte Proc__upsert = 0;
|
||||
private static final Hash_adp_bry proc_hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("upsert" , Proc__upsert)
|
||||
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.lists; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.htmls.bridges.*;
|
||||
public class Xocfg_list_bridge implements Bridge_cmd_itm {
|
||||
private Xoa_app app;
|
||||
private Xocfg_list_bridge_mgr mgr;
|
||||
public void Init_by_app(Xoa_app app) {
|
||||
this.app = app;
|
||||
}
|
||||
public String Exec(Json_nde data) {
|
||||
if (mgr == null) this.mgr = new Xocfg_list_bridge_mgr(app);
|
||||
byte proc_id = proc_hash.Get_as_byte_or(data.Get_as_bry_or(Bridge_cmd_mgr.Msg__proc, null), Byte_ascii.Max_7_bit);
|
||||
Json_nde args = data.Get_kv(Bridge_cmd_mgr.Msg__args).Val_as_nde();
|
||||
switch (proc_id) {
|
||||
case Proc__save: mgr.Save(args); break;
|
||||
case Proc__revert: mgr.Revert(args); break;
|
||||
default: throw Err_.new_unhandled_default(proc_id);
|
||||
}
|
||||
return Bridge_cmd_mgr.Msg__ok;
|
||||
}
|
||||
|
||||
private static final byte Proc__save = 0, Proc__revert = 1;
|
||||
private static final Hash_adp_bry proc_hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("save" , Proc__save)
|
||||
.Add_str_byte("revert" , Proc__revert)
|
||||
;
|
||||
|
||||
public byte[] Key() {return BRIDGE_KEY;} public static final byte[] BRIDGE_KEY = Bry_.new_a7("cfg.item.exec");
|
||||
public static final Xocfg_list_bridge Prototype = new Xocfg_list_bridge(); Xocfg_list_bridge() {}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.lists; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.addons.apps.cfgs.dbs.*;
|
||||
public class Xocfg_list_bridge_mgr {
|
||||
private final Xocfg_db_mgr db_mgr;
|
||||
public Xocfg_list_bridge_mgr(Xoa_app app) {
|
||||
this.db_mgr = new Xocfg_db_mgr(app.User().User_db_mgr().Conn());
|
||||
}
|
||||
public void Save(Json_nde args) {
|
||||
String ctx = args.Get_as_str("ctx");
|
||||
String key = args.Get_as_str("key");
|
||||
String val = args.Get_as_str("val");
|
||||
db_mgr.Set_str(ctx, key, val);
|
||||
}
|
||||
public void Revert(Json_nde args) {
|
||||
String ctx = args.Get_as_str("ctx");
|
||||
String key = args.Get_as_str("key");
|
||||
db_mgr.Del(ctx, key);
|
||||
}
|
||||
}
|
@ -17,14 +17,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.htmls.bridges.*;
|
||||
import gplx.xowa.addons.bldrs.centrals.cmds.*;
|
||||
public class Xobc_task_bridge implements gplx.xowa.htmls.bridges.Bridge_cmd_itm {
|
||||
public class Xobc_task_bridge implements Bridge_cmd_itm {
|
||||
private Xoa_app app;
|
||||
public void Init_by_app(Xoa_app app) {this.app = app;}
|
||||
public String Exec(Json_nde data) {
|
||||
Xobc_task_mgr task_mgr = Xobc_task_special.Task_mgr(app);
|
||||
byte proc_id = proc_hash.Get_as_byte_or(data.Get_as_bry_or(Msg__proc, null), Byte_ascii.Max_7_bit);
|
||||
Json_nde args = data.Get_kv(Msg__args).Val_as_nde();
|
||||
byte proc_id = proc_hash.Get_as_byte_or(data.Get_as_bry_or(Bridge_cmd_mgr.Msg__proc, null), Byte_ascii.Max_7_bit);
|
||||
Json_nde args = data.Get_kv(Bridge_cmd_mgr.Msg__args).Val_as_nde();
|
||||
switch (proc_id) {
|
||||
case Proc__reload: task_mgr.Reload(); break;
|
||||
case Proc__add_work: task_mgr.Todo_mgr().Add_work(args.Get_as_int("task_id")); break;
|
||||
@ -39,7 +40,6 @@ public class Xobc_task_bridge implements gplx.xowa.htmls.bridges.Bridge_cmd_itm
|
||||
}
|
||||
return "";
|
||||
}
|
||||
private static final byte[] Msg__proc = Bry_.new_a7("proc"), Msg__args = Bry_.new_a7("args");
|
||||
private static final byte Proc__reload = 0, Proc__add_work = 1, Proc__del_work = 2, Proc__del_done = 3, Proc__run_next = 4, Proc__stop_cur = 5, Proc__redo_cur = 6, Proc__download_db = 7, Proc__filter_todo = 8;
|
||||
private static final Hash_adp_bry proc_hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("reload" , Proc__reload)
|
||||
|
@ -16,17 +16,17 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.users.wikis.regys.specials.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.users.*; import gplx.xowa.addons.users.wikis.*; import gplx.xowa.addons.users.wikis.regys.*; import gplx.xowa.addons.users.wikis.regys.specials.*;
|
||||
import gplx.dbs.sys.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.addons.users.wikis.regys.dbs.*;
|
||||
public class Xouw_itm_bridge implements gplx.xowa.htmls.bridges.Bridge_cmd_itm {
|
||||
import gplx.xowa.htmls.bridges.*;
|
||||
public class Xouw_itm_bridge implements Bridge_cmd_itm {
|
||||
private Xouw_itm_mgr itm_mgr;
|
||||
public void Init_by_app(Xoa_app app) {
|
||||
this.itm_mgr = new Xouw_itm_mgr(app);
|
||||
}
|
||||
public String Exec(Json_nde data) {
|
||||
byte proc_id = proc_hash.Get_as_byte_or(data.Get_as_bry_or(Msg__proc, null), Byte_ascii.Max_7_bit);
|
||||
Json_nde args = data.Get_kv(Msg__args).Val_as_nde();
|
||||
byte proc_id = proc_hash.Get_as_byte_or(data.Get_as_bry_or(Bridge_cmd_mgr.Msg__proc, null), Byte_ascii.Max_7_bit);
|
||||
Json_nde args = data.Get_kv(Bridge_cmd_mgr.Msg__args).Val_as_nde();
|
||||
switch (proc_id) {
|
||||
case Proc__save: itm_mgr.Save(args); break;
|
||||
case Proc__delete: itm_mgr.Delete(args); break;
|
||||
@ -35,7 +35,6 @@ public class Xouw_itm_bridge implements gplx.xowa.htmls.bridges.Bridge_cmd_itm {
|
||||
return "";
|
||||
}
|
||||
|
||||
private static final byte[] Msg__proc = Bry_.new_a7("proc"), Msg__args = Bry_.new_a7("args");
|
||||
private static final byte Proc__save = 0, Proc__delete = 1;
|
||||
private static final Hash_adp_bry proc_hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("save" , Proc__save)
|
||||
|
@ -40,4 +40,6 @@ public class Bridge_cmd_mgr {
|
||||
}
|
||||
}
|
||||
private static final byte[] Key_cmd = Bry_.new_a7("cmd"), Key_data = Bry_.new_a7("data");
|
||||
public static final byte[] Msg__proc = Bry_.new_a7("proc"), Msg__args = Bry_.new_a7("args");
|
||||
public static String Msg__ok = String_.Empty;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user