Add in entries for other mojo input tags

This commit is contained in:
Brian Read 2024-09-15 12:06:34 +01:00
parent 3b6e1930a0
commit 4d7cc1f076
18 changed files with 821 additions and 754 deletions

View File

@ -2,7 +2,7 @@
# Routines to be edited by the developer to provide validation for parameters
# and provison of the control data for table(s)
#
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-14 17:41
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-15 12:03
#
use esmith::util;

View File

@ -1,6 +1,6 @@
package SrvMngr::Controller::CreateStarterWebsite;
#
# Generated by version:SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-14 17:41
# Generated by version:SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-15 12:03
#
#----------------------------------------------------------------------
# heading : Miscellaneous

View File

@ -1,5 +1,5 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-13 19:20
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-15 12:03
%#
<div id="CreateStarterWebsite-PARAMS" class="partial CreateStarterWebsite-PARAMS">
<script>
@ -20,8 +20,7 @@
<h2><%=l('csw_Manage_CreateStarterWebsite_settings:')%></h2>
<p>
%= l('To create a simple web page for your company, fill
in the fields below and click onCreate.')
%=l('csw_To_create_a_simple_web')
</p>
<p>
@ -29,39 +28,31 @@
</p>
<p>
%= l('The text that you enter below will be line wrapped
for a nicer appearance in your web page. Leave a blank line
whenever you want to start a new paragraph. If you need
to force a line break without starting a new paragraph (for
example after each line of a mailing address), then type
the four-character sequence')
%=l('csw_The_text_that_you_enter')
</p>
<p>
%= l('Do not use this option if you have already customized your web site, since it will
overwrite the 'index.htm' file in your web site directory.')
%=l('csw_Do_not_use_this_optionif')
</p>
<p><span class=label>
%=l('csw_')
</span><span class=data>
%=
% text_field
</span></p>
<p>
%= l('First header, typically used for short phrases such
as 'Leader in the field of textile manufacturing'')
%=l('csw_First_header,_typically_used_for')
</p>
<p><span class=label>
%=l('csw_')
</span><span class=data>
%=
% text_field
</span></p>
<p>
%= l('Text following first header, typically used for a
paragraph of marketing information.')
%=l('csw_Text_following_first_header,_typically')
</p>
<span class=label>
@ -72,19 +63,17 @@
</span><br>
<p>
%= l('Second header, typically used for short phrases such
as 'For more information' or 'To order our products':')
%=l('csw_Second_header,_typically_used_for')
</p>
<p><span class=label>
%=l('csw_')
</span><span class=data>
%=
% text_field
</span></p>
<p>
%= l('Text following second header, typically used for contact
or ordering information:')
%=l('csw_Text_following_second_header,_typically')
</p>
<span class=label>
@ -95,15 +84,17 @@
</span><br>
<p>
%= l('When you create this web page, the file
'index.htm' will be overwritten
in your web site directory.')
%=l('csw_When_you_create_this_web')
</p>
<p>
%=l('csw_Do_you_wish_to_proceed?')
</p>
<span class='data'>
%= submit_button l('csw_Create'), class => 'action'
</span>
%# Probably finally by a submit.
%end
</div>

View File

@ -1,6 +1,6 @@
% layout 'default', title => "Sme server 2 - Create Starter Website", share_dir => './';
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-14 17:41
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-15 12:03
%#
% content_for 'module' => begin
<div id="module" class="module CreateStarterWebsite-panel">

View File

@ -1,16 +1,17 @@
'csw_Do_not_use_this_optionif' => 'Do not use this optionif you have already customized your web site, Since it will overwrite the \'index. Htm\' file in your web site directory. ',
'csw_Second_header,_typically_used_for' => 'Second header, Typically used for short phrases such as \'For more information\' or \'To order our products\':',
'csw_Text_following_second_header,_typically' => 'Text following second header, Typically used for contact or ordering information:',
'csw_Hello_PARAMS' => 'Hello PARAMS',
'csw_To_create_a_simple_web' => 'To create a simple web page for your company, Fill in the fields below and click onCreate. ',
'csw_PARAMS_panel_action_was_successful' => 'PARAMS panel action was successful',
'csw_Do_you_wish_to_proceed?' => 'Do you wish to proceed?',
'csw_Create' => 'Create',
'csw_When_you_create_this_web' => 'When you create this web page, The file 'index. Htm' will be overwritten in your web site directory. ',
'csw_Manage_CreateStarterWebsite_settings:' => 'Manage CreateStarterWebsite settings:',
'csw_' => '',
'csw_The_text_that_you_enter' => 'The text that you enter below will be line wrapped for a nicer appearance in your web page. Leave a blank line whenever you want to start a new paragraph. If you need to force a line break without starting a new paragraph (for example after each line of a mailing address), Then type the four-character sequence',
'csw_You_can_leave_any_field' => 'You can leave any field blank if you do not need it. ',
'csw_First_header,_typically_used_for' => 'First header, Typically used for short phrases such as 'Leader in the field of textile manufacturing'',
'csw_Text_following_first_header,_typically' => 'Text following first header, Typically used for a paragraph of marketing information. ',
'csw_Do_you_wish_to_proceed?' => 'Do you wish to proceed?',
'csw_Manage_CreateStarterWebsite_settings:' => 'Manage CreateStarterWebsite settings:',
'csw_When_you_create_this_web' => 'When you create this web page, The file \'index. Htm\' will be overwritten in your web site directory. ',
'csw_PARAMS_panel_action_was_successful' => 'PARAMS panel action was successful',
'csw_Do_not_use_this_optionif' => 'Do not use this optionif you have already customized your web site, Since it will overwrite the 'index. Htm' file in your web site directory. ',
'csw_Create_Starter_Website' => 'Create Starter Website',
'csw_First_header,_typically_used_for' => 'First header, Typically used for short phrases such as \'Leader in the field of textile manufacturing\'',
'csw_' => '',
'csw_To_create_a_simple_web' => 'To create a simple web page for your company, Fill in the fields below and click onCreate. ',
'csw_APPLY' => 'Apply',
'csw_Text_following_second_header,_typically' => 'Text following second header, Typically used for contact or ordering information:',
'csw_Second_header,_typically_used_for' => 'Second header, Typically used for short phrases such as 'For more information' or 'To order our products':',

View File

@ -1,96 +0,0 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-14 17:41
%#
<div id="CreateStarterWebsite-PARAMS" class="partial CreateStarterWebsite-PARAMS">
<script>
window.onload = function() {
SelectInput();
};
</script>
<h2>
%= l('csw_Hello_PARAMS');
</h2>
% my $btn = l('csw_APPLY');
%= form_for "CreateStarterWebsited" => (method => 'POST') => begin
% param 'trt' => $csw_data->{trt} unless param 'trt';
%= hidden_field 'trt' => $csw_data->{trt}
%# Inputs etc in here.
<h2><%=l('csw_Manage_CreateStarterWebsite_settings:')%></h2>
<p>
%=l('csw_To_create_a_simple_web')
</p>
<p>
%=l('csw_You_can_leave_any_field')
</p>
<p>
%=l('csw_The_text_that_you_enter')
</p>
<p>
%=l('csw_Do_not_use_this_optionif')
</p>
<p><span class=label>
%=l('csw_')
</span><span class=data>
%=
</span></p>
<p>
%=l('csw_First_header,_typically_used_for')
</p>
<p><span class=label>
%=l('csw_')
</span><span class=data>
%=
</span></p>
<p>
%=l('csw_Text_following_first_header,_typically')
</p>
<span class=label>
%=l('csw_')
</span><span class=data>
% param 'text1' => $csw_data->{text1} unless param 'text1';
%= text_area 'text1', cols=>40, rows=>10
</span><br>
<p>
%=l('csw_Second_header,_typically_used_for')
</p>
<p><span class=label>
%=l('csw_')
</span><span class=data>
%=
</span></p>
<p>
%=l('csw_Text_following_second_header,_typically')
</p>
<span class=label>
%=l('csw_')
</span><span class=data>
% param 'text2' => $csw_data->{text2} unless param 'text2';
%= text_area 'text2', cols=>40, rows=>10
</span><br>
<p>
%=l('csw_When_you_create_this_web')
</p>
<p>
%=l('csw_Do_you_wish_to_proceed?')
</p>
%# Probably finally by a submit.
%end
</div>

View File

@ -2,7 +2,7 @@
# Routines to be edited by the developer to provide validation for parameters
# and provison of the control data for table(s)
#
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-14 12:09
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-15 10:49
#
use esmith::util;
@ -36,7 +36,11 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
# Return an array of hashes of the contents for each row and column for Table1
# default is a single row of strings "col1header-1, col2header-1, col3Header-1 etc"
my $c = shift;
my @ret = {};
my $control_data = $self->stash('Table1');
my @ret = {}
# foreach my $colHead (@$control_data) {
# my ret{$colHead} = "$colhead-1"
# };
return \@ret
}
@ -44,7 +48,11 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
# Return an array of hashes of the contents for each row and column for Table2
# default is a single row of strings "col1header-1, col2header-1, col3Header-1 etc"
my $c = shift;
my @ret = {};
my $control_data = $self->stash('Table2');
my @ret = {}
# foreach my $colHead (@$control_data) {
# my ret{$colHead} = "$colhead-1"
# };
return \@ret
}

View File

@ -2,7 +2,7 @@
# Routines to be edited by the developer to provide validation for parameters
# and provison of the control data for table(s)
#
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-14 11:53
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-15 11:51
#
use esmith::util;
@ -33,14 +33,26 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
# Get control data for tables(s)
sub get_Table1 {
# Return an array of hashes of the contents for each row and column for Table1
# default is a single row of strings "col1header-1, col2header-1, col3Header-1 etc"
my $c = shift;
my @ret = {};
my $control_data = $self->stash('Table1');
my @ret = {}
# foreach my $colHead (@$control_data) {
# my ret{$colHead} = "$colhead-1"
# };
return \@ret
}
sub get_Table2 {
# Return an array of hashes of the contents for each row and column for Table2
# default is a single row of strings "col1header-1, col2header-1, col3Header-1 etc"
my $c = shift;
my @ret = {};
my $control_data = $self->stash('Table2');
my @ret = {}
# foreach my $colHead (@$control_data) {
# my ret{$colHead} = "$colhead-1"
# };
return \@ret
}

View File

@ -1,19 +1,19 @@
package SrvMngr::Controller::Diskusage;
package SrvMngr::Controller::DiskUsage;
#
# Generated by version:SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-14 12:09
# Generated by version:SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-15 11:51
#
#----------------------------------------------------------------------
# heading : Miscellaneous
# description : Disk Usage
# navigation : 2000 400
#
# name : diskusage, method : get, url : /diskusage, ctlact : Diskusage#main
# name : diskusageu, method : post, url : /diskusageu, ctlact : Diskusage#do_update
# name : diskusaged, method : get, url : /diskusaged, ctlact : Diskusage#do_display
# name : diskusage, method : get, url : /diskusage, ctlact : DiskUsage#main
# name : diskusageu, method : post, url : /diskusageu, ctlact : DiskUsage#do_update
# name : diskusaged, method : get, url : /diskusaged, ctlact : DiskUsage#do_display
#
# routes : end
#
# Documentation: https://wiki.contribs.org/Diskusage
# Documentation: https://wiki.contribs.org/DiskUsage
#----------------------------------------------------------------------
#
@ -49,7 +49,7 @@ 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/Diskusage-Custom.pm'; #The code that is to be added by the developer
require '/usr/share/smanager/lib/SrvMngr/Controller/DiskUsage-Custom.pm'; #The code that is to be added by the developer
sub main {
#

View File

@ -1,7 +1,7 @@
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-14 12:09
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-15 11:51
%#
<div id="Diskusage-PARAMS" class="partial Diskusage-PARAMS">
<div id="DiskUsage-PARAMS" class="partial DiskUsage-PARAMS">
<script>
window.onload = function() {
SelectInput();
@ -11,7 +11,7 @@
%= l('du_Hello_PARAMS');
</h2>
% my $btn = l('du_APPLY');
%= form_for "Diskusaged" => (method => 'POST') => begin
%= form_for "DiskUsaged" => (method => 'POST') => begin
% param 'trt' => $du_data->{trt} unless param 'trt';
%= hidden_field 'trt' => $du_data->{trt}
@ -20,7 +20,7 @@
<h2><%=l('du_Manage_DiskUsage_settings:')%></h2>
<p>
%= l('du_&amp;nbsp')
%=l('du_')
</p>
<p>
@ -60,7 +60,7 @@ tmpfs 2.0G 648K 2.0G 1% /run
<p>
%= l('du_&amp;nbsp')
%=l('du_')
</p>
<br /><table class="sme-border TableSort sme-table">

View File

@ -1,9 +1,9 @@
% layout 'default', title => "Sme server 2 - Disk Usage", share_dir => './';
%#
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-14 12:09
%# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-09-15 11:51
%#
% content_for 'module' => begin
<div id="module" class="module Diskusage-panel">
<div id="module" class="module DiskUsage-panel">
% if ($config->{debug} == 1) {
<p>

View File

@ -1,11 +1,11 @@
'du_&amp;nbsp' => '&amp;nbsp',
'du_I-bays' => 'I-bays',
'du_Usage' => 'Usage',
'du_Disk_Usage' => 'Disk Usage',
'du_Path' => 'Path',
'du_Wed_Sep_11_19:01:00_BST' => 'Wed Sep 11 19:01:00 BST 2024',
'du_Users' => 'Users',
'du_APPLY' => 'Apply',
'du_Hello_PARAMS' => 'Hello PARAMS',
'du_' => '',
'du_Manage_DiskUsage_settings:' => 'Manage DiskUsage settings:',
'du_PARAMS_panel_action_was_successful' => 'PARAMS panel action was successful',
'du_Wed_Sep_11_19:01:00_BST' => 'Wed Sep 11 19:01:00 BST 2024',
'du_Path' => 'Path',
'du_I-bays' => 'I-bays',
'du_Hello_PARAMS' => 'Hello PARAMS',
'du_Usage' => 'Usage',
'du_Users' => 'Users',
'du_Disk_Usage' => 'Disk Usage',
'du_APPLY' => 'Apply',

View File

@ -36,7 +36,7 @@ our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
# Return an array of hashes of the contents for each row and column for ${tablecontrol}
# default is a single row of strings "col1header-1, col2header-1, col3Header-1 etc"
my $c = shift;
my $control_data = $self->stash('${TableControl}');
my $control_data = $self->stash('${tablecontrol}');
my @ret = {}
# foreach my $colHead (@$control_data) {
# my ret{$colHead} = "$colhead-1"

View File

@ -3,7 +3,7 @@
<p><span class=label>
%=l('${prefix}_${Label}')
</span><span class=data>
%= ${Value}
% text_field ${Value}
</span></p>
]]></Text>
@ -17,6 +17,8 @@
<br></span> </p>
]]></Selection>
<Textarea><![CDATA[
<span class=label>
%=l('${prefix}_${Label}')
@ -34,6 +36,15 @@
</span><br>
]]></Date>
<Time><![CDATA[
<span class=label>
%=l('${prefix}_${Label}')
</span><span class=data>
%=time_field '${Name}' =>$$${Name}, pattern=>${regexp | .*}
</span><br>
]]></Time>
<Textinput><![CDATA[
<p><span class=label>
%=l('${prefix}_${Label}')
@ -55,7 +66,7 @@
<Submit><![CDATA[
<span class='data'>
%= submit_button l('${value}'), class => 'action'
%= submit_button l('${Value}'), class => 'action'
</span>]]>
</Submit>
@ -63,6 +74,8 @@
<p><span class=label>
%=l('${prefix}_${Label}')
</span><span class=data>
%=Search field
%=search field
</span>span></p>
]]>
</search>
@ -71,6 +84,7 @@
<p><span class=label>
%=l('${Label}')
</span><span class=data>
%=URL field
</span>span></p>
]]>
</url>
@ -79,6 +93,7 @@
<p><span class=label>
%=l('${Label}')
</span><span class=data>
%=tel field
</span>span></p>
]]>
</tel>
@ -87,6 +102,7 @@
<p><span class=label>
%=l('${Label}')
</span><span class=data>
%=email field
</span>span></p>
]]>
</email>
@ -95,10 +111,92 @@
<p><span class='label'>
%=l('${Label}')
</span><span class=data>
%=password field
</span>span></p>
]]>
</password>
<timedate><![CDATA[
<p><span class='label'>
%=l('${Label}')
</span><span class=data>
%=timedate field
</span>span></p>
]]>
</timedate>
<week><![CDATA[
<p><span class='label'>
%=l('${Label}')
</span><span class=data>
%=week field
</span>span></p>
]]>
</week>
<month><![CDATA[
<p><span class='label'>
%=l('${Label}')
</span><span class=data>
%=month field
</span>span></p>
]]>
</month>
<range><![CDATA[
<p><span class='label'>
%=l('${Label}')
</span><span class=data>
%=range field
</span>span></p>
]]>
</range>
<radio><![CDATA[
<p><span class='label'>
%=l('${Label}')
</span><span class=data>
%=radio field
</span>span></p>
]]>
</radio>
<number><![CDATA[
<p><span class='label'>
%=l('${Label}')
</span><span class=data>
%=number field
</span>span></p>
]]>
</number>
<file><![CDATA[
<p><span class='label'>
%=l('${Label}')
</span><span class=data>
%=file field
</span>span></p>
]]>
</file>
<color><![CDATA[
<p><span class='label'>
%=l('${Label}')
</span><span class=data>
%=color field
</span>span></p>
]]>
</color>
<checkbox><![CDATA[
<p><span class='label'>
%=l('${Label}')
</span><span class=data>
%=checkbox field
</span>span></p>
]]>
</checkbox>
<Table><![CDATA[
<br /><table class="sme-border TableSort sme-table">
<thead>
@ -125,11 +223,5 @@
]]>
</Preformatted>
<submit><![CDATA[
<p> <br>
%= submit_button "${Value}", class => 'action'
</p>
]]>
</submit>
</root>

