Skip to content

Commit

Permalink
Add requests to get tags and metafields
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrePTJ committed Mar 4, 2024
1 parent ce4338e commit d8a629b
Show file tree
Hide file tree
Showing 13 changed files with 359 additions and 115 deletions.
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Set dependencies options
set(SPDLOG_FMT_EXTERNAL ON)

# Add dependencies
include(FetchContent)
FetchContent_Declare(fmt
Expand All @@ -22,7 +19,7 @@ FetchContent_Declare(magic_enum
GIT_TAG v0.9.5)
FetchContent_Declare(spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.12.0)
GIT_TAG v1.13.0)
FetchContent_Declare(range-v3
GIT_REPOSITORY https://github.com/ericniebler/range-v3.git
GIT_TAG 0.12.0)
Expand Down
201 changes: 107 additions & 94 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -1,97 +1,110 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"hidden": true,
"displayName": "Default Config",
"description": "Default build using Ninja generator",
"generator": "Ninja",
"binaryDir": "${sourceDir}/cmake-build-${presetName}",
"cacheVariables": {
"CMAKE_INSTALL_PREFIX": "/usr"
}
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 0
},
{
"name": "default-windows",
"hidden": true,
"cacheVariables": {
"CMAKE_PREFIX_PATH": "c:/Qt/6.5.2/msvc2019_64",
"OPENSSL_ROOT": "c:/Qt/Tools/OpenSSLv3/Win_x64",
"CMAKE_INSTALL_PREFIX": "dist"
}
},
{
"name": "default-macos",
"hidden": true,
"cacheVariables": {
"CMAKE_PREFIX_PATH": "$env{HOME}/Qt/6.5.2/macos",
"CMAKE_INSTALL_PREFIX": "dist"
}
},
{
"name": "debug",
"inherits": "default",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "release",
"inherits": "default",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "debug-win",
"inherits": ["default-windows", "debug"]
},
{
"name": "release-win",
"inherits": ["default-windows", "release"]
},
{
"name": "release-macos",
"inherits": ["default-macos", "release"]
},
{
"name": "release-macos-noupdate",
"inherits": ["default-macos", "release"],
"cacheVariables": {
"KEMAI_ENABLE_UPDATE_CHECK": "OFF"
}
}
],
"buildPresets": [
{
"name": "debug",
"configurePreset": "debug"
},
{
"name": "release",
"configurePreset": "release"
},
{
"name": "debug-win",
"configurePreset": "debug-win"
},
{
"name": "release-win",
"configurePreset": "release-win"
},
{
"name": "release-macos",
"configurePreset": "release-macos"
},
{
"name": "release-macos-noupdate",
"configurePreset": "release-macos-noupdate"
}
]
"configurePresets": [
{
"name": "default",
"hidden": true,
"displayName": "Default Config",
"description": "Default build using Ninja generator",
"generator": "Ninja",
"binaryDir": "${sourceDir}/cmake-build-${presetName}",
"cacheVariables": {
"CMAKE_INSTALL_PREFIX": "/usr",
"SPDLOG_FMT_EXTERNAL": "ON"
}
},
{
"name": "default-windows",
"hidden": true,
"cacheVariables": {
"CMAKE_PREFIX_PATH": "c:/Qt/6.6.2/msvc2019_64",
"OPENSSL_ROOT": "c:/Qt/Tools/OpenSSLv3/Win_x64",
"CMAKE_INSTALL_PREFIX": "dist"
}
},
{
"name": "default-macos",
"hidden": true,
"cacheVariables": {
"CMAKE_PREFIX_PATH": "$env{HOME}/Qt/6.6.2/macos",
"CMAKE_INSTALL_PREFIX": "dist"
}
},
{
"name": "debug",
"inherits": "default",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "release",
"inherits": "default",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "debug-win",
"inherits": [
"default-windows",
"debug"
]
},
{
"name": "release-win",
"inherits": [
"default-windows",
"release"
]
},
{
"name": "release-macos",
"inherits": [
"default-macos",
"release"
]
},
{
"name": "release-macos-noupdate",
"inherits": [
"default-macos",
"release"
],
"cacheVariables": {
"KEMAI_ENABLE_UPDATE_CHECK": "OFF"
}
}
],
"buildPresets": [
{
"name": "debug",
"configurePreset": "debug"
},
{
"name": "release",
"configurePreset": "release"
},
{
"name": "debug-win",
"configurePreset": "debug-win"
},
{
"name": "release-win",
"configurePreset": "release-win"
},
{
"name": "release-macos",
"configurePreset": "release-macos"
},
{
"name": "release-macos-noupdate",
"configurePreset": "release-macos-noupdate"
}
]
}
4 changes: 4 additions & 0 deletions src/client/kimaiAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ ApiPlugin pluginByName(const QString& pluginName)
{
return ApiPlugin::TaskManagement;
}
if (pluginName == "MetaFieldsBundle")
{
return ApiPlugin::MetaFields;
}
return ApiPlugin::Unknown;
}

