Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelGauthier committed Jan 8, 2020
1 parent 51a911d commit 05f7775
Show file tree
Hide file tree
Showing 13 changed files with 373 additions and 315 deletions.
Expand Up @@ -273,7 +273,7 @@ class NodeGroupCategoryForm(

private[this] def onFailure : JsCmd = {
formTracker.addFormError(error("There was problem with your request."))
updateFormClientSide & JsRaw("""scrollToElement("notifications","#groupDetails");""")
updateFormClientSide & JsRaw("""scrollToElement("notifications","#ajaxItemContainer");""")
}

private[this] def onSubmit() : JsCmd = {
Expand Down
Expand Up @@ -180,85 +180,83 @@ class NodeGroupForm(
val rules = dependencyService.targetDependencies(target).map( _.rules.toSet.filter(!_.isSystem).map(_.id)).toOption
RuleGrid.staticInit ++ ruleGrid.rulesGridWithUpdatedInfo(None, false, false) ++ Script(OnLoad(ruleGrid.asyncDisplayAllRules(rules).applied))
}

private[this] val groupNameString = nodeGroup.fold(
t => rootCategory.allTargets.get(t).map(_.name).getOrElse(t.target)
, _.name
)
private[this] def showFormNodeGroup(nodeGroup: NodeGroup): CssSel = {
val nodesSel = "#gridResult" #> NodeSeq.Empty
val nodes = nodesSel(searchNodeComponent.get match {
case Full(req) => req.buildQuery
case eb:EmptyBox => <span class="error">Error when retrieving the request, please try again</span>
})
(
"group-pendingchangerequest" #> PendingChangeRequestDisplayer.checkByGroup(pendingChangeRequestXml,nodeGroup.id)
"#group-name" #> groupNameString
& "group-pendingchangerequest" #> PendingChangeRequestDisplayer.checkByGroup(pendingChangeRequestXml,nodeGroup.id)
& "group-name" #> groupName.toForm_!
& "group-rudderid" #> <div class="form-group row">
<label class="wbBaseFieldLabel">Rudder ID</label>
<input readonly="" class="form-control" value={nodeGroup.id.value}/>
</div>
& "group-cfeclasses" #> <div class="form-group row">
<a href="#" onclick={s"$$('#cfe-${nodeGroup.id.value}').toggle(300);$$(this).toggleClass('open');return false;"} class="toggle-caret">
<label class="wbBaseFieldLabel">Display agent conditions</label>
<span class="caret"></span>
</a>
<div class="well row" style="display: none" id={s"cfe-${nodeGroup.id.value}"}>
{RuleTarget.toCFEngineClassName(nodeGroup.id.value)}<br/>
{RuleTarget.toCFEngineClassName(nodeGroup.name)}
<label class="wbBaseFieldLabel">Agent conditions</label>
<div class="well" id={s"cfe-${nodeGroup.id.value}"}>
{RuleTarget.toCFEngineClassName(nodeGroup.id.value)}<br/>
{RuleTarget.toCFEngineClassName(nodeGroup.name)}
</div>
</div>
</div>
& "#longDescriptionField *" #> (groupDescription.toForm_! ++ Script(OnLoad(JsRaw(s"""setupMarkdown(${Str(nodeGroup.description).toJsCmd}, "longDescriptionField")"""))))
& "group-container" #> groupContainer.toForm_!
& "group-static" #> groupStatic.toForm_!
& "group-showgroup" #> (searchNodeComponent.get match {
case Full(req) => req.buildQuery
case eb:EmptyBox => <span class="error">Error when retrieving the request, please try again</span>
})
& "group-showgroup" #> nodes
& "group-clone" #> { if (CurrentUser.checkRights(AuthorizationType.Group.Write))
SHtml.ajaxButton("Clone", () => showCloneGroupPopup()) % ("id" -> "groupCloneButtonId") % ("class" -> " btn btn-default")
else NodeSeq.Empty
}
& "group-save" #> { if (CurrentUser.checkRights(AuthorizationType.Group.Edit))
<div tooltipid="saveButtonToolTip" class="tooltipable" title=""> {
<span tooltipid="saveButtonToolTip" class="tooltipable" title=""> {
SHtml.ajaxSubmit("Save", onSubmit _) % ("id" -> saveButtonId) % ("class" -> " btn btn-success")
} </div>
} </span>
else NodeSeq.Empty
}
& "group-delete" #> SHtml.ajaxButton("Delete", () => onSubmitDelete(), ("class" -> " btn btn-danger"))
& "group-notifications" #> updateAndDisplayNotifications()
& "#groupRuleTabsContent" #> showRulesForTarget(GroupTarget(nodeGroup.id))
& "#group-shownodestable *" #> (searchNodeComponent.get match {
case Full(req) => req.displayNodesTable
case eb:EmptyBox => <span class="error">Error when retrieving the request, please try again</span>
})
)
}

