Skip to content

Commit

Permalink
Merge pull request #19 from olatundeee/development
Browse files Browse the repository at this point in the history
Added a new sidenav item for viewing user lists and individual user p…
  • Loading branch information
olatundeee committed Apr 6, 2019
2 parents 45e680b + e25ec0e commit 687ad18
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 9 deletions.
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ app.use('/users', usersRouter);
app.post('/register', usersRouter);
app.post('/login', usersRouter);
app.get('/logout', usersRouter);
app.post('/create-admin', usersRouter);

// routes for tasks api
app.get('/all-tasks', tasksRouter);
Expand Down
26 changes: 26 additions & 0 deletions client/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import { ViewEveryTeamComponent } from './view-every-team/view-every-team.compon
import { ViewAllUserProjectsComponent } from './view-all-user-projects/view-all-user-projects.component';
import { ViewAllUserTasksComponent } from './view-all-user-tasks/view-all-user-tasks.component';
import { ViewAllUserTeamsComponent } from './view-all-user-teams/view-all-user-teams.component';
import { TeamMembersComponent } from './team-members/team-members.component';
import { UsersComponent } from './users/users.component';
import { UserListComponent } from './user-list/user-list.component';
import { ProfileComponent } from './profile/profile.component';


// import route guard
import { AuthGuard } from './guards/auth.guard';
Expand Down Expand Up @@ -158,6 +163,27 @@ const routes: Routes = [
{
path: 'all-teams',
component: ViewAllTeamsComponent
},
{
path: 'team-members',
component: TeamMembersComponent
}
]
},
{
// Route for viewing user information and data
path: 'users',
component: UsersComponent,
children: [
{
// Route for viewing list of users
path: '',
component: UserListComponent
},
{
// Route for viewing user profile
path: 'profile',
component: ProfileComponent
}
]
}
Expand Down
4 changes: 3 additions & 1 deletion client/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { TasksService } from './services/tasks.service';
import { UserService } from './services/user.service';
import { TeamsService } from './services/teams.service';
import { TeamMembersComponent } from './team-members/team-members.component';
import { UserListComponent } from './user-list/user-list.component';

@NgModule({
declarations: [
Expand Down Expand Up @@ -81,7 +82,8 @@ import { TeamMembersComponent } from './team-members/team-members.component';
ViewAllUserProjectsComponent,
ViewAllUserTasksComponent,
ViewAllUserTeamsComponent,
TeamMembersComponent
TeamMembersComponent,
UserListComponent
],
imports: [
BrowserModule,
Expand Down
11 changes: 7 additions & 4 deletions client/src/app/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@ export class LoginComponent implements OnInit {
localStorage.removeItem('currentUserId');
localStorage.setItem('currentUserId', r.user._id);

// if the role of the user returned from the backend is user the navigate to the dashboard area
// set the value for current user role in local storage

if (r.user.role === 'User') {
this.router.navigateByUrl('/dashboard');
}
localStorage.removeItem('currentUserRole');
localStorage.setItem('currentUserRole', r.user.role);

// navigate to the dashboard area

this.router.navigateByUrl('/dashboard');
}
},
r => {
Expand Down
11 changes: 11 additions & 0 deletions client/src/app/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,15 @@ export class UserService {
}
);
}

// update role of the user with username administrator, new role is `administrator`

makeUserAdmin() {
console.log(localStorage.getItem('currentUser'));
console.log(localStorage.getItem('currentUserId'));

// send http request to backend

return this.http.post('http://localhost:3001/create-admin', {});
}
}
3 changes: 3 additions & 0 deletions client/src/app/sidenav/sidenav.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
<li class="collection-item red white-text">
<a routerLink="/dashboard/projects" class="white-text">Projects</a>
</li>
<li class="collection-item red white-text" *ngIf="isUserAdmin">
<a routerLink="/dashboard/users" class="white-text">Users</a>
</li>
</ul>
13 changes: 13 additions & 0 deletions client/src/app/sidenav/sidenav.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,22 @@ import { Component, OnInit } from '@angular/core';
})
export class SidenavComponent implements OnInit {

isUserAdmin;

constructor() { }

ngOnInit() {
// get the user role for currently logged in user

const isAdmin = localStorage.getItem('currentUserRole');

console.log('User role: ' + isAdmin);

// if currently logged in user is the administrator, display the users collection list item

if (isAdmin === 'Administrator') {
this.isUserAdmin = true;
}
}

}
Empty file.
3 changes: 3 additions & 0 deletions client/src/app/user-list/user-list.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>
user-list works!
</p>
25 changes: 25 additions & 0 deletions client/src/app/user-list/user-list.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { UserListComponent } from './user-list.component';

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

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

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

it('should create', () => {
expect(component).toBeTruthy();
});
});
16 changes: 16 additions & 0 deletions client/src/app/user-list/user-list.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component, OnInit } from '@angular/core';
import { UserService } from '../services/user.service';

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

constructor(private userService: UserService) { }

ngOnInit() {
}

}
4 changes: 1 addition & 3 deletions client/src/app/users/users.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<p>
users works!
</p>
<router-outlet></router-outlet>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<a class="btn green lighten-2 add-btn" *ngIf="isNotTeamLead" (click)="joinTeam()">join team</a>
</div>
<div class="col l3 m3 s12 center">
<a class="btn blue add-btn">team members</a>
<a routerLink="/dashboard/teams/team-members" class="btn blue add-btn">team members</a>
</div>
<div class="col l3 m3 s12 center">
<a class="btn green add-btn" routerLink="/dashboard/projects">back to projects list</a>
Expand Down
15 changes: 15 additions & 0 deletions routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,19 @@ router.get('/logout', function(req, res){
})
})

// // update role of the user with username administrator, new role is `administrator`

router.post('/create-admin', function(req, res) {
users.updateOne({
username: 'administrator'
},{
$set: {
role: 'Administrator'
}
}, function(err, user){
console.log(user);
console.log('Admin role updated');
})
})

module.exports = router;

0 comments on commit 687ad18

Please sign in to comment.