Skip to content

Commit

Permalink
Anytime filter added
Browse files Browse the repository at this point in the history
  • Loading branch information
alainm23 committed Mar 25, 2024
1 parent 2fd3ecb commit ccae3bb
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 250 deletions.
45 changes: 45 additions & 0 deletions core/Objects/Filters/Anytime.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright © 2023 Alain M. (https://github.com/alainm23/planify)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* Authored by: Alain M. <[email protected]>
*/

public class Objects.Filters.Anytime : Objects.BaseObject {
private static Anytime? _instance;
public static Anytime get_default () {
if (_instance == null) {
_instance = new Anytime ();
}

return _instance;
}

string _view_id;
public string view_id {
get {
_view_id = "anytime-view";
return _view_id;
}
}

construct {
name = _("Anytime");
keywords = "%s;%s".printf (_("anytime"), _("no date"));
icon_name = "grid-large-symbolic";
}
}
2 changes: 1 addition & 1 deletion core/Objects/Filters/Tomorrow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ public class Objects.Filters.Tomorrow : Objects.BaseObject {
keywords = "%s;%s".printf (_("tomorrow"), _("date"));
icon_name = "today-calendar-symbolic";
}
}
}
13 changes: 13 additions & 0 deletions core/Services/Database.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,19 @@ public class Services.Database : GLib.Object {
}
}

public Gee.ArrayList<Objects.Item> get_items_no_date (bool checked = true) {
Gee.ArrayList<Objects.Item> return_value = new Gee.ArrayList<Objects.Item> ();
lock (_items) {
foreach (Objects.Item item in items) {
if (!item.has_due && item.checked == checked) {
return_value.add (item);
}
}

return return_value;
}
}

