TemplateTimelineService.js

angular.module('homepage').
// Store templates, location and widget data
factory('TemplateTimelineService', function (GlobalDataService, TimelineService) {
	function getItemsByDate(items, date) {
		if(date) {
			return TimelineService.getItemsByDate(items, date);
		}
		else {
			return TimelineService.getItemsByDate(items, GlobalDataService.getSelectedDate());
		}
	}

	/**
	 * Exclude items of type passed
	 * @param  {Array} items List of items to be filtered
	 * @param  {String} type  Type of item to be excluded
	 * @return {Array} items  Filtered items
	 */
	function excludeItemsByType(items, type) {
		return items.filter(function (item) {
			return item.type !== type;
		});
	}

	/**
	 * Include items of type passed
	 * @param  {Array} items List of items to be filtered
	 * @param  {String} type  Type of item to be included
	 * @return {Array} items  Filtered items
	 */
	function filterItemsByType(items, type) {
		return items.filter(function (item) {
			return item.type === type;
		});
	}

	return {
		getItemsByDate: getItemsByDate,
		excludeItemsByType: excludeItemsByType,
		filterItemsByType: filterItemsByType
	};
});