Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed the way that the dashboard controller was loaded

  • Loading branch information...
commit 04cd97fb6c3e4acd841820821b383a4ac1d8bcf5 1 parent ae2b9a4
@paulbjensen paulbjensen authored
View
2  internals.coffee
@@ -11,6 +11,8 @@ app.config = require('./server/config')[ss.env]
require("#{__dirname}/server/db.coffee") app
require("#{__dirname}/server/mailer.coffee") app
+require("#{__dirname}/server/controllers/dashboard.coffee") app
+
ss.api.add 'app', app
#### HELPERS ####
View
2  server/api.coffee
@@ -1,6 +1,6 @@
# Controllers, a way of sharing common logic between RPC and REST APIs
ss = require 'socketstream'
-dashboardController = require "./controllers/dashboard.coffee"
+dashboardController = ss.api.app.controllers.dashboard
widgetController = require "./controllers/widget.coffee"
Redis = ss.api.app.Redis
View
99 server/controllers/dashboard.coffee
@@ -1,56 +1,59 @@
#### The Dashboard controller ####
ss = require 'socketstream'
-Dashboard = ss.api.app.models.Dashboard
-module.exports =
+module.exports = (app) ->
+
+ Dashboard = app.models.Dashboard
+
+ app.controllers.dashboard =
- create: (data, cb) ->
- dashboard = new Dashboard data
- dashboard.save (err,doc) ->
- if !err
- ss.api.publish.channel "user_#{data.userId}", 'dashboardCreated', doc
- cb status: 'success', dashboard: doc
- else
- cb status: 'failure', reason: err.message
+ create: (data, cb) ->
+ dashboard = new Dashboard data
+ dashboard.save (err,doc) ->
+ if !err
+ ss.api.publish.channel "user_#{data.userId}", 'dashboardCreated', doc
+ cb status: 'success', dashboard: doc
+ else
+ cb status: 'failure', reason: err.message
- getAll: (data, cb) ->
- Dashboard.find data, {}, {sort: {name: 1}}, (err, dashboards) ->
- if !err and dashboards?
- cb status: 'success', dashboards: dashboards
- else
- cb status: 'failure', reason: err
+ getAll: (data, cb) ->
+ Dashboard.find data, {}, {sort: {name: 1}}, (err, dashboards) ->
+ if !err and dashboards?
+ cb status: 'success', dashboards: dashboards
+ else
+ cb status: 'failure', reason: err
- get: (data, cb) ->
- Dashboard.findOne data, (err, dashboard) ->
- if !err and dashboard?
- cb status: 'success', dashboard: dashboard
- else
- cb status: 'failure', reason: if dashboard? then err else "Dashboard not found"
+ get: (data, cb) ->
+ Dashboard.findOne data, (err, dashboard) ->
+ if !err and dashboard?
+ cb status: 'success', dashboard: dashboard
+ else
+ cb status: 'failure', reason: if dashboard? then err else "Dashboard not found"
- update: (data, cb) ->
- Dashboard.findOne {_id: data._id, userId: data.userId}, (err, dashboard) ->
- if !err and dashboard?
- dashboard[key] = value for key,value of data
- dashboard.updatedAt = Date.now()
- dashboard.save (err, dashboard) ->
- if !err
- # NOTE - My opinion is that models is a natural place for PubSub events
- # like this one. I may change this in the future
- ss.api.publish.channel "user_#{data.userId}", 'dashboardUpdated', dashboard
- cb status: 'success', dashboard: dashboard
- else
- cb status: 'failure', reason: err
- else
- cb status: 'failure', reason: if dashboard? then err else "Dashboard not found"
+ update: (data, cb) ->
+ Dashboard.findOne {_id: data._id, userId: data.userId}, (err, dashboard) ->
+ if !err and dashboard?
+ dashboard[key] = value for key,value of data
+ dashboard.updatedAt = Date.now()
+ dashboard.save (err, dashboard) ->
+ if !err
+ # NOTE - My opinion is that models is a natural place for PubSub events
+ # like this one. I may change this in the future
+ ss.api.publish.channel "user_#{data.userId}", 'dashboardUpdated', dashboard
+ cb status: 'success', dashboard: dashboard
+ else
+ cb status: 'failure', reason: err
+ else
+ cb status: 'failure', reason: if dashboard? then err else "Dashboard not found"
- delete: (data, cb) ->
- Dashboard.find {userId: data.userId}, (err, dashboards) ->
- if !err and dashboards.length > 1
- Dashboard.remove {_id: data.id, userId: data.userId}, (err) ->
- if !err
- ss.api.publish.channel "user_#{data.userId}", 'dashboardDeleted', data.id
- cb status: 'success', dashboardId: data.id
- else
- cb status: 'failure', reason: "Dashboard not found"
- else
- cb status: 'failure', reason: err || "You can't delete your last dashboard"
+ delete: (data, cb) ->
+ Dashboard.find {userId: data.userId}, (err, dashboards) ->
+ if !err and dashboards.length > 1
+ Dashboard.remove {_id: data.id, userId: data.userId}, (err) ->
+ if !err
+ ss.api.publish.channel "user_#{data.userId}", 'dashboardDeleted', data.id
+ cb status: 'success', dashboardId: data.id
+ else
+ cb status: 'failure', reason: "Dashboard not found"
+ else
+ cb status: 'failure', reason: err || "You can't delete your last dashboard"
View
2  server/rpc/dashboard.coffee
@@ -2,7 +2,7 @@
ss = require 'socketstream'
_ = require 'underscore'
-dashboardController = require "../controllers/dashboard.coffee"
+dashboardController = ss.api.app.controllers.dashboard
Dashboard = ss.api.app.models.Dashboard
fetchUserFromSession = ss.api.fetchUserFromSession
Please sign in to comment.
Something went wrong with that request. Please try again.