Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit profile, and view Followers and Following #18

Merged
merged 6 commits into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/_models/team.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export class Team{
_id : string;
name : string;
teamLogoUrl : string;


constructor(name?: string){
this.name = name;
this.teamLogoUrl = "";
}
}
2 changes: 2 additions & 0 deletions src/_models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class User{
followers : any[];
favTeams : any[];
eventHistory: any[];
reputation : number;


constructor(username?: string, email?: string, password?: string){
Expand All @@ -18,5 +19,6 @@ export class User{
this.favTeams = [];
this.eventHistory = [];
this.followers = [];
this.reputation = 0;
}
}
23 changes: 23 additions & 0 deletions src/_services/team.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';

import { Team } from '../_models/team';
import { AppUrl } from '../_config/url.config';

@Injectable()
export class TeamService {

private url: string = AppUrl.root + '/teams';
private httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };

constructor(private http: HttpClient) { }

getAllTeams() : Observable<Team[]> {
return this.http.get<Team[]>(this.url, this.httpOptions)
.map(teams => {
return teams;
});
}
}
20 changes: 18 additions & 2 deletions src/_services/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ export class UsersService {
});
}

getAllFollowing() : Observable<User> {
let authUserId = JSON.parse(localStorage.getItem('authUser')).userId;
return this.http.get<User>(this.url + '/' + authUserId + '/following', this.httpOptions)
.map(user => {
return user;
});
}

getAllFollowers() : Observable<User> {
let authUserId = JSON.parse(localStorage.getItem('authUser')).userId;
return this.http.get<User>(this.url + '/' + authUserId + '/followers', this.httpOptions)
.map(user => {
return user;
});
}

follow(operation: string, user: string) : Observable<User>{
let authUserId = JSON.parse(localStorage.getItem('authUser')).userId;
let body = { operation: operation, user: user };
Expand All @@ -66,9 +82,9 @@ export class UsersService {
});
}

