node-red-contrib-ical-events
Version:
NodeRed calender event adapter
693 lines (672 loc) • 25.6 kB
HTML
<script type="text/javascript">
//@ts-nocheck
var icalDefaults = {
confignode: {
value: "",
type: "ical-config",
required: false
},
timeout: {
value: ""
},
timeoutUnits: {
value: ""
},
cron: {
value: ""
},
name: {
value: ""
},
offsettype: {},
offset: {
value: ""
},
offsetUnitstype: {},
offsetUnits: {
value: ""
},
eventtypes: {},
eventtypestype: {},
calendar: {},
calendartype: {},
triggertype: {},
trigger: {},
timezone: {},
timezonetype: {},
dateformat: {},
dateformattype: {},
language: {},
languagetype: {},
filterProperty: {},
filterPropertytype: {},
filterOperator: {},
filterOperatortype: {},
filtertype: {},
filter2type: {},
filter2: {
required: false,
validate: function (v) {
var val = $("#node-input-filter2").val();
if (!val)
return true;
try {
//@ts-ignore
if ($("#node-input-filterProperty").val().indexOf('event') >= 0) {
var reg = new RegExp(/^(19|20)\d\d[-/.](0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])_([0-1][0-9]|2[0-3])[:]([0-5][0-9])[:]([0-5][0-9])$/);
return reg.test(v);
}
else {
new RegExp(v);
return true;
}
}
catch (e) {
return false;
}
},
},
filter: {
required: false,
validate: function (v) {
var val = $("#node-input-filter").val();
if (!val)
return true;
try {
//@ts-ignore
if ($("#node-input-filterProperty").val().indexOf('event') >= 0) {
var reg = new RegExp(/^(19|20)\d\d[-/.](0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])_([0-1][0-9]|2[0-3])[:]([0-5][0-9])[:]([0-5][0-9])$/);
return reg.test(v);
}
else {
new RegExp(v);
return true;
}
}
catch (e) {
return false;
}
},
},
};
//@ts-nocheck
function timezones() {
var dataArray = [];
$.getJSON("timezones", function (data) {
$.each(data, function (i, element) {
dataArray.push(element);
});
});
$("#node-input-timezone").typedInput({
typeField: "#node-input-timezonetype",
default: "str",
types: ["str", "msg",
{
value: "timezone",
label: "timezone",
autoComplete: function (val) {
var matches = [];
dataArray.forEach(function (v) {
var i = v.toLowerCase().indexOf(val.toLowerCase());
if (i > -1) {
matches.push({
value: v,
label: v,
i: i
});
}
});
matches.sort(function (A, B) { return A.i - B.i; });
return matches;
}
}],
});
}
RED
.nodes
.registerType('ical-events', {
category: 'ical',
defaults: Object.assign(icalDefaults,
{
offsettype: {},
offset: {
value: ""
},
offsetUnitstype: {},
offsetUnits: {
value: ""
},
}),
inputs: 1,
outputs: 2,
outputLabels: ["Start Message", "End Message"],
color: "#DEBD5C",
label: function () {
if (this.name) {
return this.name;
} else if (this.confignode.name) {
return this.confignode.name;
}
return "event trigger";
},
icon: "font-awesome/fa-calendar",
paletteLabel: "trigger",
oneditprepare: function () {
//@ts-nocheck
var node = this;
timezones();
$("#node-input-eventtypes").typedInput({
typeField: "#node-input-eventtypestype",
types: ["str", "msg", {
value: "eventtypes",
multiple: true,
options: [
//@ts-ignore
{ value: "events", label: "Events" },
//@ts-ignore
{ value: "todos", label: "Todos" }
]
}]
});
$('#node-input-confignode').change(function () {
var value = $('#node-input-confignode').val();
$.post("icalconfig", { id: value }, function (icalconfig) {
if (icalconfig.type !== 'caldav') {
$('#node-input-eventtypes').parent().hide();
$('#node-input-calendar').parent().hide();
}
else {
$('#node-input-eventtypes').parent().show();
$('#node-input-calendar').parent().show();
}
if ((!node.eventtypes || node.eventtypes.trim() === '')) {
$("#node-input-eventtypes").typedInput('type', 'eventtypes');
$("#node-input-eventtypes").typedInput('value', icalconfig.includeTodo === true ? 'events,todos' : 'events');
node.eventtypes = icalconfig.includeTodo === true ? 'events,todos' : 'events';
}
});
});
$("#node-input-dateformat").typedInput({
typeField: "#node-input-dateformattype",
types: ["json", "msg"]
});
if (!node.dateformat) {
$('#node-input-dateformat').typedInput('value', '{ "timeStyle": "short", "dateStyle": "short" }');
}
$("#node-input-filter").typedInput({
typeField: "#node-input-filtertype",
types: ["str", "msg"]
});
$("#node-input-filter2").typedInput({
typeField: "#node-input-filter2type",
types: ["str", "msg"]
});
$("#node-input-calendar").typedInput({
typeField: "#node-input-calendartype",
types: ["str", "msg"]
});
$("#node-input-filterProperty").typedInput({
typeField: "#node-input-filterPropertytype",
default: "filterProperty",
types: ["str", "msg", {
value: "filterProperty",
options: [
//@ts-ignore
{ value: "summary", label: "summary" },
//@ts-ignore
{ value: "description", label: "description" },
//@ts-ignore
{ value: "attendee", label: "attendee" },
//@ts-ignore
{ value: "categories", label: "category" },
//@ts-ignore
{ value: "location", label: "location" },
//@ts-ignore
{ value: "eventStart", label: "start date" },
//@ts-ignore
{ value: "eventEnd", label: "end date" },
]
}]
});
$("#node-input-language").typedInput({
typeField: "#node-input-languagetype",
default: "language",
types: ["str", "msg", {
value: "language",
options: [
{ value: "en", label: "English" },
{ value: "de", label: "Deutsch" },
{ value: "ru", label: "русский" },
{ value: "pl", label: "polski" },
{ value: "nl", label: "Nederlands" },
{ value: "fr", label: "français" },
{ value: "it", label: "Italiano" },
{ value: "es", label: "Espanol" },
]
}]
});
$("#node-input-filterOperator").typedInput({
typeField: "#node-input-filterOperatortype",
default: "filterOperator",
types: ["str", "msg", {
value: "filterOperator",
options: [
//@ts-ignore
{ value: "between", label: "between" },
//@ts-ignore
{ value: "before", label: "before" },
//@ts-ignore
{ value: "after", label: "after" }
]
}]
});
$("#node-input-trigger").typedInput({
typeField: "#node-input-triggertype",
default: "trigger",
types: ["str", "msg", {
value: "trigger",
options: [
//@ts-ignore
{ value: "always", label: "Always" },
//@ts-ignore
{ value: "match", label: "Match" },
//@ts-ignore
{ value: "nomatch", label: "No match" }
]
}]
});
if (!node.timeoutUnits) {
$('#node-input-timeoutUnits option')
.filter(function () {
return $(this).val() == 'seconds';
})
.attr('selected', 'true');
}
if (!node.trigger) {
$('#node-input-trigger option')
.filter(function () {
return $(this).val() == 'always';
})
.attr('selected', 'true');
}
if (node.trigger && !node.filterProperty) {
$('#node-input-filterProperty option')
.filter(function () {
return $(this).val() == 'summary';
})
.attr('selected', 'true');
}
$('#node-input-cron').change(function () {
var value = $('#node-input-cron').val();
if (value && value.length > 0) {
$('#timeout-details-for').hide();
}
else {
$('#timeout-details-for').show();
}
});
if (node.trigger && node.filterProperty && node.filterProperty.indexOf('event') >= 0 && !node.filterOperator) {
$('#node-input-filterOperator option')
.filter(function () {
return $(this).val() == 'between';
})
.attr('selected', 'true');
}
$('#node-input-trigger').change(function () {
var value = $('#node-input-trigger').val();
var filterProperty = $('#node-input-filterProperty').val();
if (value && value === 'always') {
$('#node-input-filterProperty').parent().hide();
$('#node-input-filter').parent().hide();
$('#node-input-filter2').parent().hide();
$('#node-input-filterOperator').parent().hide();
$('#filter-tip').hide();
return;
}
else {
$('#node-input-filterProperty').parent().show();
$('#node-input-filter').parent().show();
if (!node.filterProperty) {
$('#node-input-filterProperty option')
.filter(function () {
return $(this).val() == 'summary';
})
.attr('selected', 'true');
}
if (!node.filterOperator) {
$('#node-input-filterOperator option')
.filter(function () {
return $(this).val() == 'between';
})
.attr('selected', 'true');
$('#node-input-filter-label1').hide();
$('#node-input-filter-label2').show();
$('#node-input-filter2-label1').hide();
$('#node-input-filter2-label2').show();
$('#node-input-filter-label3').hide();
}
//@ts-ignore
if (filterProperty && filterProperty.indexOf('event') >= 0) {
$('#node-input-filter2').parent().show();
$('#node-input-filterOperator').parent().show();
$('#filter-tip').show();
var filterOperator = $('#node-input-filterOperator').val();
if (filterOperator === 'between') {
$('#node-input-filter-label1').hide();
$('#node-input-filter-label2').show();
$('#node-input-filter2-label1').hide();
$('#node-input-filter2-label2').show();
$('#node-input-filter-label3').hide();
}
else {
$('#node-input-filter2-label2').hide();
$('#node-input-filter2-label1').show();
if (filterOperator === 'before') {
$('#node-input-filter-label2').hide();
$('#node-input-filter-label3').show();
$('#node-input-filter-label1').hide();
}
else {
$('#node-input-filter-label2').show();
$('#node-input-filter-label3').hide();
$('#node-input-filter-label1').hide();
}
}
}
else {
$('#node-input-filter2').parent().hide();
$('#node-input-filterOperator').parent().hide();
$('#filter-tip').hide();
$('#node-input-filter-label2').hide();
$('#node-input-filter-label1').show();
$('#node-input-filter-label3').hide();
}
}
});
$('#node-input-filterProperty').change(function () {
var value = $('#node-input-filterProperty').val();
var trigger = $('#node-input-trigger').val();
if (!node.filterProperty) {
$('#node-input-filterProperty option')
.filter(function () {
return $(this).val() == 'summary';
})
.attr('selected', 'true');
}
if (!node.filterOperator) {
$('#node-input-filterOperator option')
.filter(function () {
return $(this).val() == 'between';
})
.attr('selected', 'true');
$('#node-input-filter-label1').hide();
$('#node-input-filter-label2').show();
$('#node-input-filter2-label1').hide();
$('#node-input-filter2-label2').show();
$('#node-input-filter-label3').hide();
}
if (trigger === "always")
return;
//@ts-ignore
if (value && value.indexOf('event') >= 0) {
$('#node-input-filter2').parent().show();
$('#node-input-filterOperator').parent().show();
$('#filter-tip').show();
var filterOperator = $('#node-input-filterOperator').val();
if (filterOperator === 'between') {
$('#node-input-filter-label1').hide();
$('#node-input-filter-label2').show();
$('#node-input-filter2-label1').hide();
$('#node-input-filter2-label2').show();
$('#node-input-filter-label3').hide();
}
else {
$('#node-input-filter2-label2').hide();
$('#node-input-filter2-label1').show();
if (filterOperator === 'before') {
$('#node-input-filter-label2').hide();
$('#node-input-filter-label3').show();
$('#node-input-filter-label1').hide();
}
else {
$('#node-input-filter-label2').show();
$('#node-input-filter-label3').hide();
$('#node-input-filter-label1').hide();
}
}
}
else {
$('#node-input-filter2').parent().hide();
$('#node-input-filterOperator').parent().hide();
$('#filter-tip').hide();
$('#node-input-filter-label2').hide();
$('#node-input-filter-label1').show();
$('#node-input-filter-label3').hide();
}
});
$('#node-input-filterOperator').change(function () {
var value = $('#node-input-filterOperator').val();
var trigger = $('#node-input-trigger').val();
var filterProperty = $('#node-input-filterProperty').val();
if (trigger === "always")
return;
//@ts-ignore
if (filterProperty && ['eventStart', 'eventEnd'].indexOf(filterProperty) >= 0) {
if (value === 'between') {
$('#node-input-filter2').parent().show();
$('#node-input-filter-label1').hide();
$('#node-input-filter-label2').show();
$('#node-input-filter2-label1').hide();
$('#node-input-filter2-label2').show();
$('#node-input-filter-label3').hide();
}
else {
$('#node-input-filter2').parent().hide();
$('#node-input-filter2-label2').hide();
$('#node-input-filter2-label1').show();
if (value === 'before') {
$('#node-input-filter-label2').hide();
$('#node-input-filter-label3').show();
$('#node-input-filter-label1').hide();
}
else {
$('#node-input-filter-label2').show();
$('#node-input-filter-label3').hide();
$('#node-input-filter-label1').hide();
}
}
}
});
$('#node-input-combineResponse').parent().hide();
$('#node-input-pastview').parent().hide();
$('#node-input-preview').parent().hide();
$('#node-input-checkall').parent().hide();
$("#node-input-offsetUnits").typedInput({
typeField: "#node-input-offsetUnitstype",
default: "offsetUnits",
types: ["str", "msg", {
value: "offsetUnits",
options: [
{ value: "seconds", label: "Seconds" },
{ value: "minutes", label: "Minutes" },
{ value: "hours", label: "Hours" },
{ value: "days", label: "Days" }
]
}]
});
$("#node-input-offset").typedInput({
typeField: "#node-input-offsettype",
types: ["num", "str", "msg"]
}).typedInput('width', '200px');
$('#node-input-offset').on('change', function (event, type, value) {
if (type === 'str') {
$('#offsetUnits').hide();
} else {
$('#offsetUnits').show();
}
});
if (!this.offsetUnits) {
$("#node-input-offsetUnits option").filter(function () {
return $(this).val() == 'minutes';
}).attr('selected', true);
}
}
})
</script>
<script type="text/html" id="icalEvents-template" data-template-name="ical-events">
<style>
.event {
display: flex;
}
.event .red-ui-typedInput-container {
flex: 1
}
.event span {
flex: 1
}
.event label {
min-width: 140px;
align-self: center;
}
.padding-top {
padding-top: 10px;
}
</style>
<div class="form-row event">
<label for="node-input-name"><i class="fa fa-tag"></i> <span>Name</span></label>
<input type="text" id="node-input-name">
</div>
<hr />
<h3>Config</h3>
<div class="form-row event">
<label for="node-input-confignode"><i class="fa fa-globe"></i> <span>Calendar config</span></label>
<input type="text" id="node-input-confignode">
</div>
<div class="form-row padding-top">
<label for="node-input-checkall" style="width:200px !important">
<i class="fa fa-asterisk"></i>
<span>Fetch all configs concurrent</span></label>
<input type="checkbox" id="node-input-checkall" placeholder="" style="width:16px !important">
</div>
<div class="form-row event padding-top">
<label for="node-input-calendar">
<i class="fa fa-calendar"></i>
<span>Calendar</span>
</label>
<input type="text" id="node-input-calendar" placeholder="">
<input type="hidden" id="node-input-calendartype" placeholder="">
</div>
<div class="form-row event">
<label for="node-input-eventtypes">
<i class="fa fa-asterisk"></i>
<span>Event types</span></label>
<input type="text" id="node-input-eventtypes" placeholder="events,todos">
<input type="hidden" id="node-input-eventtypestype" placeholder="">
</div>
<hr>
<h3>Check, trigger and filter</h3>
<div class="form-row event padding-top" id="timeout-details-for">
<label for="node-input-timeout"><i class="fa fa-clock-o"></i> <span>Check every</span></label>
<input type="text" id="node-input-timeout" style="text-align:end; width:50px !important" placeholder="0">
<select id="node-input-timeoutUnits" style="width:200px !important">
<option value="seconds">Seconds</option>
<option value="minutes">Minutes</option>
<option value="hours">Hours</option>
<option value="days">Days</option>
</select>
</div>
<div class="form-row event">
<label for="node-input-cron"><i class="fa fa-clock-o"></i> <span>Cron</span></label>
<input type="text" id="node-input-cron">
</div>
<div class="form-row event">
<label for="node-input-trigger"><i class="fa fa-filter"></i> <span>Trigger</span></label>
<input type="text" id="node-input-trigger" style="text-align:end; width:50px !important" placeholder="always">
<input type="hidden" id="node-input-triggertype" style="text-align:end; width:50px !important">
</div>
<div class="form-row event">
<input type="hidden" id="node-input-filterPropertytype">
<label for="node-input-filterProperty"><i class="fa fa-filter"></i> Filter property</label>
<input type="text" id="node-input-filterProperty" placeholder="summary">
</div>
<div class="form-row event">
<input type="hidden" id="node-input-filterOperatortype">
<label for="node-input-filterOperator"><i class="fa fa-filter"></i> Filter operator</label>
<input type="text" id="node-input-filterOperator" placeholder="between">
</div>
<div class="form-tips" id="filter-tip" style="margin-bottom: 10px">
<i class="fa fa-exclamation"></i>
<b>HINT:</b> filter format for dates is <b>YYYY-MM-DD_hh:mm:sss</b>
</div>
<div class="form-row event">
<label for="node-input-filter" id="node-input-filter-label1"><i class="fa fa-filter"></i> Filter</label>
<label for="node-input-filter" id="node-input-filter-label2"><i class="fa fa-filter"></i> after</label>
<label for="node-input-filter" id="node-input-filter-label3"><i class="fa fa-filter"></i> before</label>
<input type="text" id="node-input-filter">
<input type="hidden" id="node-input-filtertype">
</div>
<div class="form-row event">
<label for="node-input-filter2" id="node-input-filter2-label1"><i class="fa fa-filter"></i> Filter2</label>
<label for="node-input-filter2" id="node-input-filter2-label2"><i class="fa fa-filter"></i> before</label>
<input type="text" id="node-input-filter2">
<input type="hidden" id="node-input-filter2type">
</div>
<div class="form-row event" id="delay-details-for">
<input type="hidden" id="node-input-previewtype" style="text-align:end; width:50px !important">
<input type="hidden" id="node-input-previewUnitstype" style="text-align:end; width:50px !important">
<label for="node-input-preview"><i class="fa fa-clock-o"></i> <span>Preview</span></label>
<input type="text" id="node-input-preview" style="text-align:end; width:50px !important" placeholder="10">
<span class="event" id="previewUnits"><input type="text" id="node-input-previewUnits"
style="text-align:end; width:50px !important" placeholder="timeunit"></span>
</div>
<div class="form-row event" id="pastview-details-for">
<input type="hidden" id="node-input-pastviewtype" style="text-align:end; width:50px !important">
<input type="hidden" id="node-input-pastviewUnitstype" style="text-align:end; width:50px !important">
<label for="node-input-pastview"><i class="fa fa-clock-o"></i> <span>Past view</span></label>
<input type="text" id="node-input-pastview" style="text-align:end; width:50px !important" placeholder="1">
<span class="event" id="pastviewUnits"><input type="text" id="node-input-pastviewUnits"
style="text-align:end; width:50px !important" placeholder="timeunit"></span>
</div>
<div class="form-row event">
<label for="node-input-offset"><i class="fa fa-clock-o"></i> <span>Offset</span></label>
<input type="hidden" id="node-input-offsettype">
<input type="hidden" id="node-input-offsetUnitstype">
<input type="text" id="node-input-offset">
<span class="event" id="offsetUnits">
<input type="text" id="node-input-offsetUnits">
</span>
</div>
<hr>
<h3>Dateformat</h3>
<div class="form-row event">
<label for="node-input-timezone"><i class="fa fa-filter"></i> Timezone for eventStart / eventEnd</label>
<input type="text" id="node-input-timezone" placeholder="UTC">
<input type="hidden" id="node-input-timezonetype">
</div>
<div class="form-row event">
<label for="node-input-dateformat"><i class="fa fa-filter"></i> Dateformat</label>
<input type="text" id="node-input-dateformat" placeholder="">
<input type="hidden" id="node-input-dateformattype">
</div>
<div class="form-row event">
<label for="node-input-language"> <i class="fa fa-language"></i> Date language</label>
<input type="text" id="node-input-language">
<input type="hidden" id="node-input-languagetype">
</div>
<hr>
<div class="form-row event">
<label for="node-input-combineResponse" style="width:190px !important">
<i class="fa fa-asterisk"></i>
<span>combine to one message</span></label>
<input type="checkbox" id="node-input-combineResponse" placeholder=""
style="flex:0; width: auto; margin-right: 10px">
<span id="combine-response-hint">(payload will be an array)</span>
</div>
</script>
<script type="text/html" data-help-name="ical-events">
<div class="form-row">
<a href="https://naimo84.github.io/kalender-events/guide/trigger.html">
<img src="https://img.shields.io/badge/doku-naimo84.github.io-0078D6?style=for-the-badge&logo=github&logoColor=white"/>
</a>
</div>
</script>