Skip to content

Commit

Permalink
fix: 1.重复日程按月、按年时,不能选择具体的天
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerHuHu committed Jan 3, 2024
1 parent bab2261 commit e816d36
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 23 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,8 @@
## v1.2.6
### feat:
1. 增加设置标签页,并将一键归档移至该标签页
2. 支持隐藏日程分类视图
2. 支持隐藏日程分类视图

## v1.2.7
### fix:
1. 修复重复日程按月、按年时,不能选择具体的天的问题 [#35]
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.2.6",
"version": "1.2.7",
"minAppVersion": "2.10.6",
"backends": ["all"],
"frontends": ["all"],
Expand Down
9 changes: 7 additions & 2 deletions src/Schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export class Schedule {
isRecurringSchedule: boolean; // 是否为重复性日程
frequency: string; // 重复频率(日、周、月、年)
weekdays: string[]; // 如果重复频率为周,则可以选择周几重复
monthdays: string[]; // 如果重复频率为月,则可以选择当月的哪一天重复
yeardays: string[]; // 如果重复频率为年,则可以选择当年的哪一天重复
interval: number; // 重复间隔,单位视重复频率
start: string;
end: string;
Expand All @@ -16,15 +18,18 @@ export class Schedule {
doneTime: number;

constructor(id?: string, title?: string, isAllDay?: boolean,
isRecurringSchedule?: boolean, frequency?: string, weekdays?: string[], interval?: number,
start?: string, end?: string,
isRecurringSchedule?: boolean, frequency?: string,
weekdays?: string[], monthdays?:string[], yeardays?:string[],
interval?: number, start?: string, end?: string,
category?: string, refBlockId?:string, content?: string, status?: number) {
this.id = id;
this.title = title;
this.isAllDay = isAllDay;
this.isRecurringSchedule = isRecurringSchedule;
this.frequency = frequency;
this.weekdays = weekdays;
this.monthdays = monthdays;
this.yeardays = yeardays;
this.interval = interval;
this.start = start;
this.end = end;
Expand Down
11 changes: 8 additions & 3 deletions src/ScheduleCategories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ export class ScheduleCategories {

if(content.isRecurringSchedule !== null && content.isRecurringSchedule === true) {
schedule = new Schedule(content.id, content.title, isAllDay,
true, content.frequency, content.weekdays, content.interval,
content.start, content.end,
true, content.frequency, content.weekdays, content.monthdays, content.yeardays,
content.interval, content.start, content.end,
content.category, content.refBlockId, content.content, content.status);
schedule.setDoneTime(content.doneTime);
} else {
schedule = new Schedule(content.id, content.title, isAllDay,
false, '', [], 1,
false, '', [], [], [], 1,
content.start, content.end,
content.category, content.refBlockId, content.content, content.status);
schedule.setDoneTime(content.doneTime);
Expand Down Expand Up @@ -158,6 +158,7 @@ export class ScheduleCategories {
let newEvent = null;

if(schedule.isRecurringSchedule) {
console.log("Schedule byyearday: ", schedule.yeardays);
newEvent = {
id: schedule.id,
title: this.getEventName(schedule.title, schedule.status),
Expand All @@ -166,6 +167,8 @@ export class ScheduleCategories {
freq: schedule.frequency,
interval: schedule.interval,
byweekday: schedule.weekdays,
bymonthday: schedule.monthdays,
byyearday: schedule.yeardays,
dtstart: schedule.start,
until: schedule.end
},
Expand All @@ -178,6 +181,8 @@ export class ScheduleCategories {
freq: schedule.frequency,
interval: schedule.interval,
byweekday: schedule.weekdays,
bymonthday: schedule.monthdays,
byyearday: schedule.yeardays,
dtstart: schedule.start,
until: schedule.end
}
Expand Down
4 changes: 2 additions & 2 deletions src/ScheduleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ export class ScheduleManager {
})

let newSchedule = new Schedule(content.id, content.title, content.isAllDay,
content.isRecurringSchedule, content.frequency, content.weekdays, content.interval,
content.start, content.end,
content.isRecurringSchedule, content.frequency, content.weekdays, content.monthdays, content.yeardays,
content.interval, content.start, content.end,
content.extendedProps.category, content.extendedProps.refBlockId,
content.extendedProps.content, content.extendedProps.status);
//console.log(newSchedule);
Expand Down
13 changes: 13 additions & 0 deletions src/ThirdPartyCalendars/CalDav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,21 @@ export class CalDavClient {

async login() {
await this.client.login();
/*
await this.client.makeCalendar({
url: 'https://calendar.dingtalk.com/dav/u_oslxrjui/primary/',
props: {
displayname: '工作',
description: ''
}
});
*/
const calendars = await this.client.fetchCalendars();
console.log("=========================calendars===========================");
console.log(calendars);
const calendarObjects = await this.client.fetchCalendarObjects({
calendar: calendars[0],
});
console.log(calendarObjects);
}
}
74 changes: 61 additions & 13 deletions src/components/ScheduleEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@
<div class="sm-schedule-item-header" style="margin-top: 3px;">{{ cycleText }}</div>
</n-gi>
<n-gi :span="3" v-if="isRecurringSchedule">
<n-select v-model:value="selectedFreq" size="tiny" :options="freqs" />
<n-select v-model:value="selectedFreq" size="tiny" :options="freqs" @update:value="handleUpdateSelectedFreq" />
</n-gi>
<n-gi :span="4" v-if="isRecurringSchedule">
<n-select v-model:value="selectedWeekday" multiple :options="weekdays" size="tiny" :disabled="selectedFreq != 'weekly'"/>
<n-gi :span="4" v-if="isRecurringSchedule && selectedFreq === 'weekly'">
<n-select v-model:value="selectedWeekday" multiple :options="weekdays" size="tiny"/>
</n-gi>
<n-gi :span="4" v-if="isRecurringSchedule && selectedFreq === 'monthly'">
<n-select v-model:value="selectedMonthday" multiple :options="monthdays" size="tiny"/>
</n-gi>
<n-gi :span="4" v-if="isRecurringSchedule && selectedFreq === 'yearly'">
<n-select v-model:value="selectedYearday" multiple :options="yeardays" size="tiny"/>
</n-gi>

<n-gi :span="1" style="display: flex; justify-content:right;" v-if="isRecurringSchedule">
Expand Down Expand Up @@ -199,6 +205,8 @@ export default defineComponent({
isRecurringSchedule: ref(null),
scheduleInterval: ref(1),
selectedWeekday: ref([]),
selectedMonthday: ref([]),
selectedYearday: ref([]),
scheduleStatusList: [
{
value: 1,
Expand Down Expand Up @@ -265,6 +273,8 @@ export default defineComponent({
label: i18n.sunday
}
],
monthdays: ref([]),
yeardays: ref([]),
selectedFreq: ref(null),
selectedEvent: null,
};
Expand All @@ -280,12 +290,34 @@ export default defineComponent({
},
methods: {
createRecurringDays() {
if(this.selectedFreq === 'monthly') {
this.monthdays = [];
for(let i = 0; i < 31; i++) {
let monthday = { value: i+1, label: (i+1).toString() }
this.monthdays.push(monthday);
}
}
else if(this.selectedFreq === 'yearly') {
this.yeardays = [];
for(let i = 0; i < 366; i++) {
let yearday = { value: i+1, label: (i+1).toString() }
this.yeardays.push(yearday);
}
}
},
handleUpdateSelectedFreq() {
this.createRecurringDays();
},
newSchedule(param) {
if(this.selectedDate !== "" && this.selectedDate === param.startStr) {
this.selectedDate = "";
this.selectedScheduleStatus = this.scheduleStatusList[0].value;
this.isDeleteButtonVisible = false;
this.showEditModal = true;
this.createRecurringDays();
} else {
this.selectedDate = param.startStr;
}
Expand All @@ -294,14 +326,14 @@ export default defineComponent({
updateSchedule(param) {
if(param.extendedProps.rrule === undefined) {
this.updateScheduleInternal(param.id, param.extendedProps.category, param.title.substring(param.title.indexOf(' ') + 1), param.allDay,
false, '', [], 1,
false, '', [], [], [], 1,
param.startStr, param.endStr, param.extendedProps.refBlockId, param.extendedProps.content,
param.extendedProps.status);
} else {
this.updateScheduleInternal(param.id, param.extendedProps.category, param.title.substring(param.title.indexOf(' ') + 1), param.allDay,
true, param.extendedProps.rrule.freq, param.extendedProps.rrule.byweekday, param.extendedProps.rrule.interval,
param.extendedProps.rrule.dtstart, param.extendedProps.rrule.until, param.extendedProps.refBlockId,
param.extendedProps.content, param.extendedProps.status);
true, param.extendedProps.rrule.freq, param.extendedProps.rrule.byweekday, param.extendedProps.rrule.bymonthday,
param.extendedProps.rrule.byyearday, param.extendedProps.rrule.interval, param.extendedProps.rrule.dtstart,
param.extendedProps.rrule.until, param.extendedProps.refBlockId, param.extendedProps.content, param.extendedProps.status);
}
},
Expand All @@ -311,13 +343,13 @@ export default defineComponent({
this.sindex = sindex;
let schedule = this.globalData.scheduleCategories.categories[cindex].schedules[sindex];
this.updateScheduleInternal(schedule.id, schedule.category, schedule.title, schedule.isAllDay,
schedule.isRecurringSchedule, schedule.frequency, schedule.weekdays, schedule.interval,
schedule.start, schedule.end,
schedule.isRecurringSchedule, schedule.frequency, schedule.weekdays, schedule.monthdays, schedule.yeardays,
schedule.interval, schedule.start, schedule.end,
schedule.refBlockId, schedule.content, schedule.status);
},
updateScheduleInternal(id, category, title, isAllDay,
isRecurringSchedule, frequency, weekdays, interval,
isRecurringSchedule, frequency, weekdays, monthdays, yeardays, interval,
startTime, endTime, refBlockId, content, status) {
this.isDeleteButtonVisible = true;
this.selectedCategory = category;
Expand All @@ -343,11 +375,14 @@ export default defineComponent({
this.isRecurringSchedule = isRecurringSchedule;
this.selectedFreq = frequency;
this.selectedWeekday = weekdays;
this.selectedMonthday = monthdays;
this.selectedYearday = yeardays;
this.scheduleInterval = interval;
this.selectedSchedule = new Schedule(id, '', isAllDay, isRecurringSchedule, frequency, weekdays, interval, '', '', category, '', '', 1);
this.selectedSchedule = new Schedule(id, '', isAllDay, isRecurringSchedule, frequency, weekdays, monthdays, yeardays, interval, '', '', category, '', '', 1);
this.showEditModal = true;
this.createRecurringDays();
},
handleSubmitSchedule() {
Expand Down Expand Up @@ -408,9 +443,22 @@ export default defineComponent({
end = format(this.endTime, "yyyy-MM-dd'T'HH:mm:ss");
}
if(this.selectedFreq === 'weekly') {
this.selectedMonthday = [];
this.selectedYearday = [];
}
else if(this.selectedFreq === 'monthly') {
this.selectedWeekday = [];
this.selectedYearday = [];
}
else if(this.selectedFreq === 'yearly') {
this.selectedMonthday = [];
this.selectedWeekday = [];
}
let newSchedule = new Schedule(id, this.scheduleName, this.isAllDaySchedule,
this.isRecurringSchedule, this.selectedFreq, this.selectedWeekday, this.scheduleInterval,
start, end,
this.isRecurringSchedule, this.selectedFreq, this.selectedWeekday, this.selectedMonthday, this.selectedYearday,
this.scheduleInterval, start, end,
this.selectedCategory, this.scheduleContentBlockId, this.scheduleContent, this.selectedScheduleStatus
);
if(this.selectedScheduleStatus == 3)
Expand Down
17 changes: 16 additions & 1 deletion src/components/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
<n-gi :span="8">
<n-divider />
</n-gi>
<!--n-gi :span="8">
<n-button strong secondary round type="info" @click="handleTest()">
{{ archiveText }}
</n-button>
</n-gi-->
</n-grid>
</n-card>
</template>
Expand All @@ -38,6 +43,7 @@
import { CheckOutlined } from '@vicons/antd'
import EventAggregator from "../utils/EventAggregator";
import { showMessage } from "siyuan";
import { CalDavClient } from "../ThirdPartyCalendars/CalDav";
export default defineComponent({
components: {
Expand All @@ -51,7 +57,8 @@ export default defineComponent({
dayText: i18n.day,
archiveText: i18n.archive,
archiveTime: ref(7),
};
calDavClient: CalDavClient,
};
},
data() {
Expand All @@ -73,6 +80,14 @@ export default defineComponent({
handleArchive() {
this.globalData.scheduleCategories.archiveSchedules(this.archiveTime);
},
handleTest() {
this.calDavClient = new CalDavClient("https://calendar.dingtalk.com/dav/users/u_oslxrjui", "u_oslxrjui", "ow5kp2zd");
//this.calDavClient = new CalDavClient("https://dav.qq.com/dav/users/[email protected]", "[email protected]", "ezgcgtzkjkihbiah");
//this.calDavClient = new CalDavClient("https://caldav.mail.qq.com/", "[email protected]", "dream91722");
//this.calDavClient = new CalDavClient("https://dida365.com/pub/calendar/feeds/quraph7at8zb/basic.ics", "[email protected]", "hello7109");
this.calDavClient.login();
}
}
})
</script>

0 comments on commit e816d36

Please sign in to comment.