Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
node_modules
*.log
.env
/build
/build/*
/seeds/*
.DS_Store
8 changes: 8 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,11 @@ function onListening() {
: 'port ' + addr.port;
debug('Listening on ' + bind);
}

const mongoose = require('mongoose')
mongoose.Promise = global.Promise
const connection ='mongodb://localhost/lizardboard'

mongoose.connect(connection)
.then(() => console.log('connection succesful'))
.catch((error) => console.error(error))
20 changes: 20 additions & 0 deletions models/dashboards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const mongoose = require('mongoose')
const { Schema } = mongoose
const User = require('./users.js')
const { DashboardWidgetSchema } = require('./dashboardwidgets.js')

const DashboardSchema = new Schema ({
name: { type: String, required: true, default: 'Company Dashboard' },
location: { type: String, required: true, default: 'Oakland' },
width: { type: Number, required: true, default: 2 },
theme: { type: String, required: true, default: 'Dark' },
responsive: { type: Boolean, required: true, default: true },
created_at: { type: Date, required: true, default: Date.now },
users: [{ type: Schema.Types.ObjectId, ref:'User' }],
dashboard_widgets: [ DashboardWidgetSchema ]
})


const Dashboard = mongoose.model('Dashboard', DashboardSchema)

module.exports = Dashboard
13 changes: 13 additions & 0 deletions models/dashboardwidgets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const mongoose = require('mongoose')
const { Schema } = mongoose

const DashboardWidgetSchema = new Schema ({
type: String,
title: String,
size: String,
contents: String
})

const DashboardWidget = mongoose.model( 'DasboardWidget', DashboardWidgetSchema )

module.exports = { DashboardWidgetSchema, DashboardWidget }
20 changes: 20 additions & 0 deletions models/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const UserSchema = new Schema({
name: String,
username: { type: String, required: true, unique: true },
password: { type: String, required: true },
admin: Boolean,
location: String,
meta: {
age: Number,
website: String
},
created_at: Date,
updated_at: Date
});

const User = mongoose.model('User', UserSchema);

module.exports = User;
13 changes: 13 additions & 0 deletions models/widgets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const mongoose = require('mongoose')
const { Schema } = mongoose

const WidgetSchema = new Schema ({
type: String,
title: String,
size: String,
contents: String
})

const Widget = mongoose.model( 'Widget', WidgetSchema )

module.exports = { WidgetSchema, Widget }
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"debug": "~2.2.0",
"ejs": "^2.5.2",
"express": "~4.13.4",
"mongoose": "^4.6.5",
"mongoose": "^4.6.6",
"morgan": "~1.7.0",
"pug": "^2.0.0-beta6",
"react": "^15.3.2",
Expand Down
7 changes: 7 additions & 0 deletions routes/api/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const dashboards = require('./v1/dashboards')
const users = require('./v1/users')


module.exports = {
v1: { dashboards, users }
}
69 changes: 69 additions & 0 deletions routes/api/v1/dashboards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const Dashboard = require('../../../models/dashboards.js')
const { DashboardWidget } = require('../../../models/dashboardwidgets.js')

const express = require('express')
const router = express.Router()

router.get('/', (request, response, next) => {
Dashboard.find().exec()
.then( dashboard => response.json( dashboard ) )
.catch( error => next( error ) )
})

router.post('/', (request, response, next) => {
Dashboard.create( request.body )
.then( dashboard => response.json( dashboard ) )
.catch( error => next( error ) )
})

router.get('/:id', (request, response, next) => {
Dashboard.findById( request.params.id ).exec()
.then( dashboard => response.json( dashboard ) )
.catch( error => next( error ) )
})

router.put('/:id', (request, response, next) => {
Dashboard.findByIdAndUpdate( request.params.id, request.body ).exec()
.then( dashboard => response.json( dashboard ) )
.catch( error => next( error ) )
})

router.delete('/:id',(request, response, next) => {
Dashboard.findByIdAndRemove( request.params.id ).exec()
.then( dashboard => response.json( dashboard ) )
.catch( error => next( error ) )
})

// get all widgets by dashboard_id
// GET dashboards/:id/widgets/

// router.get('/:id/widgets/', (request, response, next) => {
// const findAllWidgets = widgetData => dashboard => {
// return dashboard.widgets.find().exec()
// }
// Widget.find({}, 'widgets'
// Dashboard.findById( request.params.id ).exec()
// .then( ).exec())
// .then( dashboard => response.json( dashboard ) )
// .catch( error => next( error ) )
// })

router.post('/:id/dashboardwidgets', (request, response, next) => {
const addDashboardWidget = dashboardWidgetData => dashboard => {
dashboard.dashboard_widgets.push( new DashboardWidget( dashboardWidgetData ) )
return dashboard.save()
}

Dashboard.findById( request.params.id ).exec()
.then( addDashboardWidget( request.body ))
.then( dashboard => response.json( dashboard ) )
.catch( error => next( error ) )
})

// update widget by dashboard_id and widget_id
// PUT dashboards/:id/widgets/:id

// delete widget by dashboard_id and widget_id
// DELETE dashboards/:id/widgets/:id

module.exports = router
36 changes: 36 additions & 0 deletions routes/api/v1/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const User = require('../../../models/users.js')

const express = require('express')
const router = express.Router()

router.get('/', (request, response, next) => {
User.find().exec()
.then( user => response.json( user ) )
.catch( error => next( error ) )
})

router.post('/', (request, response, next) => {
User.create( request.body )
.then( user => response.json( user ) )
.catch( error => next( error ) )
})

router.get('/:id', (request, response, next) => {
User.findById( request.params.id ).exec()
.then( user => response.json( user ) )
.catch( error => next( error ) )
})

router.put('/:id', (request, response, next) => {
User.findByIdAndUpdate( request.params.id, request.body ).exec()
.then( user => response.json( user ) )
.catch( error => next( error ) )
})

router.delete('/:id',(request, response, next) => {
User.findByIdAndRemove( request.params.id ).exec()
.then( user => response.json( user ) )
.catch( error => next( error ) )
})

module.exports = router
1 change: 0 additions & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const express = require('express');
const router = express.Router();

/* GET home page. */
router.get('/', (request, response, next) => {
response.render('index', { title: 'Dragonboard', logo: 'D' });
});
Expand Down
10 changes: 8 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const bodyParser = require('body-parser');
const routes = require('../routes/index');
const users = require('../routes/users');

