Skip to content

Commit 0781ce0

Browse files
cemersozDerekTBrown
authored andcommitted
Fixes to task Proceed and labview (#152)
* issue 32 fixed * removed swp * fixed nconf issues * issue 82, 84 fixes * fixed #82 * isse #77 * fixed tests * fixed files * fixed tests master * fixed comment * moved validator * removed duplicate file * fixed tests, removed duplicate underscore, publish * changes * fixed methods.ts import * fixed issues w methods * fixes * minor fixes * A * api changes * fixed api * comments * minor changes * minor fixes * api changes (#126) * issue 32 fixed * removed swp * fixed nconf issues * issue 82, 84 fixes * fixed #82 * isse #77 * fixed tests * fixed files * fixed tests master * fixed comment * moved validator * removed duplicate file * fixed tests, removed duplicate underscore, publish * changes * fixed methods.ts import * fixed issues w methods * fixes * minor fixes * A * api changes * fixed api * comments * minor changes * minor fixes * method implementations * before merge * removed testing change * fixed typo * fixed prepareLab * removed test methods * fix prepareLab * methods changes * removed swap file * fixed merge * fixes * prepareLab WORKS * further fixes * merge * all works * deleted debug line * fixed minor excess code * minor indentation fix * reference fixes * fixes to nextTask * merged with master * minor changes * fixed merge problems * fixed md view and swithces
1 parent 3dae11f commit 0781ce0

File tree

7 files changed

+142
-101
lines changed

7 files changed

+142
-101
lines changed

client/imports/ui/pages/lab/taskview.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<!--Markdown View-->
44
<div class="tuxlab-taskview-step">
5-
65

76
<md-sidenav-layout>
87
<md-sidenav #left [opened]="false" layout-padding>
@@ -42,7 +41,7 @@
4241
<p>Checking Task...</p>
4342
<md-dialog-actions ok="Fine"></md-dialog-actions>
4443
</md-dialog>
45-
<button md-raised-button (click)="alert.show()" *ngIf="!currentCompleted">
44+
<button md-raised-button (click)="nextTask()">
4645
Check
4746
<md-icon fontIcon="tuxicon-tick"></md-icon>
4847
</button>

client/imports/ui/pages/lab/taskview.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
import { MeteorComponent } from 'angular2-meteor';
1414
import { OVERLAY_PROVIDERS } from '@angular2-material/core/overlay/overlay';
1515
import { MATERIAL_PROVIDERS, MATERIAL_DIRECTIVES } from 'ng2-material';
16-
import { MD_INPUT_DIRECTIVES } from '@angular2-material/input';
16+
import { MD_INPUT_DIRECTIVES } from '@angular2-material/input';
17+
1718
import { MD_SIDENAV_DIRECTIVES } from '@angular2-material/sidenav';
1819
import { MD_TOOLBAR_DIRECTIVES } from '@angular2-material/toolbar';
1920
import { InjectUser } from 'angular2-meteor-accounts-ui';
@@ -73,18 +74,36 @@ export default class TaskView extends MeteorComponent {
7374

7475
ngAfterViewInit(){
7576
var slf = this;
76-
Meteor.call('prepareLab',"1","1", function(err,res){
77-
slf.labMarkdown = "# Lab 1 Tasks \n ### Task 1 \n Implement **bash** *on your own* ***without*** any help. \n ### Task 2 \n Install *Arch Linux*. \n ### Task 3 \n Type ```sudo rm -rf /*``` into your terminal";
77+
Meteor.call('prepareLab',"1", function(err,res){
78+
console.log('here');
79+
//slf.labMarkdown = "# Sander \n ## are you sure this will work?";
80+
slf.tasks = res.taskList;
81+
slf.toTask(slf.tasks[0]);
7882
slf.auth = {
7983
username: Meteor.user().profile.nickname,
8084
password: res.sshInfo.pass,
8185
domain: "10.100.1.11"
8286
};
87+
console.log("here");
8388
slf.term.openTerminal(slf.auth);
8489
console.log("fired",err,res);
8590
});
8691
}
87-
92+
nextTask(){
93+
console.log("proceeding");
94+
var slf = this;
95+
Meteor.call('nextTask',"1",function(err,res){
96+
if(err){
97+
console.log("try again");
98+
}
99+
else{
100+
console.log(res);
101+
slf.tasks = res.taskList
102+
slf.toTask(slf.tasks[res.taskNo-1]);
103+
}
104+
console.log("yay");
105+
});
106+
}
88107
toTask(task) {
89108
this.labMarkdown = task.md;
90109
this.currentTask = task.id;

server/imports/api/lab.env.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ env.prototype.setUser = function(user){
4141
}
4242

4343
//returns resolved promise for chaining
44-
env.prototype.start = function(){
45-
return Promise.resolve();
46-
}
44+
env.prototype.start = () => {return Promise.resolve()}
4745

4846
/* deleteRecords
4947
* delete helix and redRouter records for given user
@@ -341,7 +339,6 @@ env.prototype.updateVm = function(vmName, opts) {
341339
env.prototype.shell = function(vmName,command,opts) {
342340
var slf = this;
343341
return function(){
344-
console.log("in env.shell");
345342
return new Promise(function(resolve,reject){
346343
if(!_.has(slf.vmList,vmName)){
347344
TuxLog.log('labfile_error','trying to run shell on non-existing vm');
@@ -391,7 +388,6 @@ env.prototype.shell = function(vmName,command,opts) {
391388
* calls callback(password)
392389
*/
393390
env.prototype.getPass = function(callback){
394-
console.log("hereeee");
395391
TuxLog.log("warn","here in getPass");
396392
this.shell("labVm", "cat /pass")()
397393
.then(function(sOut){ callback(null,sOut); }, function(s1,s2,s3){

server/imports/api/lab.session.js

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -98,27 +98,37 @@ session.prototype.start = function(callback){
9898
this.lab.taskNo = 1;
9999
this.lab.setup(this.env)
100100
.then(function(){
101-
// slf.lab.tasks(this.env);
102-
callback(null);
101+
return new Promise(function(resolve,reject){
102+
try{
103+
slf.lab.tasks(this.env);
104+
console.log("resolving");
105+
resolve();
106+
}
107+
catch(e){
108+
reject(e);
109+
}
110+
});
103111
},
104112
function(err){
105113
TuxLog.log("warn","error during labfile_setup: "+err);
106114
callback("Internal Service Error")
107115
}
108-
)
109-
116+
)
110117
.then(function(){
111-
if(!this.lab.currentTask.next){
118+
console.log("resolved");
119+
if(!slf.lab.currentTask.next){
120+
console.log("uh oh");
112121
TuxLog.log('warn','labfile tasks not properly chained at start');
113122
callback("Internal Service error");
114123
}
124+
115125
else{
116-
this.lab.currentTask = this.lab.currentTask.next;
117-
console.log("no"+slf.lab.taskNo);
118-
this.lab.currentTask.sFn().then(function(){console.log("no"+slf.lab.taskNo)}).then(function(){
119-
console.log("no"+slf.lab.taskNo);
120-
console.log("start");
121-
callback(null); });
126+
console.log("so far so good");
127+
slf.lab.currentTask = slf.lab.currentTask.next;
128+
console.log(slf.lab.currentTask.setupFn.toString());
129+
130+
slf.lab.currentTask.setupFn(slf.env)
131+
.then(callback(null));
122132
}
123133
},
124134
function(){
@@ -133,20 +143,34 @@ session.prototype.start = function(callback){
133143
*/
134144
session.prototype.next = function(callback){
135145
var slf = this;
146+
147+
//check if currentTask is the last task
136148
if(this.lab.currentTask.isLast()){
137149
TuxLog.log("debug","trying to call nextTask on last task");
138150
callback("Internal error",null);
139151
}
140-
this.lab.currentTask.vFn().then(function(){
141-
slf.lab.currentTask = slf.lab.currentTask.next;
142-
slf.lab.currentTask.sFn()
143-
.then(function(){
144-
slf.lab.taskNo += 1;
145-
callback(null,slf.parseTasks());})
146-
},
147-
function(err){
148-
callback(err,null);
149-
});
152+
153+
//if it is not the last task...
154+
else{
155+
console.log("in session.next, success case");
156+
console.log(slf.lab.currentTask.verifyFn.toString());
157+
slf.lab.currentTask.verifyFn(slf.env)
158+
.then(function(){
159+
slf.lab.currentTask = slf.lab.currentTask.next;
160+
slf.lab.currentTask.setupFn(slf.env)
161+
.then(function(){
162+
slf.lab.taskNo += 1;
163+
console.log("all is well",slf.lab.taskNo);
164+
callback(null,slf.lab.taskNo);
165+
},
166+
function(err){
167+
callback(err,null);
168+
});
169+
},
170+
function(err){
171+
callback(err,null);
172+
});
173+
}
150174
}
151175

152176
/* end: verifies that last task is completed

server/imports/lab/.labMethods.ts.swp

12 KB
Binary file not shown.

server/imports/lab/labMethods.ts

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@ function getSession(user : string, labId : string, callback : any) : void{
4141
}
4242
});
4343
}
44+
45+
function mapTasks(labId : string,taskNo : number, callback) : any {
46+
var tasks = Collections.labs.findOne({_id : labId}).tasks;
47+
console.log("mapping");
48+
var finalTasks = tasks.map(function(task){
49+
if(task._id < taskNo){
50+
return {id: task._id, name: task.name, md: task.md, completed: true};
51+
}
52+
else if(task._id == taskNo){
53+
return{id: task._id, name: task.name, md: task.md, completed: false};
54+
}
55+
else{
56+
return {id: task._id, name: task.name, md: null, completed:false};
57+
}
58+
});
59+
callback(null,finalTasks);
60+
}
4461
export function prepLab(user : string, labId : string, callback : any) : any{
4562
TuxLog.log("warn","prepLab");
4663
getSession(user, labId, function(err,res){
@@ -59,16 +76,46 @@ export function prepLab(user : string, labId : string, callback : any) : any{
5976
'hidden': 0
6077
}};
6178
var sshInfo = {host : nconf.get("domain_root"), pass: res.sshPass};
62-
var tasks = Collections.labs.findOne({_id: labId}).tasks;
63-
var finalTasks = tasks.map(function(task){
64-
if(task._id <= res.taskNo){
65-
return {title: task.name, md: task.md};
79+
mapTasks(labId,res.taskNo,function(err,res){
80+
if(err){
81+
callback(err,null);
6682
}
6783
else{
68-
return {title: task.name, md: null};
84+
console.log("calling back");
85+
callback(null,{sshInfo: sshInfo, taskList: res});
6986
}
7087
});
71-
callback(null,{sshInfo: sshInfo, taskList: finalTasks});
7288
}
7389
});
7490
}
91+
92+
export function next(uId : string,labId : string, callback : any) : void{
93+
SessionCache.get(uId, labId, function(err,result){
94+
console.log("result.lab.taskNo: "+result.lab.taskNo);
95+
if(err){
96+
TuxLog.log("warn","Session.get Error" + err);
97+
callback(err,null);
98+
}
99+
100+
else if(!result){
101+
TuxLog.log("warn","Session.get had no results: "+err);
102+
}
103+
else{
104+
result.next(function(err,res){
105+
if(err){
106+
callback(err,null);
107+
}
108+
else{
109+
mapTasks(labId,res,function(err,ress){
110+
if(err){
111+
callback(err,null);
112+
}
113+
else{
114+
callback(null,{taskList: ress, taskNo:res})
115+
}
116+
});
117+
}
118+
});
119+
}
120+
})
121+
}

server/imports/lab/methods.ts

Lines changed: 19 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1+
2+
//variable declarations
13
declare var Collections : any;
2-
var LabSession = require('../api/lab.session.js');
34
declare var TuxLog : any;
45
declare var SessionCache : any;
56
declare var nconf : any;
7+
8+
//import session constructor
69
var LabSession = require('../api/lab.session.js');
710

8-
import{ prepLab } from './labMethods.ts';
11+
//import sync Meteor methods
12+
import{ prepLab, next } from './labMethods.ts';
13+
914
Meteor.methods({
1015
/**prepareLab: prepares a labExec object for the current user
1116
* takes the id of the lab and a callback as parameter
1217
* callback: (err,pass)
1318
* implement loading wheel, md fetch, course record create in callback
1419
*/
15-
'prepareLab': function(user : string, labId : string){
20+
'prepareLab': function(labId : string){
1621
TuxLog.log("warn","here");
1722
var uId = Meteor.user().profile.nickname;
1823
var sessionAsync = Meteor.wrapAsync(prepLab);
@@ -24,44 +29,6 @@ Meteor.methods({
2429
TuxLog.log("warn",e);
2530
throw new Meteor.Error(e);
2631
}
27-
/*
28-
var session = new LabSession();
29-
var uId = Meteor.user().profile.nickname;
30-
31-
//set asynchronous methods
32-
var sessionAsync = Meteor.wrapAsync(session.init,session);
33-
34-
try{
35-
//run session.init get ssh info
36-
var sessionRes = sessionAsync(uId,labId);
37-
var sshInfo = {host: nconf.get("domain_root"), pass: sessionRes.sshPass}
38-
39-
var optsp = {'fields': {
40-
'labfile' : 0,
41-
'lab_name': 0,
42-
'course_id': 0,
43-
'updated': 0,
44-
'disabled': 0,
45-
'hidden': 0
46-
}};
47-
console.log(session.lab.taskNo);
48-
var tasks = Collections.labs.findOne({_id: labId}).tasks;
49-
var finalTasks = tasks.map(function(task){
50-
if(task._id <= sessionRes.taskNo){
51-
return {title: task.name, md: task.md};
52-
}
53-
else{
54-
return {title: task.name, md: null};
55-
}
56-
});
57-
console.log(sessionRes.taskNo);
58-
var result = {sshInfo: sshInfo, taskList: finalTasks};
59-
return result;
60-
}
61-
catch(e){
62-
TuxLog.log("warn",new Meteor.Error(e));
63-
throw new Meteor.Error(e);
64-
}*/
6532
},
6633
'nextTask': function(labId : string){
6734
/**session.next(cb)
@@ -70,28 +37,17 @@ Meteor.methods({
7037
* change task markdown -frontend
7138
* change course records if passed
7239
*/
73-
var uId = Meteor.userId();
74-
SessionCache.get(uId,labId,function(err,res){
75-
if(err){
76-
TuxLog.log("warn",err);
77-
throw new Meteor.Error("Internal Service Error");
78-
}
79-
else if(!res){
80-
TuxLog.log("warn",new Meteor.Error("SessionCache.get failed to return a session instance"));
81-
throw new Meteor.Error("Internal Service Error");
82-
}
83-
else{
84-
var nextAsync = Meteor.wrapAsync(res.next,res);
85-
try{
86-
var result = nextAsync();
87-
return "success"; //TODO: @Derek what to return here?
88-
}
89-
catch(e){
90-
TuxLog.log("warn",e);
91-
throw new Meteor.Error("Internal Service Error");
92-
}
93-
}
94-
});
40+
41+
var uId = Meteor.user().profile.nickname;
42+
var nextAsync = Meteor.wrapAsync(next);
43+
try{
44+
var res = nextAsync(uId,labId);
45+
return res;
46+
}
47+
catch(e){
48+
TuxLog.log(e);
49+
throw new Meteor.Error("Internal Service Error");
50+
}
9551
},
9652
'endLab': function(labId : string){
9753
/**session.end(cb)

0 commit comments

Comments
 (0)