From 96eb76caff3fd16cce1e7e7318417c0d9bd673ad Mon Sep 17 00:00:00 2001 From: fanf Date: Wed, 20 Feb 2013 15:31:35 +0100 Subject: [PATCH] Fixes #3308: display the content of metadata.xml and template.cf for Technique --- .../web/components/TechniqueEditForm.scala | 41 ++++++++++++++++++- .../TechniqueLibraryManagement.scala | 29 +++++++++---- .../ComponentTechniqueEditForm.html | 20 +++++++-- 3 files changed, 78 insertions(+), 12 deletions(-) diff --git a/rudder-web/src/main/scala/com/normation/rudder/web/components/TechniqueEditForm.scala b/rudder-web/src/main/scala/com/normation/rudder/web/components/TechniqueEditForm.scala index 24a46093a9b..528aadc90b0 100644 --- a/rudder-web/src/main/scala/com/normation/rudder/web/components/TechniqueEditForm.scala +++ b/rudder-web/src/main/scala/com/normation/rudder/web/components/TechniqueEditForm.scala @@ -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 { @@ -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._ @@ -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 //////////////////////////// @@ -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 @@ -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 & @@ -515,6 +532,28 @@ class TechniqueEditForm( } + /** + * 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 => Error when reading {filename} + case Some(is) => +
+

{filename.capitalize} file content for {technique.name}

+
{scala.io.Source.fromInputStream(is).getLines.mkString("\n") }
+
+ } + } + /** * Display details about a Technique. * A Technique is in the context of a reference library (it's an error if the Directive diff --git a/rudder-web/src/main/scala/com/normation/rudder/web/snippet/configuration/TechniqueLibraryManagement.scala b/rudder-web/src/main/scala/com/normation/rudder/web/snippet/configuration/TechniqueLibraryManagement.scala index c1e2a3f7d5c..b28736b2a48 100644 --- a/rudder-web/src/main/scala/com/normation/rudder/web/snippet/configuration/TechniqueLibraryManagement.scala +++ b/rudder-web/src/main/scala/com/normation/rudder/web/snippet/configuration/TechniqueLibraryManagement.scala @@ -119,7 +119,11 @@ 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) = { @@ -127,7 +131,12 @@ class TechniqueLibraryManagement extends DispatchSnippet with Loggable { 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. ))) } @@ -319,14 +328,17 @@ class TechniqueLibraryManagement extends DispatchSnippet with Loggable { } } - 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 _ => @@ -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 _ => "" } @@ -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}');") } diff --git a/rudder-web/src/main/webapp/templates-hidden/components/ComponentTechniqueEditForm.html b/rudder-web/src/main/webapp/templates-hidden/components/ComponentTechniqueEditForm.html index 01011f0bd1c..7f9732a0024 100644 --- a/rudder-web/src/main/webapp/templates-hidden/components/ComponentTechniqueEditForm.html +++ b/rudder-web/src/main/webapp/templates-hidden/components/ComponentTechniqueEditForm.html @@ -63,9 +63,17 @@
-

[Technique name]

-
-
+

+ [Technique name] - + [Technique version] +

+ + (Switch to an other version: + ) +

[technique.description]

@@ -117,7 +125,13 @@

[technique.description]

+ + +
+ +
+