Skip to content

Commit

Permalink
Item12466: restore the old capability to view the stored value of a f…
Browse files Browse the repository at this point in the history
…ormfield by adding the $formfield(Name,stored) modifier. Works with select+values and checkbox+values

git-svn-id: http://svn.foswiki.org/trunk@16661 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Apr 15, 2013
1 parent c122dfa commit c66c730
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 11 deletions.
54 changes: 53 additions & 1 deletion UnitTestContrib/test/unit/Fn_SEARCH.pm
Expand Up @@ -1323,12 +1323,23 @@ This text is fill in text which is there to ensure that the unique word below do
* Bullet 4
HERE

# Create the form
Foswiki::Func::saveTopic( $this->{test_web}, "FormattedSearchForm", undef,
<<FORM);
| *Name* | *Type* | *Size* | *Values* | *Tooltip message* |
| Name | text | 40 | | |
| Role | text | 40 | | |
| Testsample | text | 40 | | |
| Groupe | select+values | 1 | A: Tous=A, B: Financiers; Rapports =Bollocks, C: Négociation; Syndicat =C, | Quel est le groupe de diffusion du document? | |
| Chinese | checkbox+values | 1 | 一=one, 二=two, 三=three | | |
FORM

my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'FormattedSearchTopic1' );
$topicObject->put( 'TOPICPARENT',
{ name => "TestCaseAutoFormattedSearch" } );
$topicObject->put( 'FORM', { name => "FormattedSearchForm" } );
$topicObject->put(
$topicObject->putKeyed(
'FIELD',
{
name => "Name",
Expand All @@ -1337,6 +1348,24 @@ HERE
value => "!AnnaAnchor"
}
);
$topicObject->putKeyed(
'FIELD',
{
name => "Groupe",
attributes => "",
title => "Groupe",
value => "Bollocks"
}
);
$topicObject->putKeyed(
'FIELD',
{
name => "Chinese",
attributes => "",
title => "Chinese",
value => "three"
}
);
$topicObject->text($text);
$topicObject->save();
$topicObject->finish();
Expand Down Expand Up @@ -1502,6 +1531,29 @@ sub test_format_tokens_dont_expand {
return;
}

sub test_format_stored_value {
my $this = shift;

$this->set_up_for_formatted_search();

my $result =
$this->{test_topicObject}->expandMacros(
'%SEARCH{"Bullet" type="regex" nonoise="on" format="$formfield(Groupe) $formfield(Groupe, stored):$formfield(Groupe, stored, 3)"}%'
);

$this->assert_str_equals( "B: Financiers; Rapports Bollocks:Bol- loc- ks",
$result );

$result =
$this->{test_topicObject}->expandMacros(
'%SEARCH{"Bullet" type="regex" nonoise="on" format="$formfield(Chinese) $formfield(Chinese, stored)"}%'
);

$this->assert_str_equals( "三 three", $result );

return;
}

sub test_METASEARCH {
my $this = shift;
my $session = $this->{session};
Expand Down
1 change: 1 addition & 0 deletions core/data/System/FormattedSearch.txt
Expand Up @@ -107,6 +107,7 @@ Format tokens that can be used in the format string:
| =$formfield(name, 10)= | Form field value, "<tt>- </tt>" hyphenated every 10 characters |
| =$formfield(name, 20, -&lt;br /&gt;)= | Form field value, hyphenated every 20 characters with separator "<tt>-&lt;br /&gt;</tt>" |
| =$formfield(name,30,...)= | Form field value, shortened to 30 characters with trailing ellipsis. |
| =$formfield(name, stored)= | Form field value, *without* mapping the stored value to the display value (use with =+values= form fields). You can still use the hyphenation controls described above, but they must follow after e.g. =$formfield(name, stored, 10)= |
| =$pattern(reg-exp)= | A regular expression pattern to extract some text from a topic (does not search meta data; use =$formfield= instead). In case of a =multiple="on"= search, the pattern is applied to the line found in each search hit.%BB% Specify a RegularExpression that covers the whole text (topic or line), which typically starts with =.*=, and must end in =.*= %BB% Put text you want to keep in parenthesis, like =$pattern(.*?(from here.*?to here).*)= %BB% Example: =$pattern(.*?\*.*?Email\:\s*([^\n\r]+).*)= extracts the e-mail address from a bullet of format =* Email: ...= %BB% This example has non-greedy =.*?= patterns to scan for the first occurance of the Email bullet; use greedy =.*= patterns to scan for the last occurance %BB% Limitation: Do not use =.*)= inside the pattern, e.g. =$pattern(.*foo(.*)bar.*)= does not work, but =$pattern(.*foo(.*?)bar.*)= does %BB% Note: Make sure that the integrity of a web page is not compromised; for example, if you include an HTML table make sure to include everything including the table end tag |
| =$count(reg-exp)= | Count of number of times a regular expression pattern appears in the text of a topic (does not search meta data). Follows guidelines for use and limitations outlined above under =$pattern(reg-exp)=. Example: =$count(.*?(---[+][+][+][+]) .*)= counts the number of &lt;H4&gt; headers in a page. |
| =$ntopics= | Number of topics found in current web. This is the current topic count, not the total number of topics |
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Form/Checkbox.pm
Expand Up @@ -82,7 +82,7 @@ sub renderForDisplay {

$this->getOptions();

if ( $this->isValueMapped() ) {
if ( !$attrs->{nomap} && $this->isValueMapped() ) {
my @vals = ();
foreach my $val ( split( /\s*,\s*/, $value ) ) {
if ( defined( $this->{valueMap}{$val} ) ) {
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Form/Select.pm
Expand Up @@ -108,7 +108,7 @@ sub renderForDisplay {

$this->getOptions();

if ( $this->isValueMapped() ) {
if ( !$attrs->{nomap} && $this->isValueMapped() ) {
my @vals = ();
foreach my $val ( split( /\s*,\s*/, $value ) ) {
if ( defined( $this->{valueMap}{$val} ) ) {
Expand Down
30 changes: 22 additions & 8 deletions core/lib/Foswiki/Search.pm
Expand Up @@ -601,6 +601,7 @@ sub formatResults {
my %pager_formatting;
if ( $params->{paging_on} ) #TODO: if can skip()
{

#TODO: this is a dangerous assumption that should be abstracted
ASSERT( $infoCache->isa('Foswiki::Iterator::PagerIterator') ) if DEBUG;

Expand Down Expand Up @@ -1332,19 +1333,32 @@ hyphenated string.
sub displayFormField {
my ( $meta, $args ) = @_;

my $name = $args;
my ( $name, @params ) = split( /,\s*/, $args );
my $breakArgs = '';
my @params = split( /\,\s*/, $args, 2 );
if ( @params > 1 ) {
$name = $params[0] || '';
$breakArgs = $params[1] || 1;
my $nomap = 0;
if (@params) {
if ( $params[0] eq 'stored' ) {

# The stored value is required
$nomap = 1;
shift @params;
}
$breakArgs = join( ',', @params );
}

# SMELL: this is a *terrible* idea. Not only does it munge the result
# so it can only be used for display, it also munges it such that it
# can't be repaired by the options on %SEARCH.
return $meta->renderFormFieldForDisplay( $name, '$value',
{ break => $breakArgs, protectdollar => 1, showhidden => 1 } );
# can't be repaired by the options on %SEARCH. The 'nomap' goes some
# way to curing the problem, but it's still not ideal :-(
return $meta->renderFormFieldForDisplay(
$name, '$value',
{
break => $breakArgs,
protectdollar => 1,
showhidden => 1,
nomap => $nomap
}
);
}

#my ($callback, $cbdata) = setup_callback(\%params, $baseWebObject);
Expand Down

0 comments on commit c66c730

Please sign in to comment.