Skip to content

Commit

Permalink
feat: add archive projects and sections
Browse files Browse the repository at this point in the history
  • Loading branch information
alainm23 committed May 10, 2024
1 parent 8a4cee7 commit 57c3a48
Show file tree
Hide file tree
Showing 41 changed files with 842 additions and 123 deletions.
2 changes: 2 additions & 0 deletions core/Objects/BaseObject.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class Objects.BaseObject : GLib.Object {
public string icon_name { get; set; default = ""; }
public signal void deleted ();
public signal void updated ();
public signal void archived ();
public signal void unarchived ();

public uint update_timeout_id { get; set; default = 0; }

Expand Down
10 changes: 10 additions & 0 deletions core/Objects/Filters/Completed.vala
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,15 @@ public class Objects.Filters.Completed : Objects.BaseObject {
_count = Services.Database.get_default ().get_items_completed ().size;
count_updated ();
});

Services.Database.get_default ().item_archived.connect (() => {
_count = Services.Database.get_default ().get_items_completed ().size;
count_updated ();
});

Services.Database.get_default ().item_unarchived.connect (() => {
_count = Services.Database.get_default ().get_items_completed ().size;
count_updated ();
});
}
}
33 changes: 29 additions & 4 deletions core/Objects/Filters/Labels.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Objects.Filters.Labels : Objects.BaseObject {
public int count {
get {
if (_count == null) {
_count = Services.Database.get_default ().get_labels_collection ().size;
_count = Services.Database.get_default ().get_items_has_labels ().size;
}

return _count;
Expand All @@ -53,17 +53,42 @@ public class Objects.Filters.Labels : Objects.BaseObject {
view_id = FilterType.LABELS.to_string ();

Services.Database.get_default ().label_added.connect (() => {
_count = Services.Database.get_default ().get_labels_collection ().size;
_count = Services.Database.get_default ().get_items_has_labels ().size;
count_updated ();
});

Services.Database.get_default ().label_deleted.connect (() => {
_count = Services.Database.get_default ().get_labels_collection ().size;
_count = Services.Database.get_default ().get_items_has_labels ().size;
count_updated ();
});

Services.Database.get_default ().label_updated.connect (() => {
_count = Services.Database.get_default ().get_labels_collection ().size;
_count = Services.Database.get_default ().get_items_has_labels ().size;
count_updated ();
});

Services.Database.get_default ().item_added.connect (() => {
_count = Services.Database.get_default ().get_items_has_labels ().size;
count_updated ();
});

Services.Database.get_default ().item_deleted.connect (() => {
_count = Services.Database.get_default ().get_items_has_labels ().size;
count_updated ();
});

Services.Database.get_default ().item_archived.connect (() => {
_count = Services.Database.get_default ().get_items_has_labels ().size;
count_updated ();
});

Services.Database.get_default ().item_unarchived.connect ((item) => {
_count = Services.Database.get_default ().get_items_has_labels ().size;
count_updated ();
});

Services.Database.get_default ().item_updated.connect (() => {
_count = Services.Database.get_default ().get_items_has_labels ().size;
count_updated ();
});
}
Expand Down
10 changes: 10 additions & 0 deletions core/Objects/Filters/Pinboard.vala
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,15 @@ public class Objects.Filters.Pinboard : Objects.BaseObject {
_pinboard_count = Services.Database.get_default ().get_items_pinned (false).size;
pinboard_count_updated ();
});

Services.Database.get_default ().item_archived.connect (() => {
_pinboard_count = Services.Database.get_default ().get_items_pinned (false).size;
pinboard_count_updated ();
});

Services.Database.get_default ().item_unarchived.connect (() => {
_pinboard_count = Services.Database.get_default ().get_items_pinned (false).size;
pinboard_count_updated ();
});
}
}
10 changes: 10 additions & 0 deletions core/Objects/Filters/Priority.vala
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,15 @@ public class Objects.Filters.Priority : Objects.BaseObject {
_count = Services.Database.get_default ().get_items_by_priority (priority, false).size;
count_updated ();
});

