Skip to content

Commit

Permalink
Fixes #26161: Allow to enable/disable technique from the directive tr…
Browse files Browse the repository at this point in the history
…ee scree
  • Loading branch information
fanf committed Jan 16, 2025
1 parent b7109cd commit 2b2b979
Show file tree
Hide file tree
Showing 6 changed files with 310 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ class DependencyAndDeletionServiceImpl(
}
}

// group by target, and check if target status is enable
// if the target is disable, we can't change the rule status anyhow
// group by target, and check if target status is enabled
// if the target is disabled, we can't change the rule status anyhow
ZIO
.foreach(switchableCr) {
case (rule, targets) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,12 @@ function initBsTooltips(){
return tooltipTriggerList.map(function (tooltipTriggerEl) {
let dataTrigger = $(tooltipTriggerEl).attr('data-bs-trigger');
let trigger = dataTrigger === undefined ? 'hover' : dataTrigger;
tooltipTriggerEl.addEventListener('hide.bs.tooltip', () => {
removeBsTooltips();
});
tooltipTriggerEl.addEventListener('show.bs.tooltip', () => {
removeBsTooltips()
});
return new bootstrap.Tooltip(tooltipTriggerEl,{container : "body", html : true, trigger : trigger});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ class DirectiveEditForm(
onSuccessCallback: (Either[Directive, ChangeRequestId]) => JsCmd,
onMigrationCallback: (Directive, Option[Directive]) => JsCmd,
onFailureCallback: () => JsCmd = { () => Noop },
onRemoveSuccessCallBack: () => JsCmd = { () => Noop }
onRemoveSuccessCallBack: () => JsCmd = { () => Noop },
displayTechniqueDetails: ActiveTechniqueId => JsCmd = { _ => Noop }
) extends DispatchSnippet with Loggable {

import DirectiveEditForm.*
Expand Down Expand Up @@ -206,39 +207,46 @@ class DirectiveEditForm(
).display
}

val versionSelect = if (isADirectiveCreation) {
val versionSelect = if (isADirectiveCreation) {
<div id="version" class="row wbBaseField form-group">
<label for="version" class="col-sm-12 wbBaseFieldLabel">Technique version</label>
<div class="col-sm-12"><input name="version" class="form-control" readonly="" value={
directive.techniqueVersion.serialize
}/></div>
</div>
} else { directiveVersion.toForm_! }
val currentVersion = showDeprecatedVersion(directive.techniqueVersion)
val currentVersion = showDeprecatedVersion(directive.techniqueVersion)
// It is always a Full, but in case add a warning
val versionSelectId = directiveVersion.uniqueFieldId match {
val versionSelectId = directiveVersion.uniqueFieldId match {
case Full(id) => id
case _ =>
logger.warn("could not find id for migration select version")
"id_not_found"
}

val (disableMessage, enableBtn) = (activeTechnique.isEnabled, directive._isEnabled) match {
case (false, false) =>
(
"This Directive and its Technique are disabled.",
<span>
{SHtml.ajaxSubmit("Enable Directive", () => onSubmitDisable(DGModAction.Enable), ("class", "btn btn-sm btn-default"))}
<a class="btn btn-sm btn-default" href={
s"/secure/administration/techniqueLibraryManagement/#${activeTechnique.techniqueName.value}"
}>Edit Technique</a>
{
SHtml.ajaxSubmit(
"Enable Technique",
() => displayTechniqueDetails(activeTechnique.id),
("class", "btn btn-sm btn-default")
)
}
</span>
)
case (false, true) =>
(
"The Technique of this Directive is disabled.",
<a class="btn btn-sm btn-default" href={
s"/secure/administration/techniqueLibraryManagement/#${activeTechnique.techniqueName.value}"
}>Edit Technique</a>
SHtml.ajaxSubmit(
"Enable Technique",
() => displayTechniqueDetails(activeTechnique.id),
("class", "btn btn-sm btn-default")
)
)
case (true, false) =>
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ object DisplayDirectiveTree extends Loggable {

usedDirectiveIds: Seq[(DirectiveUid, Int)],
onClickCategory: Option[FullActiveTechniqueCategory => JsCmd],
onClickTechnique: Option[(FullActiveTechniqueCategory, FullActiveTechnique) => JsCmd],
onClickTechnique: Option[FullActiveTechnique => JsCmd],
onClickDirective: Option[(FullActiveTechniqueCategory, FullActiveTechnique, Directive) => JsCmd],
createDirective: Option[(Technique, FullActiveTechnique) => JsCmd],
addEditLink: Boolean,
Expand All @@ -146,8 +146,6 @@ object DisplayDirectiveTree extends Loggable {
nodeId: String
): JsTreeNode = new JsTreeNode {

private val localOnClickTechnique = onClickTechnique.map(_.curried(category))

private val localOnClickDirective = onClickDirective.map(_.curried(category))

private val tooltipContent = s"""
Expand Down Expand Up @@ -190,7 +188,7 @@ object DisplayDirectiveTree extends Loggable {
})
// We want our technique sorty by human name, default to bundle name in case we don't have any version but that should not happen
.sortBy(at => at.newestAvailableTechnique.map(_.name).getOrElse(at.techniqueName.value))
.map(at => displayActiveTechnique(at, localOnClickTechnique, localOnClickDirective))
.map(at => displayActiveTechnique(at, onClickTechnique, localOnClickDirective))
)

override val attrs =
Expand Down
Loading

0 comments on commit 2b2b979

Please sign in to comment.