Consider search fields when doing search in a Thingy normally, or via Ajax. Fixes bug #12117.

This commit is contained in:
Colin Kuskie 2011-04-20 16:05:20 -07:00
parent fa0a606f1e
commit d4672a92f1
3 changed files with 153 additions and 22 deletions

View file

@ -1,4 +1,5 @@
7.10.15
- fixed #12117: Thingy - www_searchViaAjax broken
7.10.14
- fixed #12094: Cannot enter in Macros in URLs inside TinyMCE.

View file

@ -602,8 +602,7 @@ sub editThingDataSave {
lastUpDated=>time(),
);
$fields = $session->db->read('select * from Thingy_fields where assetId = ? and thingId = ? order by sequenceNumber',
[$self->get("assetId"),$thingId]);
$fields = $self->getFields($thingId);
while (my $field = $fields->hashRef) {
my $fieldName = 'field_'.$field->{fieldId};
my $fieldValue;
@ -939,6 +938,23 @@ sub getEditForm {
#-------------------------------------------------------------------
=head2 getFields ( $thingId )
Returns a result set with all the fields in a thing in this Thingy.
=head3 $thingId
The GUID for a thing
=cut
sub getFields {
my ($self, $thingId) = @_;
return $self->session->db->read("select * from Thingy_fields where assetId=? and thingId=? order by sequenceNumber",[$self->getId, $thingId]);
}
#-------------------------------------------------------------------
=head2 getFieldValue ( value, field )
Processes the field value for date(Time) fields and Other Thing fields.
@ -1235,8 +1251,7 @@ sub getViewThingVars {
." where thingDataId = ?",[$thingDataId]);
if (%thingData) {
my $fields = $db->read('select * from Thingy_fields where assetId = ? and thingId = ? order by sequenceNumber',
[$self->get('assetId'),$thingId]);
my $fields = $self->getFields($thingId);
while (my %field = $fields->hash) {
next unless ($field{display} eq '1');
my $hidden = ($field{status} eq "hidden" && !$self->session->var->isAdminOn);
@ -1899,7 +1914,7 @@ sub www_editThing {
." <td class='formDescription'>".$i18n->get('sort by label')."</td>\n"
."</tr>\n";
$fields = $self->session->db->read('select * from Thingy_fields where assetId = '.$self->session->db->quote($self->get("assetId")).' and thingId = '.$self->session->db->quote($thingId).' order by sequenceNumber');
$fields = $self->getFields($thingId);
while (my $field = $fields->hashRef) {
my $formElement;
if ($self->field_isa($field->{fieldType}, 'WebGUI::Form::Image')) {
@ -2211,7 +2226,7 @@ sub www_editThingSave {
my ($thingId, $fields);
$thingId = $self->session->form->process("thingId");
$fields = $self->session->db->read('select * from Thingy_fields where assetId = '.$self->session->db->quote($self->get("assetId")).' and thingId = '.$self->session->db->quote($thingId).' order by sequenceNumber');
$fields = $self->getFields($thingId);
if($fields->rows < 1){
$self->session->log->warn("Thing failed to create because it had no fields");
@ -2561,8 +2576,7 @@ sub editThingData {
." where thingDataId = ?",[$thingDataId]);
}
$fields = $session->db->read('select * from Thingy_fields where assetId = ? and thingId = ? order by sequenceNumber'
,[$self->getId,$thingId]);
$fields = $self->getFields($thingId);
while (my %field = $fields->hash) {
my $fieldName = 'field_'.$field{fieldId};
$fieldValue = undef;
@ -2744,8 +2758,7 @@ sub www_exportThing {
$pb->start($i18n->get('export label').' '.$thingProperties->{label}, $session->url->extras('assets/thingy.gif'));
$pb->update($i18n->get('Creating column headers'));
my $tempStorage = WebGUI::Storage->createTemp($session);
$fields = $session->db->read('select * from Thingy_fields where assetId =? and thingId = ? order by sequenceNumber',
[$self->get("assetId"),$thingId]);
$fields = $self->getFields($thingId);
while (my $field = $fields->hashRef) {
push(@fields, {
fieldId => $field->{fieldId},
@ -2826,8 +2839,7 @@ sub www_getThingViaAjax {
$thingProperties->{groupIdView});
my @field_loop;
my $fields = $session->db->read('select * from Thingy_fields where assetId=? and thingId=? order by sequenceNumber'
,[$self->getId,$thingId]);
my $fields = $self->getFields($thingId);
while (my $field = $fields->hashRef) {
$field->{formElement} = $self->getFormElement($field);
push(@field_loop,$field);
@ -3057,8 +3069,7 @@ sub www_importForm {
." <td>".$i18n->get("check duplicates label")."</td>"
."</tr>";
$fields = $db->read('select label, fieldId from Thingy_fields where assetId =? and thingId = ? order by sequenceNumber',
[$self->get("assetId"),$thingId]);
$fields = $self->getFields($thingId);
while (my $field = $fields->hashRef) {
$fieldOptions .= "<tr><td>".$field->{label}."</td><td>";
$fieldOptions .= WebGUI::Form::checkbox($self->session, {
@ -3340,9 +3351,7 @@ sub getSearchTemplateVars {
$currentUrl = $session->url->append($currentUrl, $form.'='.$param);
}
$fields = $session->db->read('select * from Thingy_fields where assetId =
'.$session->db->quote($self->get("assetId")).' and thingId = '.$session->db->quote($thingId).' order by
sequenceNumber');
$fields = $self->getFields($thingId);
while (my $field = $fields->hashRef) {
if ($field->{searchIn}){
my $searchForm = $self->getFormPlugin($field, 1);
@ -3395,7 +3404,8 @@ sequenceNumber');
}
$query .= join(", ",map {$dbh->quote_identifier('field_'.$_->{fieldId})} @displayInSearchFields);
$query .= " from ".$dbh->quote_identifier("Thingy_".$thingId);
if($session->form->process('func') eq 'search'){
my $func = $session->form->process('func');
if( $func eq 'search' || $func eq 'searchViaAjax' ){
# Don't add constraints when the search screen is displayed as an 'after save' option.
$query .= " where ".join(" and ",@constraints) if (scalar(@constraints) > 0);
}
@ -3408,9 +3418,6 @@ sequenceNumber');
$noFields = 1;
}
# store query in cache for thirty minutes
WebGUI::Cache->new($self->session,"query_".$thingId)->set($query,30*60);
$paginatePage = $self->session->form->param('pn') || 1;
$currentUrl = $self->session->url->append($currentUrl, "orderBy=".$orderBy) if $orderBy;
@ -3418,7 +3425,7 @@ sequenceNumber');
my @visibleResults;
if (! $noFields) {
my $sth = $self->session->db->read($query) if ! $noFields;
my $sth = $self->session->db->read($query);
while (my $result = $sth->hashRef){
if ($self->canViewThingData($thingId,$result->{thingDataId})){
push(@visibleResults,$result);

View file

@ -0,0 +1,123 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../../../lib";
##The goal of this test is to test getSearchTemplateVariables
use WebGUI::Test;
use WebGUI::Session;
use Test::More tests => 6; # increment this value for each test you create
use Test::Deep;
use JSON;
use WebGUI::Asset::Wobject::Thingy;
use WebGUI::Search;
use WebGUI::Search::Index;
use Data::Dumper;
my $session = WebGUI::Test->session;
# Do our work in the import node
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Thingy Test"});
WebGUI::Test->addToCleanup($versionTag);
my $thingy = $node->addChild({
className => 'WebGUI::Asset::Wobject::Thingy',
groupIdView => 7,
url => 'some_thing',
});
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 0, 'no records yet';
$versionTag->commit;
$thingy = $thingy->cloneFromDb;
# Test indexThing, without needing a real thing
my $groupIdEdit = $thingy->get("groupIdEdit");
my %thingProperties = (
thingId => "THING_RECORD",
label => 'Label',
editScreenTitle => 'Edit',
editInstructions => 'instruction_edit',
groupIdAdd => $groupIdEdit,
groupIdEdit => $groupIdEdit,
saveButtonLabel => 'save',
afterSave => 'searchThisThing',
editTemplateId => "ThingyTmpl000000000003",
groupIdView => '7',
viewTemplateId => "ThingyTmpl000000000002",
defaultView => 'searchThing',
searchScreenTitle => 'Search',
searchDescription => 'description_search',
groupIdSearch => '7',
groupIdExport => $groupIdEdit,
groupIdImport => $groupIdEdit,
searchTemplateId => "ThingyTmpl000000000004",
thingsPerPage => 25,
);
my $thingId = $thingy->addThing(\%thingProperties);
%thingProperties = %{ $thingy->getThing($thingId) };
my $field1Id = $thingy->addField({
thingId => $thingId,
fieldId => "new",
label => "textual",
dateCreated => time(),
fieldType => "text",
status => "editable",
display => 1,
searchIn => 1,
displayInSearch => 1,
}, 0);
is $thingy->getThings->rows, 1, 'Thingy has 1 thing';
my $fields = $session->db->quickScalar('select count(*) from Thingy_fields where assetId=? and thingId=?',[$thingy->getId, $thingId]);
is $fields, '1', 'Thingy has 1 field';
$thingy->editThingDataSave($thingId, 'new', {
thingDataId => 'new',
"field_$field1Id" => 'texty',
});
$thingy->editThingDataSave($thingId, 'new', {
thingDataId => 'new',
"field_$field1Id" => 'crusty',
});
$session->request->setup_body({
thingId => $thingId,
});
my $vars;
$vars = $thingy->getSearchTemplateVars();
my @results;
@results = map { $_->{searchResult_field_loop}->[0]->{field_value} } @{ $vars->{searchResult_loop} };
cmp_bag(\@results, [qw/texty crusty/], 'with no func set, returns all data');
$session->request->setup_body({
thingId => $thingId,
func => 'search',
'field_'.$field1Id => 'texty',
});
$vars = $thingy->getSearchTemplateVars();
@results = map { $_->{searchResult_field_loop}->[0]->{field_value} } @{ $vars->{searchResult_loop} };
cmp_bag(\@results, [qw/texty/], 'with no func=search, returns only what we searched for');
$session->request->setup_body({
thingId => $thingId,
func => 'searchViaAjax',
'field_'.$field1Id => 'crusty',
});
$vars = $thingy->getSearchTemplateVars();
@results = map { $_->{searchResult_field_loop}->[0]->{field_value} } @{ $vars->{searchResult_loop} };
cmp_bag(\@results, [qw/crusty/], 'with no func=searchViaAjax, returns only what we searched for');