Refactor for cleanliness
This commit is contained in:
parent
2ee53cb8f3
commit
335eba0231
@ -23,7 +23,7 @@ use strict;
|
||||
use parent qw(ORB); # This class extends the ORB block class
|
||||
use experimental qw(smartmatch);
|
||||
use v5.14;
|
||||
use Data::Dumper;
|
||||
|
||||
## @method private % _build_tag($tag)
|
||||
# Given a reference to a hash containing tag data, generate HTML to
|
||||
# represent the tag
|
||||
@ -42,28 +42,27 @@ sub _build_tag {
|
||||
}
|
||||
|
||||
|
||||
## @method private $ _generate_list($mode)
|
||||
# Generate the list page. This will create a page containing a list
|
||||
# of recipies based on the specified mode.
|
||||
## @method private % _build_recipe($recipe)
|
||||
# Given a reference to a hash containing recipe data, generate HTML to
|
||||
# represent the recipe
|
||||
#
|
||||
# @return An array of two values containing the page title and content.
|
||||
sub _generate_list {
|
||||
# @param recipe A reference to a recipe hash
|
||||
# @return A string representing the recipe
|
||||
sub _build_recipe {
|
||||
my $self = shift;
|
||||
my $mode = shift;
|
||||
my $recipe = shift;
|
||||
|
||||
my $recipes = $self -> {"system"} -> {"recipe"} -> get_recipe_list($mode)
|
||||
or $self -> generate_errorbox(message => $self -> {"system"} -> {"recipe"} -> errstr());
|
||||
|
||||
my @list;
|
||||
foreach my $recipe (@{$recipes}) {
|
||||
my $temp = "";
|
||||
|
||||
# If a temperature has been specified, it needs including in the output
|
||||
if($recipe -> {"temp"} && $recipe -> {"temptype"} ne "N/A") {
|
||||
$temp = $self -> {"template"} -> load_template("list/temp.tem", { "%(temp)s" => $recipe -> {"temp"},
|
||||
$temp = $self -> {"template"} -> load_template("list/temp.tem",
|
||||
{ "%(temp)s" => $recipe -> {"temp"},
|
||||
"%(temptype)s" => $recipe -> {"temptype"}
|
||||
});
|
||||
}
|
||||
|
||||
# Access to recipe controls is managed by metadata contexts
|
||||
my $controls = "";
|
||||
if($self -> check_permission("recipe.edit", $recipe -> {"metadata_id"})) {
|
||||
$controls .= $self -> {"template"} -> load_template("list/recipe.tem",
|
||||
@ -73,7 +72,7 @@ sub _generate_list {
|
||||
});
|
||||
}
|
||||
|
||||
push(@list, $self -> {"template"} -> load_template("list/recipe.tem",
|
||||
return $self -> {"template"} -> load_template("list/recipe.tem",
|
||||
{ "%(id)s" => $recipe -> {"id"},
|
||||
"%(url-view)s" => $self -> build_url(block => "view",
|
||||
pathinfo => [ $recipe -> {"id"} ]),
|
||||
@ -84,13 +83,29 @@ sub _generate_list {
|
||||
"%(temp)s" => $temp,
|
||||
"%(tags)s" => join("", map { $self -> _build_tag($_) } @{$recipe -> {"tags"}}),
|
||||
"%(controls)s" => $controls,
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
## @method private $ _generate_list($mode)
|
||||
# Generate the list page. This will create a page containing a list
|
||||
# of recipies based on the specified mode.
|
||||
#
|
||||
# @return An array of two values containing the page title and content.
|
||||
sub _generate_list {
|
||||
my $self = shift;
|
||||
my $mode = shift;
|
||||
|
||||
# Pull a (hopefully) filtered list of recipes from the database
|
||||
my $recipes = $self -> {"system"} -> {"recipe"} -> get_recipe_list($mode)
|
||||
or $self -> generate_errorbox(message => $self -> {"system"} -> {"recipe"} -> errstr());
|
||||
|
||||
# And build the template fragments from that list
|
||||
return ($self -> {"template"} -> replace_langvar("LIST_TITLE", { "%(page)s" => uc($mode // "All") }),
|
||||
$self -> {"template"} -> load_template("list/content.tem", {"%(pagemenu)s" => $self -> pagemenu($mode),
|
||||
$self -> {"template"} -> load_template("list/content.tem",
|
||||
{ "%(pagemenu)s" => $self -> pagemenu($mode),
|
||||
"%(page)s" => uc($mode // "All"),
|
||||
"%(recipes)s" => join("", @list),
|
||||
"%(recipes)s" => join("", map { $self -> _build_recipe($_) }, @{$recipes}),
|
||||
}),
|
||||
$self -> {"template"} -> load_template("list/extrahead.tem"),
|
||||
$self -> {"template"} -> load_template("list/extrajs.tem"),
|
||||
@ -114,11 +129,15 @@ sub _dispatch_ui {
|
||||
my ($title, $body, $extrahead, $extrajs) = ("", "", "", "");
|
||||
my @pathinfo = $self -> {"cgi"} -> multi_param("pathinfo");
|
||||
|
||||
print STDERR "Mode: ".$pathinfo[0]."\n";
|
||||
# If the pathinfo contains a recognised page character, use that
|
||||
if(defined($pathinfo[0]) && $pathinfo[0] =~ /^[0a-zA-Z\$]$/) {
|
||||
($title, $body, $extrahead, $extrajs) = $self -> _generate_list($pathinfo[0]);
|
||||
|
||||
# If th euser has requested all recipes, do no filtering
|
||||
} elsif($pathinfo[0] && lc($pathinfo[0]) eq "all") {
|
||||
($title, $body, $extrahead, $extrajs) = $self -> _generate_list();
|
||||
|
||||
# Otherwise fall back on the default of 'A' recipes
|
||||
} else {
|
||||
($title, $body, $extrahead, $extrajs) = $self -> _generate_list('A');
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user