Services.Database.get_default ().item_archived.connect (() => {
_count = Services.Database.get_default ().get_items_by_priority (priority, false).size;
count_updated ();
});

Services.Database.get_default ().item_unarchived.connect (() => {
_count = Services.Database.get_default ().get_items_by_priority (priority, false).size;
count_updated ();
});
}
}
10 changes: 10 additions & 0 deletions core/Objects/Filters/Scheduled.vala
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,15 @@ public class Objects.Filters.Scheduled : Objects.BaseObject {
_scheduled_count = Services.Database.get_default ().get_items_by_scheduled (false).size;
scheduled_count_updated ();
});

Services.Database.get_default ().item_archived.connect (() => {
_scheduled_count = Services.Database.get_default ().get_items_by_scheduled (false).size;
scheduled_count_updated ();
});

Services.Database.get_default ().item_unarchived.connect (() => {
_scheduled_count = Services.Database.get_default ().get_items_by_scheduled (false).size;
scheduled_count_updated ();
});
}
}
14 changes: 14 additions & 0 deletions core/Objects/Filters/Today.vala
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ public class Objects.Filters.Today : Objects.BaseObject {
today_count_updated ();
});

Services.Database.get_default ().item_archived.connect (() => {
_today_count = Services.Database.get_default ().get_items_by_date (
new GLib.DateTime.now_local (), false).size;
_overdeue_count = Services.Database.get_default ().get_items_by_overdeue_view (false).size;
today_count_updated ();
});

Services.Database.get_default ().item_unarchived.connect (() => {
_today_count = Services.Database.get_default ().get_items_by_date (
new GLib.DateTime.now_local (), false).size;
_overdeue_count = Services.Database.get_default ().get_items_by_overdeue_view (false).size;
today_count_updated ();
});

