Skip to content

Commit 8679304

Browse files
committed
realtime db + file uploads
1 parent 5c7bba1 commit 8679304

28 files changed

+506
-20
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
"@angular/platform-browser-dynamic": "^4.0.0",
2424
"@angular/platform-server": "^4.0.0",
2525
"@angular/router": "^4.0.0",
26+
"@types/lodash": "^4.14.61",
2627
"angularfire2": "^2.0.0-beta.8",
2728
"core-js": "^2.4.1",
2829
"firebase": "^3.7.2",
30+
"lodash": "^4.17.4",
2931
"rxjs": "^5.1.0",
3032
"typescript": "^2.2.1",
3133
"zone.js": "^0.7.6"

src/app/app-routing.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { NgModule } from '@angular/core';
22
import { Routes, RouterModule } from '@angular/router';
33
import { UserLoginComponent } from './users/user-login/user-login.component';
4+
import { ItemsListComponent } from './items/items-list/items-list.component';
5+
import { UploadsListComponent } from './uploads/uploads-list/uploads-list.component';
46

57
const routes: Routes = [
68
{
79
path: '',
810
children: []
911
},
1012
{ path: 'login', component: UserLoginComponent, },
13+
{ path: 'items', component: ItemsListComponent, },
14+
{ path: 'uploads', component: UploadsListComponent, },
1115
];
1216