View File

@ -6,7 +6,8 @@
'MenuNavigation': '2000 400',
'firstPanel': 'PARAMS',
'signalEvent': 'smeserver-createstarterwebsite-update',
'html':[ {
'html': [
{
'Name': 'params',
'route': 'PARAMS',
'Header': 'Create a starter website',
@ -14,14 +15,14 @@
'Paragraph1': 'To create a simple web page for your company, fill in the fields below and click onCreate.',
'Paragraph2': 'You can leave any field blank if you do not need it.',
'Paragraph3': 'The text that you enter below will be line wrapped for a nicer appearance in your web page. Leave a blank line whenever you want to start a new paragraph. If you need to force a line break without starting a new paragraph (for example after each line of a mailing address), then type the four-character sequence',
'Paragraph4': 'Do not use this optionif you have already customized your web site, since it will overwrite the index.htm file in your web site directory.',
'Paragraph4': 'Do not use this optionif you have already customized your web site, since it will overwrite the \'index.htm\' file in your web site directory.',
'Input1': {
'Type': 'Text',
'Value': '',
'Name': 'companyName',
'Label': null
},
'Paragraph5': 'First header, typically used for short phrases such as Leader in the field of textile manufacturing',
'Paragraph5': 'First header, typically used for short phrases such as \'Leader in the field of textile manufacturing\'',
'Input2': {
'Type': 'Text',
'Value': '',
@ -35,7 +36,7 @@
'Name': 'text1',
'Label': null
},
'Paragraph7': 'Second header, typically used for short phrases such as For more information or To order our products:',
'Paragraph7': 'Second header, typically used for short phrases such as \'For more information\' or \'To order our products\':',
'Input4': {
'Type': 'Text',
'Value': '',
@ -49,7 +50,7 @@
'Name': 'text2',
'Label': null
},
'Paragraph9': 'When you create this web page, the file index.htm will be overwritten in your web site directory.',
'Paragraph9': 'When you create this web page, the file \'index.htm\' will be overwritten in your web site directory.',
'Paragraph10': 'Do you wish to proceed?',
'Input6': {
'Type': 'Submit',

View File

@ -1,47 +1,49 @@
{
PackageName: 'Diskusage',
prefix: 'du',
MenuHeading: 'Miscellaneous',
MenuDescription: 'Disk Usage',
MenuNavigation: '2000 400',
firstPanel: 'PARAMS',
signalEvent: 'smeserver-diskusage-update',
html: [{
Name: 'params',
route: 'PARAMS',
Header: 'Disk usage',
SubHeader: 'Manage DiskUsage settings:',
Paragraph1: '&nbsp',
Paragraph2: 'Wed Sep 11 19:01:00 BST 2024',
Preformatted1: 'Filesystem Size Used Avail Use% Mounted on\n/dev/mapper/main-root 29G 4.8G 24G 17% /\ndevtmpfs 2.0G 0 2.0G 0% /dev\ntmpfs 2.0G 12K 2.0G 1% /dev/shm\ntmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup\ntmpfs 2.0G 648K 2.0G 1% /run\n/dev/sda1 497M 111M 386M 23% /boot',
Table1: {
Type: 'Table',
TableControl: 'Table1',
TopHeadings: [
'PackageName': 'DiskUsage',
'prefix': 'du',
'MenuHeading': 'Miscellaneous',
'MenuDescription': 'Disk Usage',
'MenuNavigation': '2000 400',
'firstPanel': 'PARAMS',
'signalEvent': 'smeserver-diskusage-update',
'html': [
{
'Name': 'params',
'route': 'PARAMS',
'Header': 'Disk usage',
'SubHeader': 'Manage DiskUsage settings:',
'Paragraph1': '',
'Paragraph2': 'Wed Sep 11 19:01:00 BST 2024',
'Preformatted1': 'Filesystem Size Used Avail Use% Mounted on\n/dev/mapper/main-root 29G 4.8G 24G 17% /\ndevtmpfs 2.0G 0 2.0G 0% /dev\ntmpfs 2.0G 12K 2.0G 1% /dev/shm\ntmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup\ntmpfs 2.0G 648K 2.0G 1% /run\n/dev/sda1 497M 111M 386M 23% /boot',
'Table1': {
'Type': 'Table',
'TableControl': 'Table1',
'TopHeadings': [
'I-bays',
'Usage',
'Path'
],
Columns: [
'Columns': [
'Table1-I-bays',
'Table1-Usage',
'Table1-Path'
]
},
Paragraph3: '&nbsp',
Table2: {
Type: 'Table',
TableControl: 'Table2',
TopHeadings: [
'Paragraph3': '',
'Table2': {
'Type': 'Table',
'TableControl': 'Table2',
'TopHeadings': [
'Users',
'Usage',
'Path'
],
Columns: [
'Columns': [
'Table2-Users',
'Table2-Usage',
'Table2-Path'
]
}
}]
}
]
}

View File

@ -3,12 +3,16 @@ import os
import re
from bs4 import BeautifulSoup
from lxml import etree # Import lxml for HTML validation
import html
import argparse
def read_html_file(filename):
"""Read HTML content from a file."""
with open(filename, 'r', encoding='utf-8') as file:
with open(filename, "r", encoding="utf-8") as file:
return file.read()
def validate_html(html):
"""Validate the HTML content."""
try:
@ -17,13 +21,19 @@ def validate_html(html):
except Exception as e:
raise ValueError("Invalid HTML document") from e
def sanitize_text(text):
# Replace newlines with spaces
sanitized_text = text.replace('\n', ' ').replace('\r', ' ') # Handle both Unix and Windows line endings
decoded_text = html.unescape(text)
sanitized_text = decoded_text.replace("\n", "").replace(
"\r", " "
) # Handle both Unix and Windows line endings
# Replace tabs with spaces
sanitized_text = sanitized_text.replace('\t', ' ')
# Escape quote characters
sanitized_text = sanitized_text.replace('"', '\\"').replace("'", "\\'")
sanitized_text = sanitized_text.replace("\t", "")
# map single quotes to double
sanitized_text = sanitized_text.replace("'", '"')
#Take out any multiple spaces - reduce to one.
sanitized_text = ' '.join(sanitized_text.split())
# Strip leading and trailing whitespace
sanitized_text = sanitized_text.strip()
return sanitized_text
@ -31,15 +41,10 @@ def sanitize_text(text):
def extract_data(html):
"""Extract paragraphs, inputs, tables, and pre blocks from HTML and organize them in order."""
soup = BeautifulSoup(html, 'lxml')
soup = BeautifulSoup(html, "lxml")
records = []
hidden_input_names = [
'page',
'page_stack',
'.id',
'csrf_token'
]
hidden_input_names = ["page", "page_stack", ".id", "csrf_token"]
header_text = None
sub_header_text = None
@ -48,81 +53,81 @@ def extract_data(html):
table_counter = 0
# Extract elements while preserving order
for element in soup.find_all(['h1', 'h2', 'p', 'pre', 'input', 'select', 'textarea', 'button', 'table']):
if element.name == 'h1':
for element in soup.find_all(
["h1", "h2", "p", "pre", "input", "select", "textarea", "button", "table"]
):
if element.name == "h1":
header_text = element.get_text(strip=True)
records.append({
'Type': 'Header',
'Text': header_text
})
records.append({"Type": "Header", "Text": header_text})
elif element.name == 'h2':
elif element.name == "h2":
sub_header_text = element.get_text(strip=True)
records.append({
'Type': 'SubHeader',
'Text': sub_header_text
})
records.append({"Type": "SubHeader", "Text": sub_header_text})
elif element.name == 'p':
elif element.name == "p":
text = element.get_text(strip=True)
if text: # Ignore empty paragraphs
# Sanitise text freom newlines,tabs and escape quotes.
records.append({
'Type': 'Paragraph',
'Text': sanitize_text(text)
})
records.append({"Type": "Paragraph", "Text": sanitize_text(text)})
elif element.name == 'pre':
elif element.name == "pre":
text = element.get_text(strip=True)
if text: # Ensure non-empty before adding
records.append({
'Type': 'Preformatted',
'Text': text
})
records.append({"Type": "Preformatted", "Text": text})
elif element.name == 'input':
if element.get('type') == 'hidden' or element.get('name') in hidden_input_names:
elif element.name == "input":
if (
element.get("type") == "hidden"
or element.get("name") in hidden_input_names
):
continue
input_info = {
'Type': element.get('type', 'text').capitalize(),
'Name': element.get('name'),
'Value': element.get('value', ''),
"Type": element.get("type", "text").capitalize(),
"Name": element.get("name"),
"Value": element.get("value", ""),
}
label = element.find_next('label')
input_info['Label'] = label.get_text(strip=True) if label else None
label = element.find_next("label")
input_info["Label"] = label.get_text(strip=True) if label else None
records.append(input_info)
elif element.name == 'select':
options = [{'Value': option.get('value'), 'Text': option.get_text(strip=True)} for option in element.find_all('option')]
elif element.name == "select":
options = [
{"Value": option.get("value"), "Text": option.get_text(strip=True)}
for option in element.find_all("option")
]
select_info = {
'Type': 'Select',
'Name': element.get('name'),
'Options': options,
'Label': element.find_previous('label').get_text(strip=True) if element.find_previous('label') else None,
"Type": "Select",
"Name": element.get("name"),
"Options": options,
"Label": element.find_previous("label").get_text(strip=True)
if element.find_previous("label")
else None,
}
records.append(select_info)
elif element.name == 'textarea':
elif element.name == "textarea":
textarea_info = {
'Type': 'Textarea',
'Name': element.get('name'),
'Value': element.get_text(strip=True),
"Type": "Textarea",
"Name": element.get("name"),
"Value": element.get_text(strip=True),
}
label = element.find_previous('label')
textarea_info['Label'] = label.get_text(strip=True) if label else None
label = element.find_previous("label")
textarea_info["Label"] = label.get_text(strip=True) if label else None
records.append(textarea_info)
elif element.name == 'button':
elif element.name == "button":
button_info = {
'Type': 'Button',
'Name': element.get('name'),
'Value': element.get_text(strip=True),
'Label': element.find_previous('label').get_text(strip=True) if label else None,
"Type": "Button",
"Name": element.get("name"),
"Value": element.get_text(strip=True),
"Label": element.find_previous("label").get_text(strip=True)
if label
else None,
}
records.append(button_info)
elif element.name == 'table' and 'sme-border' in element.get('class', []):
elif element.name == "table" and "sme-border" in element.get("class", []):
# Increment the table counter
table_counter += 1
@ -132,37 +137,47 @@ def extract_data(html):
columns = []
# Extract headings from the first row
first_row = element.find('tr')
first_row = element.find("tr")
if first_row:
for th in first_row.find_all('th'):
for th in first_row.find_all("th"):
top_headings.append(th.get_text(strip=True))
# Extract only the first data row's cell values for Columns
data_rows = element.find_all('tr')[1:] # Skip the heading row
data_rows = element.find_all("tr")[1:] # Skip the heading row
if data_rows:
first_data_row = data_rows[0] # Take the first row of data
for idx, th in enumerate(first_row.find_all('th')):
td = first_data_row.find_all('td')[idx] if idx < len(first_data_row.find_all('td')) else None
for idx, th in enumerate(first_row.find_all("th")):
td = (
first_data_row.find_all("td")[idx]
if idx < len(first_data_row.find_all("td"))
else None
)
if td:
columns.append(f"{table_control}-{th.get_text(strip=True)}") # Format as desired
columns.append(
f"{table_control}-{th.get_text(strip=True)}"
) # Format as desired
records.append({
'Type': 'Table',
'TableControl': table_control,
'TopHeadings': top_headings,
'Columns': columns,
})
records.append(
{
"Type": "Table",
"TableControl": table_control,
"TopHeadings": top_headings,
"Columns": columns,
}
)
return records, header_text, sub_header_text
def insert_spaces_before_caps(text):
"""Insert spaces before each capital letter in a given string."""
return re.sub(r'(?<!^)(?=[A-Z])', ' ', text)
return re.sub(r"(?<!^)(?=[A-Z])", " ", text)
def save_to_json5(data, output_filename, package_name, header, sub_header):
"""Save extracted data to a JSON5 file with a specific structure."""
# Generate prefix from uppercase letters in PackageName made into lowercase
prefix = ''.join(re.findall(r'[A-Z]', package_name)).lower()
prefix = "".join(re.findall(r"[A-Z]", package_name)).lower()
# Prepare structured html list
structured_html = []
@ -172,81 +187,99 @@ def save_to_json5(data, output_filename, package_name, header, sub_header):
table_count = 1
for record in data:
if record['Type'] == 'Paragraph':
structured_html.append({
f'Paragraph{paragraph_count}': record['Text']
})
if record["Type"] == "Paragraph":
structured_html.append({f"Paragraph{paragraph_count}": record["Text"]})
paragraph_count += 1
elif record['Type'] == 'Preformatted':
structured_html.append({
f'Preformatted{preformatted_count}': record['Text']
})
elif record["Type"] == "Preformatted":
structured_html.append(
{f"Preformatted{preformatted_count}": record["Text"]}
)
preformatted_count += 1
elif record['Type'] == 'Header' or record['Type'] == 'SubHeader':
elif record["Type"] == "Header" or record["Type"] == "SubHeader":
continue # Skip headers for input count
elif record['Type'] == 'Table':
elif record["Type"] == "Table":
# Construct the table entry
table_structure = {
'Type': record['Type'],
'TableControl': record['TableControl'],
'TopHeadings': record['TopHeadings'],
'Columns': record['Columns']
"Type": record["Type"],
"TableControl": record["TableControl"],
"TopHeadings": record["TopHeadings"],
"Columns": record["Columns"],
}
structured_html.append({
f'Table{table_count}': table_structure
})
structured_html.append({f"Table{table_count}": table_structure})
table_count += 1
else: # For inputs, selects, textareas, and buttons
input_structure = {
'Type': record['Type'],
'Value': record.get('Value', ''), # Safely access Value
"Type": record["Type"],
"Value": record.get("Value", ""), # Safely access Value
}
# Use .get() for the Name key to avoid KeyError
input_structure['Name'] = record.get('Name', None) # Set to None if not present
input_structure['Label'] = record.get('Label', None) # Set to None if not present
input_structure["Name"] = record.get(
"Name", None
) # Set to None if not present
input_structure["Label"] = record.get(
"Label", None
) # Set to None if not present
# Handle specific case for Select options
if 'Options' in record:
input_structure['Options'] = record['Options']
if "Options" in record:
input_structure["Options"] = record["Options"]
structured_html.append({
f'Input{input_count}': input_structure
})
structured_html.append({f"Input{input_count}": input_structure})
input_count += 1
# Wrap the records with the required fields
json5_data = {
'PackageName': package_name,
'prefix': prefix,
'MenuHeading': 'Miscellaneous',
'MenuDescription': insert_spaces_before_caps(package_name),
'MenuNavigation': '2000 400',
'firstPanel': 'PARAMS',
'signalEvent': f'smeserver-{package_name.lower()}-update',
'html': {
'Name': 'params',
'route': 'PARAMS',
'Header': header if header else f'{package_name} Contrib',
'SubHeader': sub_header if sub_header else f'Manage {package_name} settings:',
**{k: v for item in structured_html for k, v in item.items()} # Flatten the structured_html into the dict
}
"PackageName": package_name,
"prefix": prefix,
"MenuHeading": "Miscellaneous",
"MenuDescription": insert_spaces_before_caps(package_name),
"MenuNavigation": "2000 400",
"firstPanel": "PARAMS",
"signalEvent": f"smeserver-{package_name.lower()}-update",
"html": [{
"Name": "params",
"route": "PARAMS",
"Header": header if header else f"{package_name} Contrib",
"SubHeader": sub_header
if sub_header
else f"Manage {package_name} settings:",
**{
k: v for item in structured_html for k, v in item.items()
}, # Flatten the structured_html into the dict
}],
}
# Save in JSON5 format (JSON with comments and unquoted keys)
with open(output_filename, 'w', encoding='utf-8') as json_file:
with open(output_filename, "w", encoding="utf-8") as json_file:
json.dump(json5_data, json_file, ensure_ascii=False, indent=4)
# Manually format as JSON5 by adding single quotes (for simplicity)
with open(output_filename, 'r+', encoding='utf-8') as json_file:
with open(output_filename, "r+", encoding="utf-8") as json_file:
content = json_file.read()
content = content.replace('"', "'") # Replace double quotes with single quotes for JSON5
content = content.replace(
'"', "'"
) # Replace double quotes with single quotes for JSON5
json_file.seek(0)
json_file.write(content)
json_file.truncate() # Remove any old content beyond the new content length
def main():
input_file = '/home/brianr/clients/SM2/SM2Gen/venv/html/CreateStarterWebsite.html' # Specify the input HTML file path
# command line parameters
parser = argparse.ArgumentParser(description="sm1--html-2-jsopn5")
parser.add_argument(
"-f",
"--filename",
help="Specify a filename for the html file",
default="CreateStarterWebsite.html",
)
args = parser.parse_args()
input_file = "/home/brianr/clients/SM2/SM2Gen/venv/html/" + args.filename
if not input_file.lower().endswith(".html"):
# Add .html extension
input_file += ".html"
print(input_file)
# Read HTML content
html_content = read_html_file(input_file)
@ -256,19 +289,29 @@ def main():
# Extract data from HTML
data, header, sub_header = extract_data(html_content)
#
# Generate output JSON5 filename based on input file name
#
# Split the original path into directory and file name
directory, filename = os.path.split(input_file)
# Replace 'html' with 'json5' in the directory path
new_directory = directory.replace('/html', '/json5')
#print(new_directory)
# Construct the new path
output_file = os.path.join(new_directory, filename.replace('.html', '.json5'))
print(output_file)
#quit(1)
# Generate output JSON5 filename based on input file name
base_name = os.path.basename(input_file) # Get the file name (with extension)
package_name = os.path.splitext(base_name)[0] # Use the filename without extension
json_filename = package_name + '.json5' # Change extension to .json5
# Create the output file path in the same directory
output_directory = os.path.dirname(input_file)
output_file = os.path.join(output_directory, json_filename)
# Save extracted data to JSON5
save_to_json5(data, output_file, package_name, header, sub_header)
print(f"Extracted data saved to '{output_file}'.")
if __name__ == '__main__':
if __name__ == "__main__":
main()

View File

@ -311,9 +311,9 @@ if __name__ == "__main__":
except pkg_resources.DistributionNotFound:
chameleon_version = "Version information not available"
python_version = sys.version
version_pattern = r'(\d{1,3}\.\d{1,3}\.\d{1,3})'
version_pattern = r"(\d{1,3}\.\d{1,3}\.\d{1,3})"
version_match = re.search(version_pattern, python_version)
python_version = version_match.group(0) if version_match else 'Unknown'
python_version = version_match.group(0) if version_match else "Unknown"
current_datetime = datetime.now()
formatted_datetime = current_datetime.strftime("%Y-%m-%d %H:%M")
strVersion = (
@ -376,7 +376,10 @@ if __name__ == "__main__":
default="yes",
)
parser.add_argument(
"-ncu", "--noCust", help="Stop it creating Custom controller file", default="yes"
"-ncu",
"--noCust",
help="Stop it creating Custom controller file",
default="yes",
)
args = parser.parse_args()
json_filename = args.filename
@ -422,7 +425,9 @@ if __name__ == "__main__":
layout_file = target_directory_path + hl("PackageName").lower() + ".html.ep"
partial_files = list()
for panel in routes:
partial_files.append(target_directory_path + hl("prefix") + "_" + panel + ".html.ep")
partial_files.append(
target_directory_path + '_' + hl("prefix") + "_" + panel + ".html.ep"
)
print(f"Partial files to be created:{partial_files}")
lex_file = target_directory_path + hl("PackageName").lower() + "_en.lex"
tablecontrols = (
@ -433,7 +438,9 @@ if __name__ == "__main__":
# Generate controller file
try:
controller_template = PageTemplateFile("Templates/controller.pm.tem",CHAMELEON_DEBUG="true")
controller_template = PageTemplateFile(
"Templates/controller.pm.tem", CHAMELEON_DEBUG="true"
)
dbentries = get_db_fields() # Params which correspond to Db fields
try:
controller_perl = controller_template.render(
@ -646,7 +653,9 @@ if __name__ == "__main__":
for lang_item in lang_dict:
print(f"Translating from english lex file to {lang_item['language']}")
code = lang_item["code"]
translated_lex_file = f"{target_directory_path}{hl('PackageName').lower()}_{code}.lex"
translated_lex_file = (
f"{target_directory_path}{hl('PackageName').lower()}_{code}.lex"
)
# Only do it if the lex file is missing
if not os.path.exists(translated_lex_file):
translated_dict = []
@ -655,7 +664,9 @@ if __name__ == "__main__":
translated_text = get_translation(
lex_item["text"], lang_item["language"]
)
translated_dict.append({"id": lex_item["id"], "text": translated_text})
translated_dict.append(
{"id": lex_item["id"], "text": translated_text}
)
print(f"Writing out lex file for {lang_item['code']}")
with open(translated_lex_file, "w") as file:
for item in translated_dict:
@ -666,7 +677,9 @@ if __name__ == "__main__":
.replace('"', r"\"")
.replace("'", r"\'")
)
line = "'" + item["id"] + "' => " + '"' + translated_text + '",\n'
line = (
"'" + item["id"] + "' => " + '"' + translated_text + '",\n'
)
file.write(line)
# print(f"{item['id']} => {item['text']}\n")
else: