diff --git a/Procfile b/Procfile index d1913eb..6f86b16 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: node web.js \ No newline at end of file +web: node server.js \ No newline at end of file diff --git a/README.md b/README.md index 58a3d01..0dbb774 100755 --- a/README.md +++ b/README.md @@ -5,11 +5,15 @@ This is a boilerplate CMS built with Angular, Twitter Bootstrap and Node; it is [![Build Status](https://travis-ci.org/jonniespratley/angular-cms.png)](https://travis-ci.org/jonniespratley/angular-cms) +[![Codacy Badge](https://www.codacy.com/project/badge/0825389c11854c23a05cc512385ec82d)](https://www.codacy.com/public/jonniespratley/angular-cms) + +[![Coverage Status](https://coveralls.io/repos/jonniespratley/angular-cms/badge.png)](https://coveralls.io/r/jonniespratley/angular-cms) + + [![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/) [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/jonniespratley/angular-cms/trend.png)](https://bitdeli.com/free) -[![Coverage Status](https://coveralls.io/repos/jonniespratley/angular-cms/badge.png)](https://coveralls.io/r/jonniespratley/angular-cms)[![Dependency Status](https://david-dm.org/jonniespratley/angular-cms.svg)](https://david-dm.org/jonniespratley/angular-cms) ### Technologies @@ -69,9 +73,13 @@ To run the application on your local machine please take the following steps. To start mongodb execute the following command: +<<<<<<< HEAD ``` $ sh ./bin/db.sh ``` +======= + $ sh ./bin/db.sh +>>>>>>> fe4af0e14ef3596c823d4777d672ba00406ddb90 > **Note:** If errors when executing command remove the `db/mongod.lock` file. @@ -130,8 +138,13 @@ $ grunt protractor --- +<<<<<<< HEAD RESTful Server -------------- +======= +## RESTful Server +The server is a Node.js server that supports dynamic RESTful API calls to resource endpoints. It will automatically create a database if it does not exist and collection(s). +>>>>>>> fe4af0e14ef3596c823d4777d672ba00406ddb90 The server is a Node.js server that supports dynamic RESTful API calls to resource endpoints. It will automatically create a database if it does not exist and collection(s). diff --git a/app/index.html b/app/index.html index 6a5b8f8..032b30a 100755 --- a/app/index.html +++ b/app/index.html @@ -178,6 +178,7 @@ + diff --git a/app/scripts/controllers/users.coffee b/app/scripts/controllers/users.coffee index 380f7bb..f96a44c 100644 --- a/app/scripts/controllers/users.coffee +++ b/app/scripts/controllers/users.coffee @@ -1,63 +1,62 @@ 'use strict' angular.module('angularCmsApp').controller('UsersCtrl', ($scope, DataService) -> - $scope.awesomeThings = [ - 'HTML5 Boilerplate' - 'AngularJS' - 'Karma' - ] - - $scope.user = - username: null - email: null - password: null - role: null - created: new Date() - modified: new Date() - metadata: - avatar: '' - name: null - aboue: null - - #Hold the users - $scope.users = [] - - #Holds the user groups - $scope.groups = ['Admin', 'Member', 'Public'] - - $scope.getGroups = () -> - DataService.fetch('groups').then((data) -> - $scope.groups = data - console.log(data) - ) + $scope.awesomeThings = [ + 'HTML5 Boilerplate' + 'AngularJS' + 'Karma' + ] - #Select user - $scope.selectUser = (user) -> - $scope.user = user + $scope.user = + username: null + email: null + password: null + role: null + created: new Date() + modified: new Date() + metadata: + avatar: '' + name: null + aboue: null - #Get users - $scope.getUsers = () -> - DataService.fetch('users').then((data) -> - $scope.users = data - $scope.getGroups() unless $scope.groups - ) + #Hold the users + $scope.users = [] + + #Holds the user groups + $scope.groups = ['Admin', 'Member', 'Public'] - #Delete user - $scope.deleteUser = (index, user) -> - ask = confirm "Delete #{user.email}?" + $scope.getGroups = () -> + DataService.fetch('groups').then((results) -> + $scope.groups = results.data + console.log(data) + ) - if ask - DataService.destroy('users', user).then((data) -> - $scope.users.pop(index) - $scope.getUsers() - ) + #Select user + $scope.selectUser = (user) -> + $scope.user = user - #Add user to database - $scope.addUser = (user) -> - DataService.save('users', user).then((data) -> + #Get users + $scope.getUsers = () -> + DataService.fetch('users').then((results) -> + $scope.users = results.data + $scope.getGroups() unless $scope.groups + ) + + #Delete user + $scope.deleteUser = (index, user) -> + ask = confirm "Delete #{user.email}?" + + if ask + DataService.destroy('users', user).then((data) -> + $scope.users.pop(index) $scope.getUsers() - #$scope.users.push(user) unless user._id - $scope.user = {} - $('#user-modal').modal('hide') ) - + + #Add user to database + $scope.addUser = (user) -> + DataService.save('users', user).then((data) -> + $scope.getUsers() + #$scope.users.push(user) unless user._id + $scope.user = {} + $('#user-modal').modal('hide') + ) ) \ No newline at end of file diff --git a/app/scripts/services/cmssocketservice.coffee b/app/scripts/services/cmssocketservice.coffee new file mode 100644 index 0000000..8923cba --- /dev/null +++ b/app/scripts/services/cmssocketservice.coffee @@ -0,0 +1,38 @@ +'use strict' + +###* + # @ngdoc service + # @name angularCmsApp.cmsSocketService + # @description + # # cmsSocketService + # Service in the angularCmsApp. +### +angular.module('angularCmsApp').service 'cmsSocketService', -> + # AngularJS will instantiate a singleton by calling "new" on this function + WebSocketClient = (options) -> + _ws = undefined + _ws = new WebSocket(options.endpoint, options.protocol) + _ws.onmessage = (e) -> + console.log e.data + + _ws.onerror = (e) -> + console.log e + + _ws.onclose = (e) -> + console.log e + + _ws.onopen = (e) -> + _ws.send "update" + return + instance: _ws + close: -> + _ws.close() + + send: (obj) -> + try + _ws.send obj + catch err + throw err + return + + return WebSocketClient \ No newline at end of file diff --git a/app/styles/main.css b/app/styles/main.css index 50318c5..ccfaa69 100755 --- a/app/styles/main.css +++ b/app/styles/main.css @@ -163,7 +163,7 @@ html { } .cms-sidebar.closed .well { - width: 45px; + width: 65px; } diff --git a/app/views/admin.html b/app/views/admin.html index 3bdeb19..e69de29 100755 --- a/app/views/admin.html +++ b/app/views/admin.html @@ -1,102 +0,0 @@ - -
-
- -
-

-

-
- -

Welcome to Angular-CMS!

-

Here are some links to help get you started:


-
- -
-

Next Steps

-

Add some plugins

-

Upload media

-
-
-

More Actions

-

Manage Users

-

Site Settings

-
-
-
-
-
-
-
Overview
-
-
-
- Content -
    -
  • - 42 Pages
  • -
  • - 2 Categories
  • -
  • - 5 Tags
  • -
  • - 23 Files
  • -
  • - 5 Plugins
  • -
-
-
- System -
-
-

You are using Angular-CMS 0.1.0

-
- -
-

-
- -
-
-
Quick Post -
-
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
- - -
-
- -
- - \ No newline at end of file diff --git a/app/views/users.html b/app/views/users.html index 3951581..a153933 100755 --- a/app/views/users.html +++ b/app/views/users.html @@ -1,9 +1,11 @@

Users -

+ + +
@@ -11,37 +13,39 @@

Users
- - - - - - - - + + + + + + + + - - - - - - - + + + + + + - + + +
E-mailUsernameActiveCreatedActions
E-mailUsernameActiveCreatedActions
- - {{user.email}} - {{ user.username }} - - {{user.active}} {{user.created | date:'medium'}} +
+ + {{user.email}} + {{ user.username }} + {{group}} + {{user.active}} {{user.created | date:'medium'}}
- -
@@ -63,80 +67,94 @@

- -
- + + +
+ +
+ + +
+ + +
+ +
+
+ +
+ +
+
+
+ -
- -
- -
-
-
- -
- -
-
- - -
- -
- -
-
-
- -
- -
-
-
- -
- -
-
- -
-
- -
-
-
-
- -
- - +
+ + +
+ + +
+ + +
+ +
+
+
+ + +
+ +
+
+
+ + +
+ +
+
+ + +
+ +
+ + + + + + + + + + diff --git a/package.json b/package.json index 1de211d..172c927 100755 --- a/package.json +++ b/package.json @@ -83,6 +83,7 @@ "jasmine-node": "~1.14.5", "jasmine-reporters": "^1.0.1", "jshint-stylish": "~1.0.0", + "jasmine-spec-reporter": "^1.1.0", "karma": "^0.12.28", "karma-chrome-launcher": "^0.1.5", "karma-coverage": "^0.2.6", diff --git a/protractor.conf.js b/protractor.conf.js index ee43245..d1a63fa 100644 --- a/protractor.conf.js +++ b/protractor.conf.js @@ -1,23 +1,32 @@ // An example configuration file. exports.config = { - // The address of a running selenium server. - seleniumAddress: 'http://localhost:4444/wd/hub', + // The address of a running selenium server. + seleniumAddress: 'http://localhost:4444/wd/hub', + params: { + baseUrl: 'http://localhost:9000/#' + }, - // Capabilities to be passed to the webdriver instance. - capabilities: { - 'browserName': 'chrome' - }, + // Capabilities to be passed to the webdriver instance. + capabilities: { + 'browserName': 'chrome' + } + , - // Spec patterns are relative to the current working directly when - // protractor is called. - specs: [ - '.tmp/protractor/*.js', - 'test/protractor/*.js' - ], +// Spec patterns are relative to the current working directly when +// protractor is called. + specs: [ + '.tmp/protractor/*.js', + 'test/protractor/*.js' + ], - // Options to be passed to Jasmine-node. - jasmineNodeOpts: { - showColors: true, - defaultTimeoutInterval: 30000 - } + // Options to be passed to Jasmine-node. + jasmineNodeOpts: { + showColors: true, + defaultTimeoutInterval: 30000 + }, + onPrepare: function () { + var SpecReporter = require( 'jasmine-spec-reporter' ); + // add jasmine spec reporter + jasmine.getEnv().addReporter( new SpecReporter( {displayStacktrace: true} ) ); + } }; diff --git a/routes/rest.js b/routes/rest.js index ca2d61d..649adb8 100755 --- a/routes/rest.js +++ b/routes/rest.js @@ -16,23 +16,24 @@ */ //## Required Modules -var mongo = require('mongodb'); -var mongoose = require('mongoose'); -var crypto = require('crypto'); +var mongo = require( 'mongodb' ); +var mongoose = require( 'mongoose' ); +var crypto = require( 'crypto' ); var Server = mongo.Server; -var path = require('path'); +var path = require( 'path' ); var Db = mongo.Db; var BSON = mongo.BSONPure; -var express = require('express'); -var fs = require('fs'); +var express = require( 'express' ); +var utils = require( 'util' ); +var fs = require( 'fs' ); var app = express(); -var request = require('request'); -var upload = require('jquery-file-upload-middleware'); -var easyimg = require('easyimage'); -var sio = require('socket.io'); -var Deferred = require("promised-io/promise").Deferred; -var when = require("promised-io/promise"); -var bodyParser = require('body-parser'); +var request = require( 'request' ); +var upload = require( 'jquery-file-upload-middleware' ); +var easyimg = require( 'easyimage' ); +var sio = require( 'socket.io' ); +var Deferred = require( "promised-io/promise" ).Deferred; +var when = require( "promised-io/promise" ); +var bodyParser = require( 'body-parser' ); //Strings for results var MESSAGES = { @@ -42,21 +43,25 @@ var MESSAGES = { }; +var DS = require( 'jps-ds' ).DS; -var DS = require('jps-ds').DS; +var _ds = new DS( { + host: 'localhost/angular-cms', + models: { + 'users': {username: String, email: String, password: String, meta: Object}, + 'pages': {title: String, body: String, published: Boolean, created: Date} + } +} ); -var _ds = new DS({ - host: 'localhost/angular-cms' -}); function delay(ms, value) { // create a new Deferred var deferred = new Deferred(); - setTimeout(function () { + setTimeout( function () { // fulfill the deferred/promise, all listeners to the promise will be notified, and // provided the value as the value of the promise - deferred.resolve(value); - }, ms); + deferred.resolve( value ); + }, ms ); // return the promise that is associated with the Deferred object return deferred.promise; } @@ -64,10 +69,10 @@ function delay(ms, value) { //### hashPassword //Hash password using basic sha1 hash. var hashPassword = function (pass, salt) { - var shasum = crypto.createHash('sha1'); - shasum.update(salt + pass); + var shasum = crypto.createHash( 'sha1' ); + shasum.update( salt + pass ); - return shasum.digest('hex'); + return shasum.digest( 'hex' ); } //## Configuration @@ -83,8 +88,8 @@ var cloudfilesConfig = { }; //### Colors Config -var colors = require('colors'); -colors.setTheme({ +var colors = require( 'colors' ); +colors.setTheme( { silly: 'rainbow', input: 'grey', verbose: 'cyan', @@ -95,11 +100,10 @@ colors.setTheme({ warn: 'yellow', debug: 'blue', error: 'red' -}); +} ); //# Class Objects - //## Rest Resource //I am a RESTful resource object for handling CRUD operations on v1 or v2 api. var RestResource = { @@ -117,57 +121,57 @@ var RestResource = { //### index //I handle displaying a message with the version for this api. index: function (req, res, next) { - res.json({ + res.json( { message: 'REST API Server ' + RestResource.useversion - }); + } ); }, //### v1index //I handle displaying a message with the version for v1 index. v1index: function (req, res, next) { RestResource.useversion = 'v1'; - request(RestResource.urls[RestResource.useversion], function (error, response, body) { - console.log(error, response, body); - res.json(JSON.parse(body)); - }); + request( RestResource.urls[RestResource.useversion], function (error, response, body) { + console.log( error, response, body ); + res.json( JSON.parse( body ) ); + } ); }, //### v1get //I handle forwarding requests to the www.myappmatrix.com v1 api server and handling the results. v1get: function (req, res, next) { - var url = RestResource.urls[RestResource.useversion] + '/Api/getall/' + req.param('model') + '?appid=' + req.param('appid'); + var url = RestResource.urls[RestResource.useversion] + '/Api/getall/' + req.param( 'model' ) + '?appid=' + req.param( 'appid' ); - console.log('URL', url.debug); + console.log( 'URL', url.debug ); var options = { url: url, qs: { - appid: req.param('appid') + appid: req.param( 'appid' ) }, headers: { Authorization: 'Basic: bXk6ZnJlZA==' } }; - if (req.param('appid')) { - options.qs['appid'] = String(req.param('appid')); + if (req.param( 'appid' )) { + options.qs['appid'] = String( req.param( 'appid' ) ); } - request(options, function (error, response, body) { + request( options, function (error, response, body) { if (!error) { try { - res.json(JSON.parse(body).results); + res.json( JSON.parse( body ).results ); } catch (e) { - console.log(e); - res.json(Array({ + console.log( e ); + res.json( Array( { status: false, message: 'There was an error parsing the data.' - })); + } ) ); } } - }); + } ); }, //### v1method //I handle forwarding method requests to a v1 api server and handling the results. v1method: function (req, res, next) { - var url = RestResource.urls[RestResource.useversion] + '/' + req.param('method'); + var url = RestResource.urls[RestResource.useversion] + '/' + req.param( 'method' ); var options = { url: url, @@ -179,33 +183,33 @@ var RestResource = { options.qs = {} - if (req.param('appid')) { - options.qs['appid'] = String(req.param('appid')); + if (req.param( 'appid' )) { + options.qs['appid'] = String( req.param( 'appid' ) ); } - request(options, function (error, response, body) { + request( options, function (error, response, body) { if (!error) { try { - res.json(JSON.parse(body).results); + res.json( JSON.parse( body ).results ); } catch (e) { - console.log(e); - res.json(Array({ + console.log( e ); + res.json( Array( { status: false, message: 'There was an error parsing the data.' - })); + } ) ); } } - }); + } ); }, //### v1add //I handle forwarding post requests to a v1 api server. v1add: function (req, res, next) { RestResource.version = 'v1'; - var url = RestResource.urls[RestResource.useversion] + '/' + req.param('collection'); + var url = RestResource.urls[RestResource.useversion] + '/' + req.param( 'collection' ); var method = 'POST'; - if (req.param('id')) { + if (req.param( 'id' )) { method = 'PUT'; - url += '/' + req.param('id'); + url += '/' + req.param( 'id' ); } var options = { @@ -219,54 +223,54 @@ var RestResource = { options.qs = {} - if (req.param('appid')) { - options.qs['appid'] = String(req.param('appid')); + if (req.param( 'appid' )) { + options.qs['appid'] = String( req.param( 'appid' ) ); } - console.log(url); + console.log( url ); - request(options, function (error, response, body) { + request( options, function (error, response, body) { if (!error) { try { - res.json(body); + res.json( body ); } catch (e) { - console.log(e); - res.json(Array({ + console.log( e ); + res.json( Array( { status: false, message: 'There was an error parsing the data.' - })); + } ) ); } } - }); + } ); }, //### v2index //I handle displaying a message for the v2 api index. v2index: function (req, res, next) { RestResource.version = 'v2'; - res.json({ + res.json( { message: 'REST API Server ' + RestResource.useversion - }); + } ); }, findOne: function (req, table, query, success, fail) { //Open db - var db = new mongo.Db('angular-cms', new mongo.Server(config.db.host, config.db.port)); - db.open(function (err, db) { - db.collection(table, function (err, collection) { + var db = new mongo.Db( 'angular-cms', new mongo.Server( config.db.host, config.db.port ) ); + db.open( function (err, db) { + db.collection( table, function (err, collection) { var options = req.params.options || {}; - collection.findOne(query, options, function (err, cursor) { + collection.findOne( query, options, function (err, cursor) { if (cursor != null) { - success(cursor); + success( cursor ); } else { err = "No data found!"; - fail(err); + fail( err ); } db.close(); - }); - }); - }); + } ); + } ); + } ); }, /** * //### login @@ -277,7 +281,7 @@ var RestResource = { */ login: function (req, res, next) { var query = {}; - console.log(req.body); + console.log( req.body ); //TODO: Need to make this externalized. if (req.body.username) { @@ -288,31 +292,29 @@ var RestResource = { } //TODO: Hashing on client side - query.password = hashPassword(req.body.password, req.body.email); + query.password = hashPassword( req.body.password, req.body.email ); - console.log('Login Query: ', query); + console.log( 'Login Query: ', query ); var deferred = new Deferred(); var userFound = false; - RestResource.findOne(req, 'users', query, function (u) { + RestResource.findOne( req, 'users', query, function (u) { userFound = true; - res.jsonp(200, { + res.jsonp( 200, { success: true, result: u - }); + } ); }, function (error) { userFound = false; - res.jsonp(404, { + res.jsonp( 404, { status: false, error: true, message: 'Invalid email/password.' - }); - - - }); + } ); + } ); }, /** @@ -328,67 +330,65 @@ var RestResource = { email: req.body.email }; + data.password = hashPassword( req.body.password, req.body.email ), + console.log( String( "Register user" ).debug, req.body ); - data.password = hashPassword(req.body.password, req.body.email), - console.log(String("Register user").debug, req.body); - - - RestResource.findOne(req, 'users', query, function (u) { + RestResource.findOne( req, 'users', query, function (u) { user = u; - res.jsonp(404, { + res.jsonp( 404, { status: false, message: MESSAGES.USER_REGISTRATION_EXISTS - }); + } ); }, function (error) { user = null; - var db = new mongo.Db(config.db.name, new mongo.Server(config.db.host, config.db.port, {safe: true})); - db.open(function (err, db) { - db.collection('users', function (err, collection) { - collection.insert(data, function (err, docs) { - console.log(err, docs); + var db = new mongo.Db( config.db.name, new mongo.Server( config.db.host, config.db.port, {safe: true} ) ); + db.open( function (err, db) { + db.collection( 'users', function (err, collection) { + collection.insert( data, function (err, docs) { + console.log( err, docs ); if (!err) { - res.header('Content-Type', 'application/json'); - res.jsonp(200, { + res.header( 'Content-Type', 'application/json' ); + res.jsonp( 200, { status: true, message: MESSAGES.USER_REGISTRATION_SUCCESS, user: req.body - }); + } ); } else { - res.jsonp(404, { + res.jsonp( 404, { status: false, message: MESSAGES.USER_REGISTRATION_ERROR - }); - console.log(error.warn); + } ); + console.log( error.warn ); } db.close(); - }); - }); - }); + } ); + } ); + } ); - }); + } ); }, session: function (req, res, next) { }, insert: function (collection, data) { - console.log(data); + console.log( data ); var deferred = new Deferred(); //Open db - var db = new mongo.Db(config.db.name, new mongo.Server(config.db.host, config.db.port, {safe: false})); - db.open(function (err, db) { - db.collection('users', function (err, collection) { - collection.insert(data, function (err, docs) { - console.log(err, docs); + var db = new mongo.Db( config.db.name, new mongo.Server( config.db.host, config.db.port, {safe: false} ) ); + db.open( function (err, db) { + db.collection( 'users', function (err, collection) { + collection.insert( data, function (err, docs) { + console.log( err, docs ); if (!err) { - deferred.resolve(true); + deferred.resolve( true ); } else { - deferred.reject(false); + deferred.reject( false ); } db.close(); - }); - }); - }); + } ); + } ); + } ); return deferred.promise; }, //### upload @@ -396,11 +396,11 @@ var RestResource = { upload: function (req, res, next) { var appid = 'public'; - if (req.param('appid')) { - appid = String(req.param('appid')); + if (req.param( 'appid' )) { + appid = String( req.param( 'appid' ) ); } - console.log(req.files) + console.log( req.files ) //Handle if dynamic filenames are enabled var tmp_filename = req.files.file.name || 'tmp_name'; @@ -419,26 +419,26 @@ var RestResource = { } //Log the vars - console.log(x1, x2, y1, y2, height, width, thumb_path); + console.log( x1, x2, y1, y2, height, width, thumb_path ); //Orignal image - console.log(String('Temp Path: ' + tmp_path).warn); - console.log(String('Target Dir: ' + target_dir).warn); - console.log(String('Target Path: ' + target_path).warn); + console.log( String( 'Temp Path: ' + tmp_path ).warn ); + console.log( String( 'Target Dir: ' + target_dir ).warn ); + console.log( String( 'Target Path: ' + target_path ).warn ); //Thumbnail image - console.log(String('Original File: ' + filename).debug); - console.log(String('Original File Path: ' + target_path).debug); - console.log(String('Thumb Dir: ' + thumb_dir).debug); - console.log(String('Thumb Path: ' + thumb_path).debug); + console.log( String( 'Original File: ' + filename ).debug ); + console.log( String( 'Original File Path: ' + target_path ).debug ); + console.log( String( 'Thumb Dir: ' + thumb_dir ).debug ); + console.log( String( 'Thumb Path: ' + thumb_path ).debug ); //Create the directory and move the file to that directory - fs.mkdir(target_dir, 0777, function (e) { + fs.mkdir( target_dir, 0777, function (e) { //Rename the file - fs.rename(tmp_path, target_path, function (err) { + fs.rename( tmp_path, target_path, function (err) { if (err) { - console.error('File Rename Error:', err); + console.error( 'File Rename Error:', err ); } ; @@ -446,7 +446,7 @@ var RestResource = { //rackspaceUpload(target_path, target_dir, filename); //Create the thumb directory - fs.mkdir(thumb_dir, 0777, function (e) { + fs.mkdir( thumb_dir, 0777, function (e) { //Create the thumbnail from the default image var imgOptions = { @@ -460,9 +460,8 @@ var RestResource = { }; //Resize the image - easyimg.resize(imgOptions, function (e) { - console.log('easyimg', imgOptions, e); - + easyimg.resize( imgOptions, function (e) { + console.log( 'easyimg', imgOptions, e ); //Upload thumb to rackspace /* @@ -491,19 +490,19 @@ var RestResource = { }; //Output the results - res.send(json); - }); - }); - }); - }); + res.send( json ); + } ); + } ); + } ); + } ); }, //### imageCrop //I handle processing a uploaded image, cropping it and moving it to the proper directory, and uploaded to Rackspace Cloud Files. imageCrop: function (req, res, next) { var appid = null; - if (req.param('appid')) { - appid = String(req.param('appid')); + if (req.param( 'appid' )) { + appid = String( req.param( 'appid' ) ); } //Handle if dynamic filenames are enabled @@ -523,18 +522,18 @@ var RestResource = { } //Dev logger - console.log(x1, x2, y1, y2, height, width, thumb_path); - console.log(String('Target Path: ' + target_path).warn); - console.log(String('Target Dir: ' + target_dir).warn); - console.log(String('Temp Path: ' + tmp_path).warn); + console.log( x1, x2, y1, y2, height, width, thumb_path ); + console.log( String( 'Target Path: ' + target_path ).warn ); + console.log( String( 'Target Dir: ' + target_dir ).warn ); + console.log( String( 'Temp Path: ' + tmp_path ).warn ); //Create the directory and move the file to that directory - fs.mkdir(target_dir, 0777, function (e) { + fs.mkdir( target_dir, 0777, function (e) { //Rename the file - fs.rename(tmp_path, target_path, function (err) { + fs.rename( tmp_path, target_path, function (err) { if (err) { - console.error('File Rename Error:', err); + console.error( 'File Rename Error:', err ); } ; @@ -550,17 +549,17 @@ var RestResource = { }; //Create the thumb directory and resize the image - fs.mkdir(thumb_dir, 0777, function (e) { + fs.mkdir( thumb_dir, 0777, function (e) { //Resize the image - easyimg.resize(imgOptions, function (e) { - console.log('easyimg', e); - }); - }); + easyimg.resize( imgOptions, function (e) { + console.log( 'easyimg', e ); + } ); + } ); //unlink the file - fs.unlink(tmp_path, function () { + fs.unlink( tmp_path, function () { if (err) { - console.error('File Unlink Error: ', err); + console.error( 'File Unlink Error: ', err ); } else { @@ -580,81 +579,81 @@ var RestResource = { results: req.files, appid: appid }; - res.send(json); + res.send( json ); } - }); - }); - }); + } ); + } ); + } ); }, //### get //I handle gathering records dynamically from a call to the v2 api. get: function (req, res, next) { - var query = req.query.query ? JSON.parse(req.query.query) : {}; + var query = req.query.query ? JSON.parse( req.query.query ) : {}; var self = this; // Providing an id overwrites giving a query in the URL if (req.params.id) { query = { - '_id': new BSON.ObjectID(req.params.id) + '_id': new BSON.ObjectID( req.params.id ) }; } //Pass a appid param to get all records for that appid - if (req.param('appid')) { - query['appid'] = String(req.param('appid')); + if (req.param( 'appid' )) { + query['appid'] = String( req.param( 'appid' ) ); } var options = req.params.options || {}; //Test array of legal query params var test = ['limit', 'sort', 'fields', 'skip', 'hint', 'explain', 'snapshot', 'timeout']; //loop and test for (o in req.query) { - if (test.indexOf(o) >= 0) { + if (test.indexOf( o ) >= 0) { options[o] = req.query[o]; } } //Log for interal usage - console.log('query', query, 'options', options); + console.log( 'query', query, 'options', options ); //new database instance - var db = new mongo.Db(req.params.db, new mongo.Server(config.db.host, config.db.port, { + var db = new mongo.Db( req.params.db, new mongo.Server( config.db.host, config.db.port, { auto_reconnect: true, safe: true - })); + } ) ); //open database - db.open(function (err, db) { + db.open( function (err, db) { if (err) { - console.log(err); + console.log( err ); } else { //prep collection - db.collection(req.params.collection, function (err, collection) { + db.collection( req.params.collection, function (err, collection) { //query - collection.find(query, options, function (err, cursor) { - cursor.toArray(function (err, docs) { - console.log(docs); + collection.find( query, options, function (err, cursor) { + cursor.toArray( function (err, docs) { + console.log( docs ); if (err) { - console.log(err); + console.log( err ); } else { var result = []; if (req.params.id) { if (docs.length > 0) { result = docs[0]; - res.header('Content-Type', 'application/json'); - res.jsonp(200, result); + res.header( 'Content-Type', 'application/json' ); + res.jsonp( 200, result ); } else { - res.jsonp(404, 'Not found'); + res.jsonp( 404, 'Not found' ); //res.send(404); } } else { - docs.forEach(function (doc) { - result.push(doc); - }); - res.header('Content-Type', 'application/json'); - res.jsonp(200, result); + docs.forEach( function (doc) { + result.push( doc ); + } ); + res.header( 'Content-Type', 'application/json' ); + res.jsonp( 200, result ); } db.close(); } - }); - }); - }); + } ); + } ); + } ); } - }); + } ); }, //### add //I handle adding a record to the database. @@ -664,81 +663,80 @@ var RestResource = { var response = {}; if (data) { - var db = new mongo.Db(req.params.db, new mongo.Server(config.db.host, config.db.port, { + var db = new mongo.Db( req.params.db, new mongo.Server( config.db.host, config.db.port, { auto_reconnect: true, safe: true - })); - db.open(function (err, db) { + } ) ); + db.open( function (err, db) { if (err) { - console.log(err); + console.log( err ); } else { - db.collection(req.params.collection, function (err, collection) { - collection.count(function (err, count) { - console.log("There are " + count + " records."); - }); - }); + db.collection( req.params.collection, function (err, collection) { + collection.count( function (err, count) { + console.log( "There are " + count + " records." ); + } ); + } ); - db.collection(req.params.collection, function (err, collection) { + db.collection( req.params.collection, function (err, collection) { //Check if the posted data is an array, if it is, then loop and insert each document if (data.length) { //insert all docs for (var i = 0; i < data.length; i++) { var obj = data[i]; - console.log(obj); - collection.insert(obj, function (err, docs) { - results.push(obj); - }); + console.log( obj ); + collection.insert( obj, function (err, docs) { + results.push( obj ); + } ); } response.results = results; db.close(); - res.header('Content-Type', 'application/json'); - res.jsonp(200, response); + res.header( 'Content-Type', 'application/json' ); + res.jsonp( 200, response ); } else { - collection.insert(req.body, function (err, docs) { + collection.insert( req.body, function (err, docs) { db.close(); if (!err) { response.status = 'ok'; response.data = docs[0]; //res.header('Location', '/' + req.params.db + '/' + req.params.collection + '/' + docs[0]._id.toHexString()); - res.header('Content-Type', 'application/json'); - res.send(response, 201); + res.header( 'Content-Type', 'application/json' ); + res.send( response, 201 ); } - }); + } ); } - }); + } ); } - }); + } ); } else { - res.header('Content-Type', 'application/json'); - res.send('{"ok":0}', 200); + res.header( 'Content-Type', 'application/json' ); + res.send( '{"ok":0}', 200 ); } }, //### edit //I handle edit: function (req, res, next) { var spec = { - '_id': new BSON.ObjectID(req.params.id) + '_id': new BSON.ObjectID( req.params.id ) }; - var db = new mongo.Db(req.params.db, new mongo.Server(config.db.host, config.db.port, { + var db = new mongo.Db( req.params.db, new mongo.Server( config.db.host, config.db.port, { 'auto_reconnect': true, 'safe': true - })); - - console.log('Upating: ' + JSON.stringify(req.body).warn); + } ) ); + console.log( 'Upating: ' + JSON.stringify( req.body ).warn ); - db.open(function (err, db) { - db.collection(req.params.collection, function (err, collection) { - collection.update(spec, req.body, true, function (err, docs) { - res.header('Location', '/' + req.params.db + '/' + req.params.collection + '/' + req.params.id); - res.header('Content-Type', 'application/json'); - res.send('{"ok":1}'); + db.open( function (err, db) { + db.collection( req.params.collection, function (err, collection) { + collection.update( spec, req.body, true, function (err, docs) { + res.header( 'Location', '/' + req.params.db + '/' + req.params.collection + '/' + req.params.id ); + res.header( 'Content-Type', 'application/json' ); + res.send( '{"ok":1}' ); db.close(); - console.log('Location', '/' + req.params.db + '/' + req.params.collection + '/' + req.params.id); - }); - }); - }); + console.log( 'Location', '/' + req.params.db + '/' + req.params.collection + '/' + req.params.id ); + } ); + } ); + } ); }, //### view //I handle @@ -748,37 +746,37 @@ var RestResource = { //I handle destroy: function (req, res, next) { var params = { - _id: new BSON.ObjectID(req.params.id) + _id: req.params.id }; - console.log('Delete by id ' + req.params); - var db = new mongo.Db(req.params.db, new mongo.Server(config.db.host, config.db.port, { + console.log( 'Delete by id ' + req.params ); + var db = new mongo.Db( req.params.db, new mongo.Server( config.db.host, config.db.port, { auto_reconnect: true, safe: true - })); - db.open(function (err, db) { - db.collection(req.params.collection, function (err, collection) { - console.log('found ', collection.collectionName, params); - collection.remove(params, function (err, docs) { + } ) ); + db.open( function (err, db) { + db.collection( req.params.collection, function (err, collection) { + console.log( 'found ', collection.collectionName, params ); + collection.remove( params, function (err, docs) { if (!err) { - res.header('Content-Type', 'application/json'); - res.send('{"ok":1}'); + res.header( 'Content-Type', 'application/json' ); + res.send( '{"ok":1}' ); db.close(); } else { - console.log(err); + console.log( err ); } - }); - }); - }); + } ); + } ); + } ); }, //### cloudupload //I handle cloudupload: function (req, res, next) { var appid = null, results = null; - if (req.param('appid')) { - appid = String(req.param('appid')); + if (req.param( 'appid' )) { + appid = String( req.param( 'appid' ) ); } - console.log(req.files); + console.log( req.files ); }, /* @@ -823,45 +821,43 @@ var RestResource = { //### v2 API //v2 mongo rest api -app.get('/api/v2', RestResource.v2index); -app.post('/api/v1/imagecrop', RestResource.imageCrop); -app.post('/api/v2/cloudupload', RestResource.cloudupload); +app.get( '/api/v2', RestResource.v2index ); +app.post( '/api/v1/imagecrop', RestResource.imageCrop ); +app.post( '/api/v2/cloudupload', RestResource.cloudupload ); -app.post('/api/v2/upload', RestResource.upload); +app.post( '/api/v2/upload', RestResource.upload ); //Always users table -app.post('/api/v2/users/login', bodyParser.json(), RestResource.login); -app.post('/api/v2/users/register', bodyParser.json(), RestResource.register); -app.post('/api/v2/users/session', bodyParser.json(), RestResource.session); - - -app.get('/api/v2/:db/:collection/:id?', RestResource.get); -app.post('/api/v2/:db/:collection', bodyParser.json(), RestResource.add); -app.put('/api/v2/:db/:collection/:id', bodyParser.json(), RestResource.edit); -app.delete('/api/v2/:db/:collection/:id', RestResource.destroy); +app.post( '/api/v2/users/login', bodyParser.json(), RestResource.login ); +app.post( '/api/v2/users/register', bodyParser.json(), RestResource.register ); +app.post( '/api/v2/users/session', bodyParser.json(), RestResource.session ); +app.get( '/api/v2/:db/:collection/:id?', RestResource.get ); +app.post( '/api/v2/:db/:collection', bodyParser.json(), RestResource.add ); +app.put( '/api/v2/:db/:collection/:id', bodyParser.json(), RestResource.edit ); +app.delete( '/api/v2/:db/:collection/:id', RestResource.destroy ); //Readme -var markdown = require("markdown").markdown; -app.get('/api/v2/README', function (res, req) { +var markdown = require( "markdown" ).markdown; +app.get( '/api/v2/README', function (res, req) { var localPath = __dirname + '/../README.md'; - fs.readFile(localPath, 'utf8', function (err, data) { + fs.readFile( localPath, 'utf8', function (err, data) { if (err) { - req.end('There was an error.'); - return console.log(err); + req.end( 'There was an error.' ); + return console.log( err ); } else { - req.writeHead(200, { + req.writeHead( 200, { "Content-Type": 'utf8', "Content-Length": data.length - }); - req.end(data); + } ); + req.end( data ); } - console.log(data); + console.log( data ); - }); -}); + } ); +} ); /* ======================[ @TODO: Other Rest Utility Methods ]====================== */ //### rackspaceUpload @@ -870,64 +866,61 @@ function rackspaceUpload(localPath, targetPath, filename, cb) { }; - //### getFile //Get file contents from a file. function getFile(localPath, mimeType, res) { - fs.readFile(localPath, 'utf8', function (err, data) { + fs.readFile( localPath, 'utf8', function (err, data) { if (err) { - res.end('There was an error.'); - return console.log(err); + res.end( 'There was an error.' ); + return console.log( err ); } else { - res.writeHead(200, { + res.writeHead( 200, { "Content-Type": 'utf8', "Content-Length": data.length - }); - res.end(data); + } ); + res.end( data ); } - console.log(data); + console.log( data ); - }); + } ); }; //### writeFile //Write contents to a file function writeFile(localPath, contents) { // create a stream, and create the file if it doesn't exist - stream = fs.createWriteStream(localPath); - console.log('writeFile', localPath); - stream.on("open", function () { + stream = fs.createWriteStream( localPath ); + console.log( 'writeFile', localPath ); + stream.on( "open", function () { // write to and close the stream at the same time - stream.end(contents, 'utf-8'); - res.end(html); - }); + stream.end( contents, 'utf-8' ); + res.end( html ); + } ); }; //### modules //Gather all of the files and folders in the app/modules directory -app.get('/api/v2/modules', function (req, res) { - var result = fs.readdir('./app/cms-content', function (err, files) { - console.log(files); - res.header('Content-Type', 'application/json'); - res.jsonp(200, files); - }); -}); +app.get( '/api/v2/modules', function (req, res) { + var result = fs.readdir( './app/cms-content', function (err, files) { + console.log( files ); + res.header( 'Content-Type', 'application/json' ); + res.jsonp( 200, files ); + } ); +} ); //Write the pass.json file to the file system -app.get('/api/v2/smartpass/sign', function (req, res) { - var result = writeFile(req.params('path'), req.params('contents')); - res.header('Content-Type', 'application/json'); - res.jsonp(200, result); -}); - +app.get( '/api/v2/smartpass/sign', function (req, res) { + var result = writeFile( req.params( 'path' ), req.params( 'contents' ) ); + res.header( 'Content-Type', 'application/json' ); + res.jsonp( 200, result ); +} ); var config = {}; var publicPath = config.publicDir; var uploadsTmpDir = config.uploadsTmpDir; var uploadDestDir = config.uploadDestDir; - //Export to public api exports.rest = { RestResource: RestResource, @@ -935,8 +928,8 @@ exports.rest = { express: express, init: function (options) { - console.log('email: admin@email.com '.verbose); - console.log('password: admin1234'.verbose) + console.log( 'email: admin@email.com '.verbose ); + console.log( 'password: admin1234'.verbose ) config = options; @@ -944,30 +937,28 @@ exports.rest = { */ //### Express Config //Configure the express app server. - app.configure(function () { - app.set("view options", {layout: false, pretty: true}); + app.configure( function () { + app.set( "view options", {layout: false, pretty: true} ); - app.use(express.static(config.staticDir)); - app.use(express.directory(config.publicDir)); + app.use( express.static( config.staticDir ) ); + app.use( express.directory( config.publicDir ) ); - app.use(bodyParser.urlencoded({ extended: false })); + app.use( bodyParser.urlencoded( {extended: false} ) ); // parse application/json - app.use(bodyParser.json()); - - app.use("jsonp callback", true); - app.use('/api/upload', upload.fileHandler()); + app.use( bodyParser.json() ); + app.use( "jsonp callback", true ); + app.use( '/api/upload', upload.fileHandler() ); - app.use(function (req, res, next) { - console.log('%s %s', req.method, req.body, req.url); + app.use( function (req, res, next) { + console.log( '%s %s', req.method, utils.inspect( req.body, {colors: true} ), req.url ); next(); - }); - }); - + } ); + } ); - app.listen(options.port || process.env.PORT, function () { - console.log(String('Node.js REST server listening on port: ' + options.port).verbose); - }); + app.listen( options.port || process.env.PORT, function () { + console.log( String( 'Node.js REST server listening on port: ' + options.port ).verbose ); + } ); return app; } diff --git a/routes/socketserver.js b/routes/socketserver.js index bf5afb0..188ae37 100644 --- a/routes/socketserver.js +++ b/routes/socketserver.js @@ -18,126 +18,124 @@ //Start the websocket server //SocketServer.init(proxyServer); -var sio = require('socket.io'); +var sio = require( 'socket.io' ); //Hold the ncmss of events that this socket server listens for and emits var CmsSocket = { - events : { - session : { - pageView : 'cms:session:pageView', - hashChange : 'cms:session:hashChange', - login : 'cms:session:login', - logout : 'cms:session:logout' + events: { + session: { + pageView: 'cms:session:pageView', + hashChange: 'cms:session:hashChange', + login: 'cms:session:login', + logout: 'cms:session:logout' }, - server : { - message : 'cms:server:message', - connected : 'cms:server:connect', - disconnected : 'cms:server:disconnect' + server: { + message: 'cms:server:message', + connected: 'cms:server:connect', + disconnected: 'cms:server:disconnect' }, - client : { - message : 'cms:client:message', - connected : 'cms:client:connect', - disconnected : 'cms:client:disconnect' + client: { + message: 'cms:client:message', + connected: 'cms:client:connect', + disconnected: 'cms:client:disconnect' } } }; var SocketServer = { - connections : [], - events : { - session : { - pageView : 'cms:session:pageView', - hashChange : 'cms:session:hashChange', - login : 'cms:session:login', - logout : 'cms:session:logout' + connections: [], + events: { + session: { + pageView: 'cms:session:pageView', + hashChange: 'cms:session:hashChange', + login: 'cms:session:login', + logout: 'cms:session:logout' }, - server : { - message : 'cms:server:message', - connected : 'cms:server:connect', - disconnected : 'cms:server:disconnect' + server: { + message: 'cms:server:message', + connected: 'cms:server:connect', + disconnected: 'cms:server:disconnect' }, - client : { - message : 'cms:client:message', - connected : 'cms:client:connect', - disconnected : 'cms:client:disconnect' + client: { + message: 'cms:client:message', + connected: 'cms:client:connect', + disconnected: 'cms:client:disconnect' } }, //###init(app) //I setup the socket server and listen for any routing requests from the express app. - init : function(app) { - var self = this, - io = sio.listen(app); - io.configure(function() { - io.set('authorization', function(handshakeData, callback) { - if(handshakeData.xdomain) { - callback('Cross-domain connections are not allowed'); + init: function (app) { + var self = this; + + io = sio.listen( app ); + io.configure( function () { + io.set( 'authorization', function (handshakeData, callback) { + if (handshakeData.xdomain) { + callback( 'Cross-domain connections are not allowed' ); } else { - callback(null, true); + callback( null, true ); } - }); - }); + } ); + } ); //Store a list of the connected clients var connections = []; //Handle when a client is connected. - io.sockets.on('connection', function(socket) { + io.sockets.on( 'connection', function (socket) { //push to connections array - self.connections.push(socket); + self.connections.push( socket ); //Publish the server connected event - io.sockets.emit(CmsSocket.events.server.connected, { - data : self.connections.length - }); + io.sockets.emit( CmsSocket.events.server.connected, { + data: self.connections.length + } ); //Listen for client connected - socket.on(CmsSocket.events.client.connected, function(msg) { - console.log(CmsSocket.events.client.connected, msg); - }); - + socket.on( CmsSocket.events.client.connected, function (msg) { + console.log( CmsSocket.events.client.connected, msg ); + } ); //Listen for any messages from the client - socket.on(CmsSocket.events.client.message, function(content) { + socket.on( CmsSocket.events.client.message, function (content) { - console.log(CmsSocket.events.client.message, JSON.stringify(content).debug); + console.log( CmsSocket.events.client.message, JSON.stringify( content ).debug ); //Broadcast the event - socket.emit(CmsSocket.events.server.message, { - id : socket.id, - data : content - }); - socket.broadcast.emit(CmsSocket.events.server.message, { - id : socket.id, - data : content - }); - }); + socket.emit( CmsSocket.events.server.message, { + id: socket.id, + data: content + } ); + socket.broadcast.emit( CmsSocket.events.server.message, { + id: socket.id, + data: content + } ); + } ); //Listen for any pageView events from the client - socket.on(CmsSocket.events.session.pageView, function(message) { - console.log(CmsSocket.events.session.pageView + message); + socket.on( CmsSocket.events.session.pageView, function (message) { + console.log( CmsSocket.events.session.pageView + message ); ip = socket.handshake.address.address; url = message; //Broadcast the event - io.sockets.emit(CmsSocket.events.session.pageView, { - 'connections' : Object.keys(io.connected).length, - 'ip' : ip, - 'url' : url, - 'xdomain' : socket.handshake.xdomain, - 'timestamp' : new Date() - }); - }); - - + io.sockets.emit( CmsSocket.events.session.pageView, { + 'connections': Object.keys( io.connected ).length, + 'ip': ip, + 'url': url, + 'xdomain': socket.handshake.xdomain, + 'timestamp': new Date() + } ); + } ); //handle disconnections - socket.on('disconnect', function() { - console.log("Socket disconnected"); + socket.on( 'disconnect', function () { + console.log( "Socket disconnected" ); - io.sockets.emit('cms:session:pageview', { - 'connections' : Object.keys(io.connected).length - }); + io.sockets.emit( 'cms:session:pageview', { + 'connections': Object.keys( io.connected ).length + } ); - }); - }); - return this; + } ); + } ); + return this; } }; diff --git a/server.js b/server.js index 21d21fe..352d04f 100755 --- a/server.js +++ b/server.js @@ -20,7 +20,7 @@ colors.setTheme({ error: 'red' }); -/* +/* */ console.log("this is an silly".silly); console.log("this is an input".input); console.log("this is an verbose".verbose); @@ -31,7 +31,7 @@ colors.setTheme({ console.log("this is an debug".debug); console.log("this is an error".error); console.log("this is a warning".warn); - */ + /** * @TODO - HTTPS Key and Cert @@ -41,6 +41,7 @@ colors.setTheme({ var httpsKey = fs.readFileSync('./config/apache.key').toString(); var httpsCert = fs.readFileSync('./config/apache.crt').toString(); + /** * @TODO - Proxy Options * This object holds options used for creating a proxy server. @@ -64,6 +65,8 @@ var options = { hostncmsOnly: true, router: {} }; + + /** * @TODO - Externalize configuration for server and proxy, mongodb */ @@ -75,10 +78,7 @@ var rest = require('./routes/rest').rest; //Socket server var socket = require('./routes/socketserver').SocketServer; -//Initialize socket server and rest server -socket.init( - rest.init(config) -); + //Create proxy server and proxy requests @@ -113,13 +113,22 @@ proxyServer = httpProxy.createServer(options, function (req, res, proxy) { } }); +//Initialize socket server and rest server +socket.init(proxyServer); + + +config.staticDir = __dirname + '/app'; +config.publicDir = __dirname + '/.tmp'; +//config.publicDir = __dirname + '/www'; +rest.init(config); + //Start the proxy server proxyServer.listen(options.port); /** * Test Email - */ + var email = require("emailjs"); var server = email.server.connect({ user: config.email.username, @@ -140,21 +149,6 @@ var message = { ] }; -// send the message and get a callback with an error or details of the message that was sent -//server.send(message, function(err, message) { console.log(err || message); }); - -// you can continue to send more messages with successive calls to 'server.send', -// they will be queued on the same smtp connection - -// or you can create a new server connection with 'email.server.connect' -// to asynchronously send individual emails instead of a queue - -/* - * fs.readFile(req.files.displayImage.path, function (err, data) { - // ... - var newPath = __dirname + "/uploads/uploadedFileName"; - fs.writeFile(newPath, data, function (err) { - res.redirect("back"); - }); - });*/ +server.send(message, function(err, message) { console.log(err || message); }); +*/ diff --git a/test/protractor/App.js b/test/protractor/App.js index baba5b7..2233513 100644 --- a/test/protractor/App.js +++ b/test/protractor/App.js @@ -1,54 +1,54 @@ - -/* - App.coffee - - This is the protractor spec that will test the different areas of the application. +/** + * This is the protractor spec that will test the different areas of the application. */ -var UsersPage = function() { - - this.newUserBtn = element(by.buttonText('New User')); - this.submitBtn = element(by.buttonText('Submit')); +/** + * UsersPage - This page object controls actions on the /users page. + * @constructor + */ +var UsersPage = function () { + this.newUserBtn = element( by.buttonText( 'New User' ) ); + this.submitBtn = element( by.buttonText( 'Submit' ) ); this.inputs = { - email: element(protractor.By.model('user.email')), - username: element(protractor.By.model('user.username')), - password: element(protractor.By.model('user.password')), - name: element(protractor.By.model('user.meta.name')), - summary: element(protractor.By.model('user.meta.summary')) + email: element( protractor.By.model( 'user.email' ) ), + username: element( protractor.By.model( 'user.username' ) ), + password: element( protractor.By.model( 'user.password' ) ), + name: element( protractor.By.model( 'user.meta.name' ) ), + summary: element( protractor.By.model( 'user.meta.summary' ) ) }; - this.get = function() { - browser.get('http://localhost:9000/#/users'); + this.get = function () { + browser.get( 'http://localhost:9000/#/users' ); }; - this.setForm = function(email, username, password, name, summary) { + this.setForm = function (email, username, password, name, summary) { this.newUserBtn.click(); - browser.sleep(500); - this.inputs.username.sendKeys(username); - this.inputs.email.sendKeys(email); - this.inputs.password.sendKeys(password); - this.inputs.name.sendKeys(name); - this.inputs.summary.sendKeys(summary); + browser.sleep( 500 ); + this.inputs.username.sendKeys( username ); + this.inputs.email.sendKeys( email ); + this.inputs.password.sendKeys( password ); + this.inputs.name.sendKeys( name ); + this.inputs.summary.sendKeys( summary ); this.submitBtn.click(); - browser.sleep(1000); + browser.sleep( 1000 ); }; }; -describe('Angular-CMS', function() { +describe( 'Angular-CMS', function () { var usersPage = null; - describe('Users Page:', function() { - beforeEach(function() { + describe( 'Users Page:', function () { + beforeEach( function () { usersPage = new UsersPage(); usersPage.get(); - }); + } ); - it('should be able to create a new user', function() { + it( 'should be able to create a new user', function () { var username = 'protractor' + Date.now(); - usersPage.setForm(username+'@test.com', username, 'test', 'John Doe', 'This is an example user.'); - }); - }); -}); + usersPage.setForm( username + '@test.com', username, 'test', 'John Doe', 'This is an example user.' ); + } ); + } ); +} ); diff --git a/test/spec/services/cmssocketservice.coffee b/test/spec/services/cmssocketservice.coffee new file mode 100644 index 0000000..b3b0451 --- /dev/null +++ b/test/spec/services/cmssocketservice.coffee @@ -0,0 +1,14 @@ +'use strict' + +describe 'Service: cmsSocketService', -> + + # load the service's module + beforeEach module 'angularCmsApp' + + # instantiate service + cmsSocketService = {} + beforeEach inject (_cmsSocketService_) -> + cmsSocketService = _cmsSocketService_ + + it 'should do something', -> + expect(!!cmsSocketService).toBe true diff --git a/web.js b/web.js deleted file mode 100644 index 338d77a..0000000 --- a/web.js +++ /dev/null @@ -1,16 +0,0 @@ -// web.js -var express = require("express"); -var logfmt = require("logfmt"); -var httpProxy = require('http-proxy'); -var app = express(); -var port = process.env.PORT || 5000; - - -app.use(logfmt.requestLogger()); -app.use(express.static(__dirname + '/dist')); -app.use('/', express.directory('/dist')); - -var port = process.env.PORT || 5000; -app.listen(port, function() { - console.log("Listening on " + port); -});