Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended schedules #739

Merged
merged 28 commits into from
Jun 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5f27f1c
Add new ToggleButton component
bjoernricks Jun 20, 2018
540c26b
Extract TimeUnitSelect from schedule/dialog module
bjoernricks Jun 20, 2018
073d145
Add a model for ical rrule by day abstraction
bjoernricks Jun 20, 2018
c9dc016
Add a component for selecting Weekdays
bjoernricks Jun 20, 2018
60c09ed
Add Event weekdays property
bjoernricks Jun 20, 2018
c5fa8ef
Update Event.fromDate to support rrule bydate
bjoernricks Jun 20, 2018
9a6079c
Update ScheduleComponent for recurrence handling
bjoernricks Jun 20, 2018
9e15659
Update ScheduleDialog to support more ical options
bjoernricks Jun 20, 2018
14ba998
Update imports of ScheduleDialog
bjoernricks Jun 20, 2018
d87a465
Allow to disable ToggleButtons
bjoernricks Jun 21, 2018
47461b0
Add new WeekDays getter methods
bjoernricks Jun 21, 2018
d8d9eea
Don't crash if weekdays is undefined
bjoernricks Jun 21, 2018
a6f7576
Return undefined if now bydate part is set
bjoernricks Jun 21, 2018
7ec4a5a
Allow to set bymonthday of ical events
bjoernricks Jun 21, 2018
cf6bbc6
Add Event monthdays property
bjoernricks Jun 21, 2018
767fb32
Load and reset the monthdays
bjoernricks Jun 21, 2018
8c2728d
Add a DaySelect component
bjoernricks Jun 21, 2018
0c554af
Add component to select dates of a month
bjoernricks Jun 21, 2018
c36a9f3
Fix freq proptype definition of ScheduleDialog
bjoernricks Jun 21, 2018
7cec4ce
Update ScheduleDialog to allow more monthly options
bjoernricks Jun 21, 2018
dddc64c
Ensure Schedule end date is after start date
bjoernricks Jun 21, 2018
c34a1b4
Return weekdays and monthdays from event recurrence property
bjoernricks Jun 22, 2018
f7f40ff
Rename Period to Recurrence
bjoernricks Jun 22, 2018
29c915c
Export localeData from moment
bjoernricks Jun 22, 2018
d269e30
Add a WeekDays entries method
bjoernricks Jun 22, 2018
77ea8c8
Update renderRecurrence to reflect complex rrules
bjoernricks Jun 22, 2018
3fb6b5a
Improve api of WeekDays class
bjoernricks Jun 22, 2018
625aaa4
Merge branch 'master' into extended-schedules
swaterkamp Jun 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ng/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ set (NG_JS_SRC_FILES
${NG_SRC_DIR}/src/web/components/form/textarea.js
${NG_SRC_DIR}/src/web/components/form/textfield.js
${NG_SRC_DIR}/src/web/components/form/timezoneselect.js
${NG_SRC_DIR}/src/web/components/form/togglebutton.js
${NG_SRC_DIR}/src/web/components/form/withChangeHandler.js
${NG_SRC_DIR}/src/web/components/form/withClickHandler.js
${NG_SRC_DIR}/src/web/components/form/withDownload.js
Expand Down Expand Up @@ -661,13 +662,17 @@ set (NG_JS_SRC_FILES
${NG_SRC_DIR}/src/web/pages/scans/page.js
${NG_SRC_DIR}/src/web/pages/scans/dashboard.js
${NG_SRC_DIR}/src/web/pages/schedules/component.js
${NG_SRC_DIR}/src/web/pages/schedules/dayselect.js
${NG_SRC_DIR}/src/web/pages/schedules/details.js
${NG_SRC_DIR}/src/web/pages/schedules/detailspage.js
${NG_SRC_DIR}/src/web/pages/schedules/dialog.js
${NG_SRC_DIR}/src/web/pages/schedules/listpage.js
${NG_SRC_DIR}/src/web/pages/schedules/monthdaysselect.js
${NG_SRC_DIR}/src/web/pages/schedules/row.js
${NG_SRC_DIR}/src/web/pages/schedules/render.js
${NG_SRC_DIR}/src/web/pages/schedules/table.js
${NG_SRC_DIR}/src/web/pages/schedules/timeunitselect.js
${NG_SRC_DIR}/src/web/pages/schedules/weekdayselect.js
${NG_SRC_DIR}/src/web/pages/secinfo/details.js
${NG_SRC_DIR}/src/web/pages/secinfo/filterdialog.js
${NG_SRC_DIR}/src/web/pages/secinfo/listpage.js
Expand Down
1 change: 1 addition & 0 deletions ng/src/gmp/models/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const {
isMoment: isDate,
locale: setLocale,
duration,
localeData: _localeData,
} = moment;

export default moment;
Expand Down
225 changes: 201 additions & 24 deletions ng/src/gmp/models/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import 'core-js/fn/object/entries';
import 'core-js/fn/object/values';

import ical from 'ical.js';

import uuid from 'uuid/v4';
Expand Down Expand Up @@ -50,10 +53,6 @@ const setEventRecurrence = (event, recurrence) => {
const PROD_ID = '-//Greenbone.net//NONSGML Greenbone Security Assistent';
const ICAL_VERSION = '2.0';

const DAYS = 'day';
const WEEKS = 'week';
const MONTHS = 'month';

export const ReccurenceFrequency = {
YEARLY: 'YEARLY',
MONTHLY: 'MONTHLY',
Expand All @@ -64,6 +63,171 @@ export const ReccurenceFrequency = {
SECONDLY: 'SECONDLY',
};

const ISOWEEKDAY_TO_WEEKDAY = {
1: 'monday',
2: 'tuesday',
3: 'wednesday',
4: 'thursday',
5: 'friday',
6: 'saturday',
7: 'sunday',
};

const ABR_TO_WEEKDAY = {
mo: 'monday',
tu: 'tuesday',
we: 'wednesday',
th: 'thursday',
fr: 'friday',
sa: 'saturday',
su: 'sunday',
};

const getWeekDaysFromRRule = rrule => {
if (!is_defined(rrule)) {
return undefined;
}

const byday = rrule.getComponent('byday');
return byday.length > 0 ? WeekDays.fromByDay(byday) : undefined;
};

const getMonthDaysFromRRule = rrule => {
if (!is_defined(rrule)) {
return undefined;
}

const bymonthday = rrule.getComponent('bymonthday');
return bymonthday.length > 0 ? bymonthday.sort() : undefined;
};

export class WeekDays {

constructor({
monday = false,
tuesday = false,
wednesday = false,
thursday = false,
friday = false,
saturday = false,
sunday = false,
} = {}) {
this._weekdays = {
monday,
tuesday,
wednesday,
thursday,
friday,
saturday,
sunday,
};
}

static fromByDay(bydate = []) {
const weekdays = new WeekDays();

for (const part of bydate) {
const pday = part.slice(-2).toLowerCase();
const pval = part.slice(0, -2);

const wday = ABR_TO_WEEKDAY[pday];
const val = pval.length === 0 ? true : pval;

if (is_defined(wday)) {
weekdays._setWeekDay(wday, val);
}
}

return weekdays;
}

_setWeekDay(weekday, value = true) {
this._weekdays[weekday] = value;
return this;
}

isDefault() {
return this.values().some(value => !value);
}

copy() {
return new WeekDays({...this._weekdays});
}

entries() {
return Object.entries(this._weekdays);
}

values() {
return Object.values(this._weekdays);
}

getSelectedWeekDay() {
const ret = this.entries().find(([, value]) => value);
return is_defined(ret) ? ret[0] : undefined;
}

get(weekday) {
return this._weekdays[weekday];
}

setWeekDay(weekday, value = true) {
const copy = this.copy();
return copy._setWeekDay(weekday, value);
}

setWeekDayFromDate(curdate, value = true) {
const wday = ISOWEEKDAY_TO_WEEKDAY[curdate.isoWeekday()];
return this.setWeekDay(wday, value);
}

toByDate() {
const byday = [];

for (const [abbr, weekday] of Object.entries(ABR_TO_WEEKDAY)) {
const value = this.get(weekday);
if (value) {
if (value === true) {
byday.push(abbr.toUpperCase());
}
else {
byday.push('' + value + abbr.toUpperCase());
}
}
}

return byday;
}

get monday() {
return this.get('monday');
}

get tuesday() {
return this.get('tuesday');
}

get wednesday() {
return this.get('wednesday');
}

get thursday() {
return this.get('thursday');
}

get friday() {
return this.get('friday');
}

get saturday() {
return this.get('saturday');
}

get sunday() {
return this.get('sunday');
}
}

class Event {

constructor(icalevent, timezone) {
Expand All @@ -81,11 +245,13 @@ class Event {

static fromData({
description,
startDate,
duration,
period = 0,
periodUnit,
freq,
interval,
monthdays = [],
startDate,
summary,
weekdays,
}, timezone) {

const event = new ical.Event();
Expand All @@ -105,35 +271,44 @@ class Event {
setEventDuration(event, eventDuration);
}

if (period > 0) {
if (is_defined(freq)) {
const eventRecur = new ical.Recur();
if (periodUnit === MONTHS) {
eventRecur.freq = ReccurenceFrequency.MONTHLY;
}
else if (periodUnit === WEEKS) {
eventRecur.freq = ReccurenceFrequency.WEEKLY;
}
else if (periodUnit === DAYS) {
eventRecur.freq = ReccurenceFrequency.WEEKLY;

eventRecur.freq = freq;
eventRecur.interval = interval;

const icalweekdays = is_defined(weekdays) ? weekdays.toByDate() : [];

if (icalweekdays.length > 0) {
eventRecur.setComponent('byday', icalweekdays);
}
else {
eventRecur.freq = ReccurenceFrequency.HOURLY;

if (monthdays.length > 0) {
eventRecur.setComponent('bymonthday', monthdays);
}
eventRecur.interval = period;

setEventRecurrence(event, eventRecur);
}

if (!is_empty(summary)) {
event.summary = summary;
}

if (!is_empty(description)) {
event.description = description;
}

return new Event(event, timezone);
}

_getReccurenceRule() {
if (this.isRecurring()) {
const rrule = this.event.component.getFirstPropertyValue('rrule');
return rrule === null ? undefined : rrule;
}
return undefined;
}

get startDate() {
return convertIcalDate(this.event.startDate, this.timezone);
}
Expand All @@ -158,11 +333,13 @@ class Event {
}

get recurrence() {
if (this.isRecurring()) {
const rrule = this.event.component.getFirstPropertyValue('rrule');
return rrule === null ? undefined : rrule;
}
return undefined;
const rrule = this._getReccurenceRule();

return {
...rrule,
weekdays: getWeekDaysFromRRule(rrule),
monthdays: getMonthDaysFromRRule(rrule),
};
}

get nextDate() {
Expand Down
Loading