Forum Moderators: coopster & phranque

Message Too Old, No Replies

Help needed to build navigation tree like structure

         

srins

7:37 am on Oct 4, 2005 (gmt 0)

10+ Year Member



I need to build navigation tree like menu through perl/CGi dynamically .complete perl script.

my hash would be like hash of arrays

my %sample =(

component1 => [command1,command2,command3],
component2 =>["command1,command2,commad3],
component3 =>["command1,command2,command3]);

so i need tree like structure as

-components
¦
¦
- --component1
¦ ¦
¦ ¦--command1
¦ ¦--command2
¦
+--component2
¦
+--component3
¦
+--component4

If I expand component1 it shold display commands like command1,command2 etc.If I press command1 it should hit the server and retrive set of test cases (which is also associated as hash of arrays) with check box associated with that command. so that i need to select check box and need to add ,delete or run the selected test case for corresponding commands and component associated .This is my scenerio.I am new to perl/cgi.can u give some guidelines and help for my scenerio.If u need more explanation i can give u.

If I click command1 it should hit server reterive series of test cases associated with that(also kept in hash of arrays) with check boxes,

like

testcase1
testcase2
testcase3.

-components
¦
¦
- --component1 for command1:
¦ ¦
¦ ¦--command1 checkboxbutton testcase1
¦ ¦--command2 checkboxbutton testcase2
¦ checkboxbutton testcase3
+--component2
¦ add/edit/run/delete
+--component3
¦
+--component4

where i will select particular testcase say testcase1,i will run the testcase or add or modify accordingly.

This is my scenerio.I am new to perl/cgi.can u give some guidelines and help for my scenerio.If u need more explanation i can give u.

Thanks,
srinivasan.

KevinADC

5:22 pm on Oct 4, 2005 (gmt 0)

10+ Year Member



I will try some code later today if nobody else replies.

KevinADC

1:48 am on Oct 5, 2005 (gmt 0)

10+ Year Member



Well, here is a very basic method for doing what you want.


#!perl
use CGI qw/:standard/;
use strict;

my $comp = param('comp');

print header,start_html;

my %sample =(
component1 => [qw(command1 command2 command3)],
component2 => [qw(command1 command2 command3)],
component3 => [qw(command1 command2 command3)],
component4 => [qw(command1 command2 command3)],
);
print qq~Components
<div style="padding: 10px 0px 0px 10px">
~;
foreach my $key (sort keys %sample) {
if ($comp eq $key) {
print qq~- <a href="$ENV{SCRIPT_NAME}/$key?comp=$key">$key</a><br/>\n~;
print qq~<div style="padding: 0px 0px 0px 20px">~;
print qq~<a href="$ENV{SCRIPT_NAME}/$key?comp=$key;comd=$_">$_</a><br/>\n~ for @{$sample{$key}};
print '</div>';
}
else {
print qq~+ <a href="$ENV{SCRIPT_NAME}/$key?comp=$key">$key</a><br/>\n~;
}
}
print qq~</div>~,
end_html;

because the hash is a hash of arrays, the arrays need to be dereferenced when you print them, which is what this is doing:

@{$sample{$key}}

Having no idea how much perl you know and what modules you are using, if any, or what type of database, if any, it's hard to give you more suggestions than the above.

There will be a number of ways to do this. Using a template is a good idea, but then you have to learn HTML::Template or other templating module. CGI::Application is also becoming popular for this type of application. I have little experience with HTML::Template and no experience with CGI::Application so will not be of much use in helping with those modules. You could do the whole thing with just the CGI module too. Or you could do it all with no modules but I suggest using CGI for the form/URI processing if nothing else.

There are a number of good tutorials here:

[perldoc.perl.org...]

and you can always look up modules and many other perl related things at:

[cpan.org...]

srins

10:19 am on Oct 5, 2005 (gmt 0)

10+ Year Member



Hi kevin,

Thanks for your sample code.In your sample code ,when i execute that code its working fine.when i expand component1 ,its show all commands associated with that,when i try to expand component2,it gets expand and but collapsing component 1 expand.That is shrinking component 1 and expanding component2.

when i press component1,its expanding as,

-components
¦
¦
- --component1
¦ ¦
¦ ¦--command1
¦ ¦--command2
¦----component2

when i expand component2 ,component 1 is shrinking,but i need to expand component1 and component 2 to retain in expanded state.

when i press component2,component1 shrinks,

-components
¦
¦
- --component1
¦
¦----component2
¦
¦--command1
¦--command2

But i need to display as both component1 and component2 get expanded and need to shrink when i press - minus button.

as
-components
¦
¦
- --component1
¦ ¦
¦ ¦--command1
¦ ¦--command2
-----component2
¦
¦--command1
¦--command2

when i press - minus it should shrink.what changes need to be done in the above code u send .can u please help me in this regard.

Thanks,
srinivasan.