Skip to content

Instantly share code, notes, and snippets.

@rahulsom
Created June 3, 2015 14:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rahulsom/350f00cd49c782157ee4 to your computer and use it in GitHub Desktop.
Save rahulsom/350f00cd49c782157ee4 to your computer and use it in GitHub Desktop.
Confluence Calendar for Dashing

Confluence Calendar for Dashing

This is designed to pull out .ics representations of your calendar from confluence and render upcoming events.

class Dashing.ConfluenceCalendar extends Dashing.Widget
computeRange: (start, end) ->
range = moment(start).twix(end)
allDayRange = moment(start).twix(end, {allDay: true})
if (range.asDuration().asHours() > 8 || start == end)
retval = allDayRange.format({showDayOfWeek: true})
else
retval = range.format({showDayOfWeek: true})
retval
ready: ->
for td in jQuery('td.ccrange')
$td = jQuery(td)
range = @computeRange($td.attr('start'), $td.attr('end'))
$td.html(range)
onData: (data) ->
for row in data.data
row.range = @computeRange(row.start, row.end)
<table>
<tbody data-foreach-item="data">
<tr>
<td class="ccrange" data-bind="item.range" data-bind-start="item.start" data-bind-end="item.end"></td>
<td data-bind="item.summary" class="title"></td>
</tr>
<tr data-bind-class="item.show">
<td ></td>
<td colspan="1" data-bind="item.attendees" class="attendees"></td>
</tr>
</tbody>
</table>
<p class="updated-at" data-bind="updatedAtMessage"></p>
require 'net/http'
require 'icalendar'
require 'icalendar/recurrence'
require 'time'
require 'tzinfo'
require 'pp'
CONFLUENCE_URI = URI.parse('https://example.atlassian.net/wiki')
CALENDARS = {
:Alpha => '77965988c4c35acf627df95d524d221337f57009',
:Bravo => '77e9178fe72586a4cb4f5992bb7d4daafff29b05',
:Charlie => '6814fe1933406db2096ddbf80c3f76d9cdd146e4',
}
CONFLUENCE_HTTP = Net::HTTP.start(CONFLUENCE_URI.host, CONFLUENCE_URI.port, :use_ssl => CONFLUENCE_URI.scheme == 'https')
class Event2
attr_reader :summary
attr_reader :dtend
attr_reader :dtstart
attr_reader :attendee
def initialize(summary, dtstart, dtend, attendee)
@summary = summary
@dtend = dtend
@dtstart = dtstart
@attendee = attendee
end
end
def get_calendar(http, cal_id)
cal_root = 'rest/calendar-services/1.0/calendar/export/subcalendar/private'
request = Net::HTTP::Get.new("#{CONFLUENCE_URI.path}/#{cal_root}/#{cal_id}.ics")
response = http.request(request)
response.body
end
def event_hash(event, tz)
def get_time(t, tz)
if t.to_s.include?('UTC')
t.utc.strftime('%Y-%m-%dT%H:%M:%S%z')
else
t1 = use_time_zone(t, tz)
t1.utc.strftime('%Y-%m-%dT%H:%M:%S%z')
end
end
interval = event.dtend - event.dtstart
delta = interval < (60*60*24) ? 0 : Rational(1, 60*60*24)
attendees = event.attendee.collect { |att| att.ical_params['cn'] }.join(', ')
{
:summary => event.summary,
:start => get_time(event.dtstart + delta, tz),
:end => get_time(event.dtend - delta, tz),
:attendees => attendees,
:show => event.summary.include?(attendees) ? 'hidden' : ''
}
end
def with_time_zone(tz_name)
prev_tz = ENV['TZ']
ENV['TZ'] = tz_name
yield
ensure
ENV['TZ'] = prev_tz
end
def use_time_zone(t, tz)
with_time_zone(tz) {Time.new(t.year, t.month, t.mday, t.hour, t.min, t.sec)}
end
def update_calendar(http)
CALENDARS.each do |key, identifier|
ics = get_calendar(http, identifier)
calendars = Icalendar.parse(ics)
calendars.each do |calendar|
tz = calendar.x_wr_timezone[0].to_s
cal_data = calendar.events.
collect { |event|
event.rrule ?
event.occurrences_between(Date.today - 1, Date.today + 90).collect { |occurrence|
Event2.new(event.summary, occurrence.start_time, occurrence.end_time, event.attendee)
} :
[Event2.new(event.summary, event.dtstart, event.dtend, event.attendee)]
}.
flatten.
select { |event| event.is_a?(Date) ? event.dtend > Date.today - 1 : event.dtend > Time.now }.
collect { |event| event_hash(event, tz) }.
sort_by { |event| event[:start] }.
take(7)
send_event("#{key}-Calendar", {:data => cal_data})
end
end
end
SCHEDULER.every '5m', :first_in => 0 do |id|
update_calendar(CONFLUENCE_HTTP)
end
// light blue theme
$background-color: #47bbb3;
$days-color: #fff;
$board-color: rgba(255, 255, 255, 0.7);
$sprint-color: rgba(255, 255, 255, 0.7);
$updated-at-color: rgba(0, 0, 0, 0.3);
/*
// light grey theme
$background-color: #999;
$days-color: #fff;
$board-color: rgba(255, 255, 255, 0.7);
$sprint-color: rgba(255, 255, 255, 0.7);
$updated-at-color: rgba(0, 0, 0, 0.3);
*/
/*
// black theme
$background-color: #000;
$days-color: #fff;
$board-color: rgba(255, 255, 255, 0.7);
$sprint-color: rgba(255, 255, 255, 0.7);
$updated-at-color: rgba(255, 255, 255, 0.7);
*/
/*
// white theme
$background-color: #fff;
$days-color: rgba(0, 0, 0, 0.7);
$board-color: rgba(0, 0, 0, 0.3);
$sprint-color: rgba(0, 0, 0, 0.3);
$updated-at-color: rgba(0, 0, 0, 0.3);
*/
.widget-confluence-calendar {
background-color: $background-color;
td {
text-align: left;
}
.board {
color: $board-color;
}
.sprint-name {
color: $sprint-color;
}
.days-remaining {
color: $days-color;
}
.updated-at {
color:$updated-at-color;
}
.attendees {
color:$sprint-color;
font-size: 0.6em;
}
tr.hidden {
display: none;
}
}
@UdoK
Copy link

UdoK commented Oct 5, 2015

Probably this is the widget I'm looking for.
Can you please add some basic description where and what to change to make it adaptable.

Thanks,
Udo

@gempir
Copy link

gempir commented Jan 4, 2017

For something like a calendar a Screenshot of the widget would be nice :)

@surfnet-niels
Copy link

surfnet-niels commented Jul 26, 2017

This will not work without adding moment.js and twix.js to the layout.erb, just before application.js

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