Skip to content

Commit

Permalink
feat: 1.支持在看板界面编辑日程信息 2.自动更新日程记录格式到1.1.0版本
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerHuHu committed Oct 1, 2023
1 parent 59a65c0 commit e29a1d3
Show file tree
Hide file tree
Showing 8 changed files with 366 additions and 83 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@
1. 点击确定、更新、删除日程或取消按钮时,界面会消失,并且会清空上次填写的信息。
2. 点击空白处,界面会消失,会保留上次填写的信息(防止误操作)。

### 7. 任务看板界面
1. 实现了比较简陋的任务看板界面。
2. 不支持日程的新增、拖拽。
3. 支持日程信息的更新。

## Todo
- [x] 界面语言、文档国际化
- [ ] 日程的拖拽
- [ ] 文档中日程记录显示样式优化
- [ ] 任务看板界面
- [x] 任务看板界面
- [ ] 适配移动端
- [ ] 根据日程分类筛选加载的日程

Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
122 changes: 116 additions & 6 deletions src/ScheduleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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) => {

});
Expand Down Expand Up @@ -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) => {

Expand Down Expand Up @@ -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;
})
Expand Down Expand Up @@ -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 => {

})
Expand All @@ -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<any[]> {
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;
}
}
}
}
5 changes: 2 additions & 3 deletions src/Schedules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
32 changes: 17 additions & 15 deletions src/components/Calendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
Expand All @@ -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();
}
},
Expand All @@ -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();
}
},
Expand Down
Loading

0 comments on commit e29a1d3

Please sign in to comment.