Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ace editor for syntax highlighting in script editor #26

Merged
merged 2 commits into from
May 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"tests"
],
"dependencies": {
"ace-min-noconflict": "~1.1.8",
"backbone": "~1.1.2",
"backbone-poller": "~0.3.0",
"bootstrap-sass-official": "~3.3.3",
Expand Down
5 changes: 4 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var elixir = require('laravel-elixir');

var bower_path = './vendor/bower_components';
var paths = {
'ace' : bower_path + '/ace-min-noconflict',
'backbone' : bower_path + '/backbone',
'backbone_poller' : bower_path + '/backbone-poller',
'underscore' : bower_path + '/underscore',
Expand Down Expand Up @@ -44,7 +45,9 @@ elixir(function(mix) {
paths.moment + '/moment.js',
paths.bootstrap + '/javascripts/bootstrap.js',
paths.backbone + '/backbone.js',
paths.backbone_poller + '/backbone.poller.js'
paths.backbone_poller + '/backbone.poller.js',
paths.ace + '/ace.js',
paths.ace + '/mode-sh.js'
], 'public/js/vendor.js', bower_path)
.scripts([
'app.js',
Expand Down
4 changes: 4 additions & 0 deletions resources/assets/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ span.label i.fa {

input[type=text].deployment-source {
display: none;
}

#command_script {
height: 250px;
}
19 changes: 16 additions & 3 deletions resources/assets/js/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,21 @@ var app = app || {};
}
});

var editor;

$('#command').on('hidden.bs.modal', function (event) {
editor.destroy();
});

// FIXME: This seems very wrong
$('#command').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget);
var modal = $(this);
var title = Lang.create;

editor = ace.edit('command_script');
editor.getSession().setMode('ace/mode/sh');

$('.btn-danger', modal).hide();
$('.callout-danger', modal).hide();
$('.has-error', modal).removeClass('has-error');
Expand All @@ -42,7 +51,8 @@ var app = app || {};
$('#command_id').val('');
$('#command_step').val(button.data('step'));
$('#command_name').val('');
$('#command_script').val('');
editor.setValue('');
editor.gotoLine(1);
$('#command_user').val('');
$('#command_optional').val('');

Expand Down Expand Up @@ -110,7 +120,7 @@ var app = app || {};

command.save({
name: $('#command_name').val(),
script: $('#command_script').val(),
script: editor.getValue(),
user: $('#command_user').val(),
step: $('#command_step').val(),
project_id: $('input[name="project_id"]').val(),
Expand All @@ -129,6 +139,9 @@ var app = app || {};
if (!command_id) {
app.Commands.add(response);
}

editor.setValue('');
editor.gotoLine(1);
},
error: function(model, response, options) {
$('.callout-danger', dialog).show();
Expand Down Expand Up @@ -260,7 +273,7 @@ var app = app || {};
$('#command_id').val(this.model.id);
$('#command_step').val(this.model.get('step'));
$('#command_name').val(this.model.get('name'));
$('#command_script').val(this.model.get('script'));
$('#command_script').text(this.model.get('script'));
$('#command_user').val(this.model.get('user'));
$('#command_optional').prop('checked', (this.model.get('optional') === true));

Expand Down
3 changes: 2 additions & 1 deletion resources/views/dialogs/command.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
</div>
<div class="form-group">
<label for="command_script">{{ Lang::get('commands.bash') }}</label>
<textarea rows="10" id="command_script" class="form-control" name="script" placeholder="echo 'Hello world'"></textarea>
<div id="command_script" class="form-control"></div>
<!--textarea rows="10" id="command_script" class="form-control" name="script" placeholder="echo 'Hello world'"></textarea-->
<h5>{{ Lang::get('commands.options') }}</h5>
<ul class="list-unstyled">
<li><code>@{{ project_path }}</code> - {{ Lang::get('commands.project_path') }}, e.g. <span class="label label-default">/var/www/</span></li>
Expand Down