pope / ticgit-watchtower

Provide a nicer looking web interface for ticgit

This URL has Read+Write access

ticgit-watchtower / watchtower.rb
09c3b63e » pope 2008-05-05 The playground for a better... 1 #!/usr/bin/env ruby
2
3 # starts a sinatra based web server that provides an interface to
4 # your ticgit tickets
5 #
11c8e874 » pope 2008-05-05 Removed my email address 6 # author : K. Adam Christensen
09c3b63e » pope 2008-05-05 The playground for a better... 7
361b4c33 » pope 2008-05-10 Comments are now shown usin... 8 %w(rubygems sinatra git ticgit haml gravatar set redcloth).each do |dependency|
09c3b63e » pope 2008-05-05 The playground for a better... 9 begin
10 require dependency
11 rescue LoadError => e
12 puts "You need to install #{dependency} before we can proceed"
13 end
14 end
15
b62f2333 » pope 2008-05-10 Now when using tiwatchtower... 16 unless ARGV[0]
17 $stderr.puts "You must specify a path to a git repository"
18 Process.exit
19 end
20
21 $ticgit = TicGit.open(ARGV[0].chomp)
22 $yui_version = '2.5.1'
23
09c3b63e » pope 2008-05-05 The playground for a better... 24 get('/screen.css') do
25 header 'Content-Type' => 'text/css; charset=utf-8'
26 sass :screen
27 end
28
29 before do
d1eaa4fb » pope 2008-05-05 Flushed out some of the lay... 30 @saved = $ticgit.config['list_options'].keys rescue []
09c3b63e » pope 2008-05-05 The playground for a better... 31 end
32
33 get('/') do
63c66953 » pope 2008-05-05 Put in some skeleton code f... 34 @title = "All Tickets"
35 @tickets = $ticgit.ticket_list(:order => 'date.desc')
839da80d » pope 2008-05-07 Renamed index.haml to list.... 36 haml :list
09c3b63e » pope 2008-05-05 The playground for a better... 37 end
8bb73a8f » pope 2008-05-07 Added the route for /ticket... 38
39 get('/tickets/state/:state') do
40 @title = "#{params[:state].capitalize} Tickets"
41 @tickets = $ticgit.ticket_list(:state => params[:state], :order => 'date.desc')
839da80d » pope 2008-05-07 Renamed index.haml to list.... 42 haml :list
8bb73a8f » pope 2008-05-07 Added the route for /ticket... 43 end
f9989014 » pope 2008-05-07 Built out the tags some. 44
45 get('/tickets/tags/:tag') do
46 @title = "#{params[:tag].capitalize} Tickets"
47 @tickets = $ticgit.ticket_list(:tag => params[:tag], :order => 'date.desc')
48 haml :list
49 end
d254262a » pope 2008-05-07 Started on the ticket detai... 50
0dfb8279 » pope 2008-05-10 Added the saved views route... 51 get('/tickets/saved_views/:view') do
52 @tickets = $ticgit.ticket_list(:saved => params[:saved_view])
53 @title = "#{params[:view].capitalize} View"
54 haml :list
55 end
56
b671efcb » pope 2008-05-07 Added the ability to create... 57 get('/tickets/new') do
58 @title = 'New Ticket'
59 haml :new
60 end
61
62 post('/tickets') do
63 title = params[:ticket_title].to_s.strip
64 if title.size > 1
b50b6ce1 » pope 2008-05-07 On the ticket details page,... 65 tags = params[:ticket_tags].split(',').map { |t| t.strip } rescue nil
b671efcb » pope 2008-05-07 Added the ability to create... 66 comment = params[:ticket_comment].strip rescue nil
67 comment = nil if comment.empty?
68 t = $ticgit.ticket_new(title, {:comment => comment, :tags => tags})
69 redirect '/tickets/' + t.ticket_id.to_s
70 else
71 redirect '/tickets/new'
72 end
73 end
74
b50b6ce1 » pope 2008-05-07 On the ticket details page,... 75 get('/tickets/:id') do
76 @ticket = $ticgit.ticket_show(params[:id])
d254262a » pope 2008-05-07 Started on the ticket detai... 77 @title = @ticket.title
78 haml :show
79 end
b50b6ce1 » pope 2008-05-07 On the ticket details page,... 80
81 put('/tickets/:id') do
82
83 @ticket = $ticgit.ticket_show(params[:id])
84
85 comment = params[:ticket_comment].strip rescue ""
86 unless comment.empty?
87 $ticgit.ticket_comment(comment, params[:id])
88 end
89
3b1cf66b » pope 2008-05-10 Added the ability to change... 90 $ticgit.ticket_assign(params[:ticket_assigned], params[:id])
b50b6ce1 » pope 2008-05-07 On the ticket details page,... 91
92 original_tags = @ticket.tags.to_set
93 updated_tags = params[:ticket_tags].split(',').map { |t| t.strip }.to_set rescue Set.new
94
95 tags_to_remove = (original_tags - updated_tags).to_a.join(',')
96 $ticgit.ticket_tag(tags_to_remove, params[:id], :remove => true)
97
98 tags_to_add = (updated_tags - original_tags).to_a.join(',')
99 $ticgit.ticket_tag(tags_to_add, params[:id])
100
3b1cf66b » pope 2008-05-10 Added the ability to change... 101 $ticgit.ticket_change(params[:ticket_state], params[:id])
102
b50b6ce1 » pope 2008-05-07 On the ticket details page,... 103 redirect "/tickets/#{@ticket.ticket_id}"
104 end