removed chaining in sub api's

made no sense to be able to chain sub api’s
This commit is contained in:
casperlamboo 2015-07-17 16:02:27 +02:00
parent 2fee42adae
commit 2b7cedfcf6
10 changed files with 27 additions and 92 deletions

View File

@ -1,18 +1,19 @@
import Doodle3DAPI from 'doodle3d-API';
import rest from 'rest-API';
var api = "http://connect.doodle3d.com/api/";
var api = 'http://connect.doodle3d.com/api/';
var known = [];
function addBox (boxData) {
if (know.indexOf(boxData.localip) === -1) {
if (known.indexOf(boxData.localip) === -1) {
known.push(boxData.localip);
var row = document.createElement('tr');
row.style.color = "gray";
row.style.color = 'gray';
var id = document.createElement('td');
var state = document.createElement('td');
var localIP = document.createElement('td');
var bed = document.createElement('td');
var bedTarget = document.createElement('td');
@ -21,36 +22,36 @@ function addBox (boxData) {
var hasControl = document.createElement('td');
var hotend = document.createElement('td');
var hotendTarget = document.createElement('td');
var state = document.createElement('td');
var totalLines = document.createElement('td');
row.appendChild(id);
row.appendChild(localIP);
row.appendChild(bed);
row.appendChild(bedTarget);
row.appendChild(bufferedLines);
row.appendChild(state);
row.appendChild(currentLine);
row.appendChild(hasControl);
row.appendChild(bufferedLines);
row.appendChild(totalLines);
row.appendChild(hotend);
row.appendChild(hotendTarget);
row.appendChild(state);
row.appendChild(totalLines);
row.appendChild(bed);
row.appendChild(bedTarget);
row.appendChild(hasControl);
id.innerHTML = boxData.wifiboxid;
localIP.innerHTML = boxData.localip;
document.getElementById("table").appendChild(row);
document.getElementById('table').appendChild(row);
var doodle3DAPI = new Doodle3DAPI(boxData.localip);
doodle3DAPI.onconnect = function () {
row.style.color = "black";
row.style.color = 'black';
};
doodle3DAPI.ondisconnect = function () {
row.style.color = "gray";
row.style.color = 'gray';
};
doodle3DAPI.onupdate = function (data) {
console.log(data);
state.innerHTML = data.state;
if (data.state === "idle") {
if (data.state !== 'disconnected' && data.state !== 'connecting' && data.state !== 'unknown') {
bed.innerHTML = data.bed;
bedTarget.innerHTML = data.bed_target;
bufferedLines.innerHTML = data.buffered_lines;
@ -69,7 +70,7 @@ function addBox (boxData) {
}
function searchBoxes () {
rest.get(api + "list.php", function (error, boxes) {
rest.get(api + 'list.php', function (error, boxes) {
if (error) {
return;
console.warn(error);
@ -87,11 +88,11 @@ setInterval(searchBoxes, 5000);
searchBoxes();
addBox({
localip: window.location.host + ":3000",
wifiboxid: "Node Server"
localip: window.location.host + ':3000',
wifiboxid: 'Node Server'
});
addBox({
localip: "192.168.5.1",
wifiboxid: "Wired Printer"
localip: '192.168.5.1',
wifiboxid: 'Wired Printer'
});

View File

@ -27,15 +27,15 @@
<tr>
<th>ID</th>
<th>Local IP</th>
<th>Bed</th>
<th>Bed Target</th>
<th>Buffered Lines</th>
<th>State</th>
<th>Current Line</th>
<th>Has Control</th>
<th>Buffered Lines</th>
<th>Total Lines</th>
<th>Hotend</th>
<th>Hotend Target</th>
<th>State</th>
<th>Total Lines</th>
<th>Bed</th>
<th>Bed Target</th>
<th>Has Control</th>
</tr>
</tbody>
</table>

View File

@ -8,31 +8,20 @@ export default class {
get (keys, callback) {
rest.get(this.api + 'config/?' + keys.join('=&') + '=', callback);
return this;
}
getAll (callback) {
rest.get(this.api + 'config/all', callback);
return this;
}
set (data, callback) {
var scope = this;
rest.post(this.api + 'config', data, function (response) {
/*for (var i in response.validation) {
if (response.validation[i] === 'ok') {
scope[i] = data[i];
}
}*/
if (callback !== undefined) {
callback(response);
}
});
return this;
}
}

View File

@ -8,14 +8,10 @@ export default class {
get (callback) {
rest.get(this.api + 'info', callback);
return this;
}
status (callback) {
rest.get(this.api + 'info/status', callback);
return this;
}
downloadLogFiles () {
@ -24,7 +20,5 @@ export default class {
acces (callback) {
rest.get(this.api + 'info/access', callback);
return this;
}
}

View File

@ -8,61 +8,43 @@ export default class {
scan (callback) {
rest.get(this.api + 'network/scan', callback);
return this;
}
known (callback) {
rest.get(this.api + 'network/known', callback);
return this;
}
status (callback) {
rest.get(this.api + 'network/status', callback);
return this;
}
assosiate (data, callback) {
rest.post(this.api + 'network/associate', data, callback);
return this;
}
disassosiate (callback) {
//not tested
rest.post(this.api + 'network/disassociate', {}, callback);
return this;
}
openAccesPoint (callback) {
//not tested
rest.post(this.api + 'network/openap', {}, callback);
return this;
}
remove (ssid, callback) {
rest.post(this.api + 'network/remove', {
'ssid': ssid
}, callback);
return this;
}
signin (callback) {
rest.get(this.api + 'network/signin', callback);
return this;
}
alive (callback) {
rest.get(this.api + 'network/alive', callback);
return this;
}
}

View File

@ -8,43 +8,29 @@ export default class {
temperature (callback) {
rest.get(this.api + 'printer/temperature', callback);
return this;
}
progress (callback) {
rest.get(this.api + 'printer/progress', callback);
return this;
}
state (callback) {
rest.get(this.api + 'printer/state', callback);
return this;
}
listAll (callback) {
rest.get(this.api + 'printer/listall', callback);
return this;
}
heatup (callback) {
rest.post(this.api + 'printer/heatup', {}, callback);
return this;
}
print (data, callback) {
rest.post(this.api + 'printer/print', data, callback);
return this;
}
stop (data, callback) {
rest.post(this.api + 'printer/stop', data, callback);
return this;
}
}

View File

@ -1,4 +1,5 @@
import $ from 'jquery';
//in future remove jquery and use framework specificly for ajax calls or write own ajax calls
export default {
post (url, data, callback) {

View File

@ -8,27 +8,19 @@ export default class {
getSketch (id, callback) {
rest.get(this.api + 'sketch/?id=' + id, callback);
return this;
}
set (data, callback) {
rest.post(this.api + 'sketch', {
'data': data
}, callback);
return this;
}
status (callback) {
rest.get(this.api + 'sketch/status', callback);
return this;
}
clear (callback) {
rest.post(this.api + 'sketch/clear', callback);
return this;
}
}

View File

@ -8,7 +8,5 @@ export default class {
versions (callback) {
rest.get(this.api + 'system/fwversions', callback);
return this;
}
}

View File

@ -8,31 +8,23 @@ export default class {
status (callback) {
rest.get(this.api + 'update/status', callback);
return this;
}
download (callback) {
//not tested
rest.post(this.api + 'update/download', {}, callback);
return this;
}
install (callback) {
//not tested
rest.post(this.api + 'update/install', {}, callback);
return this;
}
clear (callback) {
//not tested
rest.post(this.api + 'update/clear', {}, callback);
return this;
}
}