Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
alainm23 committed May 28, 2024
1 parent 354070f commit fd95dfe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
10 changes: 10 additions & 0 deletions core/Objects/Item.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1535,4 +1535,14 @@ public class Objects.Item : Objects.BaseObject {

return project_id == project.id;
}

public string to_markdown (int level = 0) {
string text = "%*s- %s%s%s\n".printf (level * 2, "", checked ? "[x]" : "[ ]", Utils.Datetime.get_markdown_format_date(this), content);

foreach (Objects.Item item in items) {
text += item.to_markdown (level + 1);
}

return text;
}
}
20 changes: 4 additions & 16 deletions core/Objects/Project.vala
Original file line number Diff line number Diff line change
Expand Up @@ -768,36 +768,24 @@ public class Objects.Project : Objects.BaseObject {

private string to_markdown () {
string text = "";
text += "# %s\n".printf (name);

text += "## %s\n".printf (name);

foreach (Objects.Item item in items) {
text += "- [%s] %s\n".printf (item.checked ? "x" : " ", item.content);
text += item.to_markdown ();
}

foreach (Objects.Section section in sections) {
text += "\n";
text += "## %s\n".printf (section.name);
text += "### %s\n".printf (section.name);

foreach (Objects.Item item in section.items) {
text += "- [%s]%s%s\n".printf (item.checked ? "x" : " ", get_format_date (item), item.content);
foreach (Objects.Item check in item.items) {
text += " - [%s]%s%s\n".printf (check.checked ? "x" : " ", get_format_date (check), check.content);
}
text += item.to_markdown ();
}
}

return text;
}

private string get_format_date (Objects.Item item) {
if (!item.has_due) {
return " ";
}

return " (" + Utils.Datetime.get_relative_date_from_date (item.due.datetime) + ") ";
}

public void delete_project (Gtk.Window window) {
var dialog = new Adw.AlertDialog (
_("Delete Project %s?".printf (name)),
Expand Down
8 changes: 8 additions & 0 deletions core/Util/Datetime.vala
Original file line number Diff line number Diff line change
Expand Up @@ -568,4 +568,12 @@ public class Utils.Datetime {

return result;
}

public static string get_markdown_format_date (Objects.Item item) {
if (!item.has_due) {
return " ";
}

return " (" + get_relative_date_from_date (item.due.datetime) + ") ";
}
}

0 comments on commit fd95dfe

Please sign in to comment.