// const widgets = require( './routes/widgets' )
const api = require( '../routes/api/manifest').v1

const appRoot = process.env.APP_ROOT
const app = express();

Expand Down Expand Up @@ -38,6 +41,10 @@ app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);
app.use('/users', users);

app.use( '/api/v1/dashboards', api.dashboards )
app.use( '/api/v1/users', api.users )


// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
Expand Down Expand Up @@ -69,5 +76,4 @@ app.use(function(err, req, res, next) {
});
});


module.exports = app;
module.exports = app;
8 changes: 8 additions & 0 deletions views/dashboard.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extends layout

block content
h1 Create a Dashboard
form(action='/dashboards',method='post')
| Dashboard Name:
input(name='name' type='text' value='Company Dashboard' placeholder='dashboard title')
input(type='submit', value='Submit')
22 changes: 11 additions & 11 deletions views/layout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ html
link(rel='stylesheet', href='/stylesheets/style.css')

div.nav
div.nav-header-left
h1.logo= logo
h2.title= title
div.nav-header-left
h1.logo= logo
h2.title= title

div.nav-header-right
a(href= '/product') Product
a(href= '/users/login') Login
input(type="text", placeholder="Email address")
button(type="submit" ) Free Trial
div.nav-header-right
a(href= '/product') Product
a(href= '/users/login') Login
input(type="text", placeholder="Email address")
button(type="submit" ) Free Trial

body
block content

div.footer-nav

include footer
script(src="/javascripts/index.js")
script(src="/public/javascripts/index.js")
//- include footer
//- script(src="/javascripts/index.js")
//- script(src="/public/javascripts/index.js")
Loading