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 #3068 : add a popup to list dependent rules (if any) when updating a directive #38

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -89,8 +89,15 @@ object DirectiveEditForm {
} yield {
chooseTemplate("component", "itemDependencies", xml)
}) openOr Nil

private def popupDependentUpdateForm =
(for {
xml <- Templates("templates-hidden" :: "components" :: "ComponentDirectiveEditForm" :: Nil)
} yield {
chooseTemplate("component", "popupDependentUpdateForm", xml)
}) openOr Nil

private def popupRemoveForm =
private def popupRemoveForm =
(for {
xml <- Templates("templates-hidden" :: "components" :: "ComponentDirectiveEditForm" :: Nil)
} yield {
Expand Down Expand Up @@ -157,12 +164,14 @@ class DirectiveEditForm(
private[this] var piCurrentStatusIsActivated = directive.isEnabled
private[this] var directiveCurrentStatusCreationStatus = isADirectiveCreation

lazy val dependentRules = dependencyService.directiveDependencies(directive.id).map(_.rules)

// pop-up: their content should be retrieve lazily
lazy val removePopupGridXml = {
if (directiveCurrentStatusCreationStatus) {
NodeSeq.Empty
} else {
dependencyService.directiveDependencies(directive.id).map(_.rules) match {
dependentRules match {
case e: EmptyBox =>
<div class="error">An error occurred while trying to find dependent item</div>
case Full(rules) => {
Expand All @@ -173,6 +182,22 @@ class DirectiveEditForm(
}
}

// popup for the list of dependent rules when updating the directives
lazy val updatePopupGridXml = {
if (directiveCurrentStatusCreationStatus) {
NodeSeq.Empty
} else {
dependentRules match {
case e: EmptyBox =>
<div class="error">An error occurred while trying to find dependent item</div>
case Full(rules) => {
val cmp = new RuleGrid("dependent_popup_grid", rules, None, false)
cmp.rulesGrid(linkCompliancePopup = false)
}
}
}
}

// if directive current inherited status is "activated", the two pop-up (disable and
// remove) show the same content. Else, we have to build two different pop-up
val switchStatusFilter = if (directive.isEnabled) OnlyDisableable else OnlyEnableable
Expand Down Expand Up @@ -236,7 +261,17 @@ class DirectiveEditForm(
"#reasonsField" #> f.toForm_!
}
}
)(popupDisactivateForm)
)(popupDisactivateForm)
}

def showUpdatePopupForm( onConfirmCallback: => JsCmd) : NodeSeq = {
(
"#dialogSaveButton" #> SHtml.ajaxButton("Save", () => JsRaw("$.modal.close();") & onConfirmCallback ) &
"#directiveDisabled [class]" #> ( if (piCurrentStatusIsActivated) "nodisplay" else "" ) &
"#updateItemDependencies" #> {
(ClearClearable & "#itemDependenciesGrid" #> updatePopupGridXml)(itemDependencies)
}
)(popupDependentUpdateForm)
}

def showDirectiveForm(): NodeSeq = {
Expand Down Expand Up @@ -574,9 +609,8 @@ class DirectiveEditForm(
}

private[this] def onSubmit(): JsCmd = {

parameterEditor.removeDuplicateSections

checkVariables()

if (formTracker.hasErrors) {
Expand All @@ -600,11 +634,24 @@ class DirectiveEditForm(
longDescription = piLongDescription.is
)
}
// here everything is good, I can display the popup if there are
// dependent rules
dependentRules match {
case e: EmptyBox => saveAndDeployDirective(newDirective, crReasons.map(_.is))
case Full(rules) if rules.size == 0 => saveAndDeployDirective(newDirective, crReasons.map(_.is))
case _ => displayDependenciesPopup(newDirective, crReasons.map(_.is))
}

saveAndDeployDirective(newDirective, crReasons.map(_.is))
}
}

// Fill the content of the popup with the list of dependant rules (this list is computed
// at the load of page), and wait for user confirmation
private[this] def displayDependenciesPopup(directive: Directive, why:Option[String]): JsCmd = {
SetHtml("confirmUpdateActionDialog", showUpdatePopupForm(saveAndDeployDirective(directive, why))) &
createPopup("updateActionDialog",140,850)
}

private[this] def saveAndDeployDirective(directive: Directive, why:Option[String]): JsCmd = {
(for {
saved <- directiveRepository
Expand Down
Binary file added rudder-web/src/main/webapp/images/icDetails.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -80,6 +80,7 @@
<div id="editForm" />
<div id="removeActionDialog" />
<div id="disableActionDialog" />
<div id="confirmUpdateActionDialog" />
</div>
</component:body>

Expand Down Expand Up @@ -256,4 +257,40 @@ <h2>Are you sure that you want to <span id="dialogDisableLabel">disable</span> t
</div>
</component:popupDisactivateForm>

<component:popupDependentUpdateForm>
<div id="updateActionDialog" class="nodisplay">
<div class="simplemodal-title">
<h1>Update the Directive</h1>
<hr/>
</div>
<div class="simplemodal-content">
<div>
<img src="/images/icDetails.png" alt="Details" height="20" width="22" class="icon"/>
<h2>Are you sure that you want to update this Directive?</h2>
</div>
<br />
<div id="directiveDisabled" class="nodisplay">
<img src="/images/icWarn.png" alt="Warning!" height="32" width="32" class="warnicon"/>
<b>Warning:</b> This directive is currently disabled. Your changes will not take effect until it is enabled.
</div>
<div>
Updating this Directive will have an impact on the following Rules which apply it.
</div>
<div id="updateItemDependencies">
Here comes the grid of Rules that will be dependantly updated
</div>
<br />
<hr class="spacer" />
</div>
<div class="simplemodal-bottom">
<hr/>
<div class="popupButton">
<span>
<button class="simplemodal-close" onClick="$.modal.close();">Cancel</button>
<button id="dialogSaveButton">Save</button>
</span>
</div>
</div>
</div>
</component:popupDependentUpdateForm>
</xml:group>