Skip to content

Commit

Permalink
fix #1353
Browse files Browse the repository at this point in the history
  • Loading branch information
alainm23 committed Jul 4, 2024
1 parent f1f2a2b commit dac7c97
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 61 deletions.
106 changes: 66 additions & 40 deletions core/Enum.vala
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ public enum ProjectViewStyle {
assert_not_reached ();
}
}

public static ProjectViewStyle parse (string value) {
switch (value) {
case "list":
return ProjectViewStyle.LIST;

case "board":
return ProjectViewStyle.BOARD;

default:
assert_not_reached ();
}
}
}

public enum ProjectIconStyle {
Expand All @@ -64,6 +77,19 @@ public enum ProjectIconStyle {
assert_not_reached ();
}
}

public static ProjectIconStyle parse (string value) {
switch (value) {
case "progress":
return ProjectIconStyle.PROGRESS;

case "emoji":
return ProjectIconStyle.EMOJI;

default:
assert_not_reached ();
}
}
}

public enum FilterType {
Expand Down Expand Up @@ -101,20 +127,20 @@ public enum FilterType {

public string get_name () {
switch (this) {
case TODAY:
return _("Today");
case TODAY:
return _("Today");

case INBOX:
return _("Inbox");
case INBOX:
return _("Inbox");

case SCHEDULED:
return _("Scheduled");
case SCHEDULED:
return _("Scheduled");

case PINBOARD:
return _("Pinboard");
case PINBOARD:
return _("Pinboard");

default:
assert_not_reached ();
default:
assert_not_reached ();
}
}
}
Expand All @@ -129,26 +155,26 @@ public enum BackendType {

public string to_string () {
switch (this) {
case ALL:
return "all";
case ALL:
return "all";

case NONE:
return "none";
case NONE:
return "none";

case LOCAL:
return "local";
case LOCAL:
return "local";

case TODOIST:
return "todoist";
case TODOIST:
return "todoist";

case GOOGLE_TASKS:
return "google-tasks";
case GOOGLE_TASKS:
return "google-tasks";

case CALDAV:
return "caldav";
case CALDAV:
return "caldav";

default:
assert_not_reached ();
default:
assert_not_reached ();
}
}
}
Expand Down Expand Up @@ -177,29 +203,29 @@ public enum ObjectType {

public string get_header () {
switch (this) {
case PROJECT:
return _("Projects");
case PROJECT:
return _("Projects");

case SECTION:
return _("Sections");
case SECTION:
return _("Sections");

case ITEM:
return _("Tasks");
case ITEM:
return _("Tasks");

case LABEL:
return _("Labels");
case LABEL:
return _("Labels");

case FILTER:
return _("Filters");
case FILTER:
return _("Filters");

case TASK:
return _("Tasks");
case TASK:
return _("Tasks");

case TASK_LIST:
return _("Lists");
case TASK_LIST:
return _("Lists");

default:
assert_not_reached ();
default:
assert_not_reached ();
}
}
}
Expand Down
28 changes: 26 additions & 2 deletions core/Objects/Item.vala
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public class Objects.Item : Objects.BaseObject {
}
}

public Item.from_import_json (Json.Node node) {
public Item.from_import_json (Json.Node node, Gee.ArrayList<Objects.Label> _labels = new Gee.ArrayList<Objects.Label> ()) {
id = node.get_object ().get_string_member ("id");
content = node.get_object ().get_string_member ("content");
description = node.get_object ().get_string_member ("description");
Expand All @@ -388,7 +388,12 @@ public class Objects.Item : Objects.BaseObject {
due.update_from_json (Services.Database.get_default ().get_due_parameter (node.get_object ().get_string_member ("due")));
collapsed = node.get_object ().get_boolean_member ("collapsed");
pinned = node.get_object ().get_boolean_member ("pinned");
labels = get_labels_from_json (node);

if (_labels.size <= 0) {
labels = get_labels_from_json (node);
} else {
labels = get_labels_from_labels_json (node, _labels);
}
}

public Item.from_caldav_xml (GXml.DomElement element) {
Expand Down Expand Up @@ -599,6 +604,25 @@ public class Objects.Item : Objects.BaseObject {
return return_value;
}

public Gee.ArrayList<Objects.Label> get_labels_from_labels_json (Json.Node node, Gee.ArrayList<Objects.Label> labels_list) {
Gee.ArrayList<Objects.Label> return_value = new Gee.ArrayList<Objects.Label> ();
foreach (unowned Json.Node element in node.get_object ().get_array_member ("labels").get_elements ()) {
Objects.Label label = get_label_by_name (element.get_string (), labels_list);
return_value.add (label);
}
return return_value;
}

private Objects.Label? get_label_by_name (string name, Gee.ArrayList<Objects.Label> labels_list) {
foreach (var label in labels_list) {
if (label.name.down () == name.down ()) {
return label;
}
}

return null;
}

public Gee.HashMap<string, Objects.Label> get_labels_maps_from_json (Json.Node node) {
Gee.HashMap<string, Objects.Label> return_value = new Gee.HashMap<string, Objects.Label> ();
foreach (unowned Json.Node element in node.get_object ().get_array_member ("labels").get_elements ()) {
Expand Down
20 changes: 2 additions & 18 deletions core/Services/Database.vala
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,11 @@ public class Services.Database : GLib.Object {
return_value.is_archived = get_parameter_bool (stmt, 8);
return_value.is_favorite = get_parameter_bool (stmt, 9);
return_value.shared = get_parameter_bool (stmt, 10);
return_value.view_style = get_view_style_by_text (stmt, 11);
return_value.view_style = ProjectViewStyle.parse (stmt.column_text (11));
return_value.sort_order = stmt.column_int (12);
return_value.parent_id = stmt.column_text (13);
return_value.collapsed = get_parameter_bool (stmt, 14);
return_value.icon_style = get_icon_style_by_text (stmt, 15);
return_value.icon_style = ProjectIconStyle.parse (stmt.column_text (15));
return_value.emoji = stmt.column_text (16);
return_value.show_completed = get_parameter_bool (stmt, 17);
return_value.description = stmt.column_text (18);
Expand All @@ -538,22 +538,6 @@ public class Services.Database : GLib.Object {
return return_value;
}

private ProjectViewStyle get_view_style_by_text (Sqlite.Statement stmt, int col) {
if (stmt.column_text (col) == "board") {
return ProjectViewStyle.BOARD;
}

return ProjectViewStyle.LIST;
}

private ProjectIconStyle get_icon_style_by_text (Sqlite.Statement stmt, int col) {
if (stmt.column_text (col) == "emoji") {
return ProjectIconStyle.EMOJI;
}

return ProjectIconStyle.PROGRESS;
}

private BackendType get_backend_type_by_text (Sqlite.Statement stmt, int col) {
if (stmt.column_text (col) == "local") {
return BackendType.LOCAL;
Expand Down
2 changes: 1 addition & 1 deletion src/Objects/Backup.vala
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class Objects.Backup : Object {
items.clear ();
unowned Json.Array _items = node.get_array_member ("items");
foreach (unowned Json.Node item in _items.get_elements ()) {
items.add (new Objects.Item.from_import_json (item));
items.add (new Objects.Item.from_import_json (item, labels));
}
} catch (Error e) {
error = e.message;
Expand Down

0 comments on commit dac7c97

Please sign in to comment.