Services.Database.get_default ().item_updated.connect (() => {
_today_count = Services.Database.get_default ().get_items_by_date (
new GLib.DateTime.now_local (), false).size;
Expand Down
24 changes: 19 additions & 5 deletions core/Objects/Item.vala
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,15 @@ public class Objects.Item : Objects.BaseObject {
}
}

public bool has_parent {
get {
return Services.Database.get_default ().get_item (parent_id) != null;
}
}

public bool has_section {
get {
return section_id != "";
return Services.Database.get_default ().get_section (section_id) != null;
}
}

Expand Down Expand Up @@ -847,6 +853,10 @@ public class Objects.Item : Objects.BaseObject {
return true;
}

public bool has_labels () {
return labels.size > 0;
}

public void add_item_label (Objects.Label label) {
if (labels == null) {
labels = new Gee.ArrayList<Objects.Label> ();
Expand Down Expand Up @@ -1506,11 +1516,15 @@ public class Objects.Item : Objects.BaseObject {
);
}

public bool has_parent () {
if (parent_id != null) {
return Services.Database.get_default ().get_item (parent_id) != null;
public bool was_archived () {
if (has_parent) {
return parent.was_archived ();
}

if (has_section) {
return section.was_archived ();
}

return false;
return project.is_archived;
}
}
54 changes: 52 additions & 2 deletions core/Objects/Project.vala
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ public class Objects.Project : Objects.BaseObject {
}
}

Gee.ArrayList<Objects.Section> _sections_archived;
public Gee.ArrayList<Objects.Section> sections_archived {
get {
_sections_archived = Services.Database.get_default ().get_sections_archived_by_project (this);
return _sections_archived;
}
}

Gee.ArrayList<Objects.Item> _items;
public Gee.ArrayList<Objects.Item> items {
get {
Expand Down Expand Up @@ -274,6 +282,22 @@ public class Objects.Project : Objects.BaseObject {
project_count_updated ();
}
});

Services.Database.get_default ().item_archived.connect ((item) => {
if (item.project_id == id) {
_project_count = update_project_count ();
_percentage = update_percentage ();
project_count_updated ();
}
});

Services.Database.get_default ().item_unarchived.connect ((item) => {
if (item.project_id == id) {
_project_count = update_project_count ();
_percentage = update_percentage ();
project_count_updated ();
}
});
}

public Project.from_json (Json.Node node) {
Expand Down Expand Up @@ -704,7 +728,7 @@ public class Objects.Project : Objects.BaseObject {
private int update_project_count () {
int returned = 0;
foreach (Objects.Item item in Services.Database.get_default ().get_items_by_project (this)) {
if (!item.checked) {
if (!item.checked && !item.was_archived ()) {
returned++;
}
}
Expand All @@ -716,7 +740,7 @@ public class Objects.Project : Objects.BaseObject {
int items_checked = 0;
foreach (Objects.Item item in Services.Database.get_default ().get_items_by_project (this)) {
items_total++;
if (item.checked) {
if (!item.checked && !item.was_archived ()) {
items_checked++;
}
}
Expand Down Expand Up @@ -817,6 +841,32 @@ public class Objects.Project : Objects.BaseObject {
});
}

public void archive_project (Gtk.Window window) {
var dialog = new Adw.MessageDialog (
window,
_("Archive?"),
_("This will archive %s and all its tasks.".printf (name))
);

dialog.add_response ("cancel", _("Cancel"));
dialog.add_response ("archive", _("Archive"));
dialog.close_response = "cancel";
dialog.set_response_appearance ("archive", Adw.ResponseAppearance.DESTRUCTIVE);
dialog.show ();

dialog.response.connect ((response) => {
if (response == "archive") {
is_archived = true;
Services.Database.get_default ().archive_project (this);
}
});
}

public void unarchive_project () {
is_archived = false;
Services.Database.get_default ().archive_project (this);
}

public Objects.Project duplicate () {
var new_project = new Objects.Project ();
new_project.name = name;
Expand Down
61 changes: 61 additions & 0 deletions core/Objects/Section.vala
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,65 @@ public class Objects.Section : Objects.BaseObject {

return new_section;
}

public void delete_section (Gtk.Window window) {
var dialog = new Adw.MessageDialog (
window,
_("Delete Section %s".printf (name)),
_("This can not be undone")
);

dialog.add_response ("cancel", _("Cancel"));
dialog.add_response ("delete", _("Delete"));
dialog.set_response_appearance ("delete", Adw.ResponseAppearance.DESTRUCTIVE);
dialog.show ();

dialog.response.connect ((response) => {
if (response == "delete") {
loading = true;
if (project.backend_type == BackendType.TODOIST) {
Services.Todoist.get_default ().delete.begin (this, (obj, res) => {
Services.Todoist.get_default ().delete.end (res);
Services.Database.get_default ().delete_section (this);
});
} else {
Services.Database.get_default ().delete_section (this);
}
}
});
}

public void archive_section (Gtk.Window window) {
var dialog = new Adw.MessageDialog (
window,
_("Archive?"),
_("This will archive %s and all its tasks.".printf (name))
);

dialog.add_response ("cancel", _("Cancel"));
dialog.add_response ("archive", _("Archive"));
dialog.close_response = "cancel";
dialog.set_response_appearance ("archive", Adw.ResponseAppearance.DESTRUCTIVE);
dialog.show ();

dialog.response.connect ((response) => {
if (response == "archive") {
is_archived = true;
Services.Database.get_default ().archive_section (this);
}
});
}

public void unarchive_section () {
is_archived = false;
Services.Database.get_default ().archive_section (this);
}

public bool was_archived () {
if (project.is_archived) {
return true;
}

return is_archived;
}
}
2 changes: 1 addition & 1 deletion core/QuickAdd.vala
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public class Layouts.QuickAdd : Adw.Bin {
private void _add_item (Objects.Item item) {
add_item_db (item, reminder_button.reminders ());

if (item.has_parent ()) {
if (item.has_parent) {
item.parent.collapsed = true;
}
}
Expand Down
Loading

0 comments on commit 57c3a48

Please sign in to comment.