mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2026-03-03 16:04:53 +01:00
Several bugfixes to the uci system
This commit is contained in:
parent
39af08f512
commit
db7ebecce3
6 changed files with 155 additions and 65 deletions
|
|
@ -272,7 +272,7 @@
|
|||
}
|
||||
UCISection.prototype.$delete = function(){
|
||||
var self = this;
|
||||
if(self[".config"]) return self[".config"].$deleteSection(self[".name"]);
|
||||
if(self[".config"]) return self[".config"].$deleteSection(self);
|
||||
var def = $.Deferred(); def.reject();
|
||||
return def.promise();
|
||||
}
|
||||
|
|
@ -283,7 +283,7 @@
|
|||
var changed = {};
|
||||
Object.keys(type).map(function(k){
|
||||
if(self[k] && self[k].dirty){
|
||||
console.log("Adding dirty field: "+k);
|
||||
//console.log("Adding dirty field: "+k);
|
||||
changed[k] = self[k].value;
|
||||
}
|
||||
});
|
||||
|
|
@ -349,30 +349,42 @@
|
|||
}
|
||||
});
|
||||
}
|
||||
UCIConfig.prototype.$deleteSection = function(name){
|
||||
UCIConfig.prototype.$deleteSection = function(section){
|
||||
var self = this;
|
||||
var deferred = $.Deferred();
|
||||
//console.log("Deleting section "+name);
|
||||
$rpc.uci.delete({
|
||||
"config": self[".name"],
|
||||
"section": name
|
||||
}).done(function(){
|
||||
var item = self[name];
|
||||
console.log("Deleting section "+section[".name"]);
|
||||
|
||||
function _unlinkSection(section){
|
||||
self[".need_commit"] = true;
|
||||
for(var i = 0; i < self["@all"].length; i++){
|
||||
if(self["@all"][i][".name"] == name) {
|
||||
var jlist = self["@"+item[".type"]]||[];
|
||||
if(self["@all"][i] == section) {
|
||||
var jlist = self["@"+section[".type"]]||[];
|
||||
for(var j = 0; j < jlist.length; j++){
|
||||
if(jlist[j][".name"] == name) jlist.splice(j, 1);
|
||||
if(jlist[j] == section) jlist.splice(j, 1);
|
||||
}
|
||||
self["@all"].splice(i, 1);
|
||||
};
|
||||
delete self[name];
|
||||
if(section[".name"]) delete self[section[".name"]];
|
||||
};
|
||||
deferred.resolve();
|
||||
}).fail(function(){
|
||||
deferred.reject();
|
||||
});
|
||||
}
|
||||
|
||||
if(section[".new"] == true){
|
||||
_unlinkSection(section);
|
||||
setTimeout(function(){
|
||||
deferred.resolve();
|
||||
}, 0);
|
||||
} else {
|
||||
$rpc.uci.delete({
|
||||
"config": self[".name"],
|
||||
"section": section[".name"]
|
||||
}).done(function(){
|
||||
console.log("Deleted section "+section[".name"]+" from server");
|
||||
_unlinkSection(section);
|
||||
deferred.resolve();
|
||||
}).fail(function(){
|
||||
deferred.reject();
|
||||
});
|
||||
}
|
||||
return deferred.promise();
|
||||
}
|
||||
// creates a new object that will have values set to values
|
||||
|
|
@ -391,7 +403,14 @@
|
|||
}
|
||||
});
|
||||
var deferred = $.Deferred();
|
||||
$rpc.uci.add({
|
||||
console.log("Adding: "+item[".type"]+": "+JSON.stringify(values));
|
||||
var section = _insertSection(self, item);
|
||||
section[".new"] = true;
|
||||
self[".need_commit"] = true;
|
||||
setTimeout(function(){
|
||||
deferred.resolve(section);
|
||||
}, 0);
|
||||
/*$rpc.uci.add({
|
||||
"config": self[".name"],
|
||||
"type": item[".type"],
|
||||
"name": item[".name"],
|
||||
|
|
@ -404,7 +423,7 @@
|
|||
deferred.resolve(section);
|
||||
}).fail(function(){
|
||||
deferred.reject();
|
||||
});
|
||||
}); */
|
||||
return deferred.promise();
|
||||
}
|
||||
UCIConfig.prototype.$getWriteRequests = function(){
|
||||
|
|
@ -423,6 +442,24 @@
|
|||
});
|
||||
return reqlist;
|
||||
}
|
||||
UCIConfig.prototype.$getAddRequests = function(){
|
||||
var self = this;
|
||||
var reqlist = [];
|
||||
self["@all"].map(function(section){
|
||||
if(section[".new"] == true){
|
||||
reqlist.push({
|
||||
section: section,
|
||||
cmd: {
|
||||
"config": self[".name"],
|
||||
"type": section[".type"],
|
||||
"name": section[".name"],
|
||||
"values": {}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return reqlist;
|
||||
}
|
||||
UCI.Config = UCIConfig;
|
||||
})();
|
||||
|
||||
|
|
@ -483,52 +520,91 @@
|
|||
var deferred = $.Deferred();
|
||||
var self = this;
|
||||
var writes = [];
|
||||
var resync = {};
|
||||
var add_requests = [];
|
||||
var resync = [];
|
||||
/*
|
||||
Object.keys(self).map(function(k){
|
||||
if(self[k].constructor == UCI.Config){
|
||||
var reqlist = self[k].$getWriteRequests();
|
||||
if(self[k][".need_commit"]) resync[self[k][".name"]] = true;
|
||||
reqlist.map(function(x){ writes.push(x); });
|
||||
var adds = self[k].$getAddRequests();
|
||||
adds.map(function(x){ add_requests.push(x); });
|
||||
}
|
||||
});
|
||||
console.log("Will do following write requests: "+JSON.stringify(writes)+ " "+JSON.stringify(resync));
|
||||
}); */
|
||||
/*if(writes.length == 0) {
|
||||
setTimeout(function(){ deferred.resolve(); }, 0);
|
||||
return deferred.promise();
|
||||
}*/
|
||||
async.eachSeries(writes, function(cmd, next){
|
||||
$rpc.uci.set(cmd).done(function(){
|
||||
console.log("Wrote config "+cmd.config);
|
||||
resync[cmd.config] = true;
|
||||
next();
|
||||
}).fail(function(){
|
||||
console.error("Failed to write config "+cmd.config);
|
||||
next();
|
||||
});
|
||||
}, function(){
|
||||
async.eachSeries(Object.keys(resync), function(key, next){
|
||||
var config = resync[key];
|
||||
console.log("Committing config "+config);
|
||||
$rpc.uci.commit({config: config}).done(function(){
|
||||
console.log("Resynching config "+config);
|
||||
self[config][".need_commit"] = false;
|
||||
self[config].$sync().done(function(){
|
||||
next();
|
||||
}).fail(function(err){
|
||||
console.log("error synching config "+config+": "+err);
|
||||
next("syncerror");
|
||||
});
|
||||
}).fail(function(err){
|
||||
next("could not commit config: "+err);
|
||||
async.series([
|
||||
function(next){
|
||||
Object.keys(self).map(function(k){
|
||||
if(self[k].constructor == UCI.Config){
|
||||
var adds = self[k].$getAddRequests();
|
||||
adds.map(function(x){ add_requests.push(x); });
|
||||
}
|
||||
});
|
||||
}, function(err){
|
||||
// this is to always make sure that we do this outside of this code flow
|
||||
setTimeout(function(){
|
||||
if(err) deferred.reject(err);
|
||||
else deferred.resolve(err);
|
||||
},0);
|
||||
});
|
||||
});
|
||||
async.eachSeries(add_requests, function(req, next){
|
||||
console.log("Adding new section "+req.cmd.config+".@"+req.cmd.type);
|
||||
$rpc.uci.add(req.cmd).done(function(state){
|
||||
req.section[".name"] = state.section;
|
||||
self[req.cmd.config][state.section] = req.section;
|
||||
delete req.section[".new"];
|
||||
next();
|
||||
}).fail(function(){
|
||||
next();
|
||||
});
|
||||
}, function(){
|
||||
next();
|
||||
});
|
||||
},
|
||||
function(next){
|
||||
Object.keys(self).map(function(k){
|
||||
if(self[k].constructor == UCI.Config){
|
||||
var reqlist = self[k].$getWriteRequests();
|
||||
if(self[k][".need_commit"]) resync.push(self[k][".name"]);
|
||||
reqlist.map(function(x){ writes.push(x); });
|
||||
}
|
||||
});
|
||||
console.log("Will do following write requests: "+JSON.stringify(writes));
|
||||
async.eachSeries(writes, function(cmd, next){
|
||||
$rpc.uci.set(cmd).done(function(){
|
||||
console.log("Wrote config "+cmd.config);
|
||||
resync.push(cmd.config);
|
||||
next();
|
||||
}).fail(function(){
|
||||
console.error("Failed to write config "+cmd.config);
|
||||
next();
|
||||
});
|
||||
}, function(){
|
||||
next();
|
||||
});
|
||||
},
|
||||
|
||||
function(next){
|
||||
async.eachSeries(resync, function(config, next){
|
||||
console.log("Committing config "+config);
|
||||
$rpc.uci.commit({config: config}).done(function(){
|
||||
console.log("Resynching config "+config);
|
||||
self[config][".need_commit"] = false;
|
||||
self[config].$sync().done(function(){
|
||||
next();
|
||||
}).fail(function(err){
|
||||
console.log("error synching config "+config+": "+err);
|
||||
next("syncerror");
|
||||
});
|
||||
}).fail(function(err){
|
||||
next("could not commit config: "+err);
|
||||
});
|
||||
}, function(err){
|
||||
// this is to always make sure that we do this outside of this code flow
|
||||
setTimeout(function(){
|
||||
if(err) deferred.reject(err);
|
||||
else deferred.resolve(err);
|
||||
},0);
|
||||
});
|
||||
}
|
||||
]);
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ $juci.module("core")
|
|||
}
|
||||
});
|
||||
scope.$watch("selectedItem", function(value){
|
||||
console.log("Selected item: "+JSON.stringify(value));
|
||||
//console.log("Selected item: "+JSON.stringify(value));
|
||||
if(value != undefined && (typeof value) == "object" && "value" in value) scope.selectedText = value.value;
|
||||
else if(value != undefined) {
|
||||
scope.itemList.map(function(x){
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@
|
|||
</table>
|
||||
<luci-config-apply></luci-config-apply>
|
||||
<modal title="Add a new WiFi Schedule" ng-show="showScheduleDialog" on-accept="onAcceptSchedule()"
|
||||
on-dismiss="onDismissSchedule()" dismiss-label="Cancel" accept-label="Save">
|
||||
<uci-wireless-schedule-edit ng-model="schedule"></uci-wireless-schedule-edit>
|
||||
on-dismiss="onDismissSchedule()" dismiss-label="Cancel" accept-label="Save" hide-close-btn="true">
|
||||
<uci-wireless-schedule-edit ng-model="schedule" schedule="schedule" data="editedData"></uci-wireless-schedule-edit>
|
||||
</modal>
|
||||
</div>
|
||||
</luci-layout-with-sidebar>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ $juci.module("wifi")
|
|||
{ label: gettext("Enabled"), value: 1 },
|
||||
{ label: gettext("Disabled"), value: 0 }
|
||||
];
|
||||
$scope.editedData = { days: [], time: "123 "};
|
||||
|
||||
$uci.sync(["wireless"]).done(function(){
|
||||
console.log("Got status");
|
||||
|
|
@ -24,6 +25,8 @@ $juci.module("wifi")
|
|||
}
|
||||
|
||||
$scope.onDismissSchedule = function(schedule){
|
||||
if($scope.schedule[".new"] == true)
|
||||
$scope.schedule.$delete();
|
||||
$scope.showScheduleDialog = 0;
|
||||
}
|
||||
|
||||
|
|
@ -39,6 +42,7 @@ $juci.module("wifi")
|
|||
}
|
||||
|
||||
$scope.onEditSchedule = function(sched){
|
||||
console.log("Editing: "+sched[".name"]);
|
||||
$scope.schedule = sched;
|
||||
$scope.showScheduleDialog = 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
<div class="modal-body">
|
||||
<luci-config>
|
||||
<luci-config-section>
|
||||
<p>{{schedule.time.value}}</p>
|
||||
<luci-config-lines>
|
||||
<luci-config-line title="{{'Time Frame'|translate}}">
|
||||
<luci-select ng-model="selectedTimeFrame" on-change="onChangeDays()" ng-items="allTimeFrames"></luci-select>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ $juci.module("wifi")
|
|||
return {
|
||||
templateUrl: plugin_root+"/widgets/uci.wireless.schedule.edit.html",
|
||||
scope: {
|
||||
schedule: "=ngModel"
|
||||
schedule: "=schedule"
|
||||
},
|
||||
controller: "uciWirelessScheduleEdit",
|
||||
replace: true,
|
||||
|
|
@ -24,6 +24,7 @@ $juci.module("wifi")
|
|||
}).controller("uciWirelessScheduleEdit", function($scope, gettext, $uci){
|
||||
$scope.selectedTimeFrame = [];
|
||||
$scope.data = {};
|
||||
|
||||
$scope.allTimeFrames = [
|
||||
{ label: gettext("Individual Days"), id: "inddays", value: [] },
|
||||
{ label: gettext("Every Day"), value: ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] },
|
||||
|
|
@ -56,23 +57,31 @@ $juci.module("wifi")
|
|||
}
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
$scope.$watch("data.timeFrom", function(){
|
||||
update_time();
|
||||
}, true);
|
||||
$scope.$watch("data.timeTo", function(){
|
||||
update_time();
|
||||
}, true);
|
||||
|
||||
$scope.$watch("schedule", function(value){
|
||||
if(value == undefined) return;
|
||||
var parts = value.time.value.split("-");//.map(function(x){ return x.split(":"); });
|
||||
$scope.data.timeFrom = parts[0];
|
||||
$scope.data.timeTo = parts[1];
|
||||
console.log("New model" + value.time.value);
|
||||
});
|
||||
console.log("New schedule ");
|
||||
if(value != undefined && value.days && value.time){
|
||||
$scope.data.days = value.days.value.map(function(x){ return x; });
|
||||
var parts = value.time.value.split("-");//.map(function(x){ return x.split(":"); });
|
||||
$scope.data.timeFrom = parts[0];
|
||||
$scope.data.timeTo = parts[1];
|
||||
} else {
|
||||
// create new
|
||||
//$scope.data = { _new: true };
|
||||
}
|
||||
//console.log("New model" + value.time.value);
|
||||
});
|
||||
|
||||
$scope.onChangeDays = function(){
|
||||
//$scope.schedule.days.value.splice(0,$scope.schedule.days.value.length);
|
||||
$scope.schedule.days.value = $scope.selectedTimeFrame;
|
||||
//console.log($scope.selectedTimeFrame);
|
||||
//Object.assign($scope.schedule.days.value, $scope.selectedTimeFrame);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue