Skip to content

Commit

Permalink
Added Course Admin View
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekTBrown committed Aug 23, 2017
1 parent 392fd8d commit 31e6510
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 22 deletions.
13 changes: 8 additions & 5 deletions both/collections/user.collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@
const user = Users.observable.findOne({ '_id' : user_id });

// Iterate over Roles to get Courses
const courses = _.map(_.filter(user.roles, (priv : Privilege) => {
return priv.role >= Role.student;
}), (priv : Privilege) => {
return priv.course_id;
});
var courses = [];
if(user){
courses = _.map(_.filter(user.roles, (priv : Privilege) => {
return priv.role >= Role.student;
}), (priv : Privilege) => {
return priv.course_id;
});
}

// Map to Find Courses
return Courses.observable.find({ '_id' : { '$in' : courses }});
Expand Down
1 change: 1 addition & 0 deletions client/imports/account/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ <h1> Login </h1>

<!-- Login Button -->
<md-list-item fxLayout fxLayoutAlign="center">
<button md-raised-button [routerLink]="['/account','create']"><md-icon>person_add</md-icon>Create User</button>
<button md-raised-button><md-icon>vpn_key</md-icon>Forgot Password</button>
<button md-raised-button><md-icon>check</md-icon>Login</button>
</md-list-item>
Expand Down
9 changes: 9 additions & 0 deletions client/imports/account/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@
})
}

private sendResetEmail(query){
Meteor.call('Users.sendPasswordEmail', query, (err) => {
if(err){
this.error = true;
this.errorText = err;
}
});
}

private LoginWithGoogle(){
this.accountService.loginWithGoogle()
.then(() => {
Expand Down
41 changes: 35 additions & 6 deletions client/imports/admin/admin_user_list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@
}
button{
height: 30px;
font-size: 12px;
line-height: 30px;
Expand Down Expand Up @@ -596,15 +595,45 @@
private user_query : string;
private course_query : Course;

constructor( private zone : NgZone, private ref : ChangeDetectorRef ) {
constructor(private zone : NgZone,
private ref : ChangeDetectorRef,
private route : ActivatedRoute) {
super();
}

ngOnInit(){
Meteor.subscribe('users.all', () => {
this.ref.markForCheck();
});
Meteor.subscribe('courses.all');

// Get Course Filter
this.route.params
.map(params => params['course_id'])
.subscribe((course_id) => {

if(course_id){

// Get Course
Meteor.subscribe('courses.id', course_id, () => {
this.course_query = Courses.findOne({ _id : course_id });
this.onSearch();
})

// Get Users for Course
Meteor.subscribe('users.course', course_id, () => {
this.ref.markForCheck();
});

} else {

// Get All Courses
Meteor.subscribe('courses.all');

// Get All Users
Meteor.subscribe('users.all', () => {
this.ref.markForCheck();
});

}
})

this.courses = Courses.observable.find({});
this.onSearch();
}
Expand Down
1 change: 1 addition & 0 deletions client/imports/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const AppRoutes : Routes = [
{ path: 'explore', component: CourseList },
{ path: 'courses', component: CourseList, canActivate: [AuthGuard] },
{ path: 'courses/:course_id', component: CourseView },
{ path: 'courses/:course_id/users', component: UserList },

// Labs
{ path: 'courses/:course_id/labs/:lab_id', component: LabView, canActivate: [AuthGuard] },
Expand Down
12 changes: 8 additions & 4 deletions client/imports/course/course_view.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,22 @@ <h4> Syllabus </h4>
</div>
</div>

<div class="right" fxLayout="row" fxLayoutAlign="end center">
<ng-container *ngIf="!edit_mode">
<div class="right" fxLayout="row" fxLayoutAlign="end center" [ngSwitch]="edit_mode">
<ng-container *ngSwitchCase="false">
<button md-button routerLink="./users">
<md-icon>people</md-icon>
User View
</button>
<button md-button (click)="exportAsJSON()">
<md-icon>get_app</md-icon>
Export
Export Grades
</button>
<button md-button (click)="edit_mode=true">
<md-icon>mode_edit</md-icon>
Edit
</button>
</ng-container>
<ng-container *ngIf="edit_mode">
<ng-container *ngSwitchCase="true">
<button md-button *ngIf="role >= Role.course_admin" (click)="addCourseAdmin()">
<md-icon>person_add</md-icon>
Add Admin
Expand Down
14 changes: 7 additions & 7 deletions client/imports/course/course_view.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ div.course_view{

md-card.info {

input,textarea{
width: 100%;
border: none;
background-color: transparent;
color: #000 !important;
}

div.title{
font-size: 21px;
font-weight: 400;
Expand Down Expand Up @@ -87,13 +94,6 @@ div.course_view{
margin:10px 0px;
}

input,textarea{
width: 100%;
border: none;
background-color: transparent;
color: #000 !important;
}

textarea{
resize: none;
}
Expand Down
41 changes: 41 additions & 0 deletions server/methods/user.methods.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as _ from "lodash";
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';

import { User, Role } from "../../both/models/user.model";
import { Users } from "../../both/collections/user.collection";
Expand Down Expand Up @@ -35,6 +36,29 @@ Meteor.publish("users.instructors", (course_id) => {
}
})

// COURSE USERS
Meteor.publish("users.course", (course_id) => {
if(!Meteor.userId()){
throw new Meteor.Error("Unauthorized");
}

switch(Users.getRoleFor(course_id, Meteor.userId())){
case Role.instructor:
case Role.course_admin:
case Role.global_admin:
return Users.find({
"roles" : {
"$elemMatch" : {
"course_id" : course_id
}
}
})
case Role.student:
case Role.guest:
throw new Meteor.Error("Unauthorized");
}
})

// ALL USERS
Meteor.publish("users.all", () => {
if(!Meteor.userId()){
Expand Down Expand Up @@ -209,6 +233,23 @@ Meteor.publish("users.all", () => {
}).fetch();
},

'Users.sendPasswordEmail'({query}){

var user = Users.findOne({
$or : [
{ "_id" : query },
{ "profile.email " : query }
]
})

if(user){
Accounts.sendResetPasswordEmail(user._id);
} else {
throw new Meteor.Error("No Matching User Found");
}

},

'Users.remove'({user_id}){
if(!Meteor.userId()){
throw new Meteor.Error("Unauthorized");
Expand Down

0 comments on commit 31e6510

Please sign in to comment.