Skip to content
Snippets Groups Projects
Commit b8f54dac authored by p1114753's avatar p1114753
Browse files

Fixed "add et edit capabilities"'s bugs

Fixed AddParamIntoCapability bugs
parent 9e72a593
No related branches found
No related tags found
No related merge requests found
...@@ -19,13 +19,18 @@ ProfileController.run(['$rootScope', 'ProtocolsFactory', function($rootScope, Pr ...@@ -19,13 +19,18 @@ ProfileController.run(['$rootScope', 'ProtocolsFactory', function($rootScope, Pr
}]); }]);
ProfileController.controller('ProfileController', ['$scope', 'ProfileService', '$rootScope', '$log', 'ProtocolsFactory', 'ngToast', function($scope, ProfileService, $rootScope, $log, ProtocolsFactory, ngToast) { ProfileController.controller('ProfileController', ['$scope', 'ProfileService', '$rootScope', '$log', 'ProtocolsFactory', 'ngToast', function($scope, ProfileService, $rootScope, $log, ProtocolsFactory, ngToast) {
$scope.directiveScope = {
counter: 0
};
$scope.newCapability = {}; $scope.newCapability = {};
$scope.newCapability.params = []; $scope.newCapability.params = [];
$scope.isResultCheckboxDisabled = true;
$rootScope.$storage.capabilitiesForProfile = []; $rootScope.$storage.capabilitiesForProfile = [];
$rootScope.$storage.addedCapabilities = $rootScope.$storage.addedCapabilities ? $rootScope.$storage.addedCapabilities : []; $rootScope.$storage.addedCapabilities = $rootScope.$storage.addedCapabilities ? $rootScope.$storage.addedCapabilities : [];
$scope.isResultCheckboxDisabled = true;
$scope.toggleResultCheckbox = function() { $scope.toggleResultCheckbox = function() {
$scope.isResultCheckboxDisabled = !$scope.isResultCheckboxDisabled; $scope.isResultCheckboxDisabled = !$scope.isResultCheckboxDisabled;
$scope.newCapability.result = (!$scope.isResultCheckboxDisabled) ? $scope.newCapibility.result : '';
}; };
/*Add the capability to the model and to the view if it's a success*/ /*Add the capability to the model and to the view if it's a success*/
...@@ -37,9 +42,9 @@ ProfileController.controller('ProfileController', ['$scope', 'ProfileService', ' ...@@ -37,9 +42,9 @@ ProfileController.controller('ProfileController', ['$scope', 'ProfileService', '
console.log(newCapability); console.log(newCapability);
var cap = {}; var cap = {};
cap.id = newCapability.id; cap.id = newCapability.id;
cap.protocol = {};
cap.protocol.protocolName = newCapability.protocol.protocolName; // /!\ : For object-assignment, we should use angular.copy
cap.protocol.parameters = newCapability.protocol.parameters; cap.protocol = angular.copy(newCapability.protocol);
cap.configuration = 'manual'; cap.configuration = 'manual';
cap.cloudPort = 0; cap.cloudPort = 0;
cap.params = []; cap.params = [];
...@@ -51,7 +56,7 @@ ProfileController.controller('ProfileController', ['$scope', 'ProfileService', ' ...@@ -51,7 +56,7 @@ ProfileController.controller('ProfileController', ['$scope', 'ProfileService', '
cap.params = newCapability.params ? newCapability.params : []; cap.params = newCapability.params ? newCapability.params : [];
} }
cap.result = (!$scope.isResultCheckboxDisabled) ? newCapability.result : null; cap.result = newCapability.result ? newCapability.result : null;
console.log(cap); console.log(cap);
// cap.isEditable=true; // cap.isEditable=true;
// cap.hydra = "http://www.w3.org/ns/hydra/core#"; // cap.hydra = "http://www.w3.org/ns/hydra/core#";
...@@ -93,6 +98,7 @@ ProfileController.controller('ProfileController', ['$scope', 'ProfileService', ' ...@@ -93,6 +98,7 @@ ProfileController.controller('ProfileController', ['$scope', 'ProfileService', '
// "status": "vs:term_status" // "status": "vs:term_status"
// }; // };
$rootScope.$storage.addedCapabilities.push(cap); $rootScope.$storage.addedCapabilities.push(cap);
$rootScope.$storage.capabilitiesForProfile.push(cap);
// // compact a document according to a particular context // // compact a document according to a particular context
// // see: http://json-ld.org/spec/latest/json-ld/#compacted-document-form // // see: http://json-ld.org/spec/latest/json-ld/#compacted-document-form
// jsonld.compact(doc, context, function(err, compacted) { // jsonld.compact(doc, context, function(err, compacted) {
...@@ -113,9 +119,10 @@ ProfileController.controller('ProfileController', ['$scope', 'ProfileService', ' ...@@ -113,9 +119,10 @@ ProfileController.controller('ProfileController', ['$scope', 'ProfileService', '
//}); //});
ngToast.create("Capability created."); ngToast.create("Capability created.");
$scope.newCapability = {}; $scope.newCapability = {};
$scope.newCapability.protocol = {};
$scope.newCapability.params = []; $scope.newCapability.params = [];
} }
}; };
...@@ -171,7 +178,7 @@ ProfileController.controller('ProfileController', ['$scope', 'ProfileService', ' ...@@ -171,7 +178,7 @@ ProfileController.controller('ProfileController', ['$scope', 'ProfileService', '
angular.forEach($rootScope.$storage.addedCapabilities, function(addedCapability) { angular.forEach($rootScope.$storage.addedCapabilities, function(addedCapability) {
$rootScope.$storage.capabilitiesForProfile.push(addedCapability); $rootScope.$storage.capabilitiesForProfile.push(addedCapability);
}); });
console.log($rootScope.$storage.capabilitiesForProfile.length); console.log("Capabilities in profiles : " + $rootScope.$storage.capabilitiesForProfile.length);
}, },
function(errors) { function(errors) {
...@@ -306,8 +313,18 @@ ProfileController.controller('AddProfileController', ['$scope', '$rootScope', 'P ...@@ -306,8 +313,18 @@ ProfileController.controller('AddProfileController', ['$scope', '$rootScope', 'P
ProfileController.controller('EditProfileController', ['$scope', '$rootScope', 'ProfileService', '$location', '$localStorage', '$routeParams', 'ngToast', function($scope, $rootScope, ProfileService, $location, $localStorage, $routeParams, ngToast) { ProfileController.controller('EditProfileController', ['$scope', '$rootScope', 'ProfileService', '$location', '$localStorage', '$routeParams', 'ngToast', function($scope, $rootScope, ProfileService, $location, $localStorage, $routeParams, ngToast) {
// $scope.capabilities = $rootScope.$storage.capabilitiesForProfile; // $scope.capabilities = $rootScope.$storage.capabilitiesForProfile;
// $scope.profiles = $rootScope.$storage.profiles; // $scope.profiles = $rootScope.$storage.profiles;
$scope.directiveScopes = {
currentIndex: 0
};
$scope.capabilities = angular.copy($rootScope.$storage.capabilitiesForProfile); $scope.capabilities = angular.copy($rootScope.$storage.capabilitiesForProfile);
$scope.profiles = angular.copy($rootScope.$storage.profiles); $scope.profiles = angular.copy($rootScope.$storage.profiles);
$scope.isResultCheckboxDisabled = true;
$scope.toggleResultCheckbox = function() {
$scope.isResultCheckboxDisabled = !$scope.isResultCheckboxDisabled;
$scope.editedCapability.result = (!$scope.isResultCheckboxDisabled) ? $scope.editedCapability.result : '';
};
angular.forEach($scope.capabilities, function(value, key) { angular.forEach($scope.capabilities, function(value, key) {
value.isActive = false; value.isActive = false;
}); });
...@@ -324,19 +341,6 @@ ProfileController.controller('EditProfileController', ['$scope', '$rootScope', ' ...@@ -324,19 +341,6 @@ ProfileController.controller('EditProfileController', ['$scope', '$rootScope', '
} }
}; };
var loadCapabilitiesIntoForm = function(index, capability) {
$scope.editedCapability = JSON.parse(JSON.stringify(capability));
//Not to have same reference
for (var i = $rootScope.protocolsFromEdited.length - 1; i >= 0; i--) {
var dataset = $rootScope.protocolsFromEdited[i];
if (dataset.protocolName == capability.protocol.protocolName) {
$rootScope.protocolsFromEdited[i].parameters = capability.protocol.parameters;
$scope.editedCapability.protocol = $rootScope.protocolsFromEdited[i];
break;
}
}
};
var findProfileById = function(id) { var findProfileById = function(id) {
var profile = {}; var profile = {};
for (var key in $scope.profiles) { for (var key in $scope.profiles) {
...@@ -369,19 +373,83 @@ ProfileController.controller('EditProfileController', ['$scope', '$rootScope', ' ...@@ -369,19 +373,83 @@ ProfileController.controller('EditProfileController', ['$scope', '$rootScope', '
console.log($scope.profile.capabilities); console.log($scope.profile.capabilities);
}; };
var initializeDirectiveScopes = function() {
for (var i = 0; i < $scope.capabilities.length; i++) {
$scope.directiveScopes[i] = {};
if ($scope.capabilities[i].params) {
$scope.directiveScopes[i].counter = $scope.capabilities[i].params.length;
} else $scope.directiveScopes[i].counter = 0;
}
$scope.directiveScopes.currentIndex = 0;
console.log($scope.directiveScopes);
};
initializeDirectiveScopes();
var loadCapabilitiesIntoForm = function(index, capability) {
$scope.editedCapability = capability;
//Not to have same reference
for (var i = $rootScope.protocolsFromEdited.length - 1; i >= 0; i--) {
var dataset = $rootScope.protocolsFromEdited[i];
if (dataset.protocolName == capability.protocol.protocolName) {
$rootScope.protocolsFromEdited[i].parameters = capability.protocol.parameters;
$scope.editedCapability.protocol = $rootScope.protocolsFromEdited[i];
break;
}
}
};
/*Function for setting the capability to modify to the scope and display the edition section*/ /*Function for setting the capability to modify to the scope and display the edition section*/
$scope.openAndEditCapability = function(index, capability){ $scope.openAndEditCapability = function(index, capability){
loadCapabilitiesIntoForm(index, capability); // Clone in the first use (openAndEditCapability), not in the second use of capability (loadCapabilitiesIntoForm)
var cloneCapability = angular.copy(capability);
loadCapabilitiesIntoForm(index, cloneCapability); // this is to fill up the $scope.editedCapability
$scope.isResultCheckboxDisabled = ($scope.editedCapability.result) ? false : true;
$scope.directiveScopes.currentIndex = index;
$scope.directiveScopes.loadParams($scope.editedCapability.params); // methode in directive
}; };
$scope.editCapability = function(editedCapability) { $scope.editCapability = function(editedCapability) {
for (var i in $scope.profile.capabilities) {
if ($scope.profile.capabilities[i].id == editedCapability.id) { if (editedCapability.protocol.protocolName != null && editedCapability.protocol.parameters!= null) {
$scope.profile.capabilities[i] = editedCapability; console.log(editedCapability);
break;
// BEGIN /!\ : This code below is to fix directive bug
var cap = {};
cap.params = [];
if (editedCapability.params instanceof Object) {
for (var key in editedCapability.params) {
cap.params.push(editedCapability.params[key]);
}
} else if (editedCapability.params instanceof Array) {
cap.params = editedCapability.params ? editedCapability.params : [];
}
editedCapability.params = cap.params;
// END /!\
for (var i in $scope.profile.capabilities) {
if ($scope.profile.capabilities[i].id == editedCapability.id) {
$scope.profile.capabilities[i] = angular.copy(editedCapability);
break;
}
}
for (var i in $scope.capabilities) {
if ($scope.capabilities[i].id == editedCapability.id) {
$scope.capabilities[i] = angular.copy(editedCapability);
break;
}
} }
console.log($scope.profile);
} }
console.log($scope.profile);
}; };
$scope.edit = function() { $scope.edit = function() {
...@@ -392,7 +460,7 @@ ProfileController.controller('EditProfileController', ['$scope', '$rootScope', ' ...@@ -392,7 +460,7 @@ ProfileController.controller('EditProfileController', ['$scope', '$rootScope', '
}); });
if (profile.name && profile.description) { if (profile.name && profile.description) {
if (profile.capabilities) { if (profile.capabilities) {
profile.capabilities = JSON.stringify($scope.profile.capabilities); profile.capabilities = JSON.stringify(profile.capabilities);
} }
console.log(profile); console.log(profile);
//$location.path('/profile'); //$location.path('/profile');
......
...@@ -2,19 +2,47 @@ ...@@ -2,19 +2,47 @@
ProfileController.directive('addParamIntoCapability',['$compile', function($compile) { ProfileController.directive('addParamIntoCapability',['$compile', function($compile) {
return { return {
restrict: 'AC', restrict: 'AEC',
replace: true,
scope: {
directiveScope: '=',
newCapability: '=',
currentIndex: '='
},
link: function(scope, elem, attrs) { link: function(scope, elem, attrs) {
scope.counter = 0;
scope.addParamIntoCapability = function() { scope.directiveScope.loadParams = function(params) {
var template = '<div class="form-inline paramDirective" role="form" style="margin-top: 10px;" id="parameter'+scope.counter+'"><h4>Parameter</h4><div class="form-group"><label for="name">Name</label><input type="text" class="form-control" ng-model="newCapability.params['+scope.counter+'].idp" /><div class="form-group"><label for="type">Type</label><select class="form-control" ng-model="newCapability.params['+scope.counter+'].type"><option value="int">int</option><option value="string">string</option></select></div><div class="form-group"><button type="button" class="btn btn-danger" ng-click="removeParamFromCapability('+scope.counter+')"><span class="glyphicon glyphicon-minus"></span></button></div></div></div>'; elem.html('');
if (params) {
for (var i = 0; i < params.length; i++) {
var template = '<div class="form-inline" role="form" style="margin-top: 10px;" id="parameter'+i+'"><h4>Parameter</h4><div class="form-group"><label for="name">Name</label><input type="text" class="form-control" ng-model="newCapability.params['+i+'].idp" /><div class="form-group"><label for="type">Type</label><select class="form-control" ng-model="newCapability.params['+i+'].type"><option value="int">int</option><option value="string">string</option></select></div><div class="form-group"><button type="button" class="btn btn-danger" ng-click="removeParamFromCapability('+i+')"><span class="glyphicon glyphicon-minus"></span></button></div></div></div>';
elem.append($compile(template)(scope));
}
}
};
scope.directiveScope.addParamIntoCapability = function() {
var template = '';
if (scope.currentIndex) {
//console.log('Current index in directive : ' + scope.currentIndex);
//console.log('Counter in current directive scope : ' + scope.directiveScope[scope.currentIndex].counter);
template = '<div class="form-inline" role="form" style="margin-top: 10px;" id="parameter'+scope.directiveScope[scope.currentIndex].counter+'"><h4>Parameter</h4><div class="form-group"><label for="name">Name</label><input type="text" class="form-control" ng-model="newCapability.params['+scope.directiveScope[scope.currentIndex].counter+'].idp" /><div class="form-group"><label for="type">Type</label><select class="form-control" ng-model="newCapability.params['+scope.directiveScope[scope.currentIndex].counter+'].type"><option value="int">int</option><option value="string">string</option></select></div><div class="form-group"><button type="button" class="btn btn-danger" ng-click="removeParamFromCapability('+scope.directiveScope[scope.currentIndex].counter+')"><span class="glyphicon glyphicon-minus"></span></button></div></div></div>';
scope.directiveScope[scope.currentIndex].counter++;
} else {
template = '<div class="form-inline" role="form" style="margin-top: 10px;" id="parameter'+scope.directiveScope.counter+'"><h4>Parameter</h4><div class="form-group"><label for="name">Name</label><input type="text" class="form-control" ng-model="newCapability.params['+scope.directiveScope.counter+'].idp" /><div class="form-group"><label for="type">Type</label><select class="form-control" ng-model="newCapability.params['+scope.directiveScope.counter+'].type"><option value="int">int</option><option value="string">string</option></select></div><div class="form-group"><button type="button" class="btn btn-danger" ng-click="removeParamFromCapability('+scope.directiveScope.counter+')"><span class="glyphicon glyphicon-minus"></span></button></div></div></div>';
scope.directiveScope.counter++;
}
elem.append($compile(template)(scope)); elem.append($compile(template)(scope));
scope.counter++;
}; };
scope.removeParamFromCapability = function(id) { scope.removeParamFromCapability = function(id) {
angular.element(document.querySelector('#parameter'+id)).remove(); angular.element(document.querySelector('#parameter'+id)).remove();
scope.newCapability.params.splice(id, 1); // Here, we shouldn't use scope.newCapability.splice because it will re-arrange the array's order which occured the bug
delete scope.newCapability.params[id];
console.log(scope.newCapability);
}; };
......
...@@ -55,9 +55,17 @@ ...@@ -55,9 +55,17 @@
<li ng-repeat="parameter in detailCapability.protocol.parameters"> <li ng-repeat="parameter in detailCapability.protocol.parameters">
{{parameter.name}}:{{parameter.value}} {{parameter.name}}:{{parameter.value}}
</li> </li>
<br> <br>
<li ng-repeat="param in detailCapability.params">
{{param.idp}}:{{param.type}}
</li>
<br>
<strong ng-if="detailCapability.result">Result : {{detailCapability.result}}</strong>
<li> Keywords </li> <li> Keywords </li>
<tags-input ng-model="detailCapability.keywords"></tags-input> <tags-input ng-model="detailCapability.keywords"></tags-input>
<br> <br>
......
...@@ -20,12 +20,13 @@ ...@@ -20,12 +20,13 @@
<a href class="list-group-item" ng-click="chooseCapability(capability)" ng-class="{active: capability.isActive}" ng-bind-template="{{capability.id}}"></a> <a href class="list-group-item" ng-click="chooseCapability(capability)" ng-class="{active: capability.isActive}" ng-bind-template="{{capability.id}}"></a>
</div> </div>
<div class="col-md-1"> <div class="col-md-1">
<a class="btn btn-info" data-toggle="modal" data-target="#editCapabilityModal" ng-click="openAndEditCapability($index, capability)">Edit</a><br /> <a class="btn btn-info" data-toggle="modal" data-target="#editCapabilityModal" ng-click="openAndEditCapability($index, capability)">Edit</a><br />
</div> </div>
</div> </div>
</div> </div>
<!-- EDIT CAPACBILITY --> <!-- EDIT CAPACBILITY -->
<div class="modal fade" tabindex="-1" role="dialog" id="editCapabilityModal"> <div class="modal fade" tabindex="-1" role="dialog" id="editCapabilityModal">
<div class="modal-dialog"> <div class="modal-dialog">
...@@ -45,12 +46,65 @@ ...@@ -45,12 +46,65 @@
</select> </select>
</li> </li>
<li ng-repeat="parameter in editedCapability.protocol.parameters"> <li ng-repeat="parameter in editedCapability.protocol.parameters">
{{parameter.name}}: {{parameter.name}}:
<input class="form-control" style="width: 40%;" type="text" ng-model="parameter.value"> <input ng-if="parameter.name != 'method'" class="form-control" style="width: 40%;" type="text" ng-model="parameter.value">
<select class="form-control" ng-model="parameter.value" ng-if="parameter.name == 'method'">
<option value="GET">GET</option>
<option value="POST">POST</option>
<option value="DELETE">DELETE</option>
<option value="PUT">PUT</option>
<option value="PATCH">PATCH</option>
</select>
</li> </li>
<br> <br>
<li> Keywords </li>
<tags-input ng-model="editedCapability.keywords"></tags-input>
<!-- <div ng-repeat="param in editedCapability.params" class="form-inline" id="parameter{{$index}}" role="form" style="margin-top: 10px;">
<h4>Parameter</h4>
<div class="form-group">
<label for="name">Name</label>
<input class="form-control" type="text" ng-model="param.idp" />
<div class="form-group">
<label for="type">Type</label>
<select class="form-control" ng-model="param.type">
<option value="int">
int
</option>
<option value="string">
string
</option>
</select>
</div>
<div class="form-group">
<button class="btn btn-danger" type="button"><span class=
"glyphicon glyphicon-minus" ng-click="directiveScopes.removeParamFromCapability($index)"></span></button>
</div>
</div>
</div> -->
<div add-param-into-capability directive-scope="directiveScopes" new-capability="editedCapability" current-index="directiveScopes.currentIndex"></div>
<!-- /!\ : Binding with element of an array is not allowed, ex: ng-click="directiveScopes[directiveScopes.currentIndex].addParamIntoCapability()" -->
<button type="button" class="btn btn-primary" ng-click="directiveScopes.addParamIntoCapability()"><span class="glyphicon glyphicon-plus"></span></button>
<br />
<div class="row form-inline">
<div class="checkbox checkbox-primary col-md-2">
<input type="checkbox" name="result" ng-click="toggleResultCheckbox()" ng-checked="!isResultCheckboxDisabled" />
<label style="font-weight: bold;">
Result
</label>
</div>
<div class="col-md-6 col-md-offset-4">
<label for="name">Result</label>
<input type="text" ng-model="editedCapability.result" ng-disabled="isResultCheckboxDisabled" />
</div>
</div>
<li>Keywords </li>
<tags-input ng-model="editedCapability.keywords"></tags-input>
<br> <br>
......
...@@ -100,7 +100,7 @@ ...@@ -100,7 +100,7 @@
New one New one
<!--Create a new capability--> <!--Create a new capability-->
</accordion-heading> </accordion-heading>
<form ng-submit="addCapability(newCapability)"> <form >
<strong>ID</strong> <strong>ID</strong>
<input class="form-control" style="width: 40%" type="text" placeholder="Type an ID... (Required)" ng-model="newCapability.id" required> <input class="form-control" style="width: 40%" type="text" placeholder="Type an ID... (Required)" ng-model="newCapability.id" required>
<strong>Protocol </strong> <strong>Protocol </strong>
...@@ -143,9 +143,9 @@ ...@@ -143,9 +143,9 @@
</div> </div>
</div>--> </div>-->
<div add-param-into-capability></div> <div add-param-into-capability directive-scope="directiveScope" new-capability="newCapability"></div>
<button type="button" class="btn btn-primary" ng-click="addParamIntoCapability()"><span class="glyphicon glyphicon-plus"></span></button> <button type="button" class="btn btn-primary" ng-click="directiveScope.addParamIntoCapability()"><span class="glyphicon glyphicon-plus"></span></button>
<br> <br>
<div class="row form-inline"> <div class="row form-inline">
...@@ -169,7 +169,7 @@ ...@@ -169,7 +169,7 @@
<!-- Reset capability button --> <!-- Reset capability button -->
<button type="button" class="btn btn-primary pull-left">Reset</button> <button type="button" class="btn btn-primary pull-left">Reset</button>
<!-- Add capability button --> <!-- Add capability button -->
<input style="margin-left:5px" class="btn btn-success pull-right" type="submit" value="Add" /> <button type="button" ng-click="addCapability(newCapability)" class="btn btn-success pull-right">Add</button>
<!-- Test capability button --> <!-- Test capability button -->
<!-- <button ng-click="testCapability(newCapability)" type="button" class="btn btn-primary pull-right">Test</button> --> <!-- <button ng-click="testCapability(newCapability)" type="button" class="btn btn-primary pull-right">Test</button> -->
</form> </form>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment