Skip to content

Commit

Permalink
Merge pull request #2 from fcanache/master
Browse files Browse the repository at this point in the history
Fix for the issue on the log file dropdown.
  • Loading branch information
lookfirst committed Jul 25, 2011
2 parents 9bb62ea + b23170b commit 0ff2194
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 46 deletions.
42 changes: 2 additions & 40 deletions public/javascripts/app.js
Expand Up @@ -11,25 +11,19 @@ var Search = {
resultsId : 'results',
search_fields: [ 'term1', 'term2', 'term3' ], // domIds of search term fields
file_list : 'file-list', // domId of select for logfiles
logfiles : {}, // hash of log files
past_params : null, // recent request
url : '/perform',
scroll_fnId : null,

// initialize Search form
// { 'grep': [ log, files, for, grep], 'tail': [ 'log', 'files', 'for', 'tail']}
init: function(logfiles, params) {
this.logfiles = logfiles;
init: function(params) {
this.past_params = params;

this.bind_grep_tool();
this.bind_tail_tool();
this.bind_options();

if (!this.past_params) return; // return if no prev settings, nothing to set

// init tool selector
(this.past_params['tool'] == 'grep') ? $('#grep-label').trigger('click') : $('#tail-tool').trigger('click');
(this.past_params['tool'] == 'grep') ? $('#grep-tool').attr('checked', 'checked') : $('#tail-tool').attr('checked', 'checked');

// init log file selector
$('#'+this.file_list).val(this.past_params['file']);
Expand Down Expand Up @@ -61,38 +55,6 @@ var Search = {
$('#auto-scroll').attr('checked', true).trigger('change'); // by default, turn on
},

// bind change grep tool
bind_grep_tool: function() {
$('#grep-tool').bind('change', function(e){
var newlist = ""
jQuery.each(Search.logfiles['grep'], function(){
newlist += "<option value='" + this + "'>" + this + "</option>\n"
});
$('#'+Search.file_list).html(newlist);
});
// watch clicking label as well
$('#grep-label').bind('click', function(e){
$('#grep-tool').attr('checked', 'checked').val('grep').trigger('change');
});
},


// bind change tail tool
bind_tail_tool: function() {
$('#tail-tool').bind('change', function(e){
var newlist = ""
jQuery.each(Search.logfiles['tail'], function(){
newlist += "<option value='" + this + "'>" + this + "</option>\n"
});
$('#'+ Search.file_list).html(newlist);
});
// watch clicking label as well
$('#tail-label').bind('click', function(e){
$('#tail-tool').attr('checked', 'checked').val('tail').trigger('change');
});
},


// clears the terms fields
clear: function() {
jQuery.each(this.search_fields, function(){
Expand Down
2 changes: 1 addition & 1 deletion public/stylesheets/app.css
Expand Up @@ -36,7 +36,7 @@ table.actions th { font-size: 11px; color: #333; text-align: left; min-width: 10
table.actions td { padding: 2px 5px; text-align: left; vertical-align: middle;}
table.actions span.note { font-weight: normal; color: #999; }
table.actions span.and { font-size: 11px; color: red; font-weight: bold; }
table.actions span.label { font-weight: bold; cursor:pointer;}
table.actions label { font-weight: bold; cursor:pointer;}
table.actions input[type=text] { width: 200px; padding: 2px; border: 1px solid #aaa;}


Expand Down
8 changes: 3 additions & 5 deletions views/_toolbar.html.erb
Expand Up @@ -16,8 +16,8 @@
</tr>
<tr>
<td id='tool-selector'>
<input type='radio' name='tool' value='grep' id='grep-tool' checked='checked'> <span class='label' id='grep-label'>Search</span> <br/>
<input type='radio' name='tool' value='tail' id='tail-tool'> <span class='label' id='tail-label'>Tail</span> <br/>
<input type='radio' name='tool' value='grep' id='grep-tool' checked='checked'> <label id='grep-label' for="grep-tool">Search</label> <br/>
<input type='radio' name='tool' value='tail' id='tail-tool'> <label id='tail-label' for="tail-tool">Tail</label> <br/>
</td>
<td id='file-selector'>
<select id='file-list' name='file'>
Expand Down Expand Up @@ -56,7 +56,5 @@

<script>
Search.url = "<%= relative_root %>" + Search.url;
Search.init({ 'grep': <%= logfiles.map {|f| f }.to_json %>,
'tail': <%= logfiles.map {|f| f }.to_json %> },
<%= params.empty? ? 'null' : json_encode(params) %> );
Search.init(<%= params.empty? ? 'null' : json_encode(params) %>);
</script>

0 comments on commit 0ff2194

Please sign in to comment.