[Bio] / FigWebServices / diagram_upload.cgi Repository:
ViewVC logotype

View of /FigWebServices/diagram_upload.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (annotate)
Mon Feb 19 18:53:43 2007 UTC (13 years ago) by paarmann
Branch: MAIN
CVS Tags: mgrast_dev_08112011, rast_rel_2009_05_18, mgrast_dev_08022011, rast_rel_2014_0912, rast_rel_2008_06_18, myrast_rel40, rast_rel_2008_06_16, mgrast_dev_05262011, rast_rel_2008_12_18, mgrast_dev_04082011, rast_rel_2008_07_21, rast_rel_2010_0928, rast_2008_0924, mgrast_version_3_2, mgrast_dev_12152011, rast_rel_2008_04_23, mgrast_dev_06072011, rast_rel_2008_09_30, rast_rel_2009_0925, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, rast_rel_2009_02_05, rast_rel_2011_0119, mgrast_rel_2008_0625, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, rast_rel_2008_10_09, mgrast_dev_04012011, rast_release_2008_09_29, mgrast_rel_2008_0806, mgrast_rel_2008_0923, mgrast_rel_2008_0919, rast_rel_2009_07_09, rast_rel_2010_0827, mgrast_rel_2008_1110, myrast_33, rast_rel_2011_0928, rast_rel_2008_09_29, mgrast_rel_2008_0917, rast_rel_2008_10_29, mgrast_dev_04052011, mgrast_dev_02222011, rast_rel_2009_03_26, mgrast_dev_10262011, rast_rel_2008_11_24, rast_rel_2008_08_07, HEAD
Changes since 1.1: +4 -4 lines
fixed the hrefs

#
# Copyright (c) 2003-2006 University of Chicago and Fellowship
# for Interpretations of Genomes. All Rights Reserved.
#
# This file is part of the SEED Toolkit.
# 
# The SEED Toolkit is free software. You can redistribute
# it and/or modify it under the terms of the SEED Toolkit
# Public License. 
#
# You should have received a copy of the SEED Toolkit Public License
# along with this program; if not write to the University of Chicago
# at info@ci.uchicago.edu or the Fellowship for Interpretation of
# Genomes at veronika@thefig.info or download a copy from
# http://www.theseed.org/LICENSE.TXT.
#

# $Id: diagram_upload.cgi,v 1.2 2007/02/19 18:53:43 paarmann Exp $

use strict;
use warnings;

use FIG_CGI;
use FIG_Config;
use CGI;

use Diagram;

eval {
    &main;
};

if ($@)
{
    my $cgi = new CGI();

    print $cgi->header();
    print $cgi->start_html();
    print "<pre>$@</pre>";
    print $cgi->end_html();

}

sub main {

    my ($fig, $cgi, $user) = FIG_CGI::init(debug_save => 0, debug_load => 0, print_params => 0);
    
    my $css = qq~body {
      font-family: Verdana, Arial, sans-serif;
      font-size: 12px;
      font-weight: normal;
      color: #000;
      background-color: #FFFFFF;
    }
    th {
    text-align: left;
    }~;

    # print out the page
    print $cgi->header();
    print $cgi->start_html(-title => 'The SEED - Upload New Subsystem Diagram',
			   -style => { -code => $css }
	);

    if ($cgi->param('Upload')) {

	if ($cgi->param('subsystem') and 
	    ( $cgi->param('change_diagram') eq 'new' and $cgi->param('diagram_name') and 
	      $cgi->param('diagram_image') and $cgi->param('diagram_map') ) or
	    ( $cgi->param('change_diagram') ne 'new' and 
	      ($cgi->param('diagram_name') or $cgi->param('diagram_image') or $cgi->param('diagram_map') ) )
	    ) {
	    print &do_Upload($fig, $cgi);
	}
	else {
	    print &show_Upload($fig, $cgi);
	    print "<p><em>No clue how you managed to lose a parameter!</em></p>" unless ($cgi->param('subsystem'));
	    print "<p><em>No clue how you managed to lose a parameter!</em></p>" unless ($cgi->param('change_diagram'));
	    if ($cgi->param('change_diagram') eq 'new') {
		print "<p><em>Please enter a diagram name!</em></p>" unless ($cgi->param('diagram_name'));
		print "<p><em>Please choose a diagram image!</em></p>" unless ($cgi->param('diagram_image'));
		print "<p><em>Please choose a diagram html map!</em></p>" unless ($cgi->param('diagram_map'));
	    }
	}
    }
    else {
	print &show_Upload($fig, $cgi);
    }

    print $cgi->end_html;

}


