Cleanup calendar jsdoc

This commit is contained in:
rejas 2020-08-03 11:19:54 +02:00
parent 05659820d0
commit 1d4d5cc4e7
3 changed files with 52 additions and 37 deletions

View File

@ -452,7 +452,7 @@ Module.register("calendar", {
/** /**
* Creates the sorted list of all events. * Creates the sorted list of all events.
* *
* @returns {*[]} Array with events. * @returns {object[]} Array with events.
*/ */
createEventList: function () { createEventList: function () {
var events = []; var events = [];
@ -533,11 +533,6 @@ Module.register("calendar", {
return false; return false;
}, },
/* createEventList(url)
*
* argument url string - Url to add.
*/
/** /**
* Requests node helper to add calendar url. * Requests node helper to add calendar url.
* *

View File

@ -6,9 +6,27 @@
*/ */
const Log = require("../../../js/logger.js"); const Log = require("../../../js/logger.js");
const ical = require("ical"); const ical = require("ical");
const moment = require("moment");
const request = require("request"); const request = require("request");
/**
* Moment date
*
* @external Moment
* @see {@link http://momentjs.com}
*/
const moment = require("moment");
/**
*
* @param {string} url The url of the calendar to fetch
* @param {number} reloadInterval Time in ms the calendar is fetched again
* @param {string[]} excludedEvents An array of words / phrases from event titles that will be excluded from being shown.
* @param {number} maximumEntries The maximum number of events fetched.
* @param {number} maximumNumberOfDays The maximum number of days an event should be in the future.
* @param {object} auth The object containing options for authentication against the calendar.
* @param {boolean} includePastEvents If true events from the past maximumNumberOfDays will be fetched too
* @class
*/
const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, includePastEvents) { const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, includePastEvents) {
const self = this; const self = this;
@ -18,7 +36,7 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
let fetchFailedCallback = function () {}; let fetchFailedCallback = function () {};
let eventsReceivedCallback = function () {}; let eventsReceivedCallback = function () {};
/* fetchCalendar() /**
* Initiates calendar fetch. * Initiates calendar fetch.
*/ */
const fetchCalendar = function () { const fetchCalendar = function () {
@ -325,7 +343,7 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
}); });
}; };
/* scheduleTimer() /**
* Schedule the timer for the next update. * Schedule the timer for the next update.
*/ */
const scheduleTimer = function () { const scheduleTimer = function () {
@ -335,12 +353,11 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
}, reloadInterval); }, reloadInterval);
}; };
/* isFullDayEvent(event) /**
* Checks if an event is a fullday event. * Checks if an event is a fullday event.
* *
* argument event object - The event object to check. * @param {object} event The event object to check.
* * @returns {boolean} True if the event is a fullday event, false otherwise
* return bool - The event is a fullday event.
*/ */
const isFullDayEvent = function (event) { const isFullDayEvent = function (event) {
if (event.start.length === 8 || event.start.dateOnly) { if (event.start.length === 8 || event.start.dateOnly) {
@ -358,14 +375,13 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
return false; return false;
}; };
/* timeFilterApplies() /**
* Determines if the user defined time filter should apply * Determines if the user defined time filter should apply
* *
* argument now Date - Date object using previously created object for consistency * @param {Date} now Date object using previously created object for consistency
* argument endDate Moment - Moment object representing the event end date * @param {Moment} endDate Moment object representing the event end date
* argument filter string - The time to subtract from the end date to determine if an event should be shown * @param {string} filter The time to subtract from the end date to determine if an event should be shown
* * @returns {boolean} True if the event should be filtered out, false otherwise
* return bool - The event should be filtered out
*/ */
const timeFilterApplies = function (now, endDate, filter) { const timeFilterApplies = function (now, endDate, filter) {
if (filter) { if (filter) {
@ -380,12 +396,11 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
return false; return false;
}; };
/* getTitleFromEvent(event) /**
* Gets the title from the event. * Gets the title from the event.
* *
* argument event object - The event object to check. * @param {object} event The event object to check.
* * @returns {string} The title of the event, or "Event" if no title is found.
* return string - The title of the event, or "Event" if no title is found.
*/ */
const getTitleFromEvent = function (event) { const getTitleFromEvent = function (event) {
let title = "Event"; let title = "Event";
@ -416,14 +431,14 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
/* public methods */ /* public methods */
/* startFetch() /**
* Initiate fetchCalendar(); * Initiate fetchCalendar();
*/ */
this.startFetch = function () { this.startFetch = function () {
fetchCalendar(); fetchCalendar();
}; };
/* broadcastItems() /**
* Broadcast the existing events. * Broadcast the existing events.
*/ */
this.broadcastEvents = function () { this.broadcastEvents = function () {
@ -431,37 +446,37 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
eventsReceivedCallback(self); eventsReceivedCallback(self);
}; };
/* onReceive(callback) /**
* Sets the on success callback * Sets the on success callback
* *
* argument callback function - The on success callback. * @param {Function} callback The on success callback.
*/ */
this.onReceive = function (callback) { this.onReceive = function (callback) {
eventsReceivedCallback = callback; eventsReceivedCallback = callback;
}; };
/* onError(callback) /**
* Sets the on error callback * Sets the on error callback
* *
* argument callback function - The on error callback. * @param {Function} callback The on error callback.
*/ */
this.onError = function (callback) { this.onError = function (callback) {
fetchFailedCallback = callback; fetchFailedCallback = callback;
}; };
/* url() /**
* Returns the url of this fetcher. * Returns the url of this fetcher.
* *
* return string - The url of this fetcher. * @returns {string} The url of this fetcher.
*/ */
this.url = function () { this.url = function () {
return url; return url;
}; };
/* events() /**
* Returns current available events for this fetcher. * Returns current available events for this fetcher.
* *
* return array - The current available events for this fetcher. * @returns {object[]} The current available events for this fetcher.
*/ */
this.events = function () { this.events = function () {
return events; return events;

View File

@ -4,7 +4,6 @@
* By Michael Teeuw https://michaelteeuw.nl * By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed. * MIT Licensed.
*/ */
const NodeHelper = require("node_helper"); const NodeHelper = require("node_helper");
const validUrl = require("valid-url"); const validUrl = require("valid-url");
const CalendarFetcher = require("./calendarfetcher.js"); const CalendarFetcher = require("./calendarfetcher.js");
@ -24,12 +23,18 @@ module.exports = NodeHelper.create({
} }
}, },
/* createFetcher(url, reloadInterval) /**
* Creates a fetcher for a new url if it doesn't exist yet. * Creates a fetcher for a new url if it doesn't exist yet.
* Otherwise it reuses the existing one. * Otherwise it reuses the existing one.
* *
* attribute url string - URL of the news feed. * @param {string} url The url of the calendar
* attribute reloadInterval number - Reload interval in milliseconds. * @param {number} fetchInterval How often does the calendar needs to be fetched in ms
* @param {string[]} excludedEvents An array of words / phrases from event titles that will be excluded from being shown.
* @param {number} maximumEntries The maximum number of events fetched.
* @param {number} maximumNumberOfDays The maximum number of days an event should be in the future.
* @param {object} auth The object containing options for authentication against the calendar.
* @param {boolean} broadcastPastEvents If true events from the past maximumNumberOfDays will be included in event broadcasts
* @param {string} identifier ID of the module
*/ */
createFetcher: function (url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents, identifier) { createFetcher: function (url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents, identifier) {
var self = this; var self = this;