Bod has asked for the wisdom of the Perl Monks concerning the following question:
An internal system for business displays a series of 'cards' which show key data across various parts of the business all in one place. These are quite diverse and cover things like property occupancy levels, future pricing data and call centre call volume.
Currently this is implemented with a bespoke kind of template. There is an HTML file with placeholders for all the data items and a Perl script which gathers all the data from various systems across the business, reads the file, substitutes that data into the placeholders before displaying the output. It can be viewed at any time as a webpage but also runs twice per week from CRON and sends an email to key people. The script knows the difference by checking if $ENV{'GATEWAY_INTERFACE'} is defined.
This system already has 106 placeholders and needs extra information adding to it and I've decided to take the opportunity to refactor it to use Template thanks to the good influence of the Monastery! As part of the refactoring I want to add the facility for different users to be able to view the system with the cards in an order to suit them. Perhaps even to be able to hide the ones that do not interest them. We operate an open information policy so everyone in the business is permitted to see everything so there are no permission issues but not everything is actually useful to everyone so it would be good if they could put the cards they use most at the top and ones they seldom use further down.
In trying to work out how to implement this I have come up with a solution but it seems there must be a more elegant solution.
I've considered having a database table consisting of 4 fields:
- User_idUser - Foriegn Key to primary of User table - Card_idCard - Foreign Key to primary of Card table - metric - order to display cards for user - visible - boolean - show card to user?with User_idUser and Card_idCard being the composite primary key.
Then have a Perl script (of course!) that reads the cards from the database in the order given by metric. For each card it calls a subroutine that assembles the appropriate data for that card and uses Template to display the template file for that card. There will need to be 12 template files plus one for header and footers. Something like this (untested):
But I especially do not like the conditional subroutine calls with magic numbers in the statement modifiers.my $cards = $dbh->prepare("SELECT Card_idCard FROM CardList WHERE User +_idUser = $user_number AND visible = 1 ORDER BY metric"); $cards->execute(); while (my $card = $cards->fetchrow_array) { card_call_center() if $card == 1; card_price_data() if $card == 2; card_occupancy() if $card == 3; # etc etc } # ... sub card_call_center { # Collect data # from systems my $vars = { 'foo' => bar, 'some' => data, }; $template->process('card_call_center.tt', $vars); }
Is there a more elegant solution?
Should I be calling multiple template files from the script or should that processing be done within Template?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Ordering Template cards
by kcott (Archbishop) on Jan 25, 2021 at 01:00 UTC | |
by Bod (Parson) on Jan 25, 2021 at 20:50 UTC | |
|
Re: Ordering Template cards
by 1nickt (Canon) on Jan 24, 2021 at 16:46 UTC | |
by Bod (Parson) on Jan 24, 2021 at 16:52 UTC | |
by Corion (Patriarch) on Jan 24, 2021 at 16:59 UTC | |
by Bod (Parson) on Jan 24, 2021 at 17:09 UTC | |
by 1nickt (Canon) on Jan 24, 2021 at 16:57 UTC | |
by Bod (Parson) on Jan 24, 2021 at 17:04 UTC | |
|
[OT] LaTeX for PDF? Re: Ordering Template cards
by bliako (Abbot) on Jan 24, 2021 at 20:41 UTC | |
by Bod (Parson) on Jan 24, 2021 at 21:17 UTC | |
|
Re: Ordering Template cards
by LanX (Saint) on Jan 25, 2021 at 21:04 UTC | |
by Bod (Parson) on Jan 25, 2021 at 21:48 UTC | |
by haukex (Archbishop) on Jan 26, 2021 at 10:30 UTC | |
by LanX (Saint) on Jan 26, 2021 at 12:32 UTC | |
by haukex (Archbishop) on Jan 26, 2021 at 12:36 UTC | |
| |
by Bod (Parson) on Jan 28, 2021 at 01:07 UTC | |
by Marshall (Canon) on Jan 26, 2021 at 02:42 UTC | |
by bliako (Abbot) on Jan 26, 2021 at 10:38 UTC | |
by Marshall (Canon) on Jan 28, 2021 at 06:30 UTC | |
| |
by LanX (Saint) on Jan 26, 2021 at 05:19 UTC | |
by Bod (Parson) on Jan 28, 2021 at 01:10 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |