From 0b2e7b691d4b25847de97b5a5d14db4f2f0d0485 Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 30 Jun 2018 12:45:23 +0100 Subject: [PATCH] Start support for search --- blocks/ORB/Search.pm | 115 ++++++++++++++++++++++++++ blocks/ORB/Userbar.pm | 5 ++ templates/default/userbar/userbar.tem | 4 +- 3 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 blocks/ORB/Search.pm diff --git a/blocks/ORB/Search.pm b/blocks/ORB/Search.pm new file mode 100644 index 0000000..5cccec2 --- /dev/null +++ b/blocks/ORB/Search.pm @@ -0,0 +1,115 @@ +## @file +# This file contains the implementation of the search page. +# +# @author Chris Page <chris@starforge.co.uk> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. + +## @class +package ORB::Search; + +use strict; +use parent qw(ORB); # This class extends the ORB block class +use experimental qw(smartmatch); +use v5.14; + +sub + + +sub _generate_search { + my $self = shift; + + my ($term, $error) = $self -> validate_string('search', + { + required => 0, + default => undef, + nicename => "{L_SEARCH_SEARCH}", + minlen => 4 + }); + + return $self -> _build_search_results($term) + if($term); + + return $self -> _build_search_form($error); +} + + +# ============================================================================ +# UI handler/dispatcher functions + +## @method private @ _fatal_error($error) +# Generate the tile and content for an error page. +# +# @param error A string containing the error message to display +# @return The title of the error page and an error message to place in the page. +sub _fatal_error { + my $self = shift; + my $error = shift; + + return ("{L_SEARCH_ERROR_FATAL}", + $self -> {"template"} -> load_template("error/page_error.tem", + { "%(message)s" => $error, + "%(url-logout)s" => $self -> build_url(block => "login", pathinfo => ["signout"]) + }) + ); +} + + +## @method private $ _dispatch_ui() +# Implements the core behaviour dispatcher for non-api functions. This will +# inspect the state of the pathinfo and invoke the appropriate handler +# function to generate content for the user. +# +# @return A string containing the page HTML. +sub _dispatch_ui { + my $self = shift; + + my ($title, $body, $extrahead, $extrajs) = $self -> _generate_search(); + + # Done generating the page content, return the filled in page template + return $self -> generate_orb_page(title => $title, + content => $body, + extrahead => $extrahead, + extrajs => $extrajs, + active => '', + doclink => 'search'); +} + + +# ============================================================================ +# Module interface functions + +## @method $ page_display() +# Generate the page content for this module. +sub page_display { + my $self = shift; + + # Is this an API call, or a normal page operation? + my $apiop = $self -> is_api_operation(); + if(defined($apiop)) { + # API call - dispatch to appropriate handler. + given($apiop) { + default { + return $self -> api_response($self -> api_errorhash('bad_op', + $self -> {"template"} -> replace_langvar("API_BAD_OP"))) + } + } + } else { + return $self -> _dispatch_ui(); + } +} + + + +1; \ No newline at end of file diff --git a/blocks/ORB/Userbar.pm b/blocks/ORB/Userbar.pm index ea9a924..ce0b349 100644 --- a/blocks/ORB/Userbar.pm +++ b/blocks/ORB/Userbar.pm @@ -86,6 +86,11 @@ sub block_display { pathinfo => [ ], params => {}, forcessl => 1), + "%(url-search)s" => $self -> build_url(block => "search", + fullurl => 1, + pathinfo => [ ], + params => {}, + forcessl => 1), "%(url-shop)s" => $self -> build_url(block => "shop", fullurl => 1, pathinfo => [ ], diff --git a/templates/default/userbar/userbar.tem b/templates/default/userbar/userbar.tem index 442ace0..745fc70 100755 --- a/templates/default/userbar/userbar.tem +++ b/templates/default/userbar/userbar.tem @@ -1,8 +1,8 @@ -
+