Skip to content

Commit

Permalink
feat #622
Browse files Browse the repository at this point in the history
  • Loading branch information
alainm23 committed Jul 10, 2024
1 parent dac7c97 commit b6bd606
Show file tree
Hide file tree
Showing 11 changed files with 812 additions and 134 deletions.
103 changes: 103 additions & 0 deletions core/Enum.vala
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,106 @@ public enum ItemType {
}
}
}

public enum ObjectEventType {
INSERT,
UPDATE;

public static ObjectEventType parse (string value) {
switch (value) {
case "insert":
return ObjectEventType.INSERT;

case "update":
return ObjectEventType.UPDATE;

default:
assert_not_reached ();
}
}

public string to_string () {
switch (this) {
case INSERT:
return "insert";

case UPDATE:
return "update";

default:
assert_not_reached ();
}
}

public string get_label () {
switch (this) {
case INSERT:
return _("Task Created");

case UPDATE:
return _("Task Updated");

default:
assert_not_reached ();
}
}
}

public enum ObjectEventKeyType {
CONTENT,
DESCRIPTION,
DUE,
PRIORITY,
LABELS,
PINNED;

public static ObjectEventKeyType parse (string value) {
switch (value) {
case "content":
return ObjectEventKeyType.CONTENT;

case "description":
return ObjectEventKeyType.DESCRIPTION;

case "due":
return ObjectEventKeyType.DUE;

case "priority":
return ObjectEventKeyType.PRIORITY;

case "labels":
return ObjectEventKeyType.LABELS;

case "pinned":
return ObjectEventKeyType.PINNED;

default:
assert_not_reached ();
}
}

public string get_label () {
switch (this) {
case ObjectEventKeyType.CONTENT:
return _("Content");

case ObjectEventKeyType.DESCRIPTION:
return _("Description");

case ObjectEventKeyType.DUE:
return _("Scheduled");

case ObjectEventKeyType.PRIORITY:
return _("Priority");

case ObjectEventKeyType.LABELS:
return _("Labels");

case ObjectEventKeyType.PINNED:
return _("Pin");

default:
assert_not_reached ();
}
}
}
142 changes: 76 additions & 66 deletions core/Objects/ObjectEvent.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,89 +21,99 @@

public class Objects.ObjectEvent : GLib.Object {
public int64 id { get; set; default = 0; }
public ObjectEventType event_type { get; set; }
public string event_date { get; set; default = ""; }
public string event_type { get; set; default = ""; }
public string extra_data { get; set; default = ""; }
public string object_id { get; set; default = ""; }
public string object_type { get; set; default = ""; }
public ObjectEventKeyType object_key { get; set; }
public string object_old_value { get; set; default = ""; }
public string object_new_value { get; set; default = ""; }
public string parent_item_id { get; set; default = ""; }
public string parent_project_id { get; set; default = ""; }

public static Objects.ObjectEvent for_add_item (Objects.Item item) {
Objects.ObjectEvent return_value = new Objects.ObjectEvent ();

return_value.event_date = new GLib.DateTime.now_local ().to_string ();
return_value.event_type = "added";
return_value.object_type = "item";
return_value.object_id = item.id;
return_value.parent_project_id = item.project_id;
return_value.extra_data = generate_extradata ("content", item.content, item.project.name, item.project.color);

return return_value;
public string icon_name {
get {
if (event_type == ObjectEventType.INSERT) {
return "plus-large-symbolic";
} else if (event_type == ObjectEventType.UPDATE) {
if (object_key == ObjectEventKeyType.CONTENT) {
return "edit-symbolic";
} else if (object_key == ObjectEventKeyType.DESCRIPTION) {
return "paper-symbolic";
} else if (object_key == ObjectEventKeyType.DUE) {
return "month-symbolic";
} else if (object_key == ObjectEventKeyType.PRIORITY) {
return "flag-outline-thick-symbolic";
} else if (object_key == ObjectEventKeyType.LABELS) {
return "tag-outline-symbolic";
} else if (object_key == ObjectEventKeyType.PINNED) {
return "pin-symbolic";
}
}

return "plus-large-symbolic";
}
}

public static Objects.ObjectEvent for_update_item (Objects.Item item, string key) {
Objects.ObjectEvent return_value = new Objects.ObjectEvent ();

return_value.event_date = new GLib.DateTime.now_local ().to_string ();
return_value.event_type = "updated";
return_value.object_type = "item";
return_value.object_id = item.id;
return_value.parent_project_id = item.project_id;
return_value.extra_data = generate_extradata ("content", item.content, item.project.name, item.project.color);

return return_value;
GLib.DateTime _datetime;
public GLib.DateTime datetime {
get {
_datetime = Utils.Datetime.get_date_from_string (event_date);
return _datetime;
}
}

public static string generate_extradata (string key, string value, string parent_project_name, string parent_project_color) {
var builder = new Json.Builder ();

builder.begin_object ();

builder.set_member_name ("client");
builder.add_string_value ("Planify");

builder.set_member_name (key);
builder.add_string_value (value);

builder.set_member_name ("parent_project_color");
builder.add_string_value (parent_project_color);

builder.set_member_name ("parent_project_name");
builder.add_string_value (parent_project_name);

builder.end_object ();

Json.Generator generator = new Json.Generator ();
Json.Node root = builder.get_root ();
generator.set_root (root);

return generator.to_data (null);
GLib.DateTime _date;
public GLib.DateTime date {
get {
_date = Utils.Datetime.format_date (Utils.Datetime.get_date_from_string (event_date));
return _date;
}
}

public static string _generate_extradata (Objects.Item item, string key) {
var builder = new Json.Builder ();

builder.begin_object ();

builder.set_member_name ("client");
builder.add_string_value ("Planify");
string _time;
public string time {
get {
if (Utils.Datetime.is_clock_format_12h ()) {
_time = datetime.format (Granite.DateTime.get_default_time_format (true));
} else {
_time = datetime.format (Granite.DateTime.get_default_time_format (false));
}

return _time;
}
}

builder.set_member_name ("content");
builder.add_string_value (item.content);
public Objects.DueDate? get_due_value (string value) {
Json.Parser parser = new Json.Parser ();

try {
parser.load_from_data (value, value.length);
} catch (Error e) {
warning (e.message);
return null;
}

builder.set_member_name ("parent_project_color");
builder.add_string_value (item.project.color);
var due = new Objects.DueDate ();
due.update_from_json (parser.get_root ().get_object ());

builder.set_member_name ("parent_project_name");
builder.add_string_value (item.project.name);
return due;
}

builder.end_object ();
public string get_labels_value (string value) {
string return_value = "";
Gee.ArrayList<Objects.Label> labels = Services.Database.get_default ().get_labels_by_item_labels (value);

Json.Generator generator = new Json.Generator ();
Json.Node root = builder.get_root ();
generator.set_root (root);
if (labels.size > 0) {
for (int index = 0; index < labels.size; index++) {
if (index < labels.size - 1) {
return_value += labels[index].name + ", ";
} else {
return_value += labels[index].name;
}
}
}

return generator.to_data (null);
return return_value;
}
}
Loading

0 comments on commit b6bd606

Please sign in to comment.