Skip to content

Commit 3cd7a90

Browse files
committed
Switch to localhost
Requires infra (#121) * Added Session Cache * Fixing Errors * Meteor.methods and api changes (#122) * 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 * Adding whitespace * INDENTATION * minor api changes (#123) * 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 * Changing tuxlab to lab object * 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 (#127) * 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 * Use routerLink for links, use child router for course page. (#129) * Updated Schemas * Load Screen * Loading Screen * publish subscribe and dynamic explore page * deleted swap file * publish subscribe * template fixes * added start for reactive publication * template issue * . * . * course_records publish * course_records reactively publish * revert meteor update * publish subscribe and lineheight for searchpage icons * fixed indentation and removed test file * indentation * indentation * Accounts page and fixed random erro * toolbar for mobile devices * toolbar * account.html fixes * Toolbar made responsive * Responsive toolbar fixes * created userlist component * course_records course_id validation * indentation * markdown * import changes * validation addition * Forms Module Deprecated Warning. Issue #110 * indentation * Use routerLink * course pages now uses Child Routing * deleted LabData class Update release Fix async error Fix Lab Validator Fixing Session Constructor Fixed TaskView
1 parent 5c22110 commit 3cd7a90

File tree

18 files changed

+114
-89
lines changed

18 files changed

+114
-89
lines changed

.meteor/release

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

client/imports/ui/pages/course/mainview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
// Create Icon Font
5757
mdIconRegistry.registerFontClassAlias('tux', 'tuxicon');
5858
mdIconRegistry.setDefaultFontSetClass('tuxicon');
59-
59+
6060
// Subscribe to courses database and set current course
6161
this.subscribe('user-courses', this.courseNumber, () => {
6262
this.course = courses.findOne({ course_number: this.courseNumber });

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import { MarkdownView } from "../../components/markdown/markdown.ts";
1717

1818
// Meteor method imports
19-
// import { create_Lab } from "../../../lab/methods.ts"
19+
import "../../../lab/methods.ts"
2020

2121
// Define TaskView Component
2222
@Component({
@@ -29,7 +29,13 @@ export default class TaskView extends MeteorComponent {
2929
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";
3030
constructor() {
3131
super();
32-
//TODO This Doesn't Exist
33-
//Meteor.call('createLab',{courseId: "5",labId: 5},(err,res) => {console.log("fired",err,res)});
32+
33+
var response = function(err, res){
34+
console.log("Finished!", err, res);
35+
}
36+
37+
Meteor.call('prepareLab',{courseId: "1", labId: 1, callback: response}, function(err,res){
38+
console.log("fired",err,res);
39+
});
3440
}
3541
}

collections/labs.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { Roles } from './users.ts';
55
declare var _ : any;
66
var _ = require('underscore');
77

8-
declare var validateLab : any;
9-
108
export const labs : any = new Mongo.Collection('labs');
119

1210
/**
@@ -98,7 +96,8 @@ labs.allow({
9896

9997
/* LAB VALIDATOR */
10098
if(Meteor.isServer){
101-
var valdateLab : any = require('../server/imports/lab/checkLab.js');
99+
var validateLab : any = require('../server/imports/lab/checkLab.js');
100+
102101
Meteor.startup(function(){
103102
var LabValidator = function(userid, doc, fieldNames?, modifier?, options?){
104103
if (typeof fieldNames === "undefined"){

collections/users.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Meteor } from 'meteor/meteor';
55
SCHEMA
66
***/
77
declare var SimpleSchema: any;
8-
declare var nconf: any
8+
declare var nconf : any;
99

1010
if (Meteor.isServer){
1111
Meteor.startup(function(){
@@ -26,7 +26,6 @@ if (Meteor.isServer){
2626
},
2727
school: {
2828
type: String,
29-
optional: true,
3029
defaultValue: nconf.get('domain_school')
3130
},
3231
email: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"nconf": "^0.8.4",
4444
"ng2-material": "^0.5.0",
4545
"node-cache": "^3.2.1",
46-
"node-etcd": "^4.2.1",
46+
"node-etcd": "^5.0.3",
4747
"reflect-metadata": "0.1.2",
4848
"responsive-directives-angular2": "^0.3.0",
4949
"rxjs": "5.0.0-beta.6",

private/settings.domain.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"domain_root" : "cmu.tuxlab.org",
3-
"domain_school" : "Carnegie Mellon University"
3+
"domain_school" : "Carnegie Mellon"
44
}

private/settings.env.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
2+
"key_private" : "/etc/ssl/local/host.key",
3+
"key_public" : "/etc/ssl/local/host.key.pub",
4+
"key_ca" : "/etc/ssl/local/host.key.ca",
5+
26
"swarm_node_ip": "10.100.1.10",
37
"swarm_node_port": "4000",
48

server/imports/api/lab.env.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ env.prototype.removeVm = function (vmName,opts) {
276276
return function(){
277277
return new Promise(function(resolve,reject){
278278

279-
//check if container initialized
279+
//check if container initialized
280280
if(!_.has(this.vmList,vmName)){
281281
TuxLog.log('labfile_error',"trying to delete non-existing vm");
282282
reject("Internal error");

server/imports/api/lab.session.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ var session = function(){
55
this.env = require('./lab.env.js');
66
};
77

8-
98
session.prototype.env = null;
109
session.prototype.lab = null;
1110
/* init: pulls labFile and initializes session object from it

server/imports/course/methods.ts

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,6 @@
1-
var async = require ('async');
2-
var future = require('fibers/future');
3-
import { courses } from '../../../collections/courses.ts';
1+
import { Meteor } from 'meteor/meteor';
2+
import { course_search } from './search.ts'
43

54
Meteor.methods({
6-
'search_courses': function(text : string, results_per_page : number, page_no : number) {
7-
let search_pattern = new RegExp(text, "i");
8-
if(results_per_page <= 0 || results_per_page > 200) {
9-
results_per_page = 200;
10-
}
11-
return courses.find({
12-
$and: [
13-
{ hidden: false },
14-
{
15-
$or: [
16-
{ course_number: search_pattern },
17-
{ $where: "this.course_number.replace(/[ .-]/g,'') == '"+text+"'" },
18-
{ course_name: search_pattern }
19-
]
20-
}
21-
]
22-
}, {
23-
limit: results_per_page,
24-
skip: (page_no - 1) * results_per_page
25-
}).fetch();
26-
27-
/*
28-
let search_options = {
29-
limit: results_per_page,
30-
skip: [ results_per_page, page_no ],
31-
fields: {
32-
course_number: 1,
33-
course_name: 1,
34-
course_description: 1,
35-
instructor_name: 1
36-
}
37-
};
38-
let result = new future();
39-
async.parallel({
40-
"course_count": function(callback) {
41-
callback(null, courses.find(search_object).count());
42-
},
43-
"course_results": function(callback) {
44-
callback(null, courses.find(search_object, search_options).fetch());
45-
}
46-
}, function(err, res) {
47-
if(err) {
48-
res.throw(err);
49-
}
50-
else {
51-
res.return(res);
52-
}
53-
});
54-
return result.wait();
55-
*/
56-
}
5+
'search_courses': Meteor.wrapAsync(course_search)
576
});

server/imports/course/search.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
var async = require ('async');
2+
3+
/**
4+
Searches Courses based on search terms
5+
**/
6+
export function course_search(text : string, results_per_page : number, page_no : number, callback : any) {
7+
8+
var courses = Collections.courses;
9+
10+
var search_pattern = new RegExp(text,"i");
11+
if (results_per_page <= 0 || results_per_page > 200) results_per_page = 200;
12+
13+
var search_object =
14+
{$and : [
15+
{"hidden" : false},
16+
{$or : [
17+
{"course_number" : search_pattern},
18+
{$where: "this.course_number.replace(/[ .-]/g,'') == '"+text+"'"},
19+
{"course_name" : search_pattern}
20+
]}
21+
]};
22+
23+
var search_options =
24+
{limit : results_per_page,
25+
skip : [results_per_page, page_no],
26+
fields : {
27+
"course_number" : 1,
28+
"course_name" : 1,
29+
"instructor_ids" : 1,
30+
"course_description" : 1}
31+
};
32+
33+
async.parallel(
34+
{
35+
"course_count" : function(callback) {callback(null, courses.find(search_object).count());},
36+
"course_results" : function(callback) {callback(null, courses.find(search_object, search_options).fetch());}
37+
},
38+
function(err, results) {
39+
if(err){
40+
callback(err);
41+
}
42+
else{
43+
callback(results);
44+
}
45+
});
46+
47+
}

server/imports/lab/cache.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,22 @@ var NodeCache = require('node-cache');
2323
})
2424

2525
// Create ETCD Cache
26-
etcd.mkdir('/tuxlab/sessions', function(err){
26+
async.series([
27+
function(callback){
28+
etcd.mkdir('tuxlab', function(err){
29+
if(err && err.errorCode !== 105 && err.errorCode !== 102)
30+
callback(err);
31+
});
32+
},
33+
function(callback){
34+
etcd.mkdir('tuxlab/sessions', function(err){
35+
if(err && err.errorCode !== 105 && err.errorCode !== 102)
36+
callback(err);
37+
});
38+
}
39+
], function(err){
2740
if(err){
28-
TuxLog.log('warn', "Couldn't create sessions dir in ETCD");
41+
TuxLog.log('warn', err);
2942
}
3043
});
3144

server/imports/lab/methods.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
declare var Collections : any;
2-
var LabSession = require('../api/lab.session.js');
32
declare var TuxLog : any;
4-
declare var SessionCache : any;
5-
Meteor.methods({
3+
declare var SessionCache : any;
64

5+
var LabSession = require('../api/lab.session.js');
6+
7+
Meteor.methods({
78
/**prepareLab: prepares a labExec object for the current user
89
* takes the id of the lab and a callback as parameter
910
* callback: (err,pass)
1011
* implement loading wheel, md fetch, course record create in callback
1112
*/
1213
'prepareLab': function(user : string, labId : string,callback : any){
13-
var session = LabSession();
14+
var session = new LabSession();
1415
var uId = Meteor.userId();
1516
session.init(uId,labId,callback);
16-
17-
return uId;
1817
},
1918
'nextTask': function(labId : string, callback : any){
2019
/**session.next(cb)

server/imports/startup/etcd.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
/*
22
Initializes ETCD Connection
33
*/
4+
var fs = require('fs');
45

56
// Get Address
6-
var etcd_address = nconf.get('etcd_node_ip')+':'+nconf.get('etcd_node_port');
7+
var etcd_address = ["localhost:2379"];
78

89
// Get Auth
9-
var etcd_auth = {
10-
user: nconf.get('etcd_user'),
11-
password: nconf.get('etcd_pass')
10+
var etcd_options;
11+
if (nconf.get('etcd_user') !== null){
12+
etcd_options = {
13+
auth: {
14+
user: nconf.get('etcd_user'),
15+
pass: nconf.get('etcd_pass')
16+
}
17+
}
1218
}
1319

1420
// Start ETCD
1521
var Etcd = require('node-etcd');
16-
etcd = new Etcd(etcd_address,etcd_auth)
17-
18-
// Create TuxLab Dir
19-
etcd.mkdir("tuxlab", function(err){
20-
if(err){
21-
TuxLog.log("warn", err);
22-
}
23-
});
22+
etcd = new Etcd(etcd_address,etcd_options);

server/imports/startup/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ import './auth.js'
99

1010
// Start ETCD
1111
import './etcd.js'
12+
13+
// Start Meteor Methods
14+
import './methods.js'

server/imports/startup/methods.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
// Import Lab Meteor Methods
3+
import "../lab/methods.ts";
4+
5+
// Import Course Meteor Methods
6+
import "../course/methods.ts";

server/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@
3131
Collections.course_records = course_records;
3232

3333
/* LABS */
34-
import './imports/lab/index.js'
34+
//import Meteor Methods
35+
import './imports/lab/index.js'
36+
import './imports/course/index.js'

0 commit comments

Comments
 (0)