Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #7016: Adapt Rudder to Scala 2.11 and Lift 2.6 #896

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions rudder-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/agpl.html>.

<dependency>
<groupId>com.typesafe.slick</groupId>
<artifactId>slick_2.10</artifactId>
<artifactId>slick_${scala-binary-version}</artifactId>
<version>2.1.0</version>
</dependency>
<!-- slick postgresql support: https://github.com/tminglei/slick-pg -->
<dependency>
<groupId>com.github.tminglei</groupId>
<artifactId>slick-pg_2.10</artifactId>
<artifactId>slick-pg_${scala-binary-version}</artifactId>
<version>0.6.3</version>
</dependency>
<dependency>
<groupId>com.github.tminglei</groupId>
<artifactId>slick-pg_joda-time_2.10</artifactId>
<artifactId>slick-pg_joda-time_${scala-binary-version}</artifactId>
<version>0.6.3</version>
</dependency>

Expand Down
4 changes: 2 additions & 2 deletions rudder-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/agpl.html>.

<dependency>
<groupId>net.liftmodules</groupId>
<artifactId>widgets_2.5_${scala-binary-version}</artifactId>
<version>1.3</version>
<artifactId>widgets_2.6_${scala-binary-version}</artifactId>
<version>1.4-SNAPSHOT</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to do something for that, we can't rely on snapshot

</dependency>

<!-- it seems to not be resolved, don't know why -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class AsyncDeployment extends CometActor with CometListener with Loggable {
private[this] val eventList = RudderConfig.eventListDisplayer
private[this] val uuidGen = RudderConfig.stringUuidGenerator


//current states of the deployment
private[this] var deploymentStatus = DeploymentStatus(NoStatus, IdleDeployer)

Expand All @@ -101,7 +100,6 @@ class AsyncDeployment extends CometActor with CometListener with Loggable {
new RenderOut(layout)
}


val deployementErrorMessage = """(.*)!errormessage!(.*)""".r