private[this] def showFormTarget(target: SimpleTarget): CssSel = {
// we want to remove the query part which doesn't mean anything for
// system group
val nodesSel = "#SearchForm" #> NodeSeq.Empty
val nodes = nodesSel(searchNodeComponent.get match {
case Full(req) => req.buildQuery
case eb:EmptyBox => <span class="error">Error when retrieving the request, please try again</span>
})

(
"group-pendingchangerequest" #> NodeSeq.Empty
& "group-name" #> groupName.readOnlyValue
& "group-rudderid" #> <div class="form-group row">
<label class="wbBaseFieldLabel">Rudder ID</label>
<input readonly="" class="form-control" value={target.target}/>
</div>
& "group-cfeclasses" #> NodeSeq.Empty
& "#longDescriptionField" #> (groupDescription.toForm_! ++ Script(JsRaw(s"""setupMarkdown("", "longDescriptionField")""")))
& "group-container" #> groupContainer.readOnlyValue
& "group-static" #> NodeSeq.Empty
& "group-showgroup" #> nodes
& "group-clone" #> NodeSeq.Empty
& "group-save" #> NodeSeq.Empty
& "group-delete" #> NodeSeq.Empty
& "group-notifications" #> NodeSeq.Empty
& "#groupRuleTabsContent" #> showRulesForTarget(target)
( "group-pendingchangerequest" #> NodeSeq.Empty
& "group-name" #> groupName.readOnlyValue
& "group-rudderid" #> <div class="form-group row">
<label class="wbBaseFieldLabel">RUDDER ID</label>
<input readonly="" class="form-control" value={target.target}/>
</div>
& "group-cfeclasses" #> NodeSeq.Empty
& "#longDescriptionField" #> (groupDescription.toForm_! ++ Script(JsRaw(s"""setupMarkdown("", "longDescriptionField")""")))
& "group-container" #> groupContainer.readOnlyValue
& "group-static" #> NodeSeq.Empty
& "group-showgroup" #> NodeSeq.Empty
& "group-clone" #> NodeSeq.Empty
& "group-save" #> NodeSeq.Empty
& "group-delete" #> NodeSeq.Empty
& "group-notifications" #> NodeSeq.Empty
& "#groupRuleTabsContent" #> showRulesForTarget(target)
& "#group-shownodestable *" #> (searchNodeComponent.get match {
case Full(req) => req.displayNodesTable
case eb:EmptyBox => <span class="error">Error when retrieving the request, please try again</span>
})
)

}

///////////// fields for category settings ///////////////////

