Version Changes

This commit is contained in:
2019-01-14 09:57:57 +01:00
commit df89539710
5 changed files with 855 additions and 0 deletions
+207
View File
@@ -0,0 +1,207 @@
var DATE_LOCALE_FORMAT = "D.M.YY"; //10.2.16
var DATE_INPUT_FORMAT = "YYYY-MM-DD"; //2016-02-10
var TIME_FORMAT = "HH:mm"; // 17:30
var WEEKDAY_FORMAT = "dddd"; //Monday
var MOMENT_LOCALE = "de";
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;
}
Array.prototype.fromChipData = function () {
var strings = [];
this.forEach(function (el, id, array) {
strings.push(el.tag);
});
return strings;
}
function Rule(duration, arten, titel) {
this.duration = duration;
this.art = arten;
this.title = titel;
}
Rule.prototype = {
get Dauer() {
return this.duration;
},
set Dauer(value) {
this.duration = value;
},
get Arten() {
return this.art.asChipData();
},
set Arten(value) {
this.art = value.fromChipData();
},
get Titel() {
return this.title.asChipData();
},
set Titel(value) {
this.title = value.fromChipData();
}
};
Rule.prototype.fits = function (art, title) {
var artMatch = false;
var nameMatch = false;
if (this.art.length == 0) artMatch = true;
else {
this.art.forEach(function (el, i) {
if (art.includes(el.toLowerCase())) artMatch = true;
});
}
if (this.title.length == 0) nameMatch = true;
else {
this.title.forEach(function (el, i) {
if (name.includes(el.toLowerCase())) nameMatch = true;
});
}
return artMatch && nameMatch;
}
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, [], []));
return rules;
}
var DURATION_RULES = Rule.defaults();
function Shift(kind, name, date, info) {
'use strict';
this.Datum = date.format(DATE_INPUT_FORMAT);
this.Beginn = date.format(TIME_FORMAT);
this.Art = kind;
this.Beschreibung = info;
this.Name = name;
Shift.setDurationFromRules(this);
}
Shift.prototype = {
get Wochentag() {
return this._date.clone().locale(MOMENT_LOCALE).format(WEEKDAY_FORMAT);
},
set Wochentag(value) {
throw "kann nicht gesetzt werden.";
},
get FormattedDatum() {
return this._date.clone().format(DATE_LOCALE_FORMAT);
},
set FormattedDatum(value) {
var dateMoment = moment(value, DATE_LOCALE_FORMAT);
this._date = dateMoment;
},
get Datum() {
return this._date.clone().format(DATE_INPUT_FORMAT);
},
set Datum(value) {
var dateMoment = moment(value).startOf('day');
this._date = dateMoment.clone();
},
get Beginn() {
return this._begin.clone().format(TIME_FORMAT);
},
set Beginn(value) {
var dateMoment = moment(this.Datum + " " + value, DATE_INPUT_FORMAT + " " + TIME_FORMAT);
this._begin = dateMoment.clone();
},
get Ende() {
return this._begin.clone().add(this._duration).format(TIME_FORMAT);
},
set Ende(value) {
var dateMoment = moment(this.Datum + " " + value, DATE_INPUT_FORMAT + " " + TIME_FORMAT);
if (this._begin > dateMoment) {
dateMoment.add(1, 'd');
}
this._duration = moment.duration(dateMoment.diff(this._begin));
},
get Dauer() {
return this._duration;
},
set Dauer(duration) {
this._duration = duration;
},
get Name() {
return this._name;
},
set Name(value) {
this._name = value ? value.trim() : "";
},
get VEventTitle() {
return this.Name + " " + this.Art;
},
set VEventTitle(value) {
throw "kann nicht gesetzt werden.";
},
get Art() {
return this._kind;
},
set Art(value) {
this._kind = value ? value.trim() : "";
},
get Beschreibung() {
return this._description;
},
set Beschreibung(value) {
this._description = value ? value.trim() : "";
}
}
Shift.setDurationFromRules = function (shift) {
'use strict';
var art = shift.Art.toLowerCase();
var name = shift.Name.toLowerCase();
var duration = 60;
for (var rIndex in DURATION_RULES) {
var rule = DURATION_RULES[rIndex];
if (rule.fits(art, name)) {
duration = rule.Dauer;
break;
}
}
shift.Dauer = moment.duration(duration, 'm').locale(MOMENT_LOCALE);
}
Shift.prototype.toVEvent = function () {
'use strict';
var end = this._begin.clone().add(this._duration);
return new VEvent(TIMEZONE_NAME, this._begin, end, this.VEventTitle, this.Beschreibung);
};
Shift.thaw = function (jsonShift) {
'use strict';
moment.locale(MOMENT_LOCALE);
var begin = moment(jsonShift._begin);
var shift = new Shift(jsonShift._kind, jsonShift._name, begin, jsonShift._description);
shift.id = jsonShift.id;
shift.Dauer = moment.duration(jsonShift._duration);
return shift;
};
+128
View File
@@ -0,0 +1,128 @@
var VCAL_DATETIME_FORMAT = "YMMDD[T]HHmmss"; //20160216T130500
var UID_FORMAT = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
var NEW_LINE = "\r\n";
function VMeta() {
this.properties = new Map();
this.children = [];
this.tag = "VMETA";
}
VMeta.formatDate = function (aMoment) {
'use strict';
return aMoment.format(VCAL_DATETIME_FORMAT);
};
VMeta.generateUID = function () {
'use strict';
return UID_FORMAT.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0,
v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
};
VMeta.prototype.set = function (key, value) {
'use strict';
this.properties.set(key, value);
};
VMeta.prototype.get = function (key) {
'use strict';
this.properties.get(key);
};
VMeta.prototype.add = function (child) {
'use strict';
this.children.push(child);
};
VMeta.prototype.mapToString = function () {
'use strict';
var output = "";
this.properties.forEach(function (value, key, map) {
output += (NEW_LINE + key + ":" + value);
});
return output;
};
VMeta.prototype.childrenToString = function () {
'use strict';
var output = "";
this.children.forEach(function (child) {
output += (NEW_LINE + child.toString());
});
return output;
};
VMeta.prototype.toString = function () {
'use strict';
var output = "BEGIN:" + this.tag;
output += this.mapToString();
output += this.childrenToString();
output += (NEW_LINE + "END:" + this.tag);
return output;
};
function VCalendar(calendarName) {
'use strict';
VMeta.call(this);
this.add(VTimeZone.Berlin());
this.tag = "VCALENDAR";
this.set('X-WR-CALNAME', calendarName);
this.set('VERSION', '2.0');
this.set('PRODID', window.location.href);
this.set('METHOD', "PUBLISH");
this.set('X-WR-TIMEZONE', "Europe/Berlin");
this.set('CALSCALE', "GREGORIAN");
};
VCalendar.prototype = Object.create(VMeta.prototype);
VCalendar.prototype.constructor = VCalendar;
function VEvent(timezoneName, startMoment, endMoment, title, description) {
VMeta.call(this);
this.tag = "VEVENT";
this.set('DTSTART;TZID=' + timezoneName, VMeta.formatDate(startMoment));
this.set('DTEND;TZID=' + timezoneName, VMeta.formatDate(endMoment));
this.set('DTSTAMP', VMeta.formatDate(moment()) + "Z");
this.set('UID', VMeta.generateUID());
this.set('SUMMARY', title);
this.set('DESCRIPTION', description);
this.set('CLASS', "PUBLIC");
this.set('TRANSP', "OPAQUE");
this.set('STATUS', "CONFIRMED");
this.set('ORGANIZER', "");
}
VEvent.prototype = Object.create(VMeta.prototype);
VEvent.prototype.constructor = VEvent;
function VTimeZone() {
VMeta.call(this);
this.tag = "VTIMEZONE";
}
VTimeZone.prototype = Object.create(VMeta.prototype);
VTimeZone.prototype.constructor = VTimeZone;
VTimeZone.Berlin = function () {
var tz = new VTimeZone();
tz.children = [VTimeDef.MESZ(), VTimeDef.MEZ()];
tz.set("TZID", "Europe/Berlin");
return tz;
}
function VTimeDef(name) {
VMeta.call(this);
this.tag = name;
}
VTimeDef.prototype = Object.create(VMeta.prototype);
VTimeDef.prototype.constructor = VTimeDef;
VTimeDef.MESZ = function () {
var timedef = new VTimeDef("DAYLIGHT");
timedef.set("TZOFFSETFROM", "+0100");
timedef.set("RRULE", "FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU");
timedef.set("DTSTART", "19819329T020000");
timedef.set("TZNAME", "MESZ");
timedef.set("TZOFFSETTO", "+0200");
return timedef;
}
VTimeDef.MEZ = function () {
var timedef = new VTimeDef("STANDARD");
timedef.set("TZOFFSETFROM", "+0200");
timedef.set("RRULE", "FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU");
timedef.set("DTSTART", "19961027T030000");
timedef.set("TZNAME", "MEZ");
timedef.set("TZOFFSETTO", "+0100");
return timedef;
}