private[this] def statusIcon : NodeSeq = {
Expand All @@ -122,7 +120,6 @@ class AsyncDeployment extends CometActor with CometListener with Loggable {

}


private[this] def lastStatus = {

deploymentStatus.current match {
Expand Down Expand Up @@ -170,14 +167,16 @@ class AsyncDeployment extends CometActor with CometListener with Loggable {

private[this] def layout = {

<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<span>Status</span> <span class="badge" id="generation-status"> {statusIcon}</span><span class="caret" style="margin-left:5px"></span></a>
<ul class="dropdown-menu" role="menu">
{lastStatus}
<li>{currentStatus}</li>
</ul>
</li>
<lift:authz role="deployment_read">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems to be a real bug correction, no ? Deserve its own ticket, I think

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact its has changed because I removed the lift:authz in common-layout to fix the comet actor correctly and ada it back here, so I don't think it needs it specific bug (lift:authz elem are not accepted in ul html5...

<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<span>Status</span> <span class="badge" id="generation-status"> {statusIcon}</span><span class="caret" style="margin-left:5px"></span></a>
<ul class="dropdown-menu" role="menu">
{lastStatus}
<li>{currentStatus}</li>
</ul>
</li>
</lift:authz>
}

private[this] def errorPopup = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ object NodeGroupForm {
xml
}

val staticInit = chooseXml("staticInit")
val staticBody = chooseXml("staticBody")
val staticInit = chooseXml("staticinit")
val staticBody = chooseXml("staticbody")
val body = chooseXml("body")

private val saveButtonId = "groupSaveButtonId"
Expand Down Expand Up @@ -177,13 +177,13 @@ class NodeGroupForm(
)

bind("group", html,
"pendingChangeRequest" -> PendingChangeRequestDisplayer.checkByGroup(pendingChangeRequestXml,nodeGroup.id, workflowEnabled),
"pendingchangerequest" -> PendingChangeRequestDisplayer.checkByGroup(pendingChangeRequestXml,nodeGroup.id, workflowEnabled),
"name" -> groupName.toForm_!,
"rudderID" -> <div><b class="threeCol">Rudder ID: </b>{nodeGroup.id.value}</div>,
"rudderid" -> <div><b class="threeCol">Rudder ID: </b>{nodeGroup.id.value}</div>,
"description" -> groupDescription.toForm_!,
"container" -> groupContainer.toForm_!,
"static" -> groupStatic.toForm_!,
"showGroup" -> (searchNodeComponent.is match {
"showgroup" -> (searchNodeComponent.is match {
case Full(req) => req.buildQuery
case eb:EmptyBox => <span class="error">Error when retrieving the request, please try again</span>
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import com.normation.rudder.domain.queries.OstypeComparator
import net.liftweb.util.ToJsCmd
import bootstrap.liftweb.RudderConfig
import com.normation.rudder.domain.RudderLDAPConstants.A_NODE_PROPERTY
import scala.collection.mutable.{Map => MutMap}

/**
* The Search Nodes component
Expand All @@ -81,7 +82,7 @@ class SearchNodeComponent(
, onSearchCallback : (Boolean, Option[Query]) => JsCmd = {(_, _) => Noop } // this callback is used when a research is done and the state of the Search button changes
, saveButtonId : String = "" // the id of the save button, that gets disabled when one change the form
, groupPage : Boolean
)extends DispatchSnippet with Loggable {
) extends DispatchSnippet with Loggable {
import SearchNodeComponent._

//our local copy of things we work on
Expand All @@ -101,7 +102,18 @@ class SearchNodeComponent(
case Full(n) => n
}

private[this] def searchNodes = chooseTemplate("query","SearchNodes",serverPortletTemplateFile)
private[this] def searchNodes = chooseTemplate("query","searchnodes",serverPortletTemplateFile)
private[this] def queryline = {
<tr class="error"></tr>
<tr class="query_line querylinecolor">
<td class="first objectType"></td>
<td class="attributeName"></td>
<td class="comparator"></td>
<td class="inputValue"></td>
<td class="removeLine"></td>
<td class="last addLine"></td>
</tr>
}
private[this] def content = chooseTemplate("content","query",searchNodes)


Expand All @@ -123,7 +135,6 @@ class SearchNodeComponent(

var dispatch : DispatchIt = {
case "showQuery" => { _ => buildQuery }
case "head" => { _ => head() }
}

var initUpdate = true // this is true when we arrive on the page, or when we've done an search
Expand All @@ -132,16 +143,7 @@ class SearchNodeComponent(
//activate the global save button
var searchFormHasError = false

val errors = Buffer[Box[String]]()

def head() : NodeSeq = {
<head>
{
srvGrid.head
}
</head>
}

val errors = MutMap[CriterionLine,String]()

def buildQuery : NodeSeq = {

Expand All @@ -157,17 +159,25 @@ class SearchNodeComponent(
lines.insert(i+1, lines(i).copy(value = ""))
} else {
//defaults values
lines.insert(i+1, CriterionLine(ditQueryData.criteriaMap(OC_NODE),ditQueryData.criteriaMap(OC_NODE).criteria(0),ditQueryData.criteriaMap(OC_NODE).criteria(0).cType.comparators(0)))
lines.insert(i+1, defaultLine)
}
query = Some(Query(rType, composition, lines.toSeq))
query = Some(Query(rType, composition, lines.to[Seq]))
initUpdate = false
ajaxCriteriaRefresh
}

def removeLine(i:Int) : JsCmd ={
if(lines.size > i) {

val line = lines(i)
lines.remove(i)
query = Some(Query(rType, composition, lines.toSeq))
// Remove error notifications if there is no more occurrences of the line
// Or new lines with that will always have th error message (ie An empty hostname)
if ( ! lines.contains(line)) {
errors remove line
}

query = Some(Query(rType, composition, lines.to[Seq]))
}
initUpdate = false
ajaxCriteriaRefresh
Expand All @@ -176,16 +186,15 @@ class SearchNodeComponent(
def processForm() : JsCmd = {
//filter on non validate values
errors.clear()
lines.zipWithIndex.foreach { case (CriterionLine(ot,a,c,v),i) =>
if(errors.size < i+1) errors.append(Empty)
lines.zipWithIndex.foreach { case (cl@CriterionLine(_,a,c,v),i) =>
a.cType.validate(v,c.id) match {
case Failure(m,_,_) => errors(i) = Full(m)
case _ => errors(i) = Empty
case Failure(m,_,_) => errors put (cl,m)
case _ =>
}
}
val newQuery = Query(rType, composition, lines.toSeq)
val newQuery = Query(rType, composition, lines.to[Seq])
query = Some(newQuery)
if(errors.filter(_.isDefined).size == 0) {
if(errors.size == 0) {
// ********* EXECUTE QUERY ***********
srvList = queryProcessor.process(newQuery)
initUpdate = true
Expand All @@ -202,72 +211,84 @@ class SearchNodeComponent(
* Refresh the query parameter part
*/
def ajaxCriteriaRefresh : JsCmd = {
SetHtml("SearchForm", displayQuery(content))& activateButtonOnChange & JsRaw("correctButtons();")
lines.clear()
SetHtml("SearchForm", displayQuery(content))& activateButtonOnChange & JsRaw("correctButtons();")
}


def displayQueryLine(cl : CriterionLine, index:Int, addRemove:Boolean) : NodeSeq = {

lines.append(cl)

val initJs = cl.attribute.cType.initForm("v_"+index)
val inputAttributes = ("id","v_"+index) :: ("class", "queryInputValue") :: {if (cl.comparator.hasValue) Nil else ("disabled", "disabled") :: Nil }
val input = cl.attribute.cType.toForm(cl.value, (x => lines(index) = lines(index).copy(value=x)), inputAttributes:_*)
( ".removeLine *" #> {
if(addRemove)
SHtml.ajaxSubmit("-", () => removeLine(index), ("class", "removeLineButton"))
else
NodeSeq.Empty
} &
".addLine *" #> SHtml.ajaxSubmit("+", () => addLine(index), ("class", "removeLineButton")) &
".objectType *" #> objectTypeSelect(cl.objectType,lines,index) &
".attributeName *" #> attributeNameSelect(cl.objectType,cl.attribute,lines,index) &
".comparator *" #> comparatorSelect(cl.objectType,cl.attribute,cl.comparator,lines,index) &
".inputValue *" #> input &
".error" #> { errors.get(cl) match {
case Some(m) => <tr><td class="error" colspan="6">{m}</td></tr>
case _ => NodeSeq.Empty
}}

).apply { queryline } ++ Script(OnLoad(initJs))

}

/**
* Display the query part
* Caution, we pass an html different at the init part (whole content:query) or at update (update:query)
*
*/
def displayQuery(html: NodeSeq) = {
val Query(otName,comp, criteria) = query.get
bind("query", html,
"typeQuery" -> <label>Include Rudder server components: <span class="compositionCheckbox">{SHtml.checkbox(rType==NodeAndPolicyServerReturnType, { value:Boolean =>
if (value)
rType = NodeAndPolicyServerReturnType
else
rType = NodeReturnType}
)}</span></label>,
"composition" -> SHtml.radio(Seq("AND", "OR"), Full(if(comp == Or) "OR" else "AND"), {value:String =>
composition = CriterionComposition.parse(value).getOrElse(And) //default to AND on unknown composition string
}, ("class", "radio")).flatMap(e => <label>{e.xhtml} <span class="radioTextLabel">{e.key.toString}</span></label>),
"lines" -> {(ns: NodeSeq) =>
/*
* General remark :
* - bind parameter of closure to lines (so that they actually get the current value of the line when evaluated)
* - bind parameter out of closure to ot/a/c/v so that they have the current value (and not a past one)
*/

{
criteria.zipWithIndex.flatMap { case (CriterionLine(ot,a,c,v),i) =>

for(j <- lines.size to i) {
lines.append(defaultLine)
}
for(j <- errors.size to i) {
errors.append(Empty)
}
bind("line",ns,
"removeLine" -> {
if(criteria.size <= 1)
NodeSeq.Empty
val checkBox = {
SHtml.checkbox(
rType==NodeAndPolicyServerReturnType
, { value:Boolean =>
if (value)
rType = NodeAndPolicyServerReturnType
else
SHtml.ajaxSubmit("-", () => removeLine(i), ("class", "removeLineButton"))
},
"addline" ->
SHtml.ajaxSubmit("+", () => addLine(i), ("class", "removeLineButton")),
"objectType" -> objectTypeSelect(ot,lines,i),
"attributeName" -> attributeNameSelect(ot,a,lines,i),
"comparator" -> comparatorSelect(ot,a,c,lines,i),
"inputValue" -> {
var form = a.cType.toForm(v, (x => lines(i) = lines(i).copy(value=x)), ("id","v_"+i), ("class", "queryInputValue"))
if(!c.hasValue) form = form % Attribute("disabled",Seq(Text("disabled")),Null)
form
} ,
"error" -> { errors(i) match {
case Full(m) => <tr><td class="error" colspan="6">{m}</td></tr>
case _ => NodeSeq.Empty
}}
)
}:NodeSeq} ++ { if(criteria.size > 0) {
rType = NodeReturnType
}
, ("id", "typeQuery")
, ( "class", "compositionCheckbox")
)
}

val radio = {
SHtml.radio(
Seq("AND", "OR")
, Full(if(comp == Or) "OR" else "AND")
, {value:String => composition = CriterionComposition.parse(value).getOrElse(And)} //default to AND on unknown composition string
, ("class", "radio")
).flatMap(radio =>
<label>
{radio.xhtml}
<span class="radioTextLabel">{radio.key.toString}</span>
</label>
)
}

( "#typeQuery" #> checkBox &
"#composition" #> radio &
"#submitSearch * " #> SHtml.ajaxSubmit("Search", processForm, ("id" -> "SubmitSearch"), ("class" -> "submitButton")) &
"#query_lines *" #> criteria.zipWithIndex.flatMap { case (cl,i) => displayQueryLine(cl,i, criteria.size > 1)}
).apply(html
/*}:NodeSeq} ++ { if(criteria.size > 0) {
//add a <script> tag to init all specific Js form renderer, like Jquery datepicker for date
val initJs = criteria.zipWithIndex.map { case (criteria,index) => criteria.attribute.cType.initForm("v_"+index)}
Script(OnLoad(initJs))
} else NodeSeq.Empty}
},
"submit" -> SHtml.ajaxSubmit("Search", processForm, ("id" -> "SubmitSearch"), ("class" -> "submitButton"))
},*/
) ++ Script(OnLoad(JsVar("""
$(".queryInputValue").keydown( function(event) {
processKey(event , 'SubmitSearch')
Expand All @@ -282,7 +303,7 @@ class SearchNodeComponent(
def showQueryAndGridContent() : NodeSeq = {
bind("content",searchNodes,
"query" -> {x:NodeSeq => displayQuery(x)},
"gridResult" -> srvGrid.displayAndInit(Seq(),"serverGrid") // we need to set something, or IE moans
"gridresult" -> srvGrid.displayAndInit(Seq(),"serverGrid") // we need to set something, or IE moans
)
}

Expand Down
Loading