Skip to content

Commit

Permalink
feat(web): replace angularjs with angular2
Browse files Browse the repository at this point in the history
  • Loading branch information
hfreire committed May 28, 2017
1 parent 65adc61 commit 11282ff
Show file tree
Hide file tree
Showing 23 changed files with 438 additions and 162 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
node_modules
coverage
share
www
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "get-me-a-tinder-date-service",
"description": "Help me get a Tinder date tonight",
"name": "get-me-a-date",
"description": "Help me get a date tonight",
"version": "0.0.0",
"author": "Hugo Freire <hugo@exec.sh>",
"license": "MIT",
Expand Down
2 changes: 2 additions & 0 deletions src/database/people.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const queryAllPeople = function (query) {
return SQLite.all(query)
.mapSeries((row) => {
row.created_date = new Date(row.created_date)
row.train = !!row.train
row.data = JSON.parse(row.data)
return row
})
Expand Down Expand Up @@ -68,6 +69,7 @@ class People {
}

person.created_date = new Date(person.created_date)
person.train = !!person.train
person.data = JSON.parse(person.data)

return person
Expand Down
26 changes: 0 additions & 26 deletions src/routes/app/app.js

This file was deleted.

121 changes: 0 additions & 121 deletions src/routes/app/index.html

This file was deleted.

8 changes: 0 additions & 8 deletions src/routes/app/index.js

This file was deleted.

1 change: 0 additions & 1 deletion src/routes/train.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class Train extends Route {

const { provider, provider_id, data } = person
const { photos } = data

return Taste.mentalSnapshot(photos)
.then(() => People.save(provider, provider_id, { train: true }))
})
Expand Down
40 changes: 40 additions & 0 deletions src/routes/web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2017, Hugo Freire <hugo@exec.sh>.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/

const { Route } = require('serverful')

const _ = require('lodash')

const { join } = require('path')

class Web extends Route {
constructor () {
super('GET', '/', 'www', 'www')
}

auth () {
return false
}

toRoute () {
return _(super.toRoute())
.omit('config.handler')
.merge({
method: 'GET',
path: '/{param*}',
handler: {
directory: {
path: join(__dirname, '../web'),
index: true
}
}
})
.value()
}
}

module.exports = new Web()
6 changes: 3 additions & 3 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ const findDates = function () {

class Server extends Serverful {
start () {
return Promise.all([ super.start(), SQLite.start().then(() => Tinder.authorize()), Taste.bootstrap() ])
.then(() => {
return Promise.all([ super.start(), SQLite.start() ])//.then(() => Tinder.authorize()), Taste.bootstrap() ])
/*.then(() => {
if (FIND_DATES_PERIOD > 0) {
this.findDates()
}
})
})*/
}

findDates () {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/rekognition.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Health = require('health-checkup')
const AWS = require('aws-sdk')

const defaultOptions = {
retry: { max_tries: 2, interval: 1000, throw_original: true },
retry: { max_tries: 2, interval: 1000, timeout: 8000, throw_original: true },
breaker: { timeout: 3000, threshold: 80, circuitDuration: 30000 }
}

Expand Down
4 changes: 4 additions & 0 deletions src/web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
*.js
!systemjs.config.js
*.js.map
38 changes: 38 additions & 0 deletions src/web/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2017, Hugo Freire <hugo@exec.sh>.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/

import {Component} from "@angular/core";

import {PeopleService} from "./people/people.service";
import {PersonDialogComponent} from "./people/person-dialog.component";

import {MdDialog, MdDialogConfig, MdDialogRef} from "@angular/material";

@Component({
selector: 'app',
templateUrl: '/app/people/people.html',
providers: [ PeopleService ]
})
export class AppComponent {
people: any;
person: any;
dialogRef: MdDialogRef<PersonDialogComponent>;

constructor (private service: PeopleService, public dialog: MdDialog) {
service.getAll()
.subscribe((people) => {
this.people = people;
});
}

openPersonDialog (person: any) {
const config = new MdDialogConfig()
config.data = {person}

this.dialogRef = this.dialog.open(PersonDialogComponent, config);
}
}
27 changes: 27 additions & 0 deletions src/web/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2017, Hugo Freire <hugo@exec.sh>.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/

import {NgModule} from "@angular/core";
import {BrowserModule} from "@angular/platform-browser";
import {HttpModule} from "@angular/http";
import {NoopAnimationsModule} from "@angular/platform-browser/animations";
import {MdButtonModule, MdDialogModule, MdTooltipModule} from "@angular/material";

import {MomentModule} from "angular2-moment";

import {AppComponent} from "./app.component";
import {PersonDialogComponent} from "./people/person-dialog.component";

@NgModule({
imports: [ BrowserModule, HttpModule, NoopAnimationsModule, MdDialogModule, MdTooltipModule, MdButtonModule, MomentModule ],
declarations: [ AppComponent, PersonDialogComponent ],
entryComponents: [ PersonDialogComponent ],
bootstrap: [ AppComponent ]
})

export class AppModule {
}
18 changes: 18 additions & 0 deletions src/web/app/people/people.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!--
~ Copyright (c) 2017, Hugo Freire <hugo@exec.sh>.
~
~ This source code is licensed under the license found in the
~ LICENSE file in the root directory of this source tree.
-->

<ul class="no-bullet">
<li *ngFor="let person of people">
<div class="tint"
[ngClass]="{pass: !person.like, like: person.like, train: person.train}"
(click)="openPersonDialog(person)"
mdTooltip="Similarity: {{person.photos_similarity_mean}}%"
tooltipPosition="bottom">
<img [src]="person.data.photos[0].url"/>
</div>
</li>
</ul>
28 changes: 28 additions & 0 deletions src/web/app/people/people.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2017, Hugo Freire <hugo@exec.sh>.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/

import {Injectable} from "@angular/core";
import {Http} from "@angular/http";
import "rxjs/add/operator/map";

@Injectable()
export class PeopleService {
constructor (private http: Http) {
}

getAll () {
return this.http.get('/people')
.map((res) => res.json());
}

train (id: string) {
console.log(id)

return this.http.post(`/train/${id}`, {})
.map(() => {})
}
}
Loading

0 comments on commit 11282ff

Please sign in to comment.