Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelGauthier committed Jun 13, 2018
1 parent c3b9d0c commit a6efdc5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ app.controller('nodePropertiesCtrl', function ($scope, $http, $compile) {
$scope.alreadyUsed = false;
$scope.errorSaving = false;
$scope.errorDeleting = false;
$scope.checkJson = false;
$scope.isJson = true ;

$scope.resetNewProperty = function(){
$scope.newProperty = {'name':"", 'value':""};
Expand Down Expand Up @@ -136,30 +138,35 @@ app.controller('nodePropertiesCtrl', function ($scope, $http, $compile) {
}
var propertyToSave = angular.copy($scope.newProperty)
var newValue = propertyToSave.value
$scope.isJson = true;
try {
newValue = JSON.parse(propertyToSave.value)
} catch(e) {
// Do nothing if error we keep the current value
//Check if Json validation is enabled. If so, the property is not saved and we display an error message, otherwise the current value is retained.
$scope.isJson = !$scope.checkJson
}

if($scope.isJson){
propertyToSave.value = newValue
var data = {
"properties": [ propertyToSave ]
, 'reason' : "Add property '"+$scope.newProperty.name+"' to Node '"+currentNodeId+"'"
};
$http.post($scope.urlAPI, data).then(function successCallback(response) {
$scope.errorSaving = false;
//Check if new property's name is already used or not.
$scope.alreadyUsed = $scope.properties.some(checkNameUnicity);
if(!$scope.alreadyUsed){
$scope.properties.push(propertyToSave);
$scope.resetNewProperty();
$('#newPropPopup').bsModal('hide');
$scope.newPropForm.$setPristine();
}
}, function errorCallback(response) {
$scope.errorSaving = response.data.errorDetails;
return response.status==200;
});
}
propertyToSave.value = newValue
var data = {
"properties": [ propertyToSave ]
, 'reason' : "Add property '"+$scope.newProperty.name+"' to Node '"+currentNodeId+"'"
};
$http.post($scope.urlAPI, data).then(function successCallback(response) {
$scope.errorSaving = false;
//Check if new property's name is already used or not.
$scope.alreadyUsed = $scope.properties.some(checkNameUnicity);
if(!$scope.alreadyUsed){
$scope.properties.push(propertyToSave);
$scope.resetNewProperty();
$('#newPropPopup').bsModal('hide');
$scope.newPropForm.$setPristine();
}
}, function errorCallback(response) {
$scope.errorSaving = response.data.errorDetails;
return response.status==200;
});
};
$scope.popupDeletion = function(prop,index) {
$scope.deletedProperty.name = prop;
Expand Down
11 changes: 10 additions & 1 deletion rudder-web/src/main/webapp/style/rudder/rudder-menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -1001,12 +1001,21 @@ a.sidebar-toggle{
#addPropTable tbody > tr > td:nth-child(2),#addPropTable tbody > tr > td:last-child{
width: 33px;
}
#addPropTable tbody > tr > td:nth-child(2) > span{
#addPropTable td.json-check-col{
width: 80px;
background-color:#f4f4f4;
}
#addPropTable tbody > tr > td:nth-child(2) > span, #addPropTable td.json-check-col > label{
border-left:none;
border-right:none;
border-radius:0;
height: 32px;
}

#addPropTable #json-check{
position:relative;
top:2px;
}
#addPropTable tbody > tr > td:nth-child(3) > .form-control{
border-left-width:1px;
border-radius:0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>
</div>
<lift:authz role="node_write">
<hr class="spacer"></hr>
<hr class="spacer">
<div class="col-lg-7 col-md-8 col-xs-12">
<label for="newPropName">Add node property</label>
<form name="newPropForm">
Expand All @@ -26,9 +26,15 @@
<td>
<span class="input-group-addon addon-json">=</span>
</td>
<td class="form-group" ng-class="{'has-error': newPropForm.newPropValue.$error.required && newPropForm.newPropValue.$dirty}">
<td class="form-group" ng-class="{'has-error': (newPropForm.newPropValue.$error.required && newPropForm.newPropValue.$dirty) || (checkJson && !isJson)}">
<textarea placeholder="Value" msd-elastic name="newPropValue" class="form-control input-sm input-value" required ng-model="newProperty.value"></textarea>
</td>
<td class="json-check-col">
<label class="input-group-addon addon-json" for="json-check">
<span>JSON</span>
<input type="checkbox" id="json-check" ng-model="checkJson">
</label>
</td>
<td>
<button type="button" ng-click="addProperty()" class="btn btn-success btn-sm" ng-disabled="newPropForm.$invalid">
<span class="fa fa-plus"></span>
Expand All @@ -40,6 +46,7 @@
</form>
<div class="text-danger" ng-show="newPropForm.newPropName.$error.required && newPropForm.newPropName.$dirty">Name is required</div>
<div class="text-danger" ng-show="alreadyUsed">This name is already used by another property</div>
<div class="text-danger" ng-show="(checkJson && !isJson)">JSON check is enabled, but the value format is invalid.</div>
<div class="alert alert-danger errorSaving" ng-show="errorSaving">
<i class="fa fa-exclamation-triangle" style="margin-right:6px"></i>
An error occured while saving this new property : <b>{{errorSaving}}</b>
Expand Down

0 comments on commit a6efdc5

Please sign in to comment.