Expand Down
44 changes: 42 additions & 2 deletions src/client/kimaiAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace kemai {
enum class ApiPlugin
{
Unknown,
TaskManagement
TaskManagement,
MetaFields
};

// reply structs
Expand All @@ -21,7 +22,7 @@ struct KimaiVersion
QVersionNumber kimai;
};

using Tags = QStringList;
using Tags = std::vector<QString>;

struct Customer
{
Expand Down Expand Up @@ -142,6 +143,45 @@ struct TimeSheetConfig
TrackingMode trackingMode = TrackingMode::Default;
};

struct MetaField
{
enum class Type
{
Undefined,
String,
Integer,
Number,
Duration,
Money,
Language,
Currency,
Country,
Color,
Date,
DateTime,
Email,
Url,
TextArea,
Invoice,
Checkbox,
ChoiceList
};

int id;
QString name;
MetaField::Type type;
bool visible;
bool required;
QString label;
QString help;
QString defaultValue;
std::optional<int> customerId;
std::optional<int> projectId;
std::optional<int> activityId;
QString entityType;
};
using MetaFields = std::vector<MetaField>;

ApiPlugin pluginByName(const QString& pluginName);

} // namespace kemai
41 changes: 41 additions & 0 deletions src/client/kimaiCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ void KimaiCache::synchronize(const std::shared_ptr<KimaiClient>& client, const s
connect(timeSheetsResult, &KimaiApiBaseResult::error, this, [this, timeSheetsResult] { processRecentTimeSheetsResult(timeSheetsResult); });
}
break;

case Category::Tags: {
mTags.clear();
auto tagsResult = client->requestTags();
connect(tagsResult, &KimaiApiBaseResult::ready, this, [this, tagsResult] { processTagsResult(tagsResult); });
connect(tagsResult, &KimaiApiBaseResult::error, this, [this, tagsResult] { processTagsResult(tagsResult); });
}
break;

case Category::MetaFields: {
mMetaFields.clear();
auto metaFieldsResult = client->requestMetaFields();
connect(metaFieldsResult, &KimaiApiBaseResult::ready, this, [this, metaFieldsResult] { processMetaFieldsResult(metaFieldsResult); });
connect(metaFieldsResult, &KimaiApiBaseResult::error, this, [this, metaFieldsResult] { processMetaFieldsResult(metaFieldsResult); });
}
break;
}
}
}
Expand Down Expand Up @@ -110,6 +126,11 @@ TimeSheets KimaiCache::recentTimeSheets() const
return mRecentTimeSheets;
}

Tags KimaiCache::tags() const
{
return mTags;
}

void KimaiCache::updateSyncProgress(Category finishedCategory)
{
const std::lock_guard<std::mutex> lockGuard(mProgressMutex);
Expand Down Expand Up @@ -163,3 +184,23 @@ void KimaiCache::processRecentTimeSheetsResult(TimeSheetsResult timeSheetsResult
timeSheetsResult->deleteLater();
updateSyncProgress(Category::RecentTimeSheets);
}

void KimaiCache::processTagsResult(TagsResult tagsResult)
{
if (!tagsResult->hasError())
{
mTags = tagsResult->takeResult();
}
tagsResult->deleteLater();
updateSyncProgress(Category::Tags);
}

void KimaiCache::processMetaFieldsResult(MetaFieldsResult metaFieldsResult)
{
if (!metaFieldsResult->hasError())
{
mMetaFields = metaFieldsResult->takeResult();
}
metaFieldsResult->deleteLater();
updateSyncProgress(Category::MetaFields);
}
9 changes: 8 additions & 1 deletion src/client/kimaiCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class KimaiCache : public QObject
Customers,
Projects,
Activities,
RecentTimeSheets
RecentTimeSheets,
Tags,
MetaFields
};

enum class Status : uint8_t
Expand All @@ -37,6 +39,7 @@ class KimaiCache : public QObject
Projects projects(std::optional<int> customerId = std::nullopt) const;
Activities activities(std::optional<int> projectId = std::nullopt) const;
TimeSheets recentTimeSheets() const;
Tags tags() const;

signals:
void synchronizeStarted();
Expand All @@ -48,13 +51,17 @@ class KimaiCache : public QObject
void processProjectsResult(ProjectsResult projectsResult);
void processActivitiesResult(ActivitiesResult activitiesResult);
void processRecentTimeSheetsResult(TimeSheetsResult timeSheetsResult);
void processTagsResult(TagsResult tagsResult);
void processMetaFieldsResult(MetaFieldsResult metaFieldsResult);

std::set<Category> mPendingSync;

Customers mCustomers;
Projects mProjects;
Activities mActivities;
TimeSheets mRecentTimeSheets;
Tags mTags;
MetaFields mMetaFields;

kemai::KimaiCache::Status mStatus = kemai::KimaiCache::Status::Empty;
std::mutex mSyncMutex;
Expand Down
Loading

0 comments on commit d8a629b

Please sign in to comment.