refactoring and reworking how to edit rules
This commit is contained in:
+61
-44
@@ -7,91 +7,108 @@ var TIMEZONE_NAME = "Europe/Berlin";
|
||||
//requires moment.js
|
||||
|
||||
Array.prototype.asChipData = function () {
|
||||
var chips = [];
|
||||
this.forEach(function (el, index, array) {
|
||||
chips.push({
|
||||
tag: el,
|
||||
id: index
|
||||
});
|
||||
});
|
||||
return chips;
|
||||
return this.map((e,i) => {return {tag:e,id:i}; })
|
||||
}
|
||||
Array.prototype.fromChipData = function () {
|
||||
var strings = [];
|
||||
this.forEach(function (el, id, array) {
|
||||
strings.push(el.tag);
|
||||
});
|
||||
return strings;
|
||||
return this.map(e => {return e.tag; })
|
||||
}
|
||||
|
||||
function Rule(duration, arten, titel) {
|
||||
this.duration = duration;
|
||||
this.art = arten;
|
||||
this.title = titel;
|
||||
function Rule() {
|
||||
var options = {};
|
||||
|
||||
if (arguments[0]) options = arguments[0];
|
||||
|
||||
var default_args = {
|
||||
'arten' : [],
|
||||
'dauer' : 60,
|
||||
'titel': [],
|
||||
'name' : "Standard"
|
||||
}
|
||||
for (var index in default_args) {
|
||||
if (typeof options[index] == "undefined") options[index] = default_args[index];
|
||||
}
|
||||
|
||||
this._duration = options.dauer;
|
||||
this._arten = options.arten;
|
||||
this._titel = options.titel;
|
||||
this._name = options.name;
|
||||
}
|
||||
|
||||
Rule.prototype = {
|
||||
get Dauer() {
|
||||
return this.duration;
|
||||
return this._duration;
|
||||
},
|
||||
set Dauer(value) {
|
||||
this.duration = value;
|
||||
this._duration = value;
|
||||
},
|
||||
|
||||
get Arten() {
|
||||
return this.art.asChipData();
|
||||
return this._arten.asChipData();
|
||||
},
|
||||
set Arten(value) {
|
||||
this.art = value.fromChipData();
|
||||
this._arten = value.fromChipData();
|
||||
},
|
||||
|
||||
get Titel() {
|
||||
return this.title.asChipData();
|
||||
return this._titel.asChipData();
|
||||
},
|
||||
set Titel(value) {
|
||||
this.title = value.fromChipData();
|
||||
}
|
||||
this._titel = value.fromChipData();
|
||||
},
|
||||
|
||||
get Name() {
|
||||
return this._name;
|
||||
},
|
||||
set Name(value) {
|
||||
this._name = value;
|
||||
},
|
||||
};
|
||||
Rule.prototype.fits = function (art, title) {
|
||||
var artMatch = false;
|
||||
var nameMatch = false;
|
||||
|
||||
if (this.art.length == 0) artMatch = true;
|
||||
if (this._arten.length == 0) artMatch = true;
|
||||
else {
|
||||
this.art.forEach(function (el, i) {
|
||||
this._arten.forEach(function (el, i) {
|
||||
if (art.includes(el.toLowerCase())) artMatch = true;
|
||||
});
|
||||
}
|
||||
|
||||
if (this.title.length == 0) nameMatch = true;
|
||||
if (this._titel.length == 0) nameMatch = true;
|
||||
else {
|
||||
this.title.forEach(function (el, i) {
|
||||
this._titel.forEach(function (el, i) {
|
||||
if (name.includes(el.toLowerCase())) nameMatch = true;
|
||||
});
|
||||
}
|
||||
|
||||
return artMatch && nameMatch;
|
||||
}
|
||||
Rule.thaw = function(json) {
|
||||
return new Rule({
|
||||
dauer: json._duration,
|
||||
name: json._name,
|
||||
arten: json._arten,
|
||||
titel: json._titel
|
||||
});
|
||||
}
|
||||
Rule.defaults = function () {
|
||||
var rules = [];
|
||||
rules.push(new Rule(60, ['VS'], ['Kinderkonzert']));
|
||||
rules.push(new Rule(120, ['VS'], ["expeditionskonzert", "sinfoniekonzert"]));
|
||||
rules.push(new Rule(150, ['Oa', 'GP'], ['Expeditionskonzert']));
|
||||
rules.push(new Rule(60, ['Oa', 'GP'], ['Expeditionskonzert']));
|
||||
rules.push(new Rule(150, ['Oa', 'OSP'], []));
|
||||
rules.push(new Rule(180, ["VS", "BO", "OHP", "HP", "GP", "Prem", "WA"], []));
|
||||
rules.push(new Rule(60, [], []));
|
||||
rules.push(new Rule(60, [], []));
|
||||
rules.push(new Rule(60, [], []));
|
||||
rules.push(new Rule(60, [], []));
|
||||
rules.push(new Rule(60, [], []));
|
||||
var input = [
|
||||
{name: "EF #01", dauer: 60, arten: ['VS'], titel: ['Kinderkonzert']},
|
||||
{name: "EF #02", dauer: 120, arten: ['VS'], titel: ["Expeditionskonzert", "Sinfoniekonzert"]},
|
||||
{name: "EF #03", dauer: 150, arten: ['Oa', 'GP'], titel: ['Expeditionskonzert']},
|
||||
{name: "EF #04", dauer: 60, arten: ['Oa', 'GP'], titel: ['Expeditionskonzert']},
|
||||
{name: "EF #05", dauer: 150, arten: ['Oa', 'OSP']},
|
||||
{name: "EF #06", dauer: 180, arten: ["VS", "BO", "OHP", "HP", "GP", "Prem", "WA"]},
|
||||
{name: "Standard", dauer: 60}
|
||||
];
|
||||
input.forEach(e => { rules.push(new Rule(e)); });
|
||||
|
||||
return rules;
|
||||
}
|
||||
var DURATION_RULES = Rule.defaults();
|
||||
|
||||
function Shift() {
|
||||
var evt = window.event || arguments[1] || arguments.callee.caller.arguments[0];
|
||||
var target = evt.target || evt.srcElement;
|
||||
|
||||
var options = {};
|
||||
|
||||
if (arguments[0]) options = arguments[0];
|
||||
@@ -218,12 +235,12 @@ Shift.setDurationFromRules = function (shift) {
|
||||
return;
|
||||
}
|
||||
var art = shift.Art.toLowerCase();
|
||||
var name = shift.Name.toLowerCase();
|
||||
var titel = shift.Name.toLowerCase();
|
||||
var duration = 60;
|
||||
for (var rIndex in DURATION_RULES) {
|
||||
var rule = DURATION_RULES[rIndex];
|
||||
|
||||
if (rule.fits(art, name)) {
|
||||
if (rule.fits(art, titel)) {
|
||||
duration = rule.Dauer;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user