1317
@NgModule({

src/app/app.module.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,43 @@ import { HttpModule } from '@angular/http';
66
import { AppRoutingModule } from './app-routing.module';
77
import { AppComponent } from './app.component';
88

9-
// FireStarter
9+
///// Start FireStarter
1010
import { environment } from '../environments/environment';
11+
import { AngularFireModule } from 'angularfire2';
12+
13+
// FireStarter Users
1114
import { AuthService } from './core/auth.service';
1215
import { UserLoginComponent } from './users/user-login/user-login.component';
16+
import { UserProfileComponent } from './users/user-profile/user-profile.component';
1317

18+
// FireStarter Items
19+
import { ItemService } from './items/shared/item.service';
20+
import { ItemsListComponent } from './items/items-list/items-list.component';
21+
import { ItemFormComponent } from './items/item-form/item-form.component';
22+
import { ItemDetailComponent } from './items/item-detail/item-detail.component';
1423

15-
import { AngularFireModule } from 'angularfire2';
16-
import { UserProfileComponent } from './users/user-profile/user-profile.component';
17-
export const firebaseConfig = environment.firebaseConfig;
24+
// FireStarter Uploads
25+
import { UploadService } from './uploads/shared/upload.service';
26+
import { UploadFormComponent } from './uploads/upload-form/upload-form.component';
27+
import { UploadsListComponent } from './uploads/uploads-list/uploads-list.component';
28+
import { UploadDetailComponent } from './uploads/upload-detail/upload-detail.component';
1829

30+
export const firebaseConfig = environment.firebaseConfig;
1931

20-
// End FireStarter
32+
///// End FireStarter
2133

2234

2335
@NgModule({
2436
declarations: [
2537
AppComponent,
2638
UserLoginComponent,
27-
UserProfileComponent
39+
UserProfileComponent,
40+
ItemsListComponent,
41+
ItemFormComponent,
42+
ItemDetailComponent,
43+
UploadFormComponent,
44+
UploadsListComponent,
45+
UploadDetailComponent
2846
],
2947
imports: [
3048
BrowserModule,
@@ -34,7 +52,10 @@ export const firebaseConfig = environment.firebaseConfig;
3452
AngularFireModule.initializeApp(firebaseConfig)
3553
],
3654
providers: [
37-
AuthService
55+
AuthService,
56+
ItemService,
57+
UploadService,
58+
3859
],
3960
bootstrap: [
4061
AppComponent

src/app/core/auth.service.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export class AuthService {
1515

1616
af.auth.subscribe((auth) => {
1717
this.authState = auth;
18+
console.log(this.af.auth)
19+
console.log(this.authState)
1820
console.log(this.authState)
1921
});
2022
}
@@ -34,6 +36,11 @@ export class AuthService {
3436
return this.authenticated ? this.authState.uid : '';
3537
}
3638

39+
// Returns current user display name or Guest
40+
get currentUserDisplayName(): string {
41+
return this.authenticated ? this.authState.auth.displayName : 'GUEST';
42+
}
43+
3744

3845
//// Social Auth ////
3946

@@ -55,7 +62,7 @@ export class AuthService {
5562

5663
private socialSignIn(provider: number): firebase.Promise<FirebaseAuthState> {
5764
return this.af.auth.login({provider, method: AuthMethods.Popup})
58-
.then(() => this.writeUserData() )
65+
.then(() => this.updateUserData() )
5966
.catch(error => console.log(error));
6067
}
6168

@@ -94,7 +101,7 @@ export class AuthService {
94101

95102
//// Helpers ////
96103

97-
private writeUserData(): void {
104+
private updateUserData(): void {
98105
// Writes user name and email to realtime db
99106
// useful if your app displays information about users or for admin features
100107

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{ item.title || 'no title' }}<br>
2+
{{ item.body || 'no body' }}<br>
3+
Active: {{ item.active }}<br>
4+
{{ item.lastClick | date: 'medium' }}<br>
5+
6+
7+
<span (click)='deleteItem()'>Delete</span>
8+
<span (click)='updateTimeStamp()'>Log Timestamp</span>
9+
10+
<span *ngIf='item.active' (click)='updateActive(false)'>Mark Active</span>
11+
<span *ngIf='!item.active' (click)='updateActive(true)'>Mark Complete</span>
12+
13+
<hr>

src/app/items/item-detail/item-detail.component.scss

Whitespace-only changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Component, OnInit, Input } from '@angular/core';
2+
import { ItemService } from '../shared/item.service';
3+
import { Item } from '../shared/item';
4+
5+
@Component({
6+
selector: 'item-detail',
7+
templateUrl: './item-detail.component.html',
8+
styleUrls: ['./item-detail.component.scss']
9+
})
10+
export class ItemDetailComponent implements OnInit {
11+
12+
@Input() item: Item;
13+
14+
constructor(private itemSvc: ItemService) { }
15+
16+
ngOnInit() {
17+
}
18+
19+
updateTimeStamp() {
20+
let date = new Date()
21+
this.itemSvc.updateItem(this.item.$key, { lastClick: date })
22+
}
23+
24+
updateActive(value: boolean) {
25+
this.itemSvc.updateItem(this.item.$key, { active: value })
26+
}
27+
28+
deleteItem() {
29+
this.itemSvc.deleteItem(this.item.$key)
30+
}
31+
32+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<h3>New Task Form</h3>
2+
3+
<div>
4+
<label>Name: </label>
5+
<input placeholder="Item Title" class="form-control"
6+
[(ngModel)]="item.title"
7+
required minlength="2" maxlength="23"
8+
#title='ngModel'>
9+
10+
<div *ngIf="title.dirty || title.touched">
11+
<p *ngIf='title.errors; then errors else valid'>template renders here...</p>
12+
</div>
13+
14+
<br>
15+
<label>Body: </label>
16+
<textarea placeholder="Item Body" class="form-control"
17+
[(ngModel)]="item.body"
18+
required minlength="2" maxlength="23"
19+
#body='ngModel'>
20+
</textarea>
21+
<br>
22+
<button (click)='createItem()' [disabled]="!title.valid || !body.valid">Create</button>
23+
</div>
24+
25+
<ng-template #valid>looks good!</ng-template>
26+
<ng-template #errors>form contains errors!</ng-template>

src/app/items/item-form/item-form.component.scss

Whitespace-only changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { FormsModule } from '@angular/forms';
3+
import { Item } from '../shared/item';
4+
import { ItemService } from '../shared/item.service';
5+
6+
@Component({
7+
selector: 'item-form',
8+
templateUrl: './item-form.component.html',
9+
styleUrls: ['./item-form.component.scss']
10+
})
11+
export class ItemFormComponent implements OnInit {
12+
13+
item: Item = new Item();
14+
15+
constructor(private itemSvc: ItemService) { }
16+
17+
ngOnInit() {
18+
}
19+
20+
createItem() {
21+
this.itemSvc.createItem(this.item)
22+
this.item = new Item() // reset item
23+
}
24+
25+
}

0 commit comments

Comments
 (0)