Skip to content

Instantly share code, notes, and snippets.

@Luzifer
Last active May 13, 2016 10:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Luzifer/11090980 to your computer and use it in GitHub Desktop.
Save Luzifer/11090980 to your computer and use it in GitHub Desktop.
A simple clone of the Dashing-Milkman widget which does not require API access to the API but uses the non-event iCalendar whose URL you can get on your dashboard.

Preview

Description

A simple clone of the Dashing-Milkman widget which does not require API access to the API but uses the non-event iCalendar whose URL you can get on your dashboard.

Dependencies

Add them to dashing's gemfile:

gem 'icalendar'
gem 'haml'
gem 'httparty'

and run bundle install. Also you need to require 'haml' in your config.ru.

Everything should work now :)

##Usage

To use this widget, copy rtm.haml, rtm.coffee, and rtm.scss into the /widgets/rtm directory. Put the rtm.rb file in your /jobs folder.

To include the widget in a dashboard, add the following snippet to the dashboard layout file:

<li data-row="1" data-col="4" data-sizex="1" data-sizey="1">
  <div data-id="rtm" data-view="Rtm"></div>
</li>

##Settings

Go to your All tasks list, copy the URL of the iCalendar link (the iCalendar (Events) link will not contain all tasks!) to the rtm.rb file and replace the webcal:// protocol with http://.

Tasks are fetched every 5 minutes, but you can change that by editing the job schedule.

class Dashing.Rtm extends Dashing.Widget
%i(class="icon-tasks icon-background")
%ul
%li(data-foreach-item="items")
%span(data-bind-class="item.priority | prepend 'priority priority-'")
%span(class="name" data-bind="item.name")
%span(class="date" data-bind="item.formatted_date")
%p(class="updated-at" data-bind="updatedAtMessage")
require 'icalendar'
require 'httparty'
ical_url = '<place your calendar url here>'
date_format = '%d.%m.%y'
SCHEDULER.every "5m", first_in: 0 do |job|
ical_data = HTTParty.get(ical_url).body
cal = Icalendar::Parser.new(ical_data, false).parse
todos = []
events = []
cal.first.todos.each do |event|
next if not event.completed.nil?
unless event.due.nil?
events << { summary: event.summary, due: event.due, prio: event.priority }
else
todos << { summary: event.summary, prio: event.priority }
end
end
send = []
todos.sort.each do |todo|
send << { name: todo[:summary], formatted_date: '', priority: todo[:prio] }
end
events.sort{ |x,y| x[:due] <=> y[:due] }.each do |event|
send << { name: event[:summary], formatted_date: event[:due].strftime(date_format), priority: event[:prio] }
end
send_event('rtm', {items: send})
end
$background-color: #2983E0
.widget-rtm
background-color: $background-color
h1
height: 141px
li
text-transform: uppercase
text-align: left
font-size: 12px
padding: 2px 0
span
display: inline-block
vertical-align: middle
text-overflow: ellipsis
overflow: hidden
white-space: nowrap
font-weight: bold
&.name
position: absolute
left: 28px
right: 75px
padding: 2px 0 0 0
min-width: 195px
&.date
position: absolute
right: 15px
width: 55px
padding: 2px 0 0 0
text-align: right
p
&.updated-at
text-transform: uppercase
letter-spacing: 1px
font-size: 10px
color: lighten($background-color, 15%)
.priority
display: inline-block
margin: 0 5px
height: 17px
width: 5px
.priority-3
background-color: #359fff
.priority-2
background-color: #0f46b9
.priority-1
background-color: #dd3f00
.priority-N
background-color: transparent
@smacdonald23
Copy link

Hi, I'm having an issue and the error i'm getting is:

W, [2016-05-11T14:50:27.701899 #26499] WARN -- : No method "last_modified=" for component #Icalendar::Calendar:0x00000003383508. Appending to custom.

Anybody seen this before

@levinceeent
Copy link

Hi, I'm having the same issue, error is:

W, [2016-05-12T22:17:24.300376 #1821] WARN -- : No method "last_modified=" for component #Icalendar::Calendar:0x31e1fe0. Appending to custom.

scheduler caught exception:
comparison of Hash with Hash failed
/home/pi/test_dashboard_project/jobs/rtm.rb:23:in sort' /home/pi/test_dashboard_project/jobs/rtm.rb:23:inblock in <top (required)>'
/var/lib/gems/2.1.0/gems/rufus-scheduler-2.0.24/lib/rufus/sc/jobs.rb:230:in call' /var/lib/gems/2.1.0/gems/rufus-scheduler-2.0.24/lib/rufus/sc/jobs.rb:230:intrigger_block'
/var/lib/gems/2.1.0/gems/rufus-scheduler-2.0.24/lib/rufus/sc/jobs.rb:204:in block in trigger' /var/lib/gems/2.1.0/gems/rufus-scheduler-2.0.24/lib/rufus/sc/scheduler.rb:430:incall'
/var/lib/gems/2.1.0/gems/rufus-scheduler-2.0.24/lib/rufus/sc/scheduler.rb:430:in `block in trigger_job'

anyway to fix this?

@smacdonald23
Copy link

I dont get any RM errors just the iCal error :( I want it fixing...

@Luzifer
Copy link
Author

Luzifer commented May 13, 2016

Maybe a broken library / breaking change in icalendar library… You could try downgrading icalendar to an older version… This Gist is more than 2 years old so most likely the library changed quite a lot during that time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment