feat: add long-term projects with AI creation
- Add project model, schema v4, sync triggers, and server support\n- Add project panel, deadline countdown, manual create/edit/complete/delete\n- Parse AI project operations and show them in the proposal diff\n- Sync projects to Android and display them read-only\n- Rebuild AppImage and update validation docs and screenshots
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
用户精力高峰(用于安排高精力任务):{ENERGY_PROFILE}
|
||||
用户现有日程(每行开头的 [bN] 是引用编号,只能用于 update/delete):
|
||||
{EXISTING_SCHEDULE}
|
||||
用户现有长期项目(避免重复创建):
|
||||
{EXISTING_PROJECTS}
|
||||
|
||||
工作规则:
|
||||
1. 先用 1–3 句简洁回复,说明你理解的需求和准备怎么安排。
|
||||
@@ -14,7 +16,8 @@
|
||||
{"operations":[
|
||||
{"type":"create","title":"任务标题","description":"可选说明","duration_min":60,"deadline":"YYYY-MM-DDTHH:MM:SS","priority":1,"energy_req":1,"splittable":false,"preferred_start":"YYYY-MM-DDTHH:MM:SS","preferred_end":"YYYY-MM-DDTHH:MM:SS"},
|
||||
{"type":"update","target_ref":"b1","title":"可选的新标题","duration_min":60,"preferred_start":"YYYY-MM-DDTHH:MM:SS","preferred_end":"YYYY-MM-DDTHH:MM:SS"},
|
||||
{"type":"delete","target_ref":"b2"}
|
||||
{"type":"delete","target_ref":"b2"},
|
||||
{"type":"project","title":"跨月项目","description":"可选说明","deadline":"YYYY-MM-DD","priority":2}
|
||||
]}
|
||||
4. 时间使用用户本地时间,不带时区;不确定的字段填 null。
|
||||
5. duration_min 必须在 15–480 之间;无法确定时用 60。
|
||||
@@ -31,6 +34,9 @@
|
||||
16. 示例:现有 [b2] 团队同步(会议)、[b4] 项目会议(会议)。用户说“删除明天所有会议”时,输出 {"operations":[{"type":"delete","target_ref":"b2"},{"type":"delete","target_ref":"b4"}]}。
|
||||
17. 示例:用户说“明天之前找时间做两小时长任务,可以拆开”,输出 create 并设置 "splittable":true;不要拆成两个独立任务。
|
||||
18. energy_req 取值:0=低精力杂务,1=一般沟通/会议,2=高专注深度工作、学习或创作;不确定时填 1。高精力任务应优先放在用户的精力高峰时段。
|
||||
19. 长期项目:当用户描述的是跨多天、数周或数月完成的目标(例如“一个月内完成飞行控制器项目”),且没有要求现在就拆成具体日程块时,使用 {"type":"project","title":"项目标题","description":"可选说明","deadline":"YYYY-MM-DD","priority":2}。不要用 create 把它塞进某一天。
|
||||
20. 只有用户明确要求“今天/明天/几点做多久”或明确要求把项目拆成执行块时,才使用 create 创建具体时间块。
|
||||
21. 长期项目的 deadline 使用日期而不是具体时间;如果用户说“这个月底/下个月/一个月内”,结合当前日期推算出合理日期。
|
||||
|
||||
补充信息:
|
||||
{EXTRA_CONTEXT}
|
||||
|
||||
@@ -4,7 +4,8 @@ JSON 格式:
|
||||
{"operations":[
|
||||
{"type":"create","title":"任务标题","description":"可选说明","duration_min":60,"deadline":"YYYY-MM-DDTHH:MM:SS","priority":1,"energy_req":1,"splittable":false,"preferred_start":"YYYY-MM-DDTHH:MM:SS","preferred_end":"YYYY-MM-DDTHH:MM:SS"},
|
||||
{"type":"update","target_ref":"b1","title":"可选的新标题","duration_min":60,"preferred_start":"YYYY-MM-DDTHH:MM:SS","preferred_end":"YYYY-MM-DDTHH:MM:SS"},
|
||||
{"type":"delete","target_ref":"b2"}
|
||||
{"type":"delete","target_ref":"b2"},
|
||||
{"type":"project","title":"长期项目标题","description":"可选说明","deadline":"YYYY-MM-DD","priority":2}
|
||||
]}
|
||||
|
||||
规则:
|
||||
@@ -14,4 +15,5 @@ JSON 格式:
|
||||
- 如果只是闲聊或没有日程变更,operations 输出空数组。
|
||||
- 用户明确要求新增/修改/删除时,必须给出 operations;冲突、时长不足或过去时间交给本地排程器处理。
|
||||
- 可拆分请求优先设置 splittable=true。
|
||||
- 跨多天/数周/数月的目标使用 type=project;只有具体执行块才使用 create。
|
||||
- 现有日程摘要中的(会议)标记用于识别会议类;删除“所有会议”时删除全部带标记项。
|
||||
|
||||
@@ -5,6 +5,7 @@ add_library(schedule_core STATIC
|
||||
core/DailyInsights.h
|
||||
core/EnergyProfile.cpp
|
||||
core/EnergyProfile.h
|
||||
core/Project.h
|
||||
core/ProposedDiff.h
|
||||
core/Recurrence.h
|
||||
core/SchedulerEngine.cpp
|
||||
@@ -84,6 +85,8 @@ add_library(schedule_ui STATIC
|
||||
ui/dialogs/BlockEditDialog.h
|
||||
ui/dialogs/DailyReviewDialog.cpp
|
||||
ui/dialogs/DailyReviewDialog.h
|
||||
ui/dialogs/ProjectDialog.cpp
|
||||
ui/dialogs/ProjectDialog.h
|
||||
ui/dialogs/SearchDialog.cpp
|
||||
ui/dialogs/SearchDialog.h
|
||||
ui/dialogs/SettingsDialog.cpp
|
||||
@@ -92,6 +95,8 @@ add_library(schedule_ui STATIC
|
||||
ui/panels/ChatPanel.h
|
||||
ui/panels/DiffPreviewCard.cpp
|
||||
ui/panels/DiffPreviewCard.h
|
||||
ui/panels/ProjectCard.cpp
|
||||
ui/panels/ProjectCard.h
|
||||
ui/panels/TodayItemCard.cpp
|
||||
ui/panels/TodayItemCard.h
|
||||
ui/panels/TodayPanel.cpp
|
||||
|
||||
@@ -479,6 +479,7 @@ QString AIService::buildSystemPrompt()
|
||||
prompt.replace(QStringLiteral("{ENERGY_PROFILE}"),
|
||||
m_scheduleService.dailyReview(now.date()).energySummary);
|
||||
prompt.replace(QStringLiteral("{EXISTING_SCHEDULE}"), scheduleSummary());
|
||||
prompt.replace(QStringLiteral("{EXISTING_PROJECTS}"), projectSummary());
|
||||
prompt.replace(QStringLiteral("{EXTRA_CONTEXT}"),
|
||||
m_filePaths.isEmpty()
|
||||
? QStringLiteral("无")
|
||||
@@ -544,6 +545,31 @@ QString AIService::scheduleSummary()
|
||||
return m_contextSummary;
|
||||
}
|
||||
|
||||
QString AIService::projectSummary()
|
||||
{
|
||||
const QVector<Project> projects = m_scheduleService.projects();
|
||||
if (projects.isEmpty())
|
||||
{
|
||||
return QStringLiteral("(暂无长期项目)");
|
||||
}
|
||||
QString summary;
|
||||
int count = 0;
|
||||
for (const Project& project : projects)
|
||||
{
|
||||
summary += QStringLiteral("- %1").arg(project.title);
|
||||
if (project.deadline.has_value())
|
||||
{
|
||||
summary += QStringLiteral("(截止 %1)").arg(project.deadline->toString(QStringLiteral("yyyy-MM-dd")));
|
||||
}
|
||||
summary += QLatin1Char('\n');
|
||||
if (++count >= 50)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return summary.trimmed();
|
||||
}
|
||||
|
||||
QJsonValue AIService::buildUserContent() const
|
||||
{
|
||||
QString text = m_userText;
|
||||
@@ -614,6 +640,9 @@ void AIService::buildProposalFromOperations(const QJsonArray& operations, const
|
||||
bool forceSplit = false;
|
||||
};
|
||||
|
||||
QJsonArray projectCreates;
|
||||
QVector<ProposedProjectEntry> projectEntries;
|
||||
|
||||
auto findContext = [this](const QString& raw) -> const ContextItem* {
|
||||
QString key = raw.trimmed();
|
||||
if (key.startsWith(QLatin1Char('[')) && key.endsWith(QLatin1Char(']')))
|
||||
@@ -824,6 +853,39 @@ void AIService::buildProposalFromOperations(const QJsonArray& operations, const
|
||||
{
|
||||
type = QStringLiteral("create");
|
||||
}
|
||||
if (type == QStringLiteral("project"))
|
||||
{
|
||||
const QString title = object.value(QStringLiteral("title")).toString().trimmed();
|
||||
const QString deadlineText = object.value(QStringLiteral("deadline")).toString().trimmed();
|
||||
const QDate deadline =
|
||||
QDate::fromString(deadlineText.left(10), Qt::ISODate);
|
||||
if (title.isEmpty() || !deadline.isValid())
|
||||
{
|
||||
Q_EMIT notice(QStringLiteral("AI 返回的长期项目缺少标题或截止日期,已跳过"));
|
||||
continue;
|
||||
}
|
||||
const QString tempId = QStringLiteral("p%1").arg(projectCreates.size() + 1);
|
||||
QJsonObject project;
|
||||
project.insert(QStringLiteral("temp_id"), tempId);
|
||||
project.insert(QStringLiteral("title"), title.left(200));
|
||||
project.insert(QStringLiteral("description"),
|
||||
object.value(QStringLiteral("description")).toString().left(2000));
|
||||
project.insert(QStringLiteral("deadline"), deadline.toString(Qt::ISODate));
|
||||
project.insert(QStringLiteral("priority"),
|
||||
std::clamp(object.value(QStringLiteral("priority")).toInt(2), 1, 5));
|
||||
project.insert(QStringLiteral("source_ref"), m_userText.left(500));
|
||||
projectCreates.append(project);
|
||||
|
||||
ProposedProjectEntry entry;
|
||||
entry.tempId = tempId;
|
||||
entry.operation = ProposedOperation::Create;
|
||||
entry.title = title;
|
||||
entry.description = project.value(QStringLiteral("description")).toString();
|
||||
entry.deadline = deadline;
|
||||
entry.priority = project.value(QStringLiteral("priority")).toInt();
|
||||
projectEntries.append(entry);
|
||||
continue;
|
||||
}
|
||||
if (type == QStringLiteral("create"))
|
||||
{
|
||||
bool changed = false;
|
||||
@@ -900,7 +962,7 @@ void AIService::buildProposalFromOperations(const QJsonArray& operations, const
|
||||
}
|
||||
}
|
||||
|
||||
if (specs.isEmpty())
|
||||
if (specs.isEmpty() && projectCreates.isEmpty())
|
||||
{
|
||||
if (tryLocalDeleteAllMeetings())
|
||||
{
|
||||
@@ -1543,7 +1605,7 @@ void AIService::buildProposalFromOperations(const QJsonArray& operations, const
|
||||
}
|
||||
}
|
||||
|
||||
if (creates.isEmpty() && updates.isEmpty() && deletes.isEmpty())
|
||||
if (creates.isEmpty() && updates.isEmpty() && deletes.isEmpty() && projectCreates.isEmpty())
|
||||
{
|
||||
appendHistory(m_visibleText);
|
||||
finishRequest();
|
||||
@@ -1558,8 +1620,8 @@ void AIService::buildProposalFromOperations(const QJsonArray& operations, const
|
||||
QString explanation = visibleReply.trimmed();
|
||||
if (explanation.isEmpty())
|
||||
{
|
||||
explanation = QStringLiteral("我整理了 %1 项日程调整建议。")
|
||||
.arg(creates.size() + updates.size() + deletes.size());
|
||||
explanation = QStringLiteral("我整理了 %1 项日程/长期项目建议。")
|
||||
.arg(creates.size() + updates.size() + deletes.size() + projectCreates.size());
|
||||
Q_EMIT streamDelta(explanation);
|
||||
}
|
||||
|
||||
@@ -1572,6 +1634,7 @@ void AIService::buildProposalFromOperations(const QJsonArray& operations, const
|
||||
{QStringLiteral("creates"), creates},
|
||||
{QStringLiteral("updates"), updates},
|
||||
{QStringLiteral("deletes"), deletes},
|
||||
{QStringLiteral("projects"), projectCreates},
|
||||
};
|
||||
if (!m_store.insertProposedDiff(diff))
|
||||
{
|
||||
@@ -1582,6 +1645,7 @@ void AIService::buildProposalFromOperations(const QJsonArray& operations, const
|
||||
m_pendingDiffs.insert(diff.id, diff);
|
||||
proposal.diffId = diff.id;
|
||||
proposal.explanation = explanation;
|
||||
proposal.projects = projectEntries;
|
||||
appendHistory(explanation);
|
||||
Q_EMIT proposalReady(proposal);
|
||||
finishRequest();
|
||||
|
||||
@@ -79,6 +79,7 @@ private:
|
||||
|
||||
QString buildSystemPrompt();
|
||||
QString scheduleSummary();
|
||||
QString projectSummary();
|
||||
QJsonValue buildUserContent() const;
|
||||
void buildProposalFromOperations(const QJsonArray& operations, const QString& visibleReply);
|
||||
bool tryLocalDeleteAllMeetings();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDate>
|
||||
#include <QDateTime>
|
||||
#include <QMetaType>
|
||||
#include <QString>
|
||||
@@ -43,6 +44,19 @@ struct ProposedScheduleEntry
|
||||
int energyRequired = -1;
|
||||
};
|
||||
|
||||
struct ProposedProjectEntry
|
||||
{
|
||||
QString tempId;
|
||||
ProposedOperation operation = ProposedOperation::Create;
|
||||
QString projectId;
|
||||
QString title;
|
||||
QString oldTitle;
|
||||
QString description;
|
||||
std::optional<QDate> deadline;
|
||||
std::optional<QDate> oldDeadline;
|
||||
int priority = 1;
|
||||
};
|
||||
|
||||
/*
|
||||
* 类名: ScheduleProposal
|
||||
* 功能: AI 生成并已落库的待确认日程建议,供 UI 展示与选择性接受
|
||||
@@ -53,6 +67,7 @@ struct ScheduleProposal
|
||||
QString diffId;
|
||||
QString explanation;
|
||||
QVector<ProposedScheduleEntry> entries;
|
||||
QVector<ProposedProjectEntry> projects;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(ScheduleProposal)
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDate>
|
||||
#include <QDateTime>
|
||||
#include <QString>
|
||||
|
||||
#include <optional>
|
||||
|
||||
/*
|
||||
* 类名: Project
|
||||
* 功能: 跨多天的长期项目/目标,只持有模糊截止日期,不占用细粒度时间块
|
||||
* 线程安全: 否(值类型)
|
||||
*/
|
||||
struct Project
|
||||
{
|
||||
QString id;
|
||||
QString title;
|
||||
QString description;
|
||||
QString source = QStringLiteral("manual");
|
||||
QString sourceRef;
|
||||
std::optional<QDate> deadline;
|
||||
int priority = 1;
|
||||
QString status = QStringLiteral("active");
|
||||
QDateTime createdAt;
|
||||
QDateTime updatedAt;
|
||||
int version = 0;
|
||||
QString deviceId;
|
||||
};
|
||||
@@ -396,6 +396,166 @@ bool ScheduleService::createRecurringBlock(const QString& title,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScheduleService::createProject(const QString& title,
|
||||
const QString& description,
|
||||
const QDate& deadline,
|
||||
QString* error)
|
||||
{
|
||||
if (title.trimmed().isEmpty())
|
||||
{
|
||||
m_lastError = QStringLiteral("项目标题不能为空");
|
||||
if (error)
|
||||
{
|
||||
*error = m_lastError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (!deadline.isValid())
|
||||
{
|
||||
m_lastError = QStringLiteral("长期项目需要截止日期");
|
||||
if (error)
|
||||
{
|
||||
*error = m_lastError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
const QDateTime now = QDateTime::currentDateTime();
|
||||
Project project;
|
||||
project.id = newId();
|
||||
project.title = title.trimmed().left(200);
|
||||
project.description = description.trimmed().left(2000);
|
||||
project.source = QStringLiteral("manual");
|
||||
project.deadline = deadline;
|
||||
project.priority = 1;
|
||||
project.status = QStringLiteral("active");
|
||||
project.createdAt = now;
|
||||
project.updatedAt = now;
|
||||
project.version = 0;
|
||||
project.deviceId = m_deviceId;
|
||||
if (!m_store.insertProject(project))
|
||||
{
|
||||
m_lastError = m_store.lastError();
|
||||
if (error)
|
||||
{
|
||||
*error = m_lastError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
m_lastError.clear();
|
||||
Q_EMIT dataChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScheduleService::updateProject(const QString& projectId,
|
||||
const QString& title,
|
||||
const QString& description,
|
||||
const QDate& deadline,
|
||||
QString* error)
|
||||
{
|
||||
auto project = m_store.projectById(projectId);
|
||||
if (!project.has_value())
|
||||
{
|
||||
m_lastError = QStringLiteral("长期项目不存在: %1").arg(projectId);
|
||||
if (error)
|
||||
{
|
||||
*error = m_lastError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (title.trimmed().isEmpty() || !deadline.isValid())
|
||||
{
|
||||
m_lastError = QStringLiteral("长期项目标题或截止日期无效");
|
||||
if (error)
|
||||
{
|
||||
*error = m_lastError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
project->title = title.trimmed().left(200);
|
||||
project->description = description.trimmed().left(2000);
|
||||
project->deadline = deadline;
|
||||
project->updatedAt = QDateTime::currentDateTime();
|
||||
project->version += 1;
|
||||
project->deviceId = m_deviceId;
|
||||
if (!m_store.updateProject(*project))
|
||||
{
|
||||
m_lastError = m_store.lastError();
|
||||
if (error)
|
||||
{
|
||||
*error = m_lastError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
m_lastError.clear();
|
||||
Q_EMIT dataChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScheduleService::setProjectStatus(const QString& projectId, const QString& status, QString* error)
|
||||
{
|
||||
if (status != QStringLiteral("active") && status != QStringLiteral("done"))
|
||||
{
|
||||
m_lastError = QStringLiteral("非法长期项目状态: %1").arg(status);
|
||||
if (error)
|
||||
{
|
||||
*error = m_lastError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
auto project = m_store.projectById(projectId);
|
||||
if (!project.has_value())
|
||||
{
|
||||
m_lastError = QStringLiteral("长期项目不存在: %1").arg(projectId);
|
||||
if (error)
|
||||
{
|
||||
*error = m_lastError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
project->status = status;
|
||||
project->updatedAt = QDateTime::currentDateTime();
|
||||
project->version += 1;
|
||||
project->deviceId = m_deviceId;
|
||||
if (!m_store.updateProject(*project))
|
||||
{
|
||||
m_lastError = m_store.lastError();
|
||||
if (error)
|
||||
{
|
||||
*error = m_lastError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
m_lastError.clear();
|
||||
Q_EMIT dataChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScheduleService::deleteProject(const QString& projectId, QString* error)
|
||||
{
|
||||
if (!m_store.deleteProject(projectId))
|
||||
{
|
||||
m_lastError = m_store.lastError();
|
||||
if (error)
|
||||
{
|
||||
*error = m_lastError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
m_lastError.clear();
|
||||
Q_EMIT dataChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
QVector<Project> ScheduleService::projects() const
|
||||
{
|
||||
return m_store.projects(false);
|
||||
}
|
||||
|
||||
std::optional<Project> ScheduleService::projectById(const QString& projectId) const
|
||||
{
|
||||
return m_store.projectById(projectId);
|
||||
}
|
||||
|
||||
bool ScheduleService::updateBlock(const QString& blockId,
|
||||
const QString& title,
|
||||
const QDateTime& start,
|
||||
@@ -688,10 +848,15 @@ bool ScheduleService::applyProposedDiff(const ProposedDiff& diff,
|
||||
QString blockId;
|
||||
QString taskId;
|
||||
};
|
||||
struct PendingProject
|
||||
{
|
||||
Project project;
|
||||
};
|
||||
|
||||
QVector<PendingCreate> creates;
|
||||
QVector<PendingUpdate> updates;
|
||||
QVector<PendingDelete> deletes;
|
||||
QVector<PendingProject> projects;
|
||||
QSet<QString> updatedBlockIds;
|
||||
QSet<QString> deletedBlockIds;
|
||||
const QDateTime now = QDateTime::currentDateTime();
|
||||
@@ -933,7 +1098,44 @@ bool ScheduleService::applyProposedDiff(const ProposedDiff& diff,
|
||||
deletedBlockIds.insert(blockId);
|
||||
}
|
||||
|
||||
if (creates.isEmpty() && updates.isEmpty() && deletes.isEmpty())
|
||||
const QJsonArray projectArray = diff.payload.value(QStringLiteral("projects")).toArray();
|
||||
for (const QJsonValue& value : projectArray)
|
||||
{
|
||||
const QJsonObject object = value.toObject();
|
||||
const QString tempId = object.value(QStringLiteral("temp_id")).toString();
|
||||
if (!accepted.contains(tempId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
const QString title = object.value(QStringLiteral("title")).toString().trimmed();
|
||||
const QString deadlineText = object.value(QStringLiteral("deadline")).toString().trimmed();
|
||||
const QDate deadline = QDate::fromString(deadlineText.left(10), Qt::ISODate);
|
||||
if (title.isEmpty() || !deadline.isValid())
|
||||
{
|
||||
m_lastError = QStringLiteral("AI 提议中的长期项目数据无效: %1").arg(tempId);
|
||||
if (error)
|
||||
{
|
||||
*error = m_lastError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Project project;
|
||||
project.id = newId();
|
||||
project.title = title.left(200);
|
||||
project.description = object.value(QStringLiteral("description")).toString().left(2000);
|
||||
project.source = QStringLiteral("ai_chat");
|
||||
project.sourceRef = object.value(QStringLiteral("source_ref")).toString();
|
||||
project.deadline = deadline;
|
||||
project.priority = qBound(1, object.value(QStringLiteral("priority")).toInt(2), 5);
|
||||
project.status = QStringLiteral("active");
|
||||
project.createdAt = now;
|
||||
project.updatedAt = now;
|
||||
project.version = 0;
|
||||
project.deviceId = m_deviceId;
|
||||
projects.append({project});
|
||||
}
|
||||
|
||||
if (creates.isEmpty() && updates.isEmpty() && deletes.isEmpty() && projects.isEmpty())
|
||||
{
|
||||
m_lastError = QStringLiteral("AI 提议中没有选中的有效操作");
|
||||
if (error)
|
||||
@@ -1121,6 +1323,20 @@ bool ScheduleService::applyProposedDiff(const ProposedDiff& diff,
|
||||
}
|
||||
}
|
||||
|
||||
for (const PendingProject& entry : projects)
|
||||
{
|
||||
if (!m_store.insertProject(entry.project))
|
||||
{
|
||||
m_store.rollback();
|
||||
m_lastError = m_store.lastError();
|
||||
if (error)
|
||||
{
|
||||
*error = m_lastError;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_store.commit())
|
||||
{
|
||||
m_store.rollback();
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "core/DailyInsights.h"
|
||||
#include "core/EnergyProfile.h"
|
||||
#include "core/Project.h"
|
||||
#include "core/ProposedDiff.h"
|
||||
#include "core/Recurrence.h"
|
||||
#include "core/ScheduleItem.h"
|
||||
@@ -29,6 +30,19 @@ public:
|
||||
const QDateTime& start,
|
||||
const QDateTime& end,
|
||||
QString* error = nullptr);
|
||||
bool createProject(const QString& title,
|
||||
const QString& description,
|
||||
const QDate& deadline,
|
||||
QString* error = nullptr);
|
||||
bool updateProject(const QString& projectId,
|
||||
const QString& title,
|
||||
const QString& description,
|
||||
const QDate& deadline,
|
||||
QString* error = nullptr);
|
||||
bool setProjectStatus(const QString& projectId, const QString& status, QString* error = nullptr);
|
||||
bool deleteProject(const QString& projectId, QString* error = nullptr);
|
||||
QVector<Project> projects() const;
|
||||
std::optional<Project> projectById(const QString& projectId) const;
|
||||
bool createRecurringBlock(const QString& title,
|
||||
const QDateTime& start,
|
||||
const QDateTime& end,
|
||||
|
||||
@@ -180,7 +180,52 @@ QVector<Migration> all()
|
||||
" VALUES('timeblock', OLD.id, 'delete', %1, %2); END")
|
||||
.arg(blockDeletePayload, nowExpression),
|
||||
};
|
||||
migrations.append(v3);
|
||||
|
||||
Migration v4;
|
||||
v4.version = 4;
|
||||
v4.name = QStringLiteral("long_term_projects");
|
||||
const QString projectJson = QStringLiteral(
|
||||
"json_object('id',%1.id,'title',%1.title,'description',%1.description,'source',%1.source,"
|
||||
"'source_ref',%1.source_ref,'deadline',%1.deadline,'priority',%1.priority,'status',%1.status,"
|
||||
"'created_at',%1.created_at,'updated_at',%1.updated_at,'version',%1.version,'device_id',%1.device_id)");
|
||||
const QString projectNow = QStringLiteral("strftime('%Y-%m-%dT%H:%M:%fZ','now')");
|
||||
v4.statements = {
|
||||
QStringLiteral(
|
||||
"CREATE TABLE IF NOT EXISTS project ("
|
||||
" id TEXT PRIMARY KEY,"
|
||||
" title TEXT NOT NULL,"
|
||||
" description TEXT,"
|
||||
" source TEXT,"
|
||||
" source_ref TEXT,"
|
||||
" deadline TEXT,"
|
||||
" priority INTEGER DEFAULT 1,"
|
||||
" status TEXT DEFAULT 'active',"
|
||||
" created_at TEXT NOT NULL,"
|
||||
" updated_at TEXT NOT NULL,"
|
||||
" version INTEGER DEFAULT 0,"
|
||||
" device_id TEXT NOT NULL"
|
||||
")"),
|
||||
QStringLiteral("CREATE INDEX IF NOT EXISTS idx_project_deadline ON project(status, deadline)"),
|
||||
QStringLiteral(
|
||||
"CREATE TRIGGER IF NOT EXISTS trg_project_outbox_insert AFTER INSERT ON project "
|
||||
"WHEN NOT EXISTS (SELECT 1 FROM sync_remote_apply) BEGIN "
|
||||
" INSERT INTO sync_outbox(entity_type, entity_id, op, payload, created_at) "
|
||||
" VALUES('project', NEW.id, 'upsert', %1, NEW.updated_at); END")
|
||||
.arg(projectJson.arg("NEW")),
|
||||
QStringLiteral(
|
||||
"CREATE TRIGGER IF NOT EXISTS trg_project_outbox_update AFTER UPDATE ON project "
|
||||
"WHEN NOT EXISTS (SELECT 1 FROM sync_remote_apply) BEGIN "
|
||||
" INSERT INTO sync_outbox(entity_type, entity_id, op, payload, created_at) "
|
||||
" VALUES('project', NEW.id, 'upsert', %1, NEW.updated_at); END")
|
||||
.arg(projectJson.arg("NEW")),
|
||||
QStringLiteral(
|
||||
"CREATE TRIGGER IF NOT EXISTS trg_project_outbox_delete AFTER DELETE ON project "
|
||||
"WHEN NOT EXISTS (SELECT 1 FROM sync_remote_apply) BEGIN "
|
||||
" INSERT INTO sync_outbox(entity_type, entity_id, op, payload, created_at) "
|
||||
" VALUES('project', OLD.id, 'delete', json_set(%1, '$.updated_at', %2), %2); END")
|
||||
.arg(projectJson.arg("OLD"), projectNow),
|
||||
};
|
||||
migrations.append(v4);
|
||||
|
||||
return migrations;
|
||||
}
|
||||
|
||||
@@ -87,6 +87,36 @@ TimeBlock mapTimeBlock(const QSqlQuery& query, int offset)
|
||||
return block;
|
||||
}
|
||||
|
||||
Project mapProject(const QSqlQuery& query, int offset = 0)
|
||||
{
|
||||
Project project;
|
||||
project.id = query.value(offset + 0).toString();
|
||||
project.title = query.value(offset + 1).toString();
|
||||
project.description = query.value(offset + 2).toString();
|
||||
project.source = query.value(offset + 3).toString();
|
||||
project.sourceRef = query.value(offset + 4).toString();
|
||||
const QVariant deadline = query.value(offset + 5);
|
||||
if (!deadline.isNull())
|
||||
{
|
||||
const QDate date = QDate::fromString(deadline.toString(), Qt::ISODate);
|
||||
if (date.isValid())
|
||||
{
|
||||
project.deadline = date;
|
||||
}
|
||||
}
|
||||
project.priority = query.value(offset + 6).toInt();
|
||||
project.status = query.value(offset + 7).toString();
|
||||
project.createdAt = DateTimeUtils::fromDb(query.value(offset + 8).toString());
|
||||
project.updatedAt = DateTimeUtils::fromDb(query.value(offset + 9).toString());
|
||||
project.version = query.value(offset + 10).toInt();
|
||||
project.deviceId = query.value(offset + 11).toString();
|
||||
return project;
|
||||
}
|
||||
|
||||
constexpr const char* kProjectColumns =
|
||||
"p.id, p.title, p.description, p.source, p.source_ref, p.deadline, p.priority, p.status, "
|
||||
"p.created_at, p.updated_at, p.version, p.device_id";
|
||||
|
||||
constexpr const char* kTaskColumns =
|
||||
"t.id, t.title, t.description, t.source, t.source_ref, t.estimated_min, t.energy_req, "
|
||||
"t.deadline, t.priority, t.status, t.created_at, t.updated_at, t.version, t.device_id";
|
||||
@@ -502,6 +532,141 @@ bool SqliteStore::hasBlocksForTask(const QString& taskId)
|
||||
return query.next();
|
||||
}
|
||||
|
||||
bool SqliteStore::insertProject(const Project& project)
|
||||
{
|
||||
m_lastError.clear();
|
||||
if (!isOpenInternal())
|
||||
{
|
||||
return setError(QStringLiteral("数据库未打开"));
|
||||
}
|
||||
QSqlQuery query(m_database);
|
||||
query.prepare(QStringLiteral(
|
||||
"INSERT INTO project (id, title, description, source, source_ref, deadline, priority, "
|
||||
"status, created_at, updated_at, version, device_id) "
|
||||
"VALUES (:id, :title, :description, :source, :source_ref, :deadline, :priority, "
|
||||
":status, :created_at, :updated_at, :version, :device_id)"));
|
||||
query.bindValue(QStringLiteral(":id"), project.id);
|
||||
query.bindValue(QStringLiteral(":title"), project.title);
|
||||
query.bindValue(QStringLiteral(":description"), project.description);
|
||||
query.bindValue(QStringLiteral(":source"), project.source);
|
||||
query.bindValue(QStringLiteral(":source_ref"), project.sourceRef);
|
||||
query.bindValue(QStringLiteral(":deadline"),
|
||||
project.deadline.has_value() ? QVariant(project.deadline->toString(Qt::ISODate))
|
||||
: QVariant());
|
||||
query.bindValue(QStringLiteral(":priority"), project.priority);
|
||||
query.bindValue(QStringLiteral(":status"), project.status);
|
||||
query.bindValue(QStringLiteral(":created_at"), DateTimeUtils::toDb(project.createdAt));
|
||||
query.bindValue(QStringLiteral(":updated_at"), DateTimeUtils::toDb(project.updatedAt));
|
||||
query.bindValue(QStringLiteral(":version"), project.version);
|
||||
query.bindValue(QStringLiteral(":device_id"), project.deviceId);
|
||||
if (!query.exec())
|
||||
{
|
||||
return setError(QStringLiteral("插入长期项目失败: %1").arg(query.lastError().text()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SqliteStore::updateProject(const Project& project)
|
||||
{
|
||||
m_lastError.clear();
|
||||
if (!isOpenInternal())
|
||||
{
|
||||
return setError(QStringLiteral("数据库未打开"));
|
||||
}
|
||||
QSqlQuery query(m_database);
|
||||
query.prepare(QStringLiteral(
|
||||
"UPDATE project SET title = :title, description = :description, source = :source, "
|
||||
"source_ref = :source_ref, deadline = :deadline, priority = :priority, status = :status, "
|
||||
"updated_at = :updated_at, version = :version, device_id = :device_id WHERE id = :id"));
|
||||
query.bindValue(QStringLiteral(":title"), project.title);
|
||||
query.bindValue(QStringLiteral(":description"), project.description);
|
||||
query.bindValue(QStringLiteral(":source"), project.source);
|
||||
query.bindValue(QStringLiteral(":source_ref"), project.sourceRef);
|
||||
query.bindValue(QStringLiteral(":deadline"),
|
||||
project.deadline.has_value() ? QVariant(project.deadline->toString(Qt::ISODate))
|
||||
: QVariant());
|
||||
query.bindValue(QStringLiteral(":priority"), project.priority);
|
||||
query.bindValue(QStringLiteral(":status"), project.status);
|
||||
query.bindValue(QStringLiteral(":updated_at"), DateTimeUtils::toDb(project.updatedAt));
|
||||
query.bindValue(QStringLiteral(":version"), project.version);
|
||||
query.bindValue(QStringLiteral(":device_id"), project.deviceId);
|
||||
query.bindValue(QStringLiteral(":id"), project.id);
|
||||
if (!query.exec())
|
||||
{
|
||||
return setError(QStringLiteral("更新长期项目失败: %1").arg(query.lastError().text()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SqliteStore::deleteProject(const QString& id)
|
||||
{
|
||||
m_lastError.clear();
|
||||
if (!isOpenInternal())
|
||||
{
|
||||
return setError(QStringLiteral("数据库未打开"));
|
||||
}
|
||||
QSqlQuery query(m_database);
|
||||
query.prepare(QStringLiteral("DELETE FROM project WHERE id = :id"));
|
||||
query.bindValue(QStringLiteral(":id"), id);
|
||||
if (!query.exec())
|
||||
{
|
||||
return setError(QStringLiteral("删除长期项目失败: %1").arg(query.lastError().text()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::optional<Project> SqliteStore::projectById(const QString& id) const
|
||||
{
|
||||
m_lastError.clear();
|
||||
if (!isOpenInternal())
|
||||
{
|
||||
setError(QStringLiteral("数据库未打开"));
|
||||
return std::nullopt;
|
||||
}
|
||||
QSqlQuery query(m_database);
|
||||
query.prepare(QStringLiteral("SELECT %1 FROM project p WHERE p.id = :id")
|
||||
.arg(QString::fromLatin1(kProjectColumns)));
|
||||
query.bindValue(QStringLiteral(":id"), id);
|
||||
if (!query.exec())
|
||||
{
|
||||
setError(QStringLiteral("查询长期项目失败: %1").arg(query.lastError().text()));
|
||||
return std::nullopt;
|
||||
}
|
||||
if (!query.next())
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
return mapProject(query);
|
||||
}
|
||||
|
||||
QVector<Project> SqliteStore::projects(bool includeDone) const
|
||||
{
|
||||
m_lastError.clear();
|
||||
QVector<Project> result;
|
||||
if (!isOpenInternal())
|
||||
{
|
||||
setError(QStringLiteral("数据库未打开"));
|
||||
return result;
|
||||
}
|
||||
QSqlQuery query(m_database);
|
||||
const QString sql = QStringLiteral(
|
||||
"SELECT %1 FROM project p %2 "
|
||||
"ORDER BY CASE WHEN p.deadline IS NULL THEN 1 ELSE 0 END, "
|
||||
"p.deadline ASC, p.priority DESC, p.title ASC")
|
||||
.arg(QString::fromLatin1(kProjectColumns),
|
||||
includeDone ? QString() : QStringLiteral("WHERE p.status = 'active'"));
|
||||
if (!query.exec(sql))
|
||||
{
|
||||
setError(QStringLiteral("查询长期项目失败: %1").arg(query.lastError().text()));
|
||||
return result;
|
||||
}
|
||||
while (query.next())
|
||||
{
|
||||
result.append(mapProject(query));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool SqliteStore::insertTimeBlock(const TimeBlock& block)
|
||||
{
|
||||
m_lastError.clear();
|
||||
@@ -916,7 +1081,9 @@ bool SqliteStore::applyRemoteChange(const RemoteChange& change, QString* error)
|
||||
{
|
||||
return setError(QStringLiteral("数据库未打开"));
|
||||
}
|
||||
if (change.entityType != QStringLiteral("task") && change.entityType != QStringLiteral("timeblock"))
|
||||
if (change.entityType != QStringLiteral("task") &&
|
||||
change.entityType != QStringLiteral("timeblock") &&
|
||||
change.entityType != QStringLiteral("project"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -931,7 +1098,8 @@ bool SqliteStore::applyRemoteChange(const RemoteChange& change, QString* error)
|
||||
QSqlQuery current(m_database);
|
||||
const QString table = change.entityType == QStringLiteral("task")
|
||||
? QStringLiteral("task")
|
||||
: QStringLiteral("timeblock");
|
||||
: (change.entityType == QStringLiteral("project") ? QStringLiteral("project")
|
||||
: QStringLiteral("timeblock"));
|
||||
current.prepare(QStringLiteral("SELECT updated_at FROM %1 WHERE id = :id").arg(table));
|
||||
current.bindValue(QStringLiteral(":id"), change.entityId);
|
||||
if (!current.exec())
|
||||
@@ -959,7 +1127,8 @@ bool SqliteStore::applyRemoteChange(const RemoteChange& change, QString* error)
|
||||
|
||||
const QString table = change.entityType == QStringLiteral("task")
|
||||
? QStringLiteral("task")
|
||||
: QStringLiteral("timeblock");
|
||||
: (change.entityType == QStringLiteral("project") ? QStringLiteral("project")
|
||||
: QStringLiteral("timeblock"));
|
||||
QSqlQuery current(m_database);
|
||||
current.prepare(QStringLiteral("SELECT updated_at FROM %1 WHERE id = :id").arg(table));
|
||||
current.bindValue(QStringLiteral(":id"), change.entityId);
|
||||
@@ -1028,6 +1197,40 @@ bool SqliteStore::applyRemoteChange(const RemoteChange& change, QString* error)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (change.entityType == QStringLiteral("project"))
|
||||
{
|
||||
const QJsonObject object = change.payload;
|
||||
QSqlQuery upsert(m_database);
|
||||
upsert.prepare(QStringLiteral(
|
||||
"INSERT INTO project (id, title, description, source, source_ref, deadline, priority, "
|
||||
"status, created_at, updated_at, version, device_id) "
|
||||
"VALUES (:id, :title, :description, :source, :source_ref, :deadline, :priority, "
|
||||
":status, :created_at, :updated_at, :version, :device_id) "
|
||||
"ON CONFLICT(id) DO UPDATE SET title=excluded.title, description=excluded.description, "
|
||||
"source=excluded.source, source_ref=excluded.source_ref, deadline=excluded.deadline, "
|
||||
"priority=excluded.priority, status=excluded.status, updated_at=excluded.updated_at, "
|
||||
"version=excluded.version, device_id=excluded.device_id"));
|
||||
upsert.bindValue(QStringLiteral(":id"), change.entityId);
|
||||
upsert.bindValue(QStringLiteral(":title"),
|
||||
jsonString(object, "title").isValid() ? jsonString(object, "title")
|
||||
: QVariant(QStringLiteral("未命名项目")));
|
||||
upsert.bindValue(QStringLiteral(":description"), jsonString(object, "description"));
|
||||
upsert.bindValue(QStringLiteral(":source"), jsonString(object, "source"));
|
||||
upsert.bindValue(QStringLiteral(":source_ref"), jsonString(object, "source_ref"));
|
||||
upsert.bindValue(QStringLiteral(":deadline"), jsonString(object, "deadline"));
|
||||
upsert.bindValue(QStringLiteral(":priority"), jsonInt(object, "priority"));
|
||||
upsert.bindValue(QStringLiteral(":status"), jsonString(object, "status"));
|
||||
upsert.bindValue(QStringLiteral(":created_at"), jsonString(object, "created_at"));
|
||||
upsert.bindValue(QStringLiteral(":updated_at"), remoteTime);
|
||||
upsert.bindValue(QStringLiteral(":version"), change.version);
|
||||
upsert.bindValue(QStringLiteral(":device_id"), change.deviceId);
|
||||
if (!upsert.exec())
|
||||
{
|
||||
return setError(QStringLiteral("应用远程长期项目失败: %1").arg(upsert.lastError().text()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// timeblock
|
||||
const QJsonObject object = change.payload;
|
||||
const QString taskId = object.value(QStringLiteral("task_id")).toString();
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <optional>
|
||||
|
||||
#include "core/EnergyProfile.h"
|
||||
#include "core/Project.h"
|
||||
#include "core/ProposedDiff.h"
|
||||
#include "core/Recurrence.h"
|
||||
#include "core/SyncTypes.h"
|
||||
@@ -46,6 +47,12 @@ public:
|
||||
bool insertRecurrence(const Recurrence& recurrence);
|
||||
std::optional<Recurrence> recurrenceForTask(const QString& taskId) const;
|
||||
|
||||
bool insertProject(const Project& project);
|
||||
bool updateProject(const Project& project);
|
||||
bool deleteProject(const QString& id);
|
||||
std::optional<Project> projectById(const QString& id) const;
|
||||
QVector<Project> projects(bool includeDone = false) const;
|
||||
|
||||
bool insertTimeBlock(const TimeBlock& block);
|
||||
bool updateTimeBlock(const TimeBlock& block);
|
||||
std::optional<TimeBlock> timeBlockById(const QString& id);
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "ui/MainWindow.h"
|
||||
#include "ui/dialogs/BlockEditDialog.h"
|
||||
#include "ui/dialogs/DailyReviewDialog.h"
|
||||
#include "ui/dialogs/ProjectDialog.h"
|
||||
#include "ui/dialogs/SettingsDialog.h"
|
||||
#include "ui/panels/ChatPanel.h"
|
||||
#include "ui/panels/TodayPanel.h"
|
||||
@@ -266,6 +267,22 @@ void CompactWindow::connectSignals()
|
||||
}
|
||||
});
|
||||
connect(m_todayPanel, &TodayPanel::reviewRequested, this, &CompactWindow::openDailyReview);
|
||||
connect(m_todayPanel, &TodayPanel::newProjectRequested, this, &CompactWindow::openNewProject);
|
||||
connect(m_todayPanel, &TodayPanel::editProjectRequested, this, &CompactWindow::openEditProject);
|
||||
connect(m_todayPanel, &TodayPanel::projectStatusRequested, this, [this](const QString& id, const QString& status) {
|
||||
QString error;
|
||||
if (!m_scheduleService.setProjectStatus(id, status, &error))
|
||||
{
|
||||
showError(QStringLiteral("更新长期项目失败"), error);
|
||||
}
|
||||
});
|
||||
connect(m_todayPanel, &TodayPanel::deleteProjectRequested, this, [this](const QString& id) {
|
||||
QString error;
|
||||
if (!m_scheduleService.deleteProject(id, &error))
|
||||
{
|
||||
showError(QStringLiteral("删除长期项目失败"), error);
|
||||
}
|
||||
});
|
||||
|
||||
connect(&m_notificationService,
|
||||
&NotificationService::overdueListChanged,
|
||||
@@ -377,6 +394,7 @@ void CompactWindow::reloadToday()
|
||||
const QDateTime now = QDateTime::currentDateTime();
|
||||
m_todayPanel->setDate(today);
|
||||
m_todayPanel->setItems(m_todayItems, now);
|
||||
m_todayPanel->setProjects(m_scheduleService.projects());
|
||||
const QVector<Suggestion> suggestions = m_scheduleService.suggestions(now);
|
||||
m_todayPanel->setInsightText(
|
||||
suggestions.isEmpty() ? QString()
|
||||
@@ -420,6 +438,50 @@ void CompactWindow::openDailyReview()
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
void CompactWindow::openNewProject()
|
||||
{
|
||||
ProjectDialog dialog(m_tokens, this);
|
||||
dialog.moveToCenter();
|
||||
if (dialog.exec() != QDialog::Accepted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
QString error;
|
||||
if (!m_scheduleService.createProject(dialog.titleValue(),
|
||||
dialog.descriptionValue(),
|
||||
dialog.deadlineValue(),
|
||||
&error))
|
||||
{
|
||||
showError(QStringLiteral("创建长期项目失败"), error);
|
||||
}
|
||||
}
|
||||
|
||||
void CompactWindow::openEditProject(const QString& projectId)
|
||||
{
|
||||
const auto project = m_scheduleService.projectById(projectId);
|
||||
if (!project.has_value())
|
||||
{
|
||||
showError(QStringLiteral("编辑长期项目失败"), QStringLiteral("找不到该项目"));
|
||||
return;
|
||||
}
|
||||
ProjectDialog dialog(m_tokens, this);
|
||||
dialog.setValues(project->title, project->description, project->deadline.value_or(QDate()));
|
||||
dialog.moveToCenter();
|
||||
if (dialog.exec() != QDialog::Accepted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
QString error;
|
||||
if (!m_scheduleService.updateProject(projectId,
|
||||
dialog.titleValue(),
|
||||
dialog.descriptionValue(),
|
||||
dialog.deadlineValue(),
|
||||
&error))
|
||||
{
|
||||
showError(QStringLiteral("保存长期项目失败"), error);
|
||||
}
|
||||
}
|
||||
|
||||
void CompactWindow::updateSyncStatus(const QString& status)
|
||||
{
|
||||
if (!m_syncLabel)
|
||||
|
||||
@@ -65,6 +65,8 @@ private:
|
||||
void openSchedule();
|
||||
void openSettings();
|
||||
void openDailyReview();
|
||||
void openNewProject();
|
||||
void openEditProject(const QString& projectId);
|
||||
void openEditDialog(const QString& blockId);
|
||||
void showError(const QString& title, const QString& message);
|
||||
void updateSyncStatus(const QString& status);
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "sync/SyncService.h"
|
||||
#include "ui/dialogs/BlockEditDialog.h"
|
||||
#include "ui/dialogs/DailyReviewDialog.h"
|
||||
#include "ui/dialogs/ProjectDialog.h"
|
||||
#include "ui/dialogs/SearchDialog.h"
|
||||
#include "ui/dialogs/SettingsDialog.h"
|
||||
#include "ui/panels/TodayPanel.h"
|
||||
@@ -423,6 +424,22 @@ void MainWindow::connectSignals()
|
||||
m_grid->setFocus(Qt::OtherFocusReason);
|
||||
});
|
||||
connect(m_todayPanel, &TodayPanel::reviewRequested, this, &MainWindow::openDailyReview);
|
||||
connect(m_todayPanel, &TodayPanel::newProjectRequested, this, &MainWindow::openNewProject);
|
||||
connect(m_todayPanel, &TodayPanel::editProjectRequested, this, &MainWindow::openEditProject);
|
||||
connect(m_todayPanel, &TodayPanel::projectStatusRequested, this, [this](const QString& id, const QString& status) {
|
||||
QString error;
|
||||
if (!m_scheduleService.setProjectStatus(id, status, &error))
|
||||
{
|
||||
showError(QStringLiteral("更新长期项目失败"), error);
|
||||
}
|
||||
});
|
||||
connect(m_todayPanel, &TodayPanel::deleteProjectRequested, this, [this](const QString& id) {
|
||||
QString error;
|
||||
if (!m_scheduleService.deleteProject(id, &error))
|
||||
{
|
||||
showError(QStringLiteral("删除长期项目失败"), error);
|
||||
}
|
||||
});
|
||||
|
||||
connect(&m_notificationService,
|
||||
&NotificationService::overdueListChanged,
|
||||
@@ -626,6 +643,7 @@ void MainWindow::reloadCurrentView()
|
||||
|
||||
m_todayPanel->setDate(m_currentDate);
|
||||
m_todayPanel->setItems(agendaItems, now);
|
||||
m_todayPanel->setProjects(m_scheduleService.projects());
|
||||
if (m_currentDate == QDate::currentDate())
|
||||
{
|
||||
const QVector<Suggestion> suggestions = m_scheduleService.suggestions(now);
|
||||
@@ -882,6 +900,50 @@ void MainWindow::openDailyReview()
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
void MainWindow::openNewProject()
|
||||
{
|
||||
ProjectDialog dialog(m_tokens, this);
|
||||
dialog.moveToCenter();
|
||||
if (dialog.exec() != QDialog::Accepted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
QString error;
|
||||
if (!m_scheduleService.createProject(dialog.titleValue(),
|
||||
dialog.descriptionValue(),
|
||||
dialog.deadlineValue(),
|
||||
&error))
|
||||
{
|
||||
showError(QStringLiteral("创建长期项目失败"), error);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::openEditProject(const QString& projectId)
|
||||
{
|
||||
const auto project = m_scheduleService.projectById(projectId);
|
||||
if (!project.has_value())
|
||||
{
|
||||
showError(QStringLiteral("编辑长期项目失败"), QStringLiteral("找不到该项目"));
|
||||
return;
|
||||
}
|
||||
ProjectDialog dialog(m_tokens, this);
|
||||
dialog.setValues(project->title, project->description, project->deadline.value_or(QDate()));
|
||||
dialog.moveToCenter();
|
||||
if (dialog.exec() != QDialog::Accepted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
QString error;
|
||||
if (!m_scheduleService.updateProject(projectId,
|
||||
dialog.titleValue(),
|
||||
dialog.descriptionValue(),
|
||||
dialog.deadlineValue(),
|
||||
&error))
|
||||
{
|
||||
showError(QStringLiteral("保存长期项目失败"), error);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::openSearch()
|
||||
{
|
||||
SearchDialog dialog(m_scheduleService,
|
||||
|
||||
@@ -91,6 +91,8 @@ private:
|
||||
void openEditDialog(const QString& blockId);
|
||||
void openSettings();
|
||||
void openDailyReview();
|
||||
void openNewProject();
|
||||
void openEditProject(const QString& projectId);
|
||||
void updateOverdueBanner(const QVector<ScheduleItem>& items);
|
||||
void showError(const QString& title, const QString& message);
|
||||
void updateSyncStatus(const QString& status);
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
#include "ProjectDialog.h"
|
||||
|
||||
#include <QDateEdit>
|
||||
#include <QFormLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "ElaLineEdit.h"
|
||||
#include "ElaPlainTextEdit.h"
|
||||
#include "ElaPushButton.h"
|
||||
#include "ElaText.h"
|
||||
|
||||
ProjectDialog::ProjectDialog(const ThemeTokens& tokens, QWidget* parent)
|
||||
: ElaDialog(parent)
|
||||
, m_errorColor(tokens.blockOverdueBorder.name())
|
||||
{
|
||||
setWindowTitle(QStringLiteral("新建长期项目"));
|
||||
setWindowButtonFlags(ElaAppBarType::CloseButtonHint);
|
||||
setMinimumWidth(460);
|
||||
resize(460, 390);
|
||||
|
||||
auto* root = new QVBoxLayout(this);
|
||||
root->setContentsMargins(22, 8, 22, 18);
|
||||
root->setSpacing(12);
|
||||
|
||||
auto* form = new QFormLayout();
|
||||
form->setLabelAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
form->setHorizontalSpacing(14);
|
||||
form->setVerticalSpacing(12);
|
||||
|
||||
auto* titleLabel = new ElaText(QStringLiteral("项目标题"), 13, this);
|
||||
m_titleEdit = new ElaLineEdit(this);
|
||||
m_titleEdit->setPlaceholderText(QStringLiteral("例如:完成飞行控制器项目"));
|
||||
m_titleEdit->setClearButtonEnabled(true);
|
||||
m_titleEdit->setMinimumHeight(34);
|
||||
|
||||
auto* descriptionLabel = new ElaText(QStringLiteral("说明"), 13, this);
|
||||
m_descriptionEdit = new ElaPlainTextEdit(this);
|
||||
m_descriptionEdit->setPlaceholderText(QStringLiteral("目标、范围或验收标准(可选)"));
|
||||
m_descriptionEdit->setMinimumHeight(130);
|
||||
|
||||
auto* deadlineLabel = new ElaText(QStringLiteral("模糊截止"), 13, this);
|
||||
m_deadlineEdit = new QDateEdit(this);
|
||||
m_deadlineEdit->setCalendarPopup(true);
|
||||
m_deadlineEdit->setDisplayFormat(QStringLiteral("yyyy-MM-dd"));
|
||||
m_deadlineEdit->setDate(QDate::currentDate().addMonths(1));
|
||||
m_deadlineEdit->setMinimumHeight(34);
|
||||
|
||||
form->addRow(titleLabel, m_titleEdit);
|
||||
form->addRow(descriptionLabel, m_descriptionEdit);
|
||||
form->addRow(deadlineLabel, m_deadlineEdit);
|
||||
root->addLayout(form);
|
||||
|
||||
m_errorLabel = new ElaText(this);
|
||||
m_errorLabel->setTextPixelSize(12);
|
||||
m_errorLabel->setStyleSheet(QStringLiteral("color:%1;").arg(m_errorColor));
|
||||
m_errorLabel->setMinimumHeight(18);
|
||||
root->addWidget(m_errorLabel);
|
||||
root->addStretch(1);
|
||||
|
||||
auto* buttonRow = new QHBoxLayout();
|
||||
buttonRow->addStretch(1);
|
||||
auto* cancel = new ElaPushButton(QStringLiteral("取消"), this);
|
||||
auto* save = new ElaPushButton(QStringLiteral("保存"), this);
|
||||
cancel->setFixedSize(88, 34);
|
||||
save->setFixedSize(88, 34);
|
||||
save->setDefault(true);
|
||||
buttonRow->addWidget(cancel);
|
||||
buttonRow->addWidget(save);
|
||||
root->addLayout(buttonRow);
|
||||
|
||||
connect(cancel, &ElaPushButton::clicked, this, &ProjectDialog::reject);
|
||||
connect(save, &ElaPushButton::clicked, this, &ProjectDialog::accept);
|
||||
}
|
||||
|
||||
void ProjectDialog::setValues(const QString& title, const QString& description, const QDate& deadline)
|
||||
{
|
||||
m_titleEdit->setText(title);
|
||||
m_descriptionEdit->setPlainText(description);
|
||||
if (deadline.isValid())
|
||||
{
|
||||
m_deadlineEdit->setDate(deadline);
|
||||
}
|
||||
m_titleEdit->setFocus();
|
||||
m_titleEdit->selectAll();
|
||||
}
|
||||
|
||||
QString ProjectDialog::titleValue() const
|
||||
{
|
||||
return m_titleEdit->text().trimmed();
|
||||
}
|
||||
|
||||
QString ProjectDialog::descriptionValue() const
|
||||
{
|
||||
return m_descriptionEdit->toPlainText().trimmed();
|
||||
}
|
||||
|
||||
QDate ProjectDialog::deadlineValue() const
|
||||
{
|
||||
return m_deadlineEdit->date();
|
||||
}
|
||||
|
||||
void ProjectDialog::updateError(const QString& message)
|
||||
{
|
||||
m_errorLabel->setText(message);
|
||||
}
|
||||
|
||||
void ProjectDialog::accept()
|
||||
{
|
||||
const QString title = titleValue();
|
||||
if (title.isEmpty())
|
||||
{
|
||||
updateError(QStringLiteral("请输入项目标题"));
|
||||
return;
|
||||
}
|
||||
if (!deadlineValue().isValid())
|
||||
{
|
||||
updateError(QStringLiteral("请选择截止日期"));
|
||||
return;
|
||||
}
|
||||
updateError(QString());
|
||||
QDialog::accept();
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDate>
|
||||
#include <QString>
|
||||
|
||||
#include "ElaDialog.h"
|
||||
#include "ui/theme/ThemeTokens.h"
|
||||
|
||||
class ElaLineEdit;
|
||||
class ElaPlainTextEdit;
|
||||
class ElaText;
|
||||
class QDateEdit;
|
||||
|
||||
/*
|
||||
* 类名: ProjectDialog
|
||||
* 功能: 手工创建/编辑长期项目(标题、说明、模糊截止日期)
|
||||
* 线程安全: 否;UI 线程
|
||||
*/
|
||||
class ProjectDialog : public ElaDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ProjectDialog(const ThemeTokens& tokens, QWidget* parent = nullptr);
|
||||
|
||||
void setValues(const QString& title, const QString& description, const QDate& deadline);
|
||||
QString titleValue() const;
|
||||
QString descriptionValue() const;
|
||||
QDate deadlineValue() const;
|
||||
|
||||
public slots:
|
||||
void accept() override;
|
||||
|
||||
private:
|
||||
void updateError(const QString& message);
|
||||
|
||||
ElaLineEdit* m_titleEdit = nullptr;
|
||||
ElaPlainTextEdit* m_descriptionEdit = nullptr;
|
||||
QDateEdit* m_deadlineEdit = nullptr;
|
||||
ElaText* m_errorLabel = nullptr;
|
||||
QString m_errorColor;
|
||||
};
|
||||
@@ -105,6 +105,7 @@ DiffPreviewCard::DiffPreviewCard(const ScheduleProposal& proposal,
|
||||
break;
|
||||
}
|
||||
}
|
||||
const int projectCount = proposal.projects.size();
|
||||
QStringList parts;
|
||||
if (creates > 0)
|
||||
{
|
||||
@@ -118,10 +119,14 @@ DiffPreviewCard::DiffPreviewCard(const ScheduleProposal& proposal,
|
||||
{
|
||||
parts.append(QStringLiteral("删除 %1").arg(deletes));
|
||||
}
|
||||
if (projectCount > 0)
|
||||
{
|
||||
parts.append(QStringLiteral("长期项目 %1").arg(projectCount));
|
||||
}
|
||||
|
||||
auto* header = new QHBoxLayout();
|
||||
header->setSpacing(8);
|
||||
auto* title = new QLabel(QStringLiteral("AI 日程建议"), this);
|
||||
auto* title = new QLabel(QStringLiteral("AI 计划建议"), this);
|
||||
title->setStyleSheet(QStringLiteral("background:transparent;border:none;color:%1;font-size:13px;font-weight:600;")
|
||||
.arg(m_tokens.textPrimary.name()));
|
||||
auto* count = new QLabel(parts.join(QStringLiteral(" · ")), this);
|
||||
@@ -140,6 +145,7 @@ DiffPreviewCard::DiffPreviewCard(const ScheduleProposal& proposal,
|
||||
check->setChecked(state == State::Pending);
|
||||
check->setEnabled(state == State::Pending);
|
||||
m_checks.append(check);
|
||||
m_tempIds.append(entry.tempId);
|
||||
|
||||
auto* textLayout = new QVBoxLayout();
|
||||
textLayout->setSpacing(1);
|
||||
@@ -232,6 +238,59 @@ DiffPreviewCard::DiffPreviewCard(const ScheduleProposal& proposal,
|
||||
connect(check, &ElaCheckBox::toggled, this, &DiffPreviewCard::updateAcceptEnabled);
|
||||
}
|
||||
|
||||
for (const ProposedProjectEntry& project : proposal.projects)
|
||||
{
|
||||
auto* row = new QHBoxLayout();
|
||||
row->setSpacing(8);
|
||||
auto* check = new ElaCheckBox(this);
|
||||
check->setChecked(state == State::Pending);
|
||||
check->setEnabled(state == State::Pending);
|
||||
m_checks.append(check);
|
||||
m_tempIds.append(project.tempId);
|
||||
|
||||
auto* textLayout = new QVBoxLayout();
|
||||
textLayout->setSpacing(1);
|
||||
auto* titleRow = new QHBoxLayout();
|
||||
titleRow->setSpacing(6);
|
||||
auto* opLabel = new QLabel(QStringLiteral("长期项目"), this);
|
||||
opLabel->setStyleSheet(
|
||||
QStringLiteral("background:transparent;border:none;color:%1;font-size:10px;font-weight:600;")
|
||||
.arg(m_tokens.diffAdd.name()));
|
||||
auto* titleLabel = new QLabel(project.title, this);
|
||||
titleLabel->setWordWrap(true);
|
||||
titleLabel->setStyleSheet(
|
||||
QStringLiteral("background:transparent;border:none;color:%1;font-size:12px;font-weight:600;")
|
||||
.arg(m_tokens.textPrimary.name()));
|
||||
titleRow->addWidget(opLabel, 0, Qt::AlignTop);
|
||||
titleRow->addWidget(titleLabel, 1);
|
||||
textLayout->addLayout(titleRow);
|
||||
if (project.deadline.has_value())
|
||||
{
|
||||
auto* deadline = new QLabel(
|
||||
QStringLiteral("截止 %1(剩余 %2 天)")
|
||||
.arg(project.deadline->toString(QStringLiteral("yyyy-MM-dd")))
|
||||
.arg(QDate::currentDate().daysTo(*project.deadline)),
|
||||
this);
|
||||
deadline->setStyleSheet(
|
||||
QStringLiteral("background:transparent;border:none;color:%1;font-size:11px;")
|
||||
.arg(m_tokens.textSecondary.name()));
|
||||
textLayout->addWidget(deadline);
|
||||
}
|
||||
if (!project.description.isEmpty())
|
||||
{
|
||||
auto* description = new QLabel(project.description, this);
|
||||
description->setWordWrap(true);
|
||||
description->setStyleSheet(
|
||||
QStringLiteral("background:transparent;border:none;color:%1;font-size:11px;")
|
||||
.arg(m_tokens.textMuted.name()));
|
||||
textLayout->addWidget(description);
|
||||
}
|
||||
row->addWidget(check, 0, Qt::AlignTop);
|
||||
row->addLayout(textLayout, 1);
|
||||
root->addLayout(row);
|
||||
connect(check, &ElaCheckBox::toggled, this, &DiffPreviewCard::updateAcceptEnabled);
|
||||
}
|
||||
|
||||
auto* buttonRow = new QHBoxLayout();
|
||||
buttonRow->setSpacing(8);
|
||||
buttonRow->addStretch(1);
|
||||
@@ -257,9 +316,9 @@ DiffPreviewCard::DiffPreviewCard(const ScheduleProposal& proposal,
|
||||
QStringList tempIds;
|
||||
for (int i = 0; i < m_checks.size(); ++i)
|
||||
{
|
||||
if (m_checks.at(i)->isChecked() && i < m_proposal.entries.size())
|
||||
if (m_checks.at(i)->isChecked() && i < m_tempIds.size())
|
||||
{
|
||||
tempIds.append(m_proposal.entries.at(i).tempId);
|
||||
tempIds.append(m_tempIds.at(i));
|
||||
}
|
||||
}
|
||||
setResolved(State::Applied);
|
||||
|
||||
@@ -45,6 +45,7 @@ private:
|
||||
ThemeTokens m_tokens;
|
||||
State m_state;
|
||||
QVector<ElaCheckBox*> m_checks;
|
||||
QStringList m_tempIds;
|
||||
ElaPushButton* m_acceptButton = nullptr;
|
||||
ElaPushButton* m_rejectButton = nullptr;
|
||||
QLabel* m_statusLabel = nullptr;
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
#include "ProjectCard.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QMouseEvent>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "ElaMenu.h"
|
||||
#include "ElaToolButton.h"
|
||||
|
||||
ProjectCard::ProjectCard(const Project& project, const ThemeTokens& tokens, QWidget* parent)
|
||||
: QFrame(parent)
|
||||
, m_project(project)
|
||||
, m_tokens(tokens)
|
||||
{
|
||||
setObjectName(QStringLiteral("ProjectCard"));
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
setStyleSheet(QStringLiteral(
|
||||
"QFrame#ProjectCard{background:%1;border:1px solid %2;border-left:3px solid %3;"
|
||||
"border-radius:9px;}"
|
||||
"QFrame#ProjectCard:hover{background:%4;}")
|
||||
.arg(m_tokens.cardBackground.name(),
|
||||
m_tokens.cardBorder.name(),
|
||||
m_tokens.accent.name(),
|
||||
m_tokens.cardHoverBackground.name()));
|
||||
|
||||
auto* row = new QHBoxLayout(this);
|
||||
row->setContentsMargins(10, 7, 6, 7);
|
||||
row->setSpacing(4);
|
||||
auto* textLayout = new QVBoxLayout();
|
||||
textLayout->setSpacing(2);
|
||||
|
||||
auto* title = new QLabel(m_project.title, this);
|
||||
title->setWordWrap(true);
|
||||
title->setStyleSheet(QStringLiteral("background:transparent;border:none;color:%1;font-size:12px;font-weight:600;")
|
||||
.arg(m_tokens.textPrimary.name()));
|
||||
auto* deadline = new QLabel(deadlineText(), this);
|
||||
const bool overdue = m_project.deadline.has_value() &&
|
||||
m_project.deadline->isValid() &&
|
||||
QDate::currentDate().daysTo(*m_project.deadline) < 0;
|
||||
deadline->setStyleSheet(QStringLiteral("background:transparent;border:none;color:%1;font-size:11px;")
|
||||
.arg(overdue ? m_tokens.blockOverdueBorder.name() : m_tokens.textMuted.name()));
|
||||
textLayout->addWidget(title);
|
||||
textLayout->addWidget(deadline);
|
||||
row->addLayout(textLayout, 1);
|
||||
|
||||
m_menuButton = new ElaToolButton(this);
|
||||
m_menuButton->setIsTransparent(true);
|
||||
m_menuButton->setFixedSize(26, 26);
|
||||
m_menuButton->setElaIcon(ElaIconType::EllipsisVertical);
|
||||
m_menuButton->setToolTip(QStringLiteral("项目操作"));
|
||||
auto* menu = new ElaMenu(this);
|
||||
QAction* edit = menu->addAction(QStringLiteral("编辑"));
|
||||
connect(edit, &QAction::triggered, this, [this]() { Q_EMIT editRequested(m_project.id); });
|
||||
QAction* done = menu->addAction(QStringLiteral("标记完成"));
|
||||
connect(done, &QAction::triggered, this, [this]() { Q_EMIT statusChangeRequested(m_project.id, QStringLiteral("done")); });
|
||||
menu->addSeparator();
|
||||
QAction* remove = menu->addAction(QStringLiteral("删除"));
|
||||
connect(remove, &QAction::triggered, this, [this]() { Q_EMIT deleteRequested(m_project.id); });
|
||||
m_menuButton->setMenu(menu);
|
||||
m_menuButton->setPopupMode(QToolButton::InstantPopup);
|
||||
row->addWidget(m_menuButton, 0, Qt::AlignTop);
|
||||
}
|
||||
|
||||
QString ProjectCard::deadlineText() const
|
||||
{
|
||||
if (!m_project.deadline.has_value() || !m_project.deadline->isValid())
|
||||
{
|
||||
return QStringLiteral("无截止日期");
|
||||
}
|
||||
const int days = QDate::currentDate().daysTo(*m_project.deadline);
|
||||
if (days < 0)
|
||||
{
|
||||
return QStringLiteral("截止 %1 · 已逾期 %2 天")
|
||||
.arg(m_project.deadline->toString(QStringLiteral("M月d日")))
|
||||
.arg(-days);
|
||||
}
|
||||
if (days == 0)
|
||||
{
|
||||
return QStringLiteral("截止 今天");
|
||||
}
|
||||
return QStringLiteral("截止 %1 · 剩余 %2 天")
|
||||
.arg(m_project.deadline->toString(QStringLiteral("M月d日")))
|
||||
.arg(days);
|
||||
}
|
||||
|
||||
void ProjectCard::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton && rect().contains(event->position().toPoint()))
|
||||
{
|
||||
Q_EMIT editRequested(m_project.id);
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
QFrame::mouseReleaseEvent(event);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <QFrame>
|
||||
|
||||
#include "core/Project.h"
|
||||
#include "ui/theme/ThemeTokens.h"
|
||||
|
||||
class ElaToolButton;
|
||||
|
||||
/*
|
||||
* 类名: ProjectCard
|
||||
* 功能: 长期项目卡片;显示模糊截止日期与剩余天数
|
||||
* 线程安全: 否;UI 线程
|
||||
*/
|
||||
class ProjectCard : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ProjectCard(const Project& project, const ThemeTokens& tokens, QWidget* parent = nullptr);
|
||||
|
||||
signals:
|
||||
void editRequested(const QString& projectId);
|
||||
void statusChangeRequested(const QString& projectId, const QString& status);
|
||||
void deleteRequested(const QString& projectId);
|
||||
|
||||
protected:
|
||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||
|
||||
private:
|
||||
QString deadlineText() const;
|
||||
|
||||
Project m_project;
|
||||
ThemeTokens m_tokens;
|
||||
ElaToolButton* m_menuButton = nullptr;
|
||||
};
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "ElaScrollArea.h"
|
||||
#include "ElaText.h"
|
||||
#include "ElaToolButton.h"
|
||||
#include "ProjectCard.h"
|
||||
#include "TodayItemCard.h"
|
||||
#include "ui/theme/AnimationUtils.h"
|
||||
|
||||
@@ -40,9 +41,17 @@ TodayPanel::TodayPanel(QWidget* parent)
|
||||
m_reviewButton->setToolTip(QStringLiteral("今日复盘 (Ctrl+R)"));
|
||||
connect(m_reviewButton, &ElaToolButton::clicked, this, &TodayPanel::reviewRequested);
|
||||
|
||||
m_newProjectButton = new ElaToolButton(this);
|
||||
m_newProjectButton->setIsTransparent(true);
|
||||
m_newProjectButton->setElaIcon(ElaIconType::FolderPlus);
|
||||
m_newProjectButton->setFixedSize(26, 26);
|
||||
m_newProjectButton->setToolTip(QStringLiteral("新建长期项目"));
|
||||
connect(m_newProjectButton, &ElaToolButton::clicked, this, &TodayPanel::newProjectRequested);
|
||||
|
||||
header->addWidget(m_titleLabel);
|
||||
header->addStretch(1);
|
||||
header->addWidget(m_countLabel, 0, Qt::AlignVCenter);
|
||||
header->addWidget(m_newProjectButton, 0, Qt::AlignVCenter);
|
||||
header->addWidget(m_reviewButton, 0, Qt::AlignVCenter);
|
||||
root->addLayout(header);
|
||||
|
||||
@@ -114,6 +123,12 @@ void TodayPanel::setItems(const QVector<ScheduleItem>& items, const QDateTime& n
|
||||
rebuild();
|
||||
}
|
||||
|
||||
void TodayPanel::setProjects(const QVector<Project>& projects)
|
||||
{
|
||||
m_projects = projects;
|
||||
rebuild();
|
||||
}
|
||||
|
||||
void TodayPanel::clearLayout(QVBoxLayout* layout)
|
||||
{
|
||||
while (QLayoutItem* item = layout->takeAt(0))
|
||||
@@ -199,20 +214,32 @@ void TodayPanel::rebuild()
|
||||
return a.block.id < b.block.id;
|
||||
});
|
||||
|
||||
if (!m_projects.isEmpty())
|
||||
{
|
||||
auto* section = new ElaText(QStringLiteral("长期项目 · %1").arg(m_projects.size()), 13, m_listWidget);
|
||||
QFont sectionFont = section->font();
|
||||
sectionFont.setWeight(QFont::DemiBold);
|
||||
section->setFont(sectionFont);
|
||||
section->setContentsMargins(2, 8, 0, 2);
|
||||
m_listLayout->addWidget(section);
|
||||
for (const Project& project : m_projects)
|
||||
{
|
||||
auto* card = new ProjectCard(project, m_tokens, m_listWidget);
|
||||
connect(card, &ProjectCard::editRequested, this, &TodayPanel::editProjectRequested);
|
||||
connect(card, &ProjectCard::statusChangeRequested, this, &TodayPanel::projectStatusRequested);
|
||||
connect(card, &ProjectCard::deleteRequested, this, &TodayPanel::deleteProjectRequested);
|
||||
m_listLayout->addWidget(card);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (sorted.isEmpty())
|
||||
{
|
||||
auto* empty = new ElaText(QStringLiteral("今天还没有安排\n双击时间网格即可新建"), 13, m_listWidget);
|
||||
empty->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
empty->setMinimumHeight(120);
|
||||
empty->setMinimumHeight(90);
|
||||
empty->setTextStyle(ElaTextType::Caption);
|
||||
m_listLayout->addWidget(empty);
|
||||
m_listLayout->addStretch(1);
|
||||
if (m_renderedCount != 0)
|
||||
{
|
||||
m_renderedCount = 0;
|
||||
AnimationUtils::fadeIn(m_listWidget, 150);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (const ScheduleItem& item : sorted)
|
||||
@@ -225,10 +252,12 @@ void TodayPanel::rebuild()
|
||||
connect(card, &TodayItemCard::deleteRequested, this, &TodayPanel::deleteRequested);
|
||||
m_listLayout->addWidget(card);
|
||||
}
|
||||
|
||||
m_listLayout->addStretch(1);
|
||||
if (m_renderedCount != sorted.size())
|
||||
const int renderedCount = sorted.size() + m_projects.size();
|
||||
if (m_renderedCount != renderedCount)
|
||||
{
|
||||
m_renderedCount = sorted.size();
|
||||
m_renderedCount = renderedCount;
|
||||
AnimationUtils::fadeIn(m_listWidget, 150);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QVector>
|
||||
#include <QWidget>
|
||||
|
||||
#include "core/Project.h"
|
||||
#include "core/ScheduleItem.h"
|
||||
#include "ui/theme/ThemeTokens.h"
|
||||
|
||||
@@ -27,6 +28,7 @@ public:
|
||||
void setTokens(const ThemeTokens& tokens);
|
||||
void setDate(const QDate& date);
|
||||
void setItems(const QVector<ScheduleItem>& items, const QDateTime& now);
|
||||
void setProjects(const QVector<Project>& projects);
|
||||
void setInsightText(const QString& text);
|
||||
|
||||
signals:
|
||||
@@ -36,6 +38,10 @@ signals:
|
||||
void deleteRequested(const QString& blockId);
|
||||
void focusRequested(const QString& blockId);
|
||||
void reviewRequested();
|
||||
void newProjectRequested();
|
||||
void editProjectRequested(const QString& projectId);
|
||||
void projectStatusRequested(const QString& projectId, const QString& status);
|
||||
void deleteProjectRequested(const QString& projectId);
|
||||
|
||||
private:
|
||||
void rebuild();
|
||||
@@ -43,12 +49,14 @@ private:
|
||||
|
||||
ThemeTokens m_tokens;
|
||||
QVector<ScheduleItem> m_items;
|
||||
QVector<Project> m_projects;
|
||||
QDateTime m_now;
|
||||
|
||||
ElaText* m_titleLabel = nullptr;
|
||||
ElaText* m_countLabel = nullptr;
|
||||
ElaText* m_insightLabel = nullptr;
|
||||
ElaToolButton* m_reviewButton = nullptr;
|
||||
ElaToolButton* m_newProjectButton = nullptr;
|
||||
ElaScrollArea* m_scrollArea = nullptr;
|
||||
QWidget* m_listWidget = nullptr;
|
||||
QVBoxLayout* m_listLayout = nullptr;
|
||||
|
||||
@@ -82,6 +82,7 @@ private slots:
|
||||
void forcesSplitWhenUserAllowsIt();
|
||||
void localDeleteAllMeetingsFallback();
|
||||
void retriesNoDiffActionableRequest();
|
||||
void createsLongTermProjectFromOperation();
|
||||
};
|
||||
|
||||
namespace
|
||||
@@ -742,5 +743,41 @@ void TestAI::retriesNoDiffActionableRequest()
|
||||
QVERIFY(proposal.entries.first().title == QStringLiteral("深度工作"));
|
||||
}
|
||||
|
||||
void TestAI::createsLongTermProjectFromOperation()
|
||||
{
|
||||
Context context;
|
||||
QVERIFY(context.initialize());
|
||||
|
||||
const QDate deadline = QDate::currentDate().addDays(30);
|
||||
context.mock->responses = {
|
||||
diffResponse(
|
||||
QStringLiteral("这是一个跨月目标,我会把它作为长期项目管理。"),
|
||||
QStringLiteral(
|
||||
"{\"operations\":[{\"type\":\"project\",\"title\":\"飞行控制器项目\","
|
||||
"\"description\":\"完成固件、测试与文档\",\"deadline\":\"%1\",\"priority\":2}]}")
|
||||
.arg(deadline.toString(QStringLiteral("yyyy-MM-dd"))))};
|
||||
|
||||
QSignalSpy proposalSpy(context.ai.get(), &AIService::proposalReady);
|
||||
QSignalSpy failedSpy(context.ai.get(), &AIService::requestFailed);
|
||||
QSignalSpy appliedSpy(context.ai.get(), &AIService::diffApplied);
|
||||
context.ai->request(QStringLiteral("一个月内完成飞行控制器项目,先不用安排具体时间"));
|
||||
|
||||
QCOMPARE(failedSpy.count(), 0);
|
||||
QCOMPARE(proposalSpy.count(), 1);
|
||||
const ScheduleProposal proposal = proposalSpy.first().at(0).value<ScheduleProposal>();
|
||||
QCOMPARE(proposal.entries.size(), 0);
|
||||
QCOMPARE(proposal.projects.size(), 1);
|
||||
QCOMPARE(proposal.projects.first().title, QStringLiteral("飞行控制器项目"));
|
||||
QCOMPARE(proposal.projects.first().deadline.value(), deadline);
|
||||
|
||||
context.ai->applyDiff(proposal.diffId, {proposal.projects.first().tempId});
|
||||
QCOMPARE(appliedSpy.count(), 1);
|
||||
const QVector<Project> projects = context.service->projects();
|
||||
QCOMPARE(projects.size(), 1);
|
||||
QCOMPARE(projects.first().title, QStringLiteral("飞行控制器项目"));
|
||||
QCOMPARE(projects.first().deadline.value(), deadline);
|
||||
QCOMPARE(projects.first().source, QStringLiteral("ai_chat"));
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestAI)
|
||||
#include "test_ai.moc"
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "ui/MainWindow.h"
|
||||
#include "ui/dialogs/BlockEditDialog.h"
|
||||
#include "ui/dialogs/DailyReviewDialog.h"
|
||||
#include "ui/dialogs/ProjectDialog.h"
|
||||
#include "ui/dialogs/SearchDialog.h"
|
||||
#include "ui/dialogs/SettingsDialog.h"
|
||||
#include "ui/panels/DiffPreviewCard.h"
|
||||
@@ -68,6 +69,7 @@ private slots:
|
||||
void opensDailyReview();
|
||||
void searchDialogFindsSchedules();
|
||||
void repeatDialogShowsOptions();
|
||||
void projectDialogShowsFields();
|
||||
void aiChatShowsDiffAndAccepts();
|
||||
void aiChatShowsMultiOperationDiff();
|
||||
|
||||
@@ -123,6 +125,12 @@ void TestCompactWindow::createSampleData(ScheduleService& service, const QDate&
|
||||
QVERIFY(create(QStringLiteral("写周报"),
|
||||
QDateTime(today, QTime(9, 0), Qt::LocalTime),
|
||||
QDateTime(today, QTime(10, 30), Qt::LocalTime)));
|
||||
QString projectError;
|
||||
QVERIFY2(service.createProject(QStringLiteral("飞行控制器项目"),
|
||||
QStringLiteral("完成固件、测试与文档"),
|
||||
today.addDays(30),
|
||||
&projectError),
|
||||
qPrintable(projectError));
|
||||
QVERIFY(create(QStringLiteral("团队同步"),
|
||||
QDateTime(today, QTime(10, 0), Qt::LocalTime),
|
||||
QDateTime(today, QTime(11, 0), Qt::LocalTime)));
|
||||
@@ -379,6 +387,24 @@ void TestCompactWindow::repeatDialogShowsOptions()
|
||||
QCOMPARE(dialog.recurrenceUntil(), start.date().addMonths(3));
|
||||
}
|
||||
|
||||
void TestCompactWindow::projectDialogShowsFields()
|
||||
{
|
||||
ThemeManager theme(*m_settings);
|
||||
theme.initialize();
|
||||
ProjectDialog dialog(theme.tokens());
|
||||
const QDate deadline = QDate::currentDate().addDays(30);
|
||||
dialog.setValues(QStringLiteral("飞行控制器项目"),
|
||||
QStringLiteral("完成固件、测试与文档"),
|
||||
deadline);
|
||||
dialog.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&dialog));
|
||||
QTest::qWait(300);
|
||||
saveWindow(&dialog, QStringLiteral("project-dialog.png"));
|
||||
QCOMPARE(dialog.titleValue(), QStringLiteral("飞行控制器项目"));
|
||||
QCOMPARE(dialog.deadlineValue(), deadline);
|
||||
dialog.accept();
|
||||
}
|
||||
|
||||
void TestCompactWindow::aiChatShowsDiffAndAccepts()
|
||||
{
|
||||
QTemporaryDir databaseDir;
|
||||
|
||||
@@ -29,6 +29,7 @@ private slots:
|
||||
void searchFindsSchedules();
|
||||
void createsRecurringSchedules();
|
||||
void startAndLeadReminders();
|
||||
void projectCrudAndPersistence();
|
||||
};
|
||||
|
||||
namespace
|
||||
@@ -474,5 +475,45 @@ void TestServices::startAndLeadReminders()
|
||||
QCOMPARE(leadSpy.count(), 1);
|
||||
}
|
||||
|
||||
void TestServices::projectCrudAndPersistence()
|
||||
{
|
||||
Context context;
|
||||
QVERIFY(context.open());
|
||||
|
||||
const QDate deadline = QDate::currentDate().addMonths(1);
|
||||
QString error;
|
||||
QVERIFY2(context.service->createProject(QStringLiteral("飞行控制器项目"),
|
||||
QStringLiteral("完成飞控板固件与测试"),
|
||||
deadline,
|
||||
&error),
|
||||
qPrintable(error));
|
||||
QVector<Project> projects = context.service->projects();
|
||||
QCOMPARE(projects.size(), 1);
|
||||
QCOMPARE(projects.first().title, QStringLiteral("飞行控制器项目"));
|
||||
QCOMPARE(projects.first().deadline.value(), deadline);
|
||||
const QString id = projects.first().id;
|
||||
|
||||
QVERIFY2(context.service->updateProject(id,
|
||||
QStringLiteral("飞行控制器项目 v2"),
|
||||
QStringLiteral("完成固件、测试与文档"),
|
||||
deadline.addDays(7),
|
||||
&error),
|
||||
qPrintable(error));
|
||||
auto updated = context.service->projectById(id);
|
||||
QVERIFY(updated.has_value());
|
||||
QCOMPARE(updated->title, QStringLiteral("飞行控制器项目 v2"));
|
||||
QCOMPARE(updated->deadline.value(), deadline.addDays(7));
|
||||
|
||||
ScheduleService reloaded(*context.store, QStringLiteral("test-device"));
|
||||
QCOMPARE(reloaded.projects().size(), 1);
|
||||
|
||||
QVERIFY2(context.service->setProjectStatus(id, QStringLiteral("done"), &error), qPrintable(error));
|
||||
QVERIFY(context.service->projects().isEmpty());
|
||||
QCOMPARE(context.store->outboxCount() > 0, true);
|
||||
|
||||
QVERIFY2(context.service->deleteProject(id, &error), qPrintable(error));
|
||||
QVERIFY(!context.service->projectById(id).has_value());
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestServices)
|
||||
#include "test_services.moc"
|
||||
|
||||
@@ -27,10 +27,10 @@ void TestStorage::migrationCreatesSchema()
|
||||
SqliteStore store(dir.filePath(QStringLiteral("schedule.db")));
|
||||
QString error;
|
||||
QVERIFY2(store.open(&error), qPrintable(error));
|
||||
QCOMPARE(store.schemaVersion(), 3);
|
||||
QCOMPARE(store.schemaVersion(), 4);
|
||||
store.close();
|
||||
QVERIFY2(store.open(&error), qPrintable(error));
|
||||
QCOMPARE(store.schemaVersion(), 3);
|
||||
QCOMPARE(store.schemaVersion(), 4);
|
||||
}
|
||||
|
||||
void TestStorage::taskAndBlockRoundTrip()
|
||||
|
||||
@@ -189,6 +189,26 @@ void TestSyncIntegration::twoClientsConverge()
|
||||
}
|
||||
QVERIFY(sawOffline);
|
||||
|
||||
const QDate projectDeadline = QDate::currentDate().addMonths(1);
|
||||
QVERIFY2(serviceA.createProject(QStringLiteral("长期项目"),
|
||||
QStringLiteral("跨月目标"),
|
||||
projectDeadline,
|
||||
&error),
|
||||
qPrintable(error));
|
||||
QTRY_VERIFY_WITH_TIMEOUT(serviceB.projects().size() == 1, 20000);
|
||||
QCOMPARE(serviceB.projects().first().title, QStringLiteral("长期项目"));
|
||||
QVERIFY2(serviceB.updateProject(serviceB.projects().first().id,
|
||||
QStringLiteral("长期项目 v2"),
|
||||
QStringLiteral("跨月目标 v2"),
|
||||
projectDeadline.addDays(14),
|
||||
&error),
|
||||
qPrintable(error));
|
||||
QTRY_VERIFY_WITH_TIMEOUT(!serviceA.projects().isEmpty() &&
|
||||
serviceA.projects().first().title == QStringLiteral("长期项目 v2"),
|
||||
20000);
|
||||
QVERIFY2(serviceA.deleteProject(serviceA.projects().first().id, &error), qPrintable(error));
|
||||
QTRY_VERIFY_WITH_TIMEOUT(serviceB.projects().isEmpty(), 20000);
|
||||
|
||||
syncA.stop();
|
||||
syncB.stop();
|
||||
serverProcess.terminate();
|
||||
|
||||
Reference in New Issue
Block a user