Skip to content

Instantly share code, notes, and snippets.

@jmibanez
Last active April 10, 2019 18:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jmibanez/ccfa6add0f4c359a9978 to your computer and use it in GitHub Desktop.
Save jmibanez/ccfa6add0f4c359a9978 to your computer and use it in GitHub Desktop.

Redmine Ticket Counts

This widget (and job) pulls ticket counts per priority from Redmine for a list of projects

Installation

Add faraday to your Gemfile:

gem 'faraday'

Usage

To use this widget, copy redmine_ticket_counts.html, redmine_ticket_counts.coffee, and redmine_ticket_counts.scss into the /widgets/redmine_ticket_counts folder.

Edit redmine.rb, replacing REDMINE_URL with the URL of your Redmine instance and REDMINE_KEY with your Redmine API key (See below for info on the Redmine API key). Change the projects hash to reflect your setup, associating a widget ID with a particular project ID in Redmine.

Once you've edited redmine.rb, put your edited version in the /jobs folder of you Dashing instance.

To include the widget in a dashboard, add a snippet such as:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="redmine-counts-foo" data-view="RedmineTicketCounts" data-title="Foo Tickets"></div>
</li>

to your dashboard layout file.

Configuring Redmine

You will need to have admin access to Redmine.

Ensure that you have enabled REST API access on your Redmine instance. To check, go to Administration -> Settings, click on the Authentication tab, and check that Enable REST web service is checked.

Go to My account, and look at the right side of the page, where you can find your API key; place this value in REDMINE_KEY in redmine.rb.

require 'open-uri'
require 'json'
require 'faraday'
projects = {
"redmine-counts-foo" => "foo-project",
}
REDMINE_URL = "http://redmine.com"
REDMINE_KEY = "YOUR_API_KEY_HERE"
REDMINE_PRIORITIES = { 3 => "low", 4 => "normal", 5 => "high",
6 => "urgent", 7 => "immediate" }
class RedmineTicketCounts
def initialize(widget_id, project_id)
@widget_id = widget_id
@project_id = project_id
end
def widget_id()
@widget_id
end
def latest_ticket_counts()
conn = Faraday.new(:url => REDMINE_URL)
counts = {}
REDMINE_PRIORITIES.each do |prio_id, prio|
response = conn.get '/issues.json',
{ :project_id => @project_id,
:priority_id => prio_id,
:limit => 1,
:key => REDMINE_KEY }
issue_list = JSON[response.body]
counts[prio] = issue_list['total_count']
end
counts
end
end
@RedmineTicketCounts = []
projects.each do |widget_id, project_id|
begin
@RedmineTicketCounts.push(RedmineTicketCounts.new(widget_id, project_id))
rescue Exception => e
puts e.to_s
end
end
SCHEDULER.every '10m', :first_in => 0 do |job|
@RedmineTicketCounts.each do |redmine_project|
ticket_counts = redmine_project.latest_ticket_counts
send_event(redmine_project.widget_id, ticket_counts)
end
end
class Dashing.RedmineTicketCounts extends Dashing.Widget
ready: ->
@keyList = [ 'immediate', 'urgent', 'high', 'normal' ]
@currentIndex = 0
@valueContainer = $(@node).find('.value')
@nextCount()
@startCarousel()
onData: (data) ->
@currentIndex = 0
startCarousel: ->
interval = $(@node).attr('data-interval')
interval = "15" if not interval
setInterval(@nextCount, parseInt( interval ) * 1000)
nextCount: =>
@valueContainer.fadeOut =>
@currentIndex = (@currentIndex + 1) % @keyList.length
valueKey = @keyList[@currentIndex]
@set 'current', @get(valueKey)
@set 'priority', valueKey
@valueContainer.fadeIn()
<h1 class="title" data-bind="title"></h1>
<h2 class="value" data-bind="current | shortenedNumber | prepend prefix | append suffix"></h2>
<h3 class="value_label" data-bind="priority"></h3>
<p class="more-info" data-bind="moreinfo"></p>
<p class="updated-at" data-bind="updatedAtMessage"></p>
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #47bbb3;
$value-color: #fff;
$title-color: rgba(255, 255, 255, 0.7);
$moreinfo-color: rgba(255, 255, 255, 0.7);
// ----------------------------------------------------------------------------
// Widget-redmine-ticket-counts styles
// ----------------------------------------------------------------------------
.widget-redmine-ticket-counts {
background-color: $background-color;
.title {
color: $title-color;
}
.value {
color: $value-color;
}
.more-info {
color: $moreinfo-color;
}
.updated-at {
color: rgba(0, 0, 0, 0.3);
}
}
@Otisoupo
Copy link

Works great - thank you. Is it possible to integrate ticket status - we are only interested to see the new tickets, that there is no action , eg "status":{"id":1,"name":"New"} ?

Thank you in advance.

Regards

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