|
|
@ -4,6 +4,8 @@ let timezone = require("dayjs/plugin/timezone");
|
|
|
|
dayjs.extend(utc);
|
|
|
|
dayjs.extend(utc);
|
|
|
|
dayjs.extend(timezone);
|
|
|
|
dayjs.extend(timezone);
|
|
|
|
const { BeanModel } = require("redbean-node/dist/bean-model");
|
|
|
|
const { BeanModel } = require("redbean-node/dist/bean-model");
|
|
|
|
|
|
|
|
const { parseVueDatePickerTimeFormat, parseTimeFormatFromVueDatePicker } = require("../../src/util");
|
|
|
|
|
|
|
|
const { isArray } = require("chart.js/helpers");
|
|
|
|
|
|
|
|
|
|
|
|
class Maintenance extends BeanModel {
|
|
|
|
class Maintenance extends BeanModel {
|
|
|
|
|
|
|
|
|
|
|
@ -13,15 +15,52 @@ class Maintenance extends BeanModel {
|
|
|
|
* @returns {Object}
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
async toPublicJSON() {
|
|
|
|
async toPublicJSON() {
|
|
|
|
return {
|
|
|
|
|
|
|
|
|
|
|
|
let dateTimeRange = [];
|
|
|
|
|
|
|
|
if (this.start_datetime) {
|
|
|
|
|
|
|
|
dateTimeRange.push( this.start_datetime);
|
|
|
|
|
|
|
|
if (this.end_datetime) {
|
|
|
|
|
|
|
|
dateTimeRange.push( this.end_datetime);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let dateRange = [];
|
|
|
|
|
|
|
|
if (this.start_date) {
|
|
|
|
|
|
|
|
dateRange.push( this.start_date);
|
|
|
|
|
|
|
|
if (this.end_date) {
|
|
|
|
|
|
|
|
dateRange.push( this.end_date);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let timeRange = [];
|
|
|
|
|
|
|
|
let startTime = parseVueDatePickerTimeFormat(this.start_time);
|
|
|
|
|
|
|
|
timeRange.push(startTime);
|
|
|
|
|
|
|
|
let endTime = parseVueDatePickerTimeFormat(this.end_time);
|
|
|
|
|
|
|
|
timeRange.push(endTime);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let obj = {
|
|
|
|
id: this.id,
|
|
|
|
id: this.id,
|
|
|
|
title: this.title,
|
|
|
|
title: this.title,
|
|
|
|
description: this.description,
|
|
|
|
description: this.description,
|
|
|
|
start_date: this.start_date,
|
|
|
|
|
|
|
|
end_date: this.end_date,
|
|
|
|
|
|
|
|
strategy: this.strategy,
|
|
|
|
strategy: this.strategy,
|
|
|
|
|
|
|
|
intervalDay: this.interval_day,
|
|
|
|
active: !!this.active,
|
|
|
|
active: !!this.active,
|
|
|
|
|
|
|
|
dateTimeRange: dateTimeRange,
|
|
|
|
|
|
|
|
dateRange: dateRange,
|
|
|
|
|
|
|
|
timeRange: timeRange,
|
|
|
|
|
|
|
|
weekdays: (this.weekdays) ? JSON.parse(this.weekdays) : [],
|
|
|
|
|
|
|
|
daysOfMonth: (this.days_of_month) ? JSON.parse(this.days_of_month) : [],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isArray(obj.weekdays)) {
|
|
|
|
|
|
|
|
obj.weekdays = [];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isArray(obj.daysOfMonth)) {
|
|
|
|
|
|
|
|
obj.daysOfMonth = [];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -31,6 +70,42 @@ class Maintenance extends BeanModel {
|
|
|
|
async toJSON() {
|
|
|
|
async toJSON() {
|
|
|
|
return this.toPublicJSON();
|
|
|
|
return this.toPublicJSON();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static jsonToBean(bean, obj) {
|
|
|
|
|
|
|
|
if (obj.id) {
|
|
|
|
|
|
|
|
bean.id = obj.id;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bean.title = obj.title;
|
|
|
|
|
|
|
|
bean.description = obj.description;
|
|
|
|
|
|
|
|
bean.strategy = obj.strategy;
|
|
|
|
|
|
|
|
bean.interval_day = obj.intervalDay;
|
|
|
|
|
|
|
|
bean.active = obj.active;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (obj.dateRange[0]) {
|
|
|
|
|
|
|
|
bean.start_date = obj.dateRange[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (obj.dateRange[1]) {
|
|
|
|
|
|
|
|
bean.end_date = obj.dateRange[1];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (obj.dateTimeRange[0]) {
|
|
|
|
|
|
|
|
bean.start_datetime = obj.dateTimeRange[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (obj.dateTimeRange[1]) {
|
|
|
|
|
|
|
|
bean.end_datetime = obj.dateTimeRange[1];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bean.start_time = parseTimeFormatFromVueDatePicker(obj.timeRange[0]);
|
|
|
|
|
|
|
|
bean.end_time = parseTimeFormatFromVueDatePicker(obj.timeRange[1]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bean.weekdays = JSON.stringify(obj.weekdays);
|
|
|
|
|
|
|
|
bean.days_of_month = JSON.stringify(obj.daysOfMonth);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return bean;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = Maintenance;
|
|
|
|
module.exports = Maintenance;
|
|
|
|