| 1 | use warnings; | ||
| 2 | use strict; | ||
| 3 | |||
| 4 | package App::SD::Server::View; | ||
| 5 | use base 'Prophet::Server::View'; | ||
| 6 | use URI::file; | ||
| 7 | use Template::Declare::Tags; | ||
| 8 | use Prophet::Server::ViewHelpers; | ||
| 9 | |||
| 10 | use App::SD::Model::Ticket; | ||
| 11 | use App::SD::Model::Comment; | ||
| 12 | use App::SD::Collection::Ticket; | ||
| 13 | |||
| 14 | |||
| 15 | my @BASIC_PROPS = qw(status milestone component owner reporter due created tags description); | ||
| 16 | |||
| 17 | sub page_box { | ||
| 18 | my ($id, $title, $component) = (@_); | ||
| 19 | |||
| 20 | div { { id is $id }; | ||
| 21 | { h2 { $title}; show($component)} | ||
| 22 | }; | ||
| 23 | |||
| 24 | } | ||
| 25 | |||
| 26 | template '' => page { 'Project overview'} content { | ||
| 27 | my $self = shift; | ||
| 28 | div { { class is 'stats sidebar'}; | ||
| 29 | page_box('components', 'Components', 'component_list'); | ||
| 30 | page_box('statuses', 'Statuses', 'status_list'); | ||
| 31 | page_box('milestones', 'Milestones', 'milestone_list'); | ||
| 32 | }; | ||
| 33 | div { { class is 'overview'}; | ||
| 34 | h2 { 'Your active tickets for '. $self->app_handle->setting( label => 'default_milestone' )->get()->[0];}; | ||
| 35 | show('/tickets/hot'); | ||
| 36 | }; | ||
| 37 | }; | ||
| 38 | |||
| 39 | template 'hot_tickets' => page {'Your open tickets for the current milestone'} | ||
| 40 | content { | ||
| 41 | show('/tickets/hot'); | ||
| 42 | |||
| 43 | }; | ||
| 44 | |||
| 45 | template 'all_tickets' => page {'All tickets'} content { | ||
| 46 | shift->show_tickets( sub {1}); | ||
| 47 | }; | ||
| 48 | |||
| 49 | template 'milestones' => page {'Project milestones'} content { | ||
| 50 | show 'milestone_list'; | ||
| 51 | }; | ||
| 52 | |||
| 53 | |||
| 54 | template 'status_list' => sub { show('property_list','status'); }; | ||
| 55 | template 'milestone_list' => sub { show('property_list', 'milestone') }; | ||
| 56 | template 'component_list' => sub { show('property_list', 'component')}; | ||
| 57 | |||
| 58 | template 'property_list' => sub { | ||
| 59 | my $self = shift; | ||
| 60 | my $property_name = shift; | ||
| 61 | my $props = $self->app_handle->setting( | ||
| 62 | label => ( $property_name =~ /s$/ ? $property_name . "es" : $property_name . 's' ) )->get(); | ||
| 63 | |||
| 64 | my %counts = map { $_ => 0 } @$props; | ||
| 65 | $self->find_tickets( sub { | ||
| 66 | my $ticket = shift; | ||
| 67 | return if ($property_name ne 'status' && !$ticket->has_active_status); | ||
| 68 | $counts{ $ticket->prop($property_name) || '' }++}); | ||
| 69 | |||
| 70 | my $total = 0; | ||
| 71 | $total += $_ for values %counts; | ||
| 72 | |||
| 73 | div { | ||
| 74 | { class is 'pagesection' }; | ||
| 75 | ul { | ||
| 76 | |||
| 77 | my @order = grep {$_ ne ''} keys %counts; | ||
| 78 | |||
| 79 | if ( defined $counts{''} && $counts{''} > 0) { | ||
| 80 | push @order, ''; | ||
| 81 | } | ||
| 82 | |||
| 83 | |||
| 84 | foreach my $prop ( @order) { | ||
| 85 | li { | ||
| 86 | div { {class is 'bar-wrapper'} ; | ||
| 87 | div { | ||
| 88 | { class is 'bar'; ($total ? style is ("width: ". int(( ($counts{$prop} ||0)/ $total) * 100 )."%") : ()) }; | ||
| 89 | outs(' '); | ||
| 90 | };}; | ||
| 91 | outs ( ($counts{$prop} ||'0') . " - "); | ||
| 92 | a { | ||
| 93 | { href is $self->server->make_link_relative( '/' . $property_name . '/' . ($prop ||'')) } | ||
| 94 | ( $prop ? $prop : 'None' ) | ||
| 95 | } | ||
| 96 | |||
| 97 | } | ||
| 98 | |||
| 99 | } | ||
| 100 | } | ||
| 101 | } | ||
| 102 | |||
| 103 | }; | ||
| 104 | |||
| 105 | |||
| 106 | |||
| 107 | |||
| 108 | template 'status' => page { 'Status: ' . ( $_[1] || 'none' ) } | ||
| 109 | content { | ||
| 110 | my $self = shift; | ||
| 111 | my $status = shift || '' ; | ||
| 112 | |||
| 113 | $self->show_tickets( | ||
| 114 | sub {my $item = shift; | ||
| 115 | ( ( $item->prop('status') || '' ) eq $status ) | ||
| 116 | ? 1 | ||
| 117 | : 0; | ||
| 118 | } | ||
| 119 | ); | ||
| 120 | }; | ||
| 121 | |||
| 122 | |||
| 123 | |||
| 124 | template 'component' => page { 'Component: ' . ( $_[1] || 'none' ) } | ||
| 125 | content { | ||
| 126 | my $self = shift; | ||
| 127 | my $component = shift || '' ; | ||
| 128 | |||
| 129 | |||
| 130 | |||
| 131 | $self->show_tickets( | ||
| 132 | sub {my $item = shift; | ||
| 133 | ( ( $item->prop('component') || '' ) eq $component && $item->has_active_status ) | ||
| 134 | ? 1 | ||
| 135 | : 0; | ||
| 136 | } | ||
| 137 | ); | ||
| 138 | }; | ||
| 139 | |||
| 140 | template 'milestone' => page { 'Milestone: ' . ( $_[1] || 'none' ) } | ||
| 141 | content { | ||
| 142 | my $self = shift; | ||
| 143 | my $milestone = shift; | ||
| 144 | |||
| 145 | $self->show_tickets( | ||
| 146 | sub {my $item = shift; | ||
| 147 | ( ( $item->prop('milestone') || '' ) eq ($milestone || '') && $item->has_active_status ) | ||
| 148 | ? 1 | ||
| 149 | : 0; | ||
| 150 | } | ||
| 151 | ); | ||
| 152 | |||
| 153 | }; | ||
| 154 | |||
| 155 | sub show_tickets { | ||
| 156 | my $self = shift; | ||
| 157 | my $tickets = $self->find_tickets(@_); | ||
| 158 | show( '/ticket_list', $tickets ); | ||
| 159 | } | ||
| 160 | |||
| 161 | sub find_tickets { | ||
| 162 | my $self = shift; | ||
| 163 | my $callback = shift; | ||
| 164 | |||
| 165 | my $tickets = App::SD::Collection::Ticket->new( | ||
| 166 | app_handle => $self->app_handle, | ||
| 167 | handle => $self->app_handle->handle | ||
| 168 | ); | ||
| 169 | $tickets->matching($callback); | ||
| 170 | return $tickets; | ||
| 171 | } | ||
| 172 | |||
| 173 | template edit_ticket => page { | ||
| 174 | |||
| 175 | my $self = shift; | ||
| 176 | my $id = shift; | ||
| 177 | my $ticket = App::SD::Model::Ticket->new( | ||
| 178 | app_handle => $self->app_handle, | ||
| 179 | handle => $self->app_handle->handle | ||
| 180 | ); | ||
| 181 | $ticket->load(($id =~ /^\d+$/ ? 'luid' : 'uuid') =>$id); | ||
| 182 | |||
| 183 | $ticket->luid.": ".$ticket->prop('summary'); | ||
| 184 | |||
| 185 | |||
| 186 | |||
| 187 | } content { | ||
| 188 | my $self = shift; | ||
| 189 | my $id = shift; | ||
| 190 | my $ticket = App::SD::Model::Ticket->new( | ||
| 191 | app_handle => $self->app_handle, | ||
| 192 | handle => $self->app_handle->handle | ||
| 193 | ); | ||
| 194 | $ticket->load(($id =~ /^\d+$/ ? 'luid' : 'uuid') =>$id); | ||
| 195 | |||
| 196 | |||
| 197 | |||
| 198 | $self->ticket_page_actions($ticket); | ||
| 199 | |||
| 200 | form { | ||
| 201 | |||
| 202 | my $f = function( | ||
| 203 | record => $ticket, | ||
| 204 | action => 'update', | ||
| 205 | order => 1, | ||
| 206 | name => 'edit-ticket' | ||
| 207 | ); | ||
| 208 | |||
| 209 | div { { class is 'ticket-props'}; | ||
| 210 | for my $prop ('summary') { | ||
| 211 | div { { class is "widget $prop"}; | ||
| 212 | widget( function => $f, prop => $prop, autocomplete => 0 ) }; | ||
| 213 | } | ||
| 214 | |||
| 215 | for my $prop (qw(status component milestone)){ | ||
| 216 | div { { class is "widget $prop"}; | ||
| 217 | widget( function => $f, prop => $prop ) }; | ||
| 218 | } | ||
| 219 | |||
| 220 | div { class is 'other-props'; | ||
| 221 | for my $prop (@BASIC_PROPS) { | ||
| 222 | next if $prop =~ /^(?:status|component|milestone|created|description)$/; | ||
| 223 | |||
| 224 | div { { class is "widget $prop"}; | ||
| 225 | widget( function => $f, prop => $prop ) }; | ||
| 226 | } | ||
| 227 | }; | ||
| 228 | |||
| 229 | div { { class is "widget description"}; | ||
| 230 | widget( function => $f, prop => 'description', type => 'textarea', autocomplete => 0) }; | ||
| 231 | |||
| 232 | }; | ||
| 233 | div { class is 'submit'; | ||
| 234 | input { attr { value => 'Save', type => 'submit' } }; | ||
| 235 | }; | ||
| 236 | |||
| 237 | div { class is 'comment-form'; | ||
| 238 | h2 { 'Add a comment' }; | ||
| 239 | |||
| 240 | my $c = function( | ||
| 241 | record => App::SD::Model::Comment->new( | ||
| 242 | app_handle => $self->app_handle ), | ||
| 243 | action => 'create', | ||
| 244 | order => 2, | ||
| 245 | name => 'update-ticket-comment' | ||
| 246 | ); | ||
| 247 | |||
| 248 | hidden_param( function => $c, | ||
| 249 | prop => 'ticket', | ||
| 250 | value => $ticket->uuid); | ||
| 251 | for my $prop (qw(content)) { | ||
| 252 | div { widget( function => $c, prop => $prop, | ||
| 253 | type => 'textarea', autocomplete => 0)}; | ||
| 254 | } | ||
| 255 | |||
| 256 | }; | ||
| 257 | div { class is 'submit'; | ||
| 258 | input { attr { value => 'Save', type => 'submit' } }; | ||
| 259 | }; | ||
| 260 | }; | ||
| 261 | }; | ||
| 262 | |||
| 263 | |||
| 264 | |||
| 265 | template new_ticket => page {'Create a new ticket'} content { | ||
| 266 | my $self = shift; | ||
| 267 | |||
| 268 | form { { class is 'create-ticket'}; | ||
| 269 | |||
| 270 | my $f = function( | ||
| 271 | record => | ||
| 272 | App::SD::Model::Ticket->new( app_handle => $self->app_handle ), | ||
| 273 | action => 'create', | ||
| 274 | order => 1, | ||
| 275 | name => 'create-ticket' | ||
| 276 | ); | ||
| 277 | div { class is 'ticket-props'; | ||
| 278 | for my $prop ('summary') { | ||
| 279 | div { | ||
| 280 | { class is "widget $prop" }; | ||
| 281 | widget( function => $f, prop => $prop, autocomplete => 0 ); | ||
| 282 | }; | ||
| 283 | } | ||
| 284 | |||
| 285 | for my $prop (qw(status component milestone)){ | ||
| 286 | div { {class is 'widget '.$prop}; | ||
| 287 | widget( function => $f, prop => $prop ) }; | ||
| 288 | |||
| 289 | } | ||
| 290 | |||
| 291 | div { class is 'other-props'; | ||
| 292 | |||
| 293 | for my $prop (@BASIC_PROPS) { | ||
| 294 | next if $prop =~ /^(?:status|component|milestone|created|description)$/; | ||
| 295 | div { {class is 'widget '.$prop}; | ||
| 296 | widget( function => $f, prop => $prop ) }; | ||
| 297 | } | ||
| 298 | |||
| 299 | div { {class is 'widget description'}; | ||
| 300 | widget( function => $f, prop => 'description', type => 'textarea', autocomplete => '0' ) }; | ||
| 301 | |||
| 302 | } | ||
| 303 | }; | ||
| 304 | |||
| 305 | div { class is 'submit'; | ||
| 306 | input { attr { value => 'Save', type => 'submit' } }; | ||
| 307 | }; | ||
| 308 | |||
| 309 | |||
| 310 | div { class is 'comment-form'; | ||
| 311 | h2 { 'Initial comments on this ticket' }; | ||
| 312 | |||
| 313 | my $c = function( | ||
| 314 | record => App::SD::Model::Comment->new( | ||
| 315 | app_handle => $self->app_handle ), | ||
| 316 | action => 'create', | ||
| 317 | order => 2, | ||
| 318 | name => 'create-ticket-comment' | ||
| 319 | ); | ||
| 320 | |||
| 321 | param_from_function( | ||
| 322 | function => $c, | ||
| 323 | prop => 'ticket', | ||
| 324 | from_function => $f, | ||
| 325 | from_result => 'record_uuid' | ||
| 326 | ); | ||
| 327 | for my $prop (qw(content)) { | ||
| 328 | |||
| 329 | div { widget( function => $c, prop => $prop, type => 'textarea', autocomplete => 0)}; | ||
| 330 | } | ||
| 331 | |||
| 332 | div { class is 'submit'; | ||
| 333 | input { attr { value => 'Save', type => 'submit' } }; | ||
| 334 | } | ||
| 335 | } | ||
| 336 | }; | ||
| 337 | }; | ||
| 338 | |||
| 339 | template footer => sub { | ||
| 340 | |||
| 341 | div { id is 'project-versions'; | ||
| 342 | outs("SD $App::SD::VERSION - Issue tracking for the distributed age - ". | ||
| 343 | " Prophet $Prophet::VERSION"); | ||
| 344 | |||
| 345 | } | ||
| 346 | }; | ||
| 347 | |||
| 348 | template header => sub { | ||
| 349 | my $self = shift; | ||
| 350 | my $title = shift; | ||
| 351 | outs_raw($self->page_nav->render_as_menubar) if ($self->page_nav); | ||
| 352 | div{ class is 'logowrapper'; | ||
| 353 | img { src is '/static/sd/images/sd.png'; | ||
| 354 | alt is 'SD Logo', | ||
| 355 | class is 'logo' | ||
| 356 | }; | ||
| 357 | }; | ||
| 358 | div { class is 'project-name'; | ||
| 359 | " for ".$self->app_handle->setting( label => 'project_name' )->get()->[0]}; | ||
| 360 | h1 { $title }; | ||
| 361 | }; | ||
| 362 | |||
| 363 | template '/tickets/hot' => sub { | ||
| 364 | my $self = shift; | ||
| 365 | |||
| 366 | my $current_milestone = $self->app_handle->setting( label => 'default_milestone' )->get()->[0]; | ||
| 367 | |||
| 368 | $self->show_tickets( | ||
| 369 | sub { | ||
| 370 | my $item = shift; | ||
| 371 | if ( $item->has_active_status | ||
| 372 | && ( $item->prop('milestone') || '' ) eq $current_milestone | ||
| 373 | && ( ( $item->prop('owner') || '' ) eq | ||
| 374 | ( $item->app_handle->config->get( | ||
| 375 | key => 'user.email-address' | ||
| 376 | ) || '') || !$item->prop('owner') ) | ||
| 377 | ) | ||
| 378 | { | ||
| 379 | return 1; | ||
| 380 | } else { | ||
| 381 | return undef; | ||
| 382 | } | ||
| 383 | } | ||
| 384 | ); | ||
| 385 | |||
| 386 | }; | ||
| 387 | |||
| 388 | template '/tickets/open' => sub { | ||
| 389 | my $self = shift; | ||
| 390 | $self->show_tickets (sub { my $item = shift; return $item->has_active_status ? 1 : 0; }); | ||
| 391 | |||
| 392 | }; | ||
| 393 | |||
| 394 | private template 'ticket_list' => sub { | ||
| 395 | my $self = shift; | ||
| 396 | my $tickets = shift; | ||
| 397 | my $id = substr(rand(10),2); # hack to get a unique id | ||
| 398 | div { { class is 'ticket-list'}; | ||
| 399 | table { | ||
| 400 | { class is 'tablesorter'; id is $id; }; | ||
| 401 | thead { | ||
| 402 | row { | ||
| 403 | th { 'id'}; | ||
| 404 | th {'Status'}; | ||
| 405 | th {'Milestone'}; | ||
| 406 | th {'Component'}; | ||
| 407 | th {'Owner'}; | ||
| 408 | th {'Reporter'}; | ||
| 409 | th {'Due'}; | ||
| 410 | th {'Created'}; | ||
| 411 | } | ||
| 412 | }; | ||
| 413 | tbody { | ||
| 414 | for my $ticket (@$tickets) { | ||
| 415 | row { | ||
| 416 | cell { class is 'id'; $self->ticket_link( $ticket => $ticket->luid ); }; | ||
| 417 | for (qw|status milestone component owner reporter due created|) { | ||
| 418 | |||
| 419 | cell { class is $_; $ticket->prop($_) }; | ||
| 420 | } | ||
| 421 | cell { class is 'summary'; $self->ticket_link( $ticket => $ticket->prop('summary') ); }; | ||
| 422 | } | ||
| 423 | |||
| 424 | } | ||
| 425 | }; | ||
| 426 | }}; | ||
| 427 | script {outs_raw(qq{ | ||
| 428 | \$(document).ready(function() { \$("#@{[$id]}").tablesorter(); } ); | ||
| 429 | } | ||
| 430 | |||
| 431 | ); | ||
| 432 | |||
| 433 | outs_raw('$("td.created,td.due").prettyDateTag(); | ||
| 434 | setInterval(function(){ $("td.created,td.due").prettyDateTag(); }, 5000);') | ||
| 435 | }; | ||
| 436 | |||
| 437 | |||
| 438 | }; | ||
| 439 | |||
| 440 | template 'history' => page { | ||
| 441 | my $self = shift; | ||
| 442 | 'History'; | ||
| 443 | } | ||
| 444 | content { | ||
| 445 | my $self = shift; | ||
| 446 | my $latest = $self->app_handle->handle->latest_sequence_no; | ||
| 447 | my $start = shift || $latest; | ||
| 448 | my $end = $start - 20; | ||
| 449 | |||
| 450 | $end = 1 if $end < 1; | ||
| 451 | |||
| 452 | my @changesets; | ||
| 453 | $self->app_handle->handle->traverse_changesets( | ||
| 454 | reverse => 1, | ||
| 455 | after => $end, | ||
| 456 | until => $start, | ||
| 457 | callback => sub { | ||
| 458 | my %args = (@_); | ||
| 459 | push @changesets, $args{changeset}; | ||
| 460 | } | ||
| 461 | ); | ||
| 462 | |||
| 463 | div { { class is 'log'}; | ||
| 464 | my $nav = sub { | ||
| 465 | div {{ class is 'nav'}; | ||
| 466 | if ($end > 1 ) { | ||
| 467 | a {{ class is 'prev', href is $self->server->make_link_relative('/history/'.($end-1)) }; 'Earlier' }; | ||
| 468 | } | ||
| 469 | if ($start < $latest) { | ||
| 470 | a {{ class is 'next', href is $self->server->make_link_relative ( '/history/'.(( $start+21 < $latest) ? ($start+21) : $latest)) }; 'Later' }; | ||
| 471 | } | ||
| 472 | } | ||
| 473 | }; | ||
| 474 | |||
| 475 | $nav->(); | ||
| 476 | |||
| 477 | show( | ||
| 478 | 'format_history', | ||
| 479 | changesets => \@changesets, | ||
| 480 | change_filter => sub {1}, | ||
| 481 | sort_changesets => sub { sort {$b->sequence_no <=> $a->sequence_no} @_ }, | ||
| 482 | change_header => sub { | ||
| 483 | my $change = shift; | ||
| 484 | if ( $change->record_type eq 'ticket' ) { | ||
| 485 | my $ticket = App::SD::Model::Ticket->new( | ||
| 486 | app_handle => $self->app_handle, | ||
| 487 | handle => $self->app_handle->handle | ||
| 488 | ); | ||
| 489 | $ticket->load( uuid => $change->record_uuid ); | ||
| 490 | |||
| 491 | h2 { | ||
| 492 | a { | ||
| 493 | { href is $self->server->make_link_relative( '/ticket/' . $ticket->uuid ); | ||
| 494 | class is 'ticket-summary'; | ||
| 495 | }; | ||
| 496 | $ticket->prop('summary'); | ||
| 497 | }; | ||
| 498 | span { | ||
| 499 | { class is 'ticket-id' }; | ||
| 500 | ' (' . ( $ticket->luid || '' ) . ')'; | ||
| 501 | }; | ||
| 502 | } | ||
| 503 | } elsif ($change->record_type eq 'comment') { | ||
| 504 | my $ticket = App::SD::Model::Ticket->new( | ||
| 505 | app_handle => $self->app_handle, | ||
| 506 | handle => $self->app_handle->handle | ||
| 507 | ); | ||
| 508 | |||
| 509 | my $id; | ||
| 510 | for ( $change->prop_changes ) { | ||
| 511 | if ( $_->name eq 'ticket' ) { $id = $_->new_value } | ||
| 512 | |||
| 513 | } | ||
| 514 | |||
| 515 | return unless ($id); | ||
| 516 | $ticket->load( uuid => $id ) ; | ||
| 517 | |||
| 518 | h2 { | ||
| 519 | outs('Comment on: '); | ||
| 520 | a {{ href is $self->server->make_link_relative('/ticket/' . $ticket->uuid); class is 'ticket-summary' }; $ticket->prop('summary') }; | ||
| 521 | span { { class is 'ticket-id'}; ' (' . ($ticket->luid ||''). ')'}; | ||
| 522 | } | ||
| 523 | |||
| 524 | |||
| 525 | } | ||
| 526 | } | ||
| 527 | ); | ||
| 528 | |||
| 529 | $nav->(); | ||
| 530 | } | ||
| 531 | }; | ||
| 532 | |||
| 533 | |||
| 534 | template 'show_ticket_history' => page { | ||
| 535 | my $self = shift; | ||
| 536 | my $id = shift; | ||
| 537 | my $ticket = App::SD::Model::Ticket->new( | ||
| 538 | app_handle => $self->app_handle, | ||
| 539 | handle => $self->app_handle->handle | ||
| 540 | ); | ||
| 541 | $ticket->load(($id =~ /^\d+$/ ? 'luid' : 'uuid') =>$id); | ||
| 542 | |||
| 543 | $ticket->luid.": ".($ticket->prop('summary') || '(No summary)'); | ||
| 544 | } content { | ||
| 545 | my $self = shift; | ||
| 546 | my $id = shift; | ||
| 547 | my $ticket = App::SD::Model::Ticket->new( | ||
| 548 | app_handle => $self->app_handle, | ||
| 549 | handle => $self->app_handle->handle | ||
| 550 | ); | ||
| 551 | $ticket->load(($id =~ /^\d+$/ ? 'luid' : 'uuid') =>$id); | ||
| 552 | |||
| 553 | $self->ticket_page_actions($ticket); | ||
| 554 | |||
| 555 | show('format_history', changesets => [$ticket->changesets], change_filter => sub { my $change = shift; return $ticket->uuid eq $change->record_uuid ? 1 : 0}, | ||
| 556 | |||
| 557 | ); | ||
| 558 | }; | ||
| 559 | |||
| 560 | template 'show_ticket' => page { | ||
| 561 | my $self = shift; | ||
| 562 | my $id = shift; | ||
| 563 | my $ticket = App::SD::Model::Ticket->new( | ||
| 564 | app_handle => $self->app_handle, | ||
| 565 | handle => $self->app_handle->handle | ||
| 566 | ); | ||
| 567 | $ticket->load(($id =~ /^\d+$/ ? 'luid' : 'uuid') =>$id); | ||
| 568 | |||
| 569 | $ticket->luid.": ".($ticket->prop('summary') ||'(No summary)'); | ||
| 570 | } content { | ||
| 571 | |||
| 572 | |||
| 573 | my $self = shift; | ||
| 574 | my $id = shift; | ||
| 575 | my $ticket = App::SD::Model::Ticket->new( | ||
| 576 | app_handle => $self->app_handle, | ||
| 577 | handle => $self->app_handle->handle | ||
| 578 | ); | ||
| 579 | $ticket->load(($id =~ /^\d+$/ ? 'luid' : 'uuid') =>$id); | ||
| 580 | |||
| 581 | $self->ticket_page_actions($ticket); | ||
| 582 | |||
| 583 | |||
| 584 | show ticket_basics => $ticket; | ||
| 585 | show ticket_attachments => $ticket; | ||
| 586 | show ticket_comments => $ticket; | ||
| 587 | |||
| 588 | }; | ||
| 589 | |||
| 590 | |||
| 591 | sub ticket_page_actions { | ||
| 592 | my $self = shift; | ||
| 593 | my $ticket = shift; | ||
| 594 | |||
| 595 | ul { {class is 'actions'}; | ||
| 596 | li { a {{ href is $self->server->make_link_relative('/ticket/'.$ticket->uuid.'/view')}; 'Show'}; }; | ||
| 597 | li { a {{ href is $self->server->make_link_relative('/ticket/'.$ticket->uuid.'/edit')}; 'Update'}; } unless($self->server->static); | ||
| 598 | li { a {{ href is $self->server->make_link_relative('/ticket/'.$ticket->uuid.'/history')}; 'History'}; }; | ||
| 599 | }; | ||
| 600 | |||
| 601 | |||
| 602 | } | ||
| 603 | |||
| 604 | |||
| 605 | sub _by_creation_date { $a->prop('created') cmp $b->prop('created') }; | ||
| 606 | |||
| 607 | |||
| 608 | private template 'ticket_basics' => sub { | ||
| 609 | my $self = shift; | ||
| 610 | my $ticket = shift; | ||
| 611 | my %props = %{$ticket->get_props}; | ||
| 612 | div { { class is 'ticket-props'}; | ||
| 613 | div { class is 'widget uuid'; | ||
| 614 | label { 'UUID' }; | ||
| 615 | div { { class is 'value uuid'}; $ticket->uuid; } | ||
| 616 | }; | ||
| 617 | for my $key (qw'status component milestone', | ||
| 618 | (grep {$_ ne 'description'} (@BASIC_PROPS, (sort keys %props)))){ | ||
| 619 | next unless defined $props{$key}; | ||
| 620 | next if ($key =~ m{(?:summary)}); | ||
| 621 | next if ($key =~ /.{8}-.{4}-.{4}-.{12}-id/); | ||
| 622 | div { class is 'widget '.$key; | ||
| 623 | label {$key}; | ||
| 624 | div { { class is 'value ' . $key }; $props{$key}; } | ||
| 625 | |||
| 626 | }; | ||
| 627 | delete $props{$key}; | ||
| 628 | |||
| 629 | }; | ||
| 630 | if ($props{description} ) { | ||
| 631 | div { class is 'widget description'; | ||
| 632 | label {'description'}; | ||
| 633 | div { { class is 'value description' }; | ||
| 634 | outs($props{description}); | ||
| 635 | } | ||
| 636 | }; | ||
| 637 | } | ||
| 638 | }; | ||
| 639 | script { outs_raw('$("div.created,div.due").prettyDateTag(); | ||
| 640 | setInterval(function(){ $("div.created,div.due").prettyDateTag(); }, 5000);') }; | ||
| 641 | |||
| 642 | }; | ||
| 643 | |||
| 644 | |||
| 645 | template ticket_attachments => sub { | ||
| 646 | my $self = shift; | ||
| 647 | my $ticket = shift; | ||
| 648 | |||
| 649 | |||
| 650 | }; | ||
| 651 | |||
| 652 | |||
| 653 | |||
| 654 | |||
| 655 | |||
| 656 | private template format_history => sub { | ||
| 657 | my $self = shift; | ||
| 658 | my %args = (changesets => undef, | ||
| 659 | change_filter => undef, | ||
| 660 | change_header => undef, | ||
| 661 | sort_changesets => sub { sort {$a->created cmp $b->created} @_ }, | ||
| 662 | @_); | ||
| 663 | |||
| 664 | dl { | ||
| 665 | { class is 'history' }; | ||
| 666 | for my $changeset ( $args{sort_changesets}->( @{$args{changesets}} )) { | ||
| 667 | dt { | ||
| 668 | span { | ||
| 669 | { class is 'created' }; | ||
| 670 | $changeset->created; | ||
| 671 | }; | ||
| 672 | span { | ||
| 673 | { class is 'creator' }; | ||
| 674 | $changeset->creator || i {'Missing author'}; | ||
| 675 | }; | ||
| 676 | span { class is 'source_info'; | ||
| 677 | span { | ||
| 678 | { class is 'original_sequence_no' }; | ||
| 679 | $changeset->original_sequence_no; | ||
| 680 | }; | ||
| 681 | span { | ||
| 682 | { class is 'original_source_uuid' }; | ||
| 683 | $self->app_handle->display_name_for_replica($changeset->original_source_uuid); | ||
| 684 | }; | ||
| 685 | }; | ||
| 686 | }; | ||
| 687 | dd { | ||
| 688 | for my $change ( $changeset->changes ) { | ||
| 689 | if ( $args{change_filter}->($change)) { | ||
| 690 | if ($args{change_header}) { | ||
| 691 | $args{change_header}->($change); | ||
| 692 | } | ||
| 693 | ul { | ||
| 694 | |||
| 695 | li { outs_raw($_) } | ||
| 696 | for (grep {$_} | ||
| 697 | map { show_history_prop_change($_) } ( $change->prop_changes )); | ||
| 698 | } | ||
| 699 | } else { | ||
| 700 | i { 'Something else changed - It was ' . $change->record_type . " ".$change->record_uuid}; | ||
| 701 | } | ||
| 702 | |||
| 703 | } | ||
| 704 | } | ||
| 705 | |||
| 706 | } | ||
| 707 | }; | ||
| 708 | script { | ||
| 709 | outs_raw( | ||
| 710 | '$("span.created").prettyDateTag(); | ||
| 711 | setInterval(function(){ $("span.created").prettyDateTag(); }, 5000);' | ||
| 712 | ); | ||
| 713 | }; | ||
| 714 | }; | ||
| 715 | |||
| 716 | sub show_history_prop_change { | ||
| 717 | my $pc = shift; | ||
| 718 | if ( defined $pc->old_value && defined $pc->new_value ) { | ||
| 719 | span { class is 'property'; $pc->name } | ||
| 720 | . span { class is 'prose'; ' changed from ' } | ||
| 721 | . span { class is 'value old'; $pc->old_value } . span { class is 'prose'; " to " } | ||
| 722 | . span { class is 'value new'; $pc->new_value }; | ||
| 723 | } elsif ( defined $pc->new_value ) { | ||
| 724 | span { class is 'property'; $pc->name } | ||
| 725 | . span { class is 'prose'; ' set to '} . span { class is 'value new'; $pc->new_value } | ||
| 726 | |||
| 727 | } elsif ( defined $pc->new_value ) { | ||
| 728 | span { class is 'property'; $pc->name } . ' ' | ||
| 729 | . span { class is 'value old'; $pc->new_value } . span { class is 'prose'; ' deleted'}; | ||
| 730 | } | ||
| 731 | } | ||
| 732 | |||
| 733 | template ticket_comments => sub { | ||
| 734 | my $self = shift; | ||
| 735 | my $ticket = shift; | ||
| 736 | my @comments = sort {$a->prop('created') cmp $b->prop('created')} @{ $ticket->comments }; | ||
| 737 | if (@comments) { | ||
| 738 | h2 { { class is 'conmments'}; 'Comments'}; | ||
| 739 | ul { | ||
| 740 | { class is 'comments' }; | ||
| 741 | for my $comment (@comments) { | ||
| 742 | show('ticket_comment', $comment); | ||
| 743 | |||
| 744 | } | ||
| 745 | } | ||
| 746 | script { outs_raw('$("span.created").prettyDateTag(); | ||
| 747 | setInterval(function(){ $("span.created").prettyDateTag(); }, 5000);') }; | ||
| 748 | } | ||
| 749 | |||
| 750 | }; | ||
| 751 | |||
| 752 | template ticket_comment => sub { | ||
| 753 | my $self = shift; | ||
| 754 | my $comment = shift; | ||
| 755 | li { | ||
| 756 | span { | ||
| 757 | { class is 'metadata' }; | ||
| 758 | span { class is 'created'; $comment->prop('created') }; | ||
| 759 | outs(" "); | ||
| 760 | span { class is 'creator'; $comment->prop('creator') }; | ||
| 761 | } | ||
| 762 | div { | ||
| 763 | class is 'content'; | ||
| 764 | if ( !$comment->prop('content') ) { | ||
| 765 | i {'No body was entered for this comment'}; | ||
| 766 | |||
| 767 | } elsif ( $comment->prop('content_type') && $comment->prop('content_type') =~ m{text/html}i ) { | ||
| 768 | outs_raw( $comment->prop('content') ); | ||
| 769 | } else { | ||
| 770 | div { class is 'content-pre'; $comment->prop('content');}; | ||
| 771 | } | ||
| 772 | } | ||
| 773 | } | ||
| 774 | }; | ||
| 775 | |||
| 776 | sub ticket_link { | ||
| 777 | my $self = shift; | ||
| 778 | my $ticket = shift; | ||
| 779 | my $label = shift; | ||
| 780 | span { | ||
| 781 | class is 'ticket-link'; | ||
| 782 | a { | ||
| 783 | { | ||
| 784 | class is 'ticket'; | ||
| 785 | href is $self->server->make_link_relative( '/ticket/' . $ticket->uuid."/view"); | ||
| 786 | }; | ||
| 787 | $label; | ||
| 788 | } | ||
| 789 | }; | ||
| 790 | } | ||
| 791 | |||
| 792 | 1; |