public Gee.ArrayList<Objects.Item> get_items_by_date_range (GLib.DateTime start_date, GLib.DateTime end_date, bool checked = true) {
Gee.ArrayList<Objects.Item> return_value = new Gee.ArrayList<Objects.Item> ();
lock (_items) {
Expand Down
3 changes: 2 additions & 1 deletion core/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ core_files = files(
'Objects/Filters/Priority.vala',
'Objects/Filters/Completed.vala',
'Objects/Filters/Labels.vala',
'Objects/Filters/Tomorrow.vala'
'Objects/Filters/Tomorrow.vala',
'Objects/Filters/Anytime.vala'
)

core_deps = [
Expand Down
3 changes: 3 additions & 0 deletions data/io.github.alainm23.planify.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<file alias="checkmark-small-symbolic.svg">resources/icons/checkmark-small-symbolic.svg</file>
<file alias="work-week-symbolic.svg">resources/icons/work-week-symbolic.svg</file>
<file alias="permissions-generic-symbolic.svg">resources/icons/permissions-generic-symbolic.svg</file>
<file alias="grid-large-symbolic.svg">resources/icons/grid-large-symbolic.svg</file>
</gresource>

<gresource prefix="/io/github/alainm23/planify/Devel/icons/scalable/actions">
Expand Down Expand Up @@ -129,6 +130,7 @@
<file alias="checkmark-small-symbolic.svg">resources/icons/checkmark-small-symbolic.svg</file>
<file alias="work-week-symbolic.svg">resources/icons/work-week-symbolic.svg</file>
<file alias="permissions-generic-symbolic.svg">resources/icons/permissions-generic-symbolic.svg</file>
<file alias="grid-large-symbolic.svg">resources/icons/grid-large-symbolic.svg</file>
</gresource>

<gresource prefix="/io/github/alainm23/planify/quick-add/icons/scalable/actions">
Expand Down Expand Up @@ -182,5 +184,6 @@
<file alias="checkmark-small-symbolic.svg">resources/icons/checkmark-small-symbolic.svg</file>
<file alias="work-week-symbolic.svg">resources/icons/work-week-symbolic.svg</file>
<file alias="permissions-generic-symbolic.svg">resources/icons/permissions-generic-symbolic.svg</file>
<file alias="grid-large-symbolic.svg">resources/icons/grid-large-symbolic.svg</file>
</gresource>
</gresources>
4 changes: 4 additions & 0 deletions data/resources/icons/grid-large-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion po/POTFILES
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ src/Views/Project/Project.vala
src/Views/Project/List.vala
src/Views/Project/Board.vala
src/Views/Today.vala
src/Views/Pinboard.vala
src/Views/Label/Label.vala
src/Views/Label/Labels.vala
src/Views/Filter.vala
Expand Down
6 changes: 5 additions & 1 deletion src/Dialogs/QuickFind/QuickFind.vala
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ public class Dialogs.QuickFind.QuickFind : Adw.Window {
new Objects.Filters.Priority (Constants.PRIORITY_4),
Objects.Filters.Labels.get_default (),
Objects.Filters.Completed.get_default (),
Objects.Filters.Tomorrow.get_default ()
Objects.Filters.Tomorrow.get_default (),
Objects.Filters.Anytime.get_default ()
};

foreach (Objects.BaseObject object in filters) {
Expand Down Expand Up @@ -246,6 +247,9 @@ public class Dialogs.QuickFind.QuickFind : Adw.Window {
} else if (base_object is Objects.Filters.Tomorrow) {
Objects.Filters.Tomorrow tomorrow = ((Objects.Filters.Tomorrow) base_object);
Services.EventBus.get_default ().pane_selected (PaneType.FILTER, tomorrow.view_id);
} else if (base_object is Objects.Filters.Anytime) {
Objects.Filters.Anytime _object = ((Objects.Filters.Anytime) base_object);
Services.EventBus.get_default ().pane_selected (PaneType.FILTER, _object.view_id);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Dialogs/QuickFind/QuickFindItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public class Dialogs.QuickFind.QuickFindItem : Gtk.ListBoxRow {
} else if (base_object is Objects.Filters.Today || base_object is Objects.Filters.Scheduled ||
base_object is Objects.Filters.Completed || base_object is Objects.Filters.Tomorrow ||
base_object is Objects.Filters.Labels || base_object is Objects.Filters.Scheduled ||
base_object is Objects.Filters.Pinboard) {
base_object is Objects.Filters.Pinboard || base_object is Objects.Filters.Anytime) {
var filter_icon = new Gtk.Image.from_icon_name (base_object.icon_name) {
valign = Gtk.Align.CENTER,
pixel_size = 16
Expand Down
121 changes: 72 additions & 49 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,15 @@ public class MainWindow : Adw.ApplicationWindow {
} else if (id == FilterType.PINBOARD.to_string ()) {
add_pinboard_view ();
} else if (id == FilterType.LABELS.to_string ()) {
add_filters_view ();
add_labels_view ();
} else if (id.has_prefix ("priority")) {
add_priority_view (id);
} else if (id == FilterType.COMPLETED.to_string ()) {
add_completed_view ();
} else if (id == "tomorrow-view") {
add_tomorrow_view ();
} else if (id == "anytime-view") {
add_anytime_view ();
}
} else if (pane_type == PaneType.LABEL) {
add_label_view (id);
Expand Down Expand Up @@ -288,7 +290,15 @@ public class MainWindow : Adw.ApplicationWindow {
}
}

private void add_inbox_view () {
add_project_view (
Services.Database.get_default ().get_project (Services.Settings.get_default ().settings.get_string ("inbox-project-id"))
);
}

public Views.Project add_project_view (Objects.Project project) {
remove_filter_view ();

Views.Project? project_view;
project_view = (Views.Project) views_stack.get_child_by_name (project.view_id);
if (project_view == null) {
Expand All @@ -300,14 +310,9 @@ public class MainWindow : Adw.ApplicationWindow {
return project_view;
}


private void add_inbox_view () {
add_project_view (
Services.Database.get_default ().get_project (Services.Settings.get_default ().settings.get_string ("inbox-project-id"))
);
}

public void add_today_view () {
remove_filter_view ();

Views.Today? today_view;
today_view = (Views.Today) views_stack.get_child_by_name ("today-view");
if (today_view == null) {
Expand All @@ -319,6 +324,8 @@ public class MainWindow : Adw.ApplicationWindow {
}

public void add_scheduled_view () {
remove_filter_view ();

Views.Scheduled.Scheduled? scheduled_view;
scheduled_view = (Views.Scheduled.Scheduled) views_stack.get_child_by_name ("scheduled-view");
if (scheduled_view == null) {
Expand All @@ -329,18 +336,9 @@ public class MainWindow : Adw.ApplicationWindow {
views_stack.set_visible_child_name ("scheduled-view");
}

public void add_pinboard_view () {
Views.Pinboard? pinboard_view;
pinboard_view = (Views.Pinboard) views_stack.get_child_by_name ("pinboard-view");
if (pinboard_view == null) {
pinboard_view = new Views.Pinboard ();
views_stack.add_named (pinboard_view, "pinboard-view");
}

views_stack.set_visible_child_name ("pinboard-view");
}

public void add_filters_view () {
public void add_labels_view () {
remove_filter_view ();

Views.Labels? labels_view;
labels_view = (Views.Labels) views_stack.get_child_by_name ("labels-view");
if (labels_view == null) {
Expand All @@ -351,52 +349,87 @@ public class MainWindow : Adw.ApplicationWindow {
views_stack.set_visible_child_name ("labels-view");
}

private void add_label_view (string id) {
remove_filter_view ();

Views.Label? label_view;
label_view = (Views.Label) views_stack.get_child_by_name ("label-view");
if (label_view == null) {
label_view = new Views.Label ();
views_stack.add_named (label_view, "label-view");
}

label_view.label = Services.Database.get_default ().get_label (id);
views_stack.set_visible_child_name ("label-view");
}


public void add_pinboard_view () {
Views.Filter? filter_view;
filter_view = (Views.Filter) views_stack.get_child_by_name ("filter-view");
if (filter_view == null) {
filter_view = new Views.Filter ();
views_stack.add_named (filter_view, "filter-view");
}

filter_view.filter = Objects.Filters.Pinboard.get_default ();
views_stack.set_visible_child_name ("filter-view");
}

public void add_priority_view (string view_id) {
Views.Filter? filter_view;
filter_view = (Views.Filter) views_stack.get_child_by_name ("priority-view");
filter_view = (Views.Filter) views_stack.get_child_by_name ("filter-view");
if (filter_view == null) {
filter_view = new Views.Filter ();
views_stack.add_named (filter_view, "priority-view");
views_stack.add_named (filter_view, "filter-view");
}

filter_view.filter = Util.get_default ().get_priority_filter (view_id);
views_stack.set_visible_child_name ("priority-view");
views_stack.set_visible_child_name ("filter-view");
}

private void add_completed_view () {
Views.Filter? filter_view;
filter_view = (Views.Filter) views_stack.get_child_by_name ("completed-view");
filter_view = (Views.Filter) views_stack.get_child_by_name ("filter-view");
if (filter_view == null) {
filter_view = new Views.Filter ();
views_stack.add_named (filter_view, "completed-view");
views_stack.add_named (filter_view, "filter-view");
}

filter_view.filter = Objects.Filters.Completed.get_default ();
views_stack.set_visible_child_name ("completed-view");
views_stack.set_visible_child_name ("filter-view");
}

private void add_tomorrow_view () {
Views.Filter? filter_view;
filter_view = (Views.Filter) views_stack.get_child_by_name ("tomorrow-view");
filter_view = (Views.Filter) views_stack.get_child_by_name ("filter-view");
if (filter_view == null) {
filter_view = new Views.Filter ();
views_stack.add_named (filter_view, "tomorrow-view");
views_stack.add_named (filter_view, "filter-view");
}

filter_view.filter = Objects.Filters.Tomorrow.get_default ();
views_stack.set_visible_child_name ("tomorrow-view");
views_stack.set_visible_child_name ("filter-view");
}

private void add_label_view (string id) {
Views.Label? label_view;
label_view = (Views.Label) views_stack.get_child_by_name ("label-view");
if (label_view == null) {
label_view = new Views.Label ();
views_stack.add_named (label_view, "label-view");
private void add_anytime_view () {
Views.Filter? filter_view;
filter_view = (Views.Filter) views_stack.get_child_by_name ("filter-view");
if (filter_view == null) {
filter_view = new Views.Filter ();
views_stack.add_named (filter_view, "filter-view");
}

label_view.label = Services.Database.get_default ().get_label (id);
views_stack.set_visible_child_name ("label-view");
filter_view.filter = Objects.Filters.Anytime.get_default ();
views_stack.set_visible_child_name ("filter-view");
}

private void remove_filter_view () {
Views.Filter? filter_view;
filter_view = (Views.Filter) views_stack.get_child_by_name ("filter-view");
if (filter_view != null) {
views_stack.remove (filter_view);
}
}

public void go_homepage () {
Expand Down Expand Up @@ -431,18 +464,8 @@ public class MainWindow : Adw.ApplicationWindow {
if (scheduled_view != null) {
scheduled_view.prepare_new_item (content);
}
} else if (views_stack.visible_child_name.has_prefix ("pinboard-view")) {
Views.Pinboard? pinboard_view = (Views.Pinboard) views_stack.visible_child;
if (pinboard_view != null) {
pinboard_view.prepare_new_item (content);
}
} else if (views_stack.visible_child_name.has_prefix ("priority-view")) {
Views.Filter? filter_view = (Views.Filter) views_stack.get_child_by_name ("priority-view");
if (filter_view != null) {
filter_view.prepare_new_item (content);
}
} else if (views_stack.visible_child_name.has_prefix ("tomorrow-view")) {
Views.Filter? filter_view = (Views.Filter) views_stack.get_child_by_name ("tomorrow-view");
} else if (views_stack.visible_child_name.has_prefix ("filter-view")) {
Views.Filter? filter_view = (Views.Filter) views_stack.get_child_by_name ("filter-view");
if (filter_view != null) {
filter_view.prepare_new_item (content);
}
Expand Down
Loading

0 comments on commit ccae3bb

Please sign in to comment.