Skip to content

Fixes to task Proceed and labview #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 74 commits into from
Jul 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
c8f5ae2
issue 32 fixed
cemersoz Jul 7, 2016
71179a9
removed swp
cemersoz Jul 7, 2016
65884ce
Merge branch 'master' of https://github.com/cemersoz/tuxlab-app
cemersoz Jul 7, 2016
9c68e12
fixed nconf issues
cemersoz Jul 7, 2016
4c41fd4
issue 82, 84 fixes
cemersoz Jul 7, 2016
6bac2e2
fixed #82
cemersoz Jul 7, 2016
c41344e
Merge branch 'master' of https://github.com/learnlinux/tuxlab-app
cemersoz Jul 7, 2016
0498eb0
isse #77
cemersoz Jul 8, 2016
097ff58
fixed tests
cemersoz Jul 8, 2016
30ee6c2
fixed files
cemersoz Jul 8, 2016
e156b44
fixed tests master
cemersoz Jul 8, 2016
c6525e0
merged with master'
cemersoz Jul 8, 2016
e9052be
fixed comment
cemersoz Jul 8, 2016
528fb7d
moved validator
cemersoz Jul 8, 2016
e9f46e2
removed duplicate file
cemersoz Jul 8, 2016
a511006
fixed tests, removed duplicate underscore, publish
cemersoz Jul 8, 2016
dbd424a
merged with master
cemersoz Jul 11, 2016
7cca5d3
changes
cemersoz Jul 14, 2016
7b1f48d
merged with master
cemersoz Jul 14, 2016
d6c8c4a
fixed methods.ts import
cemersoz Jul 14, 2016
3db2e47
fixed issues w methods
cemersoz Jul 14, 2016
719224f
fixes
cemersoz Jul 14, 2016
161838b
renamed, fixed api, meteor.methods explanation
cemersoz Jul 14, 2016
fed186e
minor fixes
cemersoz Jul 14, 2016
39e8e38
A
cemersoz Jul 15, 2016
f206ca2
half-merge
cemersoz Jul 15, 2016
cb8412b
Merge branch 'master' of https://github.com/learnlinux/tuxlab-app
cemersoz Jul 15, 2016
ddf5730
api changes
cemersoz Jul 15, 2016
ae5c30a
merged with master/requires-infra
cemersoz Jul 15, 2016
e07f9f6
merged with requires-infra
cemersoz Jul 15, 2016
7fd5d14
fixed api
cemersoz Jul 15, 2016
eb95338
merged
cemersoz Jul 15, 2016
0b5ef75
comments
cemersoz Jul 15, 2016
f0cf529
minor changes
cemersoz Jul 15, 2016
0f77939
merged with requires-infra
cemersoz Jul 15, 2016
dcf2317
minor fixes
cemersoz Jul 15, 2016
574d273
api changes (#126)
cemersoz Jul 15, 2016
7a86b9e
Merge branch 'requires-infra' of https://github.com/learnlinux/tuxlab…
cemersoz Jul 15, 2016
9c7ab13
method implementations
cemersoz Jul 15, 2016
2b653aa
before merge
cemersoz Jul 17, 2016
8921f1c
merged
cemersoz Jul 17, 2016
ee6d515
removed testing change
cemersoz Jul 17, 2016
97d1492
fixed typo
cemersoz Jul 17, 2016
461c6ea
fixed prepareLab
invalid-email-address Jul 18, 2016
d8df9f7
merged
invalid-email-address Jul 18, 2016
4e15bf9
removed test methods
cemersoz Jul 18, 2016
64c3179
fix prepareLab
invalid-email-address Jul 18, 2016
cc69eda
methods changes
cemersoz Jul 19, 2016
d36b825
merge and methods changes
cemersoz Jul 19, 2016
1f67feb
removed swap file
cemersoz Jul 19, 2016
481ac16
merged with master
cemersoz Jul 19, 2016
6aeecf5
fixed merge
cemersoz Jul 19, 2016
ada5cbd
fixes
invalid-email-address Jul 19, 2016
2483bba
Merge branch 'master' of https://github.com/learnlinux/tuxlab-app
invalid-email-address Jul 19, 2016
d445926
prepareLab WORKS
invalid-email-address Jul 20, 2016
ea90ac4
merged
invalid-email-address Jul 20, 2016
8b9cbbb
further fixes
invalid-email-address Jul 20, 2016
aac86b2
Merge branch 'master' of https://github.com/learnlinux/tuxlab-app
invalid-email-address Jul 20, 2016
6bb29d7
Merge branch 'master' of https://github.com/learnlinux/tuxlab-app
invalid-email-address Jul 20, 2016
c07c6a1
Merge branch 'master' of https://github.com/learnlinux/tuxlab-app
invalid-email-address Jul 20, 2016
7b54c86
Merge branch 'master' of https://github.com/learnlinux/tuxlab-app
invalid-email-address Jul 20, 2016
6f20115
merge
invalid-email-address Jul 20, 2016
3c90352
all works
invalid-email-address Jul 20, 2016
3763331
deleted debug line
invalid-email-address Jul 20, 2016
9cbe003
fixed minor excess code
invalid-email-address Jul 20, 2016
a4866a0
minor indentation fix
invalid-email-address Jul 20, 2016
c96e7a4
reference fixes
invalid-email-address Jul 21, 2016
0594b7d
fixes to nextTask
invalid-email-address Jul 21, 2016
03471ee
merged
invalid-email-address Jul 21, 2016
c8a20f3
merged with master
invalid-email-address Jul 21, 2016
ecf54d1
merged with master
invalid-email-address Jul 21, 2016
73aaefa
minor changes
invalid-email-address Jul 21, 2016
de776e0
fixed merge problems
invalid-email-address Jul 21, 2016
508d1a6
fixed md view and swithces
invalid-email-address Jul 22, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions client/imports/ui/pages/lab/taskview.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<!--Markdown View-->
<div class="tuxlab-taskview-step">


<md-sidenav-layout>
<md-sidenav #left [opened]="false" layout-padding>
Expand Down Expand Up @@ -42,7 +41,7 @@
<p>Checking Task...</p>
<md-dialog-actions ok="Fine"></md-dialog-actions>
</md-dialog>
<button md-raised-button (click)="alert.show()">
<button md-raised-button (click)="nextTask()">
Check
<md-icon fontIcon="tuxicon-tick"></md-icon>
</button>
Expand Down
27 changes: 23 additions & 4 deletions client/imports/ui/pages/lab/taskview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import { MeteorComponent } from 'angular2-meteor';
import { OVERLAY_PROVIDERS } from '@angular2-material/core/overlay/overlay';
import { MATERIAL_PROVIDERS, MATERIAL_DIRECTIVES } from 'ng2-material';
import { MD_INPUT_DIRECTIVES } from '@angular2-material/input';
import { MD_INPUT_DIRECTIVES } from '@angular2-material/input';

import { MD_SIDENAV_DIRECTIVES } from '@angular2-material/sidenav';
import { MD_TOOLBAR_DIRECTIVES } from '@angular2-material/toolbar';
import { InjectUser } from 'angular2-meteor-accounts-ui';
Expand Down Expand Up @@ -73,18 +74,36 @@ export default class TaskView extends MeteorComponent {

ngAfterViewInit(){
var slf = this;
Meteor.call('prepareLab',"1","1", function(err,res){
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";
Meteor.call('prepareLab',"1", function(err,res){
console.log('here');
//slf.labMarkdown = "# Sander \n ## are you sure this will work?";
slf.tasks = res.taskList;
slf.toTask(slf.tasks[0]);
slf.auth = {
username: Meteor.user().profile.nickname,
password: res.sshInfo.pass,
domain: "10.100.1.11"
};
console.log("here");
slf.term.openTerminal(slf.auth);
console.log("fired",err,res);
});
}

nextTask(){
console.log("proceeding");
var slf = this;
Meteor.call('nextTask',"1",function(err,res){
if(err){
console.log("try again");
}
else{
console.log(res);
slf.tasks = res.taskList
slf.toTask(slf.tasks[res.taskNo-1]);
}
console.log("yay");
});
}
toTask(task) {
this.labMarkdown = task.md;
this.currentTask = task.id;
Expand Down
6 changes: 1 addition & 5 deletions server/imports/api/lab.env.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ env.prototype.setUser = function(user){
}

//returns resolved promise for chaining
env.prototype.start = function(){
return Promise.resolve();
}
env.prototype.start = () => {return Promise.resolve()}

/* deleteRecords
* delete helix and redRouter records for given user
Expand Down Expand Up @@ -341,7 +339,6 @@ env.prototype.updateVm = function(vmName, opts) {
env.prototype.shell = function(vmName,command,opts) {
var slf = this;
return function(){
console.log("in env.shell");
return new Promise(function(resolve,reject){
if(!_.has(slf.vmList,vmName)){
TuxLog.log('labfile_error','trying to run shell on non-existing vm');
Expand Down Expand Up @@ -391,7 +388,6 @@ env.prototype.shell = function(vmName,command,opts) {
* calls callback(password)
*/
env.prototype.getPass = function(callback){
console.log("hereeee");
TuxLog.log("warn","here in getPass");
this.shell("labVm", "cat /pass")()
.then(function(sOut){ callback(null,sOut); }, function(s1,s2,s3){
Expand Down
66 changes: 45 additions & 21 deletions server/imports/api/lab.session.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,37 @@ session.prototype.start = function(callback){
this.lab.taskNo = 1;
this.lab.setup(this.env)
.then(function(){
// slf.lab.tasks(this.env);
callback(null);
return new Promise(function(resolve,reject){
try{
slf.lab.tasks(this.env);
console.log("resolving");
resolve();
}
catch(e){
reject(e);
}
});
},
function(err){
TuxLog.log("warn","error during labfile_setup: "+err);
callback("Internal Service Error")
}
)

)
.then(function(){
if(!this.lab.currentTask.next){
console.log("resolved");
if(!slf.lab.currentTask.next){
console.log("uh oh");
TuxLog.log('warn','labfile tasks not properly chained at start');
callback("Internal Service error");
}

else{
this.lab.currentTask = this.lab.currentTask.next;
console.log("no"+slf.lab.taskNo);
this.lab.currentTask.sFn().then(function(){console.log("no"+slf.lab.taskNo)}).then(function(){
console.log("no"+slf.lab.taskNo);
console.log("start");
callback(null); });
console.log("so far so good");
slf.lab.currentTask = slf.lab.currentTask.next;
console.log(slf.lab.currentTask.setupFn.toString());

slf.lab.currentTask.setupFn(slf.env)
.then(callback(null));
}
},
function(){
Expand All @@ -133,20 +143,34 @@ session.prototype.start = function(callback){
*/
session.prototype.next = function(callback){
var slf = this;

//check if currentTask is the last task
if(this.lab.currentTask.isLast()){
TuxLog.log("debug","trying to call nextTask on last task");
callback("Internal error",null);
}
this.lab.currentTask.vFn().then(function(){
slf.lab.currentTask = slf.lab.currentTask.next;
slf.lab.currentTask.sFn()
.then(function(){
slf.lab.taskNo += 1;
callback(null,slf.parseTasks());})
},
function(err){
callback(err,null);
});

//if it is not the last task...
else{
console.log("in session.next, success case");
console.log(slf.lab.currentTask.verifyFn.toString());
slf.lab.currentTask.verifyFn(slf.env)
.then(function(){
slf.lab.currentTask = slf.lab.currentTask.next;
slf.lab.currentTask.setupFn(slf.env)
.then(function(){
slf.lab.taskNo += 1;
console.log("all is well",slf.lab.taskNo);
callback(null,slf.lab.taskNo);
},
function(err){
callback(err,null);
});
},
function(err){
callback(err,null);
});
}
}

/* end: verifies that last task is completed
Expand Down
Binary file added server/imports/lab/.labMethods.ts.swp
Binary file not shown.
59 changes: 53 additions & 6 deletions server/imports/lab/labMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ function getSession(user : string, labId : string, callback : any) : void{
}
});
}

function mapTasks(labId : string,taskNo : number, callback) : any {
var tasks = Collections.labs.findOne({_id : labId}).tasks;
console.log("mapping");
var finalTasks = tasks.map(function(task){
if(task._id < taskNo){
return {id: task._id, name: task.name, md: task.md, completed: true};
}
else if(task._id == taskNo){
return{id: task._id, name: task.name, md: task.md, completed: false};
}
else{
return {id: task._id, name: task.name, md: null, completed:false};
}
});
callback(null,finalTasks);
}
export function prepLab(user : string, labId : string, callback : any) : any{
TuxLog.log("warn","prepLab");
getSession(user, labId, function(err,res){
Expand All @@ -59,16 +76,46 @@ export function prepLab(user : string, labId : string, callback : any) : any{
'hidden': 0
}};
var sshInfo = {host : nconf.get("domain_root"), pass: res.sshPass};
var tasks = Collections.labs.findOne({_id: labId}).tasks;
var finalTasks = tasks.map(function(task){
if(task._id <= res.taskNo){
return {title: task.name, md: task.md};
mapTasks(labId,res.taskNo,function(err,res){
if(err){
callback(err,null);
}
else{
return {title: task.name, md: null};
console.log("calling back");
callback(null,{sshInfo: sshInfo, taskList: res});
}
});
callback(null,{sshInfo: sshInfo, taskList: finalTasks});
}
});
}

export function next(uId : string,labId : string, callback : any) : void{
SessionCache.get(uId, labId, function(err,result){
console.log("result.lab.taskNo: "+result.lab.taskNo);
if(err){
TuxLog.log("warn","Session.get Error" + err);
callback(err,null);
}

else if(!result){
TuxLog.log("warn","Session.get had no results: "+err);
}
else{
result.next(function(err,res){
if(err){
callback(err,null);
}
else{
mapTasks(labId,res,function(err,ress){
if(err){
callback(err,null);
}
else{
callback(null,{taskList: ress, taskNo:res})
}
});
}
});
}
})
}
82 changes: 19 additions & 63 deletions server/imports/lab/methods.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@

//variable declarations
declare var Collections : any;
var LabSession = require('../api/lab.session.js');
declare var TuxLog : any;
declare var SessionCache : any;
declare var nconf : any;

//import session constructor
var LabSession = require('../api/lab.session.js');

import{ prepLab } from './labMethods.ts';
//import sync Meteor methods
import{ prepLab, next } from './labMethods.ts';

Meteor.methods({
/**prepareLab: prepares a labExec object for the current user
* takes the id of the lab and a callback as parameter
* callback: (err,pass)
* implement loading wheel, md fetch, course record create in callback
*/
'prepareLab': function(user : string, labId : string){
'prepareLab': function(labId : string){
TuxLog.log("warn","here");
var uId = Meteor.user().profile.nickname;
var sessionAsync = Meteor.wrapAsync(prepLab);
Expand All @@ -24,44 +29,6 @@ Meteor.methods({
TuxLog.log("warn",e);
throw new Meteor.Error(e);
}
/*
var session = new LabSession();
var uId = Meteor.user().profile.nickname;

//set asynchronous methods
var sessionAsync = Meteor.wrapAsync(session.init,session);

try{
//run session.init get ssh info
var sessionRes = sessionAsync(uId,labId);
var sshInfo = {host: nconf.get("domain_root"), pass: sessionRes.sshPass}

var optsp = {'fields': {
'labfile' : 0,
'lab_name': 0,
'course_id': 0,
'updated': 0,
'disabled': 0,
'hidden': 0
}};
console.log(session.lab.taskNo);
var tasks = Collections.labs.findOne({_id: labId}).tasks;
var finalTasks = tasks.map(function(task){
if(task._id <= sessionRes.taskNo){
return {title: task.name, md: task.md};
}
else{
return {title: task.name, md: null};
}
});
console.log(sessionRes.taskNo);
var result = {sshInfo: sshInfo, taskList: finalTasks};
return result;
}
catch(e){
TuxLog.log("warn",new Meteor.Error(e));
throw new Meteor.Error(e);
}*/
},
'nextTask': function(labId : string){
/**session.next(cb)
Expand All @@ -70,28 +37,17 @@ Meteor.methods({
* change task markdown -frontend
* change course records if passed
*/
var uId = Meteor.userId();
SessionCache.get(uId,labId,function(err,res){
if(err){
TuxLog.log("warn",err);
throw new Meteor.Error("Internal Service Error");
}
else if(!res){
TuxLog.log("warn",new Meteor.Error("SessionCache.get failed to return a session instance"));
throw new Meteor.Error("Internal Service Error");
}
else{
var nextAsync = Meteor.wrapAsync(res.next,res);
try{
var result = nextAsync();
return "success"; //TODO: @Derek what to return here?
}
catch(e){
TuxLog.log("warn",e);
throw new Meteor.Error("Internal Service Error");
}
}
});

var uId = Meteor.user().profile.nickname;
var nextAsync = Meteor.wrapAsync(next);
try{
var res = nextAsync(uId,labId);
return res;
}
catch(e){
TuxLog.log(e);
throw new Meteor.Error("Internal Service Error");
}
},
'endLab': function(labId : string){
/**session.end(cb)
Expand Down