Skip to content

Commit

Permalink
refactor: use annual instead of yearly in names
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaDucak committed Jan 8, 2024
1 parent 4e295bb commit 0f71106
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 51 deletions.
10 changes: 6 additions & 4 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ add_executable(
./date/date.cpp
./date/date.hpp

./log/annual_log_data.cpp
./log/annual_log_data.hpp
./log/local_log_repository.cpp
./log/local_log_repository.hpp
./log/log_file.cpp
./log/log_file.hpp
./log/log_repository_base.hpp
./log/log_repository_crypto_applyer.cpp
./log/log_repository_crypto_applyer.hpp
./log/year_overview_data.cpp
./log/year_overview_data.hpp

./utils/crypto.cpp
./utils/crypto.hpp
Expand All @@ -28,6 +28,9 @@ add_executable(
./utils/git_repo.cpp
./utils/git_repo.hpp

./view/annual_view.cpp
./view/annual_view.hpp
./view/annual_view_base.hpp
./view/calendar_component.cpp
./view/calendar_component.hpp
./view/ftxui_ext/extended_containers.cpp
Expand All @@ -37,10 +40,9 @@ add_executable(
./view/preview.hpp
./view/promptable.cpp
./view/promptable.hpp
./view/yearly_view.cpp
./view/yearly_view.hpp
)


target_include_directories(caps-log PRIVATE ./ ${CMAKE_CURRENT_BINARY_DIR})

target_link_libraries(caps-log
Expand Down
14 changes: 7 additions & 7 deletions source/app.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#pragma once

#include "editor/editor_base.hpp"
#include "log/annual_log_data.hpp"
#include "log/log_file.hpp"
#include "log/log_repository_base.hpp"
#include "log/year_overview_data.hpp"
#include "utils/git_repo.hpp"
#include "utils/string.hpp"
#include "utils/task_executor.hpp"
#include "view/annual_view.hpp"
#include "view/input_handler.hpp"
#include "view/yearly_view.hpp"

#include <algorithm>
#include <cassert>
Expand Down Expand Up @@ -64,10 +64,10 @@ class AsyncGitRepo {

class App : public InputHandlerBase {
unsigned m_displayedYear;
std::shared_ptr<YearViewBase> m_view;
std::shared_ptr<AnnualViewBase> m_view;
std::shared_ptr<LogRepositoryBase> m_repo;
std::shared_ptr<EditorBase> m_editor;
YearOverviewData m_data;
AnnualLogData m_data;

std::vector<const YearMap<bool> *> m_tagMaps;
std::vector<const YearMap<bool> *> m_sectionMaps;
Expand All @@ -92,12 +92,12 @@ class App : public InputHandlerBase {
}

public:
App(std::shared_ptr<YearViewBase> view, std::shared_ptr<LogRepositoryBase> repo,
App(std::shared_ptr<AnnualViewBase> view, std::shared_ptr<LogRepositoryBase> repo,
std::shared_ptr<EditorBase> editor, bool skipFirstLine = true,
std::optional<GitRepo> gitRepo = std::nullopt)
: m_displayedYear(Date::getToday().year), m_view{std::move(view)}, m_repo{std::move(repo)},
m_editor{std::move(editor)},
m_data{YearOverviewData::collect(m_repo, date::Date::getToday().year, skipFirstLine)},
m_data{AnnualLogData::collect(m_repo, date::Date::getToday().year, skipFirstLine)},
m_skipFirstLine{skipFirstLine} {
m_view->setInputHandler(this);
// if pass not prowided and repo is encrypted
Expand Down Expand Up @@ -205,7 +205,7 @@ class App : public InputHandlerBase {

void displayYear(int diff) {
m_displayedYear += diff;
m_data = YearOverviewData::collect(m_repo, m_displayedYear, m_skipFirstLine);
m_data = AnnualLogData::collect(m_repo, m_displayedYear, m_skipFirstLine);
m_view->showCalendarForYear(m_displayedYear);
m_view->setHighlightedLogsMap(nullptr);
updateViewSectionsAndTagsAfterLogChange(m_view->getFocusedDate());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "year_overview_data.hpp"
#include "annual_log_data.hpp"
#include "date/date.hpp"
#include <regex>

namespace caps_log::log {

YearOverviewData YearOverviewData::collect(const std::shared_ptr<LogRepositoryBase> &repo,
unsigned year, bool skipFirstLine) {
YearOverviewData data;
AnnualLogData AnnualLogData::collect(const std::shared_ptr<LogRepositoryBase> &repo, unsigned year,
bool skipFirstLine) {
AnnualLogData data;

for (unsigned month = date::Month::JANUARY; month <= date::Month::DECEMBER; month++) {
for (unsigned day = 1; day <= date::getNumberOfDaysForMonth(month, year); day++) {
Expand All @@ -17,8 +17,8 @@ YearOverviewData YearOverviewData::collect(const std::shared_ptr<LogRepositoryBa
return std::move(data);
}

void YearOverviewData::collect(const std::shared_ptr<LogRepositoryBase> &repo,
const date::Date &date, bool skipFirstLine) {
void AnnualLogData::collect(const std::shared_ptr<LogRepositoryBase> &repo, const date::Date &date,
bool skipFirstLine) {
// first remove all set mentions
utils::mapRemoveIf(tagMap, [date](auto &tag) {
tag.second.set(date, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ namespace caps_log::log {
* It contains data like which dates have log entries, what tags/sections/tasks were
* mentioned in which log entries but not actual log contents.
*/
class YearOverviewData {
class AnnualLogData {
public:
date::YearMap<bool> logAvailabilityMap;
date::StringYearMap sectionMap, tagMap;

/**
* Constructs YearOverviewData from logs in a given year.
*/
static YearOverviewData collect(const std::shared_ptr<LogRepositoryBase> &repo, unsigned year,
bool skipFirstLine = true);
static AnnualLogData collect(const std::shared_ptr<LogRepositoryBase> &repo, unsigned year,
bool skipFirstLine = true);

/**
* Injects/updates the current object with information parsed from a log entry form a specified
Expand Down
2 changes: 1 addition & 1 deletion source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ auto makeCapsLog(const caps_log::Config &conf) {
using namespace caps_log;

auto pathProvider = log::LocalFSLogFilePathProvider{conf.logDirPath, conf.logFilenameFormat};
auto view = std::make_shared<view::YearView>(date::Date::getToday(), conf.sundayStart);
auto view = std::make_shared<view::AnnualView>(date::Date::getToday(), conf.sundayStart);
auto repo = std::make_shared<log::LocalLogRepository>(pathProvider, conf.password);
auto editor = [&]() -> std::shared_ptr<editor::EditorBase> {
if (conf.password.empty()) {
Expand Down
28 changes: 14 additions & 14 deletions source/view/yearly_view.cpp → source/view/annual_view.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "yearly_view.hpp"
#include "annual_view.hpp"

#include "calendar_component.hpp"
#include "ftxui/component/screen_interactive.hpp"
Expand All @@ -14,19 +14,19 @@

namespace caps_log::view {

YearView::YearView(const date::Date &today, bool sundayStart)
AnnualView::AnnualView(const date::Date &today, bool sundayStart)
: m_screen{ScreenInteractive::Fullscreen()},
m_calendarButtons{Calendar::make(today, makeCalendarOptions(today, sundayStart))},
m_tagsMenu{makeTagsMenu()}, m_sectionsMenu{makeSectionsMenu()},
m_rootComponent{makeFullUIComponent()} {}

void YearView::run() { m_screen.Loop(m_rootComponent); }
void AnnualView::run() { m_screen.Loop(m_rootComponent); }

void YearView::stop() { m_screen.ExitLoopClosure()(); }
void AnnualView::stop() { m_screen.ExitLoopClosure()(); }

void YearView::showCalendarForYear(unsigned year) { m_calendarButtons->displayYear(year); }
void AnnualView::showCalendarForYear(unsigned year) { m_calendarButtons->displayYear(year); }

std::shared_ptr<Promptable> YearView::makeFullUIComponent() {
std::shared_ptr<Promptable> AnnualView::makeFullUIComponent() {
auto container = ftxui_ext::CustomContainer(
{
m_tagsMenu,
Expand Down Expand Up @@ -70,7 +70,7 @@ std::shared_ptr<Promptable> YearView::makeFullUIComponent() {
return std::make_shared<Promptable>(event_handler);
}

CalendarOption YearView::makeCalendarOptions(const Date &today, bool sundayStart) {
CalendarOption AnnualView::makeCalendarOptions(const Date &today, bool sundayStart) {
CalendarOption option;
option.transform = [this, today](const auto &date, const auto &state) {
auto element = text(state.label);
Expand Down Expand Up @@ -110,7 +110,7 @@ CalendarOption YearView::makeCalendarOptions(const Date &today, bool sundayStart
return std::move(option);
}

std::shared_ptr<WindowedMenu> YearView::makeTagsMenu() {
std::shared_ptr<WindowedMenu> AnnualView::makeTagsMenu() {
MenuOption option{
.entries = &m_tagMenuItems,
.on_change =
Expand All @@ -122,7 +122,7 @@ std::shared_ptr<WindowedMenu> YearView::makeTagsMenu() {
return WindowedMenu::make("Tags", option);
}

std::shared_ptr<WindowedMenu> YearView::makeSectionsMenu() {
std::shared_ptr<WindowedMenu> AnnualView::makeSectionsMenu() {
MenuOption option = {
.entries = &m_sectionMenuItems,
.on_change =
Expand All @@ -134,19 +134,19 @@ std::shared_ptr<WindowedMenu> YearView::makeSectionsMenu() {
return WindowedMenu::make("Sections", option);
}

void YearView::post(Task task) {
void AnnualView::post(Task task) {
m_screen.Post([task, this]() { std::get<Closure>(task)(); });
m_screen.Post(Event::Custom);
}
void YearView::prompt(std::string message, std::function<void()> onYesCallback) {
void AnnualView::prompt(std::string message, std::function<void()> onYesCallback) {
m_rootComponent->prompt(message, onYesCallback);
}
void YearView::promptOk(std::string message, std::function<void()> callback) {
void AnnualView::promptOk(std::string message, std::function<void()> callback) {
m_rootComponent->promptOk(message, callback);
}
void YearView::loadingScreen(const std::string &message) {
void AnnualView::loadingScreen(const std::string &message) {
m_rootComponent->loadingScreen(message);
}
void YearView::loadingScreenOff() { m_rootComponent->resetToMain(); }
void AnnualView::loadingScreenOff() { m_rootComponent->resetToMain(); }

} // namespace caps_log::view
6 changes: 3 additions & 3 deletions source/view/yearly_view.hpp → source/view/annual_view.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#pragma once

#include "annual_view_base.hpp"
#include "calendar_component.hpp"
#include "date/date.hpp"
#include "input_handler.hpp"
#include "preview.hpp"
#include "promptable.hpp"
#include "windowed_menu.hpp"
#include "year_view_base.hpp"

#include <array>
#include <ftxui/component/captured_mouse.hpp>
Expand All @@ -22,7 +22,7 @@ using namespace ftxui;

using namespace date;

class YearView : public YearViewBase {
class AnnualView : public AnnualViewBase {
InputHandlerBase *m_handler;
ScreenInteractive m_screen;

Expand All @@ -40,7 +40,7 @@ class YearView : public YearViewBase {
std::vector<std::string> m_tagMenuItems, m_sectionMenuItems;

public:
YearView(const Date &today, bool sundayStart);
AnnualView(const Date &today, bool sundayStart);

void run() override;
void stop() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ inline std::string makeMenuItemTitle(const std::string &title, unsigned count) {
return std::string{"("} + std::to_string(count) + ") - " + title;
}

class YearViewBase {
class AnnualViewBase {
public:
virtual ~YearViewBase() = default;
virtual ~AnnualViewBase() = default;

virtual void run() = 0;
virtual void stop() = 0;
Expand Down
4 changes: 2 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ add_executable(
./date_test.cpp
./local_log_repository_test.cpp
./log_entry_test.cpp
./year_overview_data_test.cpp
./annual_log_data_test.cpp

./../source/config.cpp
./../source/date/date.cpp
./../source/log/log_file.cpp
./../source/log/log_repository_crypto_applyer.cpp
./../source/log/local_log_repository.cpp
./../source/log/year_overview_data.cpp
./../source/log/annual_log_data.cpp
./../source/utils/crypto.cpp
./../source/utils/git_repo.cpp
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include <fmt/format.h>
#include <gtest/gtest.h>

#include "log/annual_log_data.hpp"
#include "log/log_file.hpp"
#include "log/year_overview_data.hpp"

#include "mocks.hpp"

TEST(YearOverviewDataTest, Collect) {
auto dummyDate = caps_log::date::Date{10, 10, 2020};
auto dummyRepo = std::make_shared<DummyRepository>();
dummyRepo->write({dummyDate, "\n# dummy section\n * dummy tag"});
auto data = caps_log::log::YearOverviewData::collect(dummyRepo, dummyDate.year);
auto data = caps_log::log::AnnualLogData::collect(dummyRepo, dummyDate.year);

// inital collection
ASSERT_EQ(data.tagMap.size(), 1);
Expand Down
3 changes: 1 addition & 2 deletions test/controler_test.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include "app.hpp"
#include "mocks.hpp"

#include "log/annual_log_data.hpp"
#include "log/log_file.hpp"
#include "log/log_repository_base.hpp"
#include "log/year_overview_data.hpp"
#include "view/input_handler.hpp"
#include "view/year_view_base.hpp"

#include <fstream>
#include <ftxui/component/event.hpp>
Expand Down
1 change: 0 additions & 1 deletion test/local_log_repository_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "log/log_file.hpp"
#include "log/log_repository_base.hpp"
#include "log/log_repository_crypto_applyer.hpp"
#include "log/year_overview_data.hpp"
#include "mocks.hpp"
#include <filesystem>
#include <fstream>
Expand Down
1 change: 0 additions & 1 deletion test/log_entry_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "fmt/core.h"
#include "log/log_file.hpp"
#include "log/year_overview_data.hpp"
#include "utils/string.hpp"

#include "mocks.hpp"
Expand Down
6 changes: 3 additions & 3 deletions test/mocks.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#include "date/date.hpp"
#include "editor/editor_base.hpp"
#include "log/log_repository_base.hpp"
#include "view/annual_view_base.hpp"
#include "view/calendar_component.hpp"
#include "view/input_handler.hpp"
#include "view/year_view_base.hpp"
#include <gmock/gmock-actions.h>
#include <gmock/gmock-more-actions.h>
#include <gmock/gmock-nice-strict.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <sstream>

class DummyYearView : public caps_log::view::YearViewBase {
class DummyYearView : public caps_log::view::AnnualViewBase {
public:
caps_log::view::InputHandlerBase *m_inputHandler = nullptr;
int m_displayedYear;
Expand Down Expand Up @@ -59,7 +59,7 @@ class DummyYearView : public caps_log::view::YearViewBase {
int &selectedSection() override { return m_selectedSection; }
};

class DMockYearView : public caps_log::view::YearViewBase {
class DMockYearView : public caps_log::view::AnnualViewBase {
DummyYearView view;

public:
Expand Down

0 comments on commit 0f71106

Please sign in to comment.