More sort routes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package SrvMngr::Controller::${PackageName};
|
||||
#
|
||||
# Generated by SM2Gen version:${version}
|
||||
# Generated by version:${version}
|
||||
#
|
||||
#----------------------------------------------------------------------
|
||||
# heading : ${MenuHeading}
|
||||
@@ -8,44 +8,18 @@ package SrvMngr::Controller::${PackageName};
|
||||
# navigation : ${MenuNavigation}
|
||||
#
|
||||
# name : ${lcPackageName}, method : get, url : /${lcPackageName}, ctlact : ${lcPackageName}#main
|
||||
# name : ${lcPackageName}d, method : post, url : /${lcPackageName}d, ctlact : ${lcPackageName}#do_update
|
||||
# name : ${lcPackageName}u, method : post, url : /${lcPackageName}u, ctlact : ${lcPackageName}#do_update
|
||||
# name : ${lcPackageName}d, method : get, url : /${lcPackageName}d, ctlact : ${lcPackageName}#do_display
|
||||
#
|
||||
# routes : end
|
||||
#
|
||||
# Documentation: https://wiki.contribs.org/{PackageName}
|
||||
# Documentation: https://wiki.contribs.org/${PackageName}
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
#
|
||||
# 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-<whatever>-update?)
|
||||
# set success
|
||||
# call main?
|
||||
|
||||
# TBA!!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
@@ -78,6 +52,16 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
|
||||
require '/usr/share/smanager/lib/SrvMngr/Controller/${PackageName}-Custom.pm'; #The code that is to be added by the developer
|
||||
|
||||
sub main {
|
||||
#
|
||||
# Initial entry - route is "/<whatever>"
|
||||
#
|
||||
#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 );
|
||||
@@ -89,13 +73,14 @@ sub main {
|
||||
$$${prefix}_data{'trt'} = '${firstPanel}';
|
||||
|
||||
#Load any DB entries into the <prefix>_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 = $$${controldb | db | 'cdb'}; #pickup local or global db or Default to config
|
||||
<tal:block tal:repeat="dbentry dbentries">$$${prefix}_data{${dbentry}} = $db->prop('${dbentry}') || ${dbdefault};
|
||||
<tal:block tal:repeat="dbentry dbentries">
|
||||
$$${prefix}_data{${dbentry}} = $db->prop('${dbentry}') || ${dbdefault | ""} || "";
|
||||
</tal:block>
|
||||
|
||||
# and table control fields
|
||||
<tal:block tal:repeat="tablecontrol tablecontrols"> $c->stash(${tablecontrol}=>get_${tablecontrol}());
|
||||
<tal:block tal:repeat="tablecontrol tablecontrols"> $c->stash(${tablecontrol}=>get_${tablecontrol}($c));
|
||||
</tal:block>
|
||||
|
||||
$c->stash(
|
||||
@@ -106,7 +91,32 @@ sub main {
|
||||
$c->render( template => "${PackageName}" );
|
||||
}
|
||||
|
||||
# Post request with params - submit from a form
|
||||
sub do_update {
|
||||
#
|
||||
# Return after submit pushed on panel (this is a post) - route is "/<whatever>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-<whatever>-update exists
|
||||
#signal_event smeserver-<whatever>-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);
|
||||
|
||||
@@ -119,46 +129,114 @@ 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}) {
|
||||
$$${prefix}_data{$key} = $value;
|
||||
}
|
||||
|
||||
# the value of trt will tell you which panel has returned
|
||||
my $trt = $c->param('trt') || '${firstPanel}' ; #hidden control on every form.
|
||||
my $trt = $c->param('trt') || '${firstPanel}'; #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;
|
||||
<tal:block tal:repeat="panel panels">
|
||||
if ($trt eq '${panel}'){
|
||||
#Validate form parameters for panel ${panel}
|
||||
$ret = validate_${panel}();
|
||||
$ret = validate_${panel}(\%${prefix}_data);
|
||||
$thispanel = '${panel}';
|
||||
}
|
||||
</tal:block>
|
||||
if ($ret eq "ok") {
|
||||
|
||||
if ($ret ne "ok") {
|
||||
# return to the panel with error message
|
||||
$c->stash(error => $c->l($ret));
|
||||
$c->render("${PackageName}");
|
||||
} else {
|
||||
#Do whatever is needed, including writing values to the DB
|
||||
my $db = $$${controldb | db | 'cdb'}; #pickup local or global db or Default to config
|
||||
<tal:block tal:repeat="dbentry dbentries">
|
||||
$db->set_prop('${dbentry}'=> param{'${dbentry}'}; #Copy back into db
|
||||
$$${prefix}_data{${dbentry}} = $db->prop('${dbentry}'); #Copy out into stash
|
||||
<tal:block tal:repeat="panel panels">
|
||||
if ($trt eq '${panel}'){
|
||||
#do whatever is required ...
|
||||
$ret = perform_${panel}(\%${prefix}_data);
|
||||
if ($ret ne "ok") {
|
||||
# return to the panel with error message
|
||||
$c->stash(error => $c->l($ret));
|
||||
$c->render("${PackageName}");
|
||||
} else {
|
||||
$c->stash( success => $c->l("${panel} panel action was successfull")); #A bit bland - edit it in the lex file
|
||||
}
|
||||
}
|
||||
</tal:block>
|
||||
# anything else here...
|
||||
$c->stash( success => $c->l("$thispanel successfull message"));
|
||||
# and call any signal-events needed
|
||||
|
||||
|
||||
# Setup shared data and call panel
|
||||
$c->stash(
|
||||
title => $title,
|
||||
${prefix}_data => \%${prefix}_data
|
||||
# Extra data in here - repeat for each stash data entry needed for panels
|
||||
);
|
||||
${prefix}_data{'trt'} = '${firstPanel}';
|
||||
if ('${nextpanel | "none"}' eq 'none') {
|
||||
$$${prefix}_data{'trt'} = '${firstPanel}';
|
||||
} else {
|
||||
$$${prefix}_data{'trt'} = '${NextPanel | "none"}';
|
||||
}
|
||||
$c->render("${PackageName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub do_display {
|
||||
#
|
||||
# Return after link clicked in table (this is a get) - route is "/<whatever>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 %${prefix}_data = ();
|
||||
my $title = $c->l("${prefix}_${MenuDescription}");
|
||||
|
||||
# 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}) {
|
||||
$$${prefix}_data{$key} = $value;
|
||||
}
|
||||
|
||||
# the value of trt will tell you which panel has returned
|
||||
my $trt = $c->param('trt') || '${firstPanel}'; #Indicates where to go now
|
||||
|
||||
# Now add in the params from the selected row from the table
|
||||
my %selectedrow;
|
||||
<tal:block tal:repeat="panel panels">
|
||||
if ($trt eq '${panel}'){
|
||||
#Validate form parameters for panel ${panel}
|
||||
%selectedrow = selected_${panel}($$${prefix}_data{'Selected'});
|
||||
}
|
||||
</tal:block>
|
||||
|
||||
#Copy in the selected row params to the prefix_data hash to pass to the panel
|
||||
while (my ($key, $value) = each %selectedrow){
|
||||
$$${prefix}_data{$key} = $value;
|
||||
}
|
||||
# Where to go now
|
||||
$$${prefix}_data{'trt'} = $trt;
|
||||
|
||||
# Data for panel
|
||||
$c->stash(
|
||||
title => $title,
|
||||
${prefix}_data => \%${prefix}_data
|
||||
);
|
||||
$c->render("${PackageName}");
|
||||
}
|
||||
1;
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user