Skip to content

Commit 574d273

Browse files
cemersozDerekTBrown
authored andcommitted
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
1 parent 5ff3395 commit 574d273

File tree

7 files changed

+69
-43
lines changed

7 files changed

+69
-43
lines changed

collections/labs.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,18 @@ labs.allow({
103103
var LabValidator = function(userid, doc, fieldNames?, modifier?, options?){
104104
if (typeof fieldNames === "undefined"){
105105
if(!(doc.course_id && doc.file && //check for lab fields
106-
(Roles.isInstructorFor(doc.course_id,userid)) && //check for instructor authorization
107-
validateLab(doc.file))
108-
){ //check for labfile errors
109-
return false;
110-
}
106+
Roles.isInstructorFor(doc.course_id,userid))){//check for instructor authorization
107+
return false;
108+
}
109+
else{
110+
var titleList = validateLab(doc.file);
111+
if(!titleList){
112+
return false; }
113+
else{
114+
return titleList;
115+
}
116+
}
117+
111118
}
112119
else if(fieldNames.includes('tasks') && !fieldNames.includes('file')){
113120
return false;

server/imports/api/lab.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ lab.prototype.init = function(){
1717

1818
lab.prototype.currentTask = null;
1919
lab.prototype.taskList = [];
20+
lab.prototype.titleList = [];
2021
lab.prototype.setup;
2122
lab.prototype.tasks;
2223
lab.prototype.newTask = function(ttl, mdown,sFn, vFn, opt){
@@ -25,13 +26,13 @@ lab.prototype.newTask = function(ttl, mdown,sFn, vFn, opt){
2526
setupFn: sFn,
2627
verifyFn: vFn,
2728
opts: opt,
28-
markdown: mdown,
2929
title: ttl,
3030
next: null,
3131
completed: false,
3232
nextTask: function(tsk){
3333
this.next = tsk;
3434
this.prnt.taskList.push(tsk);
35+
this.prnt.titleList.push(tsk.title);
3536
return tsk;
3637
},
3738
isLast: function(){ return this.next === null; }

server/imports/api/lab.session.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace lab_exec {
22
interface labExec{
33
var env : any;
44
var tuxlab : any;
5-
function init(user : string, labId : number, callback : any)
5+
function init(user : string, labId : string, callback : any)
66
function parseTasks() : any
77
function start(callback : any) : any
88
function next(callback : any) : any

server/imports/api/lab.session.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,31 +45,42 @@ session.prototype.init = function(user,labId,callback){
4545
});
4646

4747
slf.lab.taskNo = 0;
48-
slf.env.getPass(callback);
48+
SessionCache.add(userid,labid,slf,function(err){
49+
if(err){
50+
callback(err,null);
51+
}
52+
else{
53+
slf.start(function(error){
54+
if(err){
55+
callback(err,null);
56+
}
57+
else{
58+
slf.env.getPass(callback);
59+
}
60+
});
61+
}
62+
});
4963
}
5064
else{
5165
// Get LabFile from Cache
5266
slf.lab.taskNo = 0;
5367
slf.lab = value;
54-
slf.env.getPass(callback);
68+
SessionCache.add(userid,labid,slf,function(err){
69+
if(err){
70+
callback(err,null);
71+
}
72+
else{
73+
slf.env.getPass(callback);
74+
}
75+
});
5576
}
5677
});
5778
}
5879
}
5980

60-
session.prototype.parseTasks = function(){
61-
var slf = this;
62-
return this.lab.taskList.map(function(task,i){
63-
if(i <= slf.lab.taskNo){
64-
return {title: task.title, markdown: task.markdown};
65-
}
66-
return {title: task.title, markdown: null};
67-
});
68-
}
69-
7081
/* start: runs setup and moves task header to first task
71-
* runs callback(err,res) on err if there is an error,
72-
* (null,parseTasks) no error
82+
* runs callback(err) on err if there is an error,
83+
* (null) no error
7384
*/
7485
session.prototype.start = function(callback){
7586
var slf = this;
@@ -79,10 +90,10 @@ session.prototype.start = function(callback){
7990
var tasks = this.lab.tasks(this.env);
8091
if(!this.lab.currentTask.next){
8192
TuxLog.log('labfile_error','labfile tasks not properly chained at start');
82-
callback("Internal error",null);
93+
callback("Internal error");
8394
}
8495
this.lab.currentTask = this.lab.currentTask.next;
85-
this.currentTask.sFn().then(function(){ callback(null,slf.parseTasks(0)); });
96+
this.currentTask.sFn().then(function(){ callback(null); });
8697
}
8798

8899
/* next: verifies that task is completed

server/imports/lab/cache.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ var NodeCache = require('node-cache');
3636
SessionCache._NodeCache.get(userid+'#'+labid, function(err, value){
3737
if(err){
3838
TuxLog.log('warn', "SessionCache NodeCache Error.");
39-
callback(null);
39+
callback(err,null);
4040
}
4141
else if(value !== undefined){
42-
callback(value);
42+
callback(null,value);
4343
}
4444
else{
4545
var data = etcd.get('/tuxlab/sessions/'+userid+'/'+labid, function(err, value){

server/imports/lab/checkLab.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ var tuxOrig = require('./lab.js');
66
module.exports = function(str){
77
if(!str) { return false; } //check for file import
88
var tux = eval(str);
9-
//var s = tuxlab;
10-
return ((typeof tux != "undefined") &&
11-
(typeof tux.setup === 'function') && //check for instructor field types
12-
(typeof tux.tasks === 'function') &&
13-
(tux.init.toString() === tuxOrig.init.toString()) && //check for unchanged
14-
(tux.newTask.toString() === tuxOrig.newTask.toString()));
9+
if(((typeof tux != "undefined") &&
10+
(typeof tux.setup === 'function') && //check for instructor field types
11+
(typeof tux.tasks === 'function') &&
12+
(typeof tux.tasks() != 'undefined') &&
13+
(tux.init.toString() === tuxOrig.init.toString()) && //check for unchanged
14+
(tux.newTask.toString() === tuxOrig.newTask.toString()))){
15+
return null;
16+
}
17+
else{
18+
return tux.titleList;
19+
}
1520
}

server/imports/lab/methods.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
declare var Collections : any;
2+
var LabSession = require('../api/lab.session.js');
23
declare var TuxLog : any;
3-
4-
var Session = require('../api/lab.session.js');
4+
declare var SessionCache : any;
55
Meteor.methods({
66

77
/**prepareLab: prepares a labExec object for the current user
88
* takes the id of the lab and a callback as parameter
99
* callback: (err,pass)
1010
* implement loading wheel, md fetch, course record create in callback
1111
*/
12-
'prepareLab': function(labId : number, callback : any){
13-
var session = Session();
12+
'prepareLab': function(user : string, labId : string,callback : any){
13+
var session = LabSession();
1414
var uId = Meteor.userId();
1515
session.init(uId,labId,callback);
1616
},
17-
'startLab': function(callback : any){
18-
/** somehow get session,
19-
* cache/ram/db/parameter
20-
* session.start(cb)
21-
* call startLab callback(err,res) in session.start cb
22-
*/
23-
},
24-
'nextTask': function(callback : any){
17+
'nextTask': function(labId : string, callback : any){
2518
/**session.next(cb)
2619
* cb(err,res) implement loading wheel here
2720
* call nextTask callback(err,res) in cb
2821
* change task markdown -frontend
2922
* change course records if passed
3023
*/
24+
var uId = Meteor.userId();
25+
SessionCache.get(uId,labId,function(err,res){
26+
if(err || !res){
27+
console.log("Internal Service Error");
28+
}
29+
else{
30+
31+
}
32+
});
3133
},
3234
'endLab': function(callback : any){
3335
/**session.end(cb)

0 commit comments

Comments
 (0)