Skip to content

Commit aacf06b

Browse files
committed
Fixed categories.
1 parent 807bb03 commit aacf06b

File tree

15 files changed

+90
-156
lines changed

15 files changed

+90
-156
lines changed

src/app/app.component.ts

+9-15
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ import { SplashScreen } from '@ionic-native/splash-screen';
55
import { IntroSliderPage } from '../pages/intro-slider/intro-slider';
66
import { TabsPage } from '../pages/tabs/tabs';
77
import { AutenticationProvider } from '../providers/autentication/autentication';
8-
import { delay } from 'rxjs/operator/delay';
98

109
@Component({
1110
templateUrl: 'app.html'
1211
})
1312
export class MyApp {
1413

1514
rootPage:any
16-
17-
15+
1816
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,
1917
public authentication: AutenticationProvider)
2018
{
@@ -25,33 +23,29 @@ export class MyApp {
2523
splashScreen.hide();
2624

2725
});
28-
//async calling
29-
//this.helper();
30-
console.log("before");
26+
27+
//check if current user is login, initialize authentication.loggedIn attr.
3128
this.authentication.isLoggedIn();
32-
console.log("after");
29+
//considering authentication.loggedIn set the following page: homePage or loginPage
3330
this.getRootPage();
3431
}
35-
//logic to choose root page, uses LoginProvider
36-
//make sure to update it when implementing login feature
3732

33+
//---------------------------------------------------------------------------//
34+
//considering authentication.loggedIn set the following page: homePage or loginPage
35+
//if current user doesn't logged in -> popup google login window.
3836
getRootPage(){
3937
if(this.authentication.loggedInStatus()){
4038
this.rootPage = TabsPage;
4139
}
4240
else{
43-
this.rootPage = IntroSliderPage;
41+
this.rootPage = IntroSliderPage;
4442
this.authentication.createAuthentication().then(()=>{
4543
this.rootPage = TabsPage;
4644
})
4745

4846
}
4947
}
50-
51-
public async helper(){
52-
53-
}
54-
48+
//---------------------------------------------------------------------------//
5549

5650

5751
}

src/components/my-category/my-category.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, Input/*, Output*/ } from '@angular/core';
22
import { Category } from '../../models/Category';
3-
//import { CategoryServiceProvider } from '../../providers/category-service/category-service';
3+
import { CategoryServiceProvider } from '../../providers/category-service/category-service';
44
import { Client } from '../../models/Client';
55

66

