Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelGauthier committed Mar 9, 2020
1 parent 79ef375 commit b6e3f49
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import net.liftweb.json.JArray
import net.liftweb.json.JField
import net.liftweb.json.JObject
import net.liftweb.json.JString
import net.liftweb.json.JsonAST.JValue
import net.liftweb.json.JsonParser
import net.liftweb.util.Helpers._
import org.joda.time.Interval
Expand Down Expand Up @@ -667,7 +668,7 @@ class RuleGrid(
TimingDebugLogger.trace(s"Rule grid: transforming into data: get rule data: callback: ${t5-t4}ms")

val tags = JsObj(line.rule.tags.map(tag => (tag.name.value, Str(tag.value.value))).toList:_*).toJsCmd

val tagsDisplayed = JsonTagSerialisation.serializeTags(line.rule.tags)
RuleLine (
line.rule.name
, line.rule.id
Expand All @@ -682,6 +683,7 @@ class RuleGrid(
, policyMode
, explanation
, tags
, tagsDisplayed
)
}
}
Expand Down Expand Up @@ -716,6 +718,7 @@ final case class RuleLine (
, policyMode : String
, explanation : String
, tags : String
, tagsDisplayed : JValue
) extends JsTableLine {

/* Would love to have a reflexive way to generate that map ... */
Expand All @@ -730,16 +733,17 @@ final case class RuleLine (
val optFields : Seq[(String,JsExp)]= reasonField.toSeq ++ cbCallbackField ++ callbackField

val base = JsObj(
( "name", name )
, ( "id", id.value )
, ( "description", description )
, ( "applying", applying )
, ( "category", category )
, ( "status", status )
, ( "trClass", trClass )
, ( "policyMode", policyMode )
, ( "explanation", explanation )
, ( "tags", tags)
( "name" , name )
, ( "id" , id.value )
, ( "description" , description )
, ( "applying" , applying )
, ( "category" , category )
, ( "status" , status )
, ( "trClass" , trClass )
, ( "policyMode" , policyMode )
, ( "explanation" , explanation )
, ( "tags" , tags )
, ( "tagsDisplayed", tagsDisplayed )
)

base +* JsObj(optFields:_*)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import org.joda.time.Interval
import com.normation.cfclerk.xmlparsers.CfclerkXmlConstants.DEFAULT_COMPONENT_KEY
import com.normation.rudder.domain.policies.PolicyMode._
import com.normation.rudder.repository.FullNodeGroupCategory
import net.liftweb.json.JsonAST.JValue

object ComputePolicyMode {
def ruleMode(globalMode : GlobalPolicyMode, directives : Set[Directive], nodeModes: Set[Option[PolicyMode]]) = {
Expand Down Expand Up @@ -307,20 +308,22 @@ final case class RuleComplianceLine (
, details : JsTableData[DirectiveComplianceLine]
, policyMode : String
, modeExplanation : String
, tags : JValue
) extends JsTableLine {
val json = {
JsObj (
( "rule" -> escapeHTML(rule.name) )
, ( "compliance" -> jsCompliance(compliance) )
( "rule" -> escapeHTML(rule.name) )
, ( "compliance" -> jsCompliance(compliance) )
, ( "compliancePercent" -> compliance.compliance)
, ( "id" -> rule.id.value )
, ( "details" -> details.json )
, ( "id" -> rule.id.value )
, ( "details" -> details.json )
//unique id, usable as DOM id - rules, directives, etc can
//appear several time in a page
, ( "jsid" -> nextFuncName )
, ( "isSystem" -> rule.isSystem )
, ( "policyMode" -> policyMode )
, ( "explanation"-> modeExplanation )
, ( "jsid" -> nextFuncName )
, ( "isSystem" -> rule.isSystem )
, ( "policyMode" -> policyMode )
, ( "explanation"-> modeExplanation )
, ( "tags" -> tags )
)
}
}
Expand Down Expand Up @@ -348,22 +351,24 @@ final case class DirectiveComplianceLine (
, details : JsTableData[ComponentComplianceLine]
, policyMode : String
, modeExplanation : String
, tags : JValue
) extends JsTableLine {
val json = {
JsObj (
( "directive" -> escapeHTML(directive.name) )
, ( "id" -> directive.id.value )
, ( "techniqueName" -> escapeHTML(techniqueName) )
( "directive" -> escapeHTML(directive.name) )
, ( "id" -> directive.id.value )
, ( "techniqueName" -> escapeHTML(techniqueName) )
, ( "techniqueVersion" -> escapeHTML(techniqueVersion.toString) )
, ( "compliance" -> jsCompliance(compliance))
, ( "compliancePercent"-> compliance.compliance)
, ( "details" -> details.json )
, ( "compliance" -> jsCompliance(compliance) )
, ( "compliancePercent"-> compliance.compliance )
, ( "details" -> details.json )
//unique id, usable as DOM id - rules, directives, etc can
//appear several time in a page
, ( "jsid" -> nextFuncName )
, ( "isSystem" -> directive.isSystem )
, ( "policyMode" -> policyMode )
, ( "explanation" -> modeExplanation )
, ( "jsid" -> nextFuncName )
, ( "isSystem" -> directive.isSystem )
, ( "policyMode" -> policyMode )
, ( "explanation" -> modeExplanation )
, ( "tags" -> tags )
)
}
}
Expand Down Expand Up @@ -540,6 +545,7 @@ object ComplianceData extends Loggable {
, JsTableData(details)
, policyMode
, explanation
, JsonTagSerialisation.serializeTags(rule.tags)
)

}
Expand Down Expand Up @@ -575,6 +581,7 @@ object ComplianceData extends Loggable {
, JsTableData(Nil)
, policyMode
, explanation
, JsonTagSerialisation.serializeTags(overridenDir.tags)
)
}

Expand Down Expand Up @@ -618,7 +625,7 @@ object ComplianceData extends Loggable {
val techniqueVersion = directive.techniqueVersion
val components = getComponentsComplianceDetails(directiveStatus.components.values.toSet, true)
val (policyMode,explanation) = computeMode(directive.policyMode)

val directiveTags = JsonTagSerialisation.serializeTags(directive.tags)
DirectiveComplianceLine (
directive
, techniqueName
Expand All @@ -627,6 +634,7 @@ object ComplianceData extends Loggable {
, components
, policyMode
, explanation
, directiveTags
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ function createRuleTable(gridId, data, checkboxColumn, actionsColumn, compliance
$(nTd).prepend(elem);
var badge = createBadgeAgentPolicyMode('rule',data.policyMode, data.explanation);
$(nTd).prepend(badge);
displayTags(nTd, oData.tagsDisplayed)
}
};

Expand Down Expand Up @@ -483,7 +484,7 @@ function createRuleTable(gridId, data, checkboxColumn, actionsColumn, compliance
, "searchable": true
}]
, "fnDrawCallback": function( oSettings ) {
$('.rudder-label').bsTooltip();
$('.rudder-label, .tags-label').bsTooltip();
$('#updateRuleTable').on('click',function(){
refresh();
})
Expand Down Expand Up @@ -559,22 +560,22 @@ function createRuleComplianceTable(gridId, data, contextPath, refresh) {
, "mDataProp": "rule"
, "sTitle": "Rule"
, "fnCreatedCell" : function (nTd, sData, oData, iRow, iCol) {
$(nTd).addClass("listopen");
$(nTd).empty();
//rule name is escaped server side, avoid double escape with .text()
$(nTd).html(oData.rule);
if (! oData.isSystem) {
var editIcon = $("<i>");
editIcon.addClass("fa fa-pencil");
var editLink = $("<a />");
editLink.attr("href",contextPath + '/secure/configurationManager/ruleManagement#{"ruleId":"'+oData.id+'"}');
editLink.click(function(e) {e.stopPropagation();});
editLink.append(editIcon);
editLink.addClass("reportIcon");
$(nTd).append(editLink);
$(nTd).prepend(createBadgeAgentPolicyMode('rule', oData.policyMode, oData.explanation));
}
$(nTd).addClass("listopen");
$(nTd).empty();
//rule name is escaped server side, avoid double escape with .text()
$(nTd).html(oData.rule);
if (! oData.isSystem) {
var editIcon = $("<i>");
editIcon.addClass("fa fa-pencil");
var editLink = $("<a />");
editLink.attr("href",contextPath + '/secure/configurationManager/ruleManagement#{"ruleId":"'+oData.id+'"}');
editLink.click(function(e) {e.stopPropagation();});
editLink.append(editIcon);
editLink.addClass("reportIcon");
$(nTd).append(editLink);
$(nTd).prepend(createBadgeAgentPolicyMode('rule', oData.policyMode, oData.explanation));
}
}
} , {
"sWidth": "25%"
, "mDataProp": "compliancePercent"
Expand Down Expand Up @@ -635,7 +636,7 @@ function createExpectedReportTable(gridId, data, contextPath, refresh) {
"mDataProp": "value"
, "sTitle" : "Value"
} ];
return function (gridId,data) {createTable(gridId, data, columns, defaultParams, contextPath); createTooltip();$('.rudder-label').bsTooltip();}
return function (gridId,data) {createTable(gridId, data, columns, defaultParams, contextPath); createTooltip();$('.rudder-label, .tags-label').bsTooltip();}
};

var localComponentTable = function() {
Expand Down Expand Up @@ -669,7 +670,7 @@ function createExpectedReportTable(gridId, data, contextPath, refresh) {
toolTipContainer.attr("id",tooltipId);
$(nTd).append(tooltipIcon);
$(nTd).append(toolTipContainer);

displayTags(nTd, oData.tags)
if (! oData.isSystem) {
var editLink = $("<a />");
editLink.attr("href",contextPath + '/secure/configurationManager/directiveManagement#{"directiveId":"'+oData.id+'"}');
Expand All @@ -692,7 +693,7 @@ function createExpectedReportTable(gridId, data, contextPath, refresh) {

return function (gridId, data, refresh) {
createTable(gridId, data, columns, params, contextPath, refresh);
createTooltip();$('.rudder-label').bsTooltip();
createTooltip();$('.rudder-label, .tags-label').bsTooltip();
}
};

Expand All @@ -702,6 +703,9 @@ function createExpectedReportTable(gridId, data, contextPath, refresh) {
, "fnCreatedCell" : function (nTd, sData, oData, iRow, iCol) {
$(nTd).addClass("listopen");
$(nTd).text(oData.rule);
console.log(oData)
console.log(sData)
displayTags(nTd, oData.tags)
if (! oData.isSystem) {
var editLink = $("<a />");
editLink.attr("href",contextPath + '/secure/configurationManager/ruleManagement#{"ruleId":"'+oData.id+'"}');
Expand All @@ -717,14 +721,12 @@ function createExpectedReportTable(gridId, data, contextPath, refresh) {
} ];
var params = jQuery.extend({"fnDrawCallback" : function( oSettings ) {
createInnerTable(this, localDirectiveTable(), contextPath, "rule");
$('.rudder-label').bsTooltip();
$('.rudder-label, .tags-label').bsTooltip();
}
, "sDom": '<"dataTables_wrapper_top newFilter"f<"dataTables_refresh">>rt<"dataTables_wrapper_bottom"lip>'
}
, defaultParams);

createTable(gridId,data, ruleColumn, params, contextPath, refresh);

}


Expand Down Expand Up @@ -773,6 +775,7 @@ function createDirectiveTable(isTopLevel, isNodeView, contextPath) {
toolTipContainer.attr("id",tooltipId);
$(nTd).append(tooltipIcon);
$(nTd).append(toolTipContainer);
displayTags(nTd, oData.tags);
if (! oData.isSystem) {
var editLink = $("<a />");
editLink.attr("href",contextPath + '/secure/configurationManager/directiveManagement#{"directiveId":"'+oData.id+'"}');
Expand Down Expand Up @@ -806,7 +809,7 @@ function createDirectiveTable(isTopLevel, isNodeView, contextPath) {
, "aaSorting": [[ 0, "asc" ]]
, "fnDrawCallback" : function( oSettings ) {
createInnerTable(this, createComponentTable(isTopLevel, isNodeView, contextPath), contextPath, "directive");
$('.rudder-label').bsTooltip();
$('.rudder-label, .tags-label').bsTooltip();
}
};

Expand All @@ -822,7 +825,8 @@ function createDirectiveTable(isTopLevel, isNodeView, contextPath) {

return function (gridId, data, refresh) {
createTable(gridId, data, columns, params, contextPath, refresh);
createTooltip();$('.rudder-label').bsTooltip();
createTooltip();
$('.rudder-label, .tags-label').bsTooltip();
}
}

Expand Down Expand Up @@ -1894,3 +1898,33 @@ function createTable(gridId,data,columns, customParams, contextPath, refresh, st
return table;
}

function displayTags(element, tagsArray){
//Do nothing if there is no tag
if(!Array.isArray(tagsArray) || tagsArray.length <= 0) return false;
var tagsLabel = $("<span class='tags-label'></span>");
var iconTag = $("<i class='fa fa-tag'></i>");
var tagsCpt = $('<b></b>');
var listTags = [];
var tmp;
for(var t in tagsArray){
tmp =
[ "<span class='tags-label'><i class='fa fa-tag'></i>"
, "<span class='tag-key'> " + tagsArray[t].key + " </span>"
, "<span class='tag-separator'> = </span>"
, "<span class='tag-value'> " + tagsArray[t].value + " </span>"
, "</span>"
].join('');
listTags.push(tmp);
}
var tagsTooltipContent =
[ "<h4 class='tags-tooltip-title'>Tags <span class='tags-label'><i class='fa fa-tag'></i> "+ tagsArray.length +"</span></h4>"
, "<div class='tags-list'>"
, listTags.join('')
, "</div>"
].join('');
tagsCpt.html(" "+tagsArray.length);
tagsLabel.attr("data-toggle","tooltip").attr("data-placement","top").attr("data-html","true").attr("data-original-title",tagsTooltipContent)
tagsLabel.append(iconTag).append(tagsCpt);
$(element).append(tagsLabel);
}

Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ hr.separator-filter-tree{
padding: 10px 5px 5px 5px;
font-size: 14px;
}
.tags-label{
.tags-label,
.tooltip > .tooltip-inner .tags-label{
padding: 4px 8px;
border-radius : 20px;
background-color: #222D4215;
Expand Down Expand Up @@ -431,31 +432,17 @@ hr.separator-filter-tree{
.tags-table table{
margin-bottom: 0 !important;
}
/*
.tags-list > div {
border-bottom: 1px solid #e5e5e5;
font-size: 14px;
color: #222D42;
}
.tags-list > div > span{
display: inline-block;
padding: 4px 0;
}
.tags-list > div > span:first-child,
.tags-list > div > span:last-child{
width: calc((100% - 20px)/2);
}
.tags-list > div > span:nth-child(2){
width: 20px;
text-align: center;
background-color: #f9f9f9;
border-left: 1px solid #e5e5e5;
border-right: 1px solid #e5e5e5;

.dataTable td .tags-label{
padding: 3px 8px 1px 8px;
font-size: .9em;
margin-left: 5px;
margin-right: 2px;
}
.tags-list > div > span:last-child{
padding-left: 10px;
.dataTable td{
position: relative;
}
*/

@-webkit-keyframes exist {
0% {box-shadow: 0 0 0 #c2c2c2;}
50% {box-shadow: 0 0 13px #c2c2c2;}
Expand Down

0 comments on commit b6e3f49

Please sign in to comment.