mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
User_wikis: Add edit capability
This commit is contained in:
parent
169f972019
commit
e10aace5f9
@ -38,9 +38,11 @@ public class Gfo_qarg_mgr {
|
||||
}
|
||||
public String Read_str_or_fail(String key) {String rv = Read_str_or_null(Bry_.new_u8(key)); if (rv == null) Fail_when_missing(key); return rv;}
|
||||
public String Read_str_or_null(String key) {return Read_str_or_null(Bry_.new_u8(key));}
|
||||
public String Read_str_or_null(byte[] key) {
|
||||
public String Read_str_or_null(byte[] key) {return Read_str_or(key, null);}
|
||||
public String Read_str_or(String key, String or) {return Read_str_or(Bry_.new_u8(key), or);}
|
||||
public String Read_str_or(byte[] key, String or) {
|
||||
Gfo_qarg_itm arg = (Gfo_qarg_itm)hash.Get_by_bry(key);
|
||||
return arg == null ? null : String_.new_u8(arg.Val_bry());
|
||||
return arg == null ? or : String_.new_u8(arg.Val_bry());
|
||||
}
|
||||
public int Read_int_or(String key, int or) {return Read_int_or(Bry_.new_u8(key), or);}
|
||||
public int Read_int_or(byte[] key, int or) {
|
||||
|
@ -47,7 +47,6 @@ public class Xou_regy_addon implements Xoax_addon_itm, Xoax_addon_itm__special,
|
||||
if (!conn.Meta_tbl_exists(Xou_wiki_tbl.Tbl_name_dflt)) return;
|
||||
|
||||
// register
|
||||
// Xou_regy_addon addon = new Xou_regy_addon();
|
||||
Xouw_db_mgr db_mgr = new Xouw_db_mgr(conn);
|
||||
Xou_wiki_itm[] itms = db_mgr.Tbl__wiki().Select_all();
|
||||
int len = itms.length;
|
||||
|
@ -45,6 +45,18 @@ public class Xou_wiki_tbl implements Db_tbl {
|
||||
.Exec_insert()
|
||||
;
|
||||
}
|
||||
public void Upsert(int id, String key, String name, String file) {
|
||||
if (id == -1) {
|
||||
}
|
||||
else {
|
||||
conn.Stmt_update_exclude(tbl_name, flds, fld__wiki_id)
|
||||
.Val_int(fld__wiki_type, 0).Val_str(fld__wiki_domain, key).Val_str(fld__wiki_name, name)
|
||||
.Val_str(fld__wiki_data_date, "").Val_str(fld__wiki_core_url, file).Val_str(fld__wiki_data, "")
|
||||
.Crt_int(fld__wiki_id, id)
|
||||
.Exec_update()
|
||||
;
|
||||
}
|
||||
}
|
||||
public Xou_wiki_itm[] Select_all() {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds).Exec_select__rls_auto();
|
||||
try {
|
||||
@ -56,6 +68,15 @@ public class Xou_wiki_tbl implements Db_tbl {
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public Xou_wiki_itm Select_by_key_or_null(String key) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld__wiki_domain).Clear().Crt_str(fld__wiki_domain, key).Exec_select__rls_auto();
|
||||
try {
|
||||
return rdr.Move_next()
|
||||
? Make(rdr)
|
||||
: null;
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
private Xou_wiki_itm Make(Db_rdr rdr) {
|
||||
return new Xou_wiki_itm(rdr.Read_int(fld__wiki_id), rdr.Read_int(fld__wiki_type)
|
||||
, rdr.Read_str(fld__wiki_domain), rdr.Read_str(fld__wiki_name), Io_url_.new_fil_(rdr.Read_str(fld__wiki_core_url)), rdr.Read_str(fld__wiki_data)
|
||||
|
@ -17,18 +17,23 @@ 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.langs.jsons.*;
|
||||
import gplx.xowa.addons.users.wikis.regys.dbs.*;
|
||||
public class Xouw_itm_bridge implements gplx.xowa.htmls.bridges.Bridge_cmd_itm {
|
||||
public void Init_by_app(Xoa_app app) {}
|
||||
private Xoa_app app;
|
||||
public void Init_by_app(Xoa_app app) {
|
||||
this.app = app;
|
||||
}
|
||||
public String Exec(Json_nde data) {
|
||||
Xouw_db_mgr db_mgr = new Xouw_db_mgr(app.User().User_db_mgr().Conn());
|
||||
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();
|
||||
Json_nde args = data.Get_kv(Msg__args).Val_as_nde();
|
||||
switch (proc_id) {
|
||||
case Proc__save: break;
|
||||
case Proc__save: db_mgr.Tbl__wiki().Upsert(args.Get_as_int("id"), args.Get_as_str("key"), args.Get_as_str("name"), args.Get_as_str("file")); break;
|
||||
default: throw Err_.new_unhandled_default(proc_id);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
private static final byte[] Msg__proc = Bry_.new_a7("proc"); //, Msg__args = Bry_.new_a7("args");
|
||||
private static final byte[] Msg__proc = Bry_.new_a7("proc"), Msg__args = Bry_.new_a7("args");
|
||||
private static final byte Proc__save = 0;
|
||||
private static final Hash_adp_bry proc_hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("save" , Proc__save)
|
||||
|
@ -20,8 +20,8 @@ import gplx.core.ios.*;
|
||||
import gplx.langs.mustaches.*;
|
||||
class Xouw_itm_doc implements Mustache_doc_itm {
|
||||
private final int id;
|
||||
private final byte[] domain, name, file;
|
||||
public Xouw_itm_doc(int id, byte[] domain, byte[] name, byte[] file) {
|
||||
private final String domain, name, file;
|
||||
public Xouw_itm_doc(int id, String domain, String name, String file) {
|
||||
this.id = id;
|
||||
this.domain = domain;
|
||||
this.name = name;
|
||||
@ -29,9 +29,9 @@ class Xouw_itm_doc implements Mustache_doc_itm {
|
||||
}
|
||||
public boolean Mustache__write(String key, Mustache_bfr bfr) {
|
||||
if (String_.Eq(key, "id")) bfr.Add_int(id);
|
||||
else if (String_.Eq(key, "domain")) bfr.Add_bry(domain);
|
||||
else if (String_.Eq(key, "name")) bfr.Add_bry(name);
|
||||
else if (String_.Eq(key, "file")) bfr.Add_bry(file);
|
||||
else if (String_.Eq(key, "domain")) bfr.Add_str_u8(domain);
|
||||
else if (String_.Eq(key, "name")) bfr.Add_str_u8(name);
|
||||
else if (String_.Eq(key, "file")) bfr.Add_str_u8(file);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
@ -17,13 +17,21 @@ 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.xowa.specials.*; import gplx.langs.mustaches.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.tags.*;
|
||||
import gplx.dbs.*; import gplx.xowa.addons.users.wikis.regys.dbs.*;
|
||||
class Xouw_itm_html extends Xow_special_wtr__base {
|
||||
public Xouw_itm_html() {
|
||||
private final String key;
|
||||
public Xouw_itm_html(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
@Override protected Io_url Get_addon_dir(Xoa_app app) {return app.Fsys_mgr().Http_root().GenSubDir_nest("bin", "any", "xowa", "addon", "user", "wiki", "itm");}
|
||||
@Override protected Io_url Get_mustache_fil(Io_url addon_dir) {return addon_dir.GenSubFil_nest("bin", "xouw_itm.mustache.html");}
|
||||
@Override protected Mustache_doc_itm Bld_mustache_root(Xoa_app app) {
|
||||
return new Xouw_itm_doc(1, Bry_.new_a7("domain"), Bry_.new_a7("name"), Bry_.new_a7("file"));
|
||||
Db_conn conn = app.User().User_db_mgr().Conn();
|
||||
Xouw_db_mgr db_mgr = new Xouw_db_mgr(conn);
|
||||
Xou_wiki_itm itm = db_mgr.Tbl__wiki().Select_by_key_or_null(key);
|
||||
if (itm == null)
|
||||
itm = new Xou_wiki_itm(-1, 0, "", "", Io_url_.Empty, "");
|
||||
return new Xouw_itm_doc(itm.Id(), itm.Domain(), itm.Name(), itm.Url().Xto_api());
|
||||
}
|
||||
@Override protected void Bld_tags(Xoa_app app, Io_url addon_dir, Xopage_html_data page_data) {
|
||||
Xopg_tag_mgr head_tags = page_data.Head_tags();
|
||||
|
@ -19,9 +19,11 @@ package gplx.xowa.addons.users.wikis.regys.specials.itms; import gplx.*; import
|
||||
import gplx.xowa.specials.*; import gplx.core.net.qargs.*;
|
||||
public class Xouw_itm_special implements Xow_special_page {
|
||||
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
// Gfo_qarg_mgr url_args = new Gfo_qarg_mgr().Init(url.Qargs_ary());
|
||||
Gfo_qarg_mgr url_args = new Gfo_qarg_mgr().Init(url.Qargs_ary());
|
||||
|
||||
String key = url_args.Read_str_or("key", "");
|
||||
|
||||
new Xouw_itm_html().Bld_page_by_mustache(wiki.App(), page, this);
|
||||
new Xouw_itm_html(key).Bld_page_by_mustache(wiki.App(), page, this);
|
||||
}
|
||||
Xouw_itm_special(Xow_special_meta special__meta) {this.special__meta = special__meta;}
|
||||
public Xow_special_meta Special__meta() {return special__meta;} private final Xow_special_meta special__meta;
|
||||
|
Loading…
Reference in New Issue
Block a user