mirror of
https://github.com/Doodle3D/doodle3d-client.git
synced 2025-01-07 10:56:29 +01:00
API refactoring
This commit is contained in:
parent
43a131acde
commit
e82703420c
@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var API = function() {
|
var API = function() {
|
||||||
|
var className = 'API';
|
||||||
var _wifiboxURL = 'http://192.168.5.1/d3dapi/';
|
var _wifiboxURL = 'http://192.168.5.1/d3dapi/';
|
||||||
var _wifiboxCGIBinURL = 'http://192.168.5.1/cgi-bin/d3dapi/';
|
var _wifiboxCGIBinURL = 'http://192.168.5.1/cgi-bin/d3dapi/';
|
||||||
var _timeoutTime = 10000;
|
var _timeoutTime = 10000;
|
||||||
@ -29,40 +29,41 @@ var API = function() {
|
|||||||
success: function(response){
|
success: function(response){
|
||||||
_isBusy = false;
|
_isBusy = false;
|
||||||
if(response.status == "error" || response.status == "fail") {
|
if(response.status == "error" || response.status == "fail") {
|
||||||
console.log('API.post fail',cmd)
|
console.log(className,'post fail',cmd)
|
||||||
if (fail) fail(response);
|
if (fail) fail(response);
|
||||||
} else {
|
} else {
|
||||||
if (success) success(response.data);
|
if (success) success(response.data);
|
||||||
else console.log('API.post:',cmd,'success cb undefined')
|
else console.log(className,'post:',cmd,'success cb undefined')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).fail(function(jqXHR, textStatus) {
|
}).fail(function(jqXHR, textStatus) {
|
||||||
_isBusy = false;
|
_isBusy = false;
|
||||||
console.log('API.post fail',cmd,jqXHR,textStatus);
|
console.log(className,'post fail',cmd,jqXHR,textStatus);
|
||||||
if (fail) fail(jqXHR,textStatus);
|
if (fail) fail(jqXHR,textStatus);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function get(cmd,success,fail) {
|
function get(cmd,data,success,fail) {
|
||||||
_isBusy = true;
|
_isBusy = true;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: _wifiboxURL + cmd,
|
url: _wifiboxURL + cmd,
|
||||||
type: "GET",
|
type: "GET",
|
||||||
|
data: data,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
timeout: _timeoutTime,
|
timeout: _timeoutTime,
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
_isBusy = false;
|
_isBusy = false;
|
||||||
if (response.status == "error" || response.status == "fail") {
|
if (response.status == "error" || response.status == "fail") {
|
||||||
console.log('API.get fail',cmd,response);
|
console.log(className,'get fail',cmd,response);
|
||||||
if (fail) fail(response);
|
if (fail) fail(response);
|
||||||
} else {
|
} else {
|
||||||
if (success) success(response.data);
|
if (success) success(response.data);
|
||||||
else console.log('API.get:',cmd,'success cb undefined')
|
else console.log(className,'get:',cmd,'success cb undefined')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).fail(function() {
|
}).fail(function() {
|
||||||
_isBusy = false;
|
_isBusy = false;
|
||||||
console.log('API.get fail',cmd);
|
console.log(className,'get fail',cmd);
|
||||||
if (fail) fail();
|
if (fail) fail();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -14,11 +14,15 @@ function ConfigAPI() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadAll(success,fail) {
|
function loadAll(success,fail) {
|
||||||
API.get('config/all',success,fail);
|
API.get('config/all',{},success,fail);
|
||||||
};
|
};
|
||||||
|
|
||||||
function load(key,success,fail) {
|
function load(dataObject,success,fail) {
|
||||||
API.get('config/?'+key+'=',success,fail)
|
// console.log(className,'load',dataObject);
|
||||||
|
API.get('config', dataObject, function(res) {
|
||||||
|
console.log(className,'load get config cb',dataObject,res);
|
||||||
|
if (success) success(res);
|
||||||
|
},fail);
|
||||||
};
|
};
|
||||||
|
|
||||||
function save(newSettings,success,fail) {
|
function save(newSettings,success,fail) {
|
||||||
@ -31,7 +35,8 @@ function ConfigAPI() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function getSetting(key,success,fail) {
|
function getSetting(key,success,fail) {
|
||||||
API.get('config/?'+key+'=',function(response) {
|
console.log(className,'getSetting',key);
|
||||||
|
API.get('config/?'+key+'=',{},function(response) {
|
||||||
if (success) success(response[key]);
|
if (success) success(response[key]);
|
||||||
},fail);
|
},fail);
|
||||||
}
|
}
|
||||||
|
@ -17,19 +17,19 @@ function PrinterAPI() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.state = function(success,fail) {
|
this.state = function(success,fail) {
|
||||||
API.get('printer/state',success,fail);
|
API.get('printer/state',{},success,fail);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.listAll = function(success,fail) {
|
this.listAll = function(success,fail) {
|
||||||
API.get('printer/listall',success,fail);
|
API.get('printer/listall',{},success,fail);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.temperature = function(success,fail) {
|
this.temperature = function(success,fail) {
|
||||||
API.get('printer/temperature',success,fail);
|
API.get('printer/temperature',{},success,fail);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.progress = function(success,fail) {
|
this.progress = function(success,fail) {
|
||||||
API.get('printer/progress',success,fail);
|
API.get('printer/progress',{},success,fail);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _printPartPost(lines,data,cb) {
|
function _printPartPost(lines,data,cb) {
|
||||||
|
@ -9,13 +9,34 @@
|
|||||||
function SketchAPI() {
|
function SketchAPI() {
|
||||||
var className = 'SketchAPI';
|
var className = 'SketchAPI';
|
||||||
|
|
||||||
this.load = function(id,success,fail) {
|
function load(id,success,fail) {
|
||||||
API.get('sketch/?id='+id,success,fail);
|
API.get('sketch/?id='+id,{},success,fail);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.save = function(data,success,fail) {
|
function list(success,fail) {
|
||||||
|
API.get('sketch/list',{},success,fail);
|
||||||
|
}
|
||||||
|
|
||||||
|
function save(data,success,fail) {
|
||||||
console.log(className,'saving sketch',data);
|
console.log(className,'saving sketch',data);
|
||||||
API.post('sketch',{data:data},success,fail);
|
API.post('sketch',{data:data},success,fail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function del(id,success,fail) {
|
||||||
|
console.log(className,'deleting sketch',id);
|
||||||
|
API.post('sketch/delete',{id:id},success,fail);
|
||||||
|
}
|
||||||
|
|
||||||
|
function status(success,fail) {
|
||||||
|
API.get('sketch/status',{},success,fail);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
load: load,
|
||||||
|
list: list,
|
||||||
|
save: save,
|
||||||
|
status: status,
|
||||||
|
del: del,
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user