Add in userpanewl and fix up table sub in template
This commit is contained in:
208
Targets/Userpanels/Userpanels-Custom.pm
Normal file
208
Targets/Userpanels/Userpanels-Custom.pm
Normal file
@@ -0,0 +1,208 @@
|
||||
#
|
||||
# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-04-23 10:18:18
|
||||
#
|
||||
#
|
||||
# Routines to be edited by the developer to provide content and validation for parameters
|
||||
# and provison of the control data for table(s)
|
||||
#
|
||||
use esmith::util;
|
||||
use esmith::util::network;
|
||||
use esmith::ConfigDB;
|
||||
use esmith::HostsDB;
|
||||
use esmith::AccountsDB;
|
||||
use esmith::NetworksDB;
|
||||
use esmith::DomainsDB;
|
||||
|
||||
use constant FALSE => 0;
|
||||
use constant TRUE => 1;
|
||||
|
||||
|
||||
#The most common ones
|
||||
#my $cdb
|
||||
#my $adb
|
||||
#my $ndb
|
||||
#my $hdb
|
||||
#my $ddb
|
||||
|
||||
# Validation routines - parameters for each panel
|
||||
|
||||
sub validate_USERTABLE {
|
||||
my $c = shift;
|
||||
my $prefix_data = shift; #Data hash as parameter
|
||||
# Validation for each field
|
||||
my $ret = "";
|
||||
|
||||
if ($ret eq "") {$ret = 'ok';}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub validate_PANELTABLE {
|
||||
my $c = shift;
|
||||
my $prefix_data = shift; #Data hash as parameter
|
||||
# Validation for each field
|
||||
my $ret = "";
|
||||
|
||||
if ($ret eq "") {$ret = 'ok';}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
# Get singleton data for each panel
|
||||
|
||||
sub get_data_for_panel_USERTABLE {
|
||||
# Return a hash with the fields required which will be loaded into the shared data
|
||||
my $c = shift;
|
||||
my %ret = (
|
||||
'Data1'=>'Data for USERTABLE', #Example
|
||||
# fields from Inputs in USERTABLE $fields['USERTABLE']
|
||||
|
||||
);
|
||||
return %ret;
|
||||
}
|
||||
|
||||
sub get_data_for_panel_PANELTABLE {
|
||||
# Return a hash with the fields required which will be loaded into the shared data
|
||||
my $c = shift;
|
||||
my %ret = (
|
||||
'Data1'=>'Data for PANELTABLE', #Example
|
||||
# fields from Inputs in PANELTABLE $fields['PANELTABLE']
|
||||
|
||||
);
|
||||
return %ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Get control data for table(s)
|
||||
|
||||
# Define a constant hash for field name mapping
|
||||
use constant users_FIELD_MAPPING => (
|
||||
'Account' => 'Source-for-Account',
|
||||
'Description' => 'Source-for-Description',
|
||||
'Modify' => 'Source-for-Modify'
|
||||
#'target_field2' => 'source_field2',
|
||||
# Add more mappings as needed
|
||||
);
|
||||
|
||||
sub actual_users {
|
||||
my @ret = ();
|
||||
# Actual code for extracting users
|
||||
return @ret;
|
||||
}
|
||||
|
||||
sub get_users {
|
||||
# Return an array of hashes of the contents for each row and column for users
|
||||
my $c = shift;
|
||||
my @source_records = $c->actual_users();
|
||||
my @transformed_records;
|
||||
my %Field_Mapping = users_FIELD_MAPPING;
|
||||
# Iterate over each record in the source array
|
||||
for my $source_record (@$source_records) {
|
||||
my %transformed_record;
|
||||
# Iterate over each key-value pair in the $Field_Mapping constant
|
||||
while (my ($target, $source) = each %Field_Mapping) {
|
||||
# Check if the source field exists in the source record
|
||||
if (exists $source_record->{$source}) {
|
||||
# Assign the source field value to the target field in the transformed record
|
||||
$transformed_record{$target} = $source_record->{$source};
|
||||
}
|
||||
}
|
||||
# Add transformed record to the array if it's not empty
|
||||
push @transformed_records, \%transformed_record if %transformed_record;
|
||||
}
|
||||
return \@transformed_records;
|
||||
}
|
||||
|
||||
# Define a constant hash for field name mapping
|
||||
use constant panels_FIELD_MAPPING => (
|
||||
'Panel' => 'Source-for-Panel',
|
||||
'Description' => 'Source-for-Description',
|
||||
'Select' => 'Source-for-Select'
|
||||
#'target_field2' => 'source_field2',
|
||||
# Add more mappings as needed
|
||||
);
|
||||
|
||||
sub actual_panels {
|
||||
my @ret = ();
|
||||
# Actual code for extracting panels
|
||||
return @ret;
|
||||
}
|
||||
|
||||
sub get_panels {
|
||||
# Return an array of hashes of the contents for each row and column for panels
|
||||
my $c = shift;
|
||||
my @source_records = $c->actual_panels();
|
||||
my @transformed_records;
|
||||
my %Field_Mapping = panels_FIELD_MAPPING;
|
||||
# Iterate over each record in the source array
|
||||
for my $source_record (@$source_records) {
|
||||
my %transformed_record;
|
||||
# Iterate over each key-value pair in the $Field_Mapping constant
|
||||
while (my ($target, $source) = each %Field_Mapping) {
|
||||
# Check if the source field exists in the source record
|
||||
if (exists $source_record->{$source}) {
|
||||
# Assign the source field value to the target field in the transformed record
|
||||
$transformed_record{$target} = $source_record->{$source};
|
||||
}
|
||||
}
|
||||
# Add transformed record to the array if it's not empty
|
||||
push @transformed_records, \%transformed_record if %transformed_record;
|
||||
}
|
||||
return \@transformed_records;
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Return hash with values from row in which link clicked on table
|
||||
|
||||
sub get_selected_USERTABLE {
|
||||
my $c = shift;
|
||||
my $selected = shift; #Parameter is name of selected row.
|
||||
my $is_new_record = shift; #Indicates new record required (defaults)
|
||||
my %ret = {};
|
||||
return %ret;
|
||||
}
|
||||
|
||||
sub get_selected_PANELTABLE {
|
||||
my $c = shift;
|
||||
my $selected = shift; #Parameter is name of selected row.
|
||||
my $is_new_record = shift; #Indicates new record required (defaults)
|
||||
my %ret = {};
|
||||
return %ret;
|
||||
}
|
||||
|
||||
|
||||
#after sucessful modify or create or whatever and submit then perfom (if the params validate)
|
||||
|
||||
sub perform_USERTABLE {
|
||||
my $c = shift;
|
||||
my $prefix_data = shift; #Data hash as parameter
|
||||
my $ret = "";
|
||||
my $db = $cdb; #maybe one of the others
|
||||
my $dbkey = 'ChangeThis';
|
||||
# To make it write to DB as comment, delete this (regex) string in each if statement "TRUE\) \#copy or perform with value: .* e.g."
|
||||
|
||||
if ($ret eq "") {$ret = 'ok';}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub perform_PANELTABLE {
|
||||
my $c = shift;
|
||||
my $prefix_data = shift; #Data hash as parameter
|
||||
my $ret = "";
|
||||
my $db = $cdb; #maybe one of the others
|
||||
my $dbkey = 'ChangeThis';
|
||||
# To make it write to DB as comment, delete this (regex) string in each if statement "TRUE\) \#copy or perform with value: .* e.g."
|
||||
|
||||
if ($ret eq "") {$ret = 'ok';}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
sub create_link{
|
||||
# WIP
|
||||
my ($c,$route, $panel, $index) = @_;
|
||||
my $link = "$route?trt=$panel&Selected=$index";
|
||||
return $link;
|
||||
}
|
||||
1;
|
Reference in New Issue
Block a user