Skip to content

Commit

Permalink
Fixes #8844: General improvements on web app ( upgrade all js depende…
Browse files Browse the repository at this point in the history
…ncies, new trees, clean old files )
  • Loading branch information
VinceMacBuche committed Aug 16, 2016
1 parent a633bce commit f127555
Show file tree
Hide file tree
Showing 516 changed files with 29,976 additions and 70,165 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -9,3 +9,5 @@ target*
.cache
*.ldif.log
*configuration.properties
.cache*
.worksheet
3 changes: 2 additions & 1 deletion rudder-web/src/main/scala/bootstrap/liftweb/Boot.scala
Expand Up @@ -44,7 +44,6 @@ import net.liftweb.common._
import net.liftweb.sitemap._
import net.liftweb.sitemap.Loc._
import Helpers._
import net.liftweb.http.js.jquery.JQuery14Artifacts
import net.liftmodules.widgets.autocomplete.AutoComplete
import javax.servlet.UnavailableException
import LiftSpringApplicationContext.inject
Expand Down Expand Up @@ -89,6 +88,8 @@ class Boot extends Loggable {
LiftRules.redirectAsyncOnSessionLoss = false;
//we don't want to retry on ajax timeout, as it may have big consequence
//when it's (for example) a deploy

logger.info(LiftRules.resourceServerPath)
LiftRules.ajaxRetryCount = Full(1)

// where to search snippet
Expand Down
Expand Up @@ -87,7 +87,6 @@ object ChangeRequestChangesForm {
} ) openOr Nil
}


