forked from Normation/rudder
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3d7edd
commit 7af0cc8
Showing
7 changed files
with
366 additions
and
26 deletions.
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
158 changes: 158 additions & 0 deletions
158
rudder-web/src/main/webapp/javascript/rudder/angular/nodeProperties.js
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 |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
************************************************************************************* | ||
* Copyright 2017 Normation SAS | ||
************************************************************************************* | ||
* | ||
* This file is part of Rudder. | ||
* | ||
* Rudder is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* In accordance with the terms of section 7 (7. Additional Terms.) of | ||
* the GNU General Public License version 3, the copyright holders add | ||
* the following Additional permissions: | ||
* Notwithstanding to the terms of section 5 (5. Conveying Modified Source | ||
* Versions) and 6 (6. Conveying Non-Source Forms.) of the GNU General | ||
* Public License version 3, when you create a Related Module, this | ||
* Related Module is not considered as a part of the work and may be | ||
* distributed under the license agreement of your choice. | ||
* A "Related Module" means a set of sources files including their | ||
* documentation that, without modification of the Source Code, enables | ||
* supplementary functions or services in addition to those offered by | ||
* the Software. | ||
* | ||
* Rudder is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Rudder. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
************************************************************************************* | ||
*/ | ||
|
||
var app = angular.module('nodeProperties', ['DataTables', 'monospaced.elastic']); | ||
|
||
app.controller('nodePropertiesCtrl', function ($scope, $http, $compile) { | ||
//DataTable | ||
$scope.columnDefs = [ | ||
{"aTargets":[0], "mDataProp": "name" , "sWidth": "250px", "sTitle" : "Name" } | ||
, { | ||
"aTargets":[1], | ||
"mDataProp": "value", | ||
"sTitle" :"Value", | ||
"fnCreatedCell" : function (nTd, sData, oData, iRow, iCol) { | ||
var pre = $("<pre class='json-beautify' onclick='$(this).toggleClass(\"toggle\")'></pre>"); | ||
var content = sData != null && typeof sData === 'object' ? JSON.stringify(sData) : sData; | ||
$(nTd).empty(); | ||
pre.html(content) | ||
$(nTd).prepend(pre); | ||
} | ||
} | ||
, { | ||
"aTargets":[2], | ||
"sWidth": "50px", | ||
"mDataProp": "name", | ||
"sTitle" :"", | ||
"orderable": false, | ||
"fnCreatedCell" : function (nTd, sData, oData, iRow, iCol) { | ||
var deleteButton = $('<span class="fa fa-times text-danger" ng-click="popupDeletion(\''+sData+'\', \''+iRow+'\')"></span>'); | ||
$(nTd).addClass('text-center delete-action'); | ||
$(nTd).empty(); | ||
$(nTd).prepend(deleteButton); | ||
$compile(deleteButton)($scope); | ||
} | ||
}]; | ||
|
||
$scope.overrideOptions = { | ||
"bFilter" : true | ||
, "bPaginate" : true | ||
, "bLengthChange": true | ||
, "sPaginationType": "full_numbers" | ||
, "oLanguage": { | ||
"sSearch": "" | ||
} | ||
, "aaSorting": [[ 0, "asc" ]] | ||
, "sDom": '<"dataTables_wrapper_top"fl>rt<"dataTables_wrapper_bottom"ip>' | ||
}; | ||
|
||
|
||
//Initialize scope | ||
$scope.properties; | ||
$scope.newProperty = {'name':"", 'value':""} | ||
$scope.alreadyUsed = false; | ||
$scope.errorSaving = false; | ||
$scope.selectedProperty = {'name':"", 'index':""}; | ||
$scope.urlAPI = contextPath + '/secure/api/latest/nodes/'; | ||
$scope.nodeId; | ||
$scope.resetNewProperty = function(){ | ||
$scope.newProperty = {'name':"", 'value':""}; | ||
} | ||
|
||
$scope.init = function(properties, nodeId){ | ||
//Get current node properties | ||
$scope.properties = properties; | ||
$scope.urlAPI = contextPath + '/secure/api/latest/nodes/'+ nodeId; | ||
$("#nodePropertiesTab").dataTable().fnAddData($scope.properties); | ||
} | ||
|
||
$scope.addProperty = function(){ | ||
function getIndex(property, index, array) { | ||
return property.name == $scope.newProperty.name; | ||
} | ||
var data = {"properties":[ | ||
$scope.newProperty | ||
]}; | ||
$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(getIndex); | ||
if(!$scope.alreadyUsed){ | ||
$scope.properties.push(angular.copy($scope.newProperty)); | ||
$scope.resetNewProperty(); | ||
$('#newPropPopup').bsModal('hide'); | ||
$scope.newPropForm.$setPristine(); | ||
} | ||
}, function errorCallback(response) { | ||
return response.status==200; | ||
$scope.errorSaving = true; | ||
}); | ||
}; | ||
$scope.popupCreation = function() { | ||
$('#newPropPopup').bsModal('show'); | ||
}; | ||
$scope.popupDeletion = function(prop,index) { | ||
$scope.selectedProperty.name = prop; | ||
$scope.selectedProperty.index = index; | ||
$('#deletePropPopup').bsModal('show'); | ||
}; | ||
$scope.deleteProperty = function(){ | ||
var data = {"properties":[{"name":$scope.selectedProperty.name, "value":""}]}; | ||
$http.post($scope.urlAPI, data).then(function successCallback(response) { | ||
$('#deletePropPopup').bsModal('hide'); | ||
$scope.properties.splice($scope.selectedProperty.index, 1); | ||
$('#deletePropPopup').bsModal('hide'); | ||
}, function errorCallback(response) { | ||
return response.status==200; | ||
$('#deletePropPopup').bsModal('hide'); | ||
}); | ||
} | ||
$scope.cancelPopupCreation = function() { | ||
$('#newPropPopup').bsModal('hide'); | ||
$scope.resetNewProperty(); | ||
$scope.newPropForm.$setPristine(); | ||
$scope.errorSaving = false; | ||
$scope.alreadyUsed = false; | ||
}; | ||
}); | ||
|
||
app.config(function($locationProvider) { | ||
$locationProvider.html5Mode({ | ||
enabled: true, | ||
requireBase: false | ||
}); | ||
}) |
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.