Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DutchKevv committed May 21, 2017
1 parent 9220253 commit 682fc86
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ install:

script:
- cd electron
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then npm run test:e2e; fi
# - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then npm run test:e2e; fi
- cd ../

deploy:
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ install:
- cd ../

test_script:
- cd electron && npm run test:e2e
# - cd electron && npm run test:e2e

build: off

Expand Down
15 changes: 9 additions & 6 deletions client/app/common/file-tree/file-tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ export class FileTreeComponent implements AfterViewInit, OnDestroy {

this.jstree.create_node(filePath, {
id: result.id,
text: model.inputs[0].value
text: model.inputs[0].value,
isFile: true,
icon: 'glyphicon glyphicon-file'
}, 'inside');

this.updateEvent.emit({
Expand Down Expand Up @@ -373,15 +375,16 @@ export class FileTreeComponent implements AfterViewInit, OnDestroy {
if (err)
return alert(err);

this.jstree.create_node(filePath, {
id: result.id,
text: model.inputs[0].value
}, 'inside');

this.updateEvent.emit({
type: 'createDirectory',
value: model.inputs[0].value
});

this.jstree.create_node(filePath, {
id: result.id,
text: model.inputs[0].value,
isFile: false
}, 'inside');
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

:host {
height: 50%;
// position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
border-bottom: 1px solid;
overflow: auto;
}
Expand Down Expand Up @@ -35,7 +30,7 @@ table {
}

tbody {
height: calc(100% - 50px);
height: calc(100% - 44px);
overflow: auto;
tr {
border-top: 1px solid #8c8a8a;
Expand Down
22 changes: 13 additions & 9 deletions client/app/common/jseditor/jseditor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,21 @@ export class JSEditorComponent implements AfterViewInit {

saveFile() {
return new Promise((resolve, reject) => {
let content = this.editor.getValue();
if (!this.editor.session.getUndoManager().isClean()) {
this.editor.session.getUndoManager().markClean();

this.socket.emit('file:save', {path: this.currentFile, content: content}, (err) => {
if (err) {
this.showBanner('error', 'File not saved: ' + err);
return reject();
}
let content = this.editor.getValue();

this.socket.emit('file:save', {path: this.currentFile, content: content}, (err) => {
if (err) {
this.showBanner('error', 'File not saved: ' + err);
return reject();
}

this.showBanner('success', 'File saved');
resolve();
});
this.showBanner('success', 'File saved');
resolve();
});
}
});
}

Expand Down
7 changes: 3 additions & 4 deletions client/app/directives/modalanchor.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ModalAnchorDirective {
this.modalComponentRef.instance.model = options.model;
this.modalComponentRef.instance.options = options;


this.modalComponentRef.instance.close.subscribe(() => this.destroy(this.modalComponentRef));
this.modalComponentRef.changeDetectorRef.detectChanges();

this.show();
Expand All @@ -47,9 +47,8 @@ export class ModalAnchorDirective {
destroy(modalComponentRef) {
let $el = $(this.modalComponentRef.instance.elementRef.nativeElement.firstElementChild);


$el.on('hidden.bs.modal', function () {
modalComponentRef.destroy();
$el.on('hidden.bs.modal', () => {
this.modalComponentRef.instance.destroy();
}).modal('hide');
}
}
6 changes: 1 addition & 5 deletions client/app/pages/editor/editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class EditorComponent implements AfterViewInit {
@ViewChild(FileTreeComponent) fileTree: FileTreeComponent;
@ViewChild(JSEditorComponent) jsEditor: JSEditorComponent;

$el: any;
public zoom = 1;

constructor(private _elementRef: ElementRef,
private _router: Router,
Expand All @@ -29,13 +29,11 @@ export class EditorComponent implements AfterViewInit {

ngAfterViewInit(): void {
this._socketService.socket.on('editor:change', () => {
console.log('CHANGE CHANGE');
// this.fileTree.load();
// this.jsEditor.reloadCurrentFile();
});

this.fileTree.$el.off('select_node.jstree').on('select_node.jstree', (e: any, data: any) => {
console.log('data', 'data', data);
if (data.node && data.node.original.isFile) {
let path = this.fileTree.$el.jstree(true).get_path(data.node, '/');

Expand All @@ -60,7 +58,5 @@ export class EditorComponent implements AfterViewInit {
default:
throw new Error('Unknown fileTree update event');
}

console.log('fileTree update', JSON.stringify(event));
}
}
20 changes: 19 additions & 1 deletion client/app/services/instruments.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {IndicatorModel} from "../models/indicator";
import {DialogComponent} from "../common/dialog/dialog.component";
import {ModalService} from "./modal.service";

var counter = 0;

@Injectable()
export class InstrumentsService {

Expand Down Expand Up @@ -69,6 +71,8 @@ export class InstrumentsService {
}

public remove(model: InstrumentModel) {
console.log(counter++);

this._instruments.splice(this._instruments.indexOf(model), 1);
this.instruments$.next(this._instruments);

Expand All @@ -80,7 +84,10 @@ export class InstrumentsService {
}

public removeAll() {
this.instruments.forEach(instrument => this.remove(instrument));
this._destroyAllOnServer();

this._instruments = [];
this.instruments$.next(this._instruments);
}

public fetch(model: InstrumentModel, count = 300, offset = 0, from?: number, until?: number): Promise<any> {
Expand Down Expand Up @@ -237,6 +244,17 @@ export class InstrumentsService {
});
}

private _destroyAllOnServer() {
return new Promise((resolve, reject) => {

this._socketService.socket.emit('instrument:destroy-all', {}, err => {
if (err)
return reject(err);

resolve();
});
});
}

private _loadInstrumentList() {
this._socketService.socket.emit('instrument:list', {}, (err, instrumentList) => {
Expand Down
13 changes: 8 additions & 5 deletions custom/ea/example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {IEA} from 'tradejs/ea';

export default class MyEA extends EA implements IEA {


count = 0;
MA1: any;
MA2: any;
Expand Down Expand Up @@ -35,9 +36,7 @@ export default class MyEA extends EA implements IEA {

public async onTick(time: number, bid: number, ask: number): Promise<void> {



if (this.MA1.value > bid * 1.0001 && !this.orderManager.orders.length) {
if (this.MA1.value > bid * 1.001 && !this.orderManager.orders.length) {

// Place order
this.addOrder({
Expand All @@ -50,11 +49,15 @@ export default class MyEA extends EA implements IEA {

} else {

if (this.MA1.value < bid * 0.998 && this.orderManager.orders.length) {
if (this.MA1.value < bid * 0.999 && this.orderManager.orders.length) {

// Close order
await this.closeOrder(this.orderManager.orders[0].id, bid, ask);
}
}
}
}
}




1 change: 1 addition & 0 deletions electron/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"asar": false,
"files": [
"!_cache/*",
"!_config/*",
"!dist/*",
"!custom/indicator/*",
"!client/node_modules/*",
Expand Down
73 changes: 10 additions & 63 deletions electron/tests/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const Application = require('spectron').Application;
const path = require('path');
const chai = require('chai');
const fs = require('fs');
const chaiAsPromised = require('chai-as-promised');

var electronPath = '';
var electronPath = '',
configPath = '';

if (/^win/.test(process.platform)) {
electronPath = path.join(__dirname, '..', '..', 'dist', 'win-unpacked', 'TradeJS.exe');
Expand All @@ -13,15 +15,11 @@ if (/^win/.test(process.platform)) {
electronPath = path.join(__dirname, '..', '..', 'dist', 'linux-unpacked', 'tradejs');
}

// if (process.platform === 'win32') {
// electronPath += '.cmd';
// }

var appPath = path.join(__dirname, '..');
var appPath = path.join(__dirname, '..', '..');

var app = new Application({
path: electronPath,
args: [appPath, 'NODE_ENV=development']
args: [appPath, 'NODE_ENV=production']
});

global.before(function () {
Expand All @@ -35,6 +33,7 @@ describe('Window', function () {
});

afterEach(function () {
fs.unlinkSync(path.join(electronPath, '..', 'resources', 'app', '_config', 'tradejs.config.json'));
return app.stop();
});

Expand Down Expand Up @@ -62,13 +61,6 @@ describe('Server Connection', function () {
return app.client.waitUntilWindowLoaded()
.waitForExist('#debugContainer .circle.ok', 5000);
});

// it('shows server connection error link that opens login screen', function () {
// return app.client.waitUntilWindowLoaded()
// .setNetworkConnection(1) // airplane mode off, wifi off, data off
// .waitForExist('#debugContainer status .circle.error', 5000)
// .getText('#debugContainer .error-message').should.eventually.equal('No server connection');
// });
});

describe('Charts', function () {
Expand All @@ -83,17 +75,11 @@ describe('Charts', function () {

it('can open a chart', function () {
return app.client.waitUntilWindowLoaded()
.waitForExist('.instrument-list-rows-wrapper tr:first-child', 5000)
.click('.instrument-list-rows-wrapper tr:first-child td:first-child')
.pause(10000)
.waitForExist('.three-column:first-child tr:first-child', 5000)
.click('.three-column:first-child tr:first-child td:first-child')
.waitForExist('.chart-overview-container chart-box', 5000);
});

// it('shows server connection error link that opens login screen', function () {
// return app.client.waitUntilWindowLoaded()
// .setNetworkConnection(1) // airplane mode off, wifi off, data off
// .waitForExist('#debugContainer status .circle.error', 5000)
// .getText('#debugContainer .error-message').should.eventually.equal('No server connection');
// });
});

describe('Backtest', function () {
Expand All @@ -109,13 +95,6 @@ describe('Backtest', function () {
it('can resize the debugger', function () {
return app.client.waitUntilWindowLoaded();
});

// it('shows server connection error link that opens login screen', function () {
// return app.client.waitUntilWindowLoaded()
// .setNetworkConnection(1) // airplane mode off, wifi off, data off
// .waitForExist('#debugContainer status .circle.error', 5000)
// .getText('#debugContainer .error-message').should.eventually.equal('No server connection');
// });
});

describe('Editor', function () {
Expand All @@ -131,36 +110,4 @@ describe('Editor', function () {
it('can open a chart', function () {
return app.client.waitUntilWindowLoaded()
});

// it('shows server connection error link that opens login screen', function () {
// return app.client.waitUntilWindowLoaded()
// .setNetworkConnection(1) // airplane mode off, wifi off, data off
// .waitForExist('#debugContainer status .circle.error', 5000)
// .getText('#debugContainer .error-message').should.eventually.equal('No server connection');
// });
});

describe('Editor', function () {

beforeEach(function () {
return app.start();
});

afterEach(function () {
return app.stop();
});

it('Can open the editor window', function () {
return app.client.waitUntilWindowLoaded()
.waitForExist('.instrument-list-rows-wrapper tr:first-child', 5000)
.click('.instrument-list-rows-wrapper tr:first-child td:first-child')
.waitForExist('.chart-overview-container chart-box', 5000);
});

// it('shows server connection error link that opens login screen', function () {
// return app.client.waitUntilWindowLoaded()
// .setNetworkConnection(1) // airplane mode off, wifi off, data off
// .waitForExist('#debugContainer status .circle.error', 5000)
// .getText('#debugContainer .error-message').should.eventually.equal('No server connection');
// });
});
});
9 changes: 5 additions & 4 deletions server/api/socket/instrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ module.exports = (app: App, socket) => {
cb(null);
});

// Destroy All
socket.on('instrument:destroy-all', async (options, cb) => {
cb(null, await app.controllers.instrument.destroyAll());
});

// TODO: Move to cache API
// Read bars
socket.on('instrument:read', (options, cb) => {
Expand Down Expand Up @@ -81,8 +86,4 @@ module.exports = (app: App, socket) => {
cb(error);
}
});

socket.on('instrument:indicator:remove', async (options, cb) => {

});
};
Loading

0 comments on commit 682fc86

Please sign in to comment.