Skip to content

Commit 212c19d

Browse files
author
Jonathan Casarrubias
committed
Updated to fireloop real time charts
1 parent 7c520d2 commit 212c19d

21 files changed

+143
-111
lines changed

.gitignore

-34
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,3 @@
1717
coverage
1818
node_modules
1919
npm-debug.log
20-
# See http://help.github.com/ignore-files/ for more about ignoring files.
21-
22-
# compiled output
23-
/dist
24-
/tmp
25-
26-
# dependencies
27-
/node_modules
28-
/bower_components
29-
30-
# IDEs and editors
31-
/.idea
32-
/.vscode
33-
.project
34-
.classpath
35-
*.launch
36-
.settings/
37-
38-
# misc
39-
/.sass-cache
40-
/connect.lock
41-
/coverage/*
42-
/libpeerconnection.log
43-
npm-debug.log
44-
testem.log
45-
/typings
46-
47-
# e2e
48-
/e2e/*.js
49-
/e2e/*.map
50-
51-
#System Files
52-
.DS_Store
53-
Thumbs.db

.yo-rc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"generator-fireloop": {
3-
"version": "1.0.0-alpha.26",
3+
"version": "1.0.0-alpha.34",
44
"clients": {
55
"webapp": {
66
"path": "./webapp",

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ $ fireloop serve
3333
3434
Open your browser in [127.0.0.1:4200](http://127.0.0.1:4200) and you should see the following result:
3535
36-
![](https://storage.googleapis.com/mean-expert-images/fireloop-todo-app.gif)
36+
[Click here if gif does't load -sigh- [Shame on you @GitHub]](https://goo.gl/YRiKnz)
37+
38+
![FireLoop Stats](https://goo.gl/YRiKnz)

common/models/todo.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
"options": {
66
"validateUpsert": true
77
},
8-
"properties": {},
8+
"properties": {
9+
"text": {
10+
"type": "string"
11+
},
12+
"dueAt": {
13+
"type": "date",
14+
"required": true
15+
}
16+
},
917
"validations": [],
1018
"relations": {},
1119
"acls": [],
@@ -19,7 +27,7 @@
1927
"description": "Statistical information for Todo registers.",
2028
"type": "model",
2129
"count": {
22-
"on": "createdAt",
30+
"on": "dueAt",
2331
"by": "index"
2432
}
2533
}

common/models/todo.ts

+12-14
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,34 @@ import { Model } from '@mean-expert/model';
22
/**
33
* @module Todo
44
* @description
5-
* Write a useful Todo Model description
5+
* Write a useful Todo Model description.
6+
* Register hooks and remote methods within the
7+
* Model Decorator
68
**/
79
@Model({
810
hooks: {
911
beforeSave: { name: 'before save', type: 'operation' }
1012
},
1113
remotes: {
1214
myRemote: {
13-
accepts : { arg: 'id', type: 'string', required: true },
14-
returns : { arg: 'result', type: 'object' },
15-
http : { path: '/:id/my-remote', verb: 'get' }
15+
returns : { arg: 'result', type: 'array' },
16+
http : { path: '/my-remote', verb: 'get' }
1617
}
1718
}
1819
})
1920