saveEditions(username:string , email:string) : Observable<User>{
saveEditions(username:string , password:string) : Observable<User>{
let authUserId = JSON.parse(localStorage.getItem('authUser')).userId;
let body = { username:username, email:email };
let body = { username:username, password:password };
return this.http.put<User>( this.url + '/' + authUserId, body, this.httpOptions)
.map(user => {
return user;
Expand Down
17 changes: 17 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@ import { SearchedProfilePage } from '../pages/searched-profile/searched-profile'
import {TokenInterceptor} from "../_providers/auth.interceptor";
import { EditProfilePage } from '../pages/edit-profile/edit-profile';
import { MyBarPage } from '../pages/my-bar/my-bar';
import { EditTeamsPage } from '../pages/edit-teams/edit-teams';
import { MyTeamsPage } from '../pages/edit-teams/my-teams/my-teams';
import { AllTeamsPage } from '../pages/edit-teams/all-teams/all-teams';
import { TeamService } from '../_services/team';
import { FollowingPage } from '../pages/following/following';
import { FollowersPage } from '../pages/followers/followers';


@NgModule({
declarations: [
MyApp,
FeedPage,
ProfilePage,
FollowingPage,
FollowersPage,
MatchesPage,
CreateEventPage,
EventsPage,
Expand All @@ -49,6 +57,9 @@ import { MyBarPage } from '../pages/my-bar/my-bar';
SearchPage,
SearchedProfilePage,
EditProfilePage,
EditTeamsPage,
MyTeamsPage,
AllTeamsPage,
SignInPage,
SignUpPage,
LocationModal,
Expand All @@ -71,6 +82,8 @@ import { MyBarPage } from '../pages/my-bar/my-bar';
MyApp,
FeedPage,
ProfilePage,
FollowingPage,
FollowersPage,
MatchesPage,
CreateEventPage,
EventsPage,
Expand All @@ -79,6 +92,9 @@ import { MyBarPage } from '../pages/my-bar/my-bar';
SearchPage,
SearchedProfilePage,
EditProfilePage,
EditTeamsPage,
MyTeamsPage,
AllTeamsPage,
SignInPage,
SignUpPage,
LocationModal,
Expand All @@ -94,6 +110,7 @@ import { MyBarPage } from '../pages/my-bar/my-bar';
MatchesService,
EventsService,
UsersService,
TeamService,
BarService,
OwnerService,
{provide: HTTP_INTERCEPTORS,
Expand Down
25 changes: 10 additions & 15 deletions src/pages/edit-profile/edit-profile.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<!--
Generated template for the EditProfilePage page.

See http://ionicframework.com/docs/components/#navigation for more info on
Ionic pages and navigation.
-->
<ion-header>
<ion-navbar>
<button ion-button menuToggle>
Expand All @@ -24,19 +18,20 @@
<span class="text-default-light" text-center>{{user.email}}</span>
</p>

<input class="googol-input" type="text" placeholder="Novo username" [(ngModel)]="username"/>
<input class="googol-input" type="email" placeholder="Novo e-mail" [(ngModel)]="email"/>

<input class="googol-input" type="text" placeholder="Novo username" [(ngModel)]="username" />
<input class="googol-input" type="password" placeholder="Senha" [(ngModel)]="password" />
<input class="googol-input" type="password" placeholder="Confirmar Senha" [(ngModel)]="password_confirm" />


<button padding class="googol-btn-secondary">
<button padding class="googol-btn-secondary" (click)="goToEditTeams()">
Editar times
</button>

<div class="footer">
<button class="googol-btn-danger" (click)="save()">
Salvar edições
</button>
</div>

<button class="googol-btn-danger" (click)="save()">
Salvar edições
</button>



</ion-content>
13 changes: 0 additions & 13 deletions src/pages/edit-profile/edit-profile.module.ts

This file was deleted.

16 changes: 12 additions & 4 deletions src/pages/edit-profile/edit-profile.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
page-edit-profile {
.footer {
position: absolute;
bottom:5%;
width:92%;

input{
margin-bottom: 5%;
}

.googol-btn-light{
margin-bottom: 10px;
}

.googol-btn-danger{
margin-bottom: 3px;
}

}
121 changes: 83 additions & 38 deletions src/pages/edit-profile/edit-profile.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, AlertController } from 'ionic-angular';
import { NavController, AlertController } from 'ionic-angular';
import { User } from '../../_models/user';
import { UsersService } from '../../_services/users';
import { ProfilePage } from '../profile/profile';
import { EditTeamsPage } from '../edit-teams/edit-teams';

/**
* Generated class for the EditProfilePage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/

@IonicPage()
@Component({
selector: 'page-edit-profile',
templateUrl: 'edit-profile.html',
Expand All @@ -22,51 +14,88 @@ export class EditProfilePage {

email: string = "";
username: string = "";
password: string = "";
password_confirm: string = "";

constructor(public navCtrl: NavController, private userService : UsersService, public alert:AlertController) {
constructor(public navCtrl: NavController, private userService: UsersService, public alert: AlertController) {
let id = JSON.parse(localStorage.getItem('authUser')).userId;
this.fetchUser(id);
}

fetchUser(id : string){
fetchUser(id: string) {
this.userService.getOne(id).subscribe(
data=> {
data => {
this.user = data;
},
err =>{
err => {
console.log(err);
}
)
)
}

save(){
if(this.username === ""){
this.userService.saveEditions(this.user.username, this.email).subscribe(
data=> {
this.editedUserAlert("Edicoes realizadas com sucesso!");
this.user = data;
this.goProfile();
},
err =>{
console.log(err);
})}
else{
this.userService.saveEditions(this.username, this.email).subscribe(
data=> {
this.editedUserAlert("Ediçoes realizadas com sucesso!");
this.user = data;
this.goProfile();
},
err =>{
console.log(err);
});
}
validateFields(): boolean {
if (this.password === "" && this.username === "") {
this.presentAlert("Você não realizou alterações!");
return false;
}
if(this.password !== this.password_confirm) {
this.presentAlert("As senhas não combinam!");
return false;
}
return true;
}
save() {
if (this.validateFields()) {
if (this.username === "" && this.password !== "") {
this.userService.saveEditions(this.user.username, this.password).subscribe(
data => {
this.editedUserAlert("Edicoes realizadas com sucesso!");
this.user = data;
this.goProfile();
},
err => {
this.clearFields();
this.presentAlert(err.error.message);
})
}
else if (this.username !== "" && this.password === "") {
this.userService.saveEditions(this.username, this.user.password).subscribe(
data => {
this.editedUserAlert("Edicoes realizadas com sucesso!");
this.user = data;
this.goProfile();
},
err => {
this.clearFields();
this.presentAlert(err.error.message);
})
}
else {
this.userService.saveEditions(this.username, this.password).subscribe(
data => {
this.editedUserAlert("Ediçoes realizadas com sucesso!");
this.user = data;
this.clearFields();
this.goProfile();
},
err => {
//this.loading.dismiss();
this.clearFields();
this.presentAlert(err.error.message);

goProfile(){
});
}
}
}

goProfile() {
this.navCtrl.getPrevious();
}

goToEditTeams() {
this.navCtrl.push(EditTeamsPage);
}

editedUserAlert(message) {
let alert = this.alert.create({
title: 'Sucesso!',
Expand All @@ -76,4 +105,20 @@ export class EditProfilePage {
alert.present();
}

presentAlert(message) {
let alert = this.alert.create({
title: 'Atenção',
subTitle: message,
buttons: ['Entendido']
});
alert.present();
}

clearFields() {
this.email = "";
this.password = "";
this.password_confirm = "";

}

}
Loading