diff --git a/Gruntfile.js b/Gruntfile.js index c8a2464..258d440 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,5 +1,7 @@ /* jshint camelcase:false */ var fs = require('fs'); +var express = require('express'); +var cmsRouter = require('./routes/cms-router.js'); 'use strict'; // # Globbing @@ -11,6 +13,12 @@ var fs = require('fs'); * @TODO - Externalize configuration for server and proxy, mongodb */ +var startNodeServer = function(options, app){ + var app = express(); + var config = JSON.parse(fs.readFileSync('./config/config.json')); + var server = new cmsRouter.mount(config, app); +}; + var serverEndpoint = 'http://localhost:8181'; var proxyConfig = { proxy: { @@ -59,7 +67,7 @@ module.exports = function (grunt) { tasks: ['newer:copy:styles', 'autoprefixer'] }, scripts: { - files: ['<%= yeoman.app %>/scripts/{,**/}*.js'], + files: ['<%= yeoman.app %>/scripts/{,** /}*.js'], tasks: ['jshint:app'] }, gruntfile: { @@ -95,12 +103,7 @@ module.exports = function (grunt) { open: true, base: ['.tmp', '<%= yeoman.app %>'], middleware: function (connect, options) { - var express = require('express'); - var fs = require('fs'); - var cmsRouter = require('./routes/cms-router.js'); - var app = express(); - var config = JSON.parse(fs.readFileSync('./config/config.json')); - var server = new cmsRouter.mount(config, app); + startNodeServer(options, connect); return [ require('json-proxy').initialize(proxyConfig), mountFolder(connect, '.grunt'), diff --git a/app/index.html b/app/index.html index b363b7f..8b547f9 100755 --- a/app/index.html +++ b/app/index.html @@ -118,7 +118,8 @@ - + + @@ -138,6 +139,7 @@ + @@ -145,12 +147,14 @@ + - - - - - + + + + + + diff --git a/app/scripts/app.js b/app/scripts/app.js index b2ad642..a8cce99 100644 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -10,86 +10,83 @@ * Resize textarea automatically to the size of its text content. * * @example - - - -
{{text}}
-
-
+ + + +
{{text}}
+
+
*/ -var app; - -Parse.initialize("fYHs4Flnj7vgVHm9vaFiFTSKt5Mj2Bxf9e93mTOB", "QPFGBNHs0QQHFS54atV71oKppd3gTgaFfQIHP2VW"); - -app = angular.module('angularCmsApp', ['ngCookies', 'ngResource', 'ngSanitize', 'ngRoute', 'ngAnimate', 'mgcrea.ngStrap', 'fg']).config(function($routeProvider) { - var routeResolver; - routeResolver = { - delay: function($q, $timeout) { - var delay; - delay = $q.defer(); - $timeout(delay.resolve, 1000); - return delay.promise; - } - }; - return $routeProvider.when('/', { - templateUrl: 'views/main.html', - controller: 'MainCtrl' - }).when('/docs', { - templateUrl: 'views/docs.html', - controller: 'DocsCtrl' - }).when('/admin', { - templateUrl: 'views/admin.html', - controller: 'AdminCtrl' - }).when('/plugins', { - templateUrl: 'views/plugins.html', - controller: 'PluginsCtrl' - }).when('/themes', { - templateUrl: 'views/themes.html', - controller: 'ThemesCtrl' - }).when('/widgets', { - templateUrl: 'views/widgets.html', - controller: 'WidgetsCtrl' - }).when('/media', { - templateUrl: 'views/media.html', - controller: 'MediaCtrl' - }).when('/settings', { - templateUrl: 'views/settings.html', - controller: 'SettingsCtrl' - }).when('/users', { - templateUrl: 'views/users.html', - controller: 'UsersCtrl' - }).when('/login', { - templateUrl: 'views/login.html', - controller: 'LoginCtrl' - }).when('/register', { - templateUrl: 'views/register.html', - controller: 'RegisterCtrl' - }).when('/dashboard', { - templateUrl: 'views/dashboard.html', - controller: 'DashboardCtrl' - }).when('/profile', { - templateUrl: 'views/profile.html', - controller: 'ProfileCtrl' - }).when('/pages', { - templateUrl: 'views/pages.html', - controller: 'PagesCtrl', - resolve: { - pages: function(DataService) { - return DataService.fetch('pages').then(function(res) { - return res.data; - }); - } - } - }).when('/help', { - templateUrl: 'views/help.html', - controller: 'HelpCtrl' - }).when('/forgot-password', { - templateUrl: 'views/forgot-password.html', - controller: 'ForgotPasswordCtrl' - }).when('/register', { - templateUrl: 'views/register.html', - controller: 'RegisterCtrl' - }).otherwise({ - redirectTo: '/' - }); +Parse.initialize('fYHs4Flnj7vgVHm9vaFiFTSKt5Mj2Bxf9e93mTOB', 'QPFGBNHs0QQHFS54atV71oKppd3gTgaFfQIHP2VW'); +var app = angular.module('angularCmsApp', ['ngCookies', 'ngResource', 'ngSanitize', 'ngRoute', 'ngAnimate', 'mgcrea.ngStrap', 'fg']).config(function ($routeProvider) { + var routeResolver; + routeResolver = { + delay: function ($q, $timeout) { + var delay; + delay = $q.defer(); + $timeout(delay.resolve, 1000); + delay.promise; + } + }; + $routeProvider.when('/', { + templateUrl: 'views/main.html', + controller: 'MainCtrl' + }).when('/docs', { + templateUrl: 'views/docs.html', + controller: 'DocsCtrl' + }).when('/admin', { + templateUrl: 'views/admin.html', + controller: 'AdminCtrl' + }).when('/plugins', { + templateUrl: 'views/plugins.html', + controller: 'PluginsCtrl' + }).when('/themes', { + templateUrl: 'views/themes.html', + controller: 'ThemesCtrl' + }).when('/widgets', { + templateUrl: 'views/widgets.html', + controller: 'WidgetsCtrl' + }).when('/media', { + templateUrl: 'views/media.html', + controller: 'MediaCtrl' + }).when('/settings', { + templateUrl: 'views/settings.html', + controller: 'SettingsCtrl' + }).when('/users', { + templateUrl: 'views/users.html', + controller: 'UsersCtrl' + }).when('/login', { + templateUrl: 'views/login.html', + controller: 'LoginCtrl' + }).when('/register', { + templateUrl: 'views/register.html', + controller: 'RegisterCtrl' + }).when('/dashboard', { + templateUrl: 'views/dashboard.html', + controller: 'DashboardCtrl' + }).when('/profile', { + templateUrl: 'views/profile.html', + controller: 'ProfileCtrl' + }).when('/pages', { + templateUrl: 'views/pages.html', + controller: 'PagesCtrl', + resolve: { + pages: function (DataService) { + return DataService.fetch('pages').then(function (res) { + return res.data; + }); + } + } + }).when('/help', { + templateUrl: 'views/help.html', + controller: 'HelpCtrl' + }).when('/forgot-password', { + templateUrl: 'views/forgot-password.html', + controller: 'ForgotPasswordCtrl' + }).when('/register', { + templateUrl: 'views/register.html', + controller: 'RegisterCtrl' + }).otherwise({ + redirectTo: '/' + }); }); diff --git a/app/scripts/config.js b/app/scripts/config.js index cf37c9e..b18399e 100644 --- a/app/scripts/config.js +++ b/app/scripts/config.js @@ -1,47 +1,47 @@ window.Config = { baseurl: document.location.origin, - sitetitle: "angular-cms", - sitedesc: "This is the description", - sitebrand: "/images/angular-cms-brand.png", - sitecopy: "2014 ", - version: "0.1", - email: "jonniespratley@me.com", + sitetitle: 'angular-cms', + sitedesc: 'This is the description', + sitebrand: '/images/angular-cms-brand.png', + sitecopy: '2014 ', + version: '0.1', + email: 'jonniespratley@me.com', debug: true, feature: { - title: "angular-cms", - body: "A content management system of some sort." + title: 'angular-cms', + body: 'A content management system of some sort.' }, features: [ { id: 1, - title: "HTML5", - body: "Using HTML5 in every way to make a better user experience.", - image: "/images/feature-html5.png" + title: 'HTML5', + body: 'Using HTML5 in every way to make a better user experience.', + image: '/images/feature-html5.png' }, { id: 2, - title: "AngularJS", - body: "The client-side framework of choice is Angular, its a full-stack.", - image: "/images/feature-angular.png" + title: 'AngularJS', + body: 'The client-side framework of choice is Angular, its a full-stack.', + image: '/images/feature-angular.png' }, { id: 3, - title: "Twitter Bootstrap", - body: "The client-side UI of choice is Twitter Bootstrap 3.0.", - image: "/images/feature-bootstrap.png" + title: 'Twitter Bootstrap', + body: 'The client-side UI of choice is Twitter Bootstrap 3.0.', + image: '/images/feature-bootstrap.png' }, { id: 4, - title: "PhantomJS", - body: "Fully testable with Jasmine Karma Runner Unit e2e with PhantomJS.", - image: "/images/feature-phantomjs.png" + title: 'PhantomJS', + body: 'Fully testable with Jasmine Karma Runner Unit e2e with PhantomJS.', + image: '/images/feature-phantomjs.png' }, { id: 5, - title: "NodeJS", - body: "The server of choice is NodeJS, its fast and scalable.", - image: "/images/feature-nodejs.png" + title: 'NodeJS', + body: 'The server of choice is NodeJS, its fast and scalable.', + image: '/images/feature-nodejs.png' }, { id: 6, - title: "MongoDB", - body: "The database of choice is Mongo, its fast and scalable.", - image: "/images/feature-mongodb.png" + title: 'MongoDB', + body: 'The database of choice is Mongo, its fast and scalable.', + image: '/images/feature-mongodb.png' } ], session: { @@ -49,97 +49,97 @@ window.Config = { user: null }, layout: { - header: "views/_header.html", - sidebar: "views/_sidebar.html", - content: "views/_content.html", - footer: "views/_footer.html" + header: 'views/_header.html', + sidebar: 'views/_sidebar.html', + content: 'views/_content.html', + footer: 'views/_footer.html' }, - theme: "default", + theme: 'default', templates: { - compiled: "/dist/templates.html", - uncompiled: "/views" + compiled: '/dist/templates.html', + uncompiled: '/views' }, menu: { admin: [ { id: 1, - title: "Pages", - href: "/pages", - icon: "edit" + title: 'Pages', + href: '/pages', + icon: 'edit' }, { id: 1, - title: "Plugins", - href: "/plugins", - icon: "folder-open" + title: 'Plugins', + href: '/plugins', + icon: 'folder-open' }, { id: 1, - title: "Widgets", - href: "/widgets", - icon: "puzzle-piece" + title: 'Widgets', + href: '/widgets', + icon: 'puzzle-piece' }, { id: 1, - title: "Media", - href: "/media", - icon: "cloud-download" + title: 'Media', + href: '/media', + icon: 'cloud-download' }, { id: 1, - title: "Users", - href: "/users", - icon: "group" + title: 'Users', + href: '/users', + icon: 'group' }, { id: 1, - title: "Themes", - href: "/themes", - icon: "camera" + title: 'Themes', + href: '/themes', + icon: 'camera' }, { id: 1, - title: "Settings", - href: "/settings", - icon: "cog" + title: 'Settings', + href: '/settings', + icon: 'cog' } ], pub: [], user: [ { id: 1, - title: "Dashboard", - icon: "dashboard", - href: "/dashboard" + title: 'Dashboard', + icon: 'dashboard', + href: '/dashboard' }, { id: 2, - title: "My Profile", - icon: "user", - href: "/profile" + title: 'My Profile', + icon: 'user', + href: '/profile' }, { id: 3, - title: "Help", - icon: "book", - href: "/help" + title: 'Help', + icon: 'book', + href: '/help' } ] }, settings: { currentdate: new Date(), - dateformats: ["medium", "short", "fullDate", "longDate", "mediumDate", "shortDate"], - timeformats: ["mediumTime", "shortTime"], - dateformat: "medium", - timeformat: "shortTime", + dateformats: ['medium', 'short', 'fullDate', 'longDate', 'mediumDate', 'shortDate'], + timeformats: ['mediumTime', 'shortTime'], + dateformat: 'medium', + timeformat: 'shortTime', timezone: null, servers: [ { - name: "apiv1", - host: "127.1.0.1", + name: 'apiv1', + host: '127.1.0.1', port: 3000, - body: "This is the v1 api server" + body: 'This is the v1 api server' }, { - name: "apiv2", - host: "127.1.0.1", + name: 'apiv2', + host: '127.1.0.1', port: 3000, - body: "This is the v2 api server" + body: 'This is the v2 api server' } ], socketio: { - host: "127.1.0.1", + host: '127.1.0.1', port: 8081 }, network: { @@ -147,106 +147,106 @@ window.Config = { cache: true }, database: { - host: "127.1.0.1", + host: '127.1.0.1', port: 27017, - name: "angular-cms" + name: 'angular-cms' }, api: { - url: "", - endpoint: "/api/", - version: "v2", - versions: ["v1", "v2"] + url: '', + endpoint: '/api/', + version: 'v2', + versions: ['v1', 'v2'] }, live: false, debug: true, - version: "0.0.1", - formFactor: "desktop", + version: '0.0.1', + formFactor: 'desktop', currentOrientation: null, - cdn: "http://a481ab4f6ea4dd65cff0-b2b68ced242ecf1cb9bc1021688e3775.r49.cf1.rackcdn.com/angular-cms", + cdn: 'http://a481ab4f6ea4dd65cff0-b2b68ced242ecf1cb9bc1021688e3775.r49.cf1.rackcdn.com/angular-cms', cdns: { - http: "http://a481ab4f6ea4dd65cff0-b2b68ced242ecf1cb9bc1021688e3775.r49.cf1.rackcdn.com/angular-cms", - https: "https://4ac535c4a3d1d3359bbc-b2b68ced242ecf1cb9bc1021688e3775.ssl.cf1.rackcdn.com/angular-cms", - streaming: "http://df86ce1cf0cf1f552fe2-b2b68ced242ecf1cb9bc1021688e3775.r49.stream.cf1.rackcdn.com/angular-cms" + http: 'http://a481ab4f6ea4dd65cff0-b2b68ced242ecf1cb9bc1021688e3775.r49.cf1.rackcdn.com/angular-cms', + https: 'https://4ac535c4a3d1d3359bbc-b2b68ced242ecf1cb9bc1021688e3775.ssl.cf1.rackcdn.com/angular-cms', + streaming: 'http://df86ce1cf0cf1f552fe2-b2b68ced242ecf1cb9bc1021688e3775.r49.stream.cf1.rackcdn.com/angular-cms' } }, options: { layouts: [ { id: 0, - name: "Fixed", - value: "container" + name: 'Fixed', + value: 'container' }, { id: 1, - name: "Fluid", - value: "container-fluid" + name: 'Fluid', + value: 'container-fluid' } ], sidebars: [ { id: 1, - name: "Default", - value: "sidebar", - url: "/views/partials/sidebar.html" + name: 'Default', + value: 'sidebar', + url: '/views/partials/sidebar.html' } ], navbars: [ { id: 1, - name: "Default", - value: "navbar", - url: "/views/partials/navbar.html" + name: 'Default', + value: 'navbar', + url: '/views/partials/navbar.html' } ], backgrounds: [ { id: 0, - title: "Default" + title: 'Default' } ], - themes: ["Default", "Amelia", "Cerulean", "Cosmo", "Cyborg", "Flatly", "Journal", "Readable", "Simplex", "Slate", "Spacelab", "United", "Yeti"] + themes: ['Default', 'Amelia', 'Cerulean', 'Cosmo', 'Cyborg', 'Flatly', 'Journal', 'Readable', 'Simplex', 'Slate', 'Spacelab', 'United', 'Yeti'] }, logout: { - redirect: "#/login", - message: "Good bye..." + redirect: '#/login', + message: 'Good bye...' }, login: { - logo: "https://7fd8f70e662929940bdd-79dc9bd5ca0b6e6cb6f16ffd7b1e05e2.ssl.cf1.rackcdn.com/img/logo-login-med.png", - redirect: "/#/home", + logo: 'https://7fd8f70e662929940bdd-79dc9bd5ca0b6e6cb6f16ffd7b1e05e2.ssl.cf1.rackcdn.com/img/logo-login-med.png', + redirect: '/#/home', user: { - username: "", - password: "" + username: '', + password: '' }, - message: "Welcome {{user.username}}" + message: 'Welcome {{user.username}}' }, server: { - host: "http://localhost", + host: 'http://localhost', port: 8181, - apiBase: "/api/v2", - version: "v2", + apiBase: '/api/v2', + version: 'v2', security: { - salt: "angular-cms" + salt: 'angular-cms' }, - mongodb: "angularcms:angularcms@paulo.mongohq.com:10089/app19632340", + mongodb: 'angularcms:angularcms@paulo.mongohq.com:10089/app19632340', db: { - name: "angular-cms", - username: "amadmin", - password: "fred", - host: "localhost", + name: 'angular-cms', + username: 'amadmin', + password: 'fred', + host: 'localhost', port: 27017 }, email: { - username: "angular.cms@gmail.com", - password: "isyourdaughter18?" + username: 'angular.cms@gmail.com', + password: 'isyourdaughter18?' }, proxy: { - hostname: "localhost", + hostname: 'localhost', port: 5001 }, - staticDir: "www", - publicDir: "www", - uploadsTmpDir: ".tmp", - uploadsDestDir: "www/cms-content/uploads", - uploadsUrl: ":8181/cms-content/", - logFormat: "[:date] - [:method] - :url - :status - :response-time ms" + staticDir: 'www', + publicDir: 'www', + uploadsTmpDir: '.tmp', + uploadsDestDir: 'www/cms-content/uploads', + uploadsUrl: ':8181/cms-content/', + logFormat: '[:date] - [:method] - :url - :status - :response-time ms' } }; diff --git a/app/scripts/controllers/admin.js b/app/scripts/controllers/admin.js index c07ebb7..603255d 100644 --- a/app/scripts/controllers/admin.js +++ b/app/scripts/controllers/admin.js @@ -1,4 +1,4 @@ 'use strict'; angular.module('angularCmsApp').controller('AdminCtrl', function($scope) { - return $scope.awesomeThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma']; + $scope.awesomeThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma']; }); diff --git a/app/scripts/controllers/app.js b/app/scripts/controllers/app.js index 12892cf..eae40ee 100644 --- a/app/scripts/controllers/app.js +++ b/app/scripts/controllers/app.js @@ -1,20 +1,28 @@ 'use strict'; -angular.module('angularCmsApp').controller('AppCtrl', function($scope, $rootScope, $http, $log, $route, $location, $routeParams, $cookieStore, cmsSessionService, DataService) { - var App; - App = Config; - App.ds = DataService; - App.route = $routeParams; - App.session = cmsSessionService.getSession(); - App.theme = $cookieStore.get('App.theme'); - App.route = $route; - App.location = $location; - App.routeParams = $routeParams; - App.roles = ['guest', 'user', 'admin']; - $scope.name = 'AppCtrl'; - window.App = $scope.App = $rootScope.App = App; - return angular.element(document).ready(function() { - return angular.element('.nav').bind('click', 'a', function(e) { - return $log.info(e); - }); - }); +angular.module('angularCmsApp').controller('AppCtrl', function ($scope, $rootScope, $http, $log, $route, $location, $routeParams, $cookieStore, cmsSessionService, DataService, cmsSocketService) { + var App; + App = angular.copy(Config); + App.ds = DataService; + App.socket = cmsSocketService; + + + App.route = $routeParams; + App.session = cmsSessionService.getSession(); + App.theme = $cookieStore.get('App.theme'); + App.route = $route; + App.location = $location; + App.routeParams = $routeParams; + App.roles = ['guest', 'user', 'admin']; + + + $scope.name = 'AppCtrl'; + + window.App = $scope.App = $rootScope.App = App; + + + angular.element(document).ready(function () { + angular.element('.nav').bind('click', 'a', function (e) { + $log.info(e); + }); + }); }); diff --git a/app/scripts/controllers/dashboard.js b/app/scripts/controllers/dashboard.js index a026bb2..5e30648 100644 --- a/app/scripts/controllers/dashboard.js +++ b/app/scripts/controllers/dashboard.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('angularCmsApp').controller('DashboardCtrl', function($scope) { $scope.awesomeThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma']; - return $scope.fullscreen = function() { + $scope.fullscreen = function() { var i; i = document.getElementById("dashboard"); if (i.requestFullscreen) { diff --git a/app/scripts/controllers/docs.js b/app/scripts/controllers/docs.js index 9a1b814..807ce9b 100644 --- a/app/scripts/controllers/docs.js +++ b/app/scripts/controllers/docs.js @@ -1,4 +1,4 @@ 'use strict'; angular.module('angularCmsApp').controller('DocsCtrl', function($scope) { - return $scope.awesomeThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma']; + $scope.awesomeThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma']; }); diff --git a/app/scripts/controllers/forgot-password.js b/app/scripts/controllers/forgot-password.js index 5bdff39..44448f6 100644 --- a/app/scripts/controllers/forgot-password.js +++ b/app/scripts/controllers/forgot-password.js @@ -1,4 +1,4 @@ 'use strict'; angular.module('angularCmsApp').controller('ForgotPasswordCtrl', function($scope) { - return $scope.awesomeThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma']; + $scope.awesomeThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma']; }); diff --git a/app/scripts/controllers/help.js b/app/scripts/controllers/help.js index 28a108c..533cb5e 100644 --- a/app/scripts/controllers/help.js +++ b/app/scripts/controllers/help.js @@ -1,13 +1,7 @@ 'use strict'; -angular.module('angularCmsApp').controller('HelpCtrl', function($scope, $http) { +angular.module('angularCmsApp').controller('HelpCtrl', function($scope) { $scope.awesomeThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma']; $scope.readmeEl = angular.element('#readme'); - return $scope.loadReadme = function() { - - /* - $http.get('/api/v2/README').success((data) -> - $scope.readmeEl.html(data) - ) - */ + $scope.loadReadme = function() { }; }); diff --git a/app/scripts/controllers/login.js b/app/scripts/controllers/login.js index 8d4e746..7aef9db 100644 --- a/app/scripts/controllers/login.js +++ b/app/scripts/controllers/login.js @@ -9,7 +9,6 @@ angular.module('angularCmsApp').controller('LoginCtrl', function($scope, $rootSc password: null, remember: false }; - /** login - This functionality should be moved into the session service that handles setting the session and changing the location of the page. @@ -17,36 +16,8 @@ angular.module('angularCmsApp').controller('LoginCtrl', function($scope, $rootSc $scope.login = function(u) { return cmsAuthService.login(u); }; - - /* - Login Method to set the session. - @param {Object} user - A user model containing username and password - - $scope._login = (u) -> - console.log(u) - Parse.User.logIn u.username, u.password, - success: (user) -> - console.log user - $scope.$apply(()-> - *Set user session - session = - user: user.attributes - authorized: true - - console.log('save sessin', session) - *Set user cookie - $cookieStore.put('App.session', session) if u.remember - $rootScope.App.session = session - *Change location - $rootScope.App.location.path('/dashboard') - ) - error: (user, error) -> - $scope.$apply(()-> - $scope.error = error; - ) - */ $scope.logout = function(user) { return cmsAuthService.logout(user); }; - return $scope.name = 'login'; + $scope.name = 'login'; }); diff --git a/app/scripts/controllers/pages.js b/app/scripts/controllers/pages.js index 2b4fbbe..19b04ff 100644 --- a/app/scripts/controllers/pages.js +++ b/app/scripts/controllers/pages.js @@ -22,7 +22,7 @@ angular.module('angularCmsApp').controller('PagesCtrl', function($scope, $log, p return DataService.save('pages', p).then(function(res) { $scope.getPages(); $scope.page = {}; - cmsNotify('.alerts', 'success', 'Success!', "Page Update.", 5000); + cmsNotify('.alerts', 'success', 'Success!', 'Page Update.', 5000); return $log.info(res); }); }; @@ -33,80 +33,80 @@ angular.module('angularCmsApp').controller('PagesCtrl', function($scope, $log, p }); }; return $scope.pageSchema = { - "fields": [ + 'fields': [ { - "type": "text", - "name": "title", - "displayName": "Title:", - "validation": { - "messages": {}, - "required": true, - "minlength": 2, - "maxlength": 18 + 'type': 'text', + 'name': 'title', + 'displayName': 'Title:', + 'validation': { + 'messages': {}, + 'required': true, + 'minlength': 2, + 'maxlength': 18 }, - "placeholder": "Enter title here", - "tooltip": "Enter the page title here" + 'placeholder': 'Enter title here', + 'tooltip': 'Enter the page title here' }, { - "type": "selectlist", - "name": "parent", - "displayName": "Parent:", - "options": [ + 'type': 'selectlist', + 'name': 'parent', + 'displayName': 'Parent:', + 'options': [ { - "value": "1", - "text": "Option 1" + 'value': '1', + 'text': 'Option 1' }, { - "value": "2", - "text": "Option 2" + 'value': '2', + 'text': 'Option 2' }, { - "value": "3", - "text": "Option 3" + 'value': '3', + 'text': 'Option 3' } ], - "value": "1" + 'value': '1' }, { - "type": "selectlist", - "name": "template", - "displayName": "Template:", - "options": [ + 'type': 'selectlist', + 'name': 'template', + 'displayName': 'Template:', + 'options': [ { - "value": "1", - "text": "Option 1" + 'value': '1', + 'text': 'Option 1' }, { - "value": "2", - "text": "Option 2" + 'value': '2', + 'text': 'Option 2' }, { - "value": "3", - "text": "Option 3" + 'value': '3', + 'text': 'Option 3' } ], - "value": "1" + 'value': '1' }, { - "type": "textarea", - "name": "body", - "displayName": "Body:", - "validation": { - "messages": {} + 'type': 'textarea', + 'name': 'body', + 'displayName': 'Body:', + 'validation': { + 'messages': {} }, - "placeholder": "Enter body here", - "tooltip": "Enter page body here" + 'placeholder': 'Enter body here', + 'tooltip': 'Enter page body here' }, { - "type": "checkboxlist", - "name": "status", - "displayName": "Status:", - "options": [ + 'type': 'checkboxlist', + 'name': 'status', + 'displayName': 'Status:', + 'options': [ { - "value": "published", - "text": "Published" + 'value': 'published', + 'text': 'Published' }, { - "value": "draft", - "text": "Draft" + 'value': 'draft', + 'text': 'Draft' }, { - "value": "private", - "text": "Private" + 'value': 'private', + 'text': 'Private' } ], - "value": "draft", - "tooltip": "Select the page status" + 'value': 'draft', + 'tooltip': 'Select the page status' } ] }; diff --git a/app/scripts/controllers/plugins.js b/app/scripts/controllers/plugins.js index 2b0adf6..8c3564e 100644 --- a/app/scripts/controllers/plugins.js +++ b/app/scripts/controllers/plugins.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('angularCmsApp').controller('PluginsCtrl', function($scope) { $scope.awesomeThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma']; - return $scope.plugins = [ + $scope.plugins = [ { id: 1, title: 'Google Chart Widgets', diff --git a/app/scripts/controllers/settings.js b/app/scripts/controllers/settings.js index 61859c2..1036e4b 100644 --- a/app/scripts/controllers/settings.js +++ b/app/scripts/controllers/settings.js @@ -16,65 +16,65 @@ angular.module('angularCmsApp').controller('SettingsCtrl', function($scope, mySc ]; }); -angular.module('angularCmsApp').value("mySchema", { +angular.module('angularCmsApp').value('mySchema', { fields: [ { - type: "text", - name: "firstName", - displayName: "First name", + type: 'text', + name: 'firstName', + displayName: 'First name', validation: { messages: {}, required: true }, - placeholder: "Enter your first name here", - tooltip: "Enter your first name here" + placeholder: 'Enter your first name here', + tooltip: 'Enter your first name here' }, { - type: "text", - name: "lastName", - displayName: "Last name", + type: 'text', + name: 'lastName', + displayName: 'Last name', validation: { messages: {}, required: true }, - placeholder: "Enter your last name here", - tooltip: "Enter your last name here" + placeholder: 'Enter your last name here', + tooltip: 'Enter your last name here' }, { - type: "radiobuttonlist", - name: "sex", - displayName: "Sex", + type: 'radiobuttonlist', + name: 'sex', + displayName: 'Sex', options: [ { - value: "male", - text: "Male" + value: 'male', + text: 'Male' }, { - value: "female", - text: "Female" + value: 'female', + text: 'Female' } ], - value: "male" + value: 'male' }, { - type: "email", - name: "email", - displayName: "Email", + type: 'email', + name: 'email', + displayName: 'Email', validation: { messages: {} }, - placeholder: "Enter your email address here", - tooltip: "Enter your email address here" + placeholder: 'Enter your email address here', + tooltip: 'Enter your email address here' }, { - type: "checkboxlist", - name: "color", - displayName: "Colors", + type: 'checkboxlist', + name: 'color', + displayName: 'Colors', options: [ { - value: "red", - text: "Red" + value: 'red', + text: 'Red' }, { - value: "blue", - text: "Blue" + value: 'blue', + text: 'Blue' }, { - value: "green", - text: "Green" + value: 'green', + text: 'Green' } ], value: {} diff --git a/app/scripts/directives/cms-formgroup.js b/app/scripts/directives/cms-formgroup.js index 845d941..89b952e 100644 --- a/app/scripts/directives/cms-formgroup.js +++ b/app/scripts/directives/cms-formgroup.js @@ -4,11 +4,11 @@ @name angularCmsApp.directive:cmsFormGroup @element div @function - + @description Resize textarea automatically to the size of its text content. **Note:** ie<9 needs pollyfill for window.getComputedStyle - + @example @@ -20,7 +20,7 @@ 'use strict'; angular.module('angularCmsApp').directive('cmsFormGroup', function() { return { - template: "
\n \n
\n
\n
", + template: '
', restrict: 'E', replace: true, transclude: true, @@ -29,6 +29,7 @@ angular.module('angularCmsApp').directive('cmsFormGroup', function() { hint: '@' }, link: function(scope, element, attrs) { + console.log(attrs); return element.find('input').addClass('form-control'); } }; diff --git a/app/scripts/directives/cms-gravatar.js b/app/scripts/directives/cms-gravatar.js index 7949aa9..678baaa 100644 --- a/app/scripts/directives/cms-gravatar.js +++ b/app/scripts/directives/cms-gravatar.js @@ -4,12 +4,12 @@ @name angularCmsApp.directive:cmsGravatar @element div @function - + @description This is a Gravatar directive for displaying an image by a users email address. @example - + HTML example come here ==> `
` @@ -25,7 +25,7 @@ angular.module('angularCmsApp').directive('cmsGravatar', function() { scope: { email: '@' }, - link: function(scope, element, attrs) { + link: function(scope, element) { return element.text('this is the cmsGravatar directive'); } }; diff --git a/app/scripts/filters/markdown.js b/app/scripts/filters/markdown.js index a0b2614..68d0621 100644 --- a/app/scripts/filters/markdown.js +++ b/app/scripts/filters/markdown.js @@ -1,15 +1,16 @@ - /** -@ngdoc filter -@name angularCmsApp.filter:markdown -@function - -@description + @ngdoc filter + @name angularCmsApp.filter:markdown + @function + + @description This is a Markdown to HTML filter. */ 'use strict'; -angular.module('angularCmsApp').filter('markdown', function() { - return function(input) { - return markdown.toHTML(input); - }; +angular.module('angularCmsApp').filter('markdown', function () { + return function (input) { + if(input){ + return markdown.toHTML(input); + } + }; }); diff --git a/app/scripts/services/cmsauthservice.js b/app/scripts/services/cms-authservice.js similarity index 100% rename from app/scripts/services/cmsauthservice.js rename to app/scripts/services/cms-authservice.js diff --git a/app/scripts/services/cmsdataservicefactory.js b/app/scripts/services/cms-dataservicefactory.js similarity index 100% rename from app/scripts/services/cmsdataservicefactory.js rename to app/scripts/services/cms-dataservicefactory.js diff --git a/app/scripts/services/cmsdataserviceprovider.js b/app/scripts/services/cms-dataserviceprovider.js similarity index 100% rename from app/scripts/services/cmsdataserviceprovider.js rename to app/scripts/services/cms-dataserviceprovider.js diff --git a/app/scripts/services/cmsnotify.js b/app/scripts/services/cms-notify.js similarity index 100% rename from app/scripts/services/cmsnotify.js rename to app/scripts/services/cms-notify.js diff --git a/app/scripts/services/cmssessionservice.js b/app/scripts/services/cms-sessionservice.js similarity index 100% rename from app/scripts/services/cmssessionservice.js rename to app/scripts/services/cms-sessionservice.js diff --git a/app/scripts/services/cms-socketservice.js b/app/scripts/services/cms-socketservice.js new file mode 100644 index 0000000..d9ade8e --- /dev/null +++ b/app/scripts/services/cms-socketservice.js @@ -0,0 +1,48 @@ +'use strict'; + +/** + * @ngdoc service + * @name angularCmsApp.cmsSocketService + * @description + * # cmsSocketService + * Service in the angularCmsApp. + */ +angular.module('angularCmsApp').factory('cmsSocketService', function ($rootScope) { + /** + * I am a WebSocketClient + * @param options + * @returns {{instance: WebSocket, close: Function, send: Function}} + * @constructor + */ + var WebSocketClient = function (options) { + var _ws = new WebSocket(options.endpoint, options.protocol); + _ws.onmessage = function (e) { + $rootScope.$emit(options.protocol, e); + return console.log(e.data); + }; + _ws.onerror = function (e) { + return console.log(e); + }; + _ws.onclose = function (e) { + return console.log(e); + }; + _ws.onopen = function (e) { + _ws.send('update'); + }; + return { + instance: _ws, + close: function () { + return _ws.close(); + }, + send: function (obj) { + try { + _ws.send(JSON.stringify(obj)); + } catch (err) { + + throw err; + } + } + }; + }; + return WebSocketClient; +}); diff --git a/app/scripts/services/cmsusersfactory.js b/app/scripts/services/cms-usersfactory.js similarity index 100% rename from app/scripts/services/cmsusersfactory.js rename to app/scripts/services/cms-usersfactory.js diff --git a/app/scripts/services/cmssocketservice.js b/app/scripts/services/cmssocketservice.js deleted file mode 100644 index d9710ad..0000000 --- a/app/scripts/services/cmssocketservice.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict'; - -/** - * @ngdoc service - * @name angularCmsApp.cmsSocketService - * @description - * # cmsSocketService - * Service in the angularCmsApp. - */ -angular.module('angularCmsApp').service('cmsSocketService', function() { - var WebSocketClient; - WebSocketClient = function(options) { - var _ws; - _ws = void 0; - _ws = new WebSocket(options.endpoint, options.protocol); - _ws.onmessage = function(e) { - return console.log(e.data); - }; - _ws.onerror = function(e) { - return console.log(e); - }; - _ws.onclose = function(e) { - return console.log(e); - }; - _ws.onopen = function(e) { - _ws.send("update"); - }; - return { - instance: _ws, - close: function() { - return _ws.close(); - }, - send: function(obj) { - var err; - try { - _ws.send(obj); - } catch (_error) { - err = _error; - throw err; - } - } - }; - }; - return WebSocketClient; -}); diff --git a/app/scripts/services/dataservice.js b/app/scripts/services/dataservice.js index 7951352..2ee4fa4 100644 --- a/app/scripts/services/dataservice.js +++ b/app/scripts/services/dataservice.js @@ -1,44 +1,41 @@ 'use strict'; -angular.module('angularCmsApp').service('DataService', [ - '$http', '$q', '$resource', function($http, $q, $resource) { - var DataService; - DataService = { - endpoint: '/api/v2/angular-cms', - request: function(path, method, params, data) { - var defaults; - defaults = { - method: method, - url: this.endpoint + path, - cache: false, - data: data, - params: params - }; - console.log(path, defaults); - return $http(defaults); - }, - fetch: function(collection, params) { - return this.request("/" + collection, 'GET', params); - }, - get: function(collection, id, params) { - return this.request("/" + collection + "/" + id, 'GET', params); - }, - save: function(collection, data) { - if (data._id) { - return this._update(collection, data); - } else { - return this._create(collection, data); - } - }, - destroy: function(collection, data) { - return this.request("/" + collection + "/" + data._id, 'DELETE'); - }, - _create: function(collection, data) { - return this.request("/" + collection, 'POST', null, data); - }, - _update: function(collection, data) { - return this.request("/" + collection + "/" + data._id, 'PUT', null, data); - } - }; - return DataService; - } +angular.module('angularCmsApp').service('DataService', ['$http', function ($http) { + var DataService = { + endpoint: '/api/v2/angular-cms', + request: function (path, method, params, data) { + var defaults; + defaults = { + method: method, + url: this.endpoint + path, + cache: false, + data: data, + params: params + }; + return $http(defaults); + }, + fetch: function (collection, params) { + return this.request('/' + collection, 'GET', params); + }, + get: function (collection, id, params) { + return this.request('/' + collection + '/' + id, 'GET', params); + }, + save: function (collection, data) { + if (data && data._id) { + return this._update(collection, data); + } else { + return this._create(collection, data); + } + }, + destroy: function (collection, data) { + return this.request('/' + collection + '/' + data._id, 'DELETE'); + }, + _create: function (collection, data) { + return this.request('/' + collection, 'POST', null, data); + }, + _update: function (collection, data) { + return this.request('/' + collection + '/' + data._id, 'PUT', null, data); + } + }; + return DataService; + } ]); diff --git a/config/config.json b/config/config.json index 2f4153a..60183df 100644 --- a/config/config.json +++ b/config/config.json @@ -24,7 +24,7 @@ "password":"fred", "host":"localhost", "port":27017, - "url":"angularcms:angularcms@paulo.mongohq.com:10089/app19632340" + "url":"localhost/angular-cms" }, "email":{ "username":"angular.cms@gmail.com", diff --git a/routes/cms-auth.js b/routes/cms-auth.js index 554f0d5..520ce11 100644 --- a/routes/cms-auth.js +++ b/routes/cms-auth.js @@ -1,16 +1,14 @@ -var bodyParser = require( 'body-parser' ), - mongoose = require( 'mongoose' ), +var bodyParser = require('body-parser'), + mongoose = require('mongoose'), util = require('util'), - User = require( './models/user' ), - session = require( 'express-session' ), - crypto = require( 'crypto'), - bcrypt = require( 'bcrypt-nodejs' ); - + User = require('./models/user'), + session = require('express-session'), + crypto = require('crypto'), + bcrypt = require('bcrypt-nodejs'); var cmsAuth = function (config, app) { - console.warn( 'cms-auth' ); - + console.warn('cms-auth'); //### hashPassword @@ -35,23 +33,23 @@ var cmsAuth = function (config, app) { if (req.body.email) { query.username = req.body.email; } - query.password = hashPassword( req.body.password, query.username ); + query.password = hashPassword(req.body.password, query.username); console.warn('trying to login', query); - User.findOne( {username: query.username}, function (err, data) { + User.findOne({username: query.username}, function (err, data) { if (err) { - return res.jsonp( 400, err ); + return res.jsonp(400, err); } try { if (data && bcrypt.compareSync(req.body.password, data.password)) { req.session.user = data; - return res.json( 200, data ); + return res.json(200, data); } else { - return res.json( 404, {message: 'Wrong username/password!'} ); + return res.json(404, {message: 'Wrong username/password!'}); } } catch (error) { - return res.json( 404, {message: error} ); + return res.json(404, {message: error}); } - } ); + }); }, /** * Handle registering a new user @@ -70,7 +68,7 @@ var cmsAuth = function (config, app) { data.email = req.body.email; } - data.password = hashPassword( req.body.password, data.username ); + data.password = hashPassword(req.body.password, data.username); data.created_at = new Date(); data.updated_at = new Date(); data.active = false; @@ -79,32 +77,31 @@ var cmsAuth = function (config, app) { console.warn('trying to register', data); - //Try and find user - User.find( {username: data.username}, function (err, u) { - console.log( 'found user', err, util.inspect(u, {colors: true})); - var user = new User( data ); - if(err){ - res.jsonp( 400, {message: 'Problem registering!'} ); + User.find({username: data.username}, function (err, u) { + console.log('found user', err, util.inspect(u, {colors: true})); + var user = new User(data); + if (err) { + res.jsonp(400, {message: 'Problem registering!'}); } if (u.length) { - res.jsonp( 400, {message: 'Username already exists!'} ); + res.jsonp(400, {message: 'Username already exists!'}); } else { - user.save( function (er, ok) { + user.save(function (er, ok) { if (er) { - return res.jsonp( 400, {message: 'Problem registering!'} ); + return res.jsonp(400, {message: 'Problem registering!'}); } else { - return res.jsonp( 201, ok ); + return res.jsonp(201, ok); } - } ); + }); } - } ); + }); }, session: function (req, res, next) { var user = req.session; - if(req.session && req.session.user){ + if (req.session && req.session.user) { user = req.session.user } console.warn(util.inspect(user, {colors: true})); @@ -113,15 +110,15 @@ var cmsAuth = function (config, app) { }; //Always users table - app.use( session( { + app.use(session({ secret: 'angular-cms', resave: true, saveUninitialized: true - } ) ); - app.get( config.apiBase + '/login', bodyParser.json(), cmsAuth.login ); - app.post( config.apiBase + '/login', bodyParser.json(), cmsAuth.login ); - app.post( config.apiBase + '/register', bodyParser.json(), cmsAuth.register ); - app.get( config.apiBase + '/session', bodyParser.json(), cmsAuth.session ); + })); + app.get(config.apiBase + '/login', bodyParser.json(), cmsAuth.login); + app.post(config.apiBase + '/login', bodyParser.json(), cmsAuth.login); + app.post(config.apiBase + '/register', bodyParser.json(), cmsAuth.register); + app.get(config.apiBase + '/session', bodyParser.json(), cmsAuth.session); }; module.exports = cmsAuth; diff --git a/routes/cms-passport.js b/routes/cms-passport.js index 3e69655..b4a51aa 100644 --- a/routes/cms-passport.js +++ b/routes/cms-passport.js @@ -38,7 +38,7 @@ var ensureAuthenticated = function (req, res, next) { */ var cmsPassport = function (config, app) { -var user = new User(); + var user = new User(); if (!app) { throw new Error('Must provide express application!'); @@ -46,20 +46,22 @@ var user = new User(); /* - */ - var findOrCreate = function(u, done){ + */ + var findOrCreate = function (u, done) { console.log('find', u); for (var i = 0; i < u.emails.length; i++) { var email = u.emails[i].value - User.findOne({ email: email }, function (err, user) { - if (err) { return done(err); } + User.findOne({email: email}, function (err, user) { + if (err) { + return done(err); + } if (!user) { console.warn('create user', u); return done(null, false); } - return done(null, user); - }); + return done(null, user); + }); } }; @@ -88,15 +90,21 @@ var user = new User(); passport.deserializeUser(deserializeUser); -var strategy = function(username, password, done) { - console.warn('find user', username, password); - User.findOne({ username: username }, function (err, user) { - if (err) { return done(err); } - if (!user) { return done(null, false); } - if (!user.validPassword(password)) { return done(null, false); } - return done(null, user); - }); - }; + var strategy = function (username, password, done) { + console.warn('find user', username, password); + User.findOne({username: username}, function (err, user) { + if (err) { + return done(err); + } + if (!user) { + return done(null, false); + } + if (!user.validPassword(password)) { + return done(null, false); + } + return done(null, user); + }); + }; passport.use(new BasicStrategy(strategy)); passport.use(new LocalStrategy(strategy)); diff --git a/routes/cms-sockets.js b/routes/cms-sockets.js index bc2c29d..b1aa2f2 100644 --- a/routes/cms-sockets.js +++ b/routes/cms-sockets.js @@ -1,9 +1,9 @@ +var events = require('events'), + util = require('util'), + q = require('q'), + WebSocketServer = require('websocket').server, + WebSocketRouter = require('websocket').router; -const events = require('events'), util = require('util'); - -var q = require( 'q' ), -WebSocketServer = require('websocket').server, -WebSocketRouter = require('websocket').router; //////////////////////////// //## Socket Server //This is a socket server implementation for 'real' time analytics and other data. @@ -23,52 +23,52 @@ WebSocketRouter = require('websocket').router; module.exports = function (config, app) { 'use strict'; events.EventEmitter.call(this); - console.warn( 'cms-sockts initialized' ); + console.warn('cms-socket initialized'); //Start the websocket server //SocketServer.init(proxyServer); var cmsSockets = {}, - connections, wsserver, wsclient, router, self = cmsSockets; + connections, wsserver, wsclient, router, self = cmsSockets; var delay = function (fn, time) { var defer = q.defer(); - setTimeout( function () { + setTimeout(function () { fn(); defer.resolve(); - }, time ); + }, time); return defer.promise; }; - var delayedSocketPush = function(socket, time){ - return delay( function (msg) { - socket.emit( 'msg', { + var delayedSocketPush = function (socket, time) { + return delay(function (msg) { + socket.emit('msg', { datetime: new Date(), message: msg, id: 'Server' - } ); - }, time ); + }); + }, time); }; //Hold the names of events that this socket server listens for and emits self.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' - }, - client: { - message: 'cms:client:message', - connected: 'cms:client:connect', - disconnected: 'cms:client:disconnect' - } - }; + 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' + }, + client: { + message: 'cms:client:message', + connected: 'cms:client:connect', + disconnected: 'cms:client:disconnect' + } + }; //Store a list of the connected clients @@ -84,21 +84,30 @@ module.exports = function (config, app) { router = new WebSocketRouter(); router.attachServer(wsserver); - router.mount('*', 'echo-protocol', function(request) { + /** + * Echo Protocol + */ + router.mount('*', 'echo-protocol', function (request) { console.log('mounted to echo protocol'); + var conn = request.accept(request.origin); - conn.on('message', function(message) { - console.log('routed message', message); + + conn.on('message', function (message) { + console.log('routed message', util.inspect(message, {colors: true})); }); conn.send('hey'); }); - router.mount('*', 'update-protocol', function(request) { + /** + * Update Protocol + */ + router.mount('*', 'update-protocol', function (request) { console.log('mounted to update protocol'); var conn = request.accept(request.origin); - conn.on('message', function(message) { + conn.on('message', function (message) { console.log('update all the things', message); - }); }); + }); + }); util.inherits(cmsSockets, events.EventEmitter); diff --git a/routes/generic.js b/routes/generic.js index 4298d87..9774124 100644 --- a/routes/generic.js +++ b/routes/generic.js @@ -11,17 +11,18 @@ var mongo = require('mongodb'); var mongoose = require('mongoose'); var Server = mongo.Server; var Db = mongo.Db; +var Resource; //Connect to the database -mongoose.connect('mongodb://localhost:27017/myappmatrix'); +//mongoose.connect('mongodb://localhost:27017/myappmatrix'); /* ======================[ @TODO: Modal Schema ]====================== */ var Post = mongoose.model('post', new mongoose.Schema({ - text : String, - done : Boolean, - order : Number + text: String, + done: Boolean, + order: Number })); @@ -38,306 +39,233 @@ var Post = mongoose.model('post', new mongoose.Schema({ * PUT update http://localhost:3000/accounts/:id * DELETE destroy http://localhost:3000/accounts/:id */ -var Resource = { - host : 'localhost', - port : 27017, - /** - * I enable logging or not. - */ - debug : true, - /** - * I am the interal logger. - */ - log : function(obj) { - if (Resource.debug) { - console.log(obj); - } - }, - /** - * I am the name of the database. - */ - databaseName : 'accounts_db', - /** - * I am the name of this collection. - */ - name : 'accounts', - mongo : mongo, - server : null, - db : null, - mongoServer : mongo.Server, - mongoDb : mongo.Db, - bson : mongo.BSONPure, - /** - * I am the example schema for this resources. - */ - schema : { - id : '', - ns : 'com.domain.app', - title : '', - body : '', - address1 : '', - address2 : '', - city : '', - state : '', - zip : '', - type : '', - active : '0', - created : '', - modified : '', - website : '', - apple_url : '', - android_url : '', - user_id : '', - application_id : '', - appcellerator_url : '', - settings : '', - plan : '', - exp_date : '', - upfront_cost : '', - monthly_cost : '', - service_term : '12', - service_value : '', - total_value : '', - sla_number : '', - contract_in : '', - app_submitted : '' - }, - routes : { - 'status' : 'dbStatus' - }, - /** - * I create a new instance of the database. - */ - initDb : function() { - - Resource.server = new Server(Resource.host, Resource.port, { - auto_reconnect : true, - safe : false - }); - Resource.db = new Db(Resource.databaseName, Resource.server); - - /** - * Open the database and check for collection, if none - * then create it with the schema. - */ - Resource.db.open(function(err, db) { - if (!err) { - Resource.log('Connected to ' + Resource.databaseName); - db.collection(Resource.name, { - safe : true - }, function(err, collection) { - if (err) { - Resource.log('The collection doesnt exist. creating it with sample data...'); - Resource.populateDb(); - } - }); - } - }); - - }, - - /** - * I populate the document db with the schema. - */ - populateDb : function() { - Resource.db.collection(Resource.name, function(err, collection) { - collection.insert(Resource.schema, { - safe : true - }, function(err, result) { - Resource.log(result); - }); - }); - }, - - dbStatus: function(){ - console.log('get db status'); - }, - - /** - * I find all of the records - * @param {Object} req - * @param {Object} res - */ - findAll : function(req, res) { - Resource.db.collection(Resource.name, function(err, collection) { - collection.find().toArray(function(err, items) { - Resource.log(Resource.name + ':findAll - ' + JSON.stringify(items)); - res.send(items); - }); - }); - }, - /** - * I find one of the records by id. - * @param {Object} req - * @param {Object} res - */ - findById : function(req, res) { - - var id = req.params.id; - - Resource.log(Resource.name + ':findById - ' + id); - - Resource.db.collection(Resource.name, function(err, collection) { - collection.findOne({ - '_id' : new Resource.BSON.ObjectID(id) - }, function(err, item) { - res.send(item); - }); - }); - - - }, - /** - * I add a record to the collection - * @param {Object} req - * @param {Object} res - */ - add : function(req, res) { - var data = req.body; - - Resource.log(Resource.name + ':add - ' + JSON.stringify(data)); - Resource.db.collection(Resource.name, function(err, collection) { - collection.insert(data, { - safe : true - }, function(err, result) { - if (err) { - res.send({ - 'error' : 'An error has occurred' - }); - } else { - Resource.log('Success: ' + JSON.stringify(result[0])); - res.send(result[0]); - } - }); - }); - }, - /** - * I update a record in the collection - * @param {Object} req - * @param {Object} res - */ - update : function(req, res) { - var id = req.params.id; - var data = req.body; - Resource.log(Resource.name + ':destroy -' + id + ' - ' + JSON.stringify(data)); - Resource.db.collection(Resource.name, function(err, collection) { - collection.update({ - '_id' : new Resource.BSON.ObjectID(id) - }, data, { - safe : true - }, function(err, result) { - if (err) { - res.send({ - 'error' : 'An error has occurred' - }); - console.log('Error updating ' + Resource.name + ': ' + err); - } else { - console.log('' + result + 'document(s) updated'); - - res.send(data); - } - }); - }); - }, - /** - * I delete a record in the collection. - * @param {Object} req - * @param {Object} res - - return Todo.findById(req.params.id, function(err, todo) { - return todo.remove(function(err) { - if (!err) { - console.log("removed"); - return res.send('') - } - }); - }); - */ - destroy : function(req, res) { - var id = req.params.id; - Resource.log(Resource.name + ':destroy -' + id); - Resource.db.collection(Resource.name, function(err, collection) { - collection.remove({ - '_id' : new Resource.BSON.ObjectID(id) - }, { - safe : true - }, function(err, result) { - if (err) { - res.send({ - 'error' : 'An error has occurred' - }); - Resource.log('Error updating ' + Resource.name + ': ' + err); - } else { - res.send(req.body); - } - }); - }); - } -}; - -//Export to public api -exports.Resource = Resource; - - - - - - -var express = require('express'); -var app = express(); - app.configure(function() { - app.use(express.logger('dev')); - app.use(express.bodyParser()); - app.use(function(err, req, res, next){ - console.error(err.stack); - res.send(500, 'Something broke!'); +var database = null, server = null; +Resource = { + host: 'localhost', + port: 27017, + /** + * I enable logging or not. + */ + debug: true, + /** + * I am the interal logger. + */ + log: function (obj) { + if (Resource.debug) { + console.log(obj); + } + }, + /** + * I am the name of the database. + */ + databaseName: 'angular-cms', + /** + * I am the name of this collection. + */ + name: 'accounts', + mongo: mongo, + server: null, + db: null, + mongoServer: mongo.Server, + mongoDb: mongo.Db, + bson: mongo.BSONPure, + /** + * I am the example schema for this resources. + */ + schema: { + id: '', + ns: 'com.domain.app', + title: '', + body: '', + address1: '', + address2: '', + city: '', + state: '', + zip: '', + type: '', + active: '0', + created: '', + modified: '', + website: '', + apple_url: '', + android_url: '', + user_id: '', + application_id: '', + appcellerator_url: '', + settings: '', + plan: '', + exp_date: '', + upfront_cost: '', + monthly_cost: '', + service_term: '12', + service_value: '', + total_value: '', + sla_number: '', + contract_in: '', + app_submitted: '' + }, + routes: { + 'status': 'dbStatus' + }, + /** + * I create a new instance of the database. + */ + init: function () { + server = new Server(Resource.host, Resource.port); + database = new Db(Resource.databaseName, Resource.server, { + auto_reconnect: true, + safe: false }); - - // simple logger - app.use(function(req, res, next){ - console.log('%s %s', req.method, req.url); - next(); - }); - -}); - - - -/* @TODO: Base Route */ -app.get('/', function(req, res) { - res.send('Generic Mongo REST Server'); -}); - - - - -/* @TODO: Insert */ -app.post('/:db/:collection', function(req, res) { - if(req.body) { - var db = new mongo.Db(req.params.db, new mongo.Server(Resource.host, Resource.port, {'auto_reconnect':true, 'safe' : true})); - db.open(function(err, db) { - //set the collection - db.collection(req.params.collection, function(err, collection) { - // We only support inserting one document at a time - collection.insert(Array.isArray(req.body) ? req.body[0] : req.body, function(err, docs) { - // res.header('Location', '/'+req.params.db+'/'+req.params.collection+'/'+docs[0]._id.toHexString()); - res.header('Content-Type', 'application/json');'' - res.send('{"ok":1}', 201); - db.close(); - }); - }); - - }); - //else return false - } else { - res.header('Content-Type', 'application/json'); - res.send('{"ok":0}',200); - } -}); + database.open(function (err, db) { + if (!err) { + Resource.log('Connected to ' + Resource.databaseName); + db.collection(Resource.name, { + safe: true + }, function (err, collection) { + if (err) { + Resource.log('The collection doesnt exist. creating it with sample data...'); + Resource.populateDb(); + } + }); + } + }); + return this; + }, + /** + * I populate the document db with the schema. + */ + populateDb: function () { + database.collection(Resource.name, function (err, collection) { + collection.insert(Resource.schema, { + safe: true + }, function (err, result) { + Resource.log(result); + }); + }); + }, + + dbStatus: function () { + console.log('get db status'); + }, + + /** + * I find all of the records + * @param {Object} req + * @param {Object} res + */ + findAll: function (col) { + database.collection(col, function (err, collection) { + collection.find().toArray(function (err, items) { + if (err) { + throw err; + } + if (items) { + Resource.log(col + ':findAll - ' + JSON.stringify(items)); + return items; + } + }); + }); + }, + /** + * I find one of the records by id. + * @param {Object} req + * @param {Object} res + */ + findById: function (req, res) { + + var id = req.params.id; + + Resource.log(Resource.name + ':findById - ' + id); + + db.collection(Resource.name, function (err, collection) { + collection.findOne({ + '_id': new Resource.BSON.ObjectID(id) + }, function (err, item) { + res.send(item); + }); + }); + }, + /** + * I add a record to the collection + * @param {Object} req + * @param {Object} res + */ + add: function (req, res) { + var data = req.body; + + Resource.log(Resource.name + ':add - ' + JSON.stringify(data)); + Resource.db.collection(Resource.name, function (err, collection) { + collection.insert(data, { + safe: true + }, function (err, result) { + if (err) { + res.send({ + 'error': 'An error has occurred' + }); + } else { + Resource.log('Success: ' + JSON.stringify(result[0])); + res.send(result[0]); + } + }); + }); + }, + /** + * I update a record in the collection + * @param {Object} req + * @param {Object} res + */ + update: function (id, data) { + Resource.log(Resource.name + ':destroy -' + id + ' - ' + JSON.stringify(data)); + Resource.db.collection(Resource.name, function (err, collection) { + collection.update({ + '_id': new Resource.BSON.ObjectID(id) + }, data, { + safe: true + }, function (err, result) { + if (err) { + res.send({ + 'error': 'An error has occurred' + }); + console.log('Error updating ' + Resource.name + ': ' + err); + } else { + console.log('' + result + 'document(s) updated'); + + res.send(data); + } + }); + }); + }, + /** + * I delete a record in the collection. + * @param {Object} req + * @param {Object} res + */ + destroy: function (req, res) { + var id = req.params.id; + Resource.log(Resource.name + ':destroy -' + id); + Resource.db.collection(Resource.name, function (err, collection) { + collection.remove({ + '_id': new Resource.BSON.ObjectID(id) + }, { + safe: true + }, function (err, result) { + if (err) { + res.send({ + 'error': 'An error has occurred' + }); + Resource.log('Error updating ' + Resource.name + ': ' + err); + } else { + res.send(req.body); + } + }); + }); + } +}; +module.exports = Resource; \ No newline at end of file diff --git a/server.js b/server.js index 67ea21f..2b1271d 100755 --- a/server.js +++ b/server.js @@ -4,8 +4,18 @@ */ var express = require('express'); var fs = require('fs'); -var cmsRouter = require('./routes/cms-router.js'); +//var cmsRouter = require('./routes/cms-router.js'); var app = express(); -var config = JSON.parse(fs.readFileSync('./config/config.json')); -var server = new cmsRouter.mount(config, app); -console.log(server); +//var config = JSON.parse(fs.readFileSync('./config/config.json')); +//var server = new cmsRouter.mount(config, app); +//console.log(server); + + +var Resource = require('./routes/generic.js'); + + + + +var r = Resource.init(); + +console.log(r.findAll('users')); diff --git a/test/protractor/spec/register-spec.js b/test/protractor/spec/register-spec.js index 51d1903..0386f44 100644 --- a/test/protractor/spec/register-spec.js +++ b/test/protractor/spec/register-spec.js @@ -1,20 +1,15 @@ var registerPage, testEmail; - registerPage = require('../pages/register-page'); - - /** -Register - The user registration implementation + Register - The user registration implementation */ - testEmail = Date.now() + '-test@email.com'; - -describe('Register: ', function() { - return it('should allow a user to register', function() { - registerPage.get(); - expect(browser.getCurrentUrl()).toContain('register'); - return registerPage.register(testEmail, 'test').then(function() { - return expect(browser.getCurrentUrl()).toContain('dashboard'); - }); - }); +describe('Register: ', function () { + return it('should allow a user to register', function () { + registerPage.get(); + expect(browser.getCurrentUrl()).toContain('register'); + return registerPage.register(testEmail, 'test').then(function () { + return expect(browser.getCurrentUrl()).toContain('dashboard'); + }); + }); }); diff --git a/test/routes/cms-passport-spec.js b/test/routes/cms-passport-spec.js index 88f2972..1530e9f 100644 --- a/test/routes/cms-passport-spec.js +++ b/test/routes/cms-passport-spec.js @@ -36,7 +36,7 @@ define([ this.skip(); }, 'POST - /register - should return user on successful registration': function () { - this.skip(); + var dfd = this.async(); request(app) .post('/auth/register') @@ -49,7 +49,8 @@ define([ "name": "Jonnie Dollas" } }) - .expect("Content-Type", /json/) + .set('Accept', 'application/json') + .expect('Content-Type', /json/) .expect(201, dfd.resolve()); }, 'POST - /login - should return user on successful login': function () { @@ -61,7 +62,8 @@ define([ request(app) .post('/auth/login') .send(validUser) - .expect("Content-Type", /json/) + .set('Accept', 'application/json') + .expect('Content-Type', /json/) .expect(200) .end(function(err, res){ if (err) {throw err;} diff --git a/test/spec/services/cmssocketservice.js b/test/spec/services/cmssocketservice.js index d7f790b..afe1988 100644 --- a/test/spec/services/cmssocketservice.js +++ b/test/spec/services/cmssocketservice.js @@ -1,12 +1,12 @@ 'use strict'; -describe('Service: cmsSocketService', function() { - var cmsSocketService; - beforeEach(module('angularCmsApp')); - cmsSocketService = {}; - beforeEach(inject(function(_cmsSocketService_) { - return cmsSocketService = _cmsSocketService_; - })); - return it('should do something', function() { - return expect(!!cmsSocketService).toBe(true); - }); +describe('Service: cmsSocketService', function () { + var cmsSocketService; + beforeEach(module('angularCmsApp')); + cmsSocketService = {}; + beforeEach(inject(function (_cmsSocketService_) { + cmsSocketService = _cmsSocketService_; + })); + it('should do something', function () { + expect(!!cmsSocketService).toBe(true); + }); }); diff --git a/test/spec/services/dataservice.js b/test/spec/services/dataservice.js index eba6b0b..d0ff372 100644 --- a/test/spec/services/dataservice.js +++ b/test/spec/services/dataservice.js @@ -1,113 +1,114 @@ 'use strict'; -describe('Service: DataService', function() { - var $httpBackend, $q, $rootScope, baseUrl, ds, errorCallback, successCallback, testObject; - beforeEach(module('angularCmsApp')); - baseUrl = '/api/v2/angular-cms'; - ds = null; - $httpBackend = null; - $q = null; - $rootScope = null; - successCallback = null; - errorCallback = null; - testObject = { - _id: 1, - title: 'Test Object', - body: 'This is a sample object for testing.' - }; - beforeEach(inject(function(_$rootScope_, _DataService_, _$httpBackend_, _$q_) { - ds = _DataService_; - $httpBackend = _$httpBackend_; - $q = _$q_; - $rootScope = _$rootScope_; - successCallback = jasmine.createSpy('success'); - return errorCallback = jasmine.createSpy('error'); - })); - it('should have DataService defined', function() { - return expect(!!ds).toBe(true); - }); - it('should have a fetch method', function() { - return expect(ds.fetch).toBeDefined(); - }); - it('should have a save method', function() { - return expect(ds.save).toBeDefined(); - }); - it('should have a destroy method', function() { - return expect(ds.destroy).toBeDefined(); - }); - xit('should invoke create method if _id is not on object', function() { - $httpBackend.expectPOST("" + baseUrl + "/posts").respond(200, [{}, {}]); - spyOn(ds, '_create'); - spyOn(ds, '_update'); - ds.save('posts', { - title: 'New Post' - }).then(successCallback, errorCallback); - $httpBackend.flush(); - expect(successCallback).toHaveBeenCalled(); - expect(errorCallback).not.toHaveBeenCalled(); - expect(ds._create).toHaveBeenCalled(); - return expect(ds._update).not.toHaveBeenCalled(); - }); - xit('should invoke update method if _id is on object', function() { - $httpBackend.expectPUT("" + baseUrl + "/posts/1").respond(200, { - message: 'Success updating object' - }); - spyOn(ds, '_create'); - spyOn(ds, '_update'); - ds.save('posts', testObject).then(successCallback, errorCallback); - $httpBackend.flush(); - expect(successCallback).toHaveBeenCalled(); - expect(errorCallback).not.toHaveBeenCalled(); - expect(ds._create).not.toHaveBeenCalled(); - return expect(ds._update).toHaveBeenCalled(); - }); - it('GET - /collection - should reject promise on error', function() { - $httpBackend.expectGET("" + baseUrl + "/posts").respond(404, { - message: 'Data not found' - }); - ds.fetch('posts').then(successCallback, errorCallback); - $httpBackend.flush(); - expect(successCallback).not.toHaveBeenCalled(); - return expect(errorCallback).toHaveBeenCalled(); - }); - it('GET - /collection - should resolve promise on success', function() { - $httpBackend.expectGET("" + baseUrl + "/posts").respond(200, [{}, {}]); - ds.fetch('posts').then(successCallback, errorCallback); - $httpBackend.flush(); - expect(successCallback).toHaveBeenCalled(); - return expect(errorCallback).not.toHaveBeenCalled(); - }); - it('GET - /collection/id - should reject promise on error', function() { - $httpBackend.expectGET("" + baseUrl + "/posts/1").respond(404, { - message: 'Data not found' - }); - ds.get('posts', 1).then(successCallback, errorCallback); - $httpBackend.flush(); - expect(successCallback).not.toHaveBeenCalled(); - return expect(errorCallback).toHaveBeenCalled(); - }); - it('GET - /collection/id - should resolve promise on success', function() { - $httpBackend.expectGET("" + baseUrl + "/posts/1").respond(200, testObject); - ds.get('posts', 1).then(successCallback, errorCallback); - $httpBackend.flush(); - expect(successCallback).toHaveBeenCalled(); - return expect(errorCallback).not.toHaveBeenCalled(); - }); - it('DELETE - /collection/id - should resolve promise on success', function() { - $httpBackend.expectDELETE("" + baseUrl + "/posts/1").respond(200, { - message: 'Success deleting object' - }); - ds.destroy('posts', testObject).then(successCallback, errorCallback); - $httpBackend.flush(); - expect(successCallback).toHaveBeenCalled(); - return expect(errorCallback).not.toHaveBeenCalled(); - }); - return it('DELETE - /collection/id - should reject promise on error', function() { - $httpBackend.expectDELETE("" + baseUrl + "/posts/1").respond(404, { - message: 'Error deleting object' - }); - ds.destroy('posts', testObject).then(successCallback, errorCallback); - $httpBackend.flush(); - expect(successCallback).not.toHaveBeenCalled(); - return expect(errorCallback).toHaveBeenCalled(); - }); +describe('Service: DataService', function () { + var $httpBackend, $q, $rootScope, baseUrl, ds, errorCallback, successCallback, testObject; + beforeEach(module('angularCmsApp')); + baseUrl = '/api/v2/angular-cms'; + ds = null; + $httpBackend = null; + $q = null; + $rootScope = null; + successCallback = null; + errorCallback = null; + testObject = { + _id: 1, + title: 'Test Object', + body: 'This is a sample object for testing.' + }; + beforeEach(inject(function (_$rootScope_, _DataService_, _$httpBackend_, _$q_) { + ds = _DataService_; + $httpBackend = _$httpBackend_; + $q = _$q_; + $rootScope = _$rootScope_; + successCallback = jasmine.createSpy('success'); + errorCallback = jasmine.createSpy('error'); + })); + it('should have DataService defined', function () { + expect(!!ds).toBe(true); + }); + it('should have a fetch method', function () { + expect(ds.fetch).toBeDefined(); + }); + it('should have a save method', function () { + expect(ds.save).toBeDefined(); + }); + it('should have a destroy method', function () { + expect(ds.destroy).toBeDefined(); + }); + it('should invoke create method if _id is not on object', function () { + $httpBackend.expectPOST('' + baseUrl + '/posts').respond(200, [{}, {}]); + //ds = jasmine.createSpy('ds', ['_create', '_update', 'save']); + spyOn(ds, '_create').and.callThrough(); + spyOn(ds, '_update').and.callThrough(); + + ds.save('posts', {title: 'New Post'}).then(successCallback, errorCallback); + $httpBackend.flush(); + + expect(successCallback).toHaveBeenCalled(); + expect(errorCallback).not.toHaveBeenCalled(); + expect(ds._create).toHaveBeenCalled(); + expect(ds._update).not.toHaveBeenCalled(); + }); + it('should invoke update method if _id is on object', function () { + $httpBackend.expectPUT('' + baseUrl + '/posts/1').respond(200, { + message: 'Success updating object' + }); + spyOn(ds, '_create').and.callThrough(); + spyOn(ds, '_update').and.callThrough(); + ds.save('posts', testObject).then(successCallback, errorCallback); + $httpBackend.flush(); + expect(successCallback).toHaveBeenCalled(); + expect(errorCallback).not.toHaveBeenCalled(); + expect(ds._create).not.toHaveBeenCalled(); + expect(ds._update).toHaveBeenCalled(); + }); + it('GET - /collection - should reject promise on error', function () { + $httpBackend.expectGET('' + baseUrl + '/posts').respond(404, { + message: 'Data not found' + }); + ds.fetch('posts').then(successCallback, errorCallback); + $httpBackend.flush(); + expect(successCallback).not.toHaveBeenCalled(); + expect(errorCallback).toHaveBeenCalled(); + }); + it('GET - /collection - should resolve promise on success', function () { + $httpBackend.expectGET('' + baseUrl + '/posts').respond(200, [{}, {}]); + ds.fetch('posts').then(successCallback, errorCallback); + $httpBackend.flush(); + expect(successCallback).toHaveBeenCalled(); + expect(errorCallback).not.toHaveBeenCalled(); + }); + it('GET - /collection/id - should reject promise on error', function () { + $httpBackend.expectGET('' + baseUrl + '/posts/1').respond(404, { + message: 'Data not found' + }); + ds.get('posts', 1).then(successCallback, errorCallback); + $httpBackend.flush(); + expect(successCallback).not.toHaveBeenCalled(); + expect(errorCallback).toHaveBeenCalled(); + }); + it('GET - /collection/id - should resolve promise on success', function () { + $httpBackend.expectGET('' + baseUrl + '/posts/1').respond(200, testObject); + ds.get('posts', 1).then(successCallback, errorCallback); + $httpBackend.flush(); + expect(successCallback).toHaveBeenCalled(); + expect(errorCallback).not.toHaveBeenCalled(); + }); + it('DELETE - /collection/id - should resolve promise on success', function () { + $httpBackend.expectDELETE('' + baseUrl + '/posts/1').respond(200, { + message: 'Success deleting object' + }); + ds.destroy('posts', testObject).then(successCallback, errorCallback); + $httpBackend.flush(); + expect(successCallback).toHaveBeenCalled(); + expect(errorCallback).not.toHaveBeenCalled(); + }); + it('DELETE - /collection/id - should reject promise on error', function () { + $httpBackend.expectDELETE('' + baseUrl + '/posts/1').respond(404, { + message: 'Error deleting object' + }); + ds.destroy('posts', testObject).then(successCallback, errorCallback); + $httpBackend.flush(); + expect(successCallback).not.toHaveBeenCalled(); + expect(errorCallback).toHaveBeenCalled(); + }); });