Skip to content

Commit dbc7107

Browse files
committed
Update schedules.js to set startDate to midnight for new schedules; remove startDate for Nixie controllers. tagyoureit/nodejs-poolController#1094
Refactor Config.ts for cleaner code and ensure directory creation is recursive.
1 parent 8012239 commit dbc7107

2 files changed

Lines changed: 24 additions & 16 deletions

File tree

scripts/config/schedules.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
pnl[0].dataBind({
3535
id: -1, startTime: 480, endTime: 1020,
3636
scheduleType: st.val, startTimeType: tt.val, endTimeType: tt.val, circuit: 0, display: 0,
37-
heatSetpoint: 78, coolSetpoint: 100, heatSource: 0, scheduleDays: 127, startDate: new Date().toISOString()
37+
heatSetpoint: 78, coolSetpoint: 100, heatSource: 0, scheduleDays: 127, startDate: (function() { var today = new Date(); today.setHours(0, 0, 0, 0); return today.toISOString(); })()
3838

3939
});
4040
pnl.find('div.picAccordian:first')[0].expanded(true);
@@ -239,6 +239,12 @@
239239
delete v.startTimeMult;
240240
delete v.startTimeOffsetHours;
241241
delete v.startTimeOffsetMins;
242+
243+
// Remove startDate for Nixie controllers
244+
if (ct === 'nixie') {
245+
delete v.startDate;
246+
}
247+
242248
console.log(v);
243249
$.putApiService('/config/schedule', v, 'Saving Schedule...', function (data, status, xhr) {
244250
console.log({ data: data, status: status, xhr: xhr });
@@ -283,7 +289,12 @@
283289
var schedType = $.extend(true,
284290
{ name: 'repeat', desc: 'Repeats', startDate: false, startTime: true, endTime: true, days: 'multi' },
285291
o.scheduleTypes.find(elem => scheduleType === elem.val));
286-
schedType.startDate ? el.find('div.picPickList[data-bind=startDate]').show()[0].required(true) : el.find('div.picPickList[data-bind=startDate]').hide()[0].required(false);
292+
293+
// Check controller type for start date visibility
294+
let ct = $('body').attr('data-controllertype');
295+
let shouldShowStartDate = schedType.startDate && ct !== 'nixie';
296+
297+
shouldShowStartDate ? el.find('div.picPickList[data-bind=startDate]').show()[0].required(true) : el.find('div.picPickList[data-bind=startDate]').hide()[0].required(false);
287298
schedType.startTime ? el.find('div.schedule-time.start-time').show().find('div.picValueSpinner[data-bind=startTime]')[0].required(true) : el.find('div.schedule-time.start-time').hide().find('div.picValueSpinner[data-bind=startTime]')[0].required(false);
288299
schedType.endTime ? el.find('div.schedule-time.end-time').show().find('div.picValueSpinner[data-bind=endTime]')[0].required(true) : el.find('div.schedule-time.end-time').hide().find('div.picValueSpinner[data-bind=endTime]')[0].required(false);
289300
el.find('div.pnl-scheduleDays').each(function () {

server/config/Config.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Config {
1313
this._cfg = fs.existsSync(this.cfgPath) ? JSON.parse(fs.readFileSync(this.cfgPath, "utf8")) : {};
1414
const def = JSON.parse(fs.readFileSync(path.join(process.cwd(), "/defaultConfig.json"), "utf8").trim());
1515
const packageJson = JSON.parse(fs.readFileSync(path.join(process.cwd(), "/package.json"), "utf8").trim());
16-
this._cfg = extend(true, {}, def, this._cfg, { appVersion: {installed: packageJson.version }});
16+
this._cfg = extend(true, {}, def, this._cfg, { appVersion: { installed: packageJson.version } });
1717
this._isInitialized = true;
1818
this.getEnvVariables();
1919
this.update();
@@ -46,7 +46,7 @@ class Config {
4646
}
4747
section = arr[arr.length - 1];
4848
}
49-
if (JSON.stringify(c[section]) === JSON.stringify(val)){
49+
if (JSON.stringify(c[section]) === JSON.stringify(val)) {
5050
logger.silly(`setSection: Config section and val are identical. Not updating.`)
5151
}
5252
else {
@@ -55,7 +55,7 @@ class Config {
5555
}
5656
}
5757

58-
public getSection(section?: string, opts?: any) : any {
58+
public getSection(section?: string, opts?: any): any {
5959
if (typeof (section) === 'undefined') return this._cfg;
6060
var c: any = this._cfg;
6161
if (section.indexOf('.') !== -1) {
@@ -79,23 +79,20 @@ class Config {
7979
this.ensurePath(baseDir + '/data/outQueues/');
8080
}
8181
private ensurePath(dir: string) {
82-
if (!fs.existsSync(dir)) {
83-
fs.mkdir(dir, (err) => {
84-
// Logger will not be initialized by the time we reach here so we must
85-
// simply log these to the console.
86-
if (err) console.log(`Error creating directory: ${dir} - ${err}`);
87-
});
88-
}
82+
fs.mkdir(dir, { recursive: true }, (err) => {
83+
if (err) console.log(`Error creating directory: ${dir} - ${err}`);
84+
});
8985
}
90-
private getEnvVariables(){
86+
87+
private getEnvVariables() {
9188
// set docker env variables to config.json, if they are set
9289
let env = process.env;
9390
if (typeof env.POOL_HTTP_IP !== 'undefined' && env.POOL_HTTP_IP !== this._cfg.web.services.ip) {
9491
this._cfg.web.services.ip = env.POOL_HTTP_IP;
9592
}
96-
if (typeof env.POOL_HTTP_PORT !== 'undefined' && parseInt(env.POOL_HTTP_PORT,10) !== this._cfg.web.services.port) {
97-
this._cfg.web.services.port = parseInt(env.POOL_HTTP_PORT,10);
93+
if (typeof env.POOL_HTTP_PORT !== 'undefined' && parseInt(env.POOL_HTTP_PORT, 10) !== this._cfg.web.services.port) {
94+
this._cfg.web.services.port = parseInt(env.POOL_HTTP_PORT, 10);
9895
}
9996
}
10097
}
101-
export var config:Config = new Config();
98+
export var config: Config = new Config();

0 commit comments

Comments
 (0)