Skip to content

Instantly share code, notes, and snippets.

@pcolazurdo
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcolazurdo/c3d0f55046142f1f5c3e to your computer and use it in GitHub Desktop.
Save pcolazurdo/c3d0f55046142f1f5c3e to your computer and use it in GitHub Desktop.
Watson Explorer: Creating a Calendar Widget with info from Entities
<link href="http://fullcalendar.io/js/fullcalendar-2.3.1/fullcalendar.css" rel="stylesheet" />
<link href="http://fullcalendar.io/js/fullcalendar-2.3.1/fullcalendar.print.css" rel="stylesheet" media="print" />
<script prog src="http://fullcalendar.io/js/fullcalendar-2.3.1/lib/moment.min.js"></script>
<script prog src="http://fullcalendar.io/js/fullcalendar-2.3.1/fullcalendar.min.js"></script>
<% elementsTitle = []
elementsSnippet = []
query = entity_types('Eventos').where(subject.query).requesting(50)
query.each do |t|
begin
h = {}
h['start'] = Date.strptime(t['date'].first.to_str, '%m/%d/%y').strftime('%m/%d/%Y')
h['title'] = t['show'].first
h['color'] = 'red'
elementsTitle.push ( h )
rescue
#Avoid error when date is not formatted as expected
end
end
query = entity_types('Noticias').where(subject.query).requesting(50)
query.each do |t|
begin
h = {}
h['start'] = Date.parse(t['date'].first.to_str).strftime('%m/%d/%Y')
h['title'] = t['title'].first.gsub("'"," ")
h['color'] = 'green'
elementsTitle.push ( h )
rescue
#Avoid error when date is not formatted as expected
end
end
query = entity_types('Gacetillas').where(subject.query).requesting(50)
query.each do |t|
h = {}
h['start'] = t['date'].first
h['title'] = t['title'].first
h['color'] = 'blue'
elementsTitle.push ( h )
end
%>
<script prog>
$(document).ready(function() {
$('#calendar').fullCalendar({
firstDay: '1',
height: 400,
editable: false,
eventLimit: true, // allow "more" link when too many events
events: [
<% elementsTitle.each do |pp| %>
{start: '<%= pp['start'] %>',
title: '<%= pp['title'] %>',
color: '<%= pp['color'] %>'},
<% end %>
{start: '01/01/1970',
title: 'a'}
]
});
});
</script>
<div id="calendar"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment