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

Bug/4236/selected category should appear in popup #386

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
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class RuleCategoryTree(
}
}

def getRoot = {
root
}
Copy link
Member

Choose a reason for hiding this comment

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

Not sure about the interest of that method ?

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind, missed the "r" in var

def resetSelected = selectedCategoryId = rootCategory.id

def dispatch = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,19 @@ class RuleDisplayer (
SetHtml(gridId, viewRules)
}

private[this] def ruleCategoryTree(rootCategory : RuleCategory) = {
new RuleCategoryTree(
"categoryTree"
, rootCategory
, directive
, (() => check)
, ((c:RuleCategory) => showCategoryPopup(Some(c)))
, ((c:RuleCategory) => showDeleteCategoryPopup(c))
, () => refreshGrid
)
private[this] val ruleCategoryTree = {
root.map(
new RuleCategoryTree(
"categoryTree"
, _
, directive
, (() => check)
, ((c:RuleCategory) => showCategoryPopup(Some(c)))
, ((c:RuleCategory) => showDeleteCategoryPopup(c))
, () => refreshGrid
) )
}
def viewCategories(rootCategory : RuleCategory) : NodeSeq = {
def viewCategories(ruleCategoryTree : RuleCategoryTree) : NodeSeq = {


val actionButton =
Expand All @@ -119,7 +120,7 @@ class RuleDisplayer (
</lift:authz>
<div id="treeParent" style="overflow:auto; margin-top:10px; max-height:300px;border: 1px #999 ridge; padding-right:15px;">
<div id="categoryTree">
{ruleCategoryTree(rootCategory).tree}
{ruleCategoryTree.tree}
</div>
</div>
</div>
Expand Down Expand Up @@ -195,13 +196,13 @@ class RuleDisplayer (
if (directive.isDefined) 2 else 1
}

root match {
case Full(rootCategory) =>
ruleCategoryTree match {
case Full(ruleCategoryTree) =>
<div style="padding:10px;">
<div style="float:left; width: 20%; overflow:auto">
<div class="inner-portlet-header" style="letter-spacing:1px; padding-top:0;">CATEGORIES</div>
<div class="inner-portlet-content" id="categoryTreeParent">
{viewCategories(rootCategory)}
{viewCategories(ruleCategoryTree)}
</div>
</div>
<div style="float:left; width:78%;padding-left:2%;">
Expand All @@ -227,11 +228,13 @@ class RuleDisplayer (


def ruleCreationPopup (ruleToClone:Option[Rule]) = {
root match {
case Full(root) =>
ruleCategoryTree match {
case Full(ruleCategoryTree) =>
val root = ruleCategoryTree.getRoot
new CreateOrCloneRulePopup(
root
, ruleToClone
, ruleCategoryTree.getSelected
, onSuccessCallback = onCreateRule
).popupContent
case eb:EmptyBox =>
Expand All @@ -247,25 +250,27 @@ class RuleDisplayer (

// Popup

// Popup

private[this] def creationPopup(category : Option[RuleCategory], rootCategory : RuleCategory) =
private[this] def creationPopup(category : Option[RuleCategory], ruleCategoryTree : RuleCategoryTree) = {
val rootCategory = ruleCategoryTree.getRoot
new RuleCategoryPopup(
rootCategory
, category
, ruleCategoryTree.getSelected
, {(r : RuleCategory) =>
root = roCategoryRepository.getRootCategory
ruleCategoryTree(rootCategory).refreshTree(root) & refreshGrid
ruleCategoryTree.refreshTree(root) & refreshGrid
}
)
)
}

/**
* Create the popup
*/
private[this] def showCategoryPopup(category : Option[RuleCategory]) : JsCmd = {
val popupHtml =
root match {
case Full(rootCategory) =>
creationPopup(category,rootCategory).popupContent
ruleCategoryTree match {
case Full(ruleCategoryTree) =>
creationPopup(category,ruleCategoryTree).popupContent
case eb:EmptyBox =>
// Should not happen, the function will be called only if the rootCategory is Set
val fail = eb ?~! "Could not get root category"
Expand All @@ -284,9 +289,9 @@ class RuleDisplayer (
*/
private[this] def showDeleteCategoryPopup(category : RuleCategory) : JsCmd = {
val popupHtml =
root match {
case Full(rootCategory) =>
creationPopup(Some(category), rootCategory).deletePopupContent(category.canBeDeleted(rules.toList))
ruleCategoryTree match {
case Full(ruleCategoryTree) =>
creationPopup(Some(category), ruleCategoryTree).deletePopupContent(category.canBeDeleted(rules.toList))
case eb:EmptyBox =>
// Should not happen, the function will be called only if the rootCategory is Set
val fail = eb ?~! "Could not get root category"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ import bootstrap.liftweb.RudderConfig
import com.normation.rudder.rule.category.RuleCategoryId
import com.normation.rudder.web.model.WBSelectField
import com.normation.rudder.rule.category.RuleCategory
import com.normation.rudder.rule.category.RuleCategory

class CreateOrCloneRulePopup(
rootRuleCategory : RuleCategory
, clonedRule : Option[Rule]
, selectedCategory : RuleCategoryId
, onSuccessCallback : (Rule) => JsCmd = { (rule : Rule) => Noop }
, onFailureCallback : () => JsCmd = { () => Noop }
) extends DispatchSnippet with Loggable {
Expand Down Expand Up @@ -165,7 +167,7 @@ class CreateOrCloneRulePopup(
new WBSelectField(
"Category"
, categoryHierarchyDisplayer.getRuleCategoryHierarchy(rootRuleCategory, None).map { case (id, name) => (id.value -> name)}
, rootRuleCategory.id.value
, selectedCategory.value
) {
override def className = "rudderBaseFieldSelectClassName"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import com.normation.rudder.rule.category.RuleCategory
class RuleCategoryPopup(
rootCategory : RuleCategory
, targetCategory : Option[RuleCategory]
, selectedCategory : RuleCategoryId
, onSuccessCategory : (RuleCategory) => JsCmd
, onSuccessCallback : (String) => JsCmd = { _ => Noop }
, onFailureCallback : () => JsCmd = { () => Noop }
Expand Down Expand Up @@ -167,7 +168,7 @@ class RuleCategoryPopup(
new WBSelectField(
"Parent"
, categoryHierarchyDisplayer.getRuleCategoryHierarchy(categories, None).map { case (id, name) => (id.value -> name)}
, parentCategory.getOrElse(rootCategory.id.value)
, parentCategory.getOrElse(selectedCategory.value)
) {
override def subContainerClassName = "twoColPopup"
override def inputField = super.inputField % ("tabindex","3")
Expand Down