cross
New Foswiki release 2.1.6 is available with important security fixes.
Sourceforge foswiki email lists being discontinued. Subscribe to the new Foswiki announce and discuss lists at MailingLists
This question about Topic Markup Language and applications: Task closed

How to set the search output in different colours

Hi all,

I have a dataform like this:

Name Type Size Value Message Attributes   Document Title Text 50   Title of the document

| Description | Text | 80 | | Short description of the content of the document | |
| R&D Deliverable | Select | 1 | Mandatory, Optional | Is the document optional or mandatory deliverable | |
| State Of Document At Gate | Select | 1 | Not applicable, Draft (In work), Final | State of the document at gate | |

Then I can make a search like

| Title | Derliverable | State At Review | Description |
%S E A R C H{" (StateOfDocumentAtGate='Final' OR
StateOfDocumentAtGate='Draft (In work)'"
web="Documents" nonoise="on" type="query"
format="| $formfield(DocumentTitle) | $formfield(R&DDeliverable) |$formfield(StateOfDocumentAtGate) | $formfield(Description) |
}%

This works fine.... but I would like to have the output of the search function to be green if it is a R&DDeliverable=Mandatory else Yellow....

I have tried with this oe below but it doesnt work.....

| Title | Derliverable | State At Review | Description |
%S E A R C H{" (StateOfDocumentAtGate='Final' OR
StateOfDocumentAtGate='Draft (In work)'"
web="Documents" nonoise="on" type="query"
format="<span style="color:$percentIF{$quotPMPDeliverable='Mandatory'$quot then=$quotgreen$quot else=$quotred$quot%">| $formfield(DocumentTitle) | $formfield(R&DDeliverable) |$formfield(StateOfDocumentAtGate) | $formfield(Description) |
}%

What do I do wrong?

Thanks Peter

-- PeterSvendsen - 10 Feb 2012

Try something like this (colours only those topics created by ArthurClemens):
%STARTSECTION{"colours"}%
<style>
.classificationSupportQuestion {background-color: red;}
.classificationFrequentlyAskedQuestion {background-color: green;}
.classificationExtensionHub {background-color: blue;}
.classificationSupplementalDoc {background-color: yellow;}
.classificationWikiConsultantTopic {background-color: green;}
.classificationAdminTopic {background-color: orange;}
.boring {font-weight: bold;}
</style>
%SEARCH{
  "TopicClassification"
  type="query"
  pager="on"
  pagesize="25"
  header="| *Topic* | *Classification* | *Creator* |"
  format="| [[$web.$topic][$topic]] | <span class='$percntIF{
    \"'$createusername'='ArthurClemens'\"
    then=\"classification$formfield(TopicClassification)\"
    else=\"boring\"
  }$percnt'>$formfield(TopicClassification)</span> | [[$createwikiusername][$createusername]] |"
}%%ENDSECTION{"colours"}%

Test:

Searched: TopicClassification
Topic Classification Creator
AcronymDefinitionsPlugin ExtensionHub AlexisHazell
ActionTrackerPlugin ExtensionHub CrawfordCurrie
AdminTopic GatewayTopic RafaelAlvarez
ApacheConfigGenerator AdminTopic WillNorris
AvatarPlugin ExtensionHub ArthurClemens
ConsultantServices AdminTopic KoenMartens
ConsultantType AdminTopic KoenMartens
CpanContrib ExtensionHub MichaelDaum
CronAndMailnotifyMailercontribUbuntu FrequentlyAskedQuestion TimHandy
DBIQueryPlugin ExtensionHub VadimBelman
DataStorageInUserCookie SupportQuestion ArthurClemens
DatabaseContrib ExtensionHub VadimBelman
EasyInstallOnCiviHosting SupportQuestion CiviHosting
EditRowPlugin ExtensionHub CrawfordCurrie
ExcelImportExportPlugin ExtensionHub MichaelDaum
ExitPlugin ExtensionHub ArthurClemens
FAQCreateAdminAccount AdminTopic ArthurClemens
FAQExecuteBinFiles AdminTopic ArthurClemens
FAQPubFilesNotLoading AdminTopic ArthurClemens
FSBrowserPlugin ExtensionHub AlexisHazell
Faq0 FrequentlyAskedQuestion ArthurClemens
Faq1 FrequentlyAskedQuestion CrawfordCurrie
Faq10 FrequentlyAskedQuestion ArthurClemens
Faq12 FrequentlyAskedQuestion CrawfordCurrie
Faq13 FrequentlyAskedQuestion GeorgeClark
Number of topics: 25
Page 1 of 6 Next >
-- PaulHarvey - 13 Feb 2012

