From e29a1d3c5f0035a4abf03a5a554f973cba826b21 Mon Sep 17 00:00:00 2001 From: roger Date: Mon, 2 Oct 2023 00:44:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=201.=E6=94=AF=E6=8C=81=E5=9C=A8=E7=9C=8B?= =?UTF-8?q?=E6=9D=BF=E7=95=8C=E9=9D=A2=E7=BC=96=E8=BE=91=E6=97=A5=E7=A8=8B?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=202.=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=A5=E7=A8=8B=E8=AE=B0=E5=BD=95=E6=A0=BC=E5=BC=8F=E5=88=B0?= =?UTF-8?q?1.1.0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +- README_zh_CN.md | 7 +- plugin.json | 2 +- src/ScheduleManager.ts | 122 +++++++++++++++- src/Schedules.ts | 5 +- src/components/Calendar.vue | 32 +++-- src/components/Kanban.vue | 270 ++++++++++++++++++++++++++++-------- src/index.ts | 4 +- 8 files changed, 366 insertions(+), 83 deletions(-) diff --git a/README.md b/README.md index df95202..5343d8e 100644 --- a/README.md +++ b/README.md @@ -43,11 +43,16 @@ Clicking the remove schedule button on the above-mentioned window will remove th 1. When you click the OK, Update, Remove, or Cancel buttons, the window disappears and the last filled information will be cleared. 2. When you click on a blank space, the window disappear and will retain the last filled information (to prevent misuse). +### 7. Task kanban view +1. Implemented a relatively rudimentary task kanban. +2. Adding or dragging a schedule is not supported. +3. Support for editing schedule information. + ## Todo - [x] The internationalization of the interface language and the document - [ ] Schedule drag & drop - [ ] Optimization of the display style of schedule records in documents -- [ ] Task kanban view +- [x] Task kanban view - [ ] Adaptation for mobile - [ ] Filter loaded schedules according to schedule categories diff --git a/README_zh_CN.md b/README_zh_CN.md index 3fb08e2..cceaf86 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -44,11 +44,16 @@ 1. 点击确定、更新、删除日程或取消按钮时,界面会消失,并且会清空上次填写的信息。 2. 点击空白处,界面会消失,会保留上次填写的信息(防止误操作)。 +### 7. 任务看板界面 +1. 实现了比较简陋的任务看板界面。 +2. 不支持日程的新增、拖拽。 +3. 支持日程信息的更新。 + ## Todo - [x] 界面语言、文档国际化 - [ ] 日程的拖拽 - [ ] 文档中日程记录显示样式优化 -- [ ] 任务看板界面 +- [x] 任务看板界面 - [ ] 适配移动端 - [ ] 根据日程分类筛选加载的日程 diff --git a/plugin.json b/plugin.json index d038eb8..7791cab 100644 --- a/plugin.json +++ b/plugin.json @@ -2,7 +2,7 @@ "name": "siyuan-plugin-schedule-manager", "author": "RogerHuHu", "url": "https://github.com/RogerHuHu/siyuan-plugin-schedule-manager", - "version": "1.0.9", + "version": "1.1.0", "minAppVersion": "2.10.6", "backends": ["all"], "frontends": ["all"], diff --git a/src/ScheduleManager.ts b/src/ScheduleManager.ts index a2f118f..59a6d64 100644 --- a/src/ScheduleManager.ts +++ b/src/ScheduleManager.ts @@ -5,6 +5,7 @@ import App from "./App.vue"; import { fetchPost, fetchSyncPost } from "siyuan"; import EventAggregator from "./utils/EventAggregator"; import { Schedules } from "./Schedules"; +import { Schedule } from "./Schedule"; import { globalData } from "./utils/utils"; export class ScheduleManager { @@ -20,10 +21,12 @@ export class ScheduleManager { } init(): void { - this.readScheduleCategory(); + //this.readScheduleCategory(); + this.updateDocumentVersion(); } - show(el: HTMLElement) : void { + async show() { + await this.readScheduleCategory(); this.app = createApp(App); this.app.use(naive); } @@ -63,7 +66,7 @@ export class ScheduleManager { fetchPost("/api/block/appendBlock", { "data": JSON.stringify(p).replace(/#/g,""), "dataType": "markdown", - "parentID": this.getDocumentIdByName(p.extendedProps.category) + "parentID": this.getDocumentIdByName(p.category) }, (response) => { }); @@ -112,7 +115,7 @@ export class ScheduleManager { "attrs": { "custom-checked": checked ? "true" : "false", "custom-color": color, - "custom-version": "1.0.0" + "custom-version": "1.1.0" } }, (response) => { @@ -161,7 +164,7 @@ export class ScheduleManager { let id; // 先查询得到日程的 id - let query = "SELECT id FROM blocks WHERE content like \'%" + schedule.id + "%\' AND parent_id =\'" + this.getDocumentIdByName(schedule.extendedProps.category) + "\'"; + let query = "SELECT id FROM blocks WHERE content like \'%" + schedule.id + "%\' AND parent_id =\'" + this.getDocumentIdByName(schedule.category) + "\'"; await fetchSyncPost("/api/query/sql", {"stmt":query}).then(response => { id = response.data[0].id; }) @@ -189,7 +192,7 @@ export class ScheduleManager { await fetchSyncPost("/api/block/appendBlock", { "data": JSON.stringify(schedule.new).replace(/#/g,""), "dataType": "markdown", - "parentID": this.getDocumentIdByName(schedule.new.extendedProps.category) + "parentID": this.getDocumentIdByName(schedule.new.category) }).then(response => { }) @@ -202,4 +205,111 @@ export class ScheduleManager { } } } + + async updateDocumentVersion() { + let documents = await this.getDocuments1(); + + for(let doc of documents) { + await fetchSyncPost("/api/attr/getBlockAttrs", {"id":doc.id}).then(response => { + doc.name = response.data.title; + doc.checked = response.data["custom-checked"] === "true" ? true : false; + doc.color = response.data["custom-color"]; + doc.version = response.data["custom-version"]; + }) + } + + for(let doc of documents) { + //console.log(doc); + if(doc.version === "1.0.0") { + //console.log("version 1.0.0"); + await this.updateSchedules1(doc.id, documents); + this.setDocumentProperty1(doc.id, doc.checked, doc.color); + } + } + } + + async getDocuments1(): Promise { + let documents = []; + let query = "SELECT id FROM blocks WHERE type = \'d\' AND box =\'" + this.noteBookId + "\'"; + await fetchSyncPost("/api/query/sql", {"stmt":query}).then(response => { + for(let id of response.data) { + let document = { + id: id.id, + name: "", + checked: "", + color: "", + version: "" + } + documents.push(document); + } + }); + + return documents; + } + + setDocumentProperty1(docId: string, checked: boolean, color: string) : void { + fetchPost("/api/attr/setBlockAttrs", { + "id": docId, + "attrs": { + "custom-checked": checked ? "true" : "false", + "custom-color": color, + "custom-version": "1.1.0" + } + }, (response) => { + + }); + } + + async updateSchedules1(docId: string, documents: any[]) { + let query = "SELECT content FROM blocks WHERE parent_id =\'" + docId + "\'"; + let schedules = []; + await fetchSyncPost("/api/query/sql", {"stmt":query}).then(response => { + schedules = response.data; + }); + + //console.log(schedules); + for(let schedule of schedules) { + await this.updateSchedule1(schedule, documents); + } + //console.log("update schedules successfully"); + } + + async updateSchedule1(schedule: any, documents: any[]) { + let id; + + if(schedule.content !== "") { + let content = JSON.parse(schedule.content); + // 先查询得到日程的 id + let query = "SELECT id FROM blocks WHERE content like \'%" + content.id + "%\' AND parent_id =\'" + + this.getDocumentIdByName1(content.extendedProps.category, documents) + "\'"; + await fetchSyncPost("/api/query/sql", {"stmt":query}).then(response => { + id = response.data[0].id; + }) + + await fetchSyncPost("/api/block/deleteBlock", { + "id": id + }).then(response => { + }) + + let newSchedule = new Schedule(content.id, content.title, content.start, content.end, content.backgroundColor, + content.borderColor, content.extendedProps.category, content.extendedProps.content, + content.extendedProps.status); + //console.log(newSchedule); + await fetchSyncPost("/api/block/appendBlock", { + "data": JSON.stringify(newSchedule), + "dataType": "markdown", + "parentID": this.getDocumentIdByName1(newSchedule.category, documents) + }).then(response => { + + }) + } + } + + getDocumentIdByName1(name: string, documents: any[]) : string { + for(let doc of documents) { + if(doc.name === name) { + return doc.id; + } + } + } } \ No newline at end of file diff --git a/src/Schedules.ts b/src/Schedules.ts index 3c1f19f..eb5c511 100644 --- a/src/Schedules.ts +++ b/src/Schedules.ts @@ -21,15 +21,14 @@ export class Schedules { let content = JSON.parse(elementS.content); let schedule = new Schedule(content.id, content.title, content.start, content.end, "#" + content.backgroundColor, - "#" + content.borderColor, content.extendedProps.category, content.extendedProps.content, - content.extendedProps.status); + "#" + content.borderColor, content.category, content.content, + content.status); category.schedules.push(schedule); } } } addSchedule(schedule: Schedule) : void { - console.log("addSchedule", JSON.stringify(schedule)); let categoty = this.categories.find(c => c.name === schedule.category); if(categoty !== null) { categoty.schedules.push(schedule); diff --git a/src/components/Calendar.vue b/src/components/Calendar.vue index 60b67cb..17a7305 100644 --- a/src/components/Calendar.vue +++ b/src/components/Calendar.vue @@ -264,12 +264,12 @@ submitDeleteSchedule() { let event = this.selectedEvent; this.selectedEvent.remove(); - this.globalData.schedules.removeSchedule( - new Schedule(event.id, event.title, event.start, event.end, - event.backgroundColor, event.borderColor, - event.extendedProps.category, event.extendedProps.content, - event.extendedProps.status)); - EventAggregator.emit('deleteSchedule', event); + let schedule = new Schedule(event.id, event.title, event.start, event.end, + event.backgroundColor, event.borderColor, + event.extendedProps.category, event.extendedProps.content, + event.extendedProps.status); + this.globalData.schedules.removeSchedule(schedule); + EventAggregator.emit('deleteSchedule', schedule); this.clearEventInfo(); }, @@ -288,11 +288,12 @@ this.selectedCategory.name, this.scheduleContent, this.selectedScheduleStatus); this.$refs.fullCalendar.getApi().addEvent(newEvent); - this.globalData.schedules.addSchedule(new Schedule(newEvent.id, newEvent.title, newEvent.start, newEvent.end, - newEvent.backgroundColor, newEvent.borderColor, - newEvent.extendedProps.category, newEvent.extendedProps.content, - newEvent.extendedProps.status)); - EventAggregator.emit('addSchedule', newEvent); + let schedule = new Schedule(newEvent.id, newEvent.title, newEvent.start, newEvent.end, + newEvent.backgroundColor, newEvent.borderColor, + newEvent.extendedProps.category, newEvent.extendedProps.content, + newEvent.extendedProps.status) + this.globalData.schedules.addSchedule(schedule); + EventAggregator.emit('addSchedule', schedule); this.clearEventInfo(); } }, @@ -317,14 +318,15 @@ this.scheduleRange, this.selectedCategoryColor, tmp.name, this.scheduleContent, this.selectedScheduleStatus); - this.globalData.schedules.updateSchedule(oldCategory, - new Schedule(newEvent.id, newEvent.title, newEvent.start, newEvent.end, + + let schedule = new Schedule(newEvent.id, newEvent.title, newEvent.start, newEvent.end, newEvent.backgroundColor, newEvent.borderColor, newEvent.extendedProps.category, newEvent.extendedProps.content, - newEvent.extendedProps.status)); + newEvent.extendedProps.status); + this.globalData.schedules.updateSchedule(oldCategory, schedule); EventAggregator.emit('updateSchedule', { old: oldCategory, - new: newEvent }); + new: schedule }); this.clearEventInfo(); } }, diff --git a/src/components/Kanban.vue b/src/components/Kanban.vue index 3ba1cb6..22a7f0f 100644 --- a/src/components/Kanban.vue +++ b/src/components/Kanban.vue @@ -4,13 +4,13 @@
{{ todoText }}
- - + + {{ schedule.title }} - + @@ -30,13 +30,13 @@
{{ doingText }}
- - + + {{ schedule.title }} - + @@ -56,13 +56,13 @@
{{ doneText }}
- - + + {{ schedule.title }} - + @@ -82,13 +82,13 @@
{{ archiveText }}
- - + + {{ schedule.title }} - + @@ -105,6 +105,93 @@ + + + + +
{{ selectScheduleCategoryText }}
+
+ + + + + +
{{ selectScheduleRangeText }}
+
+ + + + + +
{{ scheduleNameText }}
+
+ + + + + +
{{ scheduleContentText }}
+
+ + + + + +
{{ statusText }}
+
+ + + + + {{ scheduleStatus.label }} + + + + + + + + + {{ cancelText }} + + + {{ removeScheduleText }} + + + {{ updateText }} + + + + +
+
+ +