Refactor controller so that it only uses do_display to display panels

This commit is contained in:
Brian Read 2024-11-29 13:02:13 +00:00
parent 9567e6e327
commit 47514f6f28
8 changed files with 50 additions and 93 deletions

View File

@ -1,6 +1,6 @@
package SrvMngr::Controller::Letsencrypt;
#
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-27 16:15:50
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-29 13:00:55
#
#----------------------------------------------------------------------
# heading : Network
@ -43,12 +43,6 @@ use esmith::HostsDB;
use esmith::DomainsDB;
#The most common ones
our $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
our $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
our $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
our $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
require '/usr/share/smanager/lib/SrvMngr/Controller/Letsencrypt-Custom.pm'; #The code that is to be added by the developer
@ -67,6 +61,13 @@ sub main {
my $c = shift;
$c->app->log->info( $c->log_req );
#The most common ones
my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
my $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
my $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
my $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
my $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
my %lets_data = ();
my $title = $c->l('lets_Letsencrypt_certificate');
my $modul = '';
@ -78,25 +79,8 @@ sub main {
my $db = $cdb; #pickup local or global db or Default to config
#pickup any other contents needed and load them into hash shared with panel
my %returned_hash;
# subroutine returns a hash directly
%returned_hash = $c->get_data_for_panel_LIST();
# Copy each key-value pair from the returned hash to the prefix data hash
while (my ($key, $value) = each %returned_hash) {
$lets_data{$key} = $value;
}
# and table control fields
$c->stash(DomainList=>$c->get_DomainList());
$c->do_display($lets_data{'trt'});
$c->stash(
title => $title,
modul => $modul,
lets_data => \%lets_data
);
$c->render( template => "letsencrypt" );
}
# Post request with params - submit from the form
@ -129,6 +113,13 @@ sub do_update {
$c->app->log->info($c->log_req);
my $modul = '';
#The most common ones - you might want to comment out any not used.
my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
my $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
my $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
my $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
my $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
my %lets_data = ();
my $title = $c->l('lets_Letsencrypt_certificate');
@ -182,14 +173,6 @@ sub do_update {
if ($ret ne "ok"){
# lets_data{'trt'} = $thispanel;
# $c->stash(error => $c->l($ret));
# $c->stash(
# title => $title,
# modul => $modul,
# lets_data => \%lets_data
# );
# $c->render( template => "letsencrypt" );
$c->do_display($thispanel);
} else {
#Do whatever is needed, including writing values to the DB
@ -287,12 +270,8 @@ sub do_update {
} else {
$lets_data{'trt'} = 'none';
}
$c->stash(
title => $title,
modul => $modul,
lets_data => \%lets_data
);
$c->render( template => "letsencrypt" );
$c->do_display($lets_data{'trt'});
}
}
@ -310,6 +289,13 @@ sub do_display {
my ($c,$trt) = @_;
$c->app->log->info($c->log_req);
#The most common ones - you might want to comment out any not used.
my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
my $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
my $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
my $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
my $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
my %lets_data = ();
my $title = $c->l('lets_Letsencrypt_certificate');

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-27 16:15:50
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-29 13:00:55
%#
<div id="Letsencrypt-CHECKALLDOMAINS" class="partial Letsencrypt-CHECKALLDOMAINS">
<script>

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-27 16:15:50
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-29 13:00:55
%#
<div id="Letsencrypt-CHECKALLENABLEDDOMAINS" class="partial Letsencrypt-CHECKALLENABLEDDOMAINS">
<script>

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-27 16:15:50
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-29 13:00:55
%#
<div id="Letsencrypt-CHECKONEDOMAIN" class="partial Letsencrypt-CHECKONEDOMAIN">
<script>

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-27 16:15:50
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-29 13:00:55
%#
<div id="Letsencrypt-LIST" class="partial Letsencrypt-LIST">
<script>

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-27 16:15:50
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-29 13:00:55
%#
<div id="Letsencrypt-PARAMS" class="partial Letsencrypt-PARAMS">
<script>

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-27 16:15:50
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-29 13:00:55
%#
% layout 'default', title => "Sme server 2 - Letsencrypt certificate", share_dir => './';
%# css specific to this panel:

View File

@ -62,11 +62,11 @@ sub main {
$c->app->log->info( $c->log_req );
#The most common ones
$cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
$adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
$ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
$hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
$ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
my $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
my $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
my $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
my $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
my %${prefix}_data = ();
my $title = $c->l('${prefix}_${MenuDescription}');
@ -81,25 +81,8 @@ sub main {
$$${prefix}_data{'${dbfield}'} = $db->prop('${dbfield}') || ${dbdefault | ""} || "";
</tal:block>
#pickup any other contents needed and load them into hash shared with panel
my %returned_hash;
# subroutine returns a hash directly
%returned_hash = $c->get_data_for_panel_${firstPanel}();
# Copy each key-value pair from the returned hash to the prefix data hash
while (my ($key, $value) = each %returned_hash) {
$$${prefix}_data{$key} = $value;
}
# and table control fields
<tal:block tal:repeat="tablecontrol tablecontrols">$c->stash(${tablecontrol[0]}=>$c->get_${tablecontrol[0]}());
</tal:block>
$c->do_display($$${prefix}_data{'trt'});
$c->stash(
title => $title,
modul => $modul,
${prefix}_data => \%${prefix}_data
);
$c->render( template => "${lcPackageName}" );
}
# Post request with params - submit from the form
@ -133,11 +116,11 @@ sub do_update {
my $modul = '';
#The most common ones - you might want to comment out any not used.
$cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
$adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
$ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
$hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
$ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
my $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
my $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
my $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
my $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
my %${prefix}_data = ();
my $title = $c->l('${prefix}_${MenuDescription}');
@ -168,14 +151,6 @@ sub do_update {
</tal:block>
if ($ret ne "ok"){
# ${prefix}_data{'trt'} = $thispanel;
# $c->stash(error => $c->l($ret));
# $c->stash(
# title => $title,
# modul => $modul,
# ${prefix}_data => \%${prefix}_data
# );
# $c->render( template => "${lcPackageName}" );
$c->do_display($thispanel);
} else {
#Do whatever is needed, including writing values to the DB
@ -205,12 +180,8 @@ sub do_update {
} else {
$$${prefix}_data{'trt'} = '${NextPanel | "none"}';
}
$c->stash(
title => $title,
modul => $modul,
${prefix}_data => \%${prefix}_data
);
$c->render( template => "${lcPackageName}" );
$c->do_display($$${prefix}_data{'trt'});
}
}
@ -230,11 +201,11 @@ sub do_display {
$c->app->log->info($c->log_req);
#The most common ones - you might want to comment out any not used.
$cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
$adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
$ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
$hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
$ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
my $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
my $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
my $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
my $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
my $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
my %${prefix}_data = ();
my $title = $c->l('${prefix}_${MenuDescription}');
@ -256,7 +227,7 @@ sub do_display {
# the value of trt will tell you which panel has returned
if (! $trt){
my $trt = $c->param('trt') || '${firstPanel}'; #Indicates where to go now
$trt = $c->param('trt') || '${firstPanel}'; #Indicates where to go now
}
# Now add in the params from the selected row from the table