Thanks SvenDowideit for cleaning up my initial answer.

Peter, does this work for you? If not, set this question back to 'asked'.

-- PaulHarvey - 13 Feb 2012

PeterSvendsen added the following:

The actual case is that I use the this to search for all delivery (documents) for projects and if the documents are mandatory I would like to make them bold or have a colour..... I have adjusted your example above... First.. I search for all documents that must be in either draft or final version at the review... and then I look if the document is a optional or mandatory through the formfield R&DDelivery... if it is mandatoy I try to make it red... (red as test, need to see how it looks, I may change this to be bold only later)

When I test all of the hits gets bold..... so I'm not 100% up and running... still looking into the issue.... smile

%STARTSECTION{"colours"}%
<style>
..classificationMandatory {background-color: red;}
..classificationOptional {background-color: yellow;}
.boring {font-weight: bold;}
</style>
%SEARCH{" (StateOfDocumentAtHWReviewInt='Final' OR 
   StateOfDocumentAtHWReviewInt='Draft (In work)') AND 
   FunctionArea='Design & Test'  AND 
   AreaOwner='Hardware'" 
   web="Documents" nonoise="on" type="query"
  header="| *Title* | *PMP deliverables* | *State At Review* | *Description* |"
  format="| [[$topic][$formfield(DocumentTitle)]] | <span class='$percntIF{
    \"'$R&DDeliverable'='Mandatory'\"
    then=\"classification$formfield(PMPDeliverableAtHWReviewInt)\"
    else=\"boring\"
  }$percnt'>$formfield(PMPDeliverableAtHWReviewInt)</span> | $formfield(StateOfDocumentAtHWReviewInt) | $formfield(Description) | "
}%%ENDSECTION{"colours"}%


Ah, there are three problems that I can see
  • Your <style> markup doesn't seem to be valid css (too many dots). It should be .classification..., not ..classification...
  • I don't think 'R&DDeliverable' is a valid field name. Foswiki probably stores it as 'RDDeliverable', and you should perhaps query it that way.
  • IF{\"'$R&DDeliverable'='Mandatory'\"... will always be false, because you are asking the IF to compare two literal strings (quoted with ' ) which are not the same. The LHS quoted string could be IF{\"'$formfield(RDDeliverable)'='Mandatory'\"... or, if expanding RDDeliverable causes problems, you can ask IF to test it directly, Eg. IF{\"'$web.$topic'/RDDeliverable='Mandatory'\"...
-- PaulHarvey - 13 Feb 2012

Thanks a lot Paul it seems to work very well.. now I get the bold color for mandatory documents. I have 2 additional questions:
  • If I would like to whole line to be bold and not just the PMPDeliverableAtHWReviewInt I would expect the logic to be more simple but agian I run my head into the wall I can not see the solution! The only way I can solve the problem is to copy the IF... for all columbs in the output which I see as a big overhead...
  • In the logic above... when will the line become red or Yellow? I have not seen a case for that yet....?
This works but seems to be a big overhead....

%STARTSECTION{"colours"}%
<style>
.classificationMandatory {background-color: red;}
.classificationOptional {background-color: yellow;}
.boring {font-weight: bold;}
</style>
%SEARCH{" (StateOfDocumentAtHWReviewInt='Final' OR 
   StateOfDocumentAtHWReviewInt='Draft (In work)') AND 
   FunctionArea='Design & Test'  AND 
   AreaOwner='Hardware'" 
   web="Documents" nonoise="on" type="query"
  header="| *Title* | *PMP deliverables* | *State At Review* | *Description* |"
  format="| <span class='$percntIF{\"'$formfield(RDDeliverable)'='Optional'\" 
    then=\"classification$formfield(DocumentTitle)\"
    else=\"boring\"
  }$percnt'>[[$topic][$formfield(DocumentTitle)]] </span> | <span class='$percntIF{\"'$formfield(RDDeliverable)'='Optional'\" 
    then=\"classification$formfield(PMPDeliverableAtHWReviewInt)\"
    else=\"boring\"
  }$percnt'>$formfield(PMPDeliverableAtHWReviewInt)</span> | <span class='$percntIF{\"'$formfield(RDDeliverable)'='Optional'\" 
    then=\"classification$formfield(StateOfDocumentAtHWReviewInt)\"
    else=\"boring\"
  }$percnt'>$formfield(StateOfDocumentAtHWReviewInt)</span> | <span class='$percntIF{\"'$formfield(RDDeliverable)'='Optional'\" 
    then=\"classification$formfield(Description))\"
    else=\"boring\"  }$percnt'>$formfield(Description)</span> | "
}%%ENDSECTION{"colours"}%


