Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
General layout for the whitelist section, will be adding tests in the…
Browse files Browse the repository at this point in the history
… subsequents commits for the section
  • Loading branch information
Johanndutoit committed Nov 5, 2015
1 parent 954fd25 commit d3d1d8f
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 1 deletion.
3 changes: 2 additions & 1 deletion goddard/handlers/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ module.exports = exports = (app) ->
require('./nodes')(app)
require('./groups')(app)
require('./apps')(app)
require('./tokens')(app)
require('./tokens')(app)
require('./whitelist')(app)
43 changes: 43 additions & 0 deletions goddard/handlers/whitelist/create.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# acts as the homepage for the dashboard
### istanbul ignore next ###
module.exports = exports = (app) ->

# required modules
async = require('async')
S = require('string')
fs = require('fs')
uuid = require('node-uuid')

# the homepage for load balancer
app.get '/whitelist/create', (req, res) ->

# get all the groups
app.get('models').groups.findAll().then (group_objs) ->

# render the create page
res.render 'whitelist/create', {

title: 'Create a Whitelist Item',
group_objs: group_objs

}

# the homepage for load balancer
app.post '/whitelist/create', (req, res) ->

# get the params
param_name_str = req.body.name
param_domain_str = req.body.domain
param_group_int = req.body.group

# output
whitelist_obj = app.get('models').whitelist.build({

name: param_name_str,
domain: param_domain_str,
groupId: param_group_int

})

# run it
whitelist_obj.save().then -> res.redirect '/whitelist'
8 changes: 8 additions & 0 deletions goddard/handlers/whitelist/index.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# loads all the modules and the subdirs for the app
### istanbul ignore next ###
module.exports = exports = (app) ->

# load in our modules
require('./list')(app)
require('./create')(app)
require('./view')(app)
51 changes: 51 additions & 0 deletions goddard/handlers/whitelist/list.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module.exports = exports = (app) ->

# the homepage for load balancer
app.get '/tokens', app.get('middleware').checkLoggedIn, app.get('middleware').handlePagination, (req, res) ->

# search params
filter_params = {}

# was the search given ?
if req.query.q
filter_params = { name: { like: '%' + req.query.q + '%' } }

# get all the nodes
app.get('models').whitelist.findAndCountAll(

offset: req.requesting_pagination_offset,
limit: req.requesting_pagination_limit,
where: filter_params

).then((result) ->

# render them out
res.render 'whitelist/list', {

title: 'Domains users are allowed to browse',
description: 'Domains users are allowed to browse',
items: result.rows,
limit: req.requesting_pagination_limit,
offset: req.requesting_pagination_offset,
total_count: result.count,
current_page: req.requesting_pagination_page,
pages: Math.ceil( result.count / req.requesting_pagination_limit )

}

).catch((err) ->

# render them out
res.render 'whitelist/list', {

title: 'Domains users are allowed to browse',
items: [],
limit: req.requesting_pagination_limit,
offset: req.requesting_pagination_offset,
total_count: 0,
current_page: req.requesting_pagination_page,
pages: 0

}

)
39 changes: 39 additions & 0 deletions goddard/handlers/whitelist/view.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# acts as the homepage for the dashboard
### istanbul ignore next ###
module.exports = exports = (app) ->

# required modules
S = require('string')

# the homepage for load balancer
app.get '/whitelist/:whitelistid', app.get('middleware').checkLoggedIn, (req, res) ->

# get all the groups
app.get('models').groups.findAll().then (group_objs) ->

app.get('models').whitelist.find(req.params.whitelistid).then((item_obj) ->
if not item_obj
res.redirect '/whitelist'
return

item_obj = item_obj.get()
res.render 'whitelist/view', {

title: item_obj.name,
item_obj: item_obj,
group_objs: group_objs

}
)

# the homepage for load balancer
app.post '/whitelist/:whitelistid', app.get('middleware').checkLoggedIn, (req, res) ->

app.get('models').whitelist.find(req.params.whitelistid).then((item_obj) ->
if not item_obj
res.redirect '/whitelist'
return

item_obj.name = req.body.name
item_obj.domain = req.body.domain
)
29 changes: 29 additions & 0 deletions views/whitelist/create.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
extends ../layout

block content
.row
.col-md-6.col-md-offset-3
br
br
br
br
form.form(action="/whitelist/create",method="post")
.form-group
label(for="") Friendly Name
input.form-control(name="name",type="text")
.form-group
label(for="group") Group
select.form-control(name="group")
option(value="none") None
-each group_obj in group_objs
option(value=group_obj.id,selected=post_params.group==group_obj.id) #{group_obj.name}
.form-group
label(for="") Domain
input.form-control(name="domain",type="text")


button.btn.btn-primary.btn-lg CREATE
br
br
br
br
35 changes: 35 additions & 0 deletions views/whitelist/list.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
extends ../layout

block content
.row
.col-md-12
table.table
thead
tr
th  
th(style="width:40%;")  
tbody
-each item_obj in items
tr
td
p(style="margin:0;margin-bottom:5px;font-size: 16px;")
a(href="/whitelist/" + item_obj.id) #{item_obj.name}
p(style="margin:0;font-size: 11px;") #{item_obj.description}
td
.pull-right
a.btn.btn-default(style="margin-left: 10px;",href="/whitelist/#{item_obj.id}") Manage
.clearfix

.row
.col-md-12
.pull-right
nav
ul.pagination
-if(current_page > 1)
li
a(href="/whitelist?q=" + (post_params.q ? post_params.q : '') + "&limit=" + limit + "&page=" + (current_page-1))
span Back
-if(current_page < pages)
li
a(href="/whitelist?q=" + (post_params.q ? post_params.q : '') + "&limit=" + limit + "&page=" + (current_page+1))
span Next
28 changes: 28 additions & 0 deletions views/whitelist/view.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
extends ../layout

block content
.row
.col-md-6.col-md-offset-3
br
br
br
br
form.form(action="/whitelist/" + item_obj.id,method="post")
.form-group
label(for="") Friendly Name
input.form-control(name="name",type="text",value=post_params.name || item_obj.name)
.form-group
label(for="group") Group
select.form-control(name="group")
option(value="none") None
-each group_obj in group_objs
option(value=group_obj.id,selected=item_obj.groupId==group_obj.id) #{group_obj.name}
.form-group
label(for="") Domain
input.form-control(name="key",type="text",value=post_params.domain || item_obj.domain)

button.btn.btn-primary.btn-lg UPDATE
br
br
br
br

0 comments on commit d3d1d8f

Please sign in to comment.