Tags:
create new tag
view all tags

Question

I am using a formatted search to output the state of certain pages in a web.

The state of the page is determined by many different variables, e.g. subtasks in a larger task.


%SEARCH{ "[T]askState.*?value=\"[A]ctive\"" scope="text" regex="on" nosearch="on" nototal="on" format="| [[$topic]] | $formfield(SubtaskA) | $formfield(SubtaskB) | $formfield(SpecialTaskC) | " }%


Now, this will return the states of the subtasks in all active tasks in a nice table. e.g.

Task Subtask A Subtask B SpecialTask C
Mytask ready finished problematic

For better overview, I would like to color the background/text of all subtasks that are "Finished" to green, and all those that are "Problematic" to red.

I see that there is a possibility to use an IF statement in a search, but I couldn't figure out how to do this. Or, could I maybe put the color in the form definition?

Any help would be greatly appreciated!

Environment

TWiki version: TWikiRelease04x01x02
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS:  
Web server:  
Perl version:  
Client OS:  
Web Browser:  
Categories: Forms, Search, Plugins, Add-Ons, Skin

-- TWikiGuest - 11 Jun 2007

Answer

ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.

nobody???

-- TWikiGuest - 20 Jun 2007

You can use a conditional SpreadSheetPlugin formula with nested $IF(). Example:

| %CALC{$SET(status, finished)$IF($EXACT($GET(status), finished), <span style='color: green'>$GET(status)</span>, $IF($EXACT($GET(status), problematic), <span style='color: red'>$GET(status)</span>, $GET(status)))}% |

resulting in:

finished

If you want to put this into a SEARCH format you need to escape the CALC so that it fires off once per search hit, not just once. Write $percntCALC{}$percnt to escape %CALC{}%. Write $SET(status, $formfield(SubtaskA)) instead of a hardcoded $SET(status, finished).

Read details in VarSEARCH, SearchPatternCookbook, FormattedSearch and SpreadSheetPlugin.

-- PeterThoeny - 21 Jun 2007

You can also use JavaScript. We use this a lot for status cells.

Here's a sample:

<style>
.cellred { background-color: #f44; text-transform:uppercase; font-weight:bold}
.cellyellow { background-color: #ff4; }
.cellgreen { background-color: #4f4; }
.cellred, .cellyellow, .cellgreen { text-align:center; text-transform:uppercase; }
</style>
<script>
var cells=document.getElementsByTagName('td');
var cn=Array('yellow', 'green', 'red');
var alltd;
for(var i=0;i<cells.length;i++) {
   var text=cells[i].innerHTML.toLowerCase();
   text = text.replace(/<.*?>/g, '');
   text = text.replace(/^\s+/, '');
   text = text.replace(/\s+$/, '');
   var ncn=null;
   for (var ci=0;ci<cn.length;ci++)
      if (text == cn[ci])
         ncn='cell' + cn[ci];
   if (ncn) cells[i].className = ncn;
}

Alternatively, attach desired CSS and JavaScript to your TWiki, then use those. (example at TWikiTutColorTable on my TWiki).

-- VickiBrown - 11 Jan 2008

I find neither the spreadsheet nor the Javascript solution particularly easy to read (apart from the fact that I avoid Javascript in public wikis). So, if all the field values are simple words, there's yet another solution, which has the benefit of allowing mucho more formatting.

For an example, let me search all topics in the support web which contain my name, and colour the status column (just reducing the result set to topics beginning with "HowTo" for no particular reason). This trick fails if the form fields can contain spaces (or even percent signs), so use it only for simple radio buttons or selects where you know all the values. That said: A malicious user could add anything to form fields shown as radio boxes or select fields by crafting a HTTP request.

   * Set STATUSAskedQuestions = :confused:
   * Set STATUSAssignedQuestions = :-p
   * Set STATUSAnsweredQuestions = :ok:
   * Set STATUSClosedUnanswered = :skull:

%SEARCH{ "HaraldJoerg" scope="text" topic="HowTo*" nonoise="on" header="| *Topic* | *Status* |" format="| [[$topic]] | $percntSTATUS$formfield(SupportStatus)$percnt | " }%

Topic Status
HowToApproveRegistration thumbs up
HowToBecomeABetaTester thumbs up
HowToChangeBulletStyle thumbs up
HowToChangeHttpHostVariable thumbs up
HowToColorCellsInAFormattedSearch thumbs up
HowToConfigureTwikiWithExchangeServe thumbs up
HowToCopyATopic thumbs up
HowToCreateAGlossary thumbs up
HowToEditWebTopicList thumbs up
HowToEnforceRegistrationInAnIntranet thumbs up
HowToExtractPartOfAFieldValue thumbs up
HowToExtractTextWithinSameTopic thumbs up
HowToFixBadFileDescriptor thumbs up
HowToForceAuthorizedUsersToRegister thumbs up
HowToForceLdapUsersToRegisterWikiName thumbs up
HowToGetFileAttachmentDetails thumbs up
HowToHaveSeparateTWikiAndApacheAuthentication thumbs up
HowToIncludeTwoLinesOfTextInTableCell thumbs up
HowToIncludeURLs thumbs up
HowToLinkFilesAndDirectories thumbs up
HowToLinkLogoAndUrl thumbs up
HowToLinkToAttachmentInOtherTopic thumbs up
HowToLogOff thumbs up
HowToMoveUsers thumbs up
HowToOverRideOrChangeHTTPHostValue thumbs up
HowToPreselectATemplate thumbs up
HowToPreventUnwantedRegistrations thumbs up
HowToSearchExactText thumbs up
HowToSearchFormFields2 thumbs up
HowToSendEverythingToSSL thumbs up
HowToSet404Response thumbs up
HowToShowPageVisitorCount thumbs up
HowToUseAForm thumbs up
HowToUseJavascriptOnload thumbs up
HowToUseLoginInTwiki dead!
HowToUseSearchVariable thumbs up
HowToUseTWikiFuncGetCgiQuery thumbs up
HowToUseTheWebNotificationForAparticularWebsiteOnly thumbs up
HowToUseWebTemplateTopics thumbs up
HowtoCacheWebList thumbs up
HowtoLogoffTwiki thumbs up

-- HaraldJoerg - 12 Jan 2008

Note that latest TablePlugin allows sorting on icons.

-- ArthurClemens - 13 Jan 2008

Change status to:
Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2008-01-13 - ArthurClemens
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.