Skip to content

Commit

Permalink
Bug Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekTBrown committed Aug 22, 2017
1 parent c7cf880 commit fb645c2
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 33 deletions.
2 changes: 1 addition & 1 deletion both/collections/course_record.collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
this.observable = new MongoObservable.Collection(this);

// Permissions
const allowed_fields = [];
const allowed_fields = ["labs"];
super.allow({
update: function(user_id, course_record : CourseRecord, fields) {
return _.reject(fields, key => _.includes(allowed_fields, key)).length === 0 &&
Expand Down
7 changes: 4 additions & 3 deletions client/imports/account/dashboard.component.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<div class="tuxlab-dashboard">

<h1> Welcome to TuxLab! </h1>

<div class="featured_courses">
<h2> Featured Courses </h2>
<tuxlab-course-list type="featured_courses"></tuxlab-course-list>

</div>


<div class="split_courses" fxLayout="row">
<div fxFlex="1 0 auto">
<h3> My Sessions </h3>
<h2> My Sessions </h2>
</div>
<div fxFlex="1 0 auto">
<h3> My Courses </h3>
<h2> My Courses </h2>

<tuxlab-course-list type="my_courses"></tuxlab-course-list>
</div>
Expand Down
2 changes: 1 addition & 1 deletion client/imports/account/dashboard.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ div.tuxlab-dashboard{

margin:0 auto;

h2, h3 {
h1, h2, h3 {
font-weight: 300;
}

Expand Down
123 changes: 96 additions & 27 deletions client/imports/admin/admin_user_list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,25 @@
<!-- Session Record -->
<h5> Session Record: </h5>
<br>
<textarea [ngModel]="getCourseRecordJSON((course_record | async))" [disabled]="!edit_mode"></textarea>
<textarea mdInput mdTextareaAutosize [(ngModel)]="session_record" [disabled]="!edit_mode"></textarea>
<!-- Actions -->
<br>
<div class="actions" fxLayout="row" fxLayoutAlign="end center">
<!-- Edit Mode -->
<ng-container *ngIf="(course_record | async)?._id as id"[ngSwitch]="edit_mode">
<button md-raised-button (click)="edit_mode = true" *ngSwitchCase="false">
<md-icon>edit</md-icon>
Edit
</button>
<button md-raised-button (click)="update(id)" *ngSwitchCase="true">
<md-icon>save</md-icon>
Save
</button>
</ng-container>
</div>
</div>
</div>
Expand Down Expand Up @@ -146,25 +164,29 @@
textarea{
width: 100%;
min-height: 300px;
border: none;
background-color: transparent;
color: #000 !important;
font-family: "Courier New", courier, monospace;
}
` ],
changeDetection: ChangeDetectionStrategy.OnPush
})

export class UserSessionItem extends MeteorComponent {
@Input('user') user : User;
@Input('course') course : Course;
@Input('course_record') course_record : Observable<CourseRecord>;

@Input('session') session : Session;
private SessionStatus = SessionStatus;
private container_index = 0;

private container_index = 0;
private lab : Lab;

private session_record;

private expand : boolean = false;
private edit_mode : boolean = false;

Expand All @@ -173,19 +195,42 @@
}

ngOnInit(){

// Get Lab
Meteor.subscribe('labs.course', this.session.course_id, () => {
this.zone.run(() => {
this.lab = Labs.findOne({ "_id" : this.session.lab_id });
this.ref.markForCheck();
new Promise((resolve, reject) => {
Meteor.subscribe('labs.course', this.session.course_id, () => {
this.zone.run(() => {
this.lab = Labs.findOne({ "_id" : this.session.lab_id });
this.ref.markForCheck();
resolve();
})
});
});
})

// Get Course Record for Lab
.then(() => {
new Promise((resolve, reject) => {
this.course_record.subscribe((record) => {
if(record && _.has(record, "labs."+this.lab._id+"."+this.session._id)){
this.session_record = JSON.stringify(record.labs[this.lab._id][this.session._id],null,2);
this.ref.markForCheck();
resolve();
}
})
})
})

}

private getCourseRecordJSON(record){
if(record && _.has(record, "labs."+this.lab._id+"."+this.session._id)){
return JSON.stringify(record.labs[this.lab._id][this.session._id],null,2);
}
update(id){
CourseRecords.update({
"_id" : id
},{
"$set" : {
["labs."+this.lab._id+"."+this.session._id] : JSON.parse(this.session_record)
}
})
this.edit_mode = false;
}
}

Expand All @@ -208,14 +253,15 @@
<div class="expand_container" *ngIf="expand" fxLayout="column">
<!-- Actions -->
<br>
<h5> Role: </h5>
<div fxLayout="row">
<md-select class="role_select">
<md-option [value]="Role.student">Student</md-option>
<md-option [value]="Role.instructor">Instructor</md-option>
<md-option [value]="Role.course_admin">Course Admin</md-option>
</md-select>
<div class="actions" fxLayout="row">
<div *ngIf="role < Role.global_admin && role > Role.guest" class="mat-raised-button" fxLayout="row" fxLayoutAlign="space-evenly center">
Role: &nbsp;
<md-select class="role_select" [(ngModel)]="role" (ngModelChanges)="update()">
<md-option [value]="Role.student">Student</md-option>
<md-option [value]="Role.instructor">Instructor</md-option>
<md-option [value]="Role.course_admin">Course Admin</md-option>
</md-select>
</div>
</div>
<!-- Sessions -->
Expand All @@ -230,7 +276,7 @@
<ul fxLayout="column" class="sessions">
<li *ngFor="let session of (sessions | async);">
<tuxlab-user-session-item [session]="session" [course_record]="course_record"></tuxlab-user-session-item>
<tuxlab-user-session-item [user]="user" [course]="course" [course_record]="course_record" [session]="session"></tuxlab-user-session-item>
</li>
</ul>
</ng-container>
Expand Down Expand Up @@ -266,6 +312,21 @@
padding: 10px !important;
}
div.actions{
padding: 4px;
font-weight: 500;
background-color: #ddd;
mat-raised-button{
padding: 4px;
md-select{
font-size: 14px !important;
}
}
}
` ],
changeDetection: ChangeDetectionStrategy.OnPush
})
Expand All @@ -275,6 +336,7 @@
@Input('course') course : Course;

private Role = Role;
private role : Role;

private sessions : ObservableCursor<Session>;
private course_record : Observable<CourseRecord>;
Expand All @@ -300,6 +362,7 @@
// Get Course
.then(() => {
this.course = Courses.findOne({ _id : this.course._id });
this.role = Users.getRoleFor(this.course._id, this.user._id);
})

// Get Sub-Items
Expand All @@ -311,6 +374,7 @@
Meteor.subscribe('course_records.id', this.course._id, this.user._id, () => {
resolve();
});

}).then(() => {
this.course_record = CourseRecords.observable.find({
user_id: this.user._id,
Expand All @@ -334,8 +398,12 @@
});
})
])
})
})
});
});
}

update(){
Users.setRoleFor(this.course._id, this.user._id, this.role);
}
}

Expand All @@ -359,7 +427,6 @@
<br>
<!-- Actions -->
<h5> Actions: </h5>
<div class="actions" fxLayout="row" style="margin-bottom:10px;">
<!-- Global Admin -->
Expand Down Expand Up @@ -517,12 +584,14 @@
private user_query : string;
private course_query : Course;

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

ngOnInit(){
Meteor.subscribe('users.all');
Meteor.subscribe('users.all', () => {
this.ref.markForCheck();
});
Meteor.subscribe('courses.all');
this.courses = Courses.observable.find({});
this.onSearch();
Expand Down
2 changes: 1 addition & 1 deletion client/imports/course/course_list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h1 *ngIf="title">{{ title }}</h1>
</md-card-header>

<!-- Action Buttons -->
<md-card-actions fxLayout="row" fxLayoutAlign="start">
<md-card-actions fxLayout="row" fxLayoutAlign="space-evenly">

<!-- View -->
<a [routerLink]="['/courses', course._id ]" md-button>
Expand Down

0 comments on commit fb645c2

Please sign in to comment.