sub show_Upload {
    my ($fig, $cgi) = @_;

    my @subsystems = ('');
    push @subsystems, sort $fig->all_subsystems();

    my $content = "<h1>Upload new diagrams:</h1>";
    $content .= $cgi->start_form();
    $content .= '<table>';
    
    if (!$cgi->param('subsystem')) {
	$content .= '<tr><th>Choose a subsystem: </th><td>'.
	    $cgi->popup_menu(-name=>'subsystem', -values=> \@subsystems, -default=>'',).'</td></tr>';
	$content .= '<tr><td colspan="2">'.$cgi->submit(-name=>'Choose this subsystem').'</td></tr>';
    }
    else {

	# get existing 'new' diagrams
	my $subsystem = $fig->get_subsystem($cgi->param('subsystem'));
	my @diagrams = $subsystem->get_diagrams(); # this is a @@: [ ($id, $name, $link) ]
	my $labels = { 'new' => 'new' };
	my $new_diagrams = [ 'new' ];
	for my $entry (@diagrams) {
            my($id, $name, $link) = @$entry;
	    if ($subsystem->is_new_diagram($id)) {
		push @$new_diagrams, $id;
		$labels->{$id} = $name;
	    }
	}

	my $subsystem_name = $cgi->param('subsystem');
	$subsystem_name =~ s/_/ /g;
	$content .= '<tr><th>Subsystem: </th><td>'.$subsystem_name.
	    $cgi->hidden(-name=>'subsystem', -value=>$cgi->param('subsystem')).'</td></tr>';
	$content .= '<tr><th>Update existing? </th><td>'.
	    $cgi->popup_menu(-name=>'change_diagram', -values=>$new_diagrams, -labels=>$labels, -default=>'new',).'</td></tr>';
	$content .= '<tr><th>Diagram Name: </th><td>'.
	    $cgi->textfield(-name=>'diagram_name', -size=>55).'</td></tr>';
	$content .= '<tr><th>Image File: </th><td>'.
	    $cgi->filefield(-name=>'diagram_image', -size=>55).'</td></tr>';
	$content .= '<tr><th>Html Map File: </th><td>'.
	    $cgi->filefield(-name=>'diagram_map', -size=>55).'</td></tr>';
	$content .= '<tr><td colspan="2">'.$cgi->submit(-name=>'Upload').
	    ' <em><a href="diagram_upload.cgi">[ start over ]</a></em></td></tr>';

    }
    
    $content .= '</table>';

    return $content;

}


sub do_Upload {
    my ($fig, $cgi) = @_;

    my $subsystem = $fig->get_subsystem($cgi->param('subsystem'));
    my $id = ($cgi->param('change_diagram')) ? $cgi->param('change_diagram') : undef;
    
    my $content = '';
    
    if ($cgi->param('change_diagram') eq 'new' ) {
	
	$id = $subsystem->create_new_diagram($cgi->param('diagram_image'), 
					     $cgi->param('diagram_map'),
					     $cgi->param('diagram_name'));
	$content .= '<p><em>Uploaded new diagram.</em></p>';
	
    }
    else {

	if ($cgi->param('diagram_name')) {
	    $subsystem->rename_diagram($cgi->param('change_diagram'), $cgi->param('diagram_name'));
	    $content .= '<p><em>Changed diagram name (id: '.$cgi->param('change_diagram').') to '.
		$cgi->param('diagram_name').'</em></p>';
	}

	if ($cgi->param('diagram_image')) {
	    $subsystem->upload_new_image($cgi->param('change_diagram'), $cgi->param('diagram_image'));
	    $content .= '<p><em>New image uploaded for diagram (id: '.$cgi->param('change_diagram').').</em></p>';
	}

	if ($cgi->param('diagram_map')) {
	    $subsystem->upload_new_html($cgi->param('change_diagram'), $cgi->param('diagram_map'));
	    $content .= '<p><em>New html map uploaded for diagram (id: '.$cgi->param('change_diagram').').</em></p>';
	}
            
    }

    unless ($content) {
	$content .= '<p><em>Nothing was done, try giving at least one parameter!</em></p>';
    }

    if (defined $id) {
	$content .= '<p><em><a href="diagram.cgi?subsystem_name='.$cgi->param('subsystem').
	    '&diagram='.$id.'" target="_new_diagram">[ view this subsystem diagram ]</a></em></p>';
    }
    $content .= '<p><em><a href="diagram_upload.cgi?subsystem='.$cgi->param('subsystem').'">[ go back to this subsystem upload ]</a></em></p>';
    $content .= '<p><em><a href="diagram_upload.cgi">[ start over ]</a></em></p>';
    
    return $content;

}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3