From 5eb13d5e7db75ed010a33ffce6342643f3c32c4a Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 8 Aug 2014 13:57:09 -0400 Subject: [PATCH] LP#1329503 report edit scheduling repairs * ensure default values for scheduling and recurrence are applied with each edited report, including today's date in the scheduler. * If the most recent report run run_time is in the past, deafult to "run now" * fix bug with propagating months recurrence * If recurrence interval is in days and divisible by 7, present as weeks * make date regexes easier on the eyes * fix bug with rendering sets of org units * fixed bug with modifying report to be "run now" from scheduled. Signed-off-by: Bill Erickson Signed-off-by: Mike Rylander --- Open-ILS/web/reports/oils_rpt_report_editor.js | 66 ++++++++++++++++++-------- Open-ILS/web/reports/oils_rpt_widget.js | 5 +- 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/Open-ILS/web/reports/oils_rpt_report_editor.js b/Open-ILS/web/reports/oils_rpt_report_editor.js index 5db7a33fb5..ae69b467bc 100644 --- a/Open-ILS/web/reports/oils_rpt_report_editor.js +++ b/Open-ILS/web/reports/oils_rpt_report_editor.js @@ -84,7 +84,19 @@ oils_rpt_editor_pivot_data hideMe(DOM.oils_rpt_editor_pivot_label_row); hideMe(DOM.oils_rpt_editor_pivot_data_row); } - + + + // schedule defaults. + DOM.oils_rpt_param_editor_sched_start_date.value = mkYearMonDay(); + setSelector(DOM.oils_rpt_param_editor_sched_start_hour, '12:00'); + DOM.oils_rpt_report_editor_run_now.checked = true; + DOM.oils_rpt_report_editor_schedule.checked = false; + DOM.oils_rpt_param_editor_sched_start_date.disabled = true; + DOM.oils_rpt_param_editor_sched_start_hour.disabled = true; + + // recur defaults + setSelector(DOM.oils_rpt_recur_interval_type, 'days'); + setSelector(DOM.oils_rpt_recur_count, '1'); if( rpt ) { // populate the report edit form w/ report data @@ -101,9 +113,26 @@ oils_rpt_editor_pivot_data } if (rpt.recurrence()) { + console.log('editing report with recurrence: ' + rpt.recurrence()); var parts = rpt.recurrence().split(/ /); - setSelector(DOM.oils_rpt_recur_count, parts[0]); - setSelector(DOM.oils_rpt_recur_interval_type, parts[1]); + var type = parts[1]; + var count = Number(parts[0]); + + if (type.match(/^mon/)) { + // PG stores 'months' as 'mon(s)' + type = 'months'; + } else if (type.match(/^day/)) { + // PG stores weeks as days. Assuming a person would typically + // use weeks to represent sets of 7 days, translate back to + // weeks when we can. + if (count % 7 == 0) { + type = 'weeks'; + count = count / 7; + } + } + + setSelector(DOM.oils_rpt_recur_count, count); + setSelector(DOM.oils_rpt_recur_interval_type, type); } if (rpt.data()) { @@ -125,26 +154,26 @@ oils_rpt_editor_pivot_data DOM.oils_rpt_param_editor_sched_email.value = run.email(); if (run.run_time()) { - DOM.oils_rpt_report_editor_run_now.checked = false; - DOM.oils_rpt_report_editor_schedule.checked = true; - DOM.oils_rpt_param_editor_sched_start_date.disabled = false; - DOM.oils_rpt_param_editor_sched_start_hour.disabled = false; - - if (new Date(Date.parse(run.run_time())) < new Date()) { - // editing a report with a past-tense run time - // clear the value so the user will have to edit - DOM.oils_rpt_param_editor_sched_start_date.value = mkYearMonDay(); - } else { + console.log('view/edit report with last run_time: ' + run.run_time()); + if (new Date(Date.parse(run.run_time())) >= new Date() || this.readonly) { + // Next run of the edited report is scheduled for some time in the future. + // Propagate the value into the data selector and de-select run-now. + // Ditto read-only mode, so the user can see info on the most recent run. + DOM.oils_rpt_param_editor_sched_start_date.value = - run.run_time().match(/(\d\d\d\d-\d\d-\d\d)/)[1] + run.run_time().match(/(\d{4}-\d{2}-\d{2})/)[1] + setSelector( DOM.oils_rpt_param_editor_sched_start_hour, - run.run_time().match(/T(\d\d:\d\d)/)[1] + run.run_time().match(/T(\d{2})/)[1] + ':00' ); + + DOM.oils_rpt_report_editor_run_now.checked = false; + DOM.oils_rpt_report_editor_schedule.checked = true; + DOM.oils_rpt_param_editor_sched_start_date.disabled = false; + DOM.oils_rpt_param_editor_sched_start_hour.disabled = false; } - } else { - DOM.oils_rpt_param_editor_sched_start_date.value = mkYearMonDay(); - } + } } } @@ -335,7 +364,6 @@ oilsRptReportEditor.prototype.save = function(options) { var time; if( DOM.oils_rpt_report_editor_run_now.checked ) { - DOM.oils_rpt_report_editor_run_now.checked = false; time = 'now'; } else { diff --git a/Open-ILS/web/reports/oils_rpt_widget.js b/Open-ILS/web/reports/oils_rpt_widget.js index 2d617ef49d..2937e9ef15 100644 --- a/Open-ILS/web/reports/oils_rpt_widget.js +++ b/Open-ILS/web/reports/oils_rpt_widget.js @@ -36,7 +36,7 @@ oilsRptSetWidget.prototype.draw = function() { this_.addButton.onclick(); } - this.inputWidget.draw(post_draw); + this.inputWidget.draw(null, post_draw); this.node.appendChild(elem('br')) this.node.appendChild(this.addButton); this.node.appendChild(this.delButton); @@ -589,7 +589,8 @@ function oilsRptRemoteWidget(args) { this.source.disabled = Boolean(args.readonly); } -oilsRptRemoteWidget.prototype.draw = function(callback) { +// selected is unused +oilsRptRemoteWidget.prototype.draw = function(selected, callback) { var orgcol; iterate(oilsIDL[this.class].fields, function(i) { -- 2.11.0