File: ticgitweb

package info (click to toggle)
ticgit 1.0.2.18-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 488 kB
  • sloc: ruby: 2,848; sh: 124; makefile: 16
file content (317 lines) | stat: -rwxr-xr-x 7,225 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/usr/bin/env ruby

# starts a sinatra based web server that provides an interface to 
# your ticgit tickets
# 
# some of the sinatra code borrowed from sr's git-wiki
#
# author : Scott Chacon (schacon@gmail.com)
#

# Add the library from the source tree to the front of the load path.
# This allows ticgitweb to run without first installing a ticgit gem,
# which is important when testing multiple branches of development.
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')

%w(sinatra git ticgit-ng haml sass).each do |dependency|
  begin
    require dependency
  rescue LoadError => e
    puts "You need to install #{dependency} before we can proceed"
  end
end

#This line is required to resolve this issue
#https://github.com/jeffWelling/ticgit/issues/22
enable :run

# !! TODO : if ARGV[1] is a path to a git repo, use that
# otherwise, look in ~/.ticgit

$ticgit = TicGitNG.open('.')

get('/_stylesheet.css') { Sass::Engine.new(File.read(__FILE__).gsub(/.*__END__/m, '')).render }

# ticket list view
get '/' do
  @tickets = $ticgit.ticket_list(:order => 'date.desc')
  haml(list('all'))
end

get '/fs/:state' do
  @tickets = $ticgit.ticket_list(:state => params[:state], :order => 'date.desc')
  haml(list(params[:state]))
end

get '/tag/:tag' do
  @tickets = $ticgit.ticket_list(:tag => params[:tag], :order => 'date.desc')
  haml(list(params[:tag]))
end

get '/sv/:saved_view' do
  @tickets = $ticgit.ticket_list(:saved => params[:saved_view])
  haml(list(params[:saved_view]))
end

# ticket single view
get '/ticket/:ticket' do
  @ticket = $ticgit.ticket_show(params[:ticket])
  haml(show)
end


# add ticket
get '/t/new' do
  haml(new_ticket)
end

# add ticket finalize
post '/t/new' do
  title = params[:title].to_s.strip
  if title.size > 1
    tags = params[:tags].split(',').map { |t| t.strip } rescue nil  
    t = $ticgit.ticket_new(title, {:comment => params[:comment].strip, :tags => tags})
    redirect '/ticket/' + t.ticket_id.to_s
  else
    redirect '/t/new'
  end
end


# add comment
post '/a/add_comment/:ticket' do
  t = $ticgit.ticket_comment(params[:comment], params[:ticket])
  redirect '/ticket/' + params[:ticket]
end

# add tag
post '/a/add_tags/:ticket' do
  t = $ticgit.ticket_tag(params[:tags], params[:ticket])
  redirect '/ticket/' + params[:ticket]
end

# change ticket state
get '/a/change_state/:ticket/:state' do
  $ticgit.ticket_change(params[:state], params[:ticket])
  redirect '/ticket/' + params[:ticket]
end


def layout(title, content)
  @saved = $ticgit.config['list_options'].keys rescue []
  %Q(
%html
  %head
    %title #{title}
    %link{:rel => 'stylesheet', :href => '/_stylesheet.css', :type => 'text/css', :media => 'screen'}
    %meta{'http-equiv' => 'Content-Type', :content => 'text/html; charset=utf-8'}

  %body
    #navigation
      %a{:href => '/'} All
      %a{:href => '/fs/open'} Open
      %a{:href => '/fs/resolved'} Resolved
      %a{:href => '/fs/hold'} Hold
      %a{:href => '/fs/invalid'} Invalid
      - if !@saved.empty?
        | Saved:
        - @saved.each do |s|
          %a{:href => "/sv/\#{s}"}= s
    #action
      %a{:href => '/t/new'} New Ticket

    #{content}
  )
end

