Table display working - added custom controller file

This commit is contained in:
2024-04-25 16:23:07 +01:00
parent 9840d4171e
commit ec2ec1915e
10 changed files with 338 additions and 126 deletions

View File

@@ -0,0 +1,59 @@
#
# 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;
use esmith::util;
use esmith::HostsDB;
use esmith::AccountsDB;
use esmith::NetworksDB;
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");
# Validation routines - parameters for each panel
sub validate_PARAMS {
$ret = 'ok';
return $ret;
}
sub validate_TABLE {
$ret = 'ok';
return $ret;
}
# 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);
}
return \@res
}
1;

View File

@@ -13,6 +13,38 @@ package SrvMngr::Controller::Nfsshare;
# 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?
use strict;
use warnings;
use Mojo::Base 'Mojolicious::Controller';
@@ -41,6 +73,8 @@ 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/Nfsshare-Custom.pm'; #The code that is to be added by the developer
sub main {
my $c = shift;
@@ -50,13 +84,17 @@ sub main {
my $title = $c->l("nfs_NFS data share");
my $modul = '';
$nfs_data{trt} = 'TABLE';
$nfs_data{'trt'} = 'TABLE';
#Load any DB entries into the <prefix>_data area so as they are preset in the form
# which DB
my $db = $cdb; #Default to config
my $db = $cdb; #pickup local or global db or Default to config
# and table control fields
$c->stash(ibays=>get_ibays());
$c->stash(
title => $title,
modul => $modul,
@@ -80,8 +118,10 @@ sub do_update {
#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");
}
@@ -89,48 +129,36 @@ sub do_update {
my $trt = $c->param('trt') || 'TABLE' ; #hidden control on every form.
my $ret = 'ok';
#Validate the parameters accordingly
my $thispanel;
if ($trt eq 'PARAMS'){
#Validate form parameters for panel PARAMS
# and set $ret = $c->l('Error message') if invalid'
# otherwise set $ret to "ok"
if ($ret ne "ok"){
$c->stash(error => $c->l($ret))
} else {
#Do whatever is needed, including writing values to the DB
my $db = $cdb; #Default to config
} $c->stash( success => $c->l('ok message'))
}
if ($trt eq 'PARAMS'){
#Validate form parameters for panel PARAMS
$ret = validate_PARAMS();
$thispanel = 'PARAMS';
}
if ($trt eq 'TABLE'){
#Validate form parameters for panel TABLE
# and set $ret = $c->l('Error message') if invalid'
# otherwise set $ret to "ok"
if ($ret ne "ok"){
$c->stash(error => $c->l($ret))
} else {
#Do whatever is needed, including writing values to the DB
my $db = $cdb; #Default to config
} $c->stash( success => $c->l('ok message'))
}
if ($trt eq 'TABLE'){
#Validate form parameters for panel TABLE
$ret = validate_TABLE();
$thispanel = 'TABLE';
}
# set nfs_data{trt} = <route>;
$c->stash(
title => $title,
nfs_data => \%nfs_data
# Extra data in here - repeat for each stash data entry needed for panels
);
$c->render("Nfsshare")
if ($ret eq "ok") {
#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"));
$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';
$c->render("Nfsshare");
}
}
# get routines for the stash contents here.
1;

View File

@@ -17,20 +17,20 @@
<table class="sme-border TableSort">
<thead>
<tr>
<td>Name</td>
<td>Description</td>
<td>Nfs status</td>
<td>Action</td>
<th class='sme-border'>Name</th>
<th class='sme-border'>Description</th>
<th class='sme-border'>Nfs status</th>
<th class='sme-border'>Action</th>
</tr>
</thead>
<tbody>
% my $control_data = $self->stash('ibays');
% foreach my $row (@$control_data) {
<tr>
<td><%=$row->Name%></td>
<td><%=$row->Description%></td>
<td><%=$row->flag%></td>
<td><%=$row->PARAMS%></td>
<td class='sme-border'><%=$row->{Name}%></td>
<td class='sme-border'><%=$row->{Description}%></td>
<td class='sme-border'><%=$row->{flag}%></td>
<td class='sme-border'><%=$row->{PARAMS}%></td>
</tr>
%}
</tbody>

View File

@@ -1,23 +1,22 @@
'nfs_Set the UID.' => 'Set the UID.'
'nfs_Requests on secure ports' => 'Requests on secure ports'
'nfs_These parameters will be effective only if the share is enabled. The share is in /home/e-smith/files/ibays//files' => 'These parameters will be effective only if the share is enabled. The share is in /home/e-smith/files/ibays//files'
'nfs_Delays the disk writing' => 'Delays the disk writing'
'nfs_Information Bay name' => 'Information Bay name'
'nfs_EnableShare on local network' => 'EnableShare on local network'
'nfs_For writing permissions,allowing the root user and using insecure ports, you must configure a list of one IP per line, being part of the local network(s).' => 'For writing permissions,allowing the root user and using insecure ports, you must configure a list of one IP per line, being part of the local network(s).'
'nfs Hello TABLE' => 'Hello TABLE'
'nfs_NFS Client(s) allowed' => 'NFS Client(s) allowed'
'nfs_Error message' => 'Error message'
'nfs_Browse the parent folders' => 'Browse the parent folders'
'nfs_APPLY' => 'APPLY'
'nfs_Save' => 'Save'
'nfs_Share owner Group' => 'Share owner Group'
'nfs_File system permissions' => 'File system permissions'
'nfs_Set the uid and gid if you want all requests appear to be from one user or one group, otherwise leave blank' => 'Set the uid and gid if you want all requests appear to be from one user or one group, otherwise leave blank'
'nfs_Enable the NFS Share' => 'Enable the NFS Share'
'nfs_Write (a)synchronously' => 'Write (a)synchronously'
'nfs_ok message' => 'ok message'
'nfs Hello PARAMS' => 'Hello PARAMS'
'nfs_Set the GID.' => 'Set the GID.'
'nfs_Squash the power of users' => 'Squash the power of users'
'nfs_$thispanel successfull message' => '$thispanel successfull message'
'nfs Hello TABLE' => 'Hello TABLE'
'nfs_Set the UID.' => 'Set the UID.'
'nfs_NFS Client(s) allowed' => 'NFS Client(s) allowed'
'nfs Hello PARAMS' => 'Hello PARAMS'
'nfs_Save' => 'Save'
'nfs_Set the uid and gid if you want all requests appear to be from one user or one group, otherwise leave blank' => 'Set the uid and gid if you want all requests appear to be from one user or one group, otherwise leave blank'
'nfs_EnableShare on local network' => 'EnableShare on local network'
'nfs_Set the GID.' => 'Set the GID.'
'nfs_APPLY' => 'APPLY'
'nfs_NFS data share' => 'NFS data share'
'nfs_File system permissions' => 'File system permissions'
'nfs_Requests on secure ports' => 'Requests on secure ports'
'nfs_Write (a)synchronously' => 'Write (a)synchronously'
'nfs_Delays the disk writing' => 'Delays the disk writing'
'nfs_Enable the NFS Share' => 'Enable the NFS Share'
'nfs_Browse the parent folders' => 'Browse the parent folders'
'nfs_Information Bay name' => 'Information Bay name'