class ChangeRequestChangesForm(
changeRequest:ChangeRequest
) extends DispatchSnippet with Loggable {
Expand All @@ -102,7 +101,6 @@ class ChangeRequestChangesForm(
private[this] val ruleCategoryService = RudderConfig.ruleCategoryService
private[this] val ruleCategoryRepository = RudderConfig.roRuleCategoryRepository


def dispatch = {
case "changes" =>
_ =>
Expand Down Expand Up @@ -153,7 +151,6 @@ class ChangeRequestChangesForm(
val children = Nil
}


val directivesChild = new JsTreeNode{
val changes = changeRequest.directives.values.map(_.changes).toList
val body = SHtml.a(
Expand All @@ -162,7 +159,7 @@ class ChangeRequestChangesForm(
)
val children = changeRequest.directives.keys.map(directiveChild(_)).toList

override val attrs = List(( "rel" -> { "changeType" } ),("id" -> { "directives"}))
override val attrs = List(("data-jstree" -> """{ "type" : "changeType" }"""),("id" -> { "directives"}))
}

def ruleChild(ruleId:RuleId) = new JsTreeNode{
Expand All @@ -183,7 +180,7 @@ class ChangeRequestChangesForm(
, <span>Rules</span>
)
val children = changeRequest.rules.keys.map(ruleChild(_)).toList
override val attrs = List(( "rel" -> { "changeType" } ),("id" -> { "rules"}))
override val attrs = List(("data-jstree" -> """{ "type" : "changeType" }"""),("id" -> { "rules"}))
}

def groupChild(groupId:NodeGroupId) = new JsTreeNode{
Expand All @@ -208,7 +205,7 @@ class ChangeRequestChangesForm(
, <span>Groups</span>
)
val children = changeRequest.nodeGroups.keys.map(groupChild(_)).toList
override val attrs = List(( "rel" -> { "changeType" } ),("id" -> { "groups"}))
override val attrs = List(("data-jstree" -> """{ "type" : "changeType" }"""),("id" -> { "groups"}))
}

def globalParameterChild(paramName:ParameterName) = new JsTreeNode{
Expand All @@ -233,10 +230,9 @@ class ChangeRequestChangesForm(
, <span>Global Parameters</span>
)
val children = changeRequest.globalParams.keys.map(globalParameterChild(_)).toList
override val attrs = List(( "rel" -> { "changeType" } ),("id" -> { "params"}))
override val attrs = List(("data-jstree" -> """{ "type" : "changeType" }"""),("id" -> { "params"}))
}


val body = SHtml.a(
() => SetHtml("history",displayHistory (
rootRuleCategory
Expand All @@ -250,7 +246,7 @@ class ChangeRequestChangesForm(

val children = directivesChild :: rulesChild :: groupsChild :: globalParametersChild :: Nil

override val attrs = List(( "rel" -> { "changeType" } ),("id" -> { "changes"}))
override val attrs = List(("data-jstree" -> """{ "type" : "changeType" }"""),("id" -> { "changes"}))

}

Expand All @@ -272,7 +268,6 @@ class ChangeRequestChangesForm(
rules.flatMap(displayRuleChange(_)) ++
globalParams.flatMap(displayGlobalParameterChange(_))


val initDatatable = JsRaw(s"""
$$('#changeHistory').dataTable( {
"asStripeClasses": [ 'color1', 'color2' ],
Expand Down Expand Up @@ -379,7 +374,6 @@ class ChangeRequestChangesForm(
) (RuleXML)
}


private[this] def displayRuleDiff (
diff : ModifyRuleDiff
, rule : Rule
Expand Down Expand Up @@ -409,7 +403,6 @@ class ChangeRequestChangesForm(
) (RuleXML)
}


private[this] val groupXML =
<div>
<h4>Group overview:</h4>
Expand Down Expand Up @@ -448,7 +441,6 @@ class ChangeRequestChangesForm(
"#isSystem" #> group.isSystem
)(groupXML)


private[this] def displayGroupDiff (
diff : ModifyNodeGroupDiff
, group : NodeGroup
Expand Down Expand Up @@ -732,7 +724,6 @@ class ChangeRequestChangesForm(
displayEvent(action,groupChange.firstChange.actor,groupChange.firstChange.creationDate, groupChange.firstChange.reason.getOrElse(""))
}


def displayDirectiveChange(directiveChange: DirectiveChange) = {
val action = directiveChange.firstChange.diff match {
case a : AddDirectiveDiff => Text(s"Create Directive ${a.directive.name}")
Expand Down
Expand Up @@ -76,13 +76,7 @@ object DirectiveEditForm {
* Any page which contains (or may contains after an ajax request)
* that component have to add the result of that method in it.
*/
def staticInit: NodeSeq =
(for {
xml <- Templates("templates-hidden" :: "components" :: "ComponentDirectiveEditForm" :: Nil)
} yield {
chooseTemplate("component", "staticInit", xml) ++
RuleGrid.staticInit
}) openOr Nil
def staticInit: NodeSeq = RuleGrid.staticInit

private def body =
(for {
Expand Down Expand Up @@ -156,6 +150,7 @@ class DirectiveEditForm(
}

def showForm(): NodeSeq = {
staticInit ++
(
"#container [id]" #> htmlId_policyConf &
"#editForm" #> showDirectiveForm()
Expand Down Expand Up @@ -415,7 +410,7 @@ class DirectiveEditForm(
<h4> Priority </h4>
Priority determines which <b> unique </b> Directive will be applied.
<br/>
Unique Directives can be applied only once (ie. Time Settings), so only the highest priority will be appllied.
Unique Directives can be applied only once (ie. Time Settings), so only the highest priority will be appllied.
<br/>
Highest Priority is 0
</div>
Expand Down
Expand Up @@ -78,8 +78,8 @@ object NodeGroupForm {
}

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

private val saveButtonId = "groupSaveButtonId"

Expand Down Expand Up @@ -149,7 +149,7 @@ class NodeGroupForm(
def initJs : JsCmd = {
JsRaw("correctButtons();")
}

val pendingChangeRequestXml =
<div id="pendingChangeRequestNotification">
<div>
Expand Down Expand Up @@ -305,7 +305,7 @@ class NodeGroupForm(
/*
* Create the confirmation pop-up
*/

private[this] def displayConfirmationPopup(
action : ModificationValidationPopup.Action
, newGroup : NodeGroup
Expand Down Expand Up @@ -335,7 +335,7 @@ class NodeGroupForm(
, xml => JsRaw("$('#confirmUpdateActionDialog').bsModal('hide');") & onFailure
, parentFormTracker = formTracker
)

}

popup.popupWarningMessages match {
Expand Down
Expand Up @@ -103,7 +103,7 @@ class RuleCategoryTree(
val html = newRoot match {
case Full(newRoot) =>
root = newRoot
tree()
<div id={htmlId_RuleCategoryTree}> {tree()}</div>
case eb : EmptyBox =>
val fail = eb ?~! "Could not get root category"
val msg = s"An error occured while refreshing Rule categoriy tree , cause is ${fail.messageChain}"
Expand All @@ -112,7 +112,7 @@ class RuleCategoryTree(
<div class="error">{msg}</div>
</div>
}
SetHtml(htmlId_RuleCategoryTree, html)&
Replace(htmlId_RuleCategoryTree, html)&
selectCategory() &
OnLoad(After(TimeSpan(50), JsRaw("""createTooltip();correctButtons();""")))
}
Expand All @@ -137,10 +137,10 @@ class RuleCategoryTree(
}) match {
case Full((long,short)) =>
val escaped = Utility.escape(short)
JsRaw(s"""
OnLoad(JsRaw(s"""
filter='${escaped}';
filterTableInclude('#grid_rules_grid_zone',filter,include);
""") &
""")) &
SetHtml("categoryDisplay",Text(long)) &
check()
case e: EmptyBox => //Display an error, for now, nothing
Expand Down Expand Up @@ -193,12 +193,14 @@ class RuleCategoryTree(
categoryNode(root).toXml}
</ul> ++
Script(
OnLoad(
After(50,
JsRaw(s"""
${treeFun}('#${htmlId_RuleCategoryTree}','${getSelected.value}','${S.contextPath}');
$$('#${htmlId_RuleCategoryTree}').bind("move_node.jstree", function (e,data) {
var sourceCatId = $$(data.rslt.o).attr("id");
var destCatId = $$(data.rslt.np).attr("id");
console.log(data)

var sourceCatId = data.node.id;
var destCatId = data.parent;
if( destCatId ) {
if( sourceCatId ) {
var arg = JSON.stringify({ 'sourceCatId' : sourceCatId, 'destCatId' : destCatId });
Expand All @@ -219,59 +221,9 @@ class RuleCategoryTree(
private[this] def categoryNode(category : RuleCategory) : JsTreeNode = new JsTreeNode {
val tooltipId = Helpers.nextFuncName

override val attrs = ( "rel" -> "category" ) :: ("id", category.id.value) :: Nil
override val attrs = ("data-jstree" -> """{ "type" : "category" }""") :: ("id", category.id.value) :: Nil

override def body = {
def img(source:String,alt:String) = <img src={"/images/"+source} alt={alt} height="14" width="14" class="iconscala" style=" margin: 0 10px 0 0;float:none;" />

// To handle correctly overflow with floating hidden elements, we need to compute the size of the container first
val manageWidth ={
// No need to compute actionWidth if directive is application
val actionWidth =
if (!isDirectiveApplication) {
s"$$('#${"actions"+category.id.value}').width()"
} else {
" 0"
}
s"""
var widthSpanName = $$('#${category.id.value+"Name"}').width();
var widthActions = ${actionWidth};
// Add size of jstree element (icons, ...) static for now, need a way to compute it ...
var jstreeElems = 40;
$$('#${category.id.value}').width(widthActions + widthSpanName + jstreeElems);"""
}

val jsInitFunction = Script(JsRaw (s"""
${manageWidth}
$$('#${"actions"+category.id.value}').hide();

$$('#${category.id.value}').mouseover( function(e) {
e.stopPropagation();
$$("#treeParent").focus();
$$('#${"actions"+category.id.value}').show();
$$('#${category.id.value} a:first').addClass("treeOver jstree-hovered");
});

$$('#${category.id.value}').hover( function(e) {
$$('.categoryAction').hide();
$$("#treeParent").focus();
$$('.treeOver').removeClass("treeOver jstree-hovered");
$$('#${"actions"+category.id.value}').show();
$$('#${category.id.value} a:first').addClass("treeOver jstree-hovered");
}, function(e) {
$$('.treeOver').removeClass("treeOver jstree-hovered");
$$('#${"actions"+category.id.value}').hide();
} );

$$('#${"edit"+category.id.value}').click( function(e) {
e.stopPropagation();
});
$$('#${"delete"+category.id.value}').click( function(e) {
e.stopPropagation();
});
"""

))

val applyCheckBox = {
directive match {
Expand Down Expand Up @@ -305,9 +257,9 @@ class RuleCategoryTree(
val actionButtons = {
if(!isDirectiveApplication && category.id.value!="rootRuleCategory") {

<span id={"actions"+category.id.value} class="categoryAction" style="float:left; padding-top:1px;padding-left:10px">{
SHtml.span(img("icPen.png","Edit") ,editPopup(category),("id","edit"+category.id.value)) ++
SHtml.span(img("icDelete.png","Delete"),deletePopup(category), ("id","delete"+category.id.value))
<span id={"actions"+category.id.value} class="categoryAction" style="padding-top:1px;padding-left:10px">{
SHtml.span(NodeSeq.Empty,editPopup(category),("id","edit"+category.id.value),("class","fa fa-pencil"), ("style", "margin-right:10px")) ++
SHtml.span(NodeSeq.Empty,deletePopup(category), ("id","delete"+category.id.value),("class","fa fa-trash-o"))
} </span>
} else {
NodeSeq.Empty
Expand All @@ -325,17 +277,11 @@ class RuleCategoryTree(
}
}
val xml = {
<span id={category.id.value+"Name"} tooltipid={tooltipId} title="" class="treeRuleCategoryName tooltipable" style="float:left">
<span id={category.id.value+"Name"} tooltipid={tooltipId} title="" class="treeRuleCategoryName tooltipable" >
{applyCheckBox}{category.name}
</span> ++
{actionButtons} ++
{tooltip} ++
( if (category.id.value!="rootRuleCategory") {
jsInitFunction
} else {
NodeSeq.Empty
}
)
{tooltip}
}
SHtml.a(() => {
selectedCategoryId = category.id
Expand Down
Expand Up @@ -139,8 +139,8 @@ class RuleDisplayer (
{actionButton}
</div>
</lift:authz>
<div id="treeParent" style="overflow:auto; margin-top:10px; max-height:443px;border: 1px #999 ridge; padding-right:15px;">
<div id="categoryTree">
<div id="treeParent" style="overflow:auto; margin-top:10px; max-height:443px;">
<div id="categoryTree" class="tw-bs">
{ruleCategoryTree.tree}
</div>
</div>
Expand Down Expand Up @@ -179,9 +179,9 @@ class RuleDisplayer (
def includeSubCategory = {
SHtml.ajaxCheckbox(
true
, value => JsRaw(s"""
, value => OnLoad(JsRaw(s"""
include=${value};
filterTableInclude('#grid_rules_grid_zone',filter,include); """) & check()
filterTableInclude('#grid_rules_grid_zone',filter,include); """)) & check()
, ("id","includeCheckbox")
)
}
Expand Down
Expand Up @@ -295,7 +295,7 @@ class RuleEditForm(
"#shortDescriptionField" #> crShortDescription.toForm_! &
"#longDescriptionField" #> crLongDescription.toForm_! &
"#selectPiField" #> {
<div id={htmlId_activeTechniquesTree}>{
<div id={htmlId_activeTechniquesTree} class="tw-bs">{
<ul>{
DisplayDirectiveTree.displayTree(
directiveLib = directiveLib
Expand All @@ -312,7 +312,7 @@ class RuleEditForm(
}</ul>
}</div> } &
"#selectGroupField" #> {
<div id={htmlId_groupTree}>
<div id={htmlId_groupTree} class="tw-bs">
<ul>{DisplayNodeGroupTree.displayTree(
groupLib
, None
Expand Down
Expand Up @@ -245,8 +245,8 @@ class ShowNodeDetailsFromNode(
val id = JsNodeId(node.id)
( "#node_name " #> s"${inventory.node.main.hostname} (last updated ${ inventory.node.inventoryDate.map(DateFormaterService.getFormatedDate(_)).getOrElse("Unknown")})" &
"#node_groupTree" #>
<div id={groupTreeId}>
<ul>{DisplayNodeGroupTree.buildTreeKeepingGroupWithNode(groupLib, node)}</ul>
<div id={groupTreeId} class="tw-bs">
<ul>{DisplayNodeGroupTree.buildTreeKeepingGroupWithNode(groupLib, node, None, None, Map(("info", _ => Noop)))}</ul>
</div> &
"#nodeDetails" #> DisplayNode.showNodeDetails(inventory, Some(node.creationDate), AcceptedInventory, isDisplayingInPopup = withinPopup) &
"#nodeInventory *" #> DisplayNode.show(inventory, false) &
Expand Down

0 comments on commit f127555

Please sign in to comment.