Add Table creation code

This commit is contained in:
Brian Read 2024-04-24 16:09:23 +01:00
parent 2d3fabcc5b
commit 9840d4171e
8 changed files with 174 additions and 73 deletions

View File

@ -35,11 +35,11 @@ use esmith::DomainsDB;
#The most common ones
our $db = esmith::ConfigDB->open() || die("Couldn't open config db");
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");
our $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
sub main {
@ -50,7 +50,12 @@ sub main {
my $title = $c->l("nfs_NFS data share");
my $modul = '';
$nfs_data{trt} = 'PARAMS';
$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
$c->stash(
title => $title,
@ -81,28 +86,38 @@ sub do_update {
}
# the value of trt will tell you which panel has returned
my $trt = $c->param('trt') || 'PARAMS' ; #hidden control on every form.
my $trt = $c->param('trt') || 'TABLE' ; #hidden control on every form.
my $ret = 'ok';
#Validate the parameters accordingly
if ($trt eq 'PARAMS'){
#Validate for panel PARAMS
# set $ret = $c->l('Error message') if invalid'
#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 'TABLE'){
#Validate for panel TABLE
# set $ret = $c->l('Error message') if invalid'
#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 ($ret ne "ok"){
$c->stash(error => $c->l($ret))
} else {
$c->stash( success => $c->l('ok message'))
}
if ($ret eq 'ok'){
#Do whatever
}
# set nfs_data{trt} = <route>;
$c->stash(
title => $title,

View File

@ -13,7 +13,11 @@
% param 'trt' => $nfs_data->{trt} unless param 'trt';
%= hidden_field 'trt' => $nfs_data->{trt}
%# Inputs etc in here.
<h2>Manage NFS Ibay settings:</h2><p>These parameters will be effective only if the share is enabled. The share is in /home/e-smith/files/ibays/$(STASH:ibayname)/files</p>
<h2>Manage NFS Ibay settings:</h2>
<p>
%= l('nfs_These parameters will be effective only if the share is enabled. The share is in /home/e-smith/files/ibays//files')
</p>
<p><span class=label>
%=l('nfs_Information Bay name'), class => 'label'
</span><span class=data>
@ -43,7 +47,11 @@
% param 'ShareOnLocalNetwork' => $nfs_data->{ShareOnLocalNetwork} unless param 'ShareOnLocalNetwork';
%= select_field 'ShareOnLocalNetwork' => @ShareOnLocalNetwork_options, class => 'input'
<br></span> </p>
<p>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).</p>
<p>
%= l('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).')
</p>
<span class=label>
%=l('nfs_NFS Client(s) allowed')
</span><span class=data>
@ -60,7 +68,7 @@
<br></span> </p>
<p><span class=label>
%=l('nfs_Write (a)synchronously.')
%=l('nfs_Write (a)synchronously')
</span><span class=data>
% my @WriteAsync_options = ['Synchronous', 'Asynchronous'];
% param 'WriteAsync' => $nfs_data->{WriteAsync} unless param 'WriteAsync';
@ -68,7 +76,7 @@
<br></span> </p>
<p><span class=label>
%=l('nfs_Delays the disk writings.')
%=l('nfs_Delays the disk writing')
</span><span class=data>
% my @DelayWrite_options = ['Write delay', 'No write delay'];
% param 'DelayWrite' => $nfs_data->{DelayWrite} unless param 'DelayWrite';
@ -76,7 +84,7 @@
<br></span> </p>
<p><span class=label>
%=l('nfs_Squash the power of users.')
%=l('nfs_Squash the power of users')
</span><span class=data>
% my @Squash_options = ['All users squash', 'No root squash', 'root squash'];
% param 'Squash' => $nfs_data->{Squash} unless param 'Squash';
@ -92,13 +100,17 @@
<br></span> </p>
<p><span class=label>
%=l('nfs_Requests on secure ports.')
%=l('nfs_Requests on secure ports')
</span><span class=data>
% my @SecurePorts_options = ['Secure', 'Insecure'];
% param 'SecurePorts' => $nfs_data->{SecurePorts} unless param 'SecurePorts';
%= select_field 'SecurePorts' => @SecurePorts_options, class => 'input'
<br></span> </p>
<p>Set the uid and gid if you want all requests appear to be from one user or one group, otherwise leave blank.</p>
<p>
%= l('nfs_Set the uid and gid if you want all requests appear to be from one user or one group, otherwise leave blank')
</p>
<p><span class=label>
%=l('nfs_Set the UID.')
</span><span class=data>

View File

@ -13,6 +13,29 @@
% param 'trt' => $nfs_data->{trt} unless param 'trt';
%= hidden_field 'trt' => $nfs_data->{trt}
%# Inputs etc in here.
<h2>Manage NFS Ibay settings:</h2>
<table class="sme-border TableSort">
<thead>
<tr>
<td>Name</td>
<td>Description</td>
<td>Nfs status</td>
<td>Action</td>
</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>
</tr>
%}
</tbody>
</table>
%# Probably finally by a submit.
% end

View File

@ -1,20 +1,23 @@
'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_Squash the power of users.' => 'Squash the power of users.'
'nfs Hello PARAMS' => 'Hello PARAMS'
'nfs_Requests on secure ports.' => 'Requests on secure ports.'
'nfs_Error message' => 'Error message'
'nfs_Enable the NFS Share' => 'Enable the NFS Share'
'nfs_NFS data share' => 'NFS data share'
'nfs_Delays the disk writings.' => 'Delays the disk writings.'
'nfs_Browse the parent folders' => 'Browse the parent folders'
'nfs_Write (a)synchronously.' => 'Write (a)synchronously.'
'nfs_NFS Client(s) allowed' => 'NFS Client(s) allowed'
'nfs_EnableShare on local network' => 'EnableShare on local network'
'nfs_Information Bay name' => 'Information Bay name'
'nfs_ok message' => 'ok message'
'nfs_Set the GID.' => 'Set the GID.'
'nfs_Share owner Group' => 'Share owner Group'
'nfs Hello TABLE' => 'Hello TABLE'
'nfs_Set the UID.' => 'Set the UID.'
'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_NFS data share' => 'NFS data share'

View File

@ -35,11 +35,11 @@ use esmith::DomainsDB;
#The most common ones
our $db = esmith::ConfigDB->open() || die("Couldn't open config db");
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");
our $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
sub main {
@ -52,6 +52,13 @@ 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
my $db = $$${db | 'cdb'}; #Default to config
<tal:block tal:repeat="dbentry dbentries">
$$${prefix}_data{${dbentry}} = $db->prop('${dbentry}') || ${dbdefault}
</tal:block>
$c->stash(
title => $title,
modul => $modul,
@ -86,18 +93,22 @@ sub do_update {
#Validate the parameters accordingly
<tal:block tal:repeat="condition conditions">
if ($trt eq '${condition}'){
#Validate for panel ${condition}
# set $ret = $c->l('Error message') if invalid'
#Validate form parameters for panel ${condition}
# 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 = $$${db | 'cdb'}; #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>
} $c->stash( success => $c->l('ok message'))
}
</tal:block>
if ($ret ne "ok"){
$c->stash(error => $c->l($ret))
} else {
$c->stash( success => $c->l('ok message'))
}
if ($ret eq 'ok'){
#Do whatever
}
# set ${prefix}_data{trt} = <route>;
$c->stash(
title => $title,

View File

@ -44,7 +44,12 @@
]]></Textinput>
<SubHeader><![CDATA[<h2>${value}</h2>]]></SubHeader>
<Paragraph><![CDATA[<p>${value}</p>]]></Paragraph>
<Paragraph><![CDATA[
<p>
%= l('${prefix}_${value}')
</p>
]]></Paragraph>
<Submit><![CDATA[
<span class='data'>
@ -92,8 +97,23 @@
]]>
</password>
<Extra6><![CDATA[
<Table><![CDATA[
<table class="sme-border TableSort">
<thead>
<tr><tal:block tal:repeat="ColHead TopHeadings">
<td>${ColHead}</td></tal:block>
</tr>
</thead>
<tbody>
% my $control_data = $self->stash('${Control}');
% foreach my $row (@$control_data) {
<tr><tal:block tal:repeat="ColContent Columns">
<td><%=$row->${ColContent}%></td></tal:block>
</tr>
%}
</tbody>
</table>
]]>
</Extra6>
</Table>
</root>

View File

@ -4,14 +4,14 @@
MenuHeading: 'Network',
MenuDescription: 'NFS data share',
MenuNavigation: '2000 400',
firstPanel: 'PARAMS',
firstPanel: 'TABLE',
html: [
{
Name: 'params',
route: 'PARAMS',
Header: 'NFS Share Contrib',
SubHeader: 'Manage NFS Ibay settings:',
Paragraph1: 'These parameters will be effective only if the share is enabled. The share is in /home/e-smith/files/ibays/$(STASH:ibayname)/files',
Paragraph1: 'These parameters will be effective only if the share is enabled. The share is in /home/e-smith/files/ibays//files',
Input1: {
Name: 'IbayName',
Type: 'Text',
@ -69,7 +69,7 @@
Input7: {
Name: 'WriteAsync',
Type: 'Selection',
Label: 'Write (a)synchronously.',
Label: 'Write (a)synchronously',
Value: [
'Synchronous',
'Asynchronous',
@ -78,7 +78,7 @@
Input8: {
Name: 'DelayWrite',
Type: 'Selection',
Label: 'Delays the disk writings.',
Label: 'Delays the disk writing',
Value: [
'Write delay',
'No write delay',
@ -88,7 +88,7 @@
Input9: {
Name: 'Squash',
Type: 'Selection',
Label: 'Squash the power of users.',
Label: 'Squash the power of users',
Value: [
'All users squash',
'No root squash',
@ -109,14 +109,14 @@
Input11: {
Name: 'SecurePorts',
Type: 'Selection',
Label: 'Requests on secure ports.',
Label: 'Requests on secure ports',
Value: [
'Secure',
'Insecure',
],
Default: 0,
},
Paragraph3: 'Set the uid and gid if you want all requests appear to be from one user or one group, otherwise leave blank.',
Paragraph3: 'Set the uid and gid if you want all requests appear to be from one user or one group, otherwise leave blank',
Input12: {
Name: 'SetUID',
Type: 'Textinput',
@ -130,7 +130,16 @@
Submit: 'Save',
},
{
Name: 'select_ibay',route:"TABLE"
},
],
Name: 'select_ibay',
route:"TABLE",
Header: 'NFS Share Contrib',
SubHeader: 'Manage NFS Ibay settings:',
Table1: {
Type:"Table",
Control:"ibays",
TopHeadings: ['Name','Description','Nfs status', 'Action'],
Columns: ['Name','Description','flag','PARAMS']
}
}
]
}

View File

@ -182,6 +182,8 @@ if __name__ == "__main__":
# Routes for each panel
routes = get_all_routes();
#print(routes)
lc_routes =lc_get_all_routes();
#File names
@ -196,8 +198,9 @@ if __name__ == "__main__":
#Generate controller file
try:
controller_template = PageTemplateFile("Templates/controller.pm.tem")
dbentries = []
try:
controller_perl = controller_template.render(**json5_dict,conditions=routes,lcPackageName=json5_dict['PackageName'].lower())
controller_perl = controller_template.render(dbentries=dbentries,**json5_dict,conditions=routes,lcPackageName=json5_dict['PackageName'].lower())
#print()
#print(controller_perl)
# Map '$ 'to '$' to overcome problem with escaping $ signs
@ -219,7 +222,7 @@ if __name__ == "__main__":
#layout_mojo = layout_mojo.replace("$ ", "$")
with open(layout_file, 'w') as file:
file.write(layout_mojo)
print(f"{layout_file} mojo template generated ok")
print(f"{layout_file} mojo template layout file generated ok")
except Exception as e:
print(f"An chameleon render on layout file error occurred: {e}")
#print()
@ -245,9 +248,9 @@ if __name__ == "__main__":
#partial_mojo_template = partial_mojo_template.replace("$ ", "$")
with open( partial_files[i], 'w') as file:
file.write(partial_mojo_template)
print(f"{partial_files[i]} mojo template generated ok")
print(f"{partial_files[i]} mojo template generated ok - phase 1")
except Exception as e:
print(f"An chameleon render on partial file {html['route']} occurred: {e}")
print(f"An chameleon render error on partial file {html['route']} occurred: {e}")
except Exception as e:
print(f"An chameleon html {html['route']} error occurred: {e}")
@ -264,7 +267,7 @@ if __name__ == "__main__":
try:
control_template = PageTemplate(html_controls[inner_html['Type']])
try:
control_html = control_template.render(**inner_html,prefix=prefix_is)
control_html = control_template.render(**inner_html,prefix=prefix_is) #Contents=Contents,Headings=Headings)
# Map '$ 'to '$' to overcome problem with escaping $ signs
#control_html = control_html.replace("$ ", "$")
# Add in two tabs before each newline
@ -272,6 +275,11 @@ if __name__ == "__main__":
# and an extra tab before each "%"
#control_html = control_html.replace("%", "\t%")
#print(control_html)
# And re-run it if the type is "table"
#if inner_html['Type'] == 'Table'
#Another scan
# print("Another scan for the table")
#Else just move on.
all_controls_html = all_controls_html + control_html
except Exception as e:
print(f"An chameleon render on partial file control {inner_html['Name']} error occurred: {e}")
@ -291,7 +299,7 @@ if __name__ == "__main__":
#simple_control_html = simple_control_html.replace("\n", "\n\t\t")
all_controls_html = all_controls_html + simple_control_html
except Exception as e:
print(f"An chameleon render on partial file control {inner_html['Name']} error occurred: {e}")
print(f"An chameleon render on partial file control {html_control} error occurred: {e}")
except Exception as e:
print(f"An chameleon template partial file control {html_control} error occurred: {e}")