#!/usr/bin/perl -w # -*- perl -*- use P4CGI ; use strict ; # ################################################################# # CONFIGURATION INFORMATION # All config info should be in P4CGI.pm # ################################################################# # # P4 change browser # View list of jobs # ################################################################# ####### # Parameters: # # LIST # If defined, show a list, if not, show select dialogue # # JOBVIEW # If defined, used as jobview # # FLDnnn # These parameters for this script depends on the fileds defined in the # jobspec. The parameters are named: # FLDnnn # Where nnn is the field number as defined in the jobspec # # MATCHTYPE # Used with FLDnnn parameters and defines if all or any should match # ###### ### ### Get and parse jobspec ### my %jobspec ; &P4CGI::p4readform("jobspec -o",\%jobspec) ; # # Make a 2000.2 jobspec compatible with 2000.1 and earlier # if(exists $jobspec{"Values"}) { foreach (split("\n",$jobspec{"Values"})) { my ($fld,$value) = split(/\s+/,$_) ; $jobspec{"Values-$fld"} = $value ; } ; } # # Get jpbspec fields # my %fields ; # Store name, type, len, and options by field number { my @tmp = split("\n",$jobspec{"Fields"}) ; my $s ; foreach $s (@tmp) { my ($code,$name,$type,$len,$option) = split(/\s+/,$s) ; $fields{$code} = [ $name, $type, $len, $option ] ; } } # File spec argument my $FSPC = &P4CGI::cgi()->param("FSPC") ; $FSPC = "" unless defined $FSPC ; $FSPC = "" if $FSPC eq "//..." ; $FSPC=&P4CGI::htmlEncode($FSPC) ; ### ### Build a selection forms for job list ### sub buildSelection() { ## Get list of users (for later use for "user" field) my %userData = &P4CGI::p4users() ; my @listOfUsers = sort { uc($a) cmp uc ($b) } (keys %userData) ; my %userCvt ; &P4CGI::p4user2name(\%userCvt ); my $ulistSize = @listOfUsers ; $ulistSize= 15 if $ulistSize > 15 ; my @fieldPrompt ; # Prompt for each field my @field ; # form entry for each field if(exists $fields{"102"}) { # Check that we have a status field (code 102) my @statusButtons ; my $name = $ { $fields{"102"}}[0] ; if(exists $jobspec{"Values-$name"}) { # Check that we have the values my @values = split('/',$jobspec{"Values-$name"}) ; my $v ; foreach $v (@values) { push @statusButtons,&P4CGI::buttonLink("jobList.cgi", "List jobs with $name $v", "FLD102=$v", "LIST=Y", "$v") ; } } push @fieldPrompt,"List all jobs with status" ; push @field, join(" ",@statusButtons) ; } push @fieldPrompt,"File spec" ; push @field, &P4CGI::cgi()->textfield(-name => "FSPC", -default => $FSPC , -override => 1, -size => 60, -maxlength => 256) ; my $code ; ## Loop over all fields (sorted by id) foreach $code (sort keys %fields) { my ($name,$type,$len,$option) = @{$fields{$code}} ; # Handle "Select" type field if($type eq "select") { my @set = split("/",$jobspec{"Values-$name"}) ; my $size = scalar @set ; if($size > 5) { $size = 5 } ; push @field, &P4CGI::cgi()->scrolling_list(-name => "FLD".$code, -values => \@set, -size => $size, -multiple => 'true') ; push @fieldPrompt,"$name is one of" ; next ; } # Date type field if($type eq "date") { my %values = ( 1 => " One Day old", 2 => " Two Days old", 3 => "Three Days old", 4 => " Four Days old", 5 => " Five Days old", 6 => " Six Days old", 7 => " One Week old", 7*2 => " Two Weeks old", 7*2 => "Three Weeks old", 7*4 => " Four Weeks old", 7*5 => " Five Weeks old", 7*6 => " Six Weeks old", 7*7 => "Seven Weeks old", 7*8 => "Eight Weeks old", 7*9 => " Nine Weeks old", 7*10 => " 10 Weeks old", 7*11 => " 11 Weeks old", 7*12 => " 12 Weeks old", 7*16 => " 16 Weeks old", 7*20 => " 20 Weeks old", 7*26 => " 26 Weeks old", 7*40 => " 40 Weeks old", 7*52 => " 52 Weeks old") ; my @values = sort { $a <=> $b } keys %values ; push @field, join("\n", (&P4CGI::cgi()->popup_menu(-name => "FLD".$code."cmp", -default => 0, -values => ["-",">",">=","<=","<"] , -labels => { "-"=>"- Ignore -", ">"=>"Less than", ">="=>"Less than or exactly", "<="=>"More than or exactly", "<"=>"More than" }), &P4CGI::cgi()->popup_menu(-name => "FLD".$code, -default => 0, -values => \@values, -labels => \%values)) ) ; push @fieldPrompt,"$name is" ; next ; } # Type must be word, line or text. Compute some lengths for # text field $len = 256 if $len == 0 ; my $displen = $len ; $displen = 40 if $displen > 40 ; my $textfield = &P4CGI::cgi()->textfield(-name => "FLD".$code, -size => $displen, -maxlength => $len) ; # Field type word if($type eq "word") { if($code == 101) { # Reserved field Job push @fieldPrompt,"Job name is" ; push @field, $textfield ; next ; } else { if($code == 103) { # Rserved field User push @fieldPrompt,"User is one of" ; push @field, &P4CGI::cgi()->scrolling_list(-name => "FLD$code", -values => \@listOfUsers, -size => $ulistSize, -multiple => 'true', -labels => \%userCvt) ; next ; } push @fieldPrompt,"$name is" ; push @field, $textfield ; next ; } } # Field type line or text if($type eq "line" or $type eq "text") { push @fieldPrompt,"$name contains
one of the words" ; push @field, $textfield ; next ; } } # end loop over fields # Add field for match for "any" or "all" fields push @fieldPrompt,"Select type of match" ; push @field, &P4CGI::cgi()->popup_menu(-name => "MATCHTYPE", -default => 0, -values => ["all","any"] , -labels => { "all"=>"Match all fields above", "any" =>"Match any field above"}) ; # # Create table contents from fields my @tmp ; while(@field > 0) { my $pr = shift @fieldPrompt ; my $fld = shift @field ; push @tmp,("", "".$pr.":", "", $fld, "") ; } ; push @tmp , &P4CGI::table_row(" ", {-align=>"left", -valign=>"bottom", -text => join(" ", &P4CGI::cgi()->hidden(-name=>"DP", -value=>&P4CGI::CURR_DEPOT_NO()), &P4CGI::cgi()->submit(-name => "LIST", -value => "Go") )}) ; # Return table and form return join("\n", ( &P4CGI::cgi()->startform(-action => "jobList.cgi", -method => "GET"), &P4CGI::start_framedTable("Select jobs"), @tmp, &P4CGI::end_framedTable(), &P4CGI::cgi()->endform())) ; } # end buildSelection() unless(defined &P4CGI::cgi()->param("LIST")) { my $selection = &buildSelection() ; my @buttons ; push @buttons,&P4CGI::buttonCell("jobList.cgi", "List all jobs", "LIST=Y", "List all jobs") ; my $title = "View job list" ; if($FSPC ne "") { $title .= "
for $FSPC" ; } ; print &P4CGI::start_page("List jobs",@buttons), $selection ; } else { # Do we have "JOBVIEW"? my $jobview = &P4CGI::cgi()->param("JOBVIEW") ; my $jobviewDesc ; if(defined $jobview) { $jobviewDesc = "Where jobview is: $jobview" ; } # If not, build a job view if(! defined $jobview) { $jobview = "" ; $jobviewDesc="" ; # Get field parameters my @selectParams = grep { /^FLD/ ; } P4CGI::cgi()->param ; my %params ; foreach (@selectParams) { my $v = $_ ; s/^FLD// ; my @pars = &P4CGI::cgi()->param($v) ; $params{$_} = \@pars ; } # Set match all/any my $MATCHTYPE = &P4CGI::cgi()->param("MATCHTYPE") ; $MATCHTYPE="all" unless defined $MATCHTYPE ; my $matchtype = "|" ; my $matchtypeDesc = "or" ; if($MATCHTYPE eq "all") { $matchtype = "" ; $matchtypeDesc = "and" ; } ; # Loop over field parameters my $id ; foreach $id (grep {/^\d+$/} keys %params) { my $desc ; next unless exists $fields{$id} ; my ($name,$type,$len,$option) = @{$fields{$id}} ; my @p = @{ $params{$id}} ; if($type eq "text" or $type eq "line") { my @tmp = map { split ; } @p ; @p = @tmp ; } ; if(@p > 0 and length($p[0]) > 0) { my $thisItem ; if($type eq "date") { my @cmp = @{ $params{"${id}cmp"}} ; my $cmp = shift @cmp ; next if $cmp eq "-" ; my $time = time()-(24*3600*$p[0]) ; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time); $year = 1900+$year ; $thisItem = sprintf("$name$cmp$year/%02.2d/%02.2d",$mon+1,$mday) ; $desc .= "$thisItem" ; } else { if(@p == 1) { $thisItem = "$name=$p[0]" ; $desc .= "$name is \"$p[0]\"" if $type eq "select" ; $desc .= "$name contains \"$p[0]\"" if $type =~ /^(word|line|text)/ ; } else { $thisItem = "($name=" . join("|$name=",@p) . ")" ; $desc .= "$name is" if $type eq "select" ; $desc .= "$name contains" if $type =~ /^(word|line|text)/ ; $desc .= " one of" if @p > 2 ; my $last = pop @p ; $desc .= " \"". join('","',@p) . "\" or \"$last\"" ; } } if(length($jobview) > 0) { $jobview .= " $matchtype $thisItem" ; $jobviewDesc .= "
$matchtypeDesc
\n$desc" ; } else { $jobview = "$thisItem" ; $jobviewDesc = $desc ; } } } ; } ; &P4CGI::cgi()->delete("LIST") ; my @buttons = (&P4CGI::buttonCell("jobList.cgi", "Make a new selection of jobs", "New selection")) ; my $title = "View job list" ; if($FSPC ne "") { $title .= "
for $FSPC" ; } ; if($jobviewDesc) { $title .= "
$jobviewDesc" ; } ; print &P4CGI::start_page("",@buttons) ; &P4CGI::ERRLOG("jobView:\"$jobview\"") ; my @tmp ; my $ejobview = "" ; $ejobview = "-e \"$jobview\"" if length($jobview) > 0 ; &P4CGI::p4call(\@tmp, "jobs -l $ejobview $FSPC" ); if(@tmp == 0) { print "No matching jobs found for: $jobview $FSPC", &buildSelection() ; } else { print &P4CGI::start_framedTable("Jobs: $jobview $FSPC"), &P4CGI::start_table(), &P4CGI::table_header("Job","","Date","User","Status") ; while (@tmp > 0) { my $l = shift @tmp ; $l =~ /^(\S+) on (\S+) by (\S+) \*(.*)\*/ and do { my ($job,$date,$user,$status) = ($1,$2,$3,$4) ; shift @tmp ; my $desc ; while(@tmp) { $_ = shift @tmp ; s/^\t// or last ; if($desc) { $desc .= "\n$_" ; } else { $desc .= "$_" ; } } $job = &P4CGI::ahref("-url" => "jobView.cgi", "JOB=$job", "HELP=View job info", "$job") ; $user = &P4CGI::ahref("-url" => "userView.cgi", "USER=$user", "HELP=View user info", $user) ; $desc = &P4CGI::formatDescription($desc) ; print &P4CGI::table_row(undef, $job, $date, $user, $status) ; print &P4CGI::table_row({-text=>"", -style=>"width: 30pt"}, undef, undef, undef, { -class=>"Description", -text => $desc }) ; } } print &P4CGI::end_table(), &P4CGI::end_framedTable("Jobs: $jobview $FSPC") ; } } ; print &P4CGI::end_page() ; # # That's all folks #