private[this] val groupName = {
val name = nodeGroup.fold(
t => rootCategory.allTargets.get(t).map(_.name).getOrElse(t.target)
, _.name
)
new WBTextField("Group name", name) {
new WBTextField("Group name", groupNameString) {
override def setFilter = notNull _ :: trim _ :: Nil
override def className = "form-control"
override def labelClassName = ""
Expand Down Expand Up @@ -309,13 +307,13 @@ class NodeGroupForm(
}
) {
override def setFilter = notNull _ :: trim _ :: Nil
override def className = ""
override def className = "switch"
override def labelClassName = ""
override def subContainerClassName = ""
}
}

private[this] val groupContainer = new WBSelectField("Group container",
private[this] val groupContainer = new WBSelectField("Category",
(categoryHierarchyDisplayer.getCategoriesHierarchy(rootCategory, None).map { case (id, name) => (id.value -> name)}),
parentCategoryId.value) {
override def className = "form-control"
Expand All @@ -333,7 +331,7 @@ class NodeGroupForm(

private[this] def onFailure : JsCmd = {
formTracker.addFormError(error("There was problem with your request."))
updateFormClientSide() & JsRaw("""scrollToElement("errorNotification","#groupDetails");""")
updateFormClientSide() & JsRaw("""scrollToElement("errorNotification","#ajaxItemContainer");""")
}

private[this] def onSubmit() : JsCmd = {
Expand Down
Expand Up @@ -95,7 +95,10 @@ class SearchNodeComponent(
List("templates-hidden", "server", "server_details")
, "query-searchnodes"
)

private[this] def nodesTable = ChooseTemplate(
List("templates-hidden", "server", "server_details")
, "nodes-table"
)
private[this] def queryline = {
<tr class="error"></tr>
<tr class="query_line">
Expand Down Expand Up @@ -212,15 +215,15 @@ class SearchNodeComponent(
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 inputAttributes = ("id","v_"+index) :: ("class", "queryInputValue form-control input-sm") :: {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 btn btn-default btn-xs"))
SHtml.ajaxSubmit("-", () => removeLine(index), ("class", "removeLineButton btn btn-danger btn-xs"))
else
NodeSeq.Empty
} &
".addLine *" #> SHtml.ajaxSubmit("+", () => addLine(index), ("class", "removeLineButton btn btn-default btn-xs")) &
".addLine *" #> SHtml.ajaxSubmit("+", () => addLine(index), ("class", "removeLineButton btn btn-success btn-xs")) &
".objectType *" #> objectTypeSelect(cl.objectType,lines,index) &
".attributeName *" #> attributeNameSelect(cl.objectType,cl.attribute,lines,index) &
".comparator *" #> comparatorSelect(cl.objectType,cl.attribute,cl.comparator,lines,index) &
Expand Down Expand Up @@ -300,6 +303,16 @@ class SearchNodeComponent(
showQueryAndGridContent() ++ Script(OnLoad(ajaxGridRefresh))
}

def displayNodesTable: NodeSeq = {
def showQueryAndGridContent() : NodeSeq = {
(
"content-query" #> NodeSeq.Empty
& "update-nodestable" #> srvGrid.displayAndInit(Seq(),"groupNodesTable") // we need to set something, or IE moans
)(nodesTable)
}
showQueryAndGridContent() ++ Script(OnLoad(ajaxNodesTableRefresh))
}

/**
* Refresh the grid result
* A small trick of the trade : since the Showing x of xx is moved out of the ajax refresh
Expand All @@ -310,7 +323,20 @@ class SearchNodeComponent(
activateButtonOnChange &
gridResult
}
def ajaxNodesTableRefresh() : JsCmd = {
srvList match {
case Full(seq) =>
val refresh = srvGrid.refreshData(() => seq, onClickCallback, "groupNodesTable")
JsRaw(s"""(${refresh.toJsCmd}());createTooltip();""")

case Empty =>
Noop

case f@Failure(_,_,_) =>
logger.error(s"Could not update node table result cause is: ${f.msg}" )
Noop
}
}
/**
* When we change the form, we can update the query
* @return
Expand Down Expand Up @@ -541,7 +567,7 @@ object SearchNodeComponent {
}),
("id","ot_"+i),
("onchange", ajaxAttr(lines,i)._2.toJsCmd),
("class","selectField")
("class","selectField form-control input-sm")

)
}
Expand All @@ -555,7 +581,7 @@ object SearchNodeComponent {
}),
("id","at_"+i),
("onchange", ajaxComp(lines,i)._2.toJsCmd),
("class","selectField")
("class","selectField form-control input-sm")
)
}

Expand All @@ -568,7 +594,7 @@ object SearchNodeComponent {
}),
("id","ct_"+i),
("onchange", ajaxVal(lines,i)._2.toJsCmd),
("class","selectComparator")
("class","selectComparator form-control input-sm")
)
}

Expand Down
Expand Up @@ -317,12 +317,6 @@ class Groups extends StatefulSnippet with DefaultExtendableSnippet[Groups] with
$$.jstree.rollback(data.rlbk);
}
});
adjustHeight('#groupsTree');
adjustHeight('#groupDetails');
$$(window).on('resize',function(){
adjustHeight('#groupsTree');
adjustHeight('#groupDetails');
});
"""))
)}
}
Expand Down Expand Up @@ -427,7 +421,7 @@ class Groups extends StatefulSnippet with DefaultExtendableSnippet[Groups] with
selectedCategoryId = Full(category.id)
//update UI - no modification here, so no refreshGroupLib
refreshRightPanel(CategoryForm(category)) &
JsRaw("""$('#groupDetails').show();""")
JsRaw("""$('#ajaxItemContainer').show();""")
}

//adaptater
Expand All @@ -440,10 +434,9 @@ class Groups extends StatefulSnippet with DefaultExtendableSnippet[Groups] with
}
refreshRightPanel(GroupForm(g, parentCategoryId))&
JsRaw(s"""
jQuery('#groupDetails').show();
jQuery('#ajaxItemContainer').show();
var groupId = JSON.stringify({${js}});
window.location.hash = "#"+groupId;
adjustHeight('#groupDetails');
""")

}
Expand Down
Expand Up @@ -825,8 +825,6 @@ function generateMarkdown(text, container) {
}

function setupMarkdown(initialValue, id) {
console.log($("#" + id))
console.log($("#" + id + " textarea"))
$("#" + id + " textarea").keyup(function() {
var value = $(this).val()
console.log(value)
Expand Down

0 comments on commit 05f7775

Please sign in to comment.