@@ -17,7 +17,6 @@ import { Client } from '../../models/Client';
1717
export class MyCategoryComponent {
1818

1919
@Input() category: Category;
20-
@Input() client: Client;
2120

2221
constructor() {
2322

src/components/phrase/phrase.ts

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ export class PhraseComponent {
1111
@Input() phrase : Phrase;
1212

1313
constructor() {
14-
console.log('Hello PhraseComponent Component');
15-
1614
}
1715

1816
}

src/environments/firebase.config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
//firebase key, initial for connecting to DB and storage.
13
export const firebaseConfig = {
24
prodction: false,
35
firebase:{

src/pages/about-me/about-me.ts

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export class AboutMePage {
1818
}
1919

2020
ionViewDidLoad() {
21-
console.log('ionViewDidLoad AboutMePage');
2221
}
2322

2423
}

src/pages/categories/categories.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010

1111

1212
<ion-content padding class="categories">
13-
<my-category [category] = "item" *ngFor = "let item of categories"> </my-category>
13+
<my-category [category] = "item" *ngFor = "let item of categoryService.getCategories"> </my-category>
1414
</ion-content>

src/pages/categories/categories.module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { NgModule } from '@angular/core';
22
import { IonicPageModule } from 'ionic-angular';
33
import { CategoriesPage } from './categories';
4+
import { MyCategoryComponent } from '../../components/my-category/my-category';
45

56
@NgModule({
67
declarations: [
78
CategoriesPage,
9+
MyCategoryComponent
810
],
911
imports: [
1012
IonicPageModule.forChild(CategoriesPage),

src/pages/categories/categories.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,15 @@ import { Category } from '../../models/Category';
2222
export class CategoriesPage {
2323

2424
private client: Client;
25-
private categories;
2625

2726
constructor(public categoryService: CategoryServiceProvider,public navCtrl: NavController, public navParams: NavParams) {
28-
this.categoryService.firebaseProvider.importCategories();
29-
this.categories = categoryService.getCategories();
30-
27+
3128
}
3229

3330

3431

3532
ionViewDidLoad() {
36-
console.log('ionViewDidLoad CategoriesPage');
37-
this.categories = this.categoryService.firebaseProvider.getCategories;
3833
}
3934

40-
public getClient(): Client{
41-
return this.client;
42-
}
4335

4436
}

src/pages/home/home.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,29 @@ export class HomePage {
2929

3030
constructor(public navCtrl: NavController,public firebaseProvider: FirebaseProvider,public authentication: AutenticationProvider) {
3131

32-
32+
//when user logged in, check in DB if the user is a new user.
33+
//if current user is new, add the user to DB.
3334
if(authentication.loggedIn)
3435
{
35-
// this.updateDisplayName();
36-
// this.user_name = authentication.GetDisplayName;
3736
var user_exists = false;
38-
let x = firebaseProvider.getUsers.subscribe(a => {
37+
let x = firebaseProvider.getUsersObservable.subscribe(a => {
3938
this.users = a;
4039
this.users.forEach(user => {
4140
if(user.getEmail == authentication.user.email) {
4241
user_exists = true;
4342
}
4443

45-
})
44+
});
4645
if(!user_exists) {
4746
firebaseProvider.addUser(new User(authentication.user.email));
4847
}
4948
this.user_name = authentication.afAuth.auth.currentUser.displayName;
49+
//after the user is loaded successfuly, stop subscribe users from DB.
5050
if(this.user_name != "אורח"){
5151
x.unsubscribe();
5252
}
53-
console.log(this.user_name)
5453
})
5554

56-
// if(this.users.length > 0)
57-
// x.unsubscribe();
5855
}
5956

6057
}

src/pages/intro-slider/intro-slider.module.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ import { IntroSliderPage } from './intro-slider';
1010
IonicPageModule.forChild(IntroSliderPage),
1111
],
1212
})
13-
export class IntroSliderPageModule {}
13+
export class IntroSliderPageModule {
14+
15+
16+
}

src/pages/intro-slider/intro-slider.ts

+17-15
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,22 @@ export class IntroSliderPage {
3030

3131
}
3232

33-
public checkIfDataLoaded()
34-
{
35-
return new Promise((resolve, reject) =>
36-
{
37-
if (this.authentication.isLoggedIn())
38-
{
39-
console.log('user is logged in');
40-
this.navCtrl.push(HomePage);
41-
resolve(true);
42-
} else
43-
{
44-
resolve(false);
45-
}
46-
});
47-
}
33+
34+
35+
// public checkIfDataLoaded()
36+
// {
37+
// return new Promise((resolve, reject) =>
38+
// {
39+
// if (this.authentication.isLoggedIn())
40+
// {
41+
// console.log('user is logged in');
42+
// this.navCtrl.push(HomePage);
43+
// resolve(true);
44+
// } else
45+
// {
46+
// resolve(false);
47+
// }
48+
// });
49+
// }
4850

4951
}

src/pages/tabs/tabs.ts

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export class TabsPage {
2323
}
2424

2525
ionViewDidLoad() {
26-
console.log('ionViewDidLoad TabsPage');
2726
}
2827

2928
}

src/providers/autentication/autentication.ts

+19-59
Original file line numberDiff line numberDiff line change
@@ -17,73 +17,33 @@ export class AutenticationProvider {
1717

1818
constructor(public afAuth: AngularFireAuth) {
1919
}
20-
21-
//open auth page for sing in
22-
public createAuthentication() {
23-
this.loggedIn = false;
24-
let user = this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider()).then(()=>
25-
{
26-
this.user = this.afAuth.auth.currentUser;
27-
this.loggedIn = true;
28-
}).catch(()=>
29-
{
30-
this.loggedIn = false;
31-
})
32-
return user;
20+
//open auth page for sing in
21+
public createAuthentication() {
22+
this.loggedIn = false;
23+
let user = this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider()).then(()=>
24+
{
25+
this.user = this.afAuth.auth.currentUser;
26+
this.loggedIn = true;
27+
}).catch(()=>
28+
{
29+
this.loggedIn = false;
30+
})
31+
return user;
3332
}
3433

35-
get GetDisplayName()
36-
{
37-
if(this.user != null)
38-
{
39-
return this.user.displayName;
40-
}
41-
}
42-
4334
//check if current user is logged in
4435
public isLoggedIn(){
45-
console.log("isLoggedIn()");
46-
try {
47-
this.afAuth.auth.currentUser.uid
48-
this.loggedIn = true;
49-
}
50-
catch(e) {
51-
console.log(e.message)
52-
this.loggedIn = false;
36+
try {
37+
this.afAuth.auth.currentUser.uid
38+
this.loggedIn = true;
39+
}
40+
catch(e) {
41+
this.loggedIn = false;
42+
}
5343
}
5444

55-
// //subscribe = listener to any user to connect
56-
// this.afAuth.authState.subscribe(res => {
57-
// if (res && res.uid )
58-
// {
59-
60-
// console.log("loggedIn is" + this.loggedIn)
61-
// return true;
62-
// }
63-
// else
64-
// {
65-
// this.loggedIn = false;
66-
// console.log("loggedIn is" + this.loggedIn)
67-
// return false;
68-
// }
69-
// });
70-
}
71-
72-
//warrped by await in isLoggedIn()
73-
isLoggedInHelper(){
74-
75-
}
76-
77-
7845
public loggedInStatus(){
79-
console.log(this.loggedIn)
8046
return this.loggedIn;
8147
}
8248

83-
84-
85-
86-
87-
88-
8949
}

src/providers/category-service/category-service.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,27 @@ import { FirebaseProvider } from '../firebase/firebase';
1414
export class CategoryServiceProvider {
1515

1616
private categories = [];
17-
firebaseProvider;
1817

19-
constructor(firebaseProvider: FirebaseProvider) {
20-
this.firebaseProvider = firebaseProvider;
18+
constructor(public firebaseProvider: FirebaseProvider) {
2119
firebaseProvider.importCategories();
20+
let x = firebaseProvider.getCategoriesObservable.subscribe(a => {
21+
this.categories = a;
22+
});
2223
}
2324

24-
public getCategories() {
25+
get getCategories() {
2526
return this.categories;
2627
}
2728

28-
public getCategory(index: number): Category{
29-
return this.categories[index];
29+
public getCategoryById(id: string): Category{
30+
return this.categories.find(cat => cat.id === id);
3031
}
3132

3233
public addCategory(category: Category): void {
3334
this.firebaseProvider.addCategory(category);
3435
}
3536

37+
//needs to connect with db
3638
removeCategory(category: Category){
3739
this.categories.splice(this.categories.indexOf(category),1);
3840
}

0 commit comments

Comments
 (0)