Skip to content

Commit

Permalink
Fixes #16337: Node details displays \"search\" form during page loading
Browse files Browse the repository at this point in the history
  • Loading branch information
fanf committed Dec 5, 2019
1 parent b47b858 commit 8254d37
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class LinkUtil (
RedirectTo(baseDirectiveLink(id))

def baseNodeLink(id:NodeId) =
s"""/secure/nodeManager/searchNodes#{"nodeId":"${id.value}"}"""
s"""/secure/nodeManager/node/${id.value}"""

def nodeLink(id:NodeId) =
s"""${S.contextPath}${baseNodeLink(id)}"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ class Boot extends Loggable {
RewriteResponse("secure" :: "administration" :: "techniqueLibraryManagement" :: Nil, Map("techniqueId" -> activeTechniqueId))
case RewriteRequest(ParsePath("secure"::"nodeManager"::"searchNodes"::nodeId::Nil, _, _, _), GetRequest, _) =>
RewriteResponse("secure"::"nodeManager"::"searchNodes"::Nil, Map("nodeId" -> nodeId))
case RewriteRequest(ParsePath("secure"::"nodeManager"::"node"::nodeId::Nil, _, _, _), GetRequest, _) =>
RewriteResponse("secure"::"nodeManager"::"node"::Nil, Map("nodeId" -> nodeId))
}

// Fix relative path to css resources
Expand Down Expand Up @@ -368,6 +370,11 @@ class Boot extends Loggable {
"secure" / "nodeManager" / "searchNodes"
>> LocGroup("nodeGroup")

, Menu("NodeDetails", <span>Node details</span>) /
"secure" / "nodeManager" / "node"
>> LocGroup("nodeGroup")
>> Hidden

, Menu("ManageNewNode", <span>Accept new nodes</span>) /
"secure" / "nodeManager" / "manageNewNode"
>> LocGroup("nodeGroup")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
*************************************************************************************
* Copyright 2018 Normation SAS
*************************************************************************************
*
* This file is part of Rudder.
*
* Rudder is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In accordance with the terms of section 7 (7. Additional Terms.) of
* the GNU General Public License version 3, the copyright holders add
* the following Additional permissions:
* Notwithstanding to the terms of section 5 (5. Conveying Modified Source
* Versions) and 6 (6. Conveying Non-Source Forms.) of the GNU General
* Public License version 3, when you create a Related Module, this
* Related Module is not considered as a part of the work and may be
* distributed under the license agreement of your choice.
* A "Related Module" means a set of sources files including their
* documentation that, without modification of the Source Code, enables
* supplementary functions or services in addition to those offered by
* the Software.
*
* Rudder is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Rudder. If not, see <http://www.gnu.org/licenses/>.
*
*************************************************************************************
*/

package com.normation.rudder.web.snippet.node

import bootstrap.liftweb.RudderConfig
import com.normation.box._
import com.normation.inventory.domain.NodeId
import com.normation.rudder.web.components.ShowNodeDetailsFromNode
import net.liftweb.common._
import net.liftweb.http.S
import net.liftweb.http.StatefulSnippet

/**
*
* Snippet that handle the "searchNodes" page.
*
* Two main feature:
* - diplay details of a node
* - search for nodes based on a query
*
* Node details are ALWAYS load via Ajax (see parseHashtag method).
* Hashtag modification are detected with the hashchange" events,
* supported since ie8/ff3.6/chrome5/safari5 - as to say,
* immemorial times (see http://caniuse.com/hashchange for details)
*
*/

class Node extends StatefulSnippet with Loggable {

private[this] val getFullGroupLibrary = RudderConfig.roNodeGroupRepository.getFullGroupLibrary _

private[this] val groupLibrary = getFullGroupLibrary().toBox match {
case Full(x) => x
case eb:EmptyBox =>
val e = eb ?~! "Major error: can not get the node group library"
logger.error(e.messageChain)
throw new Exception(e.messageChain)
}

var dispatch : DispatchIt = {
case "details" => S.param("nodeId") match {
case eb: EmptyBox =>
_ => <p>No node ID was given in URL. How did you get there?</p>
case Full(nodeId) =>
val displayCompliance = S.param("displayCompliance") match {
case Full("true") => true
case _ => false
}
_ => new ShowNodeDetailsFromNode(new NodeId(nodeId), groupLibrary).display(false, displayCompliance)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import com.normation.rudder.domain.nodes.NodeGroup
import com.normation.rudder.domain.nodes.NodeInfo
import com.normation.rudder.domain.queries.Query
import com.normation.rudder.web.components.SearchNodeComponent
import com.normation.rudder.web.components.ShowNodeDetailsFromNode
import com.normation.rudder.web.components.popup.CreateCategoryOrGroupPopup
import bootstrap.liftweb.RudderConfig
import com.normation.rudder.domain.nodes.NodeGroupId
Expand Down Expand Up @@ -78,7 +77,7 @@ import com.normation.box._

class SearchNodes extends StatefulSnippet with Loggable {

private[this] val queryParser = RudderConfig.cmdbQueryParser
private[this] val queryParser = RudderConfig.cmdbQueryParser
private[this] val getFullGroupLibrary = RudderConfig.roNodeGroupRepository.getFullGroupLibrary _
private[this] val linkUtil = RudderConfig.linkUtil

Expand Down Expand Up @@ -145,8 +144,7 @@ class SearchNodes extends StatefulSnippet with Loggable {

private[this] def setSearchComponent(query:Option[Query]) : SearchNodeComponent = {
def showNodeDetails(nodeId:String, displayCompliance : Boolean) : JsCmd = {
updateLocationHash(nodeId, displayCompliance) &
JsRaw("""scrollToElement("serverDetails", ".rudder_col");""".format(nodeId))
linkUtil.redirectToNodeLink(NodeId(nodeId))
}

val sc = new SearchNodeComponent(
Expand Down Expand Up @@ -179,22 +177,6 @@ class SearchNodes extends StatefulSnippet with Loggable {
* We want to look for #{ "nodeId":"XXXXXXXXXXXX" }
*/
private[this] def parseHashtag(): JsCmd = {
def displayDetails(jsonData: String) = {
import net.liftweb.json._
val json = parse(jsonData)
json \ "nodeId" match {
case JString(nodeId) =>
val displayCompliance = json \ "displayCompliance" match {
case JBool(displayCompliance) => displayCompliance
case _ => false
}
val nodeDetails = new ShowNodeDetailsFromNode(new NodeId(nodeId), groupLibrary).display(false, displayCompliance)
SetHtml("serverDetails", nodeDetails)
case _ =>
SetHtml("serverDetails", NodeSeq.Empty)
}
}

def executeQuery(query:String) : JsCmd = {
val q = queryParser(query)
val sc = setSearchComponent(q)
Expand All @@ -210,10 +192,7 @@ class SearchNodes extends StatefulSnippet with Loggable {
}
}

JsRaw(s"""parseSearchHash(
function(x) { ${SHtml.ajaxCall(JsVar("x"), displayDetails _ )._2.toJsCmd} }
, function(x) { ${SHtml.ajaxCall(JsVar("x") , executeQuery _ )._2.toJsCmd} }
)""")
JsRaw(s"""parseSearchHash(function(x) { ${SHtml.ajaxCall(JsVar("x") , executeQuery _ )._2.toJsCmd} })""")
}

/**
Expand Down Expand Up @@ -243,13 +222,5 @@ class SearchNodes extends StatefulSnippet with Loggable {
JsRaw(s"updateHashString('query', ${q.toJSONString})")
case None => Noop
}

}

private def updateLocationHash(nodeId:String, displayCompliance : Boolean) = {
//JsRaw("""this.window.location.hash = "#" + JSON.stringify({'nodeId':'%s'})""".format(nodeId))
JsRaw(s"updateHashString('nodeId', '${nodeId}')") &
JsRaw(s"updateHashString('displayCompliance', ${displayCompliance})") &
SetHtml("serverDetails", (new ShowNodeDetailsFromNode(new NodeId(nodeId), groupLibrary)).display(false,displayCompliance))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ function createNodeComplianceTable(gridId, data, contextPath, refresh) {
, "fnCreatedCell" : function (nTd, sData, oData, iRow, iCol) {
$(nTd).addClass("listopen");
var editLink = $("<a />");
editLink.attr("href",contextPath +'/secure/nodeManager/searchNodes#{"nodeId":"'+oData.id+'"}');
editLink.attr("href",contextPath +'/secure/nodeManager/node/'+oData.id);
var editIcon = $("<i>");
editIcon.addClass("fa fa-search node-details");
editLink.click(function(e) {e.stopPropagation();});
Expand Down Expand Up @@ -1079,7 +1079,7 @@ function createNodeTable(gridId, data, contextPath, refresh) {
});
elem.attr("href","javascript://");
} else {
elem.attr("href",contextPath+'/secure/nodeManager/searchNodes#{"nodeId":"'+oData.id+'","displayCompliance":'+displayCompliance+'}');
elem.attr("href",contextPath+'/secure/nodeManager/node/'+oData.id+'?displayCompliance='+displayCompliance);
}
return elem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,8 @@ function parseURLHash() {
}
}

function parseSearchHash(nodeIdCallback, queryCallback) {
function parseSearchHash(queryCallback) {
var hash = parseURLHash();
if( hash.nodeId != null && hash.nodeId.length > 0) {
nodeIdCallback(JSON.stringify(hash));
}
if( hash.query != null && JSON.stringify(hash.query).length > 0) {
queryCallback(JSON.stringify(hash.query));
}
Expand Down Expand Up @@ -865,4 +862,4 @@ function toggleMarkdownEditor(id) {

function toggleOpacity(target) {
$(target).toggleClass("half-opacity")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<lift:surround with="common-layout" at="content">

<head>
<title>Rudder - Search Nodes</title>
<link type="text/css" rel="stylesheet" data-lift="with-cached-resource" href="/style/rudder/rudder-tags.css" media="screen">
<link type="text/css" rel="stylesheet" data-lift="with-cached-resource" href="/style/rudder/rudder-node.css" media="screen">
<script type="text/javascript" data-lift="with-cached-resource" src="/javascript/angular/elastic.min.js"></script>
<script type="text/javascript" data-lift="with-cached-resource" src="/javascript/rudder/angular/auditMode.js"></script>
<script type="text/javascript" data-lift="with-cached-resource" src="/javascript/rudder/angular/nodeProperties.js"></script>
</head>

<div class="portlet">
<div class="portlet-header page-title">Nodes</div>
<div class="portlet-content">
<div data-lift="node.SearchNodes.head"></div>
<div class="inner-portlet">
<div class="inner-portlet-content">
<div class="node-tab-content">
<div id="serverDetails">
<div data-lift="node.Node.details"></div>
</div>
</div>
</div>
</div>
</div>
</div>

</lift:surround>
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
<div class="portlet-header page-title">Nodes</div>
<div class="portlet-content">
<div data-lift="node.SearchNodes.head"></div>
<div class="inner-portlet">
<div class="inner-portlet-content">
<div class="node-tab-content">
<div id="serverDetails"></div>
</div>
</div>
</div>
<div class="inner-portlet">
<div class="inner-portlet-content">
<div id="query-search-content">
Expand Down

0 comments on commit 8254d37

Please sign in to comment.