From 48693feaab987e28a25dcdd19d9c2377ce88e11c Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Thu, 21 Apr 2016 15:44:20 +0200 Subject: [PATCH] comply with linter --- src/api/config.js | 13 +++++-------- src/api/info.js | 16 ++++++---------- src/api/network.js | 33 +++++++++++---------------------- src/api/printer.js | 25 +++++++++---------------- src/api/sketch.js | 16 ++++++---------- src/api/system.js | 7 +++---- src/api/update.js | 19 ++++++------------- src/doodle3dbox.js | 17 ++++++----------- src/doodle3dmanager.js | 17 ++++++----------- src/rest.js | 4 ++-- src/utils.js | 2 +- 11 files changed, 61 insertions(+), 108 deletions(-) diff --git a/src/api/config.js b/src/api/config.js index 283c621..781d8a3 100644 --- a/src/api/config.js +++ b/src/api/config.js @@ -1,19 +1,16 @@ import * as rest from '../rest.js'; -export default class { - constructor (api) { +export default class Config { + constructor(api) { this.api = api; } - - get (...keys) { + get(...keys) { return rest.get(`${ this.api }config/?${ keys.join('=&') }=`); } - - getAll () { + getAll() { return rest.get(`${ this.api }config/all`); } - - set (data) { + set(data) { return rest.post(`${ this.api }config`, data); } } diff --git a/src/api/info.js b/src/api/info.js index a7485df..29dffc0 100644 --- a/src/api/info.js +++ b/src/api/info.js @@ -1,23 +1,19 @@ import * as rest from '../rest.js'; -export default class { - constructor (api) { +export default class Info { + constructor(api) { this.api = api; } - - get () { + get() { return rest.get(`${ this.api }info`); } - - status () { + status() { return rest.get(`${ this.api }info/status`); } - - downloadLogFiles () { + downloadLogFiles() { window.location = `${ this.api }info/logfiles`; } - - acces () { + acces() { return rest.get(`${ this.api }info/access`); } } diff --git a/src/api/network.js b/src/api/network.js index 1f43706..eca576d 100644 --- a/src/api/network.js +++ b/src/api/network.js @@ -1,51 +1,40 @@ import * as rest from '../rest.js'; -export default class { - constructor (api) { +export default class Network { + constructor(api) { this.api = api; } - - scan () { + scan() { return rest.get(`${ this.api }network/scan`); } - - known () { + known() { return rest.get(`${ this.api }network/known`); } - - status () { + status() { return rest.get(`${ this.api }network/status`); } - - assosiate (ssid, phrase, recreate = false) { + assosiate(ssid, phrase, recreate = false) { const data = { ssid, recreate, phrase }; return rest.post(`${ this.api }network/associate`, data); } - - disassociate () { + disassociate() { //not tested - return rest.post(`${ this.api }network/disassociate`, {}); } - - openAccesPoint () { + openAccesPoint() { //not tested - return rest.post(`${ this.api }network/openap`, {}); } - - remove (ssid) { + remove(ssid) { return rest.post(`${ this.api }network/remove`, { 'ssid': ssid }); } - - signin () { + signin() { return rest.get(`${ this.api }network/signin`); } - - async alive () { + async alive() { try { await rest.get(`${ this.api }network/alive`); diff --git a/src/api/printer.js b/src/api/printer.js index b928912..052d226 100644 --- a/src/api/printer.js +++ b/src/api/printer.js @@ -1,37 +1,30 @@ import * as rest from '../rest.js'; -export default class { - constructor (api) { +export default class Printer { + constructor(api) { this.api = api; } - - temperature () { + temperature() { return rest.get(`${ this.api }printer/temperature`); } - - progress () { + progress() { return rest.get(`${ this.api }printer/progress`); } - - state () { + state() { return rest.get(`${ this.api }printer/state`); } - - listAll () { + listAll() { return rest.get(`${ this.api }printer/listall`); } - - heatup () { + heatup() { return rest.post(`${ this.api }printer/heatup`, {}); } - - print (gcode = '', first = false, start = false, last) { + print(gcode = '', first = false, start = false, last) { const data = { gcode, first, start, last }; return rest.post(`${ this.api }printer/print`, data); } - - stop (gcode = '') { + stop(gcode = '') { const data = { gcode }; return rest.post(`${ this.api }printer/stop`, data); diff --git a/src/api/sketch.js b/src/api/sketch.js index 82fa8ac..c974af9 100644 --- a/src/api/sketch.js +++ b/src/api/sketch.js @@ -1,23 +1,19 @@ import * as rest from '../rest.js'; -export default class { - constructor (api) { +export default class Sketch { + constructor(api) { this.api = api; } - - getSketch (id) { + getSketch(id) { return rest.get(`${ this.api }sketch/?id=${ id }`); } - - set (data = '') { + set(data = '') { return rest.post(`${ this.api }sketch`, { data }); } - - status () { + status() { return rest.get(`${ this.api }sketch/status`); } - - clear () { + clear() { return rest.post(`${ this.api }sketch/clear`); } } diff --git a/src/api/system.js b/src/api/system.js index 96e1273..3506b21 100644 --- a/src/api/system.js +++ b/src/api/system.js @@ -1,11 +1,10 @@ import * as rest from '../rest.js'; -export default class { - constructor (api) { +export default class System { + constructor(api) { this.api = api; } - - versions () { + versions() { return rest.get(`${ this.api }system/fwversions`); } } diff --git a/src/api/update.js b/src/api/update.js index e0eb5fb..098a506 100644 --- a/src/api/update.js +++ b/src/api/update.js @@ -1,29 +1,22 @@ import * as rest from '../rest.js'; -export default class { - constructor (api) { +export default class Update { + constructor(api) { this.api = api; } - - status () { + status() { return rest.get(`${ this.api }update/status`); } - - download () { + download() { //not tested - return rest.post(`${ this.api }update/download`, {}); } - - install () { + install() { //not tested - return rest.post(`${ this.api }update/install`, {}); } - - clear () { + clear() { //not tested - return rest.post(`${ this.api }update/clear`, {}); } } diff --git a/src/doodle3dbox.js b/src/doodle3dbox.js index 360588d..a8e8184 100644 --- a/src/doodle3dbox.js +++ b/src/doodle3dbox.js @@ -9,7 +9,7 @@ import SystemAPI from './api/system.js'; import UpdateAPI from './api/update.js'; export default class Doodle3DBox extends EventDispatcher { - constructor (boxData) { + constructor(boxData) { super(); this.boxData = boxData; @@ -31,8 +31,7 @@ export default class Doodle3DBox extends EventDispatcher { this.system = new SystemAPI(this.api); this.update = new UpdateAPI(this.api); } - - setAutoUpdate (autoUpdate = true, updateInterval = 1000) { + setAutoUpdate(autoUpdate = true, updateInterval = 1000) { this.updateInterval = updateInterval; if (this.autoUpdate === autoUpdate) return; @@ -41,8 +40,7 @@ export default class Doodle3DBox extends EventDispatcher { return this; } - - async checkAlive () { + async checkAlive() { const alive = await this.network.alive(); if (alive !== this.alive) { @@ -53,8 +51,7 @@ export default class Doodle3DBox extends EventDispatcher { this.alive = alive; return alive; } - - async sendGCode (gcode) { + async sendGCode(gcode) { const printerState = await this.printer.state(); if (printerState.state !== 'idle') { throw `Cannot print, print state is ${ printerState.state }`; @@ -78,8 +75,7 @@ export default class Doodle3DBox extends EventDispatcher { lastIndex = index + 1; //skip next \n } } - - async _update () { + async _update() { while (this.autoUpdate) { if (this.alive) { try { @@ -96,8 +92,7 @@ export default class Doodle3DBox extends EventDispatcher { await sleep(this.updateInterval); } } - - async _sendBatch (gcode, start) { + async _sendBatch(gcode, start) { try { const response = await this.printer.print(gcode, start, start); // maybe do something with failing response diff --git a/src/doodle3dmanager.js b/src/doodle3dmanager.js index a7afcb6..af1dd89 100644 --- a/src/doodle3dmanager.js +++ b/src/doodle3dmanager.js @@ -4,7 +4,7 @@ import EventDispatcher from 'casperlamboo/EventDispatcher'; import { sleep } from './utils.js'; export default class Doodle3DManager extends EventDispatcher { - constructor () { + constructor() { super(); this.api = 'http://connect.doodle3d.com/api/'; @@ -22,8 +22,7 @@ export default class Doodle3DManager extends EventDispatcher { this.autoUpdate = false; } - - setAutoUpdate (autoUpdate = true, updateInterval = 1000) { + setAutoUpdate(autoUpdate = true, updateInterval = 1000) { this.updateInterval = updateInterval; if (this.autoUpdate === autoUpdate) return; @@ -32,16 +31,14 @@ export default class Doodle3DManager extends EventDispatcher { return this; } - - async _update () { + async _update() { while (this.autoUpdate) { await this._checkNew(); await sleep(this.updateInterval); } } - - async _checkNew () { + async _checkNew() { let boxes; try { boxes = await rest.get(`${ this.api }list.php`); @@ -76,14 +73,12 @@ export default class Doodle3DManager extends EventDispatcher { this.dispatchEvent({ type: 'boxeschanged', boxes: this.boxes }); } } - - _addBox (box) { + _addBox(box) { this.boxes.push(box); this.dispatchEvent({ type: 'boxappeared', box }); } - - _removeBox (box) { + _removeBox(box) { const index = this.boxes.indexOf(box); if (index !== -1) { this.boxes.splice(index, 1); diff --git a/src/rest.js b/src/rest.js index 00ecd34..6e7414c 100644 --- a/src/rest.js +++ b/src/rest.js @@ -3,11 +3,11 @@ import $ from 'jquery'; const GET_TIMEOUT = 5000; const POST_TIMEOUT = 10000; -export function get (url) { +export function get(url) { return send(url, 'GET'); } -export function post (url, data) { +export function post(url, data) { return send(url, 'POST', data); } diff --git a/src/utils.js b/src/utils.js index 2f952c4..58add9e 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,4 +1,4 @@ -export function sleep (time) { +export function sleep(time) { return new Promise((resolve, reject) => { setTimeout(resolve, time); });