diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 78076d6..0000000 --- a/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2016 Deployd LLC, Andrei Alecu, Nicolas Ritouet and Deployd contributors - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 2fe51f1..eb91e65 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,14 @@ > Add a dashboard for your [Deployd](http://deployd.com/) app +## Deployd Dashboard +New Deployd dashboard has these features: +1. New Theme + +Features to be added: +1. Enable Dashboard plugins + + ## Getting started To install the Deployd Dashboard in your existing Deployd project, run the following command: @@ -20,6 +28,16 @@ If you do not plan to use the dashboard on production, use the following command npm install dpd-dashboard --save-dev ``` +Screenshots: + + + + + + + + + ## License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details \ No newline at end of file diff --git a/dashboard.js b/dashboard.js index 96c9076..dc2a2d4 100644 --- a/dashboard.js +++ b/dashboard.js @@ -1,13 +1,13 @@ -var util = require('util') - , httpUtil = require('deployd/lib/util/http') - , filed = require('filed') - , Resource = require('deployd/lib/resource') - , path = require('path') - , debug = require('debug')('dashboard') - , fs = require('fs') - , ejs = require('ejs') - , loadTypes = require('deployd/lib/type-loader') - , async = require('async'); +var util = require('util'), + httpUtil = require('deployd/lib/util/http'), + filed = require('filed'), + Resource = require('deployd/lib/resource'), + path = require('path'), + debug = require('debug')('dashboard'), + fs = require('fs'), + ejs = require('ejs'), + loadTypes = require('deployd/lib/type-loader'), + async = require('async') ; function Dashboard(name, options) { // internal resource @@ -15,21 +15,23 @@ function Dashboard(name, options) { this.loadTypes = async.memoize(this.loadTypes); this.loadLayout = async.memoize(this.loadLayout); - + Resource.apply(this, arguments); } util.inherits(Dashboard, Resource); module.exports = Dashboard; -Dashboard.selfHost = function(options) { +Dashboard.selfHost = function (options) { return new Dashboard('dashboard', options); } -Dashboard.prototype.handle = function(ctx, next) { - if (ctx.req.url === this.path) { +Dashboard.prototype.handle = function (ctx, next) { + if (ctx.req.url === this.path) { return httpUtil.redirect(ctx.res, ctx.req.url + '/'); } else if (ctx.url === '/__is-root') { - ctx.done(null, {isRoot: ctx.req.isRoot}); + ctx.done(null, { + isRoot: ctx.req.isRoot + }); } else if (ctx.url.indexOf('/__custom') === 0) { this.serveCustomAsset(ctx, next); } else if (ctx.url.indexOf('.') !== -1) { @@ -43,18 +45,19 @@ Dashboard.prototype.handle = function(ctx, next) { }; -Dashboard.prototype.serveCustomAsset = function(ctx, next) { - var parts = ctx.url.split('/').filter(function(p) { return p; }) - , resourceTypePath = parts[1] - , resource = this; +Dashboard.prototype.serveCustomAsset = function (ctx, next) { + var parts = ctx.url.split('/').filter(function (p) { + return p; + }), + resourceTypePath = parts[1], + resource = this; - resource.loadTypes(function(err, types) { - var resourceTypeId - , resourceType - , dashboardPath - , reqUrl = parts.slice(2).join('/'); + resource.loadTypes(function (err, types) { + var resourceTypeId, resourceType, dashboardPath, reqUrl = parts.slice(2).join('/'); - resourceTypeId = Object.keys(types).filter(function(t) { return t.toLowerCase() === resourceTypePath; })[0]; + resourceTypeId = Object.keys(types).filter(function (t) { + return t.toLowerCase() === resourceTypePath; + })[0]; if (resourceTypeId) { resourceType = types[resourceTypeId]; @@ -68,44 +71,50 @@ Dashboard.prototype.serveCustomAsset = function(ctx, next) { }); }; -Dashboard.prototype.loadTypes = function(fn) { - loadTypes(function(defaults, types) { - Object.keys(defaults).forEach(function(key) { +Dashboard.prototype.loadTypes = function (fn) { + loadTypes(function (defaults, types) { + Object.keys(defaults).forEach(function (key) { types[key] = defaults[key]; }); fn(null, types); }); }; -Dashboard.prototype.render = function(ctx) { - var self = this - , appName = path.basename(path.resolve('./')) - , env = ctx.server && ctx.server.options && ctx.server.options.env; +Dashboard.prototype.render = function (ctx) { + var self = this, + appName = path.basename(path.resolve('./')), + env = ctx.server && ctx.server.options && ctx.server.options.env; async.parallel({ - layout: self.loadLayout - , options: async.apply(self.loadPage.bind(self), ctx) - }, function(err, results) { + layout: self.loadLayout, + options: async.apply(self.loadPage.bind(self), ctx) + }, function (err, results) { if (err) return ctx.done(err); - var options = results.options || {} - , layout = results.layout - , render = {}; + var options = results.options || {}, + layout = results.layout, + render = {}; var context = { - resourceId: options.resourceId - , resourceType: options.resourceType - , page: options.page - , basicDashboard: options.basicDashboard - , events: options.events - , appName: appName - , env: env + resourceId: options.resourceId, + resourceType: options.resourceType, + page: options.page, + basicDashboard: options.basicDashboard, + events: options.events, + appName: appName, + env: env }; render.bodyHtml = options.bodyHtml; try { - var rendered = layout({context: context, render: render, scripts: options.scripts || [], css: options.css || null, version: require('./package.json').version}); + var rendered = layout({ + context: context, + render: render, + scripts: options.scripts || [], + css: options.css || null, + version: require('./package.json').version + }); ctx.res.setHeader('Content-Type', 'text/html; charset=UTF-8'); ctx.res.end(rendered); } catch (ex) { @@ -114,25 +123,24 @@ Dashboard.prototype.render = function(ctx) { }); }; -Dashboard.prototype.loadLayout = function(fn) { +Dashboard.prototype.loadLayout = function (fn) { - fs.readFile(path.join(__dirname, 'dashboard', 'index.ejs'), 'utf-8', function(err, layout) { + fs.readFile(path.join(__dirname, 'dashboard', 'index.ejs'), 'utf-8', function (err, layout) { if (err) return fn(err); - var layoutTemplate = ejs.compile(layout, {delimiter:'?'}); //Avoid conlicts by using non-standard tags + var layoutTemplate = ejs.compile(layout, { + delimiter: '?' + }); //Avoid conlicts by using non-standard tags fn(null, layoutTemplate); }); }; -Dashboard.prototype.loadPage = function(ctx, fn) { - var parts = ctx.url.split('/').filter(function(p) { return p; }) - , resourceId - , resource - , resourceType - , options = {} - , self = this - , dashboardPath - , pagePath - , page; +Dashboard.prototype.loadPage = function (ctx, fn) { + var parts = ctx.url.split('/').filter(function (p) { + return p; + }), + resourceId, resource, resourceType, options = {}, + self = this, + dashboardPath, pagePath, page; if (parts.length) { if (/\/$/.test(ctx.url)) { // if the url ends with a slash, we have a page @@ -142,8 +150,10 @@ Dashboard.prototype.loadPage = function(ctx, fn) { // otherwise, the resource is the full url resourceId = parts.join('/'); } - - resource = ctx.server.resources.filter(function(r) { return r.name === resourceId.toLowerCase() })[0]; + + resource = ctx.server.resources.filter(function (r) { + return r.name === resourceId.toLowerCase() + })[0]; if (resource) { options.resourceId = resourceId; @@ -163,10 +173,10 @@ Dashboard.prototype.loadPage = function(ctx, fn) { dashboardPath = resourceType.dashboard && resourceType.dashboard.path; async.waterfall([ - function(fn) { + function (fn) { if (dashboardPath) { pagePath = path.join(dashboardPath, page + '.html'); - fs.exists(pagePath, function(exists) { + fs.exists(pagePath, function (exists) { fn(null, exists); }); } else { @@ -174,24 +184,24 @@ Dashboard.prototype.loadPage = function(ctx, fn) { } }, - function(exists, fn) { + function (exists, fn) { if (exists) { self.loadAdvancedDashboard({ - pagePath: pagePath - , dashboardPath: dashboardPath - , page: page - , resourceType: resourceType - , options: options + pagePath: pagePath, + dashboardPath: dashboardPath, + page: page, + resourceType: resourceType, + options: options }, fn); } else { self.loadBasicDashboard({ - options: options - , page: page - , resourceType: resourceType + options: options, + page: page, + resourceType: resourceType }, fn); } } - ], function(err) { + ], function (err) { fn(err, options); }); @@ -204,27 +214,27 @@ Dashboard.prototype.loadPage = function(ctx, fn) { fn(); //blank page }; -Dashboard.prototype.loadAdvancedDashboard = function(data, fn) { - var pagePath = data.pagePath - , dashboardPath = data.dashboardPath - , page = data.page - , resourceType = data.resourceType - , options = data.options; +Dashboard.prototype.loadAdvancedDashboard = function (data, fn) { + var pagePath = data.pagePath, + dashboardPath = data.dashboardPath, + page = data.page, + resourceType = data.resourceType, + options = data.options; async.parallel({ - bodyHtml: function(fn) { + bodyHtml: function (fn) { fs.readFile(pagePath, 'utf-8', fn); }, - scripts: function(fn) { + scripts: function (fn) { if (resourceType.dashboard.scripts) { - resourceType.dashboard.scripts.forEach(function(s) { + resourceType.dashboard.scripts.forEach(function (s) { options.scripts.push('/__custom/' + resourceType.name.toLowerCase() + s); }); } - fs.exists(path.join(dashboardPath, 'js', page + '.js'), function(exists) { + fs.exists(path.join(dashboardPath, 'js', page + '.js'), function (exists) { if (exists) { options.scripts.push('/__custom/' + resourceType.name.toLowerCase() + '/js/' + page + '.js'); } @@ -233,8 +243,8 @@ Dashboard.prototype.loadAdvancedDashboard = function(data, fn) { }); }, - stylesheet: function(fn) { - fs.exists(path.join(resourceType.dashboard.path, 'style.css'), function(exists) { + stylesheet: function (fn) { + fs.exists(path.join(resourceType.dashboard.path, 'style.css'), function (exists) { if (exists) { options.css = '/__custom/' + resourceType.name.toLowerCase() + '/style.css'; } @@ -242,7 +252,7 @@ Dashboard.prototype.loadAdvancedDashboard = function(data, fn) { fn(); }); } - }, function(err, results) { + }, function (err, results) { if (err) return fn(err); options.bodyHtml = results.bodyHtml; @@ -254,11 +264,11 @@ Dashboard.prototype.loadAdvancedDashboard = function(data, fn) { }); }; -Dashboard.prototype.loadBasicDashboard = function(data, fn) { - var options = data.options - , page = data.page - , resourceType = data.resourceType - , dashboardPath = path.join(__dirname, 'dashboard'); +Dashboard.prototype.loadBasicDashboard = function (data, fn) { + var options = data.options, + page = data.page, + resourceType = data.resourceType, + dashboardPath = path.join(__dirname, 'dashboard'); options.page = page; if (page === 'index') { @@ -266,23 +276,23 @@ Dashboard.prototype.loadBasicDashboard = function(data, fn) { if (resourceType.basicDashboard) { options.scripts.push('/js/basic.js'); options.basicDashboard = resourceType.basicDashboard; - fs.readFile(path.join(dashboardPath, 'basic.html'), function(err, bodyHtml) { + fs.readFile(path.join(dashboardPath, 'basic.html'), function (err, bodyHtml) { options.bodyHtml = bodyHtml; fn(err); }); } else { options.scripts.push('/js/default.js'); - fs.readFile(path.join(dashboardPath, 'default.html'), function(err, bodyHtml) { + fs.readFile(path.join(dashboardPath, 'default.html'), function (err, bodyHtml) { options.bodyHtml = bodyHtml; fn(err); }); } } else if (page === 'events') { - fs.readFile(path.join(dashboardPath, 'events.html'), function(err, bodyHtml) { + fs.readFile(path.join(dashboardPath, 'events.html'), function (err, bodyHtml) { options.bodyHtml = bodyHtml; fn(err); }); } else { return fn(); } -}; +}; \ No newline at end of file diff --git a/dashboard/assets/example.jpg b/dashboard/assets/example.jpg new file mode 100644 index 0000000..4ab773b Binary files /dev/null and b/dashboard/assets/example.jpg differ diff --git a/dashboard/assets/f.png b/dashboard/assets/f.png new file mode 100644 index 0000000..8c89b27 Binary files /dev/null and b/dashboard/assets/f.png differ diff --git a/dashboard/assets/folder.open.png b/dashboard/assets/folder.open.png new file mode 100644 index 0000000..6b5d520 Binary files /dev/null and b/dashboard/assets/folder.open.png differ diff --git a/dashboard/assets/folder.png b/dashboard/assets/folder.png new file mode 100644 index 0000000..df03153 Binary files /dev/null and b/dashboard/assets/folder.png differ diff --git a/dashboard/assets/line.horizontal.png b/dashboard/assets/line.horizontal.png new file mode 100644 index 0000000..a706fc7 Binary files /dev/null and b/dashboard/assets/line.horizontal.png differ diff --git a/dashboard/assets/line.junction1.png b/dashboard/assets/line.junction1.png new file mode 100644 index 0000000..3211876 Binary files /dev/null and b/dashboard/assets/line.junction1.png differ diff --git a/dashboard/assets/line.junction2.png b/dashboard/assets/line.junction2.png new file mode 100644 index 0000000..3064e8d Binary files /dev/null and b/dashboard/assets/line.junction2.png differ diff --git a/dashboard/assets/line.vertical.png b/dashboard/assets/line.vertical.png new file mode 100644 index 0000000..b4564bf Binary files /dev/null and b/dashboard/assets/line.vertical.png differ diff --git a/dashboard/img/dpd-logo-only.png b/dashboard/img/dpd-logo-only.png new file mode 100644 index 0000000..b142a92 Binary files /dev/null and b/dashboard/img/dpd-logo-only.png differ diff --git a/dashboard/img/dpd-logo.png b/dashboard/img/dpd-logo.png new file mode 100644 index 0000000..21eba8e Binary files /dev/null and b/dashboard/img/dpd-logo.png differ diff --git a/dashboard/index.ejs b/dashboard/index.ejs index c4a4806..b1e9587 100644 --- a/dashboard/index.ejs +++ b/dashboard/index.ejs @@ -1,137 +1,161 @@ -
-