Skip to content

Commit

Permalink
support public dashboards
Browse files Browse the repository at this point in the history
  • Loading branch information
eknowles committed Sep 20, 2015
1 parent d799ce8 commit 60293dc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
5 changes: 5 additions & 0 deletions public/partial/home/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ <h1 class="text-center">openboard</h1>
</section>
<section class="public-dashboards">
<p><strong>Public Dashboards</strong></p>
<ul class="list-unstyled">
<li ng-repeat="dashboard in publicDashboards track by dashboard.id">
<a ui-sref="dashboard({dashboardId:dashboard.id})">{{dashboard.title}}</a>
</li>
</ul>
<p ng-if="!publicDashboards.length" class="text-muted">We couldn't find any public dashboards.</p>
</section>
</div>
Expand Down
2 changes: 2 additions & 0 deletions public/partial/home/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ angular.module('openboard').controller('HomeCtrl', function ($scope, Dashboard,

$scope.dashboards = Dashboard.query();

$scope.publicDashboards = Dashboard.query({'public': 1});

$scope.schema = {
type: "object",
properties: {
Expand Down
16 changes: 6 additions & 10 deletions routes/dashboards.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ var async = require('async');
var allowedKeys = ['title', 'public', 'theme', 'customStyle', 'columns'];

exports.findAll = function (req, res) {
db.Dashboard.findAll({
where: {userId: req.ntlm.UserName},
order: [
['createdAt', 'DESC']
]
}).then(function (entities) {
var q = req.query.public === '1' ? {where: {public: true}} : {where: {userId: req.ntlm.UserName}};
db.Dashboard.findAll(q).then(function (entities) {
return res.json(entities);
}, function (err) {
return res.send(500, err);
Expand All @@ -20,7 +16,7 @@ exports.findAll = function (req, res) {
exports.find = function (req, res) {
db.Dashboard.findById(req.param('dashboardId')).then(function (entity) {
if (!entity) return res.send(404);
if (entity.userId !== req.ntlm.UserName) return res.send(403);
if (entity.public !== true && entity.userId !== req.ntlm.UserName) return res.send(403);
return res.json(entity);
})
};
Expand All @@ -39,9 +35,9 @@ exports.create = function (req, res) {
};

exports.update = function (req, res) {
var query = {where: {id: req.param('dashboardId'), userId: req.ntlm.UserName}};
db.Dashboard.find(query).then(function (entity) {
db.Dashboard.findById(req.param('dashboardId')).then(function (entity) {
if (!entity) return res.send(404);
if (entity.userId !== req.ntlm.UserName) return res.send(403);
var update = _.pick(req.body, allowedKeys);
entity.updateAttributes(update).then(function (entity) {
res.json(entity)
Expand All @@ -50,7 +46,7 @@ exports.update = function (req, res) {
};

exports.destroy = function (req, res) {
db.Dashboard.find({where: {id: req.param('dashboardId')}}).then(function (entity) {
db.Dashboard.findById(req.param('dashboardId')).then(function (entity) {
if (!entity) return res.send(404);
if (entity.userId !== req.ntlm.UserName) return res.send(403);
entity.destroy().then(function () {
Expand Down
2 changes: 1 addition & 1 deletion routes/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exports.findAll = function (req, res) {
exports.find = function (req, res) {
db.Dashboard.findById(req.param('dashboardId'), {attributes: ['id', 'userId']}).then(function (dashboard) {
if (!dashboard) return res.send(404);
if (dashboard.userId !== req.ntlm.UserName) return res.send(403);
if (dashboard.public !== true && dashboard.userId !== req.ntlm.UserName) return res.send(403);
db.Widget.find({where: {id: req.param('widgetId'), dashboardId: dashboard.id}}).then(function (entity) {
return !entity ? res.json(entity) : res.send(404);
}, function (err) {
Expand Down

0 comments on commit 60293dc

Please sign in to comment.