todo-cli
Loading...
Searching...
No Matches
model.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdlib>
4#include <filesystem>
5#include <vector>
6
7#include "task.h"
8#include "types.h"
9
10namespace todo {
11class Model {
12private:
13 const static inline std::filesystem::path TODO_DIR =
14 ".todo";
15 const static inline std::filesystem::path TODO_FILE =
16 "todo_list.json";
17
18public:
19 Model() = default;
20 ~Model() = default;
21
23 void dir_init();
24
28 void add(Task &task, const std::vector<u64> &path);
29
32 void remove(const std::vector<u64> &path);
33
35 void clear();
36
39 void load_file();
40
43 void save_file();
44
49 const std::vector<u64> &path, const std::string &desc
50 );
51
55 void change_task_status(const std::vector<u64> &path, const Status status);
56
60 void change_task_priority(const std::vector<u64> &path, const u16 priority);
61
63 const std::vector<Task> &get_list();
64
67 const Task *get_task(const std::vector<u64> &path);
68
71 const Task *get_parent_task(const std::vector<u64> &path);
72
73private:
74 std::vector<Task> todo_list_;
76
78 void change_child_task_status(Task &task, const Status status);
79};
80} // namespace todo
~Model()=default
const std::vector< Task > & get_list()
Returns a const reference of the todo list vector.
Definition model.cpp:231
void remove(const std::vector< u64 > &path)
Remove task from the todo list.
Definition model.cpp:121
Model()=default
void change_task_priority(const std::vector< u64 > &path, const u16 priority)
Changes the completion status of a task.
Definition model.cpp:217
void change_task_desc(const std::vector< u64 > &path, const std::string &desc)
Changes the completion status of a task.
Definition model.cpp:150
void add(Task &task, const std::vector< u64 > &path)
Adds task with description to todo list.
Definition model.cpp:101
void dir_init()
Sets up the .todo directory and its contents.
Definition model.cpp:38
const Task * get_task(const std::vector< u64 > &path)
Finds task via path.
Definition model.cpp:80
void change_task_status(const std::vector< u64 > &path, const Status status)
Changes the completion status of a task.
Definition model.cpp:188
void clear()
Clears (empties) the list.
Definition model.cpp:145
void save_file()
Save todo list vector to a JSON file.
Definition model.cpp:30
const Task * get_parent_task(const std::vector< u64 > &path)
Finds parent of task via path.
Definition model.cpp:55
void load_file()
Load from a JSON file to populate todo list vector.
Definition model.cpp:12
Definition actions.cpp:3
uint16_t u16
Definition types.h:14
todo::Task::Status Status
Definition types.h:18
Definition task.h:10