-
Notifications
You must be signed in to change notification settings - Fork 73
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 #7398: Update compliance UI to manage disable mode #963
Merged
ncharles
merged 1 commit into
Normation:branches/rudder/3.2
from
fanf:ust_7398/update_compliance_ui_to_manage_disable_mode
Nov 16, 2015
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,11 +35,13 @@ | |
package com.normation.rudder.domain.reports | ||
|
||
import org.joda.time.DateTime | ||
|
||
import com.normation.inventory.domain.NodeId | ||
import com.normation.rudder.domain.policies.DirectiveId | ||
import com.normation.rudder.domain.policies.RuleId | ||
import net.liftweb.common.Loggable | ||
import com.normation.rudder.reports.ReportsDisabled | ||
import net.liftweb.http.js.JE | ||
import net.liftweb.http.js.JE.JsArray | ||
|
||
/** | ||
* That file define a "compliance level" object, which store | ||
|
@@ -52,45 +54,48 @@ import net.liftweb.common.Loggable | |
//simple data structure to hold percentages of different compliance | ||
//the ints are actual numbers, percents are computed with the pc_ variants | ||
case class ComplianceLevel( | ||
pending : Int = 0 | ||
, success : Int = 0 | ||
, repaired : Int = 0 | ||
, error : Int = 0 | ||
, unexpected : Int = 0 | ||
, missing : Int = 0 | ||
, noAnswer : Int = 0 | ||
, notApplicable: Int = 0 | ||
pending : Int = 0 | ||
, success : Int = 0 | ||
, repaired : Int = 0 | ||
, error : Int = 0 | ||
, unexpected : Int = 0 | ||
, missing : Int = 0 | ||
, noAnswer : Int = 0 | ||
, notApplicable : Int = 0 | ||
, reportsDisabled: Int = 0 | ||
) { | ||
|
||
override def toString() = s"[p:${pending} s:${success} r:${repaired} e:${error} u:${unexpected} m:${missing} nr:${noAnswer} na:${notApplicable}]" | ||
override def toString() = s"[p:${pending} s:${success} r:${repaired} e:${error} u:${unexpected} m:${missing} nr:${noAnswer} na:${notApplicable} rd:${reportsDisabled}]" | ||
|
||
val total = pending+success+repaired+error+unexpected+missing+noAnswer+notApplicable | ||
val total = pending+success+repaired+error+unexpected+missing+noAnswer+notApplicable+reportsDisabled | ||
|
||
val complianceWithoutPending = pc_for(success+repaired+notApplicable, total-pending) | ||
val complianceWithoutPending = pc_for(success+repaired+notApplicable, total-pending-reportsDisabled) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha, shouldn't you remove the reportsDisabled on the left side as well ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ha ok |
||
val compliance = pc_for(success+repaired+notApplicable, total) | ||
|
||
private[this] def pc_for(i:Int, total:Int) : Double = if(total == 0) 0 else (i * 100 / BigDecimal(total)).setScale(2, BigDecimal.RoundingMode.HALF_UP).toDouble | ||
private[this] def pc(i:Int) : Double = pc_for(i, total) | ||
|
||
val pc_pending = pc(pending) | ||
val pc_success = pc(success) | ||
val pc_repaired = pc(repaired) | ||
val pc_error = pc(error) | ||
val pc_unexpected = pc(unexpected) | ||
val pc_missing = pc(missing) | ||
val pc_noAnswer = pc(noAnswer) | ||
val pc_notApplicable = pc(notApplicable) | ||
val pc_pending = pc(pending) | ||
val pc_success = pc(success) | ||
val pc_repaired = pc(repaired) | ||
val pc_error = pc(error) | ||
val pc_unexpected = pc(unexpected) | ||
val pc_missing = pc(missing) | ||
val pc_reportsDisabled = pc(reportsDisabled) | ||
val pc_noAnswer = pc(noAnswer) | ||
val pc_notApplicable = pc(notApplicable) | ||
|
||
def +(compliance: ComplianceLevel): ComplianceLevel = { | ||
ComplianceLevel( | ||
pending = this.pending + compliance.pending | ||
, success = this.success + compliance.success | ||
, repaired = this.repaired + compliance.repaired | ||
, error = this.error + compliance.error | ||
, unexpected = this.unexpected + compliance.unexpected | ||
, missing = this.missing + compliance.missing | ||
, noAnswer = this.noAnswer + compliance.noAnswer | ||
, notApplicable = this.notApplicable + compliance.notApplicable | ||
pending = this.pending + compliance.pending | ||
, success = this.success + compliance.success | ||
, repaired = this.repaired + compliance.repaired | ||
, error = this.error + compliance.error | ||
, unexpected = this.unexpected + compliance.unexpected | ||
, missing = this.missing + compliance.missing | ||
, noAnswer = this.noAnswer + compliance.noAnswer | ||
, notApplicable = this.notApplicable + compliance.notApplicable | ||
, reportsDisabled = this.reportsDisabled + compliance.reportsDisabled | ||
) | ||
} | ||
|
||
|
@@ -111,6 +116,7 @@ object ComplianceLevel { | |
case MissingReportType => compliance.copy(missing = compliance.missing + 1) | ||
case NoAnswerReportType => compliance.copy(noAnswer = compliance.noAnswer + 1) | ||
case PendingReportType => compliance.copy(pending = compliance.pending + 1) | ||
case DisabledReportType => compliance.copy(reportsDisabled = compliance.reportsDisabled + 1) | ||
} | ||
} | ||
} | ||
|
@@ -120,3 +126,24 @@ object ComplianceLevel { | |
else compliances.reduce( _ + _) | ||
} | ||
} | ||
|
||
|
||
object ComplianceLevelSerialisation { | ||
|
||
//transform the compliance percent to a list with a given order: | ||
// pc_reportDisabled, pc_notapplicable, pc_success, pc_repaired, | ||
// pc_error, pc_pending, pc_noAnswer, pc_missing, pc_unknown | ||
implicit class ComplianceLevelToJs(compliance: ComplianceLevel) { | ||
def toJsArray(): JsArray = JsArray ( | ||
JE.Num(compliance.pc_reportsDisabled) | ||
, JE.Num(compliance.pc_notApplicable) | ||
, JE.Num(compliance.pc_success) | ||
, JE.Num(compliance.pc_repaired) | ||
, JE.Num(compliance.pc_error) | ||
, JE.Num(compliance.pc_pending) | ||
, JE.Num(compliance.pc_noAnswer) | ||
, JE.Num(compliance.pc_missing) | ||
, JE.Num(compliance.pc_unexpected) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't you keep the try ?
What happens if the parse fails ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then why not adding a catch ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because it is not supposed to throw exception (Full/Failure), the try must be a remeniscience of the past