Skip to content

Commit

Permalink
Se agrego un mensaje para que un usuario agregue sus primeras prefere…
Browse files Browse the repository at this point in the history
…ncias
  • Loading branch information
matias1305 committed Dec 8, 2018
1 parent dbf9411 commit a8078ab
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 28 deletions.
1 change: 1 addition & 0 deletions src/app/interface/books.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface Users{
status: boolean;
role: string;
created_date: any;
firtSession: boolean;
img?: string;
preferences?: Array<string>;
phone?: string;
Expand Down
18 changes: 18 additions & 0 deletions src/app/pages/home/home.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.noSession {
width: 98%;
padding: 1rem;
background: #F2D7D5;
margin-bottom: 1rem;
display: flex;
justify-content: space-between;
}

.noSession span a {
cursor: pointer;
color: blue;
}

.noSession a {
cursor: pointer;
}

11 changes: 11 additions & 0 deletions src/app/pages/home/home.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@


<div class="noSession" *ngIf="preferences === 0">
<span>
Recuerde ingresar sus preferencias
<a (click)="preferencesRoute()"> Ingresar preferencias ahora </a>
</span>
<a class="close" style="cursor: pointer;" (click)="preferences = 1">×</a>
</div>


<!-- ============================================================================== -->
<!-- Options view bar -->
<!-- ============================================================================== -->
Expand Down
31 changes: 28 additions & 3 deletions src/app/pages/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { Component, OnInit, Input } from '@angular/core';
import { DatabaseService } from "../../services/database.service";
import { Router } from '@angular/router';


@Component({
selector: 'app-home',
templateUrl: './home.component.html'
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {

view_bar:string = 'all';
books:any[] = [];
firtSession = null;
preferences = null;

constructor( private _dbService:DatabaseService, private route:Router ) {
const UID = JSON.parse(localStorage.getItem('user')).uid;
console.log(UID);

constructor( private _dbService:DatabaseService ) {
this._dbService.getDataQuery('books', 'status', '==', 'available')
.valueChanges()
.subscribe( data => {
Expand All @@ -24,7 +32,24 @@ export class HomeComponent implements OnInit {
.subscribe( resp => this.books[i].user = resp );
}
});
}

this._dbService.getDataQuery('users', 'uid', '==', UID)
.valueChanges()
.subscribe( data => {
let user = data[0];
this.preferences = user.preferences.length;

if( !user.firtSession ) {
user.firtSession = true;
this._dbService.updateData('users', UID, user);
}
});
}

ngOnInit() {}

preferencesRoute() {
this.route.navigate(['/profile', {input: 'preferences'}]);
}

}
1 change: 1 addition & 0 deletions src/app/pages/pages.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const PAGES_ROUTE: Routes = [
{ path: 'home', component: HomeComponent },
{ path: 'addBook', component: AddBookComponent },
{ path: 'profile', component: ProfileComponent },
{ path: 'profile/:input', component: ProfileComponent },
{ path: 'library', component: LibraryComponent },
{ path: 'search/:input', component: SearchComponent },
{ path: 'messages', component: ChatsComponent },
Expand Down
61 changes: 36 additions & 25 deletions src/app/pages/profile/profile.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { Router, ActivatedRoute } from '@angular/router';
import { map } from 'rxjs/operators';

// SERVICE
Expand All @@ -17,7 +17,7 @@ import { AngularFireAuth } from 'angularfire2/auth';
export class ProfileComponent implements OnInit {

form:FormGroup;
profile_options:string = 'my_profile'; // Controla las opciones en Mi Perfil
profile_options:string; // Controla las opciones en Mi Perfil
profile:any;
user_profile: any;
uid:string; // uid usuario actual
Expand All @@ -28,31 +28,42 @@ export class ProfileComponent implements OnInit {
urlImgs:string; // Guarda la ruta de la imagen para guardar en DB


constructor( private _dbService:DatabaseService, private auth:AngularFireAuth, private router: Router ) {
this.preferences_modal = {
hour: '',
day: '',
subway_station: ''
};
constructor( private _dbService:DatabaseService,
private auth:AngularFireAuth,
private router: Router,
private acRoute:ActivatedRoute ) {

let actual_user = JSON.parse( localStorage.getItem( "user" ) );
this.acRoute.params.subscribe( params => {
const input:string = params['input'];

this._dbService.getDataQuery( "users", "uid", "==", actual_user.uid )
.snapshotChanges()
.pipe(
map(actions => actions.map(a => {
const data = a.payload.doc.data();
const key = a.payload.doc.id;
return { key, ...data };
}))
).subscribe( data => {
this.profile = data[0];
this.preferences = this.profile.preferences;
});

this._dbService.getDataQuery("books", "uid", "==", actual_user.uid)
.valueChanges()
.subscribe( data => this.count_book = data.length );
if( input === 'preferences' ) this.profile_options = 'preference_profile';
else this.profile_options = 'my_profile';

this.preferences_modal = {
hour: '',
day: '',
subway_station: ''
};

let actual_user = JSON.parse( localStorage.getItem( "user" ) );

this._dbService.getDataQuery( "users", "uid", "==", actual_user.uid )
.snapshotChanges()
.pipe(
map(actions => actions.map(a => {
const data = a.payload.doc.data();
const key = a.payload.doc.id;
return { key, ...data };
}))
).subscribe( data => {
this.profile = data[0];
this.preferences = this.profile.preferences;
});

this._dbService.getDataQuery("books", "uid", "==", actual_user.uid)
.valueChanges()
.subscribe( data => this.count_book = data.length );
});
}

ngOnInit() {
Expand Down
1 change: 1 addition & 0 deletions src/app/register/register.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class RegisterComponent implements OnInit {
email: form.email.toLowerCase(),
categories: this.selected_categories,
// phone: form.phone,
firtSession: false,
google: false,
status: true,
role: 'normal',
Expand Down

0 comments on commit a8078ab

Please sign in to comment.