mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-01 08:53:20 +00:00
Compare commits
2 commits
4bca7fac3e
...
15bd0f58a7
Author | SHA1 | Date | |
---|---|---|---|
15bd0f58a7 | |||
9de3972630 |
31 changed files with 1043 additions and 1407 deletions
|
@ -7,5 +7,7 @@ SeparateDefinitionBlocks: Always
|
|||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortLambdasOnASingleLine: Empty
|
||||
AlignAfterOpenBracket: BlockIndent
|
||||
AlignOperands: AlignAfterOperator
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
|
|
2
external/mirai-core/CMakeLists.txt
vendored
2
external/mirai-core/CMakeLists.txt
vendored
|
@ -8,14 +8,12 @@ set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
|
|||
add_library(mirai-core
|
||||
src/Mirai.cpp
|
||||
src/Task.cpp
|
||||
src/Day.cpp
|
||||
src/Event.cpp
|
||||
src/DateTime.cpp
|
||||
src/EventEmitter.cpp
|
||||
src/Source.cpp
|
||||
src/MarkdownDataProvider.cpp
|
||||
src/MarkdownDataProvider.Parser.cpp
|
||||
src/View.cpp
|
||||
src/utils.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -14,103 +14,83 @@
|
|||
namespace mirai
|
||||
{
|
||||
|
||||
struct DayData {
|
||||
enum task_state { TODO, DONE };
|
||||
|
||||
struct task_data {
|
||||
int id;
|
||||
std::string title;
|
||||
task_state state;
|
||||
std::optional<Date> due_date;
|
||||
};
|
||||
|
||||
struct updatable_task_data {
|
||||
std::optional<std::string> title = std::nullopt;
|
||||
std::optional<task_state> state = std::nullopt;
|
||||
std::optional<std::optional<Date>> due_date = std::nullopt;
|
||||
};
|
||||
|
||||
struct event_data {
|
||||
int id;
|
||||
Date date;
|
||||
std::string title;
|
||||
Time starts_at;
|
||||
Time ends_at;
|
||||
};
|
||||
|
||||
struct UpdatableDayData {
|
||||
struct updatable_event_data {
|
||||
std::optional<Date> date;
|
||||
};
|
||||
|
||||
enum TaskState { TODO, DONE };
|
||||
|
||||
struct TaskData {
|
||||
int id;
|
||||
std::string title;
|
||||
TaskState state;
|
||||
std::optional<int> dayId;
|
||||
std::optional<int> eventId;
|
||||
};
|
||||
|
||||
struct UpdatableTaskData {
|
||||
std::optional<std::string> title = std::nullopt;
|
||||
std::optional<TaskState> state = std::nullopt;
|
||||
std::optional<std::optional<int>> dayId = std::nullopt;
|
||||
std::optional<std::optional<int>> eventId = std::nullopt;
|
||||
};
|
||||
|
||||
struct EventData {
|
||||
int id;
|
||||
int dayId;
|
||||
std::string title;
|
||||
Time startsAt;
|
||||
Time endsAt;
|
||||
};
|
||||
|
||||
struct UpdatableEventData {
|
||||
std::optional<int> dayId;
|
||||
std::optional<std::string> title;
|
||||
std::optional<Time> startsAt;
|
||||
std::optional<Time> endsAt;
|
||||
std::optional<Time> starts_at;
|
||||
std::optional<Time> ends_at;
|
||||
};
|
||||
|
||||
class DataProvider
|
||||
class data_provider
|
||||
{
|
||||
|
||||
public:
|
||||
DataProvider() {};
|
||||
DataProvider(DataProvider &) = delete;
|
||||
DataProvider(DataProvider &&) = delete;
|
||||
data_provider() {};
|
||||
data_provider(data_provider &) = delete;
|
||||
data_provider(data_provider &&) = delete;
|
||||
|
||||
virtual ~DataProvider() = default;
|
||||
virtual ~data_provider() = default;
|
||||
virtual void save() = 0;
|
||||
virtual void load() = 0;
|
||||
|
||||
virtual std::string name() const = 0;
|
||||
|
||||
// Tasks
|
||||
virtual TaskData insertTask(const TaskData &task) = 0;
|
||||
virtual void removeTaskById(int taskId) = 0;
|
||||
virtual std::optional<TaskData> getTaskById(int taskId) = 0;
|
||||
virtual std::vector<TaskData> getTasksByEventId(int eventId) = 0;
|
||||
virtual std::vector<TaskData> getTasksByDayId(int dayId) = 0;
|
||||
virtual std::vector<TaskData> getTasksByDate(Date date) = 0;
|
||||
virtual std::vector<TaskData> getTasksWithoutDate() = 0;
|
||||
virtual std::vector<TaskData> getTasks() = 0;
|
||||
virtual void updateTask(int taskId, UpdatableTaskData updateData) = 0;
|
||||
virtual task_data insert_task(const task_data &task) = 0;
|
||||
virtual void remove_task_by_id(int taskId) = 0;
|
||||
virtual std::optional<task_data> get_task_by_id(int taskId) = 0;
|
||||
virtual std::vector<task_data> get_tasks_by_date(Date date) = 0;
|
||||
virtual std::vector<task_data> get_tasks_without_date() = 0;
|
||||
virtual std::vector<task_data> get_tasks() = 0;
|
||||
virtual void update_task(int taskId, updatable_task_data updateData) = 0;
|
||||
|
||||
// Events
|
||||
virtual EventData insertEvent(const EventData &task) = 0;
|
||||
virtual void removeEventById(int eventId) = 0;
|
||||
virtual std::optional<EventData> getEventById(int eventId) = 0;
|
||||
virtual std::vector<EventData> getEvents() = 0;
|
||||
virtual std::vector<EventData> getEventsByDate(Date date) = 0;
|
||||
virtual void updateEvent(int eventId, UpdatableEventData updateData) = 0;
|
||||
virtual event_data insertEvent(const event_data &task) = 0;
|
||||
virtual void remove_event_by_id(int eventId) = 0;
|
||||
virtual std::optional<event_data> get_event_by_id(int eventId) = 0;
|
||||
virtual std::vector<event_data> get_events() = 0;
|
||||
virtual std::vector<event_data> get_events_by_date(Date date) = 0;
|
||||
virtual void update_event(int eventId, updatable_event_data updateData) = 0;
|
||||
|
||||
// Days
|
||||
virtual DayData insertDay(const DayData &day) = 0;
|
||||
virtual void removeDayById(int dayId) = 0;
|
||||
virtual std::vector<DayData> getDays() = 0;
|
||||
virtual std::optional<DayData> getDayByDate(const Date &date) = 0;
|
||||
virtual void updateDay(int dayId, UpdatableDayData updateData) = 0;
|
||||
const int id = data_provider::generate_next_id();
|
||||
|
||||
const int id = DataProvider::generateNextId();
|
||||
|
||||
void setDirty(bool dirty)
|
||||
void set_dirty(bool dirty)
|
||||
{
|
||||
isDirty_ = dirty;
|
||||
_is_dirty = dirty;
|
||||
};
|
||||
|
||||
bool isDirty() const
|
||||
bool is_dirty() const
|
||||
{
|
||||
return isDirty_;
|
||||
return _is_dirty;
|
||||
};
|
||||
|
||||
private:
|
||||
bool isDirty_ = false;
|
||||
bool _is_dirty = false;
|
||||
|
||||
static int generateNextId()
|
||||
static int generate_next_id()
|
||||
{
|
||||
static int nextId = 0;
|
||||
return nextId++;
|
||||
|
|
38
external/mirai-core/include/mirai-core/Day.h
vendored
38
external/mirai-core/include/mirai-core/Day.h
vendored
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DataProvider.h"
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
class Task;
|
||||
class Event;
|
||||
|
||||
class Day
|
||||
{
|
||||
|
||||
public:
|
||||
Day(DataProvider *data, DayData day) : data_(data), dayData_(day) {};
|
||||
|
||||
Date date() const;
|
||||
std::vector<Task> tasks();
|
||||
std::vector<Event> events();
|
||||
|
||||
void mergeDay(const Day &otherDay);
|
||||
|
||||
int id() const;
|
||||
int sourceId() const;
|
||||
|
||||
private:
|
||||
DayData dayData_;
|
||||
DataProvider *data_;
|
||||
};
|
||||
|
||||
} // namespace mirai
|
24
external/mirai-core/include/mirai-core/Event.h
vendored
24
external/mirai-core/include/mirai-core/Event.h
vendored
|
@ -7,7 +7,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "DataProvider.h"
|
||||
#include "Day.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -20,25 +19,26 @@ class Event
|
|||
{
|
||||
|
||||
public:
|
||||
Event(DataProvider *data, EventData eventData) : data_(data), eventData_(eventData) {};
|
||||
Event(data_provider *provider, event_data data) : _provider(provider), _data(data) {};
|
||||
|
||||
std::string title() const;
|
||||
Time startsAt() const;
|
||||
Time endsAt() const;
|
||||
Date date() const;
|
||||
Time starts_at() const;
|
||||
Time ends_at() const;
|
||||
|
||||
std::vector<Task> queryTasks() const;
|
||||
std::vector<Task> query_tasks() const;
|
||||
|
||||
void setTitle(const std::string &newTitle);
|
||||
void setDay(const Day &day);
|
||||
void setStartTime(const Time &time);
|
||||
void setEndTime(const Time &time);
|
||||
void set_title(const std::string &newTitle);
|
||||
void set_date(const Date &date);
|
||||
void set_start_time(const Time &time);
|
||||
void set_end_time(const Time &time);
|
||||
|
||||
int id() const;
|
||||
int sourceId() const;
|
||||
int source_id() const;
|
||||
|
||||
private:
|
||||
EventData eventData_;
|
||||
DataProvider *data_;
|
||||
event_data _data;
|
||||
data_provider *_provider;
|
||||
};
|
||||
|
||||
} // namespace mirai
|
||||
|
|
|
@ -19,22 +19,21 @@
|
|||
namespace mirai
|
||||
{
|
||||
|
||||
struct MarkdownData {
|
||||
struct markdown_data {
|
||||
std::string name;
|
||||
std::vector<TaskData> tasks;
|
||||
std::vector<DayData> days;
|
||||
std::vector<EventData> events;
|
||||
std::vector<task_data> tasks;
|
||||
std::vector<event_data> events;
|
||||
};
|
||||
|
||||
class MarkdownDataProvider : public DataProvider
|
||||
class markdown_data_provider final : public data_provider
|
||||
{
|
||||
public:
|
||||
MarkdownDataProvider(const std::string &filePath) : filePath_(filePath), DataProvider()
|
||||
markdown_data_provider(const std::string &file_path) : _file_path(file_path), data_provider()
|
||||
{
|
||||
}
|
||||
|
||||
std::string toMarkdown();
|
||||
MarkdownData parseMarkdown(const std::string &content);
|
||||
std::string to_markdown();
|
||||
markdown_data parse_markdown(const std::string &content);
|
||||
|
||||
std::string path() const;
|
||||
|
||||
|
@ -44,35 +43,26 @@ class MarkdownDataProvider : public DataProvider
|
|||
std::string name() const override;
|
||||
|
||||
// Tasks
|
||||
TaskData insertTask(const TaskData &task) override;
|
||||
void removeTaskById(int taskId) override;
|
||||
std::optional<TaskData> getTaskById(int taskId) override;
|
||||
std::vector<TaskData> getTasksByEventId(int eventId) override;
|
||||
std::vector<TaskData> getTasksByDayId(int dayId) override;
|
||||
std::vector<TaskData> getTasksByDate(Date date) override;
|
||||
std::vector<TaskData> getTasksWithoutDate() override;
|
||||
std::vector<TaskData> getTasks() override;
|
||||
void updateTask(int taskId, UpdatableTaskData updateData) override;
|
||||
task_data insert_task(const task_data &task) override;
|
||||
void remove_task_by_id(int taskId) override;
|
||||
std::optional<task_data> get_task_by_id(int taskId) override;
|
||||
std::vector<task_data> get_tasks_by_date(Date date) override;
|
||||
std::vector<task_data> get_tasks_without_date() override;
|
||||
std::vector<task_data> get_tasks() override;
|
||||
void update_task(int taskId, updatable_task_data updateData) override;
|
||||
|
||||
// Events
|
||||
EventData insertEvent(const EventData &task) override;
|
||||
void removeEventById(int eventId) override;
|
||||
std::optional<EventData> getEventById(int eventId) override;
|
||||
std::vector<EventData> getEvents() override;
|
||||
std::vector<EventData> getEventsByDate(Date date) override;
|
||||
void updateEvent(int eventId, UpdatableEventData updateData) override;
|
||||
|
||||
// Days
|
||||
DayData insertDay(const DayData &day) override;
|
||||
void removeDayById(int dayId) override;
|
||||
std::vector<DayData> getDays() override;
|
||||
std::optional<DayData> getDayByDate(const Date &date) override;
|
||||
void updateDay(int dayId, UpdatableDayData updateData) override;
|
||||
event_data insertEvent(const event_data &task) override;
|
||||
void remove_event_by_id(int eventId) override;
|
||||
std::optional<event_data> get_event_by_id(int eventId) override;
|
||||
std::vector<event_data> get_events() override;
|
||||
std::vector<event_data> get_events_by_date(Date date) override;
|
||||
void update_event(int eventId, updatable_event_data updateData) override;
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
std::string filePath_;
|
||||
MarkdownData data;
|
||||
std::string _name;
|
||||
std::string _file_path;
|
||||
markdown_data _data;
|
||||
};
|
||||
|
||||
} // namespace mirai
|
||||
|
|
18
external/mirai-core/include/mirai-core/Mirai.h
vendored
18
external/mirai-core/include/mirai-core/Mirai.h
vendored
|
@ -22,7 +22,7 @@ class Mirai
|
|||
public:
|
||||
Mirai(const std::string &configFilePath);
|
||||
void addSource(
|
||||
const std::string &name, const std::string &type, std::unique_ptr<DataProvider> &&source
|
||||
const std::string &name, const std::string &type, std::unique_ptr<data_provider> &&source
|
||||
);
|
||||
void
|
||||
editSource(int id, const std::string &name, const std::string &color, const std::string &path);
|
||||
|
@ -30,25 +30,25 @@ class Mirai
|
|||
void unloadAllSources();
|
||||
void save();
|
||||
|
||||
std::vector<std::unique_ptr<Source>> &getSources();
|
||||
std::vector<std::unique_ptr<source>> &getSources();
|
||||
const std::vector<std::string> &getTags();
|
||||
|
||||
// Returns a non owning pointer to the requested resource or nullptr if not found.
|
||||
Source *getSourceById(int id);
|
||||
Source *getSourceByName(const std::string &name);
|
||||
source *getSourceById(int id);
|
||||
source *getSourceByName(const std::string &name);
|
||||
|
||||
void onSourceAdded(std::function<void(Source *)> f);
|
||||
void onSourceEdited(std::function<void(Source *)> f);
|
||||
void onSourceAdded(std::function<void(source *)> f);
|
||||
void onSourceEdited(std::function<void(source *)> f);
|
||||
void onSourceDeleted(std::function<void(int)> f);
|
||||
|
||||
private:
|
||||
void loadConfig(const std::string &path);
|
||||
void saveConfig();
|
||||
std::vector<std::unique_ptr<Source>> sources_;
|
||||
std::vector<std::unique_ptr<source>> sources_;
|
||||
std::string configPath_;
|
||||
|
||||
EventEmitter<Source *> sourceAdded;
|
||||
EventEmitter<Source *> sourceEdited;
|
||||
EventEmitter<source *> sourceAdded;
|
||||
EventEmitter<source *> sourceEdited;
|
||||
EventEmitter<int> sourceDeleted;
|
||||
};
|
||||
} // namespace mirai
|
||||
|
|
81
external/mirai-core/include/mirai-core/Source.h
vendored
81
external/mirai-core/include/mirai-core/Source.h
vendored
|
@ -8,7 +8,6 @@
|
|||
|
||||
#include "DataProvider.h"
|
||||
#include "DateTime.h"
|
||||
#include "Day.h"
|
||||
#include "Event.h"
|
||||
#include "Task.h"
|
||||
#include <string>
|
||||
|
@ -17,40 +16,39 @@
|
|||
namespace mirai
|
||||
{
|
||||
|
||||
struct createTaskParams {
|
||||
struct create_task_params {
|
||||
std::string title;
|
||||
std::optional<Event> event;
|
||||
std::optional<Date> date;
|
||||
std::optional<Date> due_date;
|
||||
};
|
||||
|
||||
struct createEventParams {
|
||||
struct create_event_params {
|
||||
std::string title;
|
||||
Date date;
|
||||
Time startsAt;
|
||||
Time endsAt;
|
||||
Time starts_at;
|
||||
Time ends_at;
|
||||
};
|
||||
|
||||
struct SourceConstructor {
|
||||
struct source_constructor {
|
||||
std::string name;
|
||||
std::string color;
|
||||
DataProvider *sourceDataProvider;
|
||||
data_provider *source_data_provider;
|
||||
};
|
||||
|
||||
class Source
|
||||
class source
|
||||
{
|
||||
public:
|
||||
Source(SourceConstructor params)
|
||||
: data(params.sourceDataProvider), name_(params.name), color_(params.color),
|
||||
type_("FileSystemMarkdown")
|
||||
source(source_constructor params)
|
||||
: data(params.source_data_provider), _name(params.name), _color(params.color),
|
||||
_type("FileSystemMarkdown")
|
||||
{
|
||||
}
|
||||
|
||||
Source(Source &) = delete;
|
||||
Source(Source &&) = delete;
|
||||
Source operator=(Source &) = delete;
|
||||
Source operator=(Source &&) = delete;
|
||||
source(source &) = delete;
|
||||
source(source &&) = delete;
|
||||
source operator=(source &) = delete;
|
||||
source operator=(source &&) = delete;
|
||||
|
||||
~Source() = default;
|
||||
~source() = default;
|
||||
|
||||
void init();
|
||||
void save();
|
||||
|
@ -59,44 +57,41 @@ class Source
|
|||
std::string name() const;
|
||||
std::string type() const;
|
||||
std::string color() const;
|
||||
DataProvider *dataProvider();
|
||||
class data_provider *data_provider();
|
||||
|
||||
void setName(const std::string &name);
|
||||
void setColor(const std::string &color);
|
||||
void set_name(const std::string &name);
|
||||
void set_color(const std::string &color);
|
||||
|
||||
void createTask(const createTaskParams &task);
|
||||
void removeTask(const Task &task);
|
||||
std::optional<Task> getTaskById(int taskId);
|
||||
std::vector<Task> getTasksByDate(Date date);
|
||||
std::vector<Task> getUnscheduledTasks();
|
||||
std::vector<Task> getTasks();
|
||||
void create_task(const create_task_params &task);
|
||||
void remove_task(const Task &task);
|
||||
std::optional<Task> get_task_by_id(int taskId);
|
||||
std::vector<Task> get_tasks_by_date(Date date);
|
||||
std::vector<Task> get_unscheduled_tasks();
|
||||
std::vector<Task> get_tasks();
|
||||
|
||||
void createEvent(const createEventParams &eventToCreate);
|
||||
void removeEvent(const Event &event);
|
||||
std::vector<Event> getEvents();
|
||||
std::optional<Event> getEventById(int eventId);
|
||||
std::vector<Event> getEventsByDate(Date date);
|
||||
void create_event(const create_event_params &eventToCreate);
|
||||
void remove_event(const Event &event);
|
||||
std::vector<Event> get_events();
|
||||
std::optional<Event> get_event_by_id(int eventId);
|
||||
std::vector<Event> get_events_by_date(Date date);
|
||||
|
||||
std::vector<Day> getDays();
|
||||
std::optional<Day> getDayByDate(Date date);
|
||||
const int id = source::generate_next_id();
|
||||
|
||||
const int id = Source::generateNextId();
|
||||
|
||||
bool isDirty() const
|
||||
bool is_dirty() const
|
||||
{
|
||||
return data->isDirty();
|
||||
return data->is_dirty();
|
||||
};
|
||||
|
||||
private:
|
||||
static int generateNextId()
|
||||
static int generate_next_id()
|
||||
{
|
||||
static int nextId = 0;
|
||||
return nextId++;
|
||||
}
|
||||
|
||||
std::string name_;
|
||||
std::string type_;
|
||||
std::string color_;
|
||||
DataProvider *data;
|
||||
std::string _name;
|
||||
std::string _type;
|
||||
std::string _color;
|
||||
class data_provider *data;
|
||||
};
|
||||
} // namespace mirai
|
||||
|
|
24
external/mirai-core/include/mirai-core/Task.h
vendored
24
external/mirai-core/include/mirai-core/Task.h
vendored
|
@ -7,7 +7,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "DataProvider.h"
|
||||
#include "DateTime.h"
|
||||
#include "Event.h"
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace mirai
|
||||
|
@ -19,27 +21,25 @@ class Task
|
|||
{
|
||||
|
||||
public:
|
||||
Task(DataProvider *data, TaskData task) : data_(data), task_(task) {};
|
||||
Task(data_provider *data, task_data task) : data_(data), task_(task) {};
|
||||
|
||||
std::string title() const;
|
||||
mirai::TaskState state() const;
|
||||
mirai::task_state state() const;
|
||||
bool checked() const;
|
||||
bool hasEvent() const;
|
||||
bool hasDate() const;
|
||||
bool has_due_date() const;
|
||||
std::optional<Date> due_date() const;
|
||||
|
||||
void setTitle(const std::string &newTitle);
|
||||
void setDay(const Day &day);
|
||||
void setDate(const Date &date);
|
||||
void setEvent(const Event &event);
|
||||
void setChecked(bool checked);
|
||||
void set_title(const std::string &newTitle);
|
||||
void set_date(const Date &date);
|
||||
void set_checked(bool checked);
|
||||
void unschedule();
|
||||
|
||||
int id() const;
|
||||
int sourceId() const;
|
||||
int source_id() const;
|
||||
|
||||
private:
|
||||
TaskData task_;
|
||||
DataProvider *data_;
|
||||
task_data task_;
|
||||
data_provider *data_;
|
||||
};
|
||||
|
||||
} // namespace mirai
|
||||
|
|
58
external/mirai-core/include/mirai-core/View.h
vendored
58
external/mirai-core/include/mirai-core/View.h
vendored
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "Mirai.h"
|
||||
#include "Task.h"
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
struct DateView {
|
||||
std::vector<Task> tasks;
|
||||
std::vector<Event> events;
|
||||
};
|
||||
|
||||
class View
|
||||
{
|
||||
|
||||
public:
|
||||
View(Mirai *mirai);
|
||||
|
||||
void hideCompletedTasks(bool hide);
|
||||
bool shouldHideCompletedTasks() const;
|
||||
|
||||
std::vector<Date> getDates();
|
||||
|
||||
std::vector<Task> getTasksForDate(const Date &date);
|
||||
std::vector<Event> getEventsForDate(const Date &date);
|
||||
std::vector<Task> getUnscheduledTasks();
|
||||
|
||||
void update();
|
||||
|
||||
void removeSources();
|
||||
void addSource(const Source &source);
|
||||
void setSources(const std::vector<Source> &sources);
|
||||
void setAllSources();
|
||||
bool isSourceSelected(const Source &source) const;
|
||||
|
||||
size_t activeSourceCount() const;
|
||||
|
||||
private:
|
||||
Mirai *mirai_;
|
||||
std::vector<int> sourcesIds_;
|
||||
std::vector<Task> unscheduledTasks_;
|
||||
std::map<Date, DateView> dates;
|
||||
|
||||
bool shouldHideCompletedTasks_ = true;
|
||||
};
|
||||
} // namespace mirai
|
|
@ -6,11 +6,14 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "DataProvider.h"
|
||||
#include "DateTime.h"
|
||||
#include <cctype>
|
||||
#include <cpp-utils/string.h>
|
||||
#include <cpp-utils/vector.h>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
@ -45,6 +48,6 @@ template <typename T, typename F> std::vector<T> findAll(std::vector<T> containe
|
|||
return result;
|
||||
}
|
||||
|
||||
int generateUniqueId();
|
||||
int generate_unique_id();
|
||||
|
||||
} // namespace mirai
|
||||
|
|
60
external/mirai-core/src/Day.cpp
vendored
60
external/mirai-core/src/Day.cpp
vendored
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "Day.h"
|
||||
#include "Task.h"
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
int Day::id() const
|
||||
{
|
||||
return dayData_.id;
|
||||
}
|
||||
|
||||
int Day::sourceId() const
|
||||
{
|
||||
return data_->id;
|
||||
}
|
||||
|
||||
Date Day::date() const
|
||||
{
|
||||
return dayData_.date;
|
||||
}
|
||||
|
||||
std::vector<Task> Day::tasks()
|
||||
{
|
||||
auto tasksData = data_->getTasksByDayId(id());
|
||||
std::vector<Task> tasks;
|
||||
std::transform(
|
||||
tasksData.begin(), tasksData.end(), std::back_inserter(tasks),
|
||||
[&](const TaskData &taskData) {
|
||||
return Task{data_, taskData};
|
||||
}
|
||||
);
|
||||
return tasks;
|
||||
}
|
||||
|
||||
std::vector<Event> Day::events()
|
||||
{
|
||||
auto eventsData = data_->getEventsByDate(dayData_.date);
|
||||
std::vector<Event> events;
|
||||
std::transform(
|
||||
eventsData.begin(), eventsData.end(), std::back_inserter(events),
|
||||
[&](const EventData &eventData) {
|
||||
return Event{data_, eventData};
|
||||
}
|
||||
);
|
||||
return events;
|
||||
}
|
||||
|
||||
void Day::mergeDay(const Day &otherDay)
|
||||
{
|
||||
throw std::runtime_error("Not implemented yet");
|
||||
}
|
||||
} // namespace mirai
|
44
external/mirai-core/src/Event.cpp
vendored
44
external/mirai-core/src/Event.cpp
vendored
|
@ -13,59 +13,51 @@ namespace mirai
|
|||
|
||||
int Event::id() const
|
||||
{
|
||||
return eventData_.id;
|
||||
return _data.id;
|
||||
}
|
||||
|
||||
int Event::sourceId() const
|
||||
int Event::source_id() const
|
||||
{
|
||||
return data_->id;
|
||||
return _provider->id;
|
||||
}
|
||||
|
||||
std::string Event::title() const
|
||||
{
|
||||
return eventData_.title;
|
||||
return _data.title;
|
||||
}
|
||||
|
||||
Time Event::startsAt() const
|
||||
Date Event::date() const
|
||||
{
|
||||
return eventData_.startsAt;
|
||||
return _data.date;
|
||||
}
|
||||
|
||||
Time Event::endsAt() const
|
||||
Time Event::starts_at() const
|
||||
{
|
||||
return eventData_.endsAt;
|
||||
return _data.starts_at;
|
||||
}
|
||||
|
||||
std::vector<Task> Event::queryTasks() const
|
||||
Time Event::ends_at() const
|
||||
{
|
||||
auto tasksData = data_->getTasksByEventId(eventData_.id);
|
||||
std::vector<Task> tasks;
|
||||
std::transform(
|
||||
tasksData.begin(), tasksData.end(), std::back_inserter(tasks),
|
||||
[&](const TaskData &taskData) {
|
||||
return Task{data_, taskData};
|
||||
}
|
||||
);
|
||||
return tasks;
|
||||
return _data.ends_at;
|
||||
}
|
||||
|
||||
void Event::setTitle(const std::string &newTitle)
|
||||
void Event::set_title(const std::string &newTitle)
|
||||
{
|
||||
data_->updateEvent(id(), {.title = newTitle});
|
||||
_provider->update_event(id(), {.title = newTitle});
|
||||
}
|
||||
|
||||
void Event::setDay(const Day &day)
|
||||
void Event::set_date(const Date &date)
|
||||
{
|
||||
data_->updateEvent(id(), {.dayId = day.id()});
|
||||
_provider->update_event(id(), {.date = date});
|
||||
}
|
||||
|
||||
void Event::setStartTime(const Time &time)
|
||||
void Event::set_start_time(const Time &time)
|
||||
{
|
||||
data_->updateEvent(id(), {.startsAt = time});
|
||||
_provider->update_event(id(), {.starts_at = time});
|
||||
}
|
||||
|
||||
void Event::setEndTime(const Time &time)
|
||||
void Event::set_end_time(const Time &time)
|
||||
{
|
||||
data_->updateEvent(id(), {.endsAt = time});
|
||||
_provider->update_event(id(), {.ends_at = time});
|
||||
}
|
||||
} // namespace mirai
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "MarkdownDataProvider.h"
|
||||
#include "cpp-utils/debug.h"
|
||||
#include "utils.h"
|
||||
#include <optional>
|
||||
#include <print>
|
||||
#include <regex>
|
||||
|
||||
|
@ -37,16 +38,17 @@ std::string fieldWithSpace(const std::string &field)
|
|||
return (field + " ");
|
||||
}
|
||||
|
||||
TaskData stringToTask(const std::string &str, const std::string &date)
|
||||
task_data stringToTask(const std::string &str, const std::string &date)
|
||||
{
|
||||
std::smatch matches;
|
||||
std::regex regex("- \\[(\\s|X)\\] (([0-9]{2}:[0-9]{2})-([0-9]{2}:[0-9]{2}) > )?(.*?)( -- (.*))?"
|
||||
std::regex regex(
|
||||
"- \\[(\\s|X)\\] (([0-9]{2}:[0-9]{2})-([0-9]{2}:[0-9]{2}) > )?(.*?)( -- (.*))?"
|
||||
);
|
||||
std::regex_match(str, matches, regex);
|
||||
|
||||
std::string text = stringUtils::trim(matches[5]);
|
||||
|
||||
TaskData taskItem{
|
||||
task_data taskItem{
|
||||
.title = text,
|
||||
.state = str.substr(0, 5) == "- [X]" ? DONE : TODO,
|
||||
};
|
||||
|
@ -69,7 +71,7 @@ Time stringToTime(const std::string &str)
|
|||
return time;
|
||||
}
|
||||
|
||||
EventData stringToEvent(const std::string &str, const std::string &dateString)
|
||||
event_data stringToEvent(const std::string &str, const std::string &dateString)
|
||||
{
|
||||
std::smatch matches;
|
||||
std::regex regex("> (([0-9]{2}h[0-9]{2})-([0-9]{2}h[0-9]{2}) )(.*?)( -- (.*))?");
|
||||
|
@ -83,68 +85,86 @@ EventData stringToEvent(const std::string &str, const std::string &dateString)
|
|||
throw std::runtime_error("Malformated date");
|
||||
}
|
||||
|
||||
EventData eventData{
|
||||
event_data eventData{
|
||||
.date = date.value(),
|
||||
.title = text,
|
||||
.startsAt = stringToTime(matches[2]),
|
||||
.endsAt = stringToTime(matches[3]),
|
||||
.starts_at = stringToTime(matches[2]),
|
||||
.ends_at = stringToTime(matches[3]),
|
||||
};
|
||||
return eventData;
|
||||
}
|
||||
|
||||
std::string taskToString(const TaskData &task)
|
||||
std::string taskToString(const task_data &task)
|
||||
{
|
||||
std::string str = task.title;
|
||||
str = (task.state == DONE ? "- [X] " : "- [ ] ") + str;
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string MarkdownDataProvider::toMarkdown()
|
||||
std::string markdown_data_provider::to_markdown()
|
||||
{
|
||||
const std::vector<DayData> days = getDays();
|
||||
std::string result = "# " + name() + "\n\n";
|
||||
std::string currentDate = "";
|
||||
|
||||
for (const auto &day : days) {
|
||||
auto &date = day.date;
|
||||
auto tasks = getTasksByDayId(day.id);
|
||||
auto events = getEventsByDate(date);
|
||||
if (tasks.size() == 0 && events.size() == 0) {
|
||||
continue;
|
||||
int next_task_index = 0;
|
||||
int next_event_index = 0;
|
||||
|
||||
while (next_event_index < _data.events.size() || next_task_index < _data.tasks.size()) {
|
||||
std::optional<Date> current_date = std::nullopt;
|
||||
// First we find the lowest date between the events and the tasks
|
||||
if (_data.events.size() > 0 && next_event_index < _data.events.size()) {
|
||||
current_date = _data.events.at(next_event_index).date;
|
||||
}
|
||||
result +=
|
||||
"## " + std::format("{:02d}-{:02d}-{:02d}", date.year, date.month, date.day) + "\n\n";
|
||||
for (auto event : events) {
|
||||
auto &start = event.startsAt;
|
||||
auto &end = event.endsAt;
|
||||
result += "> " +
|
||||
std::format(
|
||||
"{:02d}h{:02d}-{:02d}h{:02d} {}", start.hour, start.minute, end.hour,
|
||||
end.minute, event.title
|
||||
) +
|
||||
"\n";
|
||||
for (const auto &task : getTasksByEventId(event.id)) {
|
||||
result += taskToString(task) + '\n';
|
||||
if (_data.tasks.size() > 0 && next_task_index < _data.tasks.size()) {
|
||||
auto &task = _data.tasks.at(next_task_index);
|
||||
if (task.due_date.has_value() && task.due_date < current_date.value()) {
|
||||
current_date = _data.tasks.at(next_task_index).due_date;
|
||||
}
|
||||
result += '\n';
|
||||
}
|
||||
for (const auto &task : tasks) {
|
||||
result += taskToString(task) + '\n';
|
||||
|
||||
if (current_date.has_value()) {
|
||||
result += "## "
|
||||
+ std::format(
|
||||
"{:02d}-{:02d}-{:02d}", current_date.value().year,
|
||||
current_date.value().month, current_date.value().day
|
||||
)
|
||||
+ "\n\n";
|
||||
} else {
|
||||
result += "## Unscheduled\n\n";
|
||||
}
|
||||
|
||||
while (next_event_index < _data.events.size()) {
|
||||
auto ¤t_event = _data.events.at(next_event_index);
|
||||
if (current_event.date != current_date) {
|
||||
break;
|
||||
}
|
||||
auto &start = current_event.starts_at;
|
||||
auto &end = current_event.ends_at;
|
||||
result += "> "
|
||||
+ std::format(
|
||||
"{:02d}h{:02d}-{:02d}h{:02d} {}", start.hour, start.minute, end.hour,
|
||||
end.minute, current_event.title
|
||||
)
|
||||
+ "\n";
|
||||
next_event_index++;
|
||||
current_event = _data.events.at(next_event_index);
|
||||
}
|
||||
while (next_task_index < _data.tasks.size()) {
|
||||
auto ¤t_task = _data.tasks.at(next_task_index);
|
||||
if (current_task.due_date != current_date) {
|
||||
break;
|
||||
}
|
||||
taskToString(current_task);
|
||||
next_event_index++;
|
||||
current_task = _data.tasks.at(next_task_index);
|
||||
}
|
||||
result += '\n';
|
||||
}
|
||||
|
||||
auto unscheduledTasks = getTasksWithoutDate();
|
||||
if (unscheduledTasks.size() > 0) {
|
||||
result += "## Unscheduled\n\n";
|
||||
for (const auto &task : unscheduledTasks) {
|
||||
result += taskToString(task) + '\n';
|
||||
}
|
||||
result += '\n';
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
MarkdownData MarkdownDataProvider::parseMarkdown(const std::string &content)
|
||||
markdown_data markdown_data_provider::parse_markdown(const std::string &content)
|
||||
{
|
||||
cpputils::debug::Timer readMdFormatDuration;
|
||||
|
||||
|
@ -156,13 +176,10 @@ MarkdownData MarkdownDataProvider::parseMarkdown(const std::string &content)
|
|||
std::println("Couldn't find the task list name");
|
||||
}
|
||||
|
||||
data.name = line.substr(2);
|
||||
_data.name = line.substr(2);
|
||||
std::string currentDateString = "";
|
||||
|
||||
std::vector<mirai::DayData> daysData;
|
||||
std::vector<mirai::TaskData> unscheduledTasks;
|
||||
std::optional<Date> currentDate = std::nullopt;
|
||||
std::optional<EventData> currentEvent = std::nullopt;
|
||||
std::optional<Date> current_date = std::nullopt;
|
||||
|
||||
cpputils::debug::Timer stringToTaskDuration;
|
||||
stringToTaskDuration.reset();
|
||||
|
@ -171,64 +188,40 @@ MarkdownData MarkdownDataProvider::parseMarkdown(const std::string &content)
|
|||
if (std::string_view{line.data(), 3} == "## ") {
|
||||
currentDateString = line.substr(3);
|
||||
if (currentDateString == "Unscheduled") {
|
||||
currentDate = std::nullopt;
|
||||
current_date = std::nullopt;
|
||||
continue;
|
||||
}
|
||||
currentDate = mirai::stringToDate(currentDateString);
|
||||
if (!currentDate.has_value()) {
|
||||
current_date = mirai::stringToDate(currentDateString);
|
||||
if (!current_date.has_value()) {
|
||||
throw std::runtime_error("Malformated date (1)");
|
||||
}
|
||||
insertDay({.id = generateUniqueId(), .date = currentDate.value()});
|
||||
} else if (line.starts_with("> ")) {
|
||||
auto event = stringToEvent(line, currentDateString);
|
||||
if (currentDate.has_value()) {
|
||||
auto day = getDayByDate(currentDate.value());
|
||||
currentEvent = insertEvent(
|
||||
{.id = generateUniqueId(),
|
||||
.dayId = day->id,
|
||||
if (current_date.has_value()) {
|
||||
insertEvent(
|
||||
{.id = generate_unique_id(),
|
||||
.date = current_date.value(),
|
||||
.title = event.title,
|
||||
.startsAt = event.startsAt,
|
||||
.endsAt = event.endsAt}
|
||||
.starts_at = event.starts_at,
|
||||
.ends_at = event.ends_at}
|
||||
);
|
||||
}
|
||||
} else if (line.starts_with("- [ ]") || line.starts_with("- [X]")) {
|
||||
stringToTaskDuration.start();
|
||||
TaskData taskItemData = stringToTask(line, currentDateString);
|
||||
task_data taskItemData = stringToTask(line, currentDateString);
|
||||
stringToTaskDuration.stop();
|
||||
if (currentEvent.has_value()) {
|
||||
insertTask({
|
||||
.id = generateUniqueId(),
|
||||
.title = taskItemData.title,
|
||||
.state = taskItemData.state,
|
||||
.dayId = std::nullopt,
|
||||
.eventId = currentEvent.value().id,
|
||||
});
|
||||
} else if (currentDate.has_value()) {
|
||||
auto day = getDayByDate(currentDate.value());
|
||||
insertTask({
|
||||
.id = generateUniqueId(),
|
||||
.title = taskItemData.title,
|
||||
.state = taskItemData.state,
|
||||
.dayId = day->id,
|
||||
.eventId = std::nullopt,
|
||||
});
|
||||
} else {
|
||||
insertTask({
|
||||
.id = generateUniqueId(),
|
||||
.title = taskItemData.title,
|
||||
.state = taskItemData.state,
|
||||
.dayId = std::nullopt,
|
||||
.eventId = std::nullopt,
|
||||
});
|
||||
}
|
||||
} else if (cpputils::string::trim(line) == "") {
|
||||
currentEvent = std::nullopt;
|
||||
insert_task(
|
||||
{.id = generate_unique_id(),
|
||||
.title = taskItemData.title,
|
||||
.state = taskItemData.state,
|
||||
.due_date = current_date}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
gelinesDuration.printTimeElapsed("getlinesDuration");
|
||||
stringToTaskDuration.printTimeElapsed("stringToTaskDuration");
|
||||
readMdFormatDuration.printTimeElapsed("Reading MD File duration");
|
||||
return data;
|
||||
return _data;
|
||||
}
|
||||
} // namespace mirai
|
||||
|
|
192
external/mirai-core/src/MarkdownDataProvider.cpp
vendored
192
external/mirai-core/src/MarkdownDataProvider.cpp
vendored
|
@ -18,33 +18,33 @@
|
|||
namespace mirai
|
||||
{
|
||||
|
||||
std::string MarkdownDataProvider::path() const
|
||||
std::string markdown_data_provider::path() const
|
||||
{
|
||||
return filePath_;
|
||||
return _file_path;
|
||||
}
|
||||
|
||||
std::string MarkdownDataProvider::name() const
|
||||
std::string markdown_data_provider::name() const
|
||||
{
|
||||
return data.name;
|
||||
return _data.name;
|
||||
}
|
||||
|
||||
void MarkdownDataProvider::save()
|
||||
void markdown_data_provider::save()
|
||||
{
|
||||
std::ofstream file(filePath_);
|
||||
std::ofstream file(_file_path);
|
||||
if (!file.is_open()) {
|
||||
throw std::runtime_error("can't create " + filePath_);
|
||||
throw std::runtime_error("can't create " + _file_path);
|
||||
}
|
||||
|
||||
const std::string content = toMarkdown();
|
||||
const std::string content = to_markdown();
|
||||
|
||||
file << content;
|
||||
file.close();
|
||||
setDirty(false);
|
||||
set_dirty(false);
|
||||
};
|
||||
|
||||
void MarkdownDataProvider::load()
|
||||
void markdown_data_provider::load()
|
||||
{
|
||||
std::ifstream file(filePath_);
|
||||
std::ifstream file(_file_path);
|
||||
if (!file.is_open()) {
|
||||
return;
|
||||
}
|
||||
|
@ -55,19 +55,19 @@ void MarkdownDataProvider::load()
|
|||
content += line + "\n";
|
||||
}
|
||||
file.close();
|
||||
data = parseMarkdown(content);
|
||||
_data = parse_markdown(content);
|
||||
};
|
||||
|
||||
TaskData MarkdownDataProvider::insertTask(const TaskData &taskData)
|
||||
task_data markdown_data_provider::insert_task(const task_data &taskData)
|
||||
{
|
||||
data.tasks.push_back(taskData);
|
||||
setDirty(true);
|
||||
_data.tasks.push_back(taskData);
|
||||
set_dirty(true);
|
||||
return taskData;
|
||||
}
|
||||
|
||||
void MarkdownDataProvider::updateTask(int taskId, UpdatableTaskData updateData)
|
||||
void markdown_data_provider::update_task(int taskId, updatable_task_data updateData)
|
||||
{
|
||||
auto taskData = ptrFindFirst(data.tasks, [&](const TaskData &task) {
|
||||
auto taskData = ptrFindFirst(_data.tasks, [&](const task_data &task) {
|
||||
return task.id == taskId;
|
||||
});
|
||||
assert(taskData != nullptr); // Shouldn't be possible
|
||||
|
@ -77,180 +77,110 @@ void MarkdownDataProvider::updateTask(int taskId, UpdatableTaskData updateData)
|
|||
if (updateData.state.has_value()) {
|
||||
taskData->state = updateData.state.value();
|
||||
}
|
||||
if (updateData.dayId.has_value()) {
|
||||
taskData->dayId = updateData.dayId.value();
|
||||
if (updateData.due_date.has_value()) {
|
||||
taskData->due_date = updateData.due_date.value();
|
||||
}
|
||||
if (updateData.eventId.has_value()) {
|
||||
taskData->eventId = updateData.eventId.value();
|
||||
}
|
||||
setDirty(true);
|
||||
set_dirty(true);
|
||||
}
|
||||
|
||||
std::optional<TaskData> MarkdownDataProvider::getTaskById(int taskId)
|
||||
std::optional<task_data> markdown_data_provider::get_task_by_id(int taskId)
|
||||
{
|
||||
return findFirst(data.tasks, [&](const TaskData &task) {
|
||||
return findFirst(_data.tasks, [&](const task_data &task) {
|
||||
return task.id == taskId;
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<TaskData> MarkdownDataProvider::getTasksByEventId(int eventId)
|
||||
std::vector<task_data> markdown_data_provider::get_tasks_without_date()
|
||||
{
|
||||
return findAll(data.tasks, [&](const TaskData &task) {
|
||||
return task.eventId == eventId;
|
||||
return findAll(_data.tasks, [](const task_data &t) {
|
||||
return t.due_date == std::nullopt;
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<TaskData> MarkdownDataProvider::getTasksByDayId(int dayId)
|
||||
std::vector<task_data> markdown_data_provider::get_tasks_by_date(Date date)
|
||||
{
|
||||
return findAll(data.tasks, [&](const TaskData &task) {
|
||||
return task.dayId == dayId;
|
||||
return findAll(_data.tasks, [&](const task_data &t) {
|
||||
return t.due_date == date;
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<TaskData> MarkdownDataProvider::getTasksWithoutDate()
|
||||
std::vector<task_data> markdown_data_provider::get_tasks()
|
||||
{
|
||||
return findAll(data.tasks, [](const TaskData &t) {
|
||||
return t.dayId == std::nullopt && t.eventId == std::nullopt;
|
||||
});
|
||||
return _data.tasks;
|
||||
}
|
||||
|
||||
std::vector<TaskData> MarkdownDataProvider::getTasksByDate(Date date)
|
||||
void markdown_data_provider::remove_task_by_id(int taskId)
|
||||
{
|
||||
auto day = getDayByDate(date);
|
||||
if (!day.has_value()) {
|
||||
return {};
|
||||
}
|
||||
return findAll(data.tasks, [&](const TaskData &t) {
|
||||
return t.dayId == day.value().id;
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<TaskData> MarkdownDataProvider::getTasks()
|
||||
{
|
||||
return data.tasks;
|
||||
}
|
||||
|
||||
void MarkdownDataProvider::removeTaskById(int taskId)
|
||||
{
|
||||
data.tasks.erase(
|
||||
_data.tasks.erase(
|
||||
std::remove_if(
|
||||
data.tasks.begin(), data.tasks.end(),
|
||||
[&](const TaskData &task) {
|
||||
_data.tasks.begin(), _data.tasks.end(),
|
||||
[&](const task_data &task) {
|
||||
return task.id == taskId;
|
||||
}
|
||||
),
|
||||
data.tasks.end()
|
||||
_data.tasks.end()
|
||||
);
|
||||
setDirty(true);
|
||||
set_dirty(true);
|
||||
}
|
||||
|
||||
DayData MarkdownDataProvider::insertDay(const DayData &dayData)
|
||||
event_data markdown_data_provider::insertEvent(const event_data &eventData)
|
||||
{
|
||||
data.days.push_back(dayData);
|
||||
setDirty(true);
|
||||
return dayData;
|
||||
}
|
||||
|
||||
void MarkdownDataProvider::updateDay(int dayId, UpdatableDayData updateData)
|
||||
{
|
||||
auto dayData = ptrFindFirst(data.days, [&](const DayData &day) {
|
||||
return day.id == dayId;
|
||||
});
|
||||
assert(dayData != nullptr); // Shouldn't be possible
|
||||
if (updateData.date.has_value()) {
|
||||
dayData->date = updateData.date.value();
|
||||
}
|
||||
setDirty(true);
|
||||
}
|
||||
|
||||
void MarkdownDataProvider::removeDayById(int dayId)
|
||||
{
|
||||
data.days.erase(
|
||||
std::remove_if(
|
||||
data.days.begin(), data.days.end(),
|
||||
[&](const DayData &day) {
|
||||
return day.id == dayId;
|
||||
}
|
||||
),
|
||||
data.days.end()
|
||||
);
|
||||
setDirty(true);
|
||||
}
|
||||
|
||||
std::vector<DayData> MarkdownDataProvider::getDays()
|
||||
{
|
||||
return data.days;
|
||||
}
|
||||
|
||||
std::optional<DayData> MarkdownDataProvider::getDayByDate(const Date &date)
|
||||
{
|
||||
return findFirst(data.days, [&](const DayData &day) {
|
||||
return day.date == date;
|
||||
});
|
||||
}
|
||||
|
||||
EventData MarkdownDataProvider::insertEvent(const EventData &eventData)
|
||||
{
|
||||
data.events.push_back(eventData);
|
||||
setDirty(true);
|
||||
_data.events.push_back(eventData);
|
||||
set_dirty(true);
|
||||
return eventData;
|
||||
}
|
||||
|
||||
void MarkdownDataProvider::updateEvent(int eventId, UpdatableEventData updateData)
|
||||
void markdown_data_provider::update_event(int eventId, updatable_event_data updateData)
|
||||
{
|
||||
auto eventData = ptrFindFirst(data.events, [&](const EventData &event) {
|
||||
auto eventData = ptrFindFirst(_data.events, [&](const event_data &event) {
|
||||
return event.id == eventId;
|
||||
});
|
||||
assert(eventData != nullptr); // Shouldn't be possible
|
||||
if (updateData.title.has_value()) {
|
||||
eventData->title = updateData.title.value();
|
||||
}
|
||||
if (updateData.dayId.has_value()) {
|
||||
eventData->dayId = updateData.dayId.value();
|
||||
if (updateData.date.has_value()) {
|
||||
eventData->date = updateData.date.value();
|
||||
}
|
||||
if (updateData.startsAt.has_value()) {
|
||||
eventData->startsAt = updateData.startsAt.value();
|
||||
if (updateData.starts_at.has_value()) {
|
||||
eventData->starts_at = updateData.starts_at.value();
|
||||
}
|
||||
if (updateData.endsAt.has_value()) {
|
||||
eventData->endsAt = updateData.endsAt.value();
|
||||
if (updateData.ends_at.has_value()) {
|
||||
eventData->ends_at = updateData.ends_at.value();
|
||||
}
|
||||
setDirty(true);
|
||||
set_dirty(true);
|
||||
}
|
||||
|
||||
void MarkdownDataProvider::removeEventById(int eventId)
|
||||
void markdown_data_provider::remove_event_by_id(int eventId)
|
||||
{
|
||||
data.events.erase(
|
||||
_data.events.erase(
|
||||
std::remove_if(
|
||||
data.events.begin(), data.events.end(),
|
||||
[&](const EventData &event) {
|
||||
_data.events.begin(), _data.events.end(),
|
||||
[&](const event_data &event) {
|
||||
return event.id == eventId;
|
||||
}
|
||||
),
|
||||
data.events.end()
|
||||
_data.events.end()
|
||||
);
|
||||
setDirty(true);
|
||||
set_dirty(true);
|
||||
}
|
||||
|
||||
std::optional<EventData> MarkdownDataProvider::getEventById(int eventId)
|
||||
std::optional<event_data> markdown_data_provider::get_event_by_id(int eventId)
|
||||
{
|
||||
return findFirst(data.events, [&](const EventData &event) {
|
||||
return findFirst(_data.events, [&](const event_data &event) {
|
||||
return event.id == eventId;
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<EventData> MarkdownDataProvider::getEventsByDate(Date date)
|
||||
std::vector<event_data> markdown_data_provider::get_events_by_date(Date date)
|
||||
{
|
||||
auto day = getDayByDate(date);
|
||||
if (!day.has_value()) {
|
||||
return {};
|
||||
}
|
||||
return findAll(data.events, [&](const EventData &event) {
|
||||
return event.dayId == day.value().id;
|
||||
return findAll(_data.events, [&](const event_data &event) {
|
||||
return event.date == date;
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<EventData> MarkdownDataProvider::getEvents()
|
||||
std::vector<event_data> markdown_data_provider::get_events()
|
||||
{
|
||||
return data.events;
|
||||
return _data.events;
|
||||
}
|
||||
} // namespace mirai
|
||||
|
|
57
external/mirai-core/src/Mirai.cpp
vendored
57
external/mirai-core/src/Mirai.cpp
vendored
|
@ -43,12 +43,12 @@ void Mirai::loadConfig(const std::string &path)
|
|||
const auto name = filePath.asObject().getString("name");
|
||||
const auto color = filePath.asObject().getString("color");
|
||||
const auto path = filePath.asObject().getString("path");
|
||||
std::unique_ptr<DataProvider> file = std::make_unique<MarkdownDataProvider>(path);
|
||||
DataProvider *sourceDataProvider = file.release();
|
||||
std::unique_ptr<data_provider> file = std::make_unique<markdown_data_provider>(path);
|
||||
data_provider *sourceDataProvider = file.release();
|
||||
sourceDataProvider->load();
|
||||
sources_.push_back(
|
||||
std::make_unique<Source>(SourceConstructor{
|
||||
.name = name, .color = color, .sourceDataProvider = sourceDataProvider
|
||||
std::make_unique<source>(source_constructor{
|
||||
.name = name, .color = color, .source_data_provider = sourceDataProvider
|
||||
})
|
||||
);
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ void Mirai::saveConfig()
|
|||
rei::json::JsonObject jsonSource;
|
||||
jsonSource.set("name", source->name());
|
||||
jsonSource.set("color", source->color());
|
||||
auto dataProvider = dynamic_cast<MarkdownDataProvider *>(source->dataProvider());
|
||||
auto dataProvider = dynamic_cast<markdown_data_provider *>(source->data_provider());
|
||||
jsonSource.set("path", dataProvider->path());
|
||||
jsonSource.set("type", "FileSystemMarkdown");
|
||||
configJson.getArray("files").push(jsonSource);
|
||||
|
@ -84,14 +84,14 @@ Mirai::Mirai(const std::string &configFilePath) : configPath_(configFilePath)
|
|||
}
|
||||
|
||||
void Mirai::addSource(
|
||||
const std::string &name, const std::string &type, std::unique_ptr<DataProvider> &&source
|
||||
const std::string &name, const std::string &type, std::unique_ptr<data_provider> &&new_source
|
||||
)
|
||||
{
|
||||
DataProvider *sourceDataProvider = source.release();
|
||||
data_provider *sourceDataProvider = new_source.release();
|
||||
sourceDataProvider->load();
|
||||
sources_.push_back(
|
||||
std::make_unique<Source>(
|
||||
SourceConstructor{.name = name, .sourceDataProvider = sourceDataProvider}
|
||||
std::make_unique<source>(
|
||||
source_constructor{.name = name, .source_data_provider = sourceDataProvider}
|
||||
)
|
||||
);
|
||||
saveConfig();
|
||||
|
@ -103,23 +103,20 @@ void Mirai::editSource(
|
|||
)
|
||||
{
|
||||
auto source = getSourceById(id);
|
||||
source->setName(name);
|
||||
source->setColor(color);
|
||||
source->set_name(name);
|
||||
source->set_color(color);
|
||||
|
||||
DataProvider *sourceDataProvider = source->dataProvider();
|
||||
data_provider *sourceDataProvider = source->data_provider();
|
||||
saveConfig();
|
||||
sourceEdited.emit(nullptr);
|
||||
}
|
||||
|
||||
void Mirai::deleteSource(int id)
|
||||
{
|
||||
auto source = getSourceById(id);
|
||||
sources_.erase(
|
||||
std::remove_if(
|
||||
sources_.begin(), sources_.end(),
|
||||
[&](const std::unique_ptr<Source> &source) {
|
||||
return source->id == id;
|
||||
}
|
||||
[&](const std::unique_ptr<source> &source) { return source->id == id; }
|
||||
),
|
||||
sources_.end()
|
||||
);
|
||||
|
@ -136,47 +133,47 @@ void Mirai::unloadAllSources()
|
|||
void Mirai::save()
|
||||
{
|
||||
for (auto &source : sources_) {
|
||||
if (source->isDirty()) {
|
||||
if (source->is_dirty()) {
|
||||
source->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<Source>> &Mirai::getSources()
|
||||
std::vector<std::unique_ptr<source>> &Mirai::getSources()
|
||||
{
|
||||
return sources_;
|
||||
}
|
||||
|
||||
Source *Mirai::getSourceById(int id)
|
||||
source *Mirai::getSourceById(int id)
|
||||
{
|
||||
auto source = std::ranges::find_if(sources_, [&](const std::unique_ptr<Source> &source) {
|
||||
auto source_found = std::ranges::find_if(sources_, [&](const std::unique_ptr<source> &source) {
|
||||
return source->id == id;
|
||||
});
|
||||
assert(source != sources_.end()); // This should not happen
|
||||
if (source == sources_.end()) {
|
||||
// assert(source_found != sources_.end()); // This should not happen
|
||||
if (source_found == sources_.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return source->get();
|
||||
return source_found->get();
|
||||
}
|
||||
|
||||
Source *Mirai::getSourceByName(const std::string &name)
|
||||
source *Mirai::getSourceByName(const std::string &name)
|
||||
{
|
||||
auto source = std::ranges::find_if(sources_, [&](const std::unique_ptr<Source> &source) {
|
||||
auto source_found = std::ranges::find_if(sources_, [&](const std::unique_ptr<source> &source) {
|
||||
return source->name() == name;
|
||||
});
|
||||
assert(source != sources_.end()); // This should not happen
|
||||
if (source == sources_.end()) {
|
||||
assert(source_found != sources_.end()); // This should not happen
|
||||
if (source_found == sources_.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return source->get();
|
||||
return source_found->get();
|
||||
}
|
||||
|
||||
void Mirai::onSourceAdded(std::function<void(Source *)> f)
|
||||
void Mirai::onSourceAdded(std::function<void(source *)> f)
|
||||
{
|
||||
sourceAdded.registerCallback(f);
|
||||
}
|
||||
|
||||
void Mirai::onSourceEdited(std::function<void(Source *)> f)
|
||||
void Mirai::onSourceEdited(std::function<void(source *)> f)
|
||||
{
|
||||
sourceEdited.registerCallback(f);
|
||||
}
|
||||
|
|
132
external/mirai-core/src/Source.cpp
vendored
132
external/mirai-core/src/Source.cpp
vendored
|
@ -16,99 +16,65 @@
|
|||
namespace mirai
|
||||
{
|
||||
|
||||
void Source::save()
|
||||
void source::save()
|
||||
{
|
||||
data->save();
|
||||
}
|
||||
|
||||
void Source::createTask(const createTaskParams &task)
|
||||
void source::create_task(const create_task_params &task)
|
||||
{
|
||||
std::optional<int> dayId = std::nullopt;
|
||||
std::optional<int> eventId = std::nullopt;
|
||||
|
||||
if (!task.event.has_value() && task.date.has_value()) {
|
||||
auto day = data->getDayByDate(task.date.value());
|
||||
if (!day.has_value() && task.date.has_value()) {
|
||||
day = data->insertDay({.id = generateUniqueId(), .date = task.date.value()});
|
||||
}
|
||||
dayId = day->id;
|
||||
}
|
||||
|
||||
if (task.event.has_value() && task.event->id()) {
|
||||
eventId = task.event.value().id();
|
||||
}
|
||||
|
||||
data->insertTask({
|
||||
.id = generateUniqueId(),
|
||||
data->insert_task({
|
||||
.id = generate_unique_id(),
|
||||
.title = task.title,
|
||||
.state = TODO,
|
||||
.dayId = dayId,
|
||||
.eventId = eventId,
|
||||
.due_date = task.due_date,
|
||||
});
|
||||
};
|
||||
|
||||
std::vector<Day> Source::getDays()
|
||||
void source::create_event(const create_event_params &new_event)
|
||||
{
|
||||
auto daysData = data->getDays();
|
||||
std::vector<Day> days;
|
||||
std::transform(
|
||||
daysData.begin(), daysData.end(), std::back_inserter(days), [&](const DayData &dayData) {
|
||||
return Day{data, dayData};
|
||||
}
|
||||
);
|
||||
return days;
|
||||
}
|
||||
|
||||
std::optional<Day> Source::getDayByDate(Date date)
|
||||
{
|
||||
auto day = data->getDayByDate(date);
|
||||
if (!day.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return Day{data, day.value()};
|
||||
}
|
||||
|
||||
void Source::createEvent(const createEventParams &eventToCreate)
|
||||
{
|
||||
std::optional<int> dayId = std::nullopt;
|
||||
|
||||
auto day = data->getDayByDate(eventToCreate.date);
|
||||
if (!day.has_value()) {
|
||||
day = data->insertDay({.id = generateUniqueId(), .date = eventToCreate.date});
|
||||
dayId = day->id;
|
||||
}
|
||||
|
||||
data->insertEvent({
|
||||
.id = generateUniqueId(),
|
||||
.dayId = day.value().id,
|
||||
.title = eventToCreate.title,
|
||||
.startsAt = eventToCreate.startsAt,
|
||||
.endsAt = eventToCreate.endsAt,
|
||||
.id = generate_unique_id(),
|
||||
.date = new_event.date,
|
||||
.title = new_event.title,
|
||||
.starts_at = new_event.starts_at,
|
||||
.ends_at = new_event.ends_at,
|
||||
});
|
||||
};
|
||||
|
||||
std::optional<Event> Source::getEventById(int evendId)
|
||||
std::vector<Event> source::get_events()
|
||||
{
|
||||
auto event = data->getEventById(evendId);
|
||||
auto event_data = data->get_events();
|
||||
std::vector<Event> events;
|
||||
std::transform(
|
||||
event_data.begin(), event_data.end(), std::back_inserter(events),
|
||||
[&](const struct event_data &event_data) { return Event{data, event_data}; }
|
||||
);
|
||||
return events;
|
||||
}
|
||||
|
||||
std::optional<Event> source::get_event_by_id(int evendId)
|
||||
{
|
||||
auto event = data->get_event_by_id(evendId);
|
||||
if (!event.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return Event{data, event.value()};
|
||||
}
|
||||
|
||||
void Source::removeEvent(const Event &event)
|
||||
void source::remove_event(const Event &event)
|
||||
{
|
||||
data->removeEventById(event.id());
|
||||
data->remove_event_by_id(event.id());
|
||||
}
|
||||
|
||||
void Source::removeTask(const Task &task)
|
||||
void source::remove_task(const Task &task)
|
||||
{
|
||||
data->removeTaskById(task.id());
|
||||
data->remove_task_by_id(task.id());
|
||||
}
|
||||
|
||||
std::optional<Task> Source::getTaskById(int taskId)
|
||||
std::optional<Task> source::get_task_by_id(int taskId)
|
||||
{
|
||||
auto taskData = data->getTaskById(taskId);
|
||||
auto taskData = data->get_task_by_id(taskId);
|
||||
if (!taskData.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
@ -116,59 +82,55 @@ std::optional<Task> Source::getTaskById(int taskId)
|
|||
return task;
|
||||
}
|
||||
|
||||
std::vector<Task> Source::getTasks()
|
||||
std::vector<Task> source::get_tasks()
|
||||
{
|
||||
auto tasksData = data->getTasks();
|
||||
auto tasksData = data->get_tasks();
|
||||
std::vector<Task> tasks;
|
||||
std::transform(
|
||||
tasksData.begin(), tasksData.end(), std::back_inserter(tasks),
|
||||
[&](const TaskData &taskData) {
|
||||
return Task{data, taskData};
|
||||
}
|
||||
[&](const task_data &taskData) { return Task{data, taskData}; }
|
||||
);
|
||||
return tasks;
|
||||
}
|
||||
|
||||
std::vector<Task> Source::getUnscheduledTasks()
|
||||
std::vector<Task> source::get_unscheduled_tasks()
|
||||
{
|
||||
auto tasksData = data->getTasksWithoutDate();
|
||||
auto tasksData = data->get_tasks_without_date();
|
||||
std::vector<Task> tasks;
|
||||
std::transform(
|
||||
tasksData.begin(), tasksData.end(), std::back_inserter(tasks),
|
||||
[&](const TaskData &taskData) {
|
||||
return Task{data, taskData};
|
||||
}
|
||||
[&](const task_data &taskData) { return Task{data, taskData}; }
|
||||
);
|
||||
return tasks;
|
||||
}
|
||||
|
||||
std::string Source::name() const
|
||||
std::string source::name() const
|
||||
{
|
||||
return name_;
|
||||
return _name;
|
||||
}
|
||||
|
||||
std::string Source::color() const
|
||||
std::string source::color() const
|
||||
{
|
||||
return color_;
|
||||
return _color;
|
||||
}
|
||||
|
||||
void Source::setName(const std::string &name)
|
||||
void source::set_name(const std::string &name)
|
||||
{
|
||||
name_ = name;
|
||||
_name = name;
|
||||
}
|
||||
|
||||
void Source::setColor(const std::string &color)
|
||||
void source::set_color(const std::string &color)
|
||||
{
|
||||
color_ = color;
|
||||
_color = color;
|
||||
}
|
||||
|
||||
std::string Source::type() const
|
||||
std::string source::type() const
|
||||
{
|
||||
// There is only 1 type for now
|
||||
return type_;
|
||||
return _type;
|
||||
}
|
||||
|
||||
DataProvider *Source::dataProvider()
|
||||
data_provider *source::data_provider()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
|
56
external/mirai-core/src/Task.cpp
vendored
56
external/mirai-core/src/Task.cpp
vendored
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include "Task.h"
|
||||
#include "DataProvider.h"
|
||||
#include "Day.h"
|
||||
#include "utils.h"
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
@ -19,7 +18,7 @@ int Task::id() const
|
|||
return task_.id;
|
||||
}
|
||||
|
||||
int Task::sourceId() const
|
||||
int Task::source_id() const
|
||||
{
|
||||
return data_->id;
|
||||
}
|
||||
|
@ -29,7 +28,7 @@ std::string Task::title() const
|
|||
return task_.title;
|
||||
}
|
||||
|
||||
mirai::TaskState Task::state() const
|
||||
mirai::task_state Task::state() const
|
||||
{
|
||||
return task_.state;
|
||||
}
|
||||
|
@ -39,52 +38,39 @@ bool Task::checked() const
|
|||
return task_.state == mirai::DONE;
|
||||
}
|
||||
|
||||
bool Task::hasEvent() const
|
||||
bool Task::has_due_date() const
|
||||
{
|
||||
return task_.eventId.has_value();
|
||||
return task_.due_date.has_value();
|
||||
}
|
||||
|
||||
bool Task::hasDate() const
|
||||
std::optional<Date> Task::due_date() const
|
||||
{
|
||||
return task_.dayId.has_value();
|
||||
}
|
||||
|
||||
void Task::setTitle(const std::string &newTitle)
|
||||
{
|
||||
data_->updateTask(id(), {.title = newTitle});
|
||||
}
|
||||
|
||||
void Task::setDay(const Day &day)
|
||||
{
|
||||
auto emptyEventId = std::optional<std::optional<int>>(std::optional<int>(std::nullopt));
|
||||
data_->updateTask(id(), {.dayId = day.id(), .eventId = emptyEventId});
|
||||
}
|
||||
|
||||
void Task::setDate(const Date &date)
|
||||
{
|
||||
auto day = data_->getDayByDate(date);
|
||||
if (!day.has_value()) {
|
||||
day = data_->insertDay({.id = generateUniqueId(), .date = date});
|
||||
if (!task_.due_date.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return task_.due_date.value();
|
||||
}
|
||||
|
||||
void Task::set_title(const std::string &newTitle)
|
||||
{
|
||||
data_->update_task(id(), {.title = newTitle});
|
||||
}
|
||||
|
||||
void Task::set_date(const Date &date)
|
||||
{
|
||||
auto emptyEventId = std::optional<std::optional<int>>(std::optional<int>(std::nullopt));
|
||||
data_->updateTask(id(), {.dayId = day.value().id, .eventId = emptyEventId});
|
||||
data_->update_task(id(), {.due_date = date});
|
||||
}
|
||||
|
||||
void Task::unschedule()
|
||||
{
|
||||
auto emptyId = std::optional<std::optional<int>>(std::optional<int>(std::nullopt));
|
||||
data_->updateTask(id(), {.dayId = emptyId, .eventId = emptyId});
|
||||
data_->update_task(id(), {.due_date = std::nullopt});
|
||||
}
|
||||
|
||||
void Task::setEvent(const Event &event)
|
||||
void Task::set_checked(bool checked)
|
||||
{
|
||||
auto emptyDayId = std::optional<std::optional<int>>(std::optional<int>(std::nullopt));
|
||||
data_->updateTask(id(), {.dayId = emptyDayId, .eventId = event.id()});
|
||||
}
|
||||
|
||||
void Task::setChecked(bool checked)
|
||||
{
|
||||
data_->updateTask(id(), {.state = checked ? DONE : TODO});
|
||||
data_->update_task(id(), {.state = checked ? DONE : TODO});
|
||||
}
|
||||
|
||||
} // namespace mirai
|
||||
|
|
165
external/mirai-core/src/View.cpp
vendored
165
external/mirai-core/src/View.cpp
vendored
|
@ -1,165 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "View.h"
|
||||
#include "utils.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <ranges>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
View::View(Mirai *mirai) : mirai_(mirai)
|
||||
{
|
||||
}
|
||||
|
||||
void View::hideCompletedTasks(bool hide)
|
||||
{
|
||||
shouldHideCompletedTasks_ = hide;
|
||||
}
|
||||
|
||||
bool View::shouldHideCompletedTasks() const
|
||||
{
|
||||
return shouldHideCompletedTasks_;
|
||||
}
|
||||
|
||||
std::vector<Date> View::getDates()
|
||||
{
|
||||
std::vector<Date> datesVector;
|
||||
for (auto &date : dates) {
|
||||
datesVector.push_back(date.first);
|
||||
}
|
||||
return datesVector;
|
||||
}
|
||||
|
||||
std::vector<Task> View::getTasksForDate(const Date &date)
|
||||
{
|
||||
return dates.at(date).tasks;
|
||||
}
|
||||
|
||||
std::vector<Event> View::getEventsForDate(const Date &date)
|
||||
{
|
||||
if (!dates.contains(date)) {
|
||||
return {};
|
||||
}
|
||||
return dates.at(date).events;
|
||||
}
|
||||
|
||||
std::vector<Task> View::getUnscheduledTasks()
|
||||
{
|
||||
return unscheduledTasks_;
|
||||
}
|
||||
|
||||
void View::update()
|
||||
{
|
||||
dates.clear();
|
||||
unscheduledTasks_.clear();
|
||||
|
||||
auto todayDate = Date(std::chrono::system_clock::now());
|
||||
|
||||
for (int sourceId : sourcesIds_) {
|
||||
Source *source = mirai_->getSourceById(sourceId);
|
||||
for (auto day : source->getDays()) {
|
||||
// day's tasks
|
||||
auto sourceTasks = day.tasks() | std::ranges::views::filter([&](const Task &task) {
|
||||
if (day.date() >= todayDate) {
|
||||
return true;
|
||||
}
|
||||
if (shouldHideCompletedTasks()) {
|
||||
return task.checked() == false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (day.date() >= todayDate || std::ranges::distance(sourceTasks) > 0) {
|
||||
|
||||
if (!dates.contains(day.date())) {
|
||||
dates.insert_or_assign(day.date(), DateView{});
|
||||
}
|
||||
auto &tasks = dates.at(day.date()).tasks;
|
||||
tasks.insert(tasks.end(), sourceTasks.begin(), sourceTasks.end());
|
||||
}
|
||||
|
||||
// day's events
|
||||
auto sourceEvents =
|
||||
day.events() | std::ranges::views::filter([&](const Event &event) {
|
||||
return (!shouldHideCompletedTasks() || day.date() >= todayDate) ||
|
||||
findFirst(event.queryTasks(), [&](const Task &task) {
|
||||
return task.checked() == false;
|
||||
}).has_value();
|
||||
});
|
||||
|
||||
if (day.date() >= todayDate || std::ranges::distance(sourceEvents) > 0) {
|
||||
if (!dates.contains(day.date())) {
|
||||
dates.insert_or_assign(day.date(), DateView{});
|
||||
}
|
||||
auto &events = dates.at(day.date()).events;
|
||||
events.insert(events.end(), sourceEvents.begin(), sourceEvents.end());
|
||||
}
|
||||
}
|
||||
// unscheduled tasks
|
||||
auto tasks = source->getUnscheduledTasks();
|
||||
unscheduledTasks_.insert(unscheduledTasks_.end(), tasks.begin(), tasks.end());
|
||||
}
|
||||
|
||||
for (auto &date : dates) {
|
||||
auto &events = date.second.events;
|
||||
std::sort(events.begin(), events.end(), [](const Event &a, const Event &b) {
|
||||
return a.startsAt() < b.startsAt();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void View::removeSources()
|
||||
{
|
||||
sourcesIds_.clear();
|
||||
}
|
||||
|
||||
void View::addSource(const Source &source)
|
||||
{
|
||||
sourcesIds_.push_back(source.id);
|
||||
}
|
||||
|
||||
void View::setSources(const std::vector<Source> &sources)
|
||||
{
|
||||
sourcesIds_.clear();
|
||||
std::transform(
|
||||
sources.begin(), sources.end(), std::back_inserter(sourcesIds_),
|
||||
[](const Source &source) {
|
||||
return source.id;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void View::setAllSources()
|
||||
{
|
||||
const auto &sources = mirai_->getSources();
|
||||
sourcesIds_.clear();
|
||||
std::transform(
|
||||
sources.begin(), sources.end(), std::back_inserter(sourcesIds_),
|
||||
[](const std::unique_ptr<Source> &source) {
|
||||
return source->id;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
bool View::isSourceSelected(const Source &source) const
|
||||
{
|
||||
for (auto &sourceId : sourcesIds_) {
|
||||
if (sourceId == source.id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t View::activeSourceCount() const
|
||||
{
|
||||
return sourcesIds_.size();
|
||||
}
|
||||
|
||||
} // namespace mirai
|
2
external/mirai-core/src/utils.cpp
vendored
2
external/mirai-core/src/utils.cpp
vendored
|
@ -39,7 +39,7 @@ bool isDate(const std::string &dateStr)
|
|||
return true;
|
||||
}
|
||||
|
||||
int generateUniqueId()
|
||||
int generate_unique_id()
|
||||
{
|
||||
static int nextId = 0;
|
||||
return nextId++;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { ScrollView, Date, Time } from "std-widgets.slint";
|
||||
import { VCheckBox, VButton, VActionButton, Svg, VTag, VPopupIconMenu, VText, Palette } from "@selenite";
|
||||
import { Utils } from "../shared/Utils.slint";
|
||||
import { AppModels, CalendarDay, CalendarDateDisplayFormat } from "../shared/Models.slint";
|
||||
import { AppModels, CalendarViewDate, CalendarDateDisplayFormat } from "../shared/Models.slint";
|
||||
|
||||
export component Calendar inherits Rectangle {
|
||||
in property<[CalendarDay]> days;
|
||||
in property<[CalendarViewDate]> days;
|
||||
in property <CalendarDateDisplayFormat> format;
|
||||
in property <Date> current-date;
|
||||
in property <Time> current-time;
|
||||
|
@ -17,8 +17,6 @@ export component Calendar inherits Rectangle {
|
|||
|
||||
callback delete-event-request(source-id: int, event-id: int);
|
||||
|
||||
|
||||
|
||||
HorizontalLayout {
|
||||
Rectangle {
|
||||
//background: red;
|
||||
|
@ -94,20 +92,20 @@ export component Calendar inherits Rectangle {
|
|||
Rectangle {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: AppModels.get-source-color-from-id-as-color(event.sourceId);
|
||||
background: AppModels.get-source-color-from-id-as-color(event.source-id);
|
||||
opacity: 0.05;
|
||||
}
|
||||
background: Palette.card-background;
|
||||
border-radius: 4px;
|
||||
x: 8px;
|
||||
width: parent.width - 16px;
|
||||
y: day-start-y + hour-spacing * event.startsAt.hour;
|
||||
height: hour-spacing * (event.endsAt.hour - event.startsAt.hour) - 2px;
|
||||
y: day-start-y + hour-spacing * event.starts_at.hour;
|
||||
height: hour-spacing * (event.ends_at.hour - event.starts_at.hour) - 2px;
|
||||
clip: true;
|
||||
HorizontalLayout {
|
||||
Rectangle {
|
||||
width: 4px;
|
||||
background: AppModels.get-source-color-from-id-as-color(event.sourceId);
|
||||
background: AppModels.get-source-color-from-id-as-color(event.source-id);
|
||||
}
|
||||
VerticalLayout {
|
||||
padding: 16px;
|
||||
|
@ -138,7 +136,7 @@ export component Calendar inherits Rectangle {
|
|||
icon-size: 1.5rem;
|
||||
border-radius: 0;
|
||||
clicked => {
|
||||
delete-event-request(event.sourceId, event.id);
|
||||
delete-event-request(event.source-id, event.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ export component CreateTaskOrEvent inherits Rectangle {
|
|||
newTaskTitleInput := VTextInput {
|
||||
placeholder: "Enter new task";
|
||||
started-writting() => {
|
||||
sourceInput.current-index = AppModels.default-source-index;
|
||||
sourceInput.current-index = 0;
|
||||
}
|
||||
accepted => { accepted() }
|
||||
}
|
||||
|
|
|
@ -1,128 +0,0 @@
|
|||
import { Event } from "../shared/Models.slint";
|
||||
import { ScrollView } from "std-widgets.slint";
|
||||
import { VCheckBox, VTextInput, VButton, VActionButton, Svg, VTag, VPopupIconMenu, VText, Palette } from "@selenite";
|
||||
import { TaskLine } from "./TaskLine.slint";
|
||||
import { Utils } from "../shared/Utils.slint";
|
||||
|
||||
export struct EventGroupAddTask {
|
||||
title: string
|
||||
}
|
||||
|
||||
export component EventGroup {
|
||||
in property<Event> event;
|
||||
private property <bool> show-add-task: false;
|
||||
private property <bool> edit-name: false;
|
||||
|
||||
callback add-task(EventGroupAddTask);
|
||||
callback edit-task(int, EventGroupAddTask);
|
||||
callback delete-task(int);
|
||||
callback delete();
|
||||
callback edit(EventGroupAddTask);
|
||||
callback toggle-check-task(int);
|
||||
|
||||
eventPopup := VPopupIconMenu {
|
||||
VActionButton {
|
||||
icon-svg: Svg.plus;
|
||||
icon-colorize: Colors.greenyellow;
|
||||
icon-size: 1.5rem;
|
||||
border-radius: 0;
|
||||
clicked => {
|
||||
root.show-add-task = true;
|
||||
}
|
||||
}
|
||||
VActionButton {
|
||||
icon-svg: Svg.pen;
|
||||
icon-colorize: Colors.grey;
|
||||
icon-size: 1.5rem;
|
||||
border-radius: 0;
|
||||
clicked => { edit-name = true; }
|
||||
}
|
||||
|
||||
VActionButton {
|
||||
icon-svg: Svg.trash;
|
||||
icon-colorize: Colors.pink;
|
||||
icon-size: 1.5rem;
|
||||
border-radius: 0;
|
||||
clicked => { root.delete() }
|
||||
}
|
||||
}
|
||||
|
||||
ta := TouchArea {
|
||||
pointer-event(e) => {
|
||||
if (e.button == PointerEventButton.right && e.kind == PointerEventKind.up) {
|
||||
eventPopup.show(ta.mouse-x, ta.mouse-y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
VerticalLayout {
|
||||
spacing: 4px;
|
||||
VText {
|
||||
text: Utils.time-to-string(event.startsAt);
|
||||
horizontal-alignment: center;
|
||||
color: Palette.accent;
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: center;
|
||||
Rectangle {
|
||||
width: 2px;
|
||||
background: Palette.accent;
|
||||
}
|
||||
}
|
||||
VText {
|
||||
text: Utils.time-to-string(event.endsAt);
|
||||
color: Palette.accent;
|
||||
font-size: 0.9rem;
|
||||
horizontal-alignment: center;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
horizontal-stretch: 1;
|
||||
padding: 16px;
|
||||
padding-top: 32px;
|
||||
padding-bottom: 32px;
|
||||
padding-right: 0px;
|
||||
if !edit-name : VText {
|
||||
text: event.title;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
if edit-name : title := VTextInput {
|
||||
text: event.title;
|
||||
accepted => {
|
||||
root.edit({
|
||||
title: title.text
|
||||
});
|
||||
root.edit-name = false;
|
||||
}
|
||||
}
|
||||
for task[taskIndex] in event.tasks: VerticalLayout {
|
||||
padding-top: taskIndex == 0 ? 16px : 0px;
|
||||
padding-bottom: 8px;
|
||||
TaskLine {
|
||||
title: task.title;
|
||||
checked: task.checked;
|
||||
delete => {
|
||||
root.delete-task(task.id)
|
||||
}
|
||||
toggle-check => {
|
||||
root.toggle-check-task(task.id)
|
||||
}
|
||||
edited(data) => {
|
||||
root.edit-task(task.id, {
|
||||
title: data.title
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if show-add-task : taskInput := VTextInput {
|
||||
accepted => {
|
||||
root.add-task({
|
||||
title: taskInput.text
|
||||
});
|
||||
root.show-add-task = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
import { Date, Time } from "std-widgets.slint";
|
||||
import { CalendarDay } from "./Models.slint";
|
||||
|
||||
export struct NewTaskData {
|
||||
sourceId: int,
|
||||
|
|
|
@ -1,68 +1,76 @@
|
|||
import { Date, Time } from "std-widgets.slint";
|
||||
|
||||
export struct Source {
|
||||
export struct TasksViewTask {
|
||||
id: int,
|
||||
source-id: int,
|
||||
title: string,
|
||||
checked: bool
|
||||
}
|
||||
|
||||
export struct TasksViewSource {
|
||||
id: int,
|
||||
name: string,
|
||||
selected: bool,
|
||||
path: string
|
||||
color: color,
|
||||
tasks: [TasksViewTask]
|
||||
}
|
||||
|
||||
export struct TaskData {
|
||||
sourceId: int,
|
||||
eventId: int,
|
||||
id: int,
|
||||
title: string,
|
||||
date: Date,
|
||||
checked: bool,
|
||||
export struct TasksViewDate {
|
||||
due-date: Date,
|
||||
no-date: bool,
|
||||
is-late: bool,
|
||||
sources: [TasksViewSource]
|
||||
}
|
||||
|
||||
export struct Event {
|
||||
sourceId: int,
|
||||
export struct TasksView {
|
||||
dates: [TasksViewDate],
|
||||
sources: [string]
|
||||
}
|
||||
|
||||
export struct CalendarViewEvent {
|
||||
source-id: int,
|
||||
id: int,
|
||||
title: string,
|
||||
startsAt: Time,
|
||||
endsAt: Time,
|
||||
tasks: [TaskData],
|
||||
starts-at: Time,
|
||||
ends-at: Time
|
||||
}
|
||||
|
||||
export struct Day {
|
||||
sourceId: int,
|
||||
id: int,
|
||||
date: Date,
|
||||
events: [Event],
|
||||
tasks: [TaskData],
|
||||
isLate: bool,
|
||||
isToday: bool,
|
||||
relativeDaysDiff: int
|
||||
}
|
||||
|
||||
export struct CalendarDayEvent {
|
||||
sourceId: int,
|
||||
id: int,
|
||||
title: string,
|
||||
startsAt: Time,
|
||||
endsAt: Time
|
||||
}
|
||||
|
||||
export struct CalendarDay {
|
||||
events: [CalendarDayEvent],
|
||||
export struct CalendarViewDate {
|
||||
events: [CalendarViewEvent],
|
||||
date: Date,
|
||||
header: string,
|
||||
}
|
||||
|
||||
export struct CalendarView {
|
||||
dates: [CalendarViewDate]
|
||||
}
|
||||
|
||||
export struct SidebarViewSources {
|
||||
id: int,
|
||||
name: string,
|
||||
color: color,
|
||||
active: bool
|
||||
}
|
||||
|
||||
export enum SidebarViewActiveTab {
|
||||
tasks,
|
||||
calendar
|
||||
}
|
||||
|
||||
export struct SidebarView {
|
||||
sources: [SidebarViewSources],
|
||||
active-view: SidebarViewActiveTab,
|
||||
all-active: bool
|
||||
}
|
||||
|
||||
export enum CalendarDateDisplayFormat {
|
||||
Relative,
|
||||
Normal
|
||||
}
|
||||
|
||||
export global AppModels {
|
||||
in-out property<[Source]> sources-selected;
|
||||
in-out property<int> default-source-index;
|
||||
in-out property<[string]> sources;
|
||||
in-out property<bool> no-source-selected;
|
||||
in-out property<[Day]> days;
|
||||
in-out property<[CalendarDay]> calendar;
|
||||
in-out property<[TaskData]> unscheduled-tasks;
|
||||
in-out property<SidebarView> sidebar-view;
|
||||
in-out property<TasksView> tasks-view;
|
||||
in-out property<CalendarView> calendar-view;
|
||||
|
||||
callback get-source-id-from-name(string) -> int;
|
||||
pure callback get-source-name-from-id(int) -> string;
|
||||
|
|
24
src/view.h
Normal file
24
src/view.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include "DataProvider.h"
|
||||
#include "DateTime.h"
|
||||
#include <vector>
|
||||
|
||||
struct source_group {
|
||||
int source_id;
|
||||
std::vector<mirai::event_data> events;
|
||||
std::vector<mirai::task_data> tasks;
|
||||
};
|
||||
|
||||
struct day_group {
|
||||
mirai::Date date;
|
||||
source_group sources;
|
||||
};
|
||||
|
||||
std::vector<day_group>
|
||||
group_by_day(std::vector<mirai::event_data> events, std::vector<mirai::task_data> tasks)
|
||||
{
|
||||
std::vector<day_group> days;
|
||||
|
||||
// todo
|
||||
|
||||
return days;
|
||||
}
|
|
@ -8,37 +8,40 @@
|
|||
#include "../../SeleniteSetup.h"
|
||||
#include "../../shared/Utils.h"
|
||||
#include "mirai-core/DateTime.h"
|
||||
#include "mirai-core/Day.h"
|
||||
#include "mirai-core/Event.h"
|
||||
#include "mirai-core/MarkdownDataProvider.h"
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "mirai-core/Source.h"
|
||||
#include "selenite/palette.h"
|
||||
#include "slint_color.h"
|
||||
#include "slint_models.h"
|
||||
#include "slint_string.h"
|
||||
#include "ui.h"
|
||||
#include <algorithm>
|
||||
#include <bits/chrono.h>
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <print>
|
||||
#include <ranges>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
AppWindow::AppWindow(mirai::Mirai *miraiInstance)
|
||||
: miraiInstance_(miraiInstance), view_(miraiInstance)
|
||||
AppWindow::AppWindow(mirai::Mirai *miraiInstance) : miraiInstance_(miraiInstance)
|
||||
{
|
||||
sources_ = std::make_shared<slint::VectorModel<ui::Source>>();
|
||||
days_ = std::make_shared<slint::VectorModel<ui::Day>>();
|
||||
calendar_ = std::make_shared<slint::VectorModel<ui::CalendarDay>>();
|
||||
unscheduledTasks_ = std::make_shared<slint::VectorModel<ui::TaskData>>();
|
||||
auto sourcesNames = std::make_shared<slint::MapModel<ui::Source, slint::SharedString>>(
|
||||
sources_, [&](const ui::Source &a) {
|
||||
return a.name;
|
||||
}
|
||||
);
|
||||
_sidebar_view = ui::SidebarView();
|
||||
_calendar_view = ui::CalendarView();
|
||||
_tasks_view = ui::TasksView();
|
||||
/*auto sourcesNames = std::make_shared<slint::MapModel<ui::Source, slint::SharedString>>(*/
|
||||
/*sources_, [&](const ui::Source &a) {*/
|
||||
/*return a.name;*/
|
||||
/*}*/
|
||||
/*);*/
|
||||
|
||||
const auto palettePath = std::string(getenv("HOME")) + "/.config/evalyte/theme.json";
|
||||
const auto palette = selenite::parseJson(palettePath);
|
||||
|
@ -49,13 +52,14 @@ AppWindow::AppWindow(mirai::Mirai *miraiInstance)
|
|||
|
||||
bindSlintUtils(mainWindow_->global<ui::Utils>());
|
||||
|
||||
models().set_sources(sourcesNames);
|
||||
models().set_sources_selected(sources_);
|
||||
models().set_days(days_);
|
||||
models().set_calendar(calendar_);
|
||||
models().set_sidebar_view(_sidebar_view);
|
||||
models().set_calendar_view(_calendar_view);
|
||||
models().set_tasks_view(_tasks_view);
|
||||
|
||||
view_.setAllSources();
|
||||
view_.update();
|
||||
show_all_sources();
|
||||
update_views();
|
||||
/*view_.setAllSources();*/
|
||||
/*view_.update();*/
|
||||
|
||||
reloadSources();
|
||||
reloadTasks();
|
||||
|
@ -114,53 +118,49 @@ void AppWindow::setupCallbacks()
|
|||
models().on_get_source_path_from_id([&](int sourceId) {
|
||||
auto source = miraiInstance_->getSourceById(sourceId);
|
||||
assert(source);
|
||||
mirai::MarkdownDataProvider *sourceProvider =
|
||||
dynamic_cast<mirai::MarkdownDataProvider *>(source->dataProvider());
|
||||
mirai::markdown_data_provider *sourceProvider =
|
||||
dynamic_cast<mirai::markdown_data_provider *>(source->data_provider());
|
||||
return slint::SharedString(sourceProvider->path());
|
||||
});
|
||||
|
||||
miraiInstance_->onSourceAdded([&](mirai::Source *source) {
|
||||
refreshModels();
|
||||
});
|
||||
miraiInstance_->onSourceEdited([&](mirai::Source *source) {
|
||||
refreshModels();
|
||||
});
|
||||
miraiInstance_->onSourceDeleted([&](int id) {
|
||||
refreshModels();
|
||||
});
|
||||
miraiInstance_->onSourceAdded([&](mirai::source *source) { refreshModels(); });
|
||||
miraiInstance_->onSourceEdited([&](mirai::source *source) { refreshModels(); });
|
||||
miraiInstance_->onSourceDeleted([&](int id) { refreshModels(); });
|
||||
|
||||
actions().on_task_clicked([&](int sourceId, int taskId) {
|
||||
auto source = miraiInstance_->getSourceById(sourceId);
|
||||
assert(source);
|
||||
auto task = source->getTaskById(taskId);
|
||||
auto task = source->get_task_by_id(taskId);
|
||||
assert(task);
|
||||
if (!task->checked() && !task->hasDate() && !task->hasEvent()) {
|
||||
task->setDate(mirai::Date(mirai::Date(std::chrono::system_clock::now())));
|
||||
}
|
||||
task->setChecked(!task->checked());
|
||||
task->set_checked(!task->checked());
|
||||
miraiInstance_->save();
|
||||
view_.update();
|
||||
update_views();
|
||||
// view_.update();
|
||||
reloadTasks();
|
||||
});
|
||||
|
||||
actions().on_source_clicked([&](int index) {
|
||||
// index with value -1 is equal to no selection, aka "All"
|
||||
if (index == -1) {
|
||||
view_.setAllSources();
|
||||
show_all_sources();
|
||||
// view_.setAllSources();
|
||||
} else {
|
||||
view_.removeSources();
|
||||
const mirai::Source *source = miraiInstance_->getSourceById(index);
|
||||
view_.addSource(*source);
|
||||
hide_all_sources();
|
||||
// view_.removeSources();
|
||||
const mirai::source *source = miraiInstance_->getSourceById(index);
|
||||
show_source(*source);
|
||||
// view_.addSource(*source);
|
||||
}
|
||||
models().set_default_source_index(index == -1 ? 0 : index);
|
||||
view_.update();
|
||||
// models().set_default_source_index(index == -1 ? 0 : index);
|
||||
update_views();
|
||||
// view_.update();
|
||||
reloadSources();
|
||||
reloadTasks();
|
||||
});
|
||||
|
||||
actions().on_add_source([&](slint::SharedString name, slint::SharedString path) {
|
||||
std::unique_ptr<mirai::DataProvider> file =
|
||||
std::make_unique<mirai::MarkdownDataProvider>(std::string(path));
|
||||
std::unique_ptr<mirai::data_provider> file =
|
||||
std::make_unique<mirai::markdown_data_provider>(std::string(path));
|
||||
miraiInstance_->addSource(std::string(name), "FileSystemMarkdown", std::move(file));
|
||||
});
|
||||
|
||||
|
@ -174,39 +174,39 @@ void AppWindow::setupCallbacks()
|
|||
actions().on_delete_task_clicked([&](int sourceId, int taskId) {
|
||||
auto source = miraiInstance_->getSourceById(sourceId);
|
||||
assert(source);
|
||||
auto task = source->getTaskById(taskId);
|
||||
auto task = source->get_task_by_id(taskId);
|
||||
assert(task);
|
||||
source->removeTask(*task);
|
||||
source->remove_task(*task);
|
||||
miraiInstance_->save();
|
||||
view_.update();
|
||||
// view_.update();
|
||||
update_views();
|
||||
reloadTasks();
|
||||
});
|
||||
|
||||
actions().on_toggle_show_completed_tasks([&] {
|
||||
view_.hideCompletedTasks(!view_.shouldHideCompletedTasks());
|
||||
view_.update();
|
||||
// view_.hideCompletedTasks(!view_.shouldHideCompletedTasks());
|
||||
if (should_hide_completed_tasks()) {
|
||||
show_completed_tasks();
|
||||
} else {
|
||||
hide_completed_tasks();
|
||||
}
|
||||
// view_.update();
|
||||
update_views();
|
||||
reloadTasks();
|
||||
});
|
||||
|
||||
actions().on_save_task([&](ui::SaveTaskData newTaskData) {
|
||||
auto source = miraiInstance_->getSourceById(newTaskData.sourceId);
|
||||
assert(source);
|
||||
auto task = source->getTaskById(newTaskData.id);
|
||||
auto task = source->get_task_by_id(newTaskData.id);
|
||||
assert(task.has_value());
|
||||
const mirai::Date &date = SlintDateToMiraiDate(newTaskData.date);
|
||||
const auto dayOpt = source->getDayByDate(date);
|
||||
task->setTitle(std::string(newTaskData.title));
|
||||
|
||||
if (!task.value().hasEvent() && date.year != 0) {
|
||||
task->setDate(date);
|
||||
}
|
||||
|
||||
if (!task.value().hasEvent() && date.year == 0) {
|
||||
task->unschedule();
|
||||
}
|
||||
// const auto dayOpt = source->get_day_by_date(date);
|
||||
task->set_title(std::string(newTaskData.title));
|
||||
|
||||
miraiInstance_->save();
|
||||
view_.update();
|
||||
// view_.update();
|
||||
update_views();
|
||||
reloadTasks();
|
||||
});
|
||||
|
||||
|
@ -219,45 +219,47 @@ void AppWindow::setupCallbacks()
|
|||
|
||||
std::optional<mirai::Event> event = std::nullopt;
|
||||
if (newTaskData.eventId >= 0) {
|
||||
event = source->getEventById(newTaskData.eventId);
|
||||
event = source->get_event_by_id(newTaskData.eventId);
|
||||
}
|
||||
|
||||
source->createTask({
|
||||
source->create_task({
|
||||
.title = std::string(newTaskData.title),
|
||||
.event = event,
|
||||
.date = date,
|
||||
.due_date = date,
|
||||
});
|
||||
|
||||
miraiInstance_->save();
|
||||
view_.update();
|
||||
// view_.update();
|
||||
update_views();
|
||||
reloadTasks();
|
||||
});
|
||||
|
||||
actions().on_delete_event([&](int sourceId, int eventId) {
|
||||
auto source = miraiInstance_->getSourceById(sourceId);
|
||||
assert(source);
|
||||
auto event = source->getEventById(eventId);
|
||||
auto event = source->get_event_by_id(eventId);
|
||||
assert(event.has_value());
|
||||
source->removeEvent(event.value());
|
||||
source->remove_event(event.value());
|
||||
miraiInstance_->save();
|
||||
view_.update();
|
||||
// view_.update();
|
||||
update_views();
|
||||
reloadTasks();
|
||||
});
|
||||
|
||||
actions().on_create_event([&](ui::CreateEventParams newEventParams) {
|
||||
const ui::Date &date = newEventParams.date;
|
||||
const std::string dateStr = SlintDateToStdString(date);
|
||||
const auto sourceId = models().get_default_source_index();
|
||||
auto source = miraiInstance_->getSourceById(sourceId == -1 ? 0 : sourceId);
|
||||
// const auto sourceId = models().get_default_source_index();
|
||||
// auto source = miraiInstance_->getSourceById(sourceId == -1 ? 0 : sourceId);
|
||||
|
||||
source->createEvent({
|
||||
.title = std::string(newEventParams.title),
|
||||
.date = SlintDateToMiraiDate(newEventParams.date),
|
||||
.startsAt = SlintTimeToMiraiTime(newEventParams.startsAt),
|
||||
.endsAt = SlintTimeToMiraiTime(newEventParams.endsAt),
|
||||
});
|
||||
/* source->create_event({*/
|
||||
/*.title = std::string(newEventParams.title),*/
|
||||
/*.date = SlintDateToMiraiDate(newEventParams.date),*/
|
||||
/*.starts_at = SlintTimeToMiraiTime(newEventParams.startsAt),*/
|
||||
/*.ends_at = SlintTimeToMiraiTime(newEventParams.endsAt),*/
|
||||
/*});*/
|
||||
miraiInstance_->save();
|
||||
view_.update();
|
||||
// view_.update();
|
||||
update_views();
|
||||
reloadTasks();
|
||||
});
|
||||
}
|
||||
|
@ -274,157 +276,410 @@ stdToSlintStringVector(const std::vector<std::string> &stdVector)
|
|||
|
||||
void AppWindow::reloadTasks()
|
||||
{
|
||||
days_->clear();
|
||||
if (miraiInstance_->getSources().size() == 0) {
|
||||
return;
|
||||
}
|
||||
auto todayDate = mirai::Date(std::chrono::system_clock::now());
|
||||
auto dates = view_.getDates();
|
||||
auto slintDays = std::make_shared<slint::VectorModel<ui::Day>>();
|
||||
for (int dayIndex = 0; dayIndex < dates.size(); ++dayIndex) {
|
||||
auto ¤tDate = dates.at(dayIndex);
|
||||
auto slintEvents = std::make_shared<slint::VectorModel<ui::Event>>();
|
||||
auto slintDayTasks = std::make_shared<slint::VectorModel<ui::TaskData>>();
|
||||
auto relativeDaysDiff = std::chrono::duration_cast<std::chrono::days>(
|
||||
std::chrono::sys_days(currentDate.toStdChrono()) -
|
||||
std::chrono::sys_days(todayDate.toStdChrono())
|
||||
)
|
||||
.count();
|
||||
slintDays->push_back(
|
||||
ui::Day{
|
||||
.date = MiraiDateToSlintDate(currentDate),
|
||||
.events = slintEvents,
|
||||
.tasks = slintDayTasks,
|
||||
.isLate = currentDate < todayDate,
|
||||
.isToday = currentDate == todayDate,
|
||||
.relativeDaysDiff = static_cast<int>(relativeDaysDiff)
|
||||
}
|
||||
);
|
||||
// Day's tasks
|
||||
const std::vector<mirai::Task> tasksForDate = view_.getTasksForDate(currentDate);
|
||||
for (int taskIndex = 0; taskIndex < tasksForDate.size(); ++taskIndex) {
|
||||
auto &task = tasksForDate.at(taskIndex);
|
||||
slintDayTasks->push_back({
|
||||
.sourceId = task.sourceId(),
|
||||
.eventId = -1,
|
||||
.id = task.id(),
|
||||
.title = slint::SharedString(task.title()),
|
||||
.checked = task.checked(),
|
||||
});
|
||||
}
|
||||
/* days_->clear();*/
|
||||
/*if (miraiInstance_->getSources().size() == 0) {*/
|
||||
/*return;*/
|
||||
/*}*/
|
||||
/*auto todayDate = mirai::Date(std::chrono::system_clock::now());*/
|
||||
/*auto dates = view_.getDates();*/
|
||||
/*auto slintDays = std::make_shared<slint::VectorModel<ui::Day>>();*/
|
||||
/*for (int dayIndex = 0; dayIndex < dates.size(); ++dayIndex) {*/
|
||||
/*auto ¤tDate = dates.at(dayIndex);*/
|
||||
/*auto slintEvents = std::make_shared<slint::VectorModel<ui::Event>>();*/
|
||||
/*auto slintDayTasks = std::make_shared<slint::VectorModel<ui::TaskData>>();*/
|
||||
/*auto relativeDaysDiff = std::chrono::duration_cast<std::chrono::days>(*/
|
||||
/*std::chrono::sys_days(currentDate.toStdChrono()) -*/
|
||||
/*std::chrono::sys_days(todayDate.toStdChrono())*/
|
||||
/*)*/
|
||||
/*.count();*/
|
||||
/*slintDays->push_back(*/
|
||||
/*ui::Day{*/
|
||||
/*.date = MiraiDateToSlintDate(currentDate),*/
|
||||
/*.events = slintEvents,*/
|
||||
/*.tasks = slintDayTasks,*/
|
||||
/*.isLate = currentDate < todayDate,*/
|
||||
/*.isToday = currentDate == todayDate,*/
|
||||
/*.relativeDaysDiff = static_cast<int>(relativeDaysDiff)*/
|
||||
/*}*/
|
||||
/*);*/
|
||||
/*Day's tasks*/
|
||||
/*const std::vector<mirai::Task> tasksForDate = view_.getTasksForDate(currentDate);*/
|
||||
/*for (int taskIndex = 0; taskIndex < tasksForDate.size(); ++taskIndex) {*/
|
||||
/*auto &task = tasksForDate.at(taskIndex);*/
|
||||
/*slintDayTasks->push_back({*/
|
||||
/*.sourceId = task.sourceId(),*/
|
||||
/*.eventId = -1,*/
|
||||
/*.id = task.id(),*/
|
||||
/*.title = slint::SharedString(task.title()),*/
|
||||
/*.checked = task.checked(),*/
|
||||
/*});*/
|
||||
/*}*/
|
||||
|
||||
// Day's events
|
||||
const std::vector<mirai::Event> eventsForDate = view_.getEventsForDate(currentDate);
|
||||
for (int eventIndex = 0; eventIndex < eventsForDate.size(); ++eventIndex) {
|
||||
auto ¤tEvent = eventsForDate.at(eventIndex);
|
||||
auto slintTasks = std::make_shared<slint::VectorModel<ui::TaskData>>();
|
||||
slintEvents->push_back(
|
||||
ui::Event{
|
||||
.sourceId = currentEvent.sourceId(),
|
||||
.id = currentEvent.id(),
|
||||
.title = slint::SharedString(currentEvent.title()),
|
||||
.startsAt = MiraiTimeToSlintTime(currentEvent.startsAt()),
|
||||
.endsAt = MiraiTimeToSlintTime(currentEvent.endsAt()),
|
||||
.tasks = slintTasks,
|
||||
}
|
||||
);
|
||||
auto eventTasks = currentEvent.queryTasks();
|
||||
for (int taskIndex = 0; taskIndex < eventTasks.size(); ++taskIndex) {
|
||||
auto &task = eventTasks.at(taskIndex);
|
||||
slintTasks->push_back({
|
||||
.sourceId = task.sourceId(),
|
||||
.eventId = currentEvent.id(),
|
||||
.id = task.id(),
|
||||
.title = slint::SharedString(task.title()),
|
||||
.checked = task.checked(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
days_ = slintDays;
|
||||
models().set_days(days_);
|
||||
/*Day's events*/
|
||||
/*const std::vector<mirai::Event> eventsForDate = view_.getEventsForDate(currentDate);*/
|
||||
/*for (int eventIndex = 0; eventIndex < eventsForDate.size(); ++eventIndex) {*/
|
||||
/*auto ¤tEvent = eventsForDate.at(eventIndex);*/
|
||||
/*auto slintTasks = std::make_shared<slint::VectorModel<ui::TaskData>>();*/
|
||||
/*slintEvents->push_back(*/
|
||||
/*ui::Event{*/
|
||||
/*.sourceId = currentEvent.source_id(),*/
|
||||
/*.id = currentEvent.id(),*/
|
||||
/*.title = slint::SharedString(currentEvent.title()),*/
|
||||
/*.startsAt = MiraiTimeToSlintTime(currentEvent.startsAt()),*/
|
||||
/*.endsAt = MiraiTimeToSlintTime(currentEvent.endsAt()),*/
|
||||
/*.tasks = slintTasks,*/
|
||||
/*}*/
|
||||
/*);*/
|
||||
/*auto eventTasks = currentEvent.queryTasks();*/
|
||||
/*for (int taskIndex = 0; taskIndex < eventTasks.size(); ++taskIndex) {*/
|
||||
/*auto &task = eventTasks.at(taskIndex);*/
|
||||
/*slintTasks->push_back({*/
|
||||
/*.sourceId = task.sourceId(),*/
|
||||
/*.eventId = currentEvent.id(),*/
|
||||
/*.id = task.id(),*/
|
||||
/*.title = slint::SharedString(task.title()),*/
|
||||
/*.checked = task.checked(),*/
|
||||
/*});*/
|
||||
/*}*/
|
||||
/*}*/
|
||||
/*}*/
|
||||
/*days_ = slintDays;*/
|
||||
/*models().set_days(days_);*/
|
||||
|
||||
auto unscheduledTasksView = view_.getUnscheduledTasks();
|
||||
unscheduledTasks_->clear();
|
||||
for (int taskIndex = 0; taskIndex < unscheduledTasksView.size(); ++taskIndex) {
|
||||
auto &task = unscheduledTasksView.at(taskIndex);
|
||||
const auto &source = miraiInstance_->getSourceById(task.sourceId());
|
||||
std::println("request name for source id {} : {}", task.sourceId(), source->name());
|
||||
unscheduledTasks_->push_back({
|
||||
.sourceId = task.sourceId(),
|
||||
.eventId = -1,
|
||||
.id = task.id(),
|
||||
.title = slint::SharedString(task.title()),
|
||||
.checked = task.checked(),
|
||||
});
|
||||
}
|
||||
models().set_unscheduled_tasks(unscheduledTasks_);
|
||||
/*auto unscheduledTasksView = view_.getUnscheduledTasks();*/
|
||||
/*unscheduledTasks_->clear();*/
|
||||
/*for (int taskIndex = 0; taskIndex < unscheduledTasksView.size(); ++taskIndex) {*/
|
||||
/*auto &task = unscheduledTasksView.at(taskIndex);*/
|
||||
/*const auto &source = miraiInstance_->getSourceById(task.sourceId());*/
|
||||
/*std::println("request name for source id {} : {}", task.sourceId(), source->name());*/
|
||||
/*unscheduledTasks_->push_back({*/
|
||||
/*.sourceId = task.sourceId(),*/
|
||||
/*.eventId = -1,*/
|
||||
/*.id = task.id(),*/
|
||||
/*.title = slint::SharedString(task.title()),*/
|
||||
/*.checked = task.checked(),*/
|
||||
/*});*/
|
||||
/*}*/
|
||||
/*models().set_unscheduled_tasks(unscheduledTasks_);*/
|
||||
|
||||
calendar_->clear();
|
||||
for (int dayIndex = 0; dayIndex < 7; ++dayIndex) {
|
||||
std::chrono::year_month_day nextDate =
|
||||
std::chrono::floor<std::chrono::days>(std::chrono::system_clock::now()) +
|
||||
std::chrono::days{dayIndex};
|
||||
auto currentDate = mirai::Date{nextDate};
|
||||
auto events = view_.getEventsForDate(currentDate);
|
||||
auto slintEvents = std::make_shared<slint::VectorModel<ui::CalendarDayEvent>>();
|
||||
auto relativeDaysDiff = std::chrono::duration_cast<std::chrono::days>(
|
||||
std::chrono::sys_days(currentDate.toStdChrono()) -
|
||||
std::chrono::sys_days(todayDate.toStdChrono())
|
||||
)
|
||||
.count();
|
||||
if (relativeDaysDiff < 0 || relativeDaysDiff >= 7) {
|
||||
continue;
|
||||
}
|
||||
const std::vector<mirai::Event> eventsForDate = view_.getEventsForDate(currentDate);
|
||||
for (int eventIndex = 0; eventIndex < eventsForDate.size(); ++eventIndex) {
|
||||
auto ¤tEvent = eventsForDate.at(eventIndex);
|
||||
slintEvents->push_back(
|
||||
ui::CalendarDayEvent{
|
||||
.sourceId = currentEvent.sourceId(),
|
||||
.id = currentEvent.id(),
|
||||
.title = slint::SharedString(currentEvent.title()),
|
||||
.startsAt = MiraiTimeToSlintTime(currentEvent.startsAt()),
|
||||
.endsAt = MiraiTimeToSlintTime(currentEvent.endsAt()),
|
||||
}
|
||||
);
|
||||
}
|
||||
/*calendar_->clear();*/
|
||||
/*for (int dayIndex = 0; dayIndex < 7; ++dayIndex) {*/
|
||||
/*std::chrono::year_month_day nextDate =*/
|
||||
/*std::chrono::floor<std::chrono::days>(std::chrono::system_clock::now()) +*/
|
||||
/*std::chrono::days{dayIndex};*/
|
||||
/*auto currentDate = mirai::Date{nextDate};*/
|
||||
/*auto events = view_.getEventsForDate(currentDate);*/
|
||||
/*auto slintEvents = std::make_shared<slint::VectorModel<ui::CalendarDayEvent>>();*/
|
||||
/*auto relativeDaysDiff = std::chrono::duration_cast<std::chrono::days>(*/
|
||||
/*std::chrono::sys_days(currentDate.toStdChrono()) -*/
|
||||
/*std::chrono::sys_days(todayDate.toStdChrono())*/
|
||||
/*)*/
|
||||
/*.count();*/
|
||||
/*if (relativeDaysDiff < 0 || relativeDaysDiff >= 7) {*/
|
||||
/*continue;*/
|
||||
/*}*/
|
||||
/*const std::vector<mirai::Event> eventsForDate = view_.getEventsForDate(currentDate);*/
|
||||
/*for (int eventIndex = 0; eventIndex < eventsForDate.size(); ++eventIndex) {*/
|
||||
/*auto ¤tEvent = eventsForDate.at(eventIndex);*/
|
||||
/*slintEvents->push_back(*/
|
||||
/*ui::CalendarDayEvent{*/
|
||||
/*.sourceId = currentEvent.source_id(),*/
|
||||
/*.id = currentEvent.id(),*/
|
||||
/*.title = slint::SharedString(currentEvent.title()),*/
|
||||
/*.startsAt = MiraiTimeToSlintTime(currentEvent.startsAt()),*/
|
||||
/*.endsAt = MiraiTimeToSlintTime(currentEvent.endsAt()),*/
|
||||
/*}*/
|
||||
/*);*/
|
||||
/*}*/
|
||||
|
||||
auto calendarDay = ui::CalendarDay{
|
||||
.events = slintEvents,
|
||||
.date = MiraiDateToSlintDate(currentDate),
|
||||
.header = slint::SharedString(
|
||||
capitalize(formatDateRelative(MiraiDateToSlintDate(currentDate)))
|
||||
)
|
||||
};
|
||||
calendar_->push_back(calendarDay);
|
||||
}
|
||||
/*auto calendarDay = ui::CalendarDay{*/
|
||||
/*.events = slintEvents,*/
|
||||
/*.date = MiraiDateToSlintDate(currentDate),*/
|
||||
/*.header = slint::SharedString(*/
|
||||
/*capitalize(formatDateRelative(MiraiDateToSlintDate(currentDate)))*/
|
||||
/*)*/
|
||||
/*};*/
|
||||
/*calendar_->push_back(calendarDay);*/
|
||||
/*}*/
|
||||
}
|
||||
|
||||
void AppWindow::reloadSources()
|
||||
{
|
||||
sources_->clear();
|
||||
bool noSourceSelected = miraiInstance_->getSources().size() == view_.activeSourceCount();
|
||||
for (const auto &source : miraiInstance_->getSources()) {
|
||||
bool isSourceSelected = view_.isSourceSelected(*source);
|
||||
mirai::MarkdownDataProvider *sourceProvider =
|
||||
dynamic_cast<mirai::MarkdownDataProvider *>(source->dataProvider());
|
||||
sources_->push_back(
|
||||
{.id = source->id,
|
||||
.name = slint::SharedString(source->name()),
|
||||
.selected = isSourceSelected && !noSourceSelected,
|
||||
.path = slint::SharedString(sourceProvider->path())}
|
||||
);
|
||||
}
|
||||
models().set_no_source_selected(noSourceSelected);
|
||||
/*sources_->clear();*/
|
||||
/*bool noSourceSelected = miraiInstance_->getSources().size() == view_.activeSourceCount();*/
|
||||
/*for (const auto &source : miraiInstance_->getSources()) {*/
|
||||
/*bool isSourceSelected = view_.isSourceSelected(*source);*/
|
||||
/*mirai::markdown_data_provider *sourceProvider =*/
|
||||
/*dynamic_cast<mirai::markdown_data_provider *>(source->data_provider());*/
|
||||
/*sources_->push_back(*/
|
||||
/*{.id = source->id,*/
|
||||
/*.name = slint::SharedString(source->name()),*/
|
||||
/*.selected = isSourceSelected && !noSourceSelected,*/
|
||||
/*.path = slint::SharedString(sourceProvider->path())}*/
|
||||
/*);*/
|
||||
/*}*/
|
||||
/*models().set_no_source_selected(noSourceSelected);*/
|
||||
}
|
||||
|
||||
void AppWindow::refreshModels()
|
||||
{
|
||||
view_.setAllSources();
|
||||
view_.update();
|
||||
reloadSources();
|
||||
reloadTasks();
|
||||
show_all_sources();
|
||||
update_views();
|
||||
}
|
||||
|
||||
void AppWindow::update_views()
|
||||
{
|
||||
update_sidebar_view();
|
||||
update_calendar_view();
|
||||
update_tasks_view();
|
||||
}
|
||||
|
||||
void AppWindow::update_sidebar_view()
|
||||
{
|
||||
const auto &sources = miraiInstance_->getSources();
|
||||
|
||||
auto new_sources = std::make_shared<slint::VectorModel<ui::SidebarViewSources>>();
|
||||
std::println("sources");
|
||||
for (auto &source : sources) {
|
||||
std::println("source: {}", source->name());
|
||||
mirai::markdown_data_provider *sourceProvider =
|
||||
dynamic_cast<mirai::markdown_data_provider *>(source->data_provider());
|
||||
|
||||
new_sources->push_back(
|
||||
{.id = source->id, .name = slint::SharedString(source->name()), .active = false}
|
||||
);
|
||||
}
|
||||
|
||||
_sidebar_view.sources = new_sources;
|
||||
_sidebar_view.all_active = true; // TESTING
|
||||
_sidebar_view.active_view = ui::SidebarViewActiveTab::Calendar;
|
||||
models().set_sidebar_view(_sidebar_view);
|
||||
}
|
||||
|
||||
std::vector<mirai::Event>
|
||||
get_all_events_from_sources(std::vector<std::unique_ptr<mirai::source>> &sources)
|
||||
{
|
||||
std::vector<mirai::Event> all_events;
|
||||
for (auto &source : sources) {
|
||||
const auto &events = source->get_events();
|
||||
all_events.insert(all_events.end(), events.begin(), events.end());
|
||||
}
|
||||
return all_events;
|
||||
}
|
||||
|
||||
std::vector<mirai::Event>
|
||||
get_events_for_date(const std::vector<mirai::Event> &events, const mirai::Date &date)
|
||||
{
|
||||
auto filtered_events = events | std::ranges::views::filter([&](const mirai::Event &event) {
|
||||
return event.date() == date;
|
||||
});
|
||||
return std::ranges::to<std::vector>(filtered_events);
|
||||
}
|
||||
|
||||
void AppWindow::update_calendar_view()
|
||||
{
|
||||
auto today = mirai::Date(std::chrono::system_clock::now());
|
||||
auto new_slint_dates = std::make_shared<slint::VectorModel<ui::CalendarViewDate>>();
|
||||
|
||||
auto &sources = miraiInstance_->getSources();
|
||||
auto all_events = get_all_events_from_sources(sources);
|
||||
|
||||
for (int day_index = 0; day_index < 7; ++day_index) {
|
||||
std::chrono::year_month_day next_date =
|
||||
std::chrono::floor<std::chrono::days>(std::chrono::system_clock::now())
|
||||
+ std::chrono::days{day_index};
|
||||
auto current_date = mirai::Date{next_date};
|
||||
auto new_slint_events = std::make_shared<slint::VectorModel<ui::CalendarViewEvent>>();
|
||||
auto relative_days_diff = std::chrono::duration_cast<std::chrono::days>(
|
||||
std::chrono::sys_days(current_date.toStdChrono())
|
||||
- std::chrono::sys_days(today.toStdChrono())
|
||||
)
|
||||
.count();
|
||||
if (relative_days_diff < 0 || relative_days_diff >= 7) {
|
||||
continue;
|
||||
}
|
||||
auto events_for_date = get_events_for_date(all_events, current_date);
|
||||
for (int event_index = 0; event_index < events_for_date.size(); ++event_index) {
|
||||
auto ¤t_event = events_for_date.at(event_index);
|
||||
new_slint_events->push_back(
|
||||
ui::CalendarViewEvent{
|
||||
.source_id = current_event.source_id(),
|
||||
.id = current_event.id(),
|
||||
.title = slint::SharedString(current_event.title()),
|
||||
.starts_at = MiraiTimeToSlintTime(current_event.starts_at()),
|
||||
.ends_at = MiraiTimeToSlintTime(current_event.ends_at()),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
auto new_slint_date = ui::CalendarViewDate{
|
||||
.events = new_slint_events,
|
||||
.date = MiraiDateToSlintDate(current_date),
|
||||
.header = slint::SharedString(
|
||||
capitalize(formatDateRelative(MiraiDateToSlintDate(current_date)))
|
||||
)
|
||||
};
|
||||
new_slint_dates->push_back(new_slint_date);
|
||||
}
|
||||
_calendar_view.dates = new_slint_dates;
|
||||
models().set_calendar_view(_calendar_view);
|
||||
}
|
||||
|
||||
std::vector<mirai::Task>
|
||||
get_all_tasks_from_sources(std::vector<std::unique_ptr<mirai::source>> &sources)
|
||||
{
|
||||
std::vector<mirai::Task> all_tasks;
|
||||
for (auto &source : sources) {
|
||||
const auto &tasks = source->get_tasks();
|
||||
all_tasks.insert(all_tasks.end(), tasks.begin(), tasks.end());
|
||||
}
|
||||
std::sort(all_tasks.begin(), all_tasks.end(), [](const mirai::Task &t1, const mirai::Task &t2) {
|
||||
if (!t1.has_due_date() && !t2.has_due_date()) {
|
||||
return false;
|
||||
}
|
||||
if (t1.has_due_date() && !t2.has_due_date()) {
|
||||
return true;
|
||||
}
|
||||
if (!t1.has_due_date() && t2.has_due_date()) {
|
||||
return false;
|
||||
}
|
||||
return t1.due_date() < t2.due_date();
|
||||
});
|
||||
return all_tasks;
|
||||
}
|
||||
|
||||
struct tasks_source_group {
|
||||
int id;
|
||||
std::vector<mirai::Task> tasks;
|
||||
};
|
||||
|
||||
struct tasks_date_group {
|
||||
std::optional<mirai::Date> date;
|
||||
std::vector<tasks_source_group> sources;
|
||||
};
|
||||
|
||||
std::vector<tasks_date_group> group_tasks_by_date(const std::vector<mirai::Task> &tasks)
|
||||
{
|
||||
if (tasks.size() == 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<tasks_date_group> dates_group;
|
||||
int next_task_index = 0;
|
||||
|
||||
mirai::Task current_task = tasks.at(next_task_index);
|
||||
|
||||
while (next_task_index < tasks.size()) {
|
||||
tasks_date_group date_group{.date = current_task.due_date()};
|
||||
|
||||
while (next_task_index < tasks.size() && current_task.due_date() == date_group.date) {
|
||||
tasks_source_group source_group{.id = current_task.source_id()};
|
||||
|
||||
while (next_task_index < tasks.size() && current_task.due_date() == date_group.date
|
||||
&& current_task.source_id() == source_group.id) {
|
||||
source_group.tasks.push_back(current_task);
|
||||
next_task_index++;
|
||||
if (next_task_index >= tasks.size()) {
|
||||
break;
|
||||
}
|
||||
current_task = tasks.at(next_task_index);
|
||||
}
|
||||
date_group.sources.push_back(source_group);
|
||||
}
|
||||
dates_group.push_back(date_group);
|
||||
}
|
||||
|
||||
return dates_group;
|
||||
};
|
||||
|
||||
void AppWindow::update_tasks_view()
|
||||
{
|
||||
auto today = mirai::Date(std::chrono::system_clock::now());
|
||||
auto new_slint_dates = std::make_shared<slint::VectorModel<ui::TasksViewDate>>();
|
||||
|
||||
auto &sources = miraiInstance_->getSources();
|
||||
auto all_tasks_dates = group_tasks_by_date(get_all_tasks_from_sources(sources));
|
||||
|
||||
for (int date_index = 0; date_index < all_tasks_dates.size(); ++date_index) {
|
||||
auto ¤t_date_group = all_tasks_dates.at(date_index);
|
||||
auto ¤t_date = current_date_group.date;
|
||||
std::optional<int> relative_days_diff = std::nullopt;
|
||||
if (current_date.has_value()) {
|
||||
relative_days_diff = std::chrono::duration_cast<std::chrono::days>(
|
||||
std::chrono::sys_days(current_date.value().toStdChrono())
|
||||
- std::chrono::sys_days(today.toStdChrono())
|
||||
)
|
||||
.count();
|
||||
}
|
||||
|
||||
auto new_slint_sources = std::make_shared<slint::VectorModel<ui::TasksViewSource>>();
|
||||
for (auto &source : current_date_group.sources) {
|
||||
auto new_slint_source = ui::TasksViewSource();
|
||||
auto new_slint_tasks = std::make_shared<slint::VectorModel<ui::TasksViewTask>>();
|
||||
for (auto &task : source.tasks) {
|
||||
if (task.has_due_date() && task.due_date() < today) {
|
||||
continue;
|
||||
}
|
||||
new_slint_tasks->push_back(
|
||||
{.id = task.id(),
|
||||
.source_id = source.id,
|
||||
.title = slint::SharedString(task.title()),
|
||||
.checked = task.checked()}
|
||||
);
|
||||
}
|
||||
new_slint_source.tasks = new_slint_tasks;
|
||||
new_slint_source.id = source.id;
|
||||
new_slint_source.name =
|
||||
slint::SharedString(miraiInstance_->getSourceById(source.id)->name());
|
||||
const auto color =
|
||||
selenite::hexStringToColor(miraiInstance_->getSourceById(source.id)->color());
|
||||
new_slint_source.color = slint::Color::from_rgb_uint8(color.r, color.g, color.b);
|
||||
if (new_slint_source.tasks->row_count() > 0) {
|
||||
new_slint_sources->push_back(new_slint_source);
|
||||
}
|
||||
}
|
||||
auto new_slint_date = ui::TasksViewDate{
|
||||
.sources = new_slint_sources,
|
||||
};
|
||||
|
||||
if (current_date.has_value()) {
|
||||
new_slint_date.due_date = MiraiDateToSlintDate(current_date.value());
|
||||
new_slint_date.is_late = current_date.value() < today;
|
||||
} else {
|
||||
new_slint_date.no_date = true;
|
||||
}
|
||||
|
||||
if (new_slint_date.sources->row_count() > 0) {
|
||||
new_slint_dates->push_back(new_slint_date);
|
||||
}
|
||||
_tasks_view.dates = new_slint_dates;
|
||||
models().set_tasks_view(_tasks_view);
|
||||
}
|
||||
}
|
||||
|
||||
void AppWindow::show_source(const mirai::source &source)
|
||||
{
|
||||
}
|
||||
|
||||
void AppWindow::show_all_sources()
|
||||
{
|
||||
}
|
||||
|
||||
void AppWindow::hide_all_sources()
|
||||
{
|
||||
}
|
||||
|
||||
void AppWindow::show_completed_tasks()
|
||||
{
|
||||
}
|
||||
|
||||
void AppWindow::hide_completed_tasks()
|
||||
{
|
||||
}
|
||||
|
||||
bool AppWindow::should_hide_completed_tasks() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AppWindow::run()
|
||||
|
|
|
@ -7,9 +7,10 @@
|
|||
#pragma once
|
||||
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "mirai-core/View.h"
|
||||
#include "mirai-core/Source.h"
|
||||
#include "slint.h"
|
||||
#include "ui.h"
|
||||
#include <vector>
|
||||
|
||||
class AppWindow
|
||||
{
|
||||
|
@ -23,18 +24,32 @@ class AppWindow
|
|||
void reloadTasks();
|
||||
void refreshModels();
|
||||
|
||||
void update_views();
|
||||
void update_sidebar_view();
|
||||
void update_calendar_view();
|
||||
void update_tasks_view();
|
||||
|
||||
void show_all_sources();
|
||||
void show_source(const mirai::source &source);
|
||||
void hide_all_sources();
|
||||
|
||||
void show_completed_tasks();
|
||||
void hide_completed_tasks();
|
||||
bool should_hide_completed_tasks() const;
|
||||
|
||||
private:
|
||||
void setupCallbacks();
|
||||
const ui::AppModels &models();
|
||||
const ui::AppActions &actions();
|
||||
|
||||
std::shared_ptr<slint::VectorModel<ui::Source>> sources_;
|
||||
std::shared_ptr<slint::VectorModel<ui::Day>> days_;
|
||||
std::shared_ptr<slint::VectorModel<ui::CalendarDay>> calendar_;
|
||||
std::shared_ptr<slint::VectorModel<ui::TaskData>> unscheduledTasks_;
|
||||
ui::SidebarView _sidebar_view;
|
||||
ui::TasksView _tasks_view;
|
||||
ui::CalendarView _calendar_view;
|
||||
|
||||
slint::ComponentHandle<ui::AppWindow> mainWindow_ = ui::AppWindow::create();
|
||||
|
||||
mirai::Mirai *miraiInstance_;
|
||||
mirai::View view_;
|
||||
|
||||
std::vector<int> _source_filters;
|
||||
bool _should_hide_completed_tasks;
|
||||
};
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import { AppModels, TaskData } from "../../../shared/Models.slint";
|
||||
import { AppModels } from "../../../shared/Models.slint";
|
||||
import { AppActions, NewTaskData, SaveTaskData } from "../../../shared/Actions.slint";
|
||||
import { Button, VerticalBox, CheckBox, ScrollView, ComboBox } from "std-widgets.slint";
|
||||
import { TaskLine } from "../../../components/TaskLine.slint";
|
||||
import { EventGroup } from "../../../components/EventGroup.slint";
|
||||
import { Calendar } from "../../../components/Calendar.slint";
|
||||
import { VDatePicker, VTimePicker, VCheckBox, VButton, VTag, VText, VTextInput, Svg, Palette } from "@selenite";
|
||||
import { CreateTaskOrEvent } from "../../../components/CreateTaskOrEvent.slint";
|
||||
|
@ -41,7 +40,7 @@ export component CalendarView inherits Rectangle {
|
|||
delete-event-request(source-id, event-id) => {
|
||||
AppActions.delete-event(source-id, event-id)
|
||||
}
|
||||
days: AppModels.calendar;
|
||||
days: AppModels.calendar-view.dates;
|
||||
current-date: Utils.current-date;
|
||||
current-time: Utils.current-time;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { AppModels, TaskData } from "../../../shared/Models.slint";
|
||||
import { AppModels } from "../../../shared/Models.slint";
|
||||
import { AppActions } from "../../../shared/Actions.slint";
|
||||
import { VButton, ToggleButton, VActionButton, VText, Svg, Palette } from "@selenite";
|
||||
import { EditSourceModal } from "../../../modals/EditSourceModal.slint";
|
||||
|
@ -10,7 +10,7 @@ export component SideBar inherits Rectangle {
|
|||
editSourcePopup.edit(source-id)
|
||||
}
|
||||
|
||||
addSourcePopup := AddSourceModal{}
|
||||
addSourcePopup := AddSourceModal{}
|
||||
editSourcePopup := EditSourceModal {}
|
||||
|
||||
VerticalLayout {
|
||||
|
@ -46,17 +46,17 @@ export component SideBar inherits Rectangle {
|
|||
ToggleButton {
|
||||
text: "All";
|
||||
text-alignment: left;
|
||||
active: AppModels.no-source-selected;
|
||||
active: AppModels.sidebar-view.all-active;
|
||||
clicked => { AppActions.source-clicked(-1) }
|
||||
|
||||
|
||||
}
|
||||
for item[index] in AppModels.sources-selected: ToggleButton {
|
||||
text: item.name;
|
||||
for source[index] in AppModels.sidebar-view.sources: ToggleButton {
|
||||
text: source.name;
|
||||
text-alignment: left;
|
||||
active: item.selected;
|
||||
clicked => { AppActions.source-clicked(item.id) }
|
||||
right-clicked => { editSourcePopup.edit(item.id) }
|
||||
active: source.active;
|
||||
clicked => { AppActions.source-clicked(source.id) }
|
||||
right-clicked => { editSourcePopup.edit(source.id) }
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import { AppModels, TaskData } from "../../../shared/Models.slint";
|
||||
import { AppModels } from "../../../shared/Models.slint";
|
||||
import { AppActions, NewTaskData, SaveTaskData } from "../../../shared/Actions.slint";
|
||||
import { Button, VerticalBox, CheckBox, ScrollView, ComboBox } from "std-widgets.slint";
|
||||
import { TaskLine } from "../../../components/TaskLine.slint";
|
||||
import { EventGroup } from "../../../components/EventGroup.slint";
|
||||
import { Calendar } from "../../../components/Calendar.slint";
|
||||
import { VPopupIconMenu, VDatePicker, VTimePicker, VCheckBox, VButton, VTag, VText, VTextInput, Svg, Palette } from "@selenite";
|
||||
import { CreateTaskOrEvent } from "../../../components/CreateTaskOrEvent.slint";
|
||||
|
@ -37,7 +36,7 @@ export component MainView inherits Rectangle {
|
|||
}
|
||||
|
||||
CreateTaskOrEvent {
|
||||
sources: AppModels.sources;
|
||||
sources: AppModels.tasks-view.sources;
|
||||
create-task(data) => {
|
||||
AppActions.create-task({
|
||||
sourceId: data.sourceId,
|
||||
|
@ -54,106 +53,66 @@ export component MainView inherits Rectangle {
|
|||
horizontal-stretch: 1;
|
||||
VerticalLayout {
|
||||
alignment: start;
|
||||
if AppModels.days.length == 0 && AppModels.unscheduled-tasks.length == 0 : VText {
|
||||
if AppModels.tasks-view.dates.length == 0 : VText {
|
||||
text: "There is no task to show";
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
for day[dayIndex] in AppModels.days: VerticalLayout {
|
||||
spacing: day.tasks.length > 0 ? 16px : 0px;
|
||||
for day[dayIndex] in AppModels.tasks-view.dates: VerticalLayout {
|
||||
spacing: day.sources.length > 0 ? 16px : 0px;
|
||||
padding-bottom: 32px;
|
||||
|
||||
if day.tasks.length > 0 : Rectangle {
|
||||
border-radius: 8px;
|
||||
VerticalLayout {
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
VText {
|
||||
text: Utils.format-date(day.date);
|
||||
color: day.isLate ? Palette.orange : Palette.foreground;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
VText {
|
||||
text: day.relativeDaysDiff == 0 ? " - today" :
|
||||
day.relativeDaysDiff == 1 ? " - tomorrow" :
|
||||
day.relativeDaysDiff == -1 ? " - yesterday" :
|
||||
day.relativeDaysDiff > 0 ? " - in \{day.relativeDaysDiff} days" :
|
||||
" - \{-day.relativeDaysDiff} days ago";
|
||||
color: Palette.foreground-hint;
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for task[taskIndex] in day.tasks: VerticalLayout {
|
||||
padding-top: taskIndex == 0 ? 16px : 0px;
|
||||
padding-bottom: 8px;
|
||||
TaskLine {
|
||||
title: task.title;
|
||||
source-name: AppModels.get-source-name-from-id(task.sourceId);
|
||||
source-color: AppModels.get-source-color-from-id-as-color(task.sourceId);
|
||||
scheduled: task.date.year != 0;
|
||||
date: day.date;
|
||||
checked: task.checked;
|
||||
allow-edit-date: true;
|
||||
delete => {
|
||||
AppActions.delete-task-clicked(task.sourceId, task.id)
|
||||
}
|
||||
toggle-check => {
|
||||
AppActions.task-clicked(task.sourceId, task.id);
|
||||
}
|
||||
edited(data) => {
|
||||
AppActions.save-task({
|
||||
id: task.id,
|
||||
sourceId: task.sourceId,
|
||||
title: data.title,
|
||||
scheduled: data.scheduled,
|
||||
date: data.date
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
VText {
|
||||
text: day.no-date ? "Unscheduled" : Utils.format-date(day.due-date);
|
||||
color: day.is-late ? Palette.orange : Palette.foreground;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
//VerticalLayout {
|
||||
//alignment: center;
|
||||
//VText {
|
||||
//text: day.relativeDaysDiff == 0 ? " - today" :
|
||||
//day.relativeDaysDiff == 1 ? " - tomorrow" :
|
||||
//day.relativeDaysDiff == -1 ? " - yesterday" :
|
||||
//day.relativeDaysDiff > 0 ? " - in \{day.relativeDaysDiff} days" :
|
||||
//" - \{-day.relativeDaysDiff} days ago";
|
||||
//color: Palette.foreground-hint;
|
||||
//font-size: 1rem;
|
||||
//}
|
||||
//}
|
||||
}
|
||||
}
|
||||
if AppModels.unscheduled-tasks.length > 0 : VerticalLayout {
|
||||
Rectangle {
|
||||
//background: Palette.card-background;
|
||||
border-radius: 8px;
|
||||
VerticalLayout {
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
VText {
|
||||
text: "Unscheduled";
|
||||
color: Palette.foreground;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
}
|
||||
for task[taskIndex] in AppModels.unscheduled-tasks: VerticalLayout {
|
||||
padding-top: taskIndex == 0 ? 16px : 0px;
|
||||
padding-bottom: 8px;
|
||||
TaskLine {
|
||||
title: task.title;
|
||||
source-name: AppModels.get-source-name-from-id(task.sourceId);
|
||||
source-color: AppModels.get-source-color-from-id-as-color(task.sourceId);
|
||||
checked: task.checked;
|
||||
allow-edit-date: true;
|
||||
delete => {
|
||||
AppActions.delete-task-clicked(task.sourceId, task.id)
|
||||
}
|
||||
toggle-check => {
|
||||
AppActions.task-clicked(task.sourceId, task.id);
|
||||
}
|
||||
edited(data) => {
|
||||
AppActions.save-task({
|
||||
id: task.id,
|
||||
sourceId: task.sourceId,
|
||||
title: data.title,
|
||||
scheduled: data.scheduled,
|
||||
date: data.date
|
||||
})
|
||||
|
||||
for source[source-index] in day.sources: VerticalLayout {
|
||||
VText {
|
||||
text: source.name;
|
||||
}
|
||||
if source.tasks.length > 0 : Rectangle {
|
||||
VerticalLayout {
|
||||
for task[taskIndex] in source.tasks: VerticalLayout {
|
||||
padding-top: taskIndex == 0 ? 16px : 0px;
|
||||
padding-bottom: 8px;
|
||||
TaskLine {
|
||||
title: task.title;
|
||||
source-name: AppModels.get-source-name-from-id(task.source-id);
|
||||
source-color: AppModels.get-source-color-from-id-as-color(task.source-id);
|
||||
checked: task.checked;
|
||||
allow-edit-date: true;
|
||||
delete => {
|
||||
AppActions.delete-task-clicked(task.source-id, task.id)
|
||||
}
|
||||
toggle-check => {
|
||||
AppActions.task-clicked(task.source-id, task.id);
|
||||
}
|
||||
edited(data) => {
|
||||
AppActions.save-task({
|
||||
id: task.id,
|
||||
sourceId: task.source-id,
|
||||
title: data.title,
|
||||
scheduled: data.scheduled,
|
||||
date: data.date
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue