From 26e9889061615ff1a784775132dd6546540a4c4f Mon Sep 17 00:00:00 2001 From: Brian Read Date: Sun, 28 Apr 2024 12:03:06 +0100 Subject: [PATCH] More sort routes --- Targets/Nfsshare-Custom.pm | 84 +++++++++--- Targets/Nfsshare-Custom.pm.new | 48 +++++-- Targets/Nfsshare.html.ep | 3 + Targets/Nfsshare.pm | 201 +++++++++++++++++++++------- Targets/_nfs_PARAMS.html.ep | 7 +- Targets/_nfs_TABLE.html.ep | 17 ++- Targets/nfsshare_en.lex | 35 ++--- Templates/controller.pm.tem | 186 +++++++++++++++++-------- Templates/custom.pm.tem | 31 ++++- Templates/html_controls.html.ep.xml | 6 +- Templates/layout.html.ep.tem | 2 +- Templates/partial.html.ep.tem | 2 +- flow of control through controller | 52 +++++++ nfsshare.json5 | 3 +- sm2gen.py | 107 +++++---------- 15 files changed, 549 insertions(+), 235 deletions(-) create mode 100644 flow of control through controller diff --git a/Targets/Nfsshare-Custom.pm b/Targets/Nfsshare-Custom.pm index 9d489c2..4e09e2c 100644 --- a/Targets/Nfsshare-Custom.pm +++ b/Targets/Nfsshare-Custom.pm @@ -2,13 +2,8 @@ # Routines to be editted by the developer to provide validation for parameters # and provison of the control data for table(s) # -# Generated by SM2Gen version:${version} +# Generated by SME2Gen version:0.6 Chameleon version:4.5.4 On Python:3.10.12 at 2024-04-27 10:35 # -#$cdb=$main::cdb; -#$adb=$main::adb; -#$ndb=$main::ndb; -#$hdb=$main::hdb; -#$ddb=$main::ddb; use esmith::util; use esmith::HostsDB; @@ -28,11 +23,13 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db"); # Validation routines - parameters for each panel sub validate_PARAMS { + $prefix_data = shift; #Data hash as parameter $ret = 'ok'; return $ret; } sub validate_TABLE { + $prefix_data = shift; #Data hash as parameter $ret = 'ok'; return $ret; } @@ -40,19 +37,70 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db"); # Get control data for tables(s) -sub get_ibays { - my @res; - my @ibays = $adb->ibays(); - foreach my $i (@ibays){ - my %hash = ('Name'=> $i->prop('Name'), - 'Description' => $i->prop('Description'), - 'Flag' => 1, - 'PARAMS' => 'Modify' - ); - push(@res,\%hash); + sub get_ibays { + my $c = shift; + my @res; + my @ibays = $adb->ibays(); + foreach my $i (@ibays){ + # Taken pretty well verbatim from /usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/nfsshare.pm + # although the href is more specific to the SM2 structure. + my $ibayname = $i->key(); + my $ibaydesc = $i->prop('Name'); + my $ibaynfs = $i->prop('NfsStatus')||'disabled'; + my $modifiable = $i->prop('Modifiable') || 'yes'; + + $ibaynfs = $c->l('ENABLED') if ($ibaynfs eq 'enabled'); + $ibaynfs = $c->l('DISABLED') if ($ibaynfs eq 'disabled'); + + + #my $params = $self->build_ibay_cgi_params($ibayname, $i->props()); + #my $scriptname = "nfsshareu"; + #my $href = "$scriptname?$params&action=modify&wherenext="; + + my $actionModify = ' '; + if ($modifiable eq 'yes'){ + $actionModify .= ""." " + } + + my %hash = ('Name'=> $ibayname, + 'Description' => $ibaydesc, + 'Flag' => $ibaynfs, + 'Modify' => $actionModify + ); + push(@res,\%hash); + } + return \@res } - return \@res -} + +# Return hash with values from row in which link clicked on table + + sub validate_get_selected_PARAMS { + $selected = shift; #Parameter is name of selected row. + %ret = {}; + return $ret; + } + + sub validate_get_selected_TABLE { + $selected = shift; #Parameter is name of selected row. + %ret = {}; + return $ret; + } + + +#after sucessful modify or create or whatever and submit then perfom (if the params validate) + + sub perform_PARAMS { + $prefix_data = shift; #Data hash as parameter + $ret = 'ok'; + return $ret; + } + + sub perform_TABLE { + $prefix_data = shift; #Data hash as parameter + $ret = 'ok'; + return $ret; + } + 1; diff --git a/Targets/Nfsshare-Custom.pm.new b/Targets/Nfsshare-Custom.pm.new index e56af02..4ce9b53 100644 --- a/Targets/Nfsshare-Custom.pm.new +++ b/Targets/Nfsshare-Custom.pm.new @@ -2,11 +2,8 @@ # Routines to be editted by the developer to provide validation for parameters # and provison of the control data for table(s) # -#$cdb=$main::cdb; -#$adb=$main::adb; -#$ndb=$main::ndb; -#$hdb=$main::hdb; -#$ddb=$main::ddb; +# Generated by SME2Gen version:0.6 Chameleon version:4.5.4 On Python:3.10.12 at 2024-04-28 11:53 +# use esmith::util; use esmith::HostsDB; @@ -26,11 +23,13 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db"); # Validation routines - parameters for each panel sub validate_PARAMS { + $prefix_data = shift; #Data hash as parameter $ret = 'ok'; return $ret; } sub validate_TABLE { + $prefix_data = shift; #Data hash as parameter $ret = 'ok'; return $ret; } @@ -38,9 +37,42 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db"); # Get control data for tables(s) -sub get_ibays { - return [] -} + sub get_ibays { + my $c = shift; + @ret = {} + return \@ret + } + + +# Return hash with values from row in which link clicked on table + + sub validate_get_selected_PARAMS { + $selected = shift; #Parameter is name of selected row. + %ret = {}; + return $ret; + } + + sub validate_get_selected_TABLE { + $selected = shift; #Parameter is name of selected row. + %ret = {}; + return $ret; + } + + +#after sucessful modify or create or whatever and submit then perfom (if the params validate) + + sub perform_PARAMS { + $prefix_data = shift; #Data hash as parameter + $ret = 'ok'; + return $ret; + } + + sub perform_TABLE { + $prefix_data = shift; #Data hash as parameter + $ret = 'ok'; + return $ret; + } + 1; diff --git a/Targets/Nfsshare.html.ep b/Targets/Nfsshare.html.ep index 0635265..63ea5dd 100644 --- a/Targets/Nfsshare.html.ep +++ b/Targets/Nfsshare.html.ep @@ -1,4 +1,7 @@ % layout 'default', title => "Sme server 2 - NFS data share", share_dir => './'; +%# +%# Generated by SME2Gen version:0.6 Chameleon version:4.5.4 On Python:3.10.12 at 2024-04-28 11:53 +%# % content_for 'module' => begin
diff --git a/Targets/Nfsshare.pm b/Targets/Nfsshare.pm index 6def024..70d8c83 100644 --- a/Targets/Nfsshare.pm +++ b/Targets/Nfsshare.pm @@ -1,49 +1,25 @@ package SrvMngr::Controller::Nfsshare; - +# +# Generated by version:SME2Gen version:0.6 Chameleon version:4.5.4 On Python:3.10.12 at 2024-04-28 11:53 +# #---------------------------------------------------------------------- # heading : Network # description : NFS data share # navigation : 2000 400 # # name : nfsshare, method : get, url : /nfsshare, ctlact : nfsshare#main -# name : nfsshared, method : post, url : /nfsshared, ctlact : nfsshare#do_update +# name : nfsshareu, method : post, url : /nfsshareu, ctlact : nfsshare#do_update +# name : nfsshared, method : get, url : /nfsshared, ctlact : nfsshare#do_display # # routes : end # -# Documentation: https://wiki.contribs.org/{PackageName} +# Documentation: https://wiki.contribs.org/Nfsshare #---------------------------------------------------------------------- # # Scheme of things: # -#main: -## -## Initial entry -## -#set initial panel -#for initial panel: -# load up _data hash with DB fields -# load up stash with pointer(s) to control fields hash(= get-)) -#render initial panel -# -#do_display -## -## Return after submit pushed on panel -## -#load up all params into local hash -# by panel: -# by param: -# validate param (return ret = ok or error message) - call validate- -# break out on error -#if validation not ok -# render back to current panel with error message in stash -#otherwise -# By panel: -# Copy back to DB any that have changed (how to easily tell if it has changed?) -# do whatever is required (inc signal_event smeserver--update?) -# set success -# call main? - +# TBA!! use strict; use warnings; @@ -76,6 +52,16 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db"); require '/usr/share/smanager/lib/SrvMngr/Controller/Nfsshare-Custom.pm'; #The code that is to be added by the developer sub main { +# +# Initial entry - route is "/" +# +#set initial panel +#for initial panel: + #Specifiy panel to enter + #load up _data hash with DB fields + #load up stash with pointer(s) to control fields hash(= get-)) + #and a pointer to the prefix_data hash +#render initial panel my $c = shift; $c->app->log->info( $c->log_req ); @@ -87,12 +73,12 @@ sub main { $nfs_data{'trt'} = 'TABLE'; #Load any DB entries into the _data area so as they are preset in the form - # which DB + # which DB - this only really works if the initial panel is a PARAMS type panel and not a TABLE my $db = $cdb; #pickup local or global db or Default to config # and table control fields - $c->stash(ibays=>get_ibays()); + $c->stash(ibays=>get_ibays($c)); $c->stash( @@ -103,7 +89,32 @@ sub main { $c->render( template => "Nfsshare" ); } +# Post request with params - submit from a form sub do_update { +# +# Return after submit pushed on panel (this is a post) - route is "/u" +# parameters in the params hash. +# +#load up all params into prefix_data hash: +#By panel (series of if statements - only one executed): + #call validate-PANEL() - return ret = ok or error message + +#if validation not ok: + #render back to current panel with error message in stash +#otherwise: + #By panel (series of if statements - only one executed): + #do whatever is required: call perform-PANEL() - return "ok" or Error Message + #call signal-event for any global actions specified (check it exists - error and continue?) + #if action smeserver--update exists + #signal_event smeserver--update + #call signal-event for any specific actions for thids panel (check it exists first - error and continue) + #set success in stash + #if no "nextpanel" entry: + #set firstpanel + #else + #set nextpanel + #call render + my $c = shift; $c->app->log->info($c->log_req); @@ -116,49 +127,137 @@ sub do_update { # Get number of POST parameters my $num_params = keys %params; - #Params are available in the hash "params" - # you may use: - my @result; - foreach my $key (keys %params) { - my $value = $params{$key}; - push @result, { $key => $value }; - $c->app->log->debug("$key: $value"); + #Params are available in the hash "params" - copy to the prefix_data hash + while (my ($key, $value) = each %{$c->req->params->to_hash}) { + $nfs_data{$key} = $value; } # the value of trt will tell you which panel has returned - my $trt = $c->param('trt') || 'TABLE' ; #hidden control on every form. + my $trt = $c->param('trt') || 'TABLE'; #hidden control on every form. my $ret = 'ok'; - #Validate the parameters accordingly + #Validate the parameters in a custom sub one for each panel (although only one of these will be executed) + my $thispanel; if ($trt eq 'PARAMS'){ #Validate form parameters for panel PARAMS - $ret = validate_PARAMS(); + $ret = validate_PARAMS(\%nfs_data); $thispanel = 'PARAMS'; } if ($trt eq 'TABLE'){ #Validate form parameters for panel TABLE - $ret = validate_TABLE(); + $ret = validate_TABLE(\%nfs_data); $thispanel = 'TABLE'; } - if ($ret eq "ok") { + + if ($ret ne "ok") { + # return to the panel with error message + $c->stash(error => $c->l($ret)); + $c->render("Nfsshare"); + } else { #Do whatever is needed, including writing values to the DB - my $db = $cdb; #pickup local or global db or Default to config - # anything else here... - $c->stash( success => $c->l("$thispanel successfull message")); + if ($trt eq 'PARAMS'){ + #do whatever is required ... + $ret = perform_PARAMS(\%nfs_data); + if ($ret ne "ok") { + # return to the panel with error message + $c->stash(error => $c->l($ret)); + $c->render("Nfsshare"); + } else { + $c->stash( success => $c->l("PARAMS panel action was successfull")); #A bit bland - edit it in the lex file + } + } + + if ($trt eq 'TABLE'){ + #do whatever is required ... + $ret = perform_TABLE(\%nfs_data); + if ($ret ne "ok") { + # return to the panel with error message + $c->stash(error => $c->l($ret)); + $c->render("Nfsshare"); + } else { + $c->stash( success => $c->l("TABLE panel action was successfull")); #A bit bland - edit it in the lex file + } + } + + # and call any signal-events needed + + + # Setup shared data and call panel $c->stash( title => $title, nfs_data => \%nfs_data - # Extra data in here - repeat for each stash data entry needed for panels ); - nfs_data{'trt'} = 'TABLE'; + if ('none' eq 'none') { + $nfs_data{'trt'} = 'TABLE'; + } else { + $nfs_data{'trt'} = 'none'; + } $c->render("Nfsshare"); - } + } } +sub do_display { +# +# Return after link clicked in table (this is a get) - route is "/d" +# Expects ?trt=PANEL&selected="TableRowName" plus any other required +# +#load up all supplied params into prefix_data hash +#call get-selected-PANEL() - returns hash of all relevent parameters +#load up returned hash into prefix_data +#render - to called panel + + my $c = shift; + $c->app->log->info($c->log_req); + + my %nfs_data = (); + my $title = $c->l("nfs_NFS data share"); + + # Accessing all POST parameters + my %params = $c->req->params->to_hash; + + # Get number of POST parameters + my $num_params = keys %params; + + #Params are available in the hash "params" - copy to the prefix_data hash + while (my ($key, $value) = each %{$c->req->params->to_hash}) { + $nfs_data{$key} = $value; + } + + # the value of trt will tell you which panel has returned + my $trt = $c->param('trt') || 'TABLE'; #Indicates where to go now + + # Now add in the params from the selected row from the table + my %selectedrow; + + if ($trt eq 'PARAMS'){ + #Validate form parameters for panel PARAMS + %selectedrow = selected_PARAMS($nfs_data{'Selected'}); + } + + if ($trt eq 'TABLE'){ + #Validate form parameters for panel TABLE + %selectedrow = selected_TABLE($nfs_data{'Selected'}); + } + + + #Copy in the selected row params to the prefix_data hash to pass to the panel + while (my ($key, $value) = each %selectedrow){ + $nfs_data{$key} = $value; + } + # Where to go now + $nfs_data{'trt'} = $trt; + + # Data for panel + $c->stash( + title => $title, + nfs_data => \%nfs_data + ); + $c->render("Nfsshare"); +} 1; diff --git a/Targets/_nfs_PARAMS.html.ep b/Targets/_nfs_PARAMS.html.ep index 2d3c469..faba353 100644 --- a/Targets/_nfs_PARAMS.html.ep +++ b/Targets/_nfs_PARAMS.html.ep @@ -1,3 +1,6 @@ +%# +%# Generated by SME2Gen version:0.6 Chameleon version:4.5.4 On Python:3.10.12 at 2024-04-28 11:53 +%#