From 22a324d7a4a4be7344db84bdf458361f3d703fd7 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Tue, 2 May 2017 18:00:13 -0400 Subject: [PATCH] webstaff: add PredictionPattern.compile() method Signed-off-by: Galen Charlton --- .../staff/serials/directives/prediction_wizard.js | 110 +++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/Open-ILS/web/js/ui/default/staff/serials/directives/prediction_wizard.js b/Open-ILS/web/js/ui/default/staff/serials/directives/prediction_wizard.js index 8cb05468b1..01e8e3bfbe 100644 --- a/Open-ILS/web/js/ui/default/staff/serials/directives/prediction_wizard.js +++ b/Open-ILS/web/js/ui/default/staff/serials/directives/prediction_wizard.js @@ -250,6 +250,116 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider) { } } + // return current pattern compiled to subfield list + this.compile = function() { + var patternCode = []; + patternCode.push(self.compress_expand); + patternCode.push(self.caption_evaluation); + patternCode.push('8'); + patternCode.push(self.link); + if (self.use_enum) { + for (var i = 0; i < self.enum_levels.length; i++) { + patternCode.push(['a', 'b', 'c', 'd', 'e', 'f'][i]); + patternCode.push(self.enum_levels[i].caption); + if (i > 0 && self.enum_levels[i].units_per_next_higher) { + patternCode.push('u'); + if (self.enum_levels[i].units_per_next_higher.type == 'number') { + patternCode.push(self.enum_levels[i].units_per_next_higher.value); + } else { + patternCode.push(self.enum_levels[i].units_per_next_higher.type); + } + } + if (i > 0 && self.enum_levels[i].restart != null) { + patternCode.push('v'); + patternCode.push(self.enum_levels[i].restart ? 'r' : 'c'); + } + } + } + if (self.use_alt_enum) { + for (var i = 0; i < self.alt_enum_levels.length; i++) { + patternCode.push(['g','h'][i]); + patternCode.push(self.alt_enum_levels[i].caption); + if (i > 0 && self.alt_enum_levels[i].units_per_next_higher) { + patternCode.push('u'); + if (self.alt_enum_levels[i].units_per_next_higher.type == 'number') { + patternCode.push(self.alt_enum_levels[i].units_per_next_higher.value); + } else { + patternCode.push(self.alt_enum_levels[i].units_per_next_higher.type); + } + } + if (i > 0 && self.alt_enum_levels[i].restart != null) { + patternCode.push('v'); + patternCode.push(self.alt_enum_levels[i].restart ? 'r' : 'c'); + } + } + } + var chron_sfs = (self.use_enum) ? ['i', 'j', 'k', 'l'] : ['a', 'b', 'c', 'd']; + if (self.use_chron) { + for (var i = 0; i < self.chron_levels.length; i++) { + patternCode.push(chron_sfs[i], + self.chron_levels[i].display_caption ? + self.chron_levels[i].caption : + '(' + self.chron_levels[i].caption + ')' + ); + } + } + var alt_chron_sf = (self.use_enum) ? 'm' : 'g'; + if (self.use_alt_chron) { + patternCode.push(alt_chron_sf, + self.alt_chron_levels[0].display_caption ? + self.alt_chron_levels[0].caption : + '(' + self.alt_chron_levels[0].caption + ')' + ); + } + // frequency + patternCode.push('w', + self.frequency_type == 'numeric' ? + self.frequency_numeric : + self.frequency_preset + ); + // calendar change + if (self.use_calendar_change) { + patternCode.push('x'); + patternCode.push(self.calendar_change.map(function(chg) { + if (chg.type == 'season') { + return chg.season; + } else if (chg.type == 'month') { + return chg.month; + } else if (chg.type == 'date') { + return chg.month + chg.day; + } + }).join(',')); + } + // regularity + if (self.use_regularity) { + self.regularity.forEach(function(reg) { + patternCode.push('y'); + var val = reg.regularity_type + reg.chron_type; + val += reg.parts.map(function(part) { + if (reg.chron_type == 'd') { + return part[part.sub_type]; + } else if (reg.chron_type == 'm') { + return part.month; + } else if (reg.chron_type == 'w') { + if (part.sub_type == 'week_in_month') { + return part.week + part.month; + } else if (part.sub_type == 'week_day') { + return part.week + part.day; + } else if (part.sub_type == 'week_day_in_month') { + return part.month + part.week + part.day; + } + } else if (reg.chron_type == 's') { + return part.season; + } else if (reg.chron_type == 'y') { + return part.year; + } + }).join(','); + patternCode.push(val); + }); + } + return JSON.stringify(patternCode); + } + this.add_enum_level = function() { if (self.enum_levels.length < 6) { self.enum_levels.push({ -- 2.11.0