Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of git://github.com/mattallen/unfuddle-helpdesk…

… into mattallen/master

Conflicts:
	app.rb
  • Loading branch information...
commit 9b7b9c3b896bf07095d204477af48459709a907e 2 parents ee3ee63 + fda7759
@timriley authored
View
9 app.rb
@@ -23,6 +23,10 @@
use Rack::Flash
+CONFIG = {'memcached' => 'localhost:11211'}
+
+require 'lib/cache'
+
configure do
require File.join(File.dirname(__FILE__), 'app_config')
enable :sessions
@@ -126,3 +130,8 @@ def out_of_bounds?(t)
flash[:notice] = Comment.create(params[:comment]).created? ? 'comment_success' : 'comment_error'
redirect "/tickets/#{params[:id]}"
end
+
+get '/dashboard' do
+ @ticket_report = TicketReport.find(Sinatra::Application.unfuddle_ticket_report_id)
+ haml :dashboard
+end
View
50 lib/cache.rb
@@ -0,0 +1,50 @@
+require 'memcache'
+require 'digest/md5'
+
+module Sinatra
+ class Cache
+ def self.cache(key, &block)
+ unless CONFIG['memcached']
+ raise "Configure CONFIG['memcached'] to be a string like 'localhost:11211' "
+ end
+ begin
+ key = Digest::MD5.hexdigest(key)
+ @@connection ||= MemCache.new(CONFIG['memcached'], :namespace => 'Sinatra/')
+ result = @@connection.get(key)
+ return result if result
+ result = yield
+ @@connection.set(key, result)
+ result
+ rescue
+ yield
+ end
+ end
+ end
+end
+
+module CacheableEvent
+ def self.included(base)
+ base.send :include, CacheableEvent::InstanceMethods
+ base.class_eval do
+ alias_method :_invoke_without_caching, :invoke unless method_defined?(:_invoke_without_caching)
+ alias_method :invoke, :_invoke_with_caching
+ end
+ end
+
+ module InstanceMethods
+ def _invoke_with_caching(*args)
+ if options[:cache_key]
+ # replace the block with another block that can be cached
+ def wrap_block(key,block)
+ Proc.new do
+ Sinatra::Cache.cache(key + "/" + params.to_a.join("/")) { instance_eval(&block) }
+ end
+ end
+ @block = wrap_block(options[:cache_key], block)
+ end
+ _invoke_without_caching(*args)
+ end
+ end
+
+end
+
View
4 lib/ticket.rb
@@ -80,6 +80,10 @@ def summary
@attributes.summary.match(self.class.delimiter) ? @attributes.summary.split(self.class.delimiter).last : @attributes.summary
end
+ def get(attribute)
+ @attributes.send(attribute)
+ end
+
private
def self.prepare_attributes(attrs)
View
7 lib/ticket_group.rb
@@ -17,4 +17,11 @@ def unassigned_tickets
def assigned_tickets
@assigned_tickets ||= @tickets.select { |t| !t.assignee_id.nil? }
end
+
+ def tickets_by_status(status)
+ @tickets.select { |t| t.get(:status) == status }
+ end
+ def tickets_not_by_status(status)
+ @tickets.select { |t| t.get(:status) != status }
+ end
end
View
5 lib/ticket_report.rb
@@ -1,6 +1,9 @@
class TicketReport < UnfuddleRecord
def self.find(id)
- new(get("https://#{Sinatra::Application.unfuddle_subdomain}.unfuddle.com/api/v1/projects/#{Sinatra::Application.unfuddle_project_id}/ticket_reports/#{id}/generate")['ticket_report'])
+ hsh = Sinatra::Cache.cache("ticked_report_#{id}") do
+ get("https://#{Sinatra::Application.unfuddle_subdomain}.unfuddle.com/api/v1/projects/#{Sinatra::Application.unfuddle_project_id}/ticket_reports/#{id}/generate")['ticket_report']
+ end
+ new(hsh)
end
attr_accessor :ticket_groups
View
38 views/dashboard.haml
@@ -0,0 +1,38 @@
+- @title = 'Dashboard'
+
+#tickets
+ %h1
+ Helpdesk Dashboard
+ #buttons
+ %ul
+ %li
+ %a{:href => '/tickets/new'} <span>New Ticket</span>
+
+ - @ticket_report.ticket_groups.each do |group|
+
+ .component
+ %h3
+ Reports
+ %table.tickets{:cellpadding => 0, :cellspacing => 0}
+ %thead
+ %tr
+ %th Type
+ %th Count
+ %tbody
+ %tr
+ %td
+ Total
+ %td
+ = group.tickets.size
+ %tr
+ %td
+ Open
+ %td
+ = group.tickets_not_by_status("closed").size
+ = (group.tickets_not_by_status("closed").size.to_f / group.tickets.size.to_f * 100.0).to_i.to_s + "%"
+ %tr
+ %td
+ Closed
+ %td
+ = group.tickets_by_status("closed").size
+ = (group.tickets_by_status("closed").size.to_f / group.tickets.size.to_f * 100.0).to_i.to_s + "%"
Please sign in to comment.
Something went wrong with that request. Please try again.