#!/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,("