Skip to content

Commit

Permalink
leshan-bsserver-demo now delete only object /0 and /1
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Apr 2, 2019
1 parent 3d20110 commit f7628dd
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions leshan-bsserver-demo/src/main/resources/webapp/js/bsconfigstore.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// convert config from server format to UI format :
// convert config from rest API format to UI format :
// we regroup security and server data
var convertConfig = function(config){
var configFromRestToUI = function(config){
var newConfig = {dm:[],bs:[]};
for (var i in config.security){
var security = config.security[i];
Expand All @@ -23,16 +23,16 @@ var convertConfig = function(config){
}
return newConfig;
};
var convertConfigs = function(configs){
var configsFromRestToUI = function(configs){
var newConfigs = {};
for (var endpoint in configs){
newConfigs[endpoint] = convertConfig(configs[endpoint]);
newConfigs[endpoint] = configFromRestToUI(configs[endpoint]);
}
return newConfigs;
};

//convert config from UI to UI server:
var toConfig = function(config){
//convert config from UI to rest API format:
var configFromUIToRest = function(config){
var newConfig = {servers:{}, security:{}};
for (var i = 0; i < config.bs.length; i++) {
var bs = config.bs[i];
Expand All @@ -44,6 +44,7 @@ var toConfig = function(config){
delete dm.security;
newConfig.servers[j] = dm;
}
newConfig.toDelete = ["/0", "/1"]
return newConfig;
};

Expand All @@ -57,7 +58,7 @@ function BsConfigStore() {

self.init = function (){
$.get('api/bootstrap', function(data) {
self.bsconfigs = convertConfigs(data);
self.bsconfigs = configsFromRestToUI(data);
self.trigger('changed', self.bsconfigs);
}).fail(function(xhr, status, error){
var err = "Unable to get the bootstrap info list";
Expand All @@ -67,15 +68,14 @@ function BsConfigStore() {
};

self.add = function(endpoint,config) {
var data = toConfig(config);
console.log(data);
var data = configFromUIToRest(config);
$.ajax({
type: "POST",
url: 'api/bootstrap/'+endpoint,
data: JSON.stringify(data),
contentType:"application/json; charset=utf-8",
}).done(function () {
self.bsconfigs[endpoint] = convertConfig(data);
self.bsconfigs[endpoint] = configFromRestToUI(data);
self.trigger('changed', self.bsconfigs);
}).fail(function (xhr, status, error) {
var err = "Unable to post the bootstrap config";
Expand Down

0 comments on commit f7628dd

Please sign in to comment.