mirror of
https://github.com/zhigang1992/deployd.git
synced 2026-05-13 12:37:17 +08:00
Made deployments page load actual registered deployments
This commit is contained in:
@@ -2,6 +2,7 @@ var fs = require('fs')
|
||||
, path = require('path')
|
||||
, _loadTypes = require('./type-loader')
|
||||
, InternalResources = require('./resources/internal-resources')
|
||||
, InternalDeployments = require('./resources/internal-deployments')
|
||||
, Files = require('./resources/files')
|
||||
, ClientLib = require('./resources/client-lib')
|
||||
, Dashboard = require('./resources/dashboard')
|
||||
@@ -174,6 +175,7 @@ function addInternalResources(server, basepath, resources, fn) {
|
||||
new Files('', { config: { 'public': publicFolder }, server: server })
|
||||
, new ClientLib('dpd.js', { config: { resources: resources }, server: server})
|
||||
, new InternalResources('__resources', {config: {configPath: basepath}, server: server})
|
||||
, new InternalDeployments('__deployments', {server: server})
|
||||
, new Dashboard('dashboard', {server: server})
|
||||
];
|
||||
async.forEach(internals, loadResourceExtras, function(err) {
|
||||
|
||||
@@ -2,30 +2,13 @@
|
||||
<div class="well">
|
||||
<h3 class="clearfix">
|
||||
Deployments
|
||||
<a class="pull-right header-link" href="http://deploydapp.com">Manage</a>
|
||||
<a class="pull-right header-link" href="http://deploydapp.com/apps">Manage</a>
|
||||
</h3>
|
||||
|
||||
<div id="deployments-empty" class="empty hide">
|
||||
You do not have any deployments. Add one now:
|
||||
</div>
|
||||
<ul class="component-list" id="deployment-list">
|
||||
<li class="component-item">
|
||||
<div class="component-item-header">
|
||||
<span class="code deploymentname">my-awesome-app-production</span>
|
||||
<div class="pull-right actions">
|
||||
<a href="#">Deploy</a>
|
||||
<a href="#">Manage</a>
|
||||
<a href="#">Remove</a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="component-item">
|
||||
<div class="component-item-header">
|
||||
<span class="code deploymentname">my-awesome-app-staging</span>
|
||||
<div class="pull-right actions">
|
||||
<a href="#">Deploy</a>
|
||||
<a href="#">Manage</a>
|
||||
<a href="#">Remove</a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<hr />
|
||||
@@ -48,4 +31,17 @@
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/html" id="deployment-template">
|
||||
<li class="component-item" data-index="<%= index %>">
|
||||
<div class="component-item-header">
|
||||
<span class="code deploymentname"><%= deployment.name %></span>
|
||||
<div class="pull-right actions">
|
||||
<a href="#" class="deploy-btn">Deploy</a>
|
||||
<a href="http://deploydapp.com/apps/<%= deployment.name %>" class="manage-btn">Manage</a>
|
||||
<a href="#" class="remove-btn">Remove</a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</script>
|
||||
@@ -0,0 +1,44 @@
|
||||
(function() {
|
||||
|
||||
var scope = {
|
||||
deployments: null
|
||||
};
|
||||
|
||||
var dpdDeployments = dpd('__deployments');
|
||||
var deploymentTemplate = _.template($('#deployment-template').html());
|
||||
|
||||
loadDeployments();
|
||||
|
||||
$('#deployment-list').on('click', '.component-item', onClickDeployment);
|
||||
|
||||
function loadDeployments() {
|
||||
dpdDeployments.get(function(deployments, error) {
|
||||
scope.deployments = deployments;
|
||||
renderDeployments();
|
||||
});
|
||||
}
|
||||
|
||||
function onClickDeployment() {
|
||||
var href = $(this).find('.manage-btn').attr('href');
|
||||
location.href = href;
|
||||
}
|
||||
|
||||
function renderDeployments() {
|
||||
if (scope.deployments === null || scope.deployments.length) {
|
||||
$('#deployments-empty').hide();
|
||||
} else {
|
||||
$('#deployments-empty').show();
|
||||
}
|
||||
|
||||
if (scope.deployments) {
|
||||
$('#deployment-list').empty();
|
||||
scope.deployments.forEach(function(d, i) {
|
||||
$('#deployment-list').append(deploymentTemplate({
|
||||
deployment: d,
|
||||
index: i
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -8,6 +8,11 @@
|
||||
border-top-color: #555
|
||||
}
|
||||
|
||||
.empty {
|
||||
margin-top: 20px;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.component-item-header {
|
||||
.actions {
|
||||
visibility: hidden;
|
||||
|
||||
61
lib/resources/internal-deployments.js
Normal file
61
lib/resources/internal-deployments.js
Normal file
@@ -0,0 +1,61 @@
|
||||
var util = require('util')
|
||||
, Resource = require('../resource')
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, q = require('q')
|
||||
, qutil = require('../util/qutil');
|
||||
|
||||
function InternalDeployments() {
|
||||
Resource.apply(this, arguments);
|
||||
this.deploymentsFile = this.config.deploymentsFile || './.dpd/deployments.json';
|
||||
}
|
||||
util.inherits(InternalDeployments, Resource);
|
||||
module.exports = InternalDeployments;
|
||||
|
||||
InternalDeployments.prototype.handle = function(ctx, next) {
|
||||
if (!ctx.req.isRoot) {
|
||||
ctx.done({statusCode: 401, message: "Not Allowed"});
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx.method === "GET" && ctx.url === "/") {
|
||||
this.getList(ctx, next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
};
|
||||
|
||||
InternalDeployments.prototype.getList = function(ctx, next) {
|
||||
var self = this;
|
||||
var fileQ = q.ninvoke(fs, 'readFile', self.deploymentsFile, 'utf-8');
|
||||
|
||||
var listQ = fileQ.then(function(file) {
|
||||
var deploymentsJson = JSON.parse(file);
|
||||
var list = [];
|
||||
Object.keys(deploymentsJson).forEach(function(k) {
|
||||
if (k !== 'sid' && k !== 'user') {
|
||||
deploymentsJson[k].id = k;
|
||||
list.push(deploymentsJson[k]);
|
||||
}
|
||||
});
|
||||
|
||||
list.sort(function(a, b) {
|
||||
return a.id.localeCompare(b.id);
|
||||
});
|
||||
|
||||
return list;
|
||||
}, function(err) {
|
||||
if (err.code === "ENOENT") {
|
||||
return [];
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
listQ.then(function(list) {
|
||||
ctx.done(null, list);
|
||||
}, function(err) {
|
||||
ctx.done(err);
|
||||
});
|
||||
|
||||
};
|
||||
22
lib/util/qutil.js
Normal file
22
lib/util/qutil.js
Normal file
@@ -0,0 +1,22 @@
|
||||
var q = require('q');
|
||||
|
||||
exports.cinvoke = function(obj, func) {
|
||||
var args = Array.prototype.slice.call(arguments, 2);
|
||||
|
||||
var d = q.defer();
|
||||
|
||||
if (typeof func !== 'function') {
|
||||
func = obj[func];
|
||||
}
|
||||
|
||||
var callback = function(result) {
|
||||
d.resolve(result);
|
||||
};
|
||||
|
||||
args.push(callback);
|
||||
|
||||
func.apply(obj, args);
|
||||
|
||||
return d.promise;
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user