Skip to content

Commit 51f316d

Browse files
author
Ian Redpath
committed
mostly working project prototype stuff
1 parent 7a62ccc commit 51f316d

26 files changed

+694
-116
lines changed

gulpfile.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference path="./node_modules/gulpclass/index.d.ts" />
22
/// <reference path="./typings/main.d.ts" />
3-
import {Gulpclass, SequenceTask, Task } from "gulpclass/Decorators";
3+
import { Gulpclass, SequenceTask, Task } from "gulpclass/Decorators";
44

55
import * as gulp from 'gulp'
66
import * as del from 'del'
@@ -32,6 +32,12 @@ export class Gulpfile {
3232
return gulp.src('server/models/**/*.json')
3333
.pipe(gulp.dest('dist/models'))
3434
}
35+
36+
@Task("build:projectData")
37+
buildProjectData() {
38+
return gulp.src('server/project/data/*.json')
39+
.pipe(gulp.dest('dist/project/data'))
40+
}
3541
@Task("build:public")
3642
buildPublic() {
3743
const tsProject = ts.createProject('public/tsconfig.json')
@@ -49,7 +55,7 @@ export class Gulpfile {
4955

5056
@SequenceTask("build")
5157
build() {
52-
return ["clean", "build:server", "build:data", "build:public"]
58+
return ["clean", "build:server", "build:data", "build:projectData", "build:public"]
5359
}
5460

5561
@SequenceTask("default")

public/project/components/libraries/libraries.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ export class Libraries {
1717

1818
constructor(public libraryService: LibraryService) {
1919
this.fetchingLibraries = true
20-
this.libraries = libraryService.getAll()
21-
this.fetchingLibraries = false
20+
libraryService.getAll()
21+
.subscribe(resp => {
22+
if (resp.json().libraries) {
23+
this.libraries = resp.json().libraries
24+
}
25+
this.fetchingLibraries = false
26+
})
2227

2328
}
2429
}

public/project/components/libraries/library.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ export class Library {
2323
public userService: UserService) {
2424
this.fetchingLibrary = true
2525
const libraryId: number = +params.get('library')
26-
this.library = libraryService.get(libraryId)
27-
this.fetchingLibrary = false
26+
libraryService.get(libraryId)
27+
.subscribe(resp => {
28+
if (resp.json().library) {
29+
this.library = resp.json().library
30+
}
31+
this.fetchingLibrary = false
32+
})
2833
}
2934

3035
hasEditRights() {
31-
return this.userService.getActiveUser() && this.library.user.id === this.userService.getActiveUser().id
36+
return this.userService.getActiveUser() && this.library.user._id === this.userService.getActiveUser()._id
3237
}
3338

3439
editLibraryName() {
@@ -43,10 +48,23 @@ export class Library {
4348

4449
saveNewLibraryName() {
4550
this.isEditingLibraryName = false
51+
this.libraryService.updateLibrary(this.library)
52+
.subscribe(resp => {
53+
if(resp.json().library) {
54+
this.library = resp.json().library
55+
this.libraryBackup = resp.json().library
56+
}
57+
})
4658
}
4759

4860
removeMovie(id: string) {
49-
_.remove(this.library.movies, mov => { return mov.imdbId === id })
61+
this.libraryService.removeMovie(this.library.id, id)
62+
.subscribe(resp => {
63+
if (resp.json().library) {
64+
this.library = resp.json().library
65+
}
66+
})
67+
//_.remove(this.library.movies, mov => { return mov.imdbId === id })
5068
}
5169

5270
}

public/project/components/libraries/library.view.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<div *ngIf='!fetchingLibrary' class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2">
22
<div>
33
<div *ngIf="!isEditingLibraryName" class="library-name-container">
4-
<h1>{{library.name}}</h1>
5-
<span *ngIf="hasEditRights()" class="glyphicon glyphicon-pencil" (click)="editLibraryName()"></span>
4+
<h1 *ngIf="hasEditRights()" (click)="editLibraryName()" class="clickable">{{library.name}}</h1>
5+
<h1 *ngIf="!hasEditRights()">{{library.name}}</h1>
66
</div>
77
<div *ngIf="isEditingLibraryName">
88
<input type="text" [(ngModel)]="library.name">
99
<span class="glyphicon glyphicon-check" (click)="saveNewLibraryName()"></span>
1010
<button class="btn btn-default" (click)="cancelEditingLibraryName()">Cancel</button>
1111
</div>
12-
<a [routerLink]='["/User", { user: library.user.id }]'>{{library.user.username}}</a>
12+
<a [routerLink]='["/User", { user: library.user._id }]'>{{library.user.username}}</a>
1313
</div>
1414
<div class="movie-carousel">
1515
<div *ngFor="#movie of library.movies" class="library-movie">

public/project/components/movies/movie.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,51 @@ import { UserService } from '../../services/userService'
1818

1919
export class Movie {
2020

21-
movie:OmdbMovieModel
22-
libraries: Array<LibraryModel>
21+
movie: any
22+
omdbMovie:OmdbMovieModel
2323
fetchingMovie:boolean
2424
fetchingLibraries: boolean
25+
libraryId: string
2526

2627
constructor(public params:RouteParams, public omdbService:OmdbService,
2728
public movieService: MovieService, public libraryService: LibraryService,
2829
public userService: UserService) {
2930
this.fetchingMovie = true
3031
this.fetchingLibraries = true
31-
//const id: number = +params.get('movie')
32-
//const localMovie: MovieModel = movieService.get(id)
33-
const imdbId: string = params.get('movie')//localMovie.imdbId
32+
const imdbId: string = params.get('movie')
33+
movieService.get(imdbId)
34+
.subscribe(
35+
resp => {
36+
if (resp.json().movie) {
37+
this.movie = resp.json().movie
38+
}
39+
this.fetchingLibraries = false
40+
})
3441
omdbService.findMovieById(imdbId)
3542
.subscribe(
36-
data => this.movie = OmdbMovieModel.newMovie(data.json()),
37-
err => { alert(err); this.movie = OmdbMovieModel.emptyMovie() },
43+
data => { this.omdbMovie = OmdbMovieModel.newMovie(data.json()) },
44+
err => { alert(err); this.omdbMovie = OmdbMovieModel.emptyMovie() },
3845
() => { this.fetchingMovie = false}
3946
)
40-
this.libraries = libraryService.getLibrariesWith(imdbId)
41-
this.fetchingLibraries = false
4247
}
4348
// eventually, this will be part of a new component and logic will be moved out of here
4449
addMovie() {
50+
if (this.libraryId) {
51+
this.movieService.addMovieToLibrary(this.movie, this.libraryId)
52+
.subscribe(resp => {
53+
if (resp.json().movie) {
54+
this.movie = resp.json().movie
55+
}
56+
})
57+
} else {
58+
alert("please select a library first")
59+
}
60+
/*
4561
if(this.userService.getActiveUser()) {
4662
const movieToAdd: MovieModel = this.movieService.transformFromOmdb(this.movie)
4763
this.userService.addMovie(movieToAdd)
4864
} else {
4965
alert('sign in to add a movie!')
50-
}
66+
}*/
5167
}
5268
}

public/project/components/movies/movie.view.html

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
<div *ngIf='!fetchingMovie' class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2">
2-
<h1 class="movie-title">{{movie.title}}</h1>
2+
<h1 class="movie-title">{{omdbMovie.title}}</h1>
33
<div class="col-sm-4 col-md-5">
4-
<img *ngIf="movie.image !== 'N/A'" class="movie-image" src="">
5-
<div>
6-
<button class="btn btn-small" (click)="addMovie()">+</button>
4+
<img *ngIf="omdbMovie.image !== 'N/A'" class="movie-image" src="">
5+
<div *ngIf="userService.getActiveUser()">
6+
<div>
7+
<select [(ngModel)]="libraryId">
8+
<option *ngFor="#library of userService.getActiveUser().libraries" value={{library.id}}>{{library.name}}</option>
9+
</select>
10+
<button class="btn btn-small" (click)="addMovie()">+</button>
11+
</div>
712
<span class="glyphicon glyphicon-star"></span>
813
<span class="glyphicon glyphicon-star"></span>
914
<span class="glyphicon glyphicon-star"></span>
@@ -15,24 +20,24 @@ <h1 class="movie-title">{{movie.title}}</h1>
1520
<div class="actors-container">
1621
<label for="actors">Actors:</label>
1722
<ul class="actors">
18-
<li *ngFor="#actor of movie.actors">{{actor}}</li>
23+
<li *ngFor="#actor of omdbMovie.actors">{{actor}}</li>
1924
</ul>
2025
</div>
2126
<div>
2227
<label for="director">Directed By:</label>
23-
<span class="director">{{movie.directors}}</span>
28+
<span class="director">{{omdbMovie.directors}}</span>
2429
</div>
2530
<div>
2631
<label for="summary">Plot Summary:</label>
27-
<p class="summary">{{movie.plot}}</p>
32+
<p class="summary">{{omdbMovie.plot}}</p>
2833
</div>
2934
<div>
3035
<label for="rating">Rated:</label>
31-
<span class="rating">{{movie.rating}}</span>
36+
<span class="rating">{{omdbMovie.rating}}</span>
3237
</div>
3338
<div>
3439
<label for="released">Released on:</label>
35-
<span class="released">{{movie.releaseDate}}</span>
40+
<span class="released">{{omdbMovie.releaseDate}}</span>
3641
</div>
3742
<div class="ratings-container">
3843
<label for="ratings">Average Rating:</label>
@@ -42,16 +47,16 @@ <h1 class="movie-title">{{movie.title}}</h1>
4247
<span class="glyphicon glyphicon-star"></span>
4348
<span class="glyphicon glyphicon-star"></span>
4449
<span class="glyphicon glyphicon-star"></span>
45-
<span *ngIf="movie.tomatoMeter !== 'N/A'" class="rating-rt">
46-
<a href={{movie.tomatoUrl}}>{{movie.tomatoMeter}}% on rotton tomatoes</a>
50+
<span *ngIf="omdbMovie.tomatoMeter !== 'N/A'" class="rating-rt">
51+
<a href={{omdbMovie.tomatoUrl}}>{{omdbMovie.tomatoMeter}}% on rotton tomatoes</a>
4752
</span>
4853
</div>
4954
</div>
5055
</div>
5156
<div class="col-sm-12 col-md-12" *ngIf="!fetchingLibraries">
5257
<h3>Libraries With This Title</h3>
5358
<div class="movie-in-libraries">
54-
<div *ngFor="#library of libraries" class="movie-in-library">
59+
<div *ngFor="#library of movie.libraries" class="movie-in-library">
5560
<a class="thumbnail" [routerLink]="['/Library', { library: library.id }]">{{library.name}}</a>
5661
</div>
5762
</div>

public/project/components/movies/movies.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ export class Movies {
1818

1919
constructor(public movieService: MovieService) {
2020
this.fetchingMovies = true
21-
this.movies = movieService.getAll()
22-
this.fetchingMovies = false
21+
this.movieService.getAll()
22+
.subscribe(resp => {
23+
if (resp.json().movies) {
24+
this.movies = resp.json().movies
25+
} else {
26+
alert('error fetching all movies')
27+
}
28+
this.fetchingMovies = false
29+
})
2330
}
2431
}

public/project/components/users/login.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { View, Component, Inject } from 'angular2/core'
22
import { Router } from 'angular2/router'
33
import { UserService } from '../../services/userService'
4-
import { UserModel } from '../../models/userModel'
54

65
@Component({
76
selector: "vml-login"
@@ -22,15 +21,17 @@ export class Login {
2221
}
2322

2423
login() {
25-
this.userService.findUserByCredentials(this.username, this.password, resp => {
26-
if (resp) {
27-
this.userService.login(resp)
28-
this.router.navigate(['/Home', {}])
29-
} else {
30-
alert('Invalid name/password')
31-
this.username = ""
32-
this.password = ""
33-
}
34-
})
24+
this.userService.findUserByCredentials(this.username, this.password)
25+
.subscribe(
26+
resp => {
27+
if (resp.json().user) {
28+
this.userService.login(resp.json().user)
29+
this.router.navigate(['/Home', {}])
30+
} else {
31+
alert('Invalid name/password')
32+
this.username = ""
33+
this.password = ""
34+
}
35+
})
3536
}
3637
}
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { View, Component, Inject } from 'angular2/core'
22
import { Router } from 'angular2/router'
33
import { UserService } from '../../services/userService'
4-
import { UserModel } from '../../models/userModel'
54

65
@Component({
76
selector: "vml-register"
@@ -13,21 +12,22 @@ import { UserModel } from '../../models/userModel'
1312

1413
export class Register {
1514

16-
user: UserModel
15+
user: any
1716

1817
constructor(public userService: UserService, public router: Router) {
19-
this.user = UserModel.newUser({})
18+
this.user = {}
2019
}
2120

2221
register() {
23-
this.userService.createUser(this.user, newUser => {
24-
if(newUser) {
25-
this.userService.login(newUser)
26-
this.router.navigate(['/Home', {}])
27-
} else {
28-
// assume invalid username
29-
alert('invalid username')
30-
}
31-
})
22+
this.userService.createUser(this.user)
23+
.subscribe(resp => {
24+
const response = resp.json()
25+
if(response.user) {
26+
this.userService.login(response.user)
27+
this.router.navigate(['/Home', {}])
28+
} else if (response.error) {
29+
alert(response.error)
30+
}
31+
})
3232
}
3333
}

0 commit comments

Comments
 (0)