Added default editor

This commit is contained in:
DallonF
2012-07-30 12:11:42 -07:00
parent 4141a5a25a
commit f29a04040f
8 changed files with 68 additions and 7 deletions

View File

@@ -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;
}
});

View File

@@ -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

View File

@@ -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>

View File

@@ -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>
<{ }); }>

View 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) {}
}
})();

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -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