20-
export class Todo {
21-
/**
22-
* @method constructor
23-
* @description
24-
* Register model hooks and methods.
25-
*/
26-
constructor(app: any) {}
21+
class Todo {
22+
// LoopBack model instance is injected in constructor
23+
constructor(public model: any) {}
24+
2725
// Example Operation Hook
28-
static beforeSave(ctx: any, next: Function): void {
26+
beforeSave(ctx: any, next: Function): void {
2927
console.log('Todo: Before Save');
3028
next();
3129
}
3230
// Example Remote Method
33-
static myRemote(id: string, next: Function): void {
34-
next(null, `My Remote Example: ${id}`);
31+
myRemote(next: Function): void {
32+
this.model.find(next);
3533
}
3634
}
3735

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"dependencies": {
1212
"@mean-expert/loopback-component-realtime": "^1.0.0-beta.8",
1313
"@mean-expert/loopback-stats-mixin": "^1.2.0",
14-
"@mean-expert/model": "^1.0.7",
15-
"@mean-expert/model-register": "^1.0.4",
14+
"@mean-expert/model": "^1.0.9",
1615
"compression": "^1.0.3",
1716
"cors": "^2.5.2",
1817
"helmet": "^1.3.0",
@@ -25,17 +24,18 @@
2524
"strong-error-handler": "^1.0.1"
2625
},
2726
"devDependencies": {
28-
"@mean-expert/loopback-sdk-builder": "^2.1.0-beta.15",
27+
"@mean-expert/loopback-sdk-builder": "^2.1.0-beta.16",
28+
"@types/node": "^6.0.46",
2929
"eslint": "^2.13.1",
3030
"eslint-config-loopback": "^4.0.0",
3131
"nsp": "^2.1.0",
32-
"ts-node": "^1.6.1",
33-
"typescript": "^2.0.7"
32+
"ts-node": "^1.7.0",
33+
"typescript": "^2.0.8"
3434
},
3535
"repository": {
3636
"type": "",
3737
"url": ""
3838
},
3939
"license": "UNLICENSED",
40-
"description": "fireloop_todo"
40+
"description": "fireloop_project"
4141
}

server/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"restApiRoot": "/api",
3-
"host": "127.0.0.1",
3+
"host": "0.0.0.0",
44
"port": 3000,
55
"remoting": {
66
"context": false,

tsconfig.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
"preserveConstEnums": true,
77
"sourceMap": true,
88
"experimentalDecorators": true,
9-
"moduleResolution": "node"
9+
"moduleResolution": "node",
10+
"typeRoots": [
11+
"./node_modules/types"
12+
],
13+
"types": [
14+
"node"
15+
]
1016
}
1117
}

webapp/.editorconfig

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ root = true
55
charset = utf-8
66
indent_style = space
77
indent_size = 2
8-
end_of_line = lf
98
insert_final_newline = true
109
trim_trailing_whitespace = true
1110

webapp/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Webapp
22

3-
This project was generated with [angular-cli](https://github.com/angular/angular-cli) version 1.0.0-beta.18.
3+
This project was generated with [angular-cli](https://github.com/angular/angular-cli) version 1.0.0-beta.19-3.
44

55
## Development server
66
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.

webapp/angular-cli.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"project": {
3-
"version": "1.0.0-beta.18",
3+
"version": "1.0.0-beta.19-3",
44
"name": "webapp"
55
},
66
"apps": [

webapp/karma.conf.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ module.exports = function (config) {
2727
config: './angular-cli.json',
2828
environment: 'dev'
2929
},
30-
reporters: ['progress', 'karma-remap-istanbul'],
30+
reporters: config.angularCli && config.angularCli.codeCoverage
31+
? ['progress', 'karma-remap-istanbul']
32+
: ['progress'],
3133
port: 9876,
3234
colors: true,
3335
logLevel: config.LOG_INFO,

webapp/package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
"@angular/platform-browser": "~2.1.0",
2121
"@angular/platform-browser-dynamic": "~2.1.0",
2222
"@angular/router": "~3.1.0",
23+
"chart.js": "^2.3.0",
2324
"core-js": "^2.4.1",
25+
"moment": "^2.16.0",
26+
"ng2-charts": "^1.4.1",
2427
"rxjs": "5.0.0-beta.12",
2528
"socket.io-client": "^1.5.1",
2629
"ts-helpers": "^1.1.1",
@@ -30,7 +33,7 @@
3033
"@types/jasmine": "^2.2.30",
3134
"@types/node": "^6.0.42",
3235
"@types/socket.io-client": "^1.4.28",
33-
"angular-cli": "1.0.0-beta.18",
36+
"angular-cli": "1.0.0-beta.19-3",
3437
"codelyzer": "1.0.0-beta.1",
3538
"jasmine-core": "2.4.1",
3639
"jasmine-spec-reporter": "2.5.0",
@@ -42,6 +45,7 @@
4245
"protractor": "4.0.9",
4346
"ts-node": "1.2.1",
4447
"tslint": "3.13.0",
45-
"typescript": "~2.0.3"
48+
"typescript": "~2.0.3",
49+
"webdriver-manager": "10.2.5"
4650
}
4751
}

webapp/src/app/app.component.html

+16-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ <h1>
22
{{title}}
33
</h1>
44
<form (submit)="create()">
5-
<input name="todo" [(ngModel)]="todo.text" placeholder="Add Todo" />
5+
<input name="todo" type="text" [(ngModel)]="todo.text" placeholder="Add Todo" />
6+
<input name="todo" type="date" [(ngModel)]="todo.dueAt" placeholder="Due Date" />
67
<button>Add Todo</button>
78
</form>
89
<ul>
@@ -11,4 +12,17 @@ <h1>
1112
<button (click)="update(_todo)">Update</button>
1213
<button (click)="remove(_todo)">Remove</button>
1314
</li>
14-
</ul>
15+
</ul>
16+
<div class="row">
17+
<div class="col-md-6">
18+
<div style="display: block;">
19+
<canvas *ngIf="lineChartData.length > 0" baseChart width="400" height="400"
20+
[datasets]="lineChartData"
21+
[labels]="lineChartLabels"
22+
[options]="lineChartOptions"
23+
[colors]="lineChartColors"
24+
[legend]="lineChartLegend"
25+
[chartType]="lineChartType"></canvas>
26+
</div>
27+
</div>
28+
</div>

webapp/src/app/app.component.ts

+31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
require('chart.js');
2+
13
import { Component } from '@angular/core';
24
import { Todo, FireLoopRef } from './shared/sdk/models';
35
import { RealTime } from './shared/sdk/services';
6+
import * as moment from 'moment';
47

58
@Component({
69
selector: 'app-root',
@@ -13,9 +16,37 @@ export class AppComponent {
1316
private title : string = 'Todo app works!';
1417
private todo : Todo = new Todo();
1518
private todoRef : FireLoopRef<Todo>;
19+
private lineChartData:Array<any> = [];
20+
private lineChartLabels:Array<any> = [];
21+
private lineChartOptions:any = {
22+
animation: false,
23+
responsive: false
24+
};
25+
private lineChartColors:Array<any> = [
26+
{
27+
backgroundColor: 'rgba(148,159,177,0.2)',
28+
borderColor: 'rgba(148,159,177,1)',
29+
pointBackgroundColor: 'rgba(148,159,177,1)',
30+
pointBorderColor: '#fff',
31+
pointHoverBackgroundColor: '#fff',
32+
pointHoverBorderColor: 'rgba(148,159,177,0.8)'
33+
}
34+
];
35+
private lineChartLegend:boolean = true;
36+
private lineChartType:string = 'line';
1637

1738
constructor(private rt: RealTime) {
1839
this.todoRef = this.rt.FireLoop.ref<Todo>(Todo);
40+
this.todoRef.stats().subscribe((stats: any) => {
41+
this.lineChartLabels = new Array();
42+
this.lineChartData = new Array();
43+
let data = new Array();
44+
stats.forEach((stat: any) => {
45+
data.push(stat.count);
46+
this.lineChartLabels.push(moment(stat.universal).format('MM-YYYY'));
47+
});
48+
this.lineChartData.push({ data: data, label: 'Number of Dued Todos'});
49+
});
1950
}
2051

2152
create(): void {

webapp/src/app/app.module.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { NgModule } from '@angular/core';
33
import { FormsModule } from '@angular/forms';
44
import { SDKModule } from './shared/sdk/index';
55
import { AppComponent } from './app.component';
6+
import { ChartsModule } from 'ng2-charts/ng2-charts';
67

78
@NgModule({
89
declarations: [
@@ -11,10 +12,11 @@ import { AppComponent } from './app.component';
1112
imports: [
1213
BrowserModule,
1314
FormsModule,
14-
SDKModule.forRoot()
15+
SDKModule.forRoot(),
16+
ChartsModule
1517
],
1618
providers: [],
1719
bootstrap: [AppComponent]
1820
})
1921

20-
export class AppModule { }
22+
export class AppModule { }

webapp/src/app/shared/sdk/lb.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* }
2121
**/
2222
export class LoopBackConfig {
23-
private static path: string = '//127.0.0.1:3000';
23+
private static path: string = '//0.0.0.0:3000';
2424
private static version: string | number = 'api';
2525
private static authPrefix: string = '';
2626
private static debug: boolean = true;

webapp/src/app/shared/sdk/models/Todo.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
declare var Object: any;
44
export interface TodoInterface {
55
text?: string;
6+
dueAt: Date;
67
id?: number;
78
createdAt: Date;
89
updatedAt: Date;
910
}
1011

1112
export class Todo implements TodoInterface {
1213
text: string;
14+
dueAt: Date;
1315
id: number;
1416
createdAt: Date;
1517
updatedAt: Date;

0 commit comments

Comments
 (0)