|
100 | 100 | <!-- Session Record -->
|
101 | 101 | <h5> Session Record: </h5>
|
102 | 102 | <br>
|
103 |
| - <textarea [ngModel]="getCourseRecordJSON((course_record | async))" [disabled]="!edit_mode"></textarea> |
| 103 | + <textarea mdInput mdTextareaAutosize [(ngModel)]="session_record" [disabled]="!edit_mode"></textarea> |
| 104 | +
|
| 105 | + <!-- Actions --> |
| 106 | + <br> |
| 107 | + <div class="actions" fxLayout="row" fxLayoutAlign="end center"> |
| 108 | +
|
| 109 | + <!-- Edit Mode --> |
| 110 | + <ng-container *ngIf="(course_record | async)?._id as id"[ngSwitch]="edit_mode"> |
| 111 | + <button md-raised-button (click)="edit_mode = true" *ngSwitchCase="false"> |
| 112 | + <md-icon>edit</md-icon> |
| 113 | + Edit |
| 114 | + </button> |
| 115 | + <button md-raised-button (click)="update(id)" *ngSwitchCase="true"> |
| 116 | + <md-icon>save</md-icon> |
| 117 | + Save |
| 118 | + </button> |
| 119 | + </ng-container> |
| 120 | +
|
| 121 | + </div> |
104 | 122 | </div>
|
105 | 123 |
|
106 | 124 | </div>
|
|
146 | 164 |
|
147 | 165 | textarea{
|
148 | 166 | width: 100%;
|
149 |
| - min-height: 300px; |
150 | 167 | border: none;
|
151 | 168 | background-color: transparent;
|
152 | 169 | color: #000 !important;
|
| 170 | + font-family: "Courier New", courier, monospace; |
153 | 171 | }
|
154 | 172 |
|
| 173 | +
|
155 | 174 | ` ],
|
156 | 175 | changeDetection: ChangeDetectionStrategy.OnPush
|
157 | 176 | })
|
158 | 177 |
|
159 | 178 | export class UserSessionItem extends MeteorComponent {
|
| 179 | + @Input('user') user : User; |
| 180 | + @Input('course') course : Course; |
160 | 181 | @Input('course_record') course_record : Observable<CourseRecord>;
|
161 |
| - |
162 | 182 | @Input('session') session : Session;
|
163 | 183 | private SessionStatus = SessionStatus;
|
164 |
| - private container_index = 0; |
165 | 184 |
|
| 185 | + private container_index = 0; |
166 | 186 | private lab : Lab;
|
167 | 187 |
|
| 188 | + private session_record; |
| 189 | + |
168 | 190 | private expand : boolean = false;
|
169 | 191 | private edit_mode : boolean = false;
|
170 | 192 |
|
|
173 | 195 | }
|
174 | 196 |
|
175 | 197 | ngOnInit(){
|
| 198 | + |
176 | 199 | // Get Lab
|
177 |
| - Meteor.subscribe('labs.course', this.session.course_id, () => { |
178 |
| - this.zone.run(() => { |
179 |
| - this.lab = Labs.findOne({ "_id" : this.session.lab_id }); |
180 |
| - this.ref.markForCheck(); |
| 200 | + new Promise((resolve, reject) => { |
| 201 | + Meteor.subscribe('labs.course', this.session.course_id, () => { |
| 202 | + this.zone.run(() => { |
| 203 | + this.lab = Labs.findOne({ "_id" : this.session.lab_id }); |
| 204 | + this.ref.markForCheck(); |
| 205 | + resolve(); |
| 206 | + }) |
181 | 207 | });
|
182 |
| - }); |
| 208 | + }) |
| 209 | + |
| 210 | + // Get Course Record for Lab |
| 211 | + .then(() => { |
| 212 | + new Promise((resolve, reject) => { |
| 213 | + this.course_record.subscribe((record) => { |
| 214 | + if(record && _.has(record, "labs."+this.lab._id+"."+this.session._id)){ |
| 215 | + this.session_record = JSON.stringify(record.labs[this.lab._id][this.session._id],null,2); |
| 216 | + this.ref.markForCheck(); |
| 217 | + resolve(); |
| 218 | + } |
| 219 | + }) |
| 220 | + }) |
| 221 | + }) |
| 222 | + |
183 | 223 | }
|
184 | 224 |
|
185 |
| - private getCourseRecordJSON(record){ |
186 |
| - if(record && _.has(record, "labs."+this.lab._id+"."+this.session._id)){ |
187 |
| - return JSON.stringify(record.labs[this.lab._id][this.session._id],null,2); |
188 |
| - } |
| 225 | + update(id){ |
| 226 | + CourseRecords.update({ |
| 227 | + "_id" : id |
| 228 | + },{ |
| 229 | + "$set" : { |
| 230 | + ["labs."+this.lab._id+"."+this.session._id] : JSON.parse(this.session_record) |
| 231 | + } |
| 232 | + }) |
| 233 | + this.edit_mode = false; |
189 | 234 | }
|
190 | 235 | }
|
191 | 236 |
|
|
208 | 253 | <div class="expand_container" *ngIf="expand" fxLayout="column">
|
209 | 254 |
|
210 | 255 | <!-- Actions -->
|
211 |
| - <br> |
212 |
| - <h5> Role: </h5> |
213 |
| - <div fxLayout="row"> |
214 |
| - <md-select class="role_select"> |
215 |
| - <md-option [value]="Role.student">Student</md-option> |
216 |
| - <md-option [value]="Role.instructor">Instructor</md-option> |
217 |
| - <md-option [value]="Role.course_admin">Course Admin</md-option> |
218 |
| - </md-select> |
| 256 | + <div class="actions" fxLayout="row"> |
| 257 | + <div *ngIf="role < Role.global_admin && role > Role.guest" class="mat-raised-button" fxLayout="row" fxLayoutAlign="space-evenly center"> |
| 258 | + Role: |
| 259 | + <md-select class="role_select" [(ngModel)]="role" (ngModelChanges)="update()"> |
| 260 | + <md-option [value]="Role.student">Student</md-option> |
| 261 | + <md-option [value]="Role.instructor">Instructor</md-option> |
| 262 | + <md-option [value]="Role.course_admin">Course Admin</md-option> |
| 263 | + </md-select> |
| 264 | + </div> |
219 | 265 | </div>
|
220 | 266 |
|
221 | 267 | <!-- Sessions -->
|
|
230 | 276 |
|
231 | 277 | <ul fxLayout="column" class="sessions">
|
232 | 278 | <li *ngFor="let session of (sessions | async);">
|
233 |
| - <tuxlab-user-session-item [session]="session" [course_record]="course_record"></tuxlab-user-session-item> |
| 279 | + <tuxlab-user-session-item [user]="user" [course]="course" [course_record]="course_record" [session]="session"></tuxlab-user-session-item> |
234 | 280 | </li>
|
235 | 281 | </ul>
|
236 | 282 | </ng-container>
|
|
266 | 312 | padding: 10px !important;
|
267 | 313 | }
|
268 | 314 |
|
| 315 | + div.actions{ |
| 316 | + padding: 4px; |
| 317 | +
|
| 318 | + font-weight: 500; |
| 319 | + background-color: #ddd; |
| 320 | +
|
| 321 | + mat-raised-button{ |
| 322 | + padding: 4px; |
| 323 | +
|
| 324 | + md-select{ |
| 325 | + font-size: 14px !important; |
| 326 | + } |
| 327 | + } |
| 328 | + } |
| 329 | +
|
269 | 330 | ` ],
|
270 | 331 | changeDetection: ChangeDetectionStrategy.OnPush
|
271 | 332 | })
|
|
275 | 336 | @Input('course') course : Course;
|
276 | 337 |
|
277 | 338 | private Role = Role;
|
| 339 | + private role : Role; |
278 | 340 |
|
279 | 341 | private sessions : ObservableCursor<Session>;
|
280 | 342 | private course_record : Observable<CourseRecord>;
|
|
300 | 362 | // Get Course
|
301 | 363 | .then(() => {
|
302 | 364 | this.course = Courses.findOne({ _id : this.course._id });
|
| 365 | + this.role = Users.getRoleFor(this.course._id, this.user._id); |
303 | 366 | })
|
304 | 367 |
|
305 | 368 | // Get Sub-Items
|
|
311 | 374 | Meteor.subscribe('course_records.id', this.course._id, this.user._id, () => {
|
312 | 375 | resolve();
|
313 | 376 | });
|
| 377 | + |
314 | 378 | }).then(() => {
|
315 | 379 | this.course_record = CourseRecords.observable.find({
|
316 | 380 | user_id: this.user._id,
|
|
334 | 398 | });
|
335 | 399 | })
|
336 | 400 | ])
|
337 |
| - }) |
338 |
| - }) |
| 401 | + }); |
| 402 | + }); |
| 403 | + } |
| 404 | + |
| 405 | + update(){ |
| 406 | + Users.setRoleFor(this.course._id, this.user._id, this.role); |
339 | 407 | }
|
340 | 408 | }
|
341 | 409 |
|
|
359 | 427 | <br>
|
360 | 428 |
|
361 | 429 | <!-- Actions -->
|
362 |
| - <h5> Actions: </h5> |
363 | 430 | <div class="actions" fxLayout="row" style="margin-bottom:10px;">
|
364 | 431 |
|
365 | 432 | <!-- Global Admin -->
|
|
517 | 584 | private user_query : string;
|
518 | 585 | private course_query : Course;
|
519 | 586 |
|
520 |
| - constructor( private zone : NgZone ) { |
| 587 | + constructor( private zone : NgZone, private ref : ChangeDetectorRef ) { |
521 | 588 | super();
|
522 | 589 | }
|
523 | 590 |
|
524 | 591 | ngOnInit(){
|
525 |
| - Meteor.subscribe('users.all'); |
| 592 | + Meteor.subscribe('users.all', () => { |
| 593 | + this.ref.markForCheck(); |
| 594 | + }); |
526 | 595 | Meteor.subscribe('courses.all');
|
527 | 596 | this.courses = Courses.observable.find({});
|
528 | 597 | this.onSearch();
|
|
0 commit comments