1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

DownloadCentral: Cleanup filter_by_lang

This commit is contained in:
gnosygnu
2016-10-21 10:00:14 -04:00
parent 55ea1fa39a
commit bd6576b716
10 changed files with 133 additions and 41 deletions

View File

@@ -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.bldrs.centrals; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import gplx.xowa.addons.bldrs.centrals.tasks.*;
import gplx.xowa.wikis.domains.*;
import gplx.xowa.langs.*;
public class Xobc_filter_mgr {
public static Xobc_task_itm[] Filter_by_lang(Xobc_task_regy__base task_list, String lang_key_str) {
List_adp tmp = List_adp_.New();
// loop tasks and find matches
int len = task_list.Len();
for (int i = 0; i < len; ++i) {
Xobc_task_itm task = (Xobc_task_itm)task_list.Get_at(i);
Xobc_task_key task_key_itm = Xobc_task_key.To_itm(task.Task_key());
if (Xow_domain_itm_.Match_lang(task_key_itm.Wiki_domain_itm(), lang_key_str))
tmp.Add(task);
}
return (Xobc_task_itm[])tmp.To_ary_and_clear(Xobc_task_itm.class);
}
}

View File

@@ -51,21 +51,20 @@ public class Xobc_task_mgr implements Xog_json_wkr {
user_db.Done_task_tbl().Select_all(todo_mgr, done_mgr);
return this;
}
public static final String Lang_key__all = "all";
public void Reload() {
Gfo_log_.Instance.Info("task_mgr.reload.bgn");
Gfobj_nde root = Gfobj_nde.New();
Gfobj_nde lists_nde = root.New_nde("lists");
work_mgr.Save_to(lists_nde.New_ary("work"), Lang_key__all);
todo_mgr.Save_to(lists_nde.New_ary("todo"), Lang_key__all);
done_mgr.Save_to(lists_nde.New_ary("done"), Lang_key__all);
work_mgr.Save_to(lists_nde.New_ary("work"));
todo_mgr.Save_to(lists_nde.New_ary("todo"));
done_mgr.Save_to(lists_nde.New_ary("done"));
cbk_mgr.Send_json(cbk_trg, "xo.bldr.core.reload__recv", root);
}
public void Filter_by_lang(String lang_key) {
Gfo_log_.Instance.Info("task_mgr.reload.bgn");
Gfo_log_.Instance.Info("task_mgr.filter_by_lang.bgn");
Gfobj_nde root = Gfobj_nde.New();
Gfobj_nde lists_nde = root.New_nde("lists").Add_str("list_name", "todo");
todo_mgr.Save_to(lists_nde.New_ary("todo"), lang_key);
todo_mgr.Save_to(lists_nde.New_ary("todo"), Xobc_filter_mgr.Filter_by_lang(todo_mgr, lang_key));
cbk_mgr.Send_json(cbk_trg, "xo.bldr.core.reload_list__recv", root);
}
public void Transfer(Xobc_task_regy__base src, Xobc_task_regy__base trg, Xobc_task_itm task) {

View File

@@ -73,7 +73,7 @@ public class Xobc_task_regy_tbl implements Db_tbl {
String sql = Db_sql_.Make_by_fmt(String_.Ary
( "SELECT *"
, "FROM task_regy"
, "WHERE task_key LIKE '{0}%'"
, "WHERE task_key LIKE '{0}%'" // DEPENDENCY:Xobc_task_key
, "AND task_seqn != 999999"
), wiki_domain);
List_adp list = List_adp_.New();

View File

@@ -0,0 +1,46 @@
/*
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.bldrs.centrals.tasks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.xowa.wikis.domains.*;
public class Xobc_task_key {
public Xobc_task_key(String wiki_domain, String wiki_date, String task_type) {
this.wiki_domain = wiki_domain;
this.wiki_date = wiki_date;
this.task_type = task_type;
}
public String Wiki_domain() {return wiki_domain;} private final String wiki_domain;
public String Wiki_date() {return wiki_date;} private final String wiki_date;
public String Wiki_date_ui() {return String_.Replace(wiki_date, ".", "-");}
public String Task_type() {return task_type;} private final String task_type;
public String Task_type_ui() {
if (String_.Eq(task_type, "html")) return "Articles";
else if (String_.Eq(task_type, "file")) return "Images";
else if (String_.Eq(task_type, "text")) return "Source";
else if (String_.Eq(task_type, "patch")) return "Patch";
else return task_type;
}
public Xow_domain_itm Wiki_domain_itm() {return Xow_domain_itm_.parse(Bry_.new_u8(wiki_domain));}
public static Xobc_task_key To_itm(String task_key) {
String[] ary = String_.Split(task_key, "|");
return new Xobc_task_key(ary[0], ary[1], ary[2]);
}
public static String To_str(String wiki_domain, String wiki_date, String task_type) {
return String_.Concat(wiki_domain, "|", wiki_date, "|", task_type);
}
}

View File

@@ -30,24 +30,13 @@ public abstract class Xobc_task_regy__base {
public void Del_by(int i) {hash.Del(i);}
public void Sort() {hash.Sort();}
public void Save_to(Gfobj_ary ary, String lang_key) {
List_adp list = List_adp_.New();
int len = hash.Len();
for (int i = 0; i < len; ++i) {
Xobc_task_itm sub_task = (Xobc_task_itm)hash.Get_at(i);
if (!String_.Eq(lang_key, Xobc_task_mgr.Lang_key__all)) {
String task_key = sub_task.Task_key();
if (!String_.Has_at_bgn(task_key, lang_key + ".")) continue;
}
list.Add(sub_task);
}
len = list.Len();
public void Save_to(Gfobj_ary ary) {Save_to(ary, (Xobc_task_itm[])hash.To_ary(Xobc_task_itm.class));}
public void Save_to(Gfobj_ary ary, Xobc_task_itm[] itms) {
int len = itms.length;
Gfobj_nde[] sub_ndes = new Gfobj_nde[len];
for (int i = 0; i < len; ++i) {
Gfobj_nde sub_nde = sub_ndes[i] = Gfobj_nde.New();
Xobc_task_itm sub_task = (Xobc_task_itm)list.Get_at(i);
sub_task.Save_to(sub_nde);
itms[i].Save_to(sub_nde);
}
ary.Ary_(sub_ndes);
}