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.
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
--
TWikiGuest - 11 Jun 2007
Answer
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:
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 | " }%
--
HaraldJoerg - 12 Jan 2008
Note that latest
TablePlugin allows sorting on icons.
--
ArthurClemens - 13 Jan 2008