Update Search for Moose.
This commit is contained in:
parent
34b513aa89
commit
fb87626e22
1 changed files with 62 additions and 51 deletions
|
|
@ -11,7 +11,61 @@ package WebGUI::Asset::Wobject::Search;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use base "WebGUI::Asset::Wobject";
|
||||
use WebGUI::Definition::Asset;
|
||||
extends "WebGUI::Asset::Wobject";
|
||||
aspect assetName => ['assetName', 'Asset_Search'];
|
||||
aspect icon => 'search.gif';
|
||||
aspect tableName => 'search';
|
||||
property templateId => (
|
||||
fieldType => "template",
|
||||
default => 'PBtmpl0000000000000200',
|
||||
tab => "display",
|
||||
namespace => "Search",
|
||||
hoverHelp => ['search template description', 'Asset_Search'],
|
||||
label => ['search template', 'Asset_Search'],
|
||||
);
|
||||
property searchRoot => (
|
||||
fieldType => "asset",
|
||||
builder => '_searchRoot_builder',
|
||||
tab => "properties",
|
||||
hoverHelp => ["search root description", 'Asset_Search'],
|
||||
label => ['search root', 'Asset_Search'],
|
||||
);
|
||||
sub _searchRoot_builder {
|
||||
my $session = shift->session;
|
||||
return $session->setting->get("defaultPage");
|
||||
}
|
||||
property classLimiter => (
|
||||
fieldType => "checkList",
|
||||
default => undef,
|
||||
vertical => 1,
|
||||
tab => "properties",
|
||||
hoverHelp => ["class limiter description", 'Asset_Search'],
|
||||
label => ["class limiter", 'Asset_Search'],
|
||||
options => \&_classLimiter_options,
|
||||
showSelectAll => 1,
|
||||
);
|
||||
sub _classLimiter_options {
|
||||
my $session = shift->session;
|
||||
return $session->db->buildHashRef("select distinct(className) from asset");
|
||||
}
|
||||
property useContainers => (
|
||||
tab => "properties",
|
||||
hoverHelp => ["useContainers help", 'Asset_Search'],
|
||||
label => ["useContainers", 'Asset_Search'],
|
||||
fieldType => "yesNo",
|
||||
default => 0,
|
||||
);
|
||||
property paginateAfter => (
|
||||
hoverHelp => ["paginate after help", 'Asset_Search'],
|
||||
label => ["paginate after", 'Asset_Search'],
|
||||
tab => "display",
|
||||
fieldType => "integer",
|
||||
default => 25,
|
||||
);
|
||||
|
||||
|
||||
|
||||
use Tie::IxHash;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Paginator;
|
||||
|
|
@ -73,52 +127,9 @@ sub definition {
|
|||
my %properties;
|
||||
tie %properties, 'Tie::IxHash';
|
||||
%properties = (
|
||||
templateId => {
|
||||
fieldType => "template",
|
||||
defaultValue => 'PBtmpl0000000000000200',
|
||||
tab => "display",
|
||||
namespace => "Search",
|
||||
hoverHelp => $i18n->get('search template description'),
|
||||
label => $i18n->get('search template')
|
||||
},
|
||||
searchRoot => {
|
||||
fieldType => "asset",
|
||||
defaultValue => $session->setting->get("defaultPage"),
|
||||
tab => "properties",
|
||||
hoverHelp => $i18n->get("search root description"),
|
||||
label => $i18n->get('search root')
|
||||
},
|
||||
classLimiter => {
|
||||
fieldType => "checkList",
|
||||
defaultValue => undef,
|
||||
vertical => 1,
|
||||
tab => "properties",
|
||||
hoverHelp => $i18n->get("class limiter description"),
|
||||
label => $i18n->get("class limiter"),
|
||||
options => $session->db->buildHashRef("select distinct(className) from asset"),
|
||||
showSelectAll => 1,
|
||||
},
|
||||
useContainers => {
|
||||
tab => "properties",
|
||||
hoverHelp => $i18n->get("useContainers help"),
|
||||
label => $i18n->get("useContainers"),
|
||||
fieldType => "yesNo",
|
||||
defaultValue => 0,
|
||||
},
|
||||
paginateAfter => {
|
||||
hoverHelp => $i18n->get("paginate after help"),
|
||||
label => $i18n->get("paginate after"),
|
||||
tab => "display",
|
||||
fieldType => "integer",
|
||||
defaultValue => 25,
|
||||
},
|
||||
);
|
||||
|
||||
push(@{$definition}, {
|
||||
assetName=>$i18n->get('assetName'),
|
||||
icon=>'search.gif',
|
||||
autoGenerateForms=>1,
|
||||
tableName=>'search',
|
||||
className=>'WebGUI::Asset::Wobject::Search',
|
||||
properties=>\%properties
|
||||
});
|
||||
|
|
@ -136,11 +147,11 @@ See WebGUI::Asset::prepareView() for details.
|
|||
sub prepareView {
|
||||
my $self = shift;
|
||||
$self->SUPER::prepareView();
|
||||
my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId"));
|
||||
my $template = WebGUI::Asset::Template->new($self->session, $self->templateId);
|
||||
if (!$template) {
|
||||
WebGUI::Error::ObjectNotFound::Template->throw(
|
||||
error => qq{Template not found},
|
||||
templateId => $self->get("templateId"),
|
||||
templateId => $self->templateId,
|
||||
assetId => $self->getId,
|
||||
);
|
||||
}
|
||||
|
|
@ -187,10 +198,10 @@ sub view {
|
|||
my %rules = (
|
||||
keywords =>$keywords,
|
||||
lineage =>[
|
||||
WebGUI::Asset->newById($session,$self->getValue("searchRoot"))->get("lineage")
|
||||
WebGUI::Asset->newById($session,$self->searchRoot)->get("lineage")
|
||||
],
|
||||
);
|
||||
my @classes = split("\n",$self->get("classLimiter"));
|
||||
my @classes = split("\n",$self->classLimiter);
|
||||
$rules{classes} = \@classes if (scalar(@classes));
|
||||
$search->search(\%rules);
|
||||
|
||||
|
|
@ -205,7 +216,7 @@ sub view {
|
|||
#Set up the paginator
|
||||
my $p = $search->getPaginatorResultSet (
|
||||
$self->getUrl('doit=1;keywords='.$session->url->escape($keywords)),
|
||||
$self->get("paginateAfter"),
|
||||
$self->paginateAfter,
|
||||
);
|
||||
|
||||
my @results = ();
|
||||
|
|
@ -219,8 +230,8 @@ sub view {
|
|||
my $asset = WebGUI::Asset->new($session, $data->{assetId}, $data->{className});
|
||||
if (defined $asset) {
|
||||
my $properties = $asset->get;
|
||||
if ($self->get("useContainers")) {
|
||||
$properties->{url} = $asset->getContainer->get("url");
|
||||
if ($self->useContainers) {
|
||||
$properties->{url} = $asset->getContainer->url;
|
||||
}
|
||||
#Add highlighting
|
||||
$properties->{'title' } = $hl->highlight($properties->{title} || '');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue