Skip to content

Commit

Permalink
Add wiring for profile editing page
Browse files Browse the repository at this point in the history
  • Loading branch information
marvac committed Jan 16, 2019
1 parent 1534dec commit b926c28
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 4 deletions.
9 changes: 7 additions & 2 deletions Client/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import { MemberCardComponent } from './components/members/member-card/member-car
import { MemberDetailComponent } from './components/members/member-detail/member-detail.component';
import { MemberDetailResolver } from './resolvers/member-detail.resolver';
import { MemberListResolver } from './resolvers/member-list.resolver';
import { MemberEditComponent } from './components/members/member-edit/member-edit.component';
import { MemberEditResolver } from './resolvers/member-edit.resolver';


export function tokenGetter() {
return localStorage.getItem("token");
Expand All @@ -39,7 +42,8 @@ export function tokenGetter() {
ListsComponent,
MessagesComponent,
MemberCardComponent,
MemberDetailComponent
MemberDetailComponent,
MemberEditComponent
],
imports: [
BrowserModule,
Expand All @@ -64,7 +68,8 @@ export function tokenGetter() {
AuthGuard,
UserService,
MemberDetailResolver,
MemberListResolver
MemberListResolver,
MemberEditResolver
],
bootstrap: [AppComponent]
})
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>
{{user.knownAs}}
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { MemberEditComponent } from './member-edit.component';

describe('MemberEditComponent', () => {
let component: MemberEditComponent;
let fixture: ComponentFixture<MemberEditComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ MemberEditComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(MemberEditComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { User } from 'src/app/models/user';

@Component({
selector: 'app-member-edit',
templateUrl: './member-edit.component.html',
styleUrls: ['./member-edit.component.css']
})
export class MemberEditComponent implements OnInit {
user: User;

constructor(private route: ActivatedRoute) { }

ngOnInit() {
this.route.data.subscribe(data => {
this.user = data['user'];
});
}

}
2 changes: 1 addition & 1 deletion Client/src/app/components/nav-menu/nav-menu.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</a>

<div class="dropdown-menu" *dropdownMenu>
<a class="dropdown-item"><i class="fa fa-user"></i> Edit Profile</a>
<a class="dropdown-item" [routerLink]="['/members/edit']"><i class="fa fa-user"></i> Edit Profile</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger" (click)="logout()"><i class="fa fa-sign-out"></i> Logout</a>
</div>
Expand Down
27 changes: 27 additions & 0 deletions Client/src/app/resolvers/member-edit.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Injectable } from "@angular/core";
import { User } from "../models/user";
import { UserService } from "../services/user.service";
import { Resolve, Router, ActivatedRouteSnapshot } from "@angular/router";
import { AlertifyService } from "../services/alertify.service";
import { Observable, of } from "rxjs";
import { catchError } from "rxjs/operators";
import { AuthService } from "../services/auth.service";

@Injectable()
export class MemberEditResolver implements Resolve<User> {

constructor(
private userService: UserService,
private authService: AuthService,
private router: Router,
private alertify: AlertifyService) { }

resolve(route: ActivatedRouteSnapshot): Observable<User> {
return this.userService.getUser(this.authService.decodedToken.nameid)
.pipe(catchError(error => {
this.alertify.error('Problem retrieving your data');
this.router.navigate(['/members']);
return of(null);
}));
}
}
7 changes: 6 additions & 1 deletion Client/src/app/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { AuthGuard } from './guards/auth.guard';
import { MemberDetailComponent } from './components/members/member-detail/member-detail.component';
import { MemberDetailResolver } from './resolvers/member-detail.resolver';
import { MemberListResolver } from './resolvers/member-list.resolver';
import { MemberEditComponent } from './components/members/member-edit/member-edit.component';
import { MemberEditResolver } from './resolvers/member-edit.resolver';

export const appRoutes: Routes = [
{ path: '', component: HomeComponent },
Expand All @@ -16,7 +18,10 @@ export const appRoutes: Routes = [
canActivate: [AuthGuard],
children: [
{ path: 'members', component: MemberListComponent, resolve: { users: MemberListResolver } },
{ path: 'members/:id', component: MemberDetailComponent, resolve: { user: MemberDetailResolver } },
{ path: 'members/edit', component: MemberEditComponent, resolve: { user: MemberEditResolver },
{ path: 'members/:id', component: MemberDetailComponent,
resolve: { user: MemberDetailResolver }
},
{ path: 'messages', component: MessagesComponent },
{ path: 'lists', component: ListsComponent }
]
Expand Down
1 change: 1 addition & 0 deletions Friendster.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</ItemGroup>

<ItemGroup>
<Folder Include="Client\src\app\components\members\member-edit\" />
<Folder Include="Client\src\app\guards\" />
<Folder Include="Client\src\app\models\" />
<Folder Include="wwwroot\" />
Expand Down

0 comments on commit b926c28

Please sign in to comment.