Skip to content

Commit

Permalink
Merge pull request #129 from fanf/ust_3306/dev/3308_display_metadata_…
Browse files Browse the repository at this point in the history
…and_template_content_of_technique

Fixes #3308: display the content of metadata.xml and template.cf for Technique
  • Loading branch information
ncharles committed Feb 23, 2013
2 parents 3b071fa + 96eb76c commit 8a1ba5e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ import com.normation.rudder.domain.eventlog.RudderEventActor
import org.joda.time.DateTime
import com.normation.eventlog.ModificationId
import bootstrap.liftweb.RudderConfig
import java.io.InputStream
import com.normation.cfclerk.domain.TechniqueVersion

object TechniqueEditForm {

Expand Down Expand Up @@ -122,7 +124,8 @@ class TechniqueEditForm(
//JS to execute on form success (update UI parts)
//there are call by name to have the context matching their execution when called
onSuccessCallback : () => JsCmd = { () => Noop },
onFailureCallback : () => JsCmd = { () => Noop }
onFailureCallback : () => JsCmd = { () => Noop },
onChangeVersionCallback: TechniqueVersion => JsCmd = { _ => Noop }
) extends DispatchSnippet with Loggable {
import TechniqueEditForm._

Expand Down Expand Up @@ -150,6 +153,7 @@ class TechniqueEditForm(
private[this] var currentActiveTechnique = roActiveTechniqueRepository.getActiveTechnique(technique.id.name)
private[this] var uptCurrentStatusIsActivated = currentActiveTechnique.map( _.isEnabled)

private[this] val otherVersions = techniqueRepository.getTechniqueVersions(technique.id.name) - technique.id.version

//////////////////////////// public methods ////////////////////////////

Expand Down Expand Up @@ -205,6 +209,18 @@ class TechniqueEditForm(
def showCrForm() : NodeSeq = {
(
ClearClearable &
".metadata *" #> showMetadata() &
".templates *" #> showTemplates() &
//change version notification
"#changeVersion" #> ( (xml:NodeSeq) =>
if(otherVersions.size < 1) NodeSeq.Empty
else {
val options = (technique.id.version, "-") +: otherVersions.map( v => (v, v.toString)).toSeq
(
"#techniqueVersionSelect" #> SHtml.ajaxSelectObj(options, Empty, ((v:TechniqueVersion) => onChangeVersionCallback(v)) )
).apply(xml)
}
) &
//all the top level action are displayed only if the template is on the user library
"#userTemplateAction" #> { xml:NodeSeq => currentActiveTechnique match {
case e:EmptyBox => NodeSeq.Empty
Expand All @@ -220,6 +236,7 @@ class TechniqueEditForm(
} }
)(xml)
} } &
"#techniqueVersion" #> technique.id.version.toString &
"#techniqueName" #> technique.name &
"#compatibility" #> (if (!technique.compatible.isEmpty) technique.compatible.head.toHtml else NodeSeq.Empty) &
"#techniqueDescription" #> technique.description &
Expand Down Expand Up @@ -515,6 +532,28 @@ class TechniqueEditForm(
</span>
}

/**
* Display in raw format le metadata.xml
*/
private[this] def showMetadata() : NodeSeq = {
techniqueRepository.getMetadataContent(technique.id)( fileContent("metadata.xml", _) )
}

private[this] def showTemplates() : NodeSeq = {
technique.templates.flatMap( tml => techniqueRepository.getTemplateContent(tml.id)( fileContent(tml.id.toString, _) ) )
}

private[this] def fileContent(filename: String, opt:Option[InputStream]) : NodeSeq = {
opt match {
case None => <span class="error">Error when reading {filename}</span>
case Some(is) =>
<div style="padding=10px">
<h3>{filename.capitalize} <span onclick="$(this).closest('div').find('pre').toggle();" style="text-decoration:underline; cursor:pointer">file content</span> for {technique.name}</h3>
<pre style="display:none; font-size:9px; overflow:scroll">{scala.io.Source.fromInputStream(is).getLines.mkString("\n") }</pre>
</div>
}
}

/**
* Display details about a Technique.
* A Technique is in the context of a reference library (it's an error if the Directive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,24 @@ class TechniqueLibraryManagement extends DispatchSnippet with Loggable {
private[this] val currentTechniqueDetails = new LocalSnippet[TechniqueEditForm]
private[this] var currentTechniqueCategoryDetails = new LocalSnippet[TechniqueCategoryEditForm]

private[this] val techniqueId: Box[String] = S.param("techniqueId")
private[this] val name: Box[String] = S.param("techniqueId")

//for version update
private[this] var newTechniqueName : Option[TechniqueName] = name.map(TechniqueName(_))
private[this] var newTechniqueVersion : Option[TechniqueVersion] = None

//create a new Technique edit form and update currentTechniqueDetails
private[this] def updateCurrentTechniqueDetails(technique:Technique) = {
currentTechniqueDetails.set(Full(new TechniqueEditForm(
htmlId_editForm,
technique,
currentTechniqueCategoryDetails.is.map( _.getCategory ),
{ () => Replace(htmlId_activeTechniquesTree, userLibrary) }
{ () => Replace(htmlId_activeTechniquesTree, userLibrary) },
onChangeVersionCallback = { (v:TechniqueVersion) => {
newTechniqueName = Some(technique.id.name)
newTechniqueVersion = Some(v)
SetHtml(htmlId_bottomPanel, showBottomPanel )
} }
//we don't need/want an error callback here - the error is managed in the form.
)))
}
Expand Down Expand Up @@ -319,14 +328,17 @@ class TechniqueLibraryManagement extends DispatchSnippet with Loggable {
}</div>
}

def showBottomPanel : NodeSeq = {
def showBottomPanel() : NodeSeq = {
(for {
ptName <- techniqueId
technique <- techniqueRepository.getLastTechniqueByName(TechniqueName(ptName))
name <- newTechniqueName
technique <- newTechniqueVersion match {
case Some(v) => techniqueRepository.get(TechniqueId(name, v))
case None => techniqueRepository.getLastTechniqueByName(name)
}
} yield {
technique
}) match {
case Full(technique) =>
case Some(technique) =>
updateCurrentTechniqueDetails(technique)
showTechniqueDetails()
case _ =>
Expand Down Expand Up @@ -523,7 +535,7 @@ class TechniqueLibraryManagement extends DispatchSnippet with Loggable {
*/
private[this] def buildReferenceLibraryJsTree : JsExp = JsRaw(
"""buildReferenceTechniqueTree('#%s','%s','%s')""".format(htmlId_techniqueLibraryTree,{
techniqueId match {
name match {
case Full(activeTechniqueId) => "ref-technique-"+activeTechniqueId
case _ => ""
}
Expand All @@ -545,7 +557,8 @@ class TechniqueLibraryManagement extends DispatchSnippet with Loggable {
updateCurrentTechniqueDetails(technique)

//update UI
SetHtml(htmlId_bottomPanel, showTechniqueDetails() )
SetHtml(htmlId_bottomPanel, showTechniqueDetails() ) &
JsRaw(s"scrollToElement('${htmlId_bottomPanel}');")
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,17 @@

<div class="groupedEditZone">
<div class="groupDiv">
<h3><span id="techniqueName">[Technique name]</span></h3>
<div class="groupDiv">
</div>
<h3 style="display:inline;padding-right:20px">
<span id="techniqueName">[Technique name]</span> -
<span id="techniqueVersion">[Technique version]</span>
</h3>
<span class="groupDiv" id="changeVersion">
(Switch to an other version:
<select id="techniqueVersionSelect">
<option>1.0</option>
<option>2.0</option>
</select>)
</span>
<h4><span id="techniqueDescription">[technique.description]</span></h4>
</div>

Expand Down Expand Up @@ -117,7 +125,13 @@ <h4><span id="techniqueDescription">[technique.description]</span></h4>
</fieldset>

</div>

</fieldset>

<div class="metadata"/>

<div class="templates"/>

</div>

</component:form>
Expand Down

0 comments on commit 8a1ba5e

Please sign in to comment.