def new_ticket
  layout('New Ticket', %q{
    %h1 Create a New Ticket
    %form{:action => '/t/new', :method => 'POST'}
      %table
        %tr
          %th Title
          %td 
            %input{:type => 'text', :name => 'title', :size => 30}
        %tr
          %th Tags
          %td
            %input{:name => 'tags', :size => 30}
            %small (comma delimited)
        %tr
          %th Comment
          %td 
            %textarea{:name => 'comment', :rows => 15, :cols => 30}
        %tr
          %td
          %td
            %input{:type => 'submit', :value => 'Create Ticket'}
  })
end

def list(title = 'all')
  @title = title
  layout(title + ' tickets', %q{
    %h1= "#{@title} tickets"
    - if @tickets.empty?
      %p No tickets found.
    - else
      %table.long
        - c = 'even'
        - @tickets.each do |t|
          %tr{:class => (c == 'even' ? c = 'odd' : c = 'even') }
            %td
              %a{:href => "/ticket/#{t.ticket_id}" }
                %code= t.ticket_id[0,6]
            %td&= t.title
            %td{:class => t.state}= t.state
            %td= t.opened.strftime("%m/%d")
            %td= t.assigned_name
            %td
              - t.tags.each do |tag|
                %a{:href => "/tag/#{tag}"}= tag
  })
end

def show
  layout('ticket', %q{
  %center
    %h1&= @ticket.title
  
    %form{:action => "/a/add_tags/#{@ticket.ticket_id}", :method => 'POST'}
      %table
        %tr
          %th TicId
          %td
            %code= @ticket.ticket_id
        %tr
          %th Assigned
          %td= @ticket.assigned
        %tr
          %th Opened
          %td= @ticket.opened
        %tr
          %th State
          %td{:class => @ticket.state}
            %table{:width => '300'}
              %tr
                %td{:width=>'90%'}= @ticket.state
                - $ticgit.tic_states.select { |s| s != @ticket.state}.each do |st|
                  %td{:class => st}
                    %a{:href => "/a/change_state/#{@ticket.ticket_id}/#{st}"}= st[0,2]
        %tr
          %th Tags
          %td
            - @ticket.tags.each do |t|
              %a{:href => "/tag/#{t}"}= t
            %div.addtag
              %input{:name => 'tags'}
              %input{:type => 'submit', :value => 'add tag'}
    
    %h3 Comments
    %form{:action => "/a/add_comment/#{@ticket.ticket_id}", :method => 'POST'}
      %div
        %textarea{:name => 'comment', :cols => 50}
        %br
        %input{:type => 'submit', :value => 'add comment'}
        
    %div.comments
      - @ticket.comments.reverse.each do |t|
        %div.comment
          %span.head
            Added
            = t.added.strftime("%m/%d %H:%M")
            by
            = t.user
          %div.comment-text
            = t.comment
        %br
  })
end

__END__
body
  :font
    family: Verdana, Arial, "Bitstream Vera Sans", Helvetica, sans-serif
    color: black
  line-height: 160%
  background-color: white
  margin: 2em

#navigation
  a
    background-color: #e0e0e0
    color: black
    text-decoration: none
    padding: 2px
  padding: 5px
  border-bottom: 1px black solid
  
#action
  text-align: right
  
.addtag
  padding: 5px 0
  
h1
  display: block
  padding-bottom: 5px

a
  color: black
a.exists
  font-weight: bold
a.unknown
  font-style: italic

.comments
  margin: 10px 20px
  .comment
    .head
      background: #eee
      padding: 4px
    .comment-text
      padding: 10px
      color: #333
  
table.long
  width: 100%
  
table
  tr.even
    td
      background: #eee
  tr.odd
    td
      background: #fff
      
table
  tr
    th
      text-align: left
      padding: 3px
      vertical-align: top
    td.open
      background: #ada
    td.resolved
      background: #abd
    td.hold
      background: #dda
    td.invalid
      background: #aaa  
      
.submit
  font-size: large
  font-weight: bold

.page_title
  font-size: xx-large

.edit_link
  color: black
  font-size: 14px
  font-weight: bold
  background-color: #e0e0e0
  font-variant: small-caps
  text-decoration: none