mirror of
https://github.com/zhigang1992/deployd.git
synced 2026-05-14 05:10:10 +08:00
Added default editor
This commit is contained in:
@@ -207,7 +207,11 @@ function notifyType(resource, ctx, fn) {
|
||||
ctx.server.resources.forEach(function(r) {
|
||||
if(resource.type === r.settings.type && (resource.path === r.settings.path || resource.$renameFrom === r.settings.path) ) {
|
||||
debug('notifying resource', r.settings.path);
|
||||
r.changed && r.changed(ctx, fn);
|
||||
if (r.changed) {
|
||||
r.changed(ctx, fn);
|
||||
} else {
|
||||
fn();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -74,7 +74,7 @@ Dashboard.prototype.route = function(ctx) {
|
||||
|
||||
if (parts.length) {
|
||||
resourceId = parts[0];
|
||||
resource = ctx.server.resources.filter(function(r) { return r.name === resourceId.toLowerCase() })[0];
|
||||
resource = ctx.server.resources.filter(function(r) { return r.settings && r.settings.path === '/' + resourceId.toLowerCase() })[0];
|
||||
|
||||
if (resource) {
|
||||
resourceType = resource.constructor;
|
||||
@@ -87,7 +87,7 @@ Dashboard.prototype.route = function(ctx) {
|
||||
|
||||
if (resourceType.dashboard.scripts) {
|
||||
resourceType.dashboard.scripts.forEach(function(s) {
|
||||
scripts.push('/' + resourceType.name.toLowerCase() + s);
|
||||
scripts.push('/__custom/' + resourceType.name.toLowerCase() + s);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ Dashboard.prototype.route = function(ctx) {
|
||||
|
||||
fs.stat(path.join(resourceType.dashboard.path, 'js', page + '.js'), function(err, stat) {
|
||||
if (stat) {
|
||||
scripts.push('/' + resourceType.name.toLowerCase() + '/js/' + page + '.js');
|
||||
scripts.push('/__custom/' + resourceType.name.toLowerCase() + '/js/' + page + '.js');
|
||||
}
|
||||
|
||||
render(ctx, {
|
||||
@@ -109,6 +109,7 @@ Dashboard.prototype.route = function(ctx) {
|
||||
|
||||
} else {
|
||||
pagePath = path.join(__dirname, 'dashboard', 'default.html');
|
||||
scripts.push('/js/default.js');
|
||||
|
||||
this.render(ctx, {
|
||||
resourceId: resourceId
|
||||
|
||||
@@ -1 +1,7 @@
|
||||
<h1>Default editor</h1>
|
||||
<div id="default-editor" class="well hide">
|
||||
<h3>settings.json</h3>
|
||||
<div class="editor-container">
|
||||
<div id="settings">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -76,13 +76,14 @@
|
||||
<script type="text/javascript" src="/dashboard/js/lib/ace.js"></script>
|
||||
<script type="text/javascript" src="/dashboard/js/lib/ace-theme-deployd.js"></script>
|
||||
<script type="text/javascript" src="/dashboard/js/lib/ace-mode-javascript.js"></script>
|
||||
<script type="text/javascript" src="/dashboard/js/lib/ace-mode-json.js"></script>
|
||||
<script type="text/javascript" src="/dashboard/js/lib/prettify.js"></script>
|
||||
<script type="text/javascript" src="/dpd.js"></script>
|
||||
<script type="text/javascript" src="/dashboard/js/sidebar.js"></script>
|
||||
|
||||
<{ if (typeof scripts !== 'undefined') scripts.forEach(function(s) { }>
|
||||
|
||||
<script type="text/javascript" src="/dashboard/__custom<{- s }>"></script>
|
||||
<script type="text/javascript" src="/dashboard<{- s }>"></script>
|
||||
|
||||
<{ }); }>
|
||||
|
||||
|
||||
47
lib/resources/dashboard/js/default.js
Normal file
47
lib/resources/dashboard/js/default.js
Normal file
@@ -0,0 +1,47 @@
|
||||
(function() {
|
||||
|
||||
var settings = ""
|
||||
, editor
|
||||
, timeout;
|
||||
|
||||
dpd('__resources').get(Context.resourceId, function(res, err) {
|
||||
if (res) {
|
||||
delete res.type;
|
||||
delete res.path;
|
||||
delete res.ctime;
|
||||
|
||||
settings = JSON.stringify(res, null, '\t');
|
||||
editor = ace.edit('settings');
|
||||
editor.setTheme("ace/theme/deployd");
|
||||
editor.session.setMode("ace/mode/json");
|
||||
editor.setShowPrintMargin(false);
|
||||
editor.getSession().setValue(settings);
|
||||
editor.getSession().on('change', function() { trackUpdate() } );
|
||||
$('#default-editor').show();
|
||||
}
|
||||
});
|
||||
|
||||
function trackUpdate(name, editor) {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
|
||||
timeout = setTimeout(function() {
|
||||
update();
|
||||
timeout = undefined;
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function update() {
|
||||
try {
|
||||
var settings = JSON.parse(editor.getSession().getValue());
|
||||
dpd('__resources').put(Context.resourceId, settings, function(res, err) {
|
||||
if (err) { ui.error("Error saving", err.message).slide().closable(); }
|
||||
if (!$('#notifications li').length) ui.notify("Saved").hide(1000).effect('slide');
|
||||
});
|
||||
} catch (ex) {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
})();
|
||||
1
lib/resources/dashboard/js/lib/ace-mode-json.js
Normal file
1
lib/resources/dashboard/js/lib/ace-mode-json.js
Normal file
File diff suppressed because one or more lines are too long
1
lib/resources/dashboard/js/lib/worker-json.js
Normal file
1
lib/resources/dashboard/js/lib/worker-json.js
Normal file
File diff suppressed because one or more lines are too long
@@ -105,7 +105,7 @@ $(document).ready(function() {
|
||||
|
||||
function createResource(typeId) {
|
||||
var type = resourceTypes[typeId];
|
||||
pathDialog("Create", "Create New " + (type.label || type.id), type.defaultPath, function(path) {
|
||||
pathDialog("Create", "Create New " + (type.label || type.id), type.defaultPath || ('/' + typeId.toLowerCase()), function(path) {
|
||||
dpd('__resources').post({
|
||||
type: typeId
|
||||
, path: path
|
||||
|
||||
Reference in New Issue
Block a user