From 7d4b64fb1bdbc1d312f80be61c9ca44cfdd0c818 Mon Sep 17 00:00:00 2001
From: Cliff Eby
Date: Sat, 23 Aug 2014 21:14:40 -0400
Subject: [PATCH 01/27] Adding Qas and Takers
---
gruntfile.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/gruntfile.js b/gruntfile.js
index ca48bbd883..a977357986 100644
--- a/gruntfile.js
+++ b/gruntfile.js
@@ -31,7 +31,7 @@ module.exports = function(grunt) {
clientViews: {
files: watchFiles.clientViews,
options: {
- livereload: true,
+ livereload: true
}
},
clientJS: {
@@ -59,7 +59,7 @@ module.exports = function(grunt) {
},
csslint: {
options: {
- csslintrc: '.csslintrc',
+ csslintrc: '.csslintrc'
},
all: {
src: watchFiles.clientCSS
From 6ecf6ff011b6b0f67abffdadcd9430a414a24654 Mon Sep 17 00:00:00 2001
From: Cliff Eby
Date: Sat, 23 Aug 2014 21:27:57 -0400
Subject: [PATCH 02/27] Adding Qas and Takers
---
app/models/qa.server.model.js | 133 +++++++++++++
app/models/taker.server.model.js | 174 ++++++++++++++++++
app/routes/qas.server.routes.js | 19 ++
app/routes/takers.server.routes.js | 19 ++
.../modules/qas/config/qas.client.config.js | 11 ++
.../modules/qas/config/qas.client.routes.js | 25 +++
.../qas/controllers/qas.client.controller.js | 164 +++++++++++++++++
public/modules/qas/qas.client.module.js | 4 +
.../qas/services/qas.client.service.js | 13 ++
.../qas/tests/qas.client.controller.test.js | 163 ++++++++++++++++
.../qas/views/create-qa.client.view.html | 98 ++++++++++
.../qas/views/edit-qa.client.view.html | 99 ++++++++++
.../qas/views/list-qas.client.view.html | 19 ++
.../qas/views/view-qa.client.view.html | 24 +++
.../takers/config/takers.client.config.js | 12 ++
.../takers/config/takers.client.routes.js | 27 +++
.../controllers/takers.client.controller.js | 85 +++++++++
.../takers/services/takers.client.service.js | 13 ++
public/modules/takers/takers.client.module.js | 4 +
.../tests/taker.client.controller.test.js | 58 ++++++
.../tests/takers.client.controller.test.js | 58 ++++++
.../views/create-taker.client.view.html | 23 +++
.../takers/views/edit-taker.client.view.html | 23 +++
.../takers/views/list-takers.client.view.html | 19 ++
public/modules/takers/views/take.html | 63 +++++++
.../takers/views/view-taker.client.view.html | 21 +++
26 files changed, 1371 insertions(+)
create mode 100644 app/models/qa.server.model.js
create mode 100644 app/models/taker.server.model.js
create mode 100644 app/routes/qas.server.routes.js
create mode 100644 app/routes/takers.server.routes.js
create mode 100644 public/modules/qas/config/qas.client.config.js
create mode 100644 public/modules/qas/config/qas.client.routes.js
create mode 100644 public/modules/qas/controllers/qas.client.controller.js
create mode 100644 public/modules/qas/qas.client.module.js
create mode 100644 public/modules/qas/services/qas.client.service.js
create mode 100644 public/modules/qas/tests/qas.client.controller.test.js
create mode 100644 public/modules/qas/views/create-qa.client.view.html
create mode 100644 public/modules/qas/views/edit-qa.client.view.html
create mode 100644 public/modules/qas/views/list-qas.client.view.html
create mode 100644 public/modules/qas/views/view-qa.client.view.html
create mode 100644 public/modules/takers/config/takers.client.config.js
create mode 100644 public/modules/takers/config/takers.client.routes.js
create mode 100644 public/modules/takers/controllers/takers.client.controller.js
create mode 100644 public/modules/takers/services/takers.client.service.js
create mode 100644 public/modules/takers/takers.client.module.js
create mode 100644 public/modules/takers/tests/taker.client.controller.test.js
create mode 100644 public/modules/takers/tests/takers.client.controller.test.js
create mode 100644 public/modules/takers/views/create-taker.client.view.html
create mode 100644 public/modules/takers/views/edit-taker.client.view.html
create mode 100644 public/modules/takers/views/list-takers.client.view.html
create mode 100644 public/modules/takers/views/take.html
create mode 100644 public/modules/takers/views/view-taker.client.view.html
diff --git a/app/models/qa.server.model.js b/app/models/qa.server.model.js
new file mode 100644
index 0000000000..d317777085
--- /dev/null
+++ b/app/models/qa.server.model.js
@@ -0,0 +1,133 @@
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+var mongoose = require('mongoose'),
+ Schema = mongoose.Schema;
+
+//
+// Answer Schema
+//
+var AnswerSchema = new mongoose.Schema({
+ text: String,
+ selectedAnswer: Boolean});
+/**
+ * Qa Schema
+ */
+var QaSchema = new Schema({
+ created: {
+ type: Date,
+ default: Date.now
+ },
+ question: {
+ type: String,
+ default: '',
+ trim: true
+ },
+ questionNumber: {
+ type: String,
+ default: '',
+ trim: true
+ },
+ imageURL: {
+ type: String,
+ default: '',
+ trim: true
+ },
+ choices: [AnswerSchema],
+ hint: {
+ type: String,
+ default: '',
+ trim: true
+ },
+ user: {
+ type: Schema.ObjectId,
+ ref: 'User'
+ },
+ difficulty: {
+ type: String,
+ default: 'Easy',
+ trim: true
+ },
+ type: {
+ type: String,
+ default: 'FIB',
+ trim: true
+ },
+ hintOn: {
+ type: Boolean,
+ default: false,
+ trim: true
+ },
+ timeOn: {
+ type: Boolean,
+ default: false,
+ trim: true
+ },
+ fifty50On: {
+ type: Boolean,
+ default: false,
+ trim: true
+ },
+ randomizeQuestionsOn: {
+ type: Boolean,
+ default: false,
+ trim: true
+ },
+ randomizeAnswersOn: {
+ type: Boolean,
+ default: false,
+ trim: true
+
+ }
+});
+
+//console.log(AnswerSchema);
+var QuizSchema = new Schema({
+ created: {
+ type: Date,
+ default: Date.now
+ },
+ name: {
+ type: String,
+ default: '',
+ trim: true
+ },
+ quizNumber: {
+ type: String,
+ default: '',
+ trim: true
+ },
+ category: {
+ type: String,
+ default: '',
+ trim: true
+ },
+ keyWords: {
+ type: String,
+ default: '',
+ trim: true
+ },
+ qas: [QaSchema]
+ });
+/**
+ * Validations
+ */
+QaSchema.path('question').validate(function(question) {
+ return question.length;
+}, 'Question cannot be blank');
+
+/**
+ * Statics
+ */
+QaSchema.statics = {
+ load: function(id, cb) {
+ this.findOne({
+ _id: id
+ }).populate('user', 'displayName').exec(cb);
+ }
+};
+//console.log(QaSchema);
+mongoose.model('Qa', QaSchema);
+mongoose.model('Answer', AnswerSchema);
\ No newline at end of file
diff --git a/app/models/taker.server.model.js b/app/models/taker.server.model.js
new file mode 100644
index 0000000000..e2f4db4dd1
--- /dev/null
+++ b/app/models/taker.server.model.js
@@ -0,0 +1,174 @@
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+var mongoose = require('mongoose'),
+ Schema = mongoose.Schema;
+ var takerAnswerSchema = new mongoose.Schema({
+ text: String,
+ correctAnswer: Boolean});
+/**
+ * QA Schema
+ */
+var takerQASchema = new Schema({
+ created: {
+ type: Date,
+ default: Date.now
+ },
+ question: {
+ type: String,
+ default: '',
+ trim: true
+ },
+ questionNumber: {
+ type: String,
+ default: '',
+ trim: true
+ },
+ imageURL: {
+ type: String,
+ default: '',
+ trim: true
+ },
+ choices: [takerAnswerSchema],
+ hint: {
+ type: String,
+ default: '',
+ trim: true
+ },
+ user: {
+ type: Schema.ObjectId,
+ ref: 'User'
+ },
+ difficulty: {
+ type: String,
+ default: 'Easy',
+ trim: true
+ },
+ type: {
+ type: String,
+ default: 'FIB',
+ trim: true
+ },
+ hintOn: {
+ type: Boolean,
+ default: false,
+ trim: true
+ },
+ timeOn: {
+ type: Boolean,
+ default: false,
+ trim: true
+ },
+ fifty50On: {
+ type: Boolean,
+ default: false,
+ trim: true
+ },
+ randomizeQuestionsOn: {
+ type: Boolean,
+ default: false,
+ trim: true
+ },
+ randomizeAnswersOn: {
+ type: Boolean,
+ default: false,
+ trim: true
+
+ }
+});
+
+
+/**
+ * Statics
+ */
+takerQASchema.statics = {
+ load: function(id, cb) {
+ this.findOne({
+ _id: id
+ }).populate('user', 'displayName').exec(cb);
+ }
+};
+//
+// AnswerCorrect Schema
+//
+var AnswerSelectedSchema = new mongoose.Schema({
+ text: String,
+ isSelected: Number});
+
+
+
+var TakerAnswersSchema = new Schema({
+ updated: {
+ type: Date,
+ default: Date.now
+ },
+ questionViewed: {
+ type: Boolean,
+ default: false
+ },
+ questionAnswered: {
+ type: Boolean,
+ default: false
+ },
+ questionNumber: {
+ type: String,
+ default: '',
+ trim: true
+ },
+ answer: [AnswerSelectedSchema]
+
+});
+
+//console.log(TakerResultsSchema);
+
+
+var TakerSchema = new Schema({
+ updated: {
+ type: Date,
+ default: Date.now
+ },
+
+ quizNumber: {
+ type: Number,
+ default: 0
+ },
+ trialNumber: {
+ type: Number,
+ default: 0
+ },
+ trialOptions: {
+ type: String,
+ default: '',
+ trim: true
+ },
+ results: [TakerAnswersSchema],
+ qa:[takerQASchema]
+
+});
+
+ //Validations
+
+//QASchema.path('question').validate(function(question) {
+// return question.length;
+//}, 'Question cannot be blank');
+
+
+ // Statics
+
+ TakerSchema.statics = {
+ load: function(id, cb) {
+ this.findOne({
+ _id: id
+ }).populate('user', 'displayName').exec(cb);
+ }
+};
+
+mongoose.model('takerQA', takerQASchema);
+mongoose.model('takerAnswer', takerAnswerSchema);
+mongoose.model('AnswerSelected', AnswerSelectedSchema);
+mongoose.model('TakerAnswers', TakerAnswersSchema);
+mongoose.model('Taker', TakerSchema);
+
+
diff --git a/app/routes/qas.server.routes.js b/app/routes/qas.server.routes.js
new file mode 100644
index 0000000000..68f1d840c5
--- /dev/null
+++ b/app/routes/qas.server.routes.js
@@ -0,0 +1,19 @@
+'use strict';
+//Routes...
+module.exports = function(app) {
+ var users = require('../../app/controllers/users');
+ var qas = require('../../app/controllers/qas');
+
+ // Qas Routes
+ app.route('/qas')
+ .get(qas.list)
+ .post(users.requiresLogin, qas.create);
+
+ app.route('/qas/:qaId')
+ .get(qas.read)
+ .put(users.requiresLogin, qas.hasAuthorization, qas.update)
+ .delete(users.requiresLogin, qas.hasAuthorization, qas.delete);
+
+ // Finish by binding the Qa middleware
+ app.param('qaId', qas.qaByID);
+};
\ No newline at end of file
diff --git a/app/routes/takers.server.routes.js b/app/routes/takers.server.routes.js
new file mode 100644
index 0000000000..1b26b0deed
--- /dev/null
+++ b/app/routes/takers.server.routes.js
@@ -0,0 +1,19 @@
+'use strict';
+
+module.exports = function(app) {
+ var users = require('../../app/controllers/users');
+ var takers = require('../../app/controllers/takers');
+
+ // Takers Routes
+ app.route('/takers')
+ .get(takers.list)
+ .post(users.requiresLogin, takers.create);
+
+ app.route('/takers/:takerId')
+ .get(takers.read)
+ .put(users.requiresLogin, takers.hasAuthorization, takers.update)
+ .delete(users.requiresLogin, takers.hasAuthorization, takers.delete);
+
+ // Finish by binding the Taker middleware
+ app.param('takerId', takers.takerByID);
+};
\ No newline at end of file
diff --git a/public/modules/qas/config/qas.client.config.js b/public/modules/qas/config/qas.client.config.js
new file mode 100644
index 0000000000..3d90803b75
--- /dev/null
+++ b/public/modules/qas/config/qas.client.config.js
@@ -0,0 +1,11 @@
+'use strict';
+
+// Configuring the Articles module.
+angular.module('qas').run(['Menus',
+ function(Menus) {
+ // Set top bar menu items
+ Menus.addMenuItem('topbar', 'Qas', 'qas', 'dropdown', '/qas(/create)?');
+ Menus.addSubMenuItem('topbar', 'qas', 'List Qas', 'qas');
+ Menus.addSubMenuItem('topbar', 'qas', 'New Qa', 'qas/create');
+ }
+]);
\ No newline at end of file
diff --git a/public/modules/qas/config/qas.client.routes.js b/public/modules/qas/config/qas.client.routes.js
new file mode 100644
index 0000000000..36457fb828
--- /dev/null
+++ b/public/modules/qas/config/qas.client.routes.js
@@ -0,0 +1,25 @@
+'use strict';
+
+//Setting up route...
+angular.module('qas').config(['$stateProvider',
+ function($stateProvider) {
+ // Qas state routing
+ $stateProvider.
+ state('listQas', {
+ url: '/qas',
+ templateUrl: 'modules/qas/views/list-qas.client.view.html'
+ }).
+ state('createQa', {
+ url: '/qas/create',
+ templateUrl: 'modules/qas/views/create-qa.client.view.html'
+ }).
+ state('viewQa', {
+ url: '/qas/:qaId',
+ templateUrl: 'modules/qas/views/view-qa.client.view.html'
+ }).
+ state('editQa', {
+ url: '/qas/:qaId/edit',
+ templateUrl: 'modules/qas/views/edit-qa.client.view.html'
+ });
+ }
+]);
\ No newline at end of file
diff --git a/public/modules/qas/controllers/qas.client.controller.js b/public/modules/qas/controllers/qas.client.controller.js
new file mode 100644
index 0000000000..bfea388c3f
--- /dev/null
+++ b/public/modules/qas/controllers/qas.client.controller.js
@@ -0,0 +1,164 @@
+'use strict';
+
+// Qas controller...
+angular.module('qas').controller('QasController', ['$scope', '$stateParams', '$location', 'Authentication', 'Qas',
+ function ($scope, $stateParams, $location, Authentication, Qas) {
+ $scope.authentication = Authentication;
+
+ // Create new Qa
+ $scope.typeDropdown = [
+ {
+ 'label': 'FIB',
+ 'value': 1
+ },
+ {
+ 'label': 'TF',
+ 'value': 2
+ },
+ {
+ 'label': 'MC',
+ 'value': 3
+ },
+ {
+ 'label': 'Matching',
+ 'value': 4
+ }
+ ];
+ $scope.difficultyDropdown = [
+ {
+ 'label': 'Easy',
+ 'value': 1
+ },
+ {
+ 'label': 'Medium',
+ 'value': 2
+ },
+ {
+ 'label': 'Hard',
+ 'value': 3
+ },
+ {
+ 'label': 'Impossible',
+ 'value': 4
+ }
+ ];
+
+
+ $scope.qa = new Qas({
+ question: '',
+ answer: '',
+ choices: [
+ { text: '', correctAnswer: false },
+ { text: '', correctAnswer: false}
+ ],
+ content: ''
+ });
+ //$scope.taker = new Taker({
+ // quizNumber: '9999'});
+ console.log('From Scope1 taker', $scope.taker);
+ $scope.qa.choices.correctAnswer;
+ // Create and validate qa entries
+ $scope.create = function () {
+ console.log("From QA CReate");
+ var qa = $scope.qa;
+ // Grab data from input boxes
+ qa.question = this.question;
+ qa.imageURL = this.imageURL;
+ qa.choices.text = [
+ { text: this.text },
+ { text: this.text }
+ ];
+ qa.content = this.content;
+ qa.hint = this.hint;
+ qa.hintOn = this.hintOn;
+ qa.timeOn = this.timeOn;
+ qa.fifty50On = this.fifty50On;
+ qa.randomizeQuestionsOn = this.randomizeQuestionsOn;
+ qa.randomizeAnswersOn = this.randomizeAnswersOn;
+
+ console.log('From qa 1', qa);
+ // Check that question was entered
+ console.log('qa.question.length', qa.question.length);
+ if (qa.question.length > 0) {
+ var choiceCount = 0;
+ //Loop through choices to get at least two
+ for (var i = 0, ln = qa.choices.length; i < ln; i++) {
+ var choice = qa.choices[i];
+ if (choice.text.length > 0) {
+ choiceCount++;
+ }
+ }
+ if (choiceCount > 1) {
+ // Call API to save to database
+ qa.$save(function (response) {
+ $location.path('qas/' + response._id);
+ });
+ } else {
+ alert('You must have at least two choices');
+ }
+ } else {
+ alert('You must have a question');
+ }
+ };
+
+ // Method to add an additional choice option
+ $scope.addChoice = function () {
+ $scope.qa.choices.push({ text: this.text, correctAnswer: false });
+ };
+
+ $scope.remove = function (qa) {
+ if (qa) {
+ qa.$remove();
+
+ for (var i in $scope.qas) {
+ if ($scope.qas[i] === qa) {
+ $scope.qas.splice(i, 1);
+ }
+ }
+ } else {
+ $scope.qa.$remove(function () {
+ $location.path('qas');
+ });
+ }
+ };
+
+ $scope.update = function () {
+ var qa = $scope.qa;
+ console.log('From update', qa);
+ if (!qa.updated) {
+ qa.updated = [];
+ }
+ qa.updated.push(new Date().getTime());
+
+ qa.$update(function () {
+ $location.path('qas/' + qa._id);
+ });
+ };
+
+ $scope.find = function () {
+ Qas.query(function (qas) {
+ $scope.qas = qas;
+ });
+ };
+
+ $scope.findOne = function () {
+ Qas.get({
+ qaId: $stateParams.qaId
+ }, function (qa) {
+ $scope.qa = qa;
+ });
+ };
+ $scope.deleteChoice = function (ev) {
+ var ss = ev.target.innerText.toString() - 1;
+ console.log(ss);
+ var qa = $scope.qa;
+ console.log(qa);
+ $scope.qa.choices.splice(ss, 1);
+ };
+
+ }
+
+
+
+]);
+
diff --git a/public/modules/qas/qas.client.module.js b/public/modules/qas/qas.client.module.js
new file mode 100644
index 0000000000..49cad3f2cc
--- /dev/null
+++ b/public/modules/qas/qas.client.module.js
@@ -0,0 +1,4 @@
+'use strict';
+
+// Use applicaion configuration module to register a new module
+ApplicationConfiguration.registerModule('qas');
\ No newline at end of file
diff --git a/public/modules/qas/services/qas.client.service.js b/public/modules/qas/services/qas.client.service.js
new file mode 100644
index 0000000000..f92714de09
--- /dev/null
+++ b/public/modules/qas/services/qas.client.service.js
@@ -0,0 +1,13 @@
+'use strict';
+
+//Qas service used to communicate Qas REST endpoints
+angular.module('qas').factory('Qas', ['$resource',
+ function($resource) {
+ return $resource('qas/:qaId', { qaId: '@_id'
+ }, {
+ update: {
+ method: 'PUT'
+ }
+ });
+ }
+]);
\ No newline at end of file
diff --git a/public/modules/qas/tests/qas.client.controller.test.js b/public/modules/qas/tests/qas.client.controller.test.js
new file mode 100644
index 0000000000..e841df9621
--- /dev/null
+++ b/public/modules/qas/tests/qas.client.controller.test.js
@@ -0,0 +1,163 @@
+'use strict';
+
+(function() {
+ // Qas Controller Spec
+ describe('Qas Controller Tests', function() {
+ // Initialize global variables
+ var QasController,
+ scope,
+ $httpBackend,
+ $stateParams,
+ $location;
+
+ // The $resource service augments the response object with methods for updating and deleting the resource.
+ // If we were to use the standard toEqual matcher, our tests would fail because the test values would not match
+ // the responses exactly. To solve the problem, we define a new toEqualData Jasmine matcher.
+ // When the toEqualData matcher compares two objects, it takes only object properties into
+ // account and ignores methods.
+ beforeEach(function() {
+ jasmine.addMatchers({
+ toEqualData: function(util, customEqualityTesters) {
+ return {
+ compare: function(actual, expected) {
+ return {
+ pass: angular.equals(actual, expected)
+ };
+ }
+ };
+ }
+ });
+ });
+
+ // Then we can start by loading the main application module
+ beforeEach(module(ApplicationConfiguration.applicationModuleName));
+
+ // The injector ignores leading and trailing underscores here (i.e. _$httpBackend_).
+ // This allows us to inject a service but then attach it to a variable
+ // with the same name as the service.
+ beforeEach(inject(function($controller, $rootScope, _$location_, _$stateParams_, _$httpBackend_) {
+ // Set a new global scope
+ scope = $rootScope.$new();
+
+ // Point global variables to injected services
+ $stateParams = _$stateParams_;
+ $httpBackend = _$httpBackend_;
+ $location = _$location_;
+
+ // Initialize the Qas controller.
+ QasController = $controller('QasController', {
+ $scope: scope
+ });
+ }));
+
+ it('$scope.find() should create an array with at least one Qa object fetched from XHR', inject(function(Qas) {
+ // Create sample Qa using the Qas service
+ var sampleQa = new Qas({
+ name: 'New Qa'
+ });
+
+ // Create a sample Qas array that includes the new Qa
+ var sampleQas = [sampleQa];
+
+ // Set GET response
+ $httpBackend.expectGET('qas').respond(sampleQas);
+
+ // Run controller functionality
+ scope.find();
+ $httpBackend.flush();
+
+ // Test scope value
+ expect(scope.qas).toEqualData(sampleQas);
+ }));
+
+ it('$scope.findOne() should create an array with one Qa object fetched from XHR using a qaId URL parameter', inject(function(Qas) {
+ // Define a sample Qa object
+ var sampleQa = new Qas({
+ name: 'New Qa'
+ });
+
+ // Set the URL parameter
+ $stateParams.qaId = '525a8422f6d0f87f0e407a33';
+
+ // Set GET response
+ $httpBackend.expectGET(/qas\/([0-9a-fA-F]{24})$/).respond(sampleQa);
+
+ // Run controller functionality
+ scope.findOne();
+ $httpBackend.flush();
+
+ // Test scope value
+ expect(scope.qa).toEqualData(sampleQa);
+ }));
+
+ it('$scope.create() with valid form data should send a POST request with the form input values and then locate to new object URL', inject(function(Qas) {
+ // Create a sample Qa object
+ var sampleQaPostData = new Qas({
+ name: 'New Qa'
+ });
+
+ // Create a sample Qa response
+ var sampleQaResponse = new Qas({
+ _id: '525cf20451979dea2c000001',
+ name: 'New Qa'
+ });
+
+ // Fixture mock form input values
+ scope.name = 'New Qa';
+
+ // Set POST response
+ $httpBackend.expectPOST('qas', sampleQaPostData).respond(sampleQaResponse);
+
+ // Run controller functionality
+ scope.create();
+ $httpBackend.flush();
+
+ // Test form inputs are reset
+ expect(scope.name).toEqual('');
+
+ // Test URL redirection after the Qa was created
+ expect($location.path()).toBe('/qas/' + sampleQaResponse._id);
+ }));
+
+ it('$scope.update() should update a valid Qa', inject(function(Qas) {
+ // Define a sample Qa put data
+ var sampleQaPutData = new Qas({
+ _id: '525cf20451979dea2c000001',
+ name: 'New Qa'
+ });
+
+ // Mock Qa in scope
+ scope.qa = sampleQaPutData;
+
+ // Set PUT response
+ $httpBackend.expectPUT(/qas\/([0-9a-fA-F]{24})$/).respond();
+
+ // Run controller functionality
+ scope.update();
+ $httpBackend.flush();
+
+ // Test URL location to new object
+ expect($location.path()).toBe('/qas/' + sampleQaPutData._id);
+ }));
+
+ it('$scope.remove() should send a DELETE request with a valid qaId and remove the Qa from the scope', inject(function(Qas) {
+ // Create new Qa object
+ var sampleQa = new Qas({
+ _id: '525a8422f6d0f87f0e407a33'
+ });
+
+ // Create new Qas array and include the Qa
+ scope.qas = [sampleQa];
+
+ // Set expected DELETE response
+ $httpBackend.expectDELETE(/qas\/([0-9a-fA-F]{24})$/).respond(204);
+
+ // Run controller functionality
+ scope.remove(sampleQa);
+ $httpBackend.flush();
+
+ // Test array after successful delete
+ expect(scope.qas.length).toBe(0);
+ }));
+ });
+}());
\ No newline at end of file
diff --git a/public/modules/qas/views/create-qa.client.view.html b/public/modules/qas/views/create-qa.client.view.html
new file mode 100644
index 0000000000..cf16d47edd
--- /dev/null
+++ b/public/modules/qas/views/create-qa.client.view.html
@@ -0,0 +1,98 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/public/modules/qas/views/edit-qa.client.view.html b/public/modules/qas/views/edit-qa.client.view.html
new file mode 100644
index 0000000000..a8e1077b04
--- /dev/null
+++ b/public/modules/qas/views/edit-qa.client.view.html
@@ -0,0 +1,99 @@
+
+
+
+
+
+
+
+
+
+
+ Add another
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/public/modules/qas/views/list-qas.client.view.html b/public/modules/qas/views/list-qas.client.view.html
new file mode 100644
index 0000000000..159210d967
--- /dev/null
+++ b/public/modules/qas/views/list-qas.client.view.html
@@ -0,0 +1,19 @@
+
\ No newline at end of file
diff --git a/public/modules/qas/views/view-qa.client.view.html b/public/modules/qas/views/view-qa.client.view.html
new file mode 100644
index 0000000000..6865bf5907
--- /dev/null
+++ b/public/modules/qas/views/view-qa.client.view.html
@@ -0,0 +1,24 @@
+
+
+
+
+
+ Updated on {{qa.created | date:'mediumDate'}} by {{qa.user.displayName}}
+
+
+ {{qa.question}}
+
+
+
{{choices.text}}
+
+
+
\ No newline at end of file
diff --git a/public/modules/takers/config/takers.client.config.js b/public/modules/takers/config/takers.client.config.js
new file mode 100644
index 0000000000..b5e11106e4
--- /dev/null
+++ b/public/modules/takers/config/takers.client.config.js
@@ -0,0 +1,12 @@
+'use strict';
+
+// Configuring the Takers module
+angular.module('takers').run(['Menus',
+ function(Menus) {
+ // Set top bar menu items
+ Menus.addMenuItem('topbar', 'Takers', 'takers', 'dropdown', '/takers(/create)?');
+ Menus.addSubMenuItem('topbar', 'takers', 'List Takers', 'takers');
+ Menus.addSubMenuItem('topbar', 'takers', 'New Taker', 'takers/create');
+ Menus.addSubMenuItem('topbar', 'takers', 'Take', 'takers/');
+ }
+]);
\ No newline at end of file
diff --git a/public/modules/takers/config/takers.client.routes.js b/public/modules/takers/config/takers.client.routes.js
new file mode 100644
index 0000000000..17d3d1be1d
--- /dev/null
+++ b/public/modules/takers/config/takers.client.routes.js
@@ -0,0 +1,27 @@
+'use strict';
+
+//Setting up route
+angular.module('takers').config(['$stateProvider',
+ function($stateProvider) {
+ // Takers state routing
+ $stateProvider.
+ state('listTakers', {
+ url: '/takers',
+ templateUrl: 'modules/takers/views/take.html'
+ }).
+
+ state('createTaker', {
+ url: '/takers/create',
+ templateUrl: 'modules/takers/views/create-taker.client.view.html'
+ }).
+
+ state('viewTaker', {
+ url: '/takers/:takerId',
+ templateUrl: 'modules/takers/views/view-taker.client.view.html'
+ }).
+ state('editTaker', {
+ url: '/takers/:takerId/edit',
+ templateUrl: 'modules/takers/views/edit-taker.client.view.html'
+ });
+ }
+]);
\ No newline at end of file
diff --git a/public/modules/takers/controllers/takers.client.controller.js b/public/modules/takers/controllers/takers.client.controller.js
new file mode 100644
index 0000000000..d79dcab075
--- /dev/null
+++ b/public/modules/takers/controllers/takers.client.controller.js
@@ -0,0 +1,85 @@
+'use strict';
+
+angular.module('takers').controller('TakersController', ['$scope', '$stateParams', '$location', 'Authentication', 'Articles',
+ function($scope, $stateParams, $location, Authentication, Qas, Takers) {
+ $scope.authentication = Authentication;
+ // Takers controller logic
+ var taker = new Takers();
+ //taker.qa = qas;
+ $scope.taker = new Takers({
+ quizNumber: '0',
+ trialNumber: '0',
+ trialOptions: '',
+ results: [{ questionViewed: false, questionAnswered: false,
+ questionNumber: '', answer:[{selection: '0', answer: '0'}]}]
+
+ });
+ console.log('From ScopeTaker', $scope.taker);
+ $scope.find = function() {
+ Qas.query(function(qas) {
+ $scope.qas = qas;
+
+ });
+ };
+ console.log('From ScopeTaker', $scope.qas);
+ // Create and validate taker entries
+ $scope.next = function () {
+
+ $scope.questionIndex++;
+ taker.questionViewed = true;
+ taker.$save(function (response) {
+ $location.path('takers/' + response._id);
+ });
+ console.log('next', $scope.questionIndex);
+
+ };
+ $scope.prev = function() {
+ $scope.questionIndex--;
+ console.log('prev',$scope.questionIndex);
+ };
+
+ $scope.answerToggled = function() {
+ //var taker = $scope.taker;
+ // Grab data from input boxes
+
+ //console.log(taker);
+ //taker.qa.question = qas[questionIndex].question;
+ //taker.questionNumber = $scope.questionNumber;
+ console.log('toggledtaker',taker);
+ for (var i=0, ln = taker.qa[$scope.questionIndex].choices.length; i
+
+
+
\ No newline at end of file
diff --git a/public/modules/takers/views/edit-taker.client.view.html b/public/modules/takers/views/edit-taker.client.view.html
new file mode 100644
index 0000000000..a7bbbad0ea
--- /dev/null
+++ b/public/modules/takers/views/edit-taker.client.view.html
@@ -0,0 +1,23 @@
+
\ No newline at end of file
diff --git a/public/modules/takers/views/list-takers.client.view.html b/public/modules/takers/views/list-takers.client.view.html
new file mode 100644
index 0000000000..a0d59302c8
--- /dev/null
+++ b/public/modules/takers/views/list-takers.client.view.html
@@ -0,0 +1,19 @@
+
+
+
+
+ No Takers yet, why don't you
create one ?
+
+
\ No newline at end of file
diff --git a/public/modules/takers/views/take.html b/public/modules/takers/views/take.html
new file mode 100644
index 0000000000..1533058e26
--- /dev/null
+++ b/public/modules/takers/views/take.html
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Prev
+ Next
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/public/modules/takers/views/view-taker.client.view.html b/public/modules/takers/views/view-taker.client.view.html
new file mode 100644
index 0000000000..a3c84f1acc
--- /dev/null
+++ b/public/modules/takers/views/view-taker.client.view.html
@@ -0,0 +1,21 @@
+
+
+
+
+
+ Posted on
+
+ by
+
+
+
+
\ No newline at end of file
From 44b1d330a6894fc535ef1de69e166b25042bb062 Mon Sep 17 00:00:00 2001
From: Cliff Eby
Date: Sat, 23 Aug 2014 21:34:15 -0400
Subject: [PATCH 03/27] Adding Qas and Takers
---
app/controllers/qas.server.controller.js | 129 ++++++++++++++++++++
app/controllers/takers.server.controller.js | 128 +++++++++++++++++++
2 files changed, 257 insertions(+)
create mode 100644 app/controllers/qas.server.controller.js
create mode 100644 app/controllers/takers.server.controller.js
diff --git a/app/controllers/qas.server.controller.js b/app/controllers/qas.server.controller.js
new file mode 100644
index 0000000000..4ff4a6a9e7
--- /dev/null
+++ b/app/controllers/qas.server.controller.js
@@ -0,0 +1,129 @@
+'use strict';
+
+/**
+ * Module dependencies...
+ */
+var mongoose = require('mongoose'),
+ Qa = mongoose.model('Qa'),
+ _ = require('lodash');
+
+/**
+ * Get the error message from error object
+ */
+var getErrorMessage = function(err) {
+ var message = '';
+
+ if (err.code) {
+ switch (err.code) {
+ case 11000:
+ case 11001:
+ message = 'Qa already exists';
+ break;
+ default:
+ message = 'Something went wrong';
+ }
+ } else {
+ for (var errName in err.errors) {
+ if (err.errors[errName].message) message = err.errors[errName].message;
+ }
+ }
+
+ return message;
+};
+
+/**
+ * Create a Qa
+ */
+exports.create = function(req, res) {
+ var qa = new Qa(req.body);
+ qa.user = req.user;
+
+ qa.save(function(err) {
+ if (err) {
+ return res.send(400, {
+ message: getErrorMessage(err)
+ });
+ } else {
+ res.jsonp(qa);
+ }
+ });
+};
+
+/**
+ * *
+ * Show the current Qa
+ */
+exports.read = function(req, res) {
+ res.jsonp(req.qa);
+};
+
+/**
+ * Update a Qa
+ */
+exports.update = function(req, res) {
+ var qa = req.qa ;
+
+ qa = _.extend(qa , req.body);
+
+ qa.save(function(err) {
+ if (err) {
+ return res.send(400, {
+ message: getErrorMessage(err)
+ });
+ } else {
+ res.jsonp(qa);
+ }
+ });
+};
+
+/**
+ * Delete an Qa
+ */
+exports.delete = function(req, res) {
+ var qa = req.qa ;
+
+ qa.remove(function(err) {
+ if (err) {
+ return res.send(400, {
+ message: getErrorMessage(err)
+ });
+ } else {
+ res.jsonp(qa);
+ }
+ });
+};
+
+/**
+ * List of Qas
+ */
+exports.list = function(req, res) { Qa.find().sort('-created').populate('user', 'displayName').exec(function(err, qas) {
+ if (err) {
+ return res.send(400, {
+ message: getErrorMessage(err)
+ });
+ } else {
+ res.jsonp(qas);
+ }
+ });
+};
+
+/**
+ * Qa middleware
+ */
+exports.qaByID = function(req, res, next, id) { Qa.findById(id).populate('user', 'displayName').exec(function(err, qa) {
+ if (err) return next(err);
+ if (! qa) return next(new Error('Failed to load Qa ' + id));
+ req.qa = qa ;
+ next();
+ });
+};
+
+/**
+ * Qa authorization middleware
+ */
+exports.hasAuthorization = function(req, res, next) {
+ if (req.qa.user.id !== req.user.id) {
+ return res.send(403, 'User is not authorized');
+ }
+ next();
+};
\ No newline at end of file
diff --git a/app/controllers/takers.server.controller.js b/app/controllers/takers.server.controller.js
new file mode 100644
index 0000000000..27faa175ac
--- /dev/null
+++ b/app/controllers/takers.server.controller.js
@@ -0,0 +1,128 @@
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+var mongoose = require('mongoose'),
+ Taker = mongoose.model('Taker'),
+ _ = require('lodash');
+
+/**
+ * Get the error message from error object
+ */
+var getErrorMessage = function(err) {
+ var message = '';
+
+ if (err.code) {
+ switch (err.code) {
+ case 11000:
+ case 11001:
+ message = 'Taker already exists';
+ break;
+ default:
+ message = 'Something went wrong';
+ }
+ } else {
+ for (var errName in err.errors) {
+ if (err.errors[errName].message) message = err.errors[errName].message;
+ }
+ }
+
+ return message;
+};
+
+/**
+ * Create a Taker
+ */
+exports.create = function(req, res) {
+ var taker = new Taker(req.body);
+ taker.user = req.user;
+
+ taker.save(function(err) {
+ if (err) {
+ return res.send(400, {
+ message: getErrorMessage(err)
+ });
+ } else {
+ res.jsonp(taker);
+ }
+ });
+};
+
+/**
+ * Show the current Taker
+ */
+exports.read = function(req, res) {
+ res.jsonp(req.taker);
+};
+
+/**
+ * Update a Taker
+ */
+exports.update = function(req, res) {
+ var taker = req.taker ;
+
+ taker = _.extend(taker , req.body);
+
+ taker.save(function(err) {
+ if (err) {
+ return res.send(400, {
+ message: getErrorMessage(err)
+ });
+ } else {
+ res.jsonp(taker);
+ }
+ });
+};
+
+/**
+ * Delete an Taker
+ */
+exports.delete = function(req, res) {
+ var taker = req.taker ;
+
+ taker.remove(function(err) {
+ if (err) {
+ return res.send(400, {
+ message: getErrorMessage(err)
+ });
+ } else {
+ res.jsonp(taker);
+ }
+ });
+};
+
+/**
+ * List of Takers
+ */
+exports.list = function(req, res) { Taker.find().sort('-created').populate('user', 'displayName').exec(function(err, takers) {
+ if (err) {
+ return res.send(400, {
+ message: getErrorMessage(err)
+ });
+ } else {
+ res.jsonp(takers);
+ }
+ });
+};
+
+/**
+ * Taker middleware
+ */
+exports.takerByID = function(req, res, next, id) { Taker.findById(id).populate('user', 'displayName').exec(function(err, taker) {
+ if (err) return next(err);
+ if (! taker) return next(new Error('Failed to load Taker ' + id));
+ req.taker = taker ;
+ next();
+ });
+};
+
+/**
+ * Taker authorization middleware
+ */
+exports.hasAuthorization = function(req, res, next) {
+ if (req.taker.user.id !== req.user.id) {
+ return res.send(403, 'User is not authorized');
+ }
+ next();
+};
\ No newline at end of file
From 75c58999a2d503f690e0d27504469bc2b0ddf4b1 Mon Sep 17 00:00:00 2001
From: Cliff Eby
Date: Sat, 23 Aug 2014 21:36:25 -0400
Subject: [PATCH 04/27] Adding Qas and Takers
---
app/tests/qa.server.model.test.js | 64 ++++++++++++++++++++++++++++
app/tests/taker.server.model.test.js | 64 ++++++++++++++++++++++++++++
2 files changed, 128 insertions(+)
create mode 100644 app/tests/qa.server.model.test.js
create mode 100644 app/tests/taker.server.model.test.js
diff --git a/app/tests/qa.server.model.test.js b/app/tests/qa.server.model.test.js
new file mode 100644
index 0000000000..0d1306cd64
--- /dev/null
+++ b/app/tests/qa.server.model.test.js
@@ -0,0 +1,64 @@
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+var should = require('should'),
+ mongoose = require('mongoose'),
+ User = mongoose.model('User'),
+ Qa = mongoose.model('Qa');
+
+/**
+ * Globals
+ */
+var user, qa;
+
+/**
+ * Unit tests
+ */
+describe('Qa Model Unit Tests:', function() {
+ beforeEach(function(done) {
+ user = new User({
+ firstName: 'Full',
+ lastName: 'Name',
+ displayName: 'Full Name',
+ email: 'test@test.com',
+ username: 'username',
+ password: 'password'
+ });
+
+ user.save(function() {
+ qa = new Qa({
+ name: 'Qa Name',
+ user: user
+ });
+
+ done();
+ });
+ });
+
+ describe('Method Save', function() {
+ it('should be able to save without problems', function(done) {
+ return qa.save(function(err) {
+ should.not.exist(err);
+ done();
+ });
+ });
+
+ it('should be able to show an error when try to save without name', function(done) {
+ qa.name = '';
+
+ return qa.save(function(err) {
+ should.exist(err);
+ done();
+ });
+ });
+ });
+
+ afterEach(function(done) {
+ Qa.remove().exec();
+ User.remove().exec();
+
+ done();
+ });
+});
\ No newline at end of file
diff --git a/app/tests/taker.server.model.test.js b/app/tests/taker.server.model.test.js
new file mode 100644
index 0000000000..f55980cd93
--- /dev/null
+++ b/app/tests/taker.server.model.test.js
@@ -0,0 +1,64 @@
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+var should = require('should'),
+ mongoose = require('mongoose'),
+ User = mongoose.model('User'),
+ Taker = mongoose.model('Taker');
+
+/**
+ * Globals
+ */
+var user, taker;
+
+/**
+ * Unit tests
+ */
+describe('Taker Model Unit Tests:', function() {
+ beforeEach(function(done) {
+ user = new User({
+ firstName: 'Full',
+ lastName: 'Name',
+ displayName: 'Full Name',
+ email: 'test@test.com',
+ username: 'username',
+ password: 'password'
+ });
+
+ user.save(function() {
+ taker = new Taker({
+ name: 'Taker Name',
+ user: user
+ });
+
+ done();
+ });
+ });
+
+ describe('Method Save', function() {
+ it('should be able to save without problems', function(done) {
+ return taker.save(function(err) {
+ should.not.exist(err);
+ done();
+ });
+ });
+
+ it('should be able to show an error when try to save without name', function(done) {
+ taker.name = '';
+
+ return taker.save(function(err) {
+ should.exist(err);
+ done();
+ });
+ });
+ });
+
+ afterEach(function(done) {
+ Taker.remove().exec();
+ User.remove().exec();
+
+ done();
+ });
+});
\ No newline at end of file
From 5e423ede351cc0b09a6dc30b9c99f0cb6b39b1c3 Mon Sep 17 00:00:00 2001
From: Cliff Eby
Date: Sun, 24 Aug 2014 21:19:25 -0400
Subject: [PATCH 05/27] Adding a Service
---
.../qas/controllers/qas.client.controller.js | 74 +++++++++++++------
public/modules/qas/qas.client.module.js | 2 +-
.../qas/services/qas.client.service1.js | 23 ++++++
.../qas/services/qas.client.service2.js | 36 +++++++++
.../qas/views/list-qas.client.view.html | 1 +
5 files changed, 114 insertions(+), 22 deletions(-)
create mode 100644 public/modules/qas/services/qas.client.service1.js
create mode 100644 public/modules/qas/services/qas.client.service2.js
diff --git a/public/modules/qas/controllers/qas.client.controller.js b/public/modules/qas/controllers/qas.client.controller.js
index bfea388c3f..583014adbb 100644
--- a/public/modules/qas/controllers/qas.client.controller.js
+++ b/public/modules/qas/controllers/qas.client.controller.js
@@ -1,29 +1,40 @@
'use strict';
// Qas controller...
-angular.module('qas').controller('QasController', ['$scope', '$stateParams', '$location', 'Authentication', 'Qas',
- function ($scope, $stateParams, $location, Authentication, Qas) {
+angular.module('qas').controller('QasController', ['$scope', '$stateParams', '$location', 'Authentication',
+ 'Qas','CalculatorService','MathService',
+ function ($scope, $stateParams, $location, Authentication, Qas, CalculatorService, MathService ) {
$scope.authentication = Authentication;
+ $scope.doSquare = CalculatorService.square(16);
+ //$scope.doSquare = MathService.multiply(4,4);
+ // $scope.doit = MathService.multiply(4,4);
+ $scope.doit = CalculatorService.square(4);
+ $scope.doit = CalculatorService.cube(9);
+ $scope.doit = MathService.add(3,4);
+
+
+
// Create new Qa
- $scope.typeDropdown = [
- {
- 'label': 'FIB',
- 'value': 1
- },
- {
- 'label': 'TF',
- 'value': 2
- },
- {
- 'label': 'MC',
- 'value': 3
- },
- {
- 'label': 'Matching',
- 'value': 4
- }
- ];
+ $scope.typeDropdown = "AAA";
+// $scope.typeDropdown = [
+// {
+// 'label': 'FIB',
+// 'value': 1
+// },
+// {
+// 'label': 'TF',
+// 'value': 2
+// },
+// {
+// 'label': 'MC',
+// 'value': 3
+// },
+// {
+// 'label': 'Matching',
+// 'value': 4
+// }
+// ];
$scope.difficultyDropdown = [
{
'label': 'Easy',
@@ -160,5 +171,26 @@ angular.module('qas').controller('QasController', ['$scope', '$stateParams', '$l
-]);
+])
+ .service('MathService', function() {
+
+ this.add = function(a, b) { return a + b };
+
+ this.subtract = function(a, b) { return a - b };
+
+ this.multiply = function(a, b) { return a * b };
+
+ this.divide = function(a, b) { return a / b };
+
+ })
+
+ .service('CalculatorService', function(MathService){
+
+ this.square = function(a) { return MathService.multiply(a,a); };
+ this.cce = function(a) {return a+a*1000};
+ this.cube = function(a) { return MathService.multiply(a, MathService.multiply(a,a)); };
+
+ });
+
+;
diff --git a/public/modules/qas/qas.client.module.js b/public/modules/qas/qas.client.module.js
index 49cad3f2cc..abf27a7ec1 100644
--- a/public/modules/qas/qas.client.module.js
+++ b/public/modules/qas/qas.client.module.js
@@ -1,4 +1,4 @@
'use strict';
-// Use applicaion configuration module to register a new module
+// Use application configuration module to register a new module
ApplicationConfiguration.registerModule('qas');
\ No newline at end of file
diff --git a/public/modules/qas/services/qas.client.service1.js b/public/modules/qas/services/qas.client.service1.js
new file mode 100644
index 0000000000..61738f53d6
--- /dev/null
+++ b/public/modules/qas/services/qas.client.service1.js
@@ -0,0 +1,23 @@
+/**
+ * Created by EbyC on 8/24/2014.
+ */
+'use strict';
+
+//Qas service used to communicate Qas REST endpoints
+angular.module('qas').service('MathService', [ function() {
+
+ this.add = function(a, b) { return a + b };
+
+ this.subtract = function(a, b) { return a - b };
+
+ this.multiply = function(a, b) { return a * b };
+
+ this.divide = function(a, b) { return a / b };
+ }])
+
+ .service('CalculatorService', [ function(MathService){
+
+ this.square = function(a) { return MathService.multiply(a,a); };
+ this.cube = function(a) { return MathService.multiply(a, MathService.multiply(a,a)); };
+
+ }]);
diff --git a/public/modules/qas/services/qas.client.service2.js b/public/modules/qas/services/qas.client.service2.js
new file mode 100644
index 0000000000..1d1b4c970a
--- /dev/null
+++ b/public/modules/qas/services/qas.client.service2.js
@@ -0,0 +1,36 @@
+/**
+ * Created by EbyC on 8/24/2014.
+ */
+'use strict';
+
+//Qas service used to communicate Qas REST endpoints
+angular.module('qas').service('qasInitService', [ function() {
+
+ this.init = function() { return [
+ {
+ 'label': 'FIB',
+ 'value': 1
+ },
+ {
+ 'label': 'TF',
+ 'value': 2
+ },
+ {
+ 'label': 'MC',
+ 'value': 3
+ },
+ {
+ 'label': 'Matching',
+ 'value': 4
+ }
+ ];
+ };
+
+ this.subtract = function(a, b) { return a - b };
+
+ this.multiply = function(a, b) { return a * b };
+
+ this.divide = function(a, b) { return a / b };
+ }])
+
+ ;
diff --git a/public/modules/qas/views/list-qas.client.view.html b/public/modules/qas/views/list-qas.client.view.html
index 159210d967..91a3018377 100644
--- a/public/modules/qas/views/list-qas.client.view.html
+++ b/public/modules/qas/views/list-qas.client.view.html
@@ -9,6 +9,7 @@ LIST
{{qa.question}}
{{qa.choices.length}}
+ {{doit}}
From 554cc075d68d9e49fede76d069ac3a1864be88be Mon Sep 17 00:00:00 2001
From: cliffeby
Date: Mon, 25 Aug 2014 13:10:45 -0400
Subject: [PATCH 06/27] Adding a Service
---
.../qas/controllers/qas.client.controller.js | 39 ++++++++++---------
.../qas/services/qas.client.service1.js | 10 +++--
2 files changed, 26 insertions(+), 23 deletions(-)
diff --git a/public/modules/qas/controllers/qas.client.controller.js b/public/modules/qas/controllers/qas.client.controller.js
index 583014adbb..d45eb2ab31 100644
--- a/public/modules/qas/controllers/qas.client.controller.js
+++ b/public/modules/qas/controllers/qas.client.controller.js
@@ -12,6 +12,7 @@ angular.module('qas').controller('QasController', ['$scope', '$stateParams', '$l
$scope.doit = CalculatorService.square(4);
$scope.doit = CalculatorService.cube(9);
$scope.doit = MathService.add(3,4);
+ $scope.doit = CalculatorService.cce(77);
@@ -172,25 +173,25 @@ angular.module('qas').controller('QasController', ['$scope', '$stateParams', '$l
])
- .service('MathService', function() {
-
- this.add = function(a, b) { return a + b };
-
- this.subtract = function(a, b) { return a - b };
-
- this.multiply = function(a, b) { return a * b };
-
- this.divide = function(a, b) { return a / b };
-
- })
-
- .service('CalculatorService', function(MathService){
-
- this.square = function(a) { return MathService.multiply(a,a); };
- this.cce = function(a) {return a+a*1000};
- this.cube = function(a) { return MathService.multiply(a, MathService.multiply(a,a)); };
-
- });
+// .service('MathService', function() {
+//
+// this.add = function(a, b) { return a + b };
+//
+// this.subtract = function(a, b) { return a - b };
+//
+// this.multiply = function(a, b) { return a * b };
+//
+// this.divide = function(a, b) { return a / b };
+//
+// })
+
+// .service('CalculatorService', function(MathService){
+//
+// this.square = function(a) { return MathService.multiply(a,a); };
+// this.cce = function(a) {return a+a*1000};
+// this.cube = function(a) { return MathService.multiply(a, MathService.multiply(a,a)); };
+//
+// });
;
diff --git a/public/modules/qas/services/qas.client.service1.js b/public/modules/qas/services/qas.client.service1.js
index 61738f53d6..d7a06f8904 100644
--- a/public/modules/qas/services/qas.client.service1.js
+++ b/public/modules/qas/services/qas.client.service1.js
@@ -15,9 +15,11 @@ angular.module('qas').service('MathService', [ function() {
this.divide = function(a, b) { return a / b };
}])
- .service('CalculatorService', [ function(MathService){
+ .service('CalculatorService', function(MathService){
- this.square = function(a) { return MathService.multiply(a,a); };
- this.cube = function(a) { return MathService.multiply(a, MathService.multiply(a,a)); };
+this.square = function(a) { return MathService.multiply(a,a); };
+this.cce = function(a) {return a+a*1000};
+this.cube = function(a) { return MathService.multiply(a, MathService.multiply(a,a)); };
- }]);
+});
+// }]);
From 5567c2573309e20908d03b178297b52045fc26cf Mon Sep 17 00:00:00 2001
From: cliffeby
Date: Mon, 25 Aug 2014 13:58:55 -0400
Subject: [PATCH 07/27] Adding init Service
---
.../qas/controllers/qas.client.controller.js | 49 ++-----------
.../qas/services/qas.client.service1.js | 19 +++--
.../qas/services/qas.client.service2.js | 70 +++++++++++--------
3 files changed, 53 insertions(+), 85 deletions(-)
diff --git a/public/modules/qas/controllers/qas.client.controller.js b/public/modules/qas/controllers/qas.client.controller.js
index d45eb2ab31..e490c61b33 100644
--- a/public/modules/qas/controllers/qas.client.controller.js
+++ b/public/modules/qas/controllers/qas.client.controller.js
@@ -2,59 +2,18 @@
// Qas controller...
angular.module('qas').controller('QasController', ['$scope', '$stateParams', '$location', 'Authentication',
- 'Qas','CalculatorService','MathService',
- function ($scope, $stateParams, $location, Authentication, Qas, CalculatorService, MathService ) {
+ 'Qas','CalculatorService','MathService','qasInitService',
+ function ($scope, $stateParams, $location, Authentication, Qas, CalculatorService, MathService, qasInitService ) {
$scope.authentication = Authentication;
- $scope.doSquare = CalculatorService.square(16);
- //$scope.doSquare = MathService.multiply(4,4);
- // $scope.doit = MathService.multiply(4,4);
- $scope.doit = CalculatorService.square(4);
- $scope.doit = CalculatorService.cube(9);
- $scope.doit = MathService.add(3,4);
$scope.doit = CalculatorService.cce(77);
// Create new Qa
- $scope.typeDropdown = "AAA";
-// $scope.typeDropdown = [
-// {
-// 'label': 'FIB',
-// 'value': 1
-// },
-// {
-// 'label': 'TF',
-// 'value': 2
-// },
-// {
-// 'label': 'MC',
-// 'value': 3
-// },
-// {
-// 'label': 'Matching',
-// 'value': 4
-// }
-// ];
- $scope.difficultyDropdown = [
- {
- 'label': 'Easy',
- 'value': 1
- },
- {
- 'label': 'Medium',
- 'value': 2
- },
- {
- 'label': 'Hard',
- 'value': 3
- },
- {
- 'label': 'Impossible',
- 'value': 4
- }
- ];
+ $scope.typeDropdown = qasInitService.typeDropdown();
+ $scope.difficultyDropdown = qasInitService.difficultyDropdown();
$scope.qa = new Qas({
question: '',
diff --git a/public/modules/qas/services/qas.client.service1.js b/public/modules/qas/services/qas.client.service1.js
index d7a06f8904..85e2309417 100644
--- a/public/modules/qas/services/qas.client.service1.js
+++ b/public/modules/qas/services/qas.client.service1.js
@@ -3,23 +3,20 @@
*/
'use strict';
-//Qas service used to communicate Qas REST endpoints
-angular.module('qas').service('MathService', [ function() {
-
- this.add = function(a, b) { return a + b };
+angular.module('qas')
+ .service('MathService', [ function() {
+ this.add = function(a, b) { return a + b };
this.subtract = function(a, b) { return a - b };
-
this.multiply = function(a, b) { return a * b };
-
this.divide = function(a, b) { return a / b };
}])
.service('CalculatorService', function(MathService){
-this.square = function(a) { return MathService.multiply(a,a); };
-this.cce = function(a) {return a+a*1000};
-this.cube = function(a) { return MathService.multiply(a, MathService.multiply(a,a)); };
+ this.square = function(a) { return MathService.multiply(a,a); };
+ this.cce = function(a) {return a+a*1000};
+ this.cube = function(a) { return MathService.multiply(a, MathService.multiply(a,a)); };
+
+ });
-});
-// }]);
diff --git a/public/modules/qas/services/qas.client.service2.js b/public/modules/qas/services/qas.client.service2.js
index 1d1b4c970a..609866dd8a 100644
--- a/public/modules/qas/services/qas.client.service2.js
+++ b/public/modules/qas/services/qas.client.service2.js
@@ -4,33 +4,45 @@
'use strict';
//Qas service used to communicate Qas REST endpoints
-angular.module('qas').service('qasInitService', [ function() {
+angular.module('qas')
+ .service('qasInitService', [ function() {
- this.init = function() { return [
- {
- 'label': 'FIB',
- 'value': 1
- },
- {
- 'label': 'TF',
- 'value': 2
- },
- {
- 'label': 'MC',
- 'value': 3
- },
- {
- 'label': 'Matching',
- 'value': 4
- }
- ];
- };
-
- this.subtract = function(a, b) { return a - b };
-
- this.multiply = function(a, b) { return a * b };
-
- this.divide = function(a, b) { return a / b };
- }])
-
- ;
+ this.typeDropdown = function() { return [
+ {
+ 'label': 'FIB',
+ 'value': 1
+ },
+ {
+ 'label': 'TF',
+ 'value': 2
+ },
+ {
+ 'label': 'MC',
+ 'value': 3
+ },
+ {
+ 'label': 'Matching',
+ 'value': 4
+ }
+ ];
+ };
+ this.difficultyDropdown = function() { return [
+ {
+ 'label': 'Easy',
+ 'value': 1
+ },
+ {
+ 'label': 'Medium',
+ 'value': 2
+ },
+ {
+ 'label': 'Hard',
+ 'value': 3
+ },
+ {
+ 'label': 'Impossible',
+ 'value': 4
+ }
+ ];
+ }
+ }]);
From e460d409aaf44c8df4b693940de9f3219263e7f2 Mon Sep 17 00:00:00 2001
From: cliffeby
Date: Mon, 25 Aug 2014 23:18:36 -0400
Subject: [PATCH 08/27] Working on Initializing data in service
---
.../qas/controllers/qas.client.controller.js | 54 ++++---------------
.../qas/services/qas.client.service2.js | 13 ++++-
2 files changed, 22 insertions(+), 45 deletions(-)
diff --git a/public/modules/qas/controllers/qas.client.controller.js b/public/modules/qas/controllers/qas.client.controller.js
index e490c61b33..105f565861 100644
--- a/public/modules/qas/controllers/qas.client.controller.js
+++ b/public/modules/qas/controllers/qas.client.controller.js
@@ -5,33 +5,24 @@ angular.module('qas').controller('QasController', ['$scope', '$stateParams', '$l
'Qas','CalculatorService','MathService','qasInitService',
function ($scope, $stateParams, $location, Authentication, Qas, CalculatorService, MathService, qasInitService ) {
$scope.authentication = Authentication;
-
+//Test of Calculator and Math Service
$scope.doit = CalculatorService.cce(77);
-
-
- // Create new Qa
+// Initialize Dropdown labels
$scope.typeDropdown = qasInitService.typeDropdown();
-
$scope.difficultyDropdown = qasInitService.difficultyDropdown();
- $scope.qa = new Qas({
- question: '',
- answer: '',
- choices: [
- { text: '', correctAnswer: false },
- { text: '', correctAnswer: false}
- ],
- content: ''
- });
+ var qa = new Qas();
+ $scope.qa = qasInitService.init(qa);
//$scope.taker = new Taker({
// quizNumber: '9999'});
- console.log('From Scope1 taker', $scope.taker);
- $scope.qa.choices.correctAnswer;
+
+ $scope.qa.choices.correctAnswer;
// Create and validate qa entries
$scope.create = function () {
- console.log("From QA CReate");
- var qa = $scope.qa;
+ // console.log("From QA CReate");
+ qa = $scope.qa;
+ console.log('qa', qa);
// Grab data from input boxes
qa.question = this.question;
qa.imageURL = this.imageURL;
@@ -126,31 +117,6 @@ angular.module('qas').controller('QasController', ['$scope', '$stateParams', '$l
console.log(qa);
$scope.qa.choices.splice(ss, 1);
};
-
}
-
-
-
-])
-// .service('MathService', function() {
-//
-// this.add = function(a, b) { return a + b };
-//
-// this.subtract = function(a, b) { return a - b };
-//
-// this.multiply = function(a, b) { return a * b };
-//
-// this.divide = function(a, b) { return a / b };
-//
-// })
-
-// .service('CalculatorService', function(MathService){
-//
-// this.square = function(a) { return MathService.multiply(a,a); };
-// this.cce = function(a) {return a+a*1000};
-// this.cube = function(a) { return MathService.multiply(a, MathService.multiply(a,a)); };
-//
-// });
-
-;
+]);
diff --git a/public/modules/qas/services/qas.client.service2.js b/public/modules/qas/services/qas.client.service2.js
index 609866dd8a..30b6e99d1d 100644
--- a/public/modules/qas/services/qas.client.service2.js
+++ b/public/modules/qas/services/qas.client.service2.js
@@ -44,5 +44,16 @@ angular.module('qas')
'value': 4
}
];
- }
+ };
+
+ this.init = function(qa){return ({
+ question: 'a',
+ answer: 'b',
+ choices: [
+ { text: '', correctAnswer: false },
+ { text: '', correctAnswer: false}
+ ],
+ content: ''
+ });}
+
}]);
From 2daebefba799cccf21afa4541e5d3aaa0d50a83f Mon Sep 17 00:00:00 2001
From: cliffeby
Date: Tue, 26 Aug 2014 23:12:15 -0400
Subject: [PATCH 09/27] Working on Initializing data in service
---
.../qas/controllers/qas.client.controller.js | 12 ++++++------
.../modules/qas/services/qas.client.service2.js | 16 +++++++++++++---
.../modules/qas/views/create-qa.client.view.html | 2 +-
3 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/public/modules/qas/controllers/qas.client.controller.js b/public/modules/qas/controllers/qas.client.controller.js
index 105f565861..9ec67d3b00 100644
--- a/public/modules/qas/controllers/qas.client.controller.js
+++ b/public/modules/qas/controllers/qas.client.controller.js
@@ -11,22 +11,22 @@ angular.module('qas').controller('QasController', ['$scope', '$stateParams', '$l
// Initialize Dropdown labels
$scope.typeDropdown = qasInitService.typeDropdown();
$scope.difficultyDropdown = qasInitService.difficultyDropdown();
-
var qa = new Qas();
$scope.qa = qasInitService.init(qa);
- //$scope.taker = new Taker({
- // quizNumber: '9999'});
- $scope.qa.choices.correctAnswer;
+ // $scope.qa.choices.correctAnswer;
// Create and validate qa entries
$scope.create = function () {
- // console.log("From QA CReate");
- qa = $scope.qa;
+ var qa = new Qas();
+ qa = qasInitService.init(qa);
+ console.log('$scope.qa', $scope.qa);
+ //qa = $scope.qa;
console.log('qa', qa);
// Grab data from input boxes
qa.question = this.question;
qa.imageURL = this.imageURL;
qa.choices.text = [
+ { text: this.text },
{ text: this.text },
{ text: this.text }
];
diff --git a/public/modules/qas/services/qas.client.service2.js b/public/modules/qas/services/qas.client.service2.js
index 30b6e99d1d..44f82d3681 100644
--- a/public/modules/qas/services/qas.client.service2.js
+++ b/public/modules/qas/services/qas.client.service2.js
@@ -47,13 +47,23 @@ angular.module('qas')
};
this.init = function(qa){return ({
- question: 'a',
- answer: 'b',
+ question: '',
+ questionNumber: "",
+ imageURL:"",
choices: [
{ text: '', correctAnswer: false },
+ { text: '', correctAnswer: false},
{ text: '', correctAnswer: false}
],
- content: ''
+ content: '',
+ hint:"",
+ difficulty:"",
+ type:"",
+ hintOn:false,
+ timeOn:false,
+ fifty50On:false,
+ randomizeQuestionsOn:false,
+ randomizeAnswersOn:false
});}
}]);
diff --git a/public/modules/qas/views/create-qa.client.view.html b/public/modules/qas/views/create-qa.client.view.html
index cf16d47edd..8f83dd24f4 100644
--- a/public/modules/qas/views/create-qa.client.view.html
+++ b/public/modules/qas/views/create-qa.client.view.html
@@ -67,7 +67,7 @@ New Big QA
-
+
Difficulty
From acf836cb54be79308c9723b81af3a5f997f39b4c Mon Sep 17 00:00:00 2001
From: cliffeby
Date: Tue, 9 Sep 2014 23:17:14 -0400
Subject: [PATCH 10/27] getting create() to function
---
.../controllers/articles.client.controller.js | 1 +
.../qas/controllers/qas.client.controller.js | 61 ++++++------
.../qas/services/qas.client.service2.js | 4 +-
.../qas/views/create-qa.client.view.html | 23 +++--
.../was/services/was.client.service2.js | 69 +++++++++++++
.../was/views/create-wa.client.view.html | 98 +++++++++++++++++++
6 files changed, 214 insertions(+), 42 deletions(-)
create mode 100644 public/modules/was/services/was.client.service2.js
create mode 100644 public/modules/was/views/create-wa.client.view.html
diff --git a/public/modules/articles/controllers/articles.client.controller.js b/public/modules/articles/controllers/articles.client.controller.js
index 364987eb9e..ee02cd230a 100644
--- a/public/modules/articles/controllers/articles.client.controller.js
+++ b/public/modules/articles/controllers/articles.client.controller.js
@@ -9,6 +9,7 @@ angular.module('articles').controller('ArticlesController', ['$scope', '$statePa
title: this.title,
content: this.content
});
+ // console.log(response);
article.$save(function(response) {
$location.path('articles/' + response._id);
diff --git a/public/modules/qas/controllers/qas.client.controller.js b/public/modules/qas/controllers/qas.client.controller.js
index 9ec67d3b00..f1626d2591 100644
--- a/public/modules/qas/controllers/qas.client.controller.js
+++ b/public/modules/qas/controllers/qas.client.controller.js
@@ -11,61 +11,62 @@ angular.module('qas').controller('QasController', ['$scope', '$stateParams', '$l
// Initialize Dropdown labels
$scope.typeDropdown = qasInitService.typeDropdown();
$scope.difficultyDropdown = qasInitService.difficultyDropdown();
- var qa = new Qas();
- $scope.qa = qasInitService.init(qa);
- // $scope.qa.choices.correctAnswer;
+ $scope.qa = qasInitService.init();
+ //var qa = $scope.qa;
// Create and validate qa entries
$scope.create = function () {
- var qa = new Qas();
- qa = qasInitService.init(qa);
- console.log('$scope.qa', $scope.qa);
- //qa = $scope.qa;
- console.log('qa', qa);
- // Grab data from input boxes
- qa.question = this.question;
- qa.imageURL = this.imageURL;
- qa.choices.text = [
- { text: this.text },
- { text: this.text },
- { text: this.text }
- ];
- qa.content = this.content;
- qa.hint = this.hint;
- qa.hintOn = this.hintOn;
- qa.timeOn = this.timeOn;
- qa.fifty50On = this.fifty50On;
- qa.randomizeQuestionsOn = this.randomizeQuestionsOn;
- qa.randomizeAnswersOn = this.randomizeAnswersOn;
+ var qa = new Qas({
+ question: this.question,
+ imageURL: this.imageURL,
+ choices: [{
+ text: this.text, selectedAnswer: false
+ }, {text: this.text, selectedAnswer: this.correctAnswer
+ }, {text: this.text, selectedAnswer: this.correctAnswer
+ }],
+ hint: this.hint,
- console.log('From qa 1', qa);
+ hintOn: this.hintOn,
+ timeOn: this.timeOn,
+ fifty50On: this.fifty50On,
+ randomizeQuestionsOn: this.randomizeQuestionsOn,
+ randomizeAnswersOn: this.randomizeAnswersOn
+ });
+
+ qa.choices = $scope.qa.choices;
+ console.log('From qa 1',qa);console.log('From $qa 1',$scope.qa);
// Check that question was entered
console.log('qa.question.length', qa.question.length);
if (qa.question.length > 0) {
var choiceCount = 0;
//Loop through choices to get at least two
+ console.log('qa if', qa);
for (var i = 0, ln = qa.choices.length; i < ln; i++) {
- var choice = qa.choices[i];
- if (choice.text.length > 0) {
+ var choice = qa.choices[i].text;
+ console.log('choice', choice, " i", i);
+ if (choice.length > 0) {
choiceCount++;
}
}
if (choiceCount > 1) {
// Call API to save to database
- qa.$save(function (response) {
- $location.path('qas/' + response._id);
- });
+
+
} else {
alert('You must have at least two choices');
}
} else {
alert('You must have a question');
}
+ console.log('qaFinal',qa);
+ qa.$save(function(response) {
+ $location.path('qas/' + response._id)});
};
// Method to add an additional choice option
$scope.addChoice = function () {
- $scope.qa.choices.push({ text: this.text, correctAnswer: false });
+ console.log('qa add', $scope.qa);
+ $scope.qa.choices.push({ text: this.text, selectedAnswer: false });
};
$scope.remove = function (qa) {
diff --git a/public/modules/qas/services/qas.client.service2.js b/public/modules/qas/services/qas.client.service2.js
index 44f82d3681..023b016d61 100644
--- a/public/modules/qas/services/qas.client.service2.js
+++ b/public/modules/qas/services/qas.client.service2.js
@@ -46,8 +46,8 @@ angular.module('qas')
];
};
- this.init = function(qa){return ({
- question: '',
+ this.init = function(){return ({
+ question: 'dffdfdfdf',
questionNumber: "",
imageURL:"",
choices: [
diff --git a/public/modules/qas/views/create-qa.client.view.html b/public/modules/qas/views/create-qa.client.view.html
index 8f83dd24f4..3b14df887c 100644
--- a/public/modules/qas/views/create-qa.client.view.html
+++ b/public/modules/qas/views/create-qa.client.view.html
@@ -2,10 +2,11 @@
+