-- PeterSvendsen - 13 Feb 2012

  • Hrm, I think if you want better efficiency, you should avoid TML table constructs ( | symbols) and emit HTML directly. That way, you could apply a class for the row (<tr class="boring">...) and use a CSS style like tr.boring td { background-color: red }
  • I'm not sure if you're using this pattern properly - what is 'DocumentTitle' allowed to contain? When we have: class="classification$formfield(Foo)", we want the 'Foo' field to only contain one of several existing possible values; like Mandatory, Optional or Banana. Then, we write definitions for all the possible CSS classes which that field might generate: classificationMandatory, classificationOptional and classificationBana
-- PaulHarvey - 14 Feb 2012

  • It seems that there are room for improvements here.
  • I may not use the pattern properly but would like to optimize it so I dont cause extra work for the application.
  • I have placed a screen shoot how it looks today and how I would like it to look.... I would expect that the red and yellow classes are not needed and can be moved due to the fact that the mandatory documents are highlighted with bold.
  • As you write in your example class="classification$formfield(Foo) I properly use it the wrong way.... could you give me a hint how it then would look like or a place where I can find the information?
  • As you see the DocumentTitle is a title and could therefore easy be "This is a document title"
example.png

-- PeterSvendsen - 15 Feb 2012

Try this:
%STARTSECTION{"colours"}%
<style>
.classificationMandatory {font-weight: bold;}
</style>
%SEARCH{" (StateOfDocumentAtHWReviewInt='Final' OR 
   StateOfDocumentAtHWReviewInt='Draft (In work)') AND 
   FunctionArea='Design & Test'  AND 
   AreaOwner='Hardware'" 
   web="Documents" nonoise="on" type="query"
  header="| *Title* | *PMP deliverables* | *State At Review* | *Description* |"
  format="| <span class='classification$formfield(RDDeliverable)'>[[$topic][$formfield(DocumentTitle)]] </span> \
          | <span class='classification$formfield(RDDeliverable)'>$formfield(PMPDeliverableAtHWReviewInt)</span> \
          | <span class='classification$formfield(RDDeliverable)'>$formfield(StateOfDocumentAtHWReviewInt)</span> \
          | <span class='classification$formfield(RDDeliverable)'>$formfield(Description)</span> |"
}%%ENDSECTION{"colours"}%

-- PaulHarvey - 15 Feb 2012

This is perfect Paul thanks a lot smile

-- PeterSvendsen - 15 Feb 2012
 

QuestionForm edit

Subject Topic Markup Language and applications
Extension
Version Foswiki 1.1.3
Status Task closed
Related Topics
Topic attachments
I Attachment Action Size Date Who Comment
example.pngpng example.png manage 24 K 15 Feb 2012 - 09:18 PeterSvendsen  
Topic revision: r13 - 20 Feb 2012, PeterSvendsen - This page was cached on 22 Jun 2018 - 00:25.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy