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

[NOT FINISHED] update UI with bootstrap #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ Tail command for your .log files via browser. In order to have a quick access to

Also you can highlight any particular string you are looking for.

![How it works](how_it_works.gif)

![How it works](how_it_works.png)

##Installation

Expand All @@ -34,8 +33,6 @@ Ruby 1.9.3+

Rails 4.0+

No other gems required. No jQuery or any JS frameworks required.

##License

This gem uses MIT-LICENSE. Fork it or create pull request. Any contribution is appreciated.
Empty file removed app/assets/images/tail/.keep
Empty file.
Binary file removed app/assets/images/tail/cleaning.png
Binary file not shown.
Binary file removed app/assets/images/tail/refresh.png
Binary file not shown.
Binary file removed app/assets/images/tail/up_arrow.png
Binary file not shown.
16 changes: 3 additions & 13 deletions app/assets/javascripts/tail/application.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require_tree .
//= require jquery
//= require bootstrap/dropdown
//= require tail/logs
102 changes: 39 additions & 63 deletions app/assets/javascripts/tail/logs.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,47 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
document.onreadystatechange = function () {
if (document.readyState == "interactive") {
initApplication();
}
}

function initApplication(){
var appended = false, up_arrow = document.querySelector("#up");

onscroll = function () {
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
if (scrollTop > 500) {
if (!appended) {
up_arrow.hidden = false;
appended = true;
}
} else {
if (appended) {
up_arrow.hidden = true;
appended = false;
}
}
};

}

function getPageVar(sVar) {
return decodeURI(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + encodeURI(sVar).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
}
$(function () {
window.scrollTo(0, document.body.scrollHeight);
$('input#grep').change(function () {
getGrep(this.value);
});
$('form.navbar-form-alt').submit(function (e) {
e.preventDefault();
});
});

function getGrep(text) {
var sign;
if (location.search == "") sign = "?"; else sign = "&";
var search = sign + 'query=' + text;
var query = location.pathname + 'grep' + location.search + search;
sendRequest(query, true)
var sign;
if (location.search == "") sign = "?"; else sign = "&";
var search = sign + 'query=' + text;
var query = location.pathname + 'grep' + location.search + search;
sendRequest(query, true);
}

function sendRequest(url, isGoToBottom) {
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
}
}
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
}
}
if (!httpRequest) {
return false;
}
if (!httpRequest) {
return false;
}
httpRequest.open("GET", url);
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState != 4 || httpRequest.status != 200) return;
document.getElementById('main').innerHTML = httpRequest.responseText;
if (isGoToBottom) {
window.scrollTo(0, document.body.scrollHeight);
}
httpRequest.open("GET", url);
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState != 4 || httpRequest.status != 200) return;
document.getElementById('main').innerHTML = httpRequest.responseText;
if (isGoToBottom) {
window.scrollTo(0, document.body.scrollHeight);
}
};
httpRequest.send();
return true;
};
httpRequest.send();
return true;
}


18 changes: 18 additions & 0 deletions app/assets/stylesheets/tail/_bootstrap-custom.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Core variables and mixins
@import "bootstrap/variables";
@import "bootstrap/mixins";

// Reset and dependencies
@import "bootstrap/glyphicons";

// Core CSS
@import "bootstrap/scaffolding";
@import "bootstrap/grid";
@import "bootstrap/forms";
@import "bootstrap/buttons";

// Components
@import "bootstrap/dropdowns";
@import "bootstrap/navs";
@import "bootstrap/navbar";
@import "bootstrap/button-groups";
13 changes: 0 additions & 13 deletions app/assets/stylesheets/tail/application.css

This file was deleted.

3 changes: 3 additions & 0 deletions app/assets/stylesheets/tail/application.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@import 'bootstrap-sprockets';
@import 'bootstrap-custom';
@import 'tail/logs';
79 changes: 0 additions & 79 deletions app/assets/stylesheets/tail/logs.css

This file was deleted.

50 changes: 50 additions & 0 deletions app/assets/stylesheets/tail/logs.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
body {
background: #1d1f21;
& > .container-fluid {
padding: 50px 15px 10px;
}
}
a {
color: #333333;
}
.code {
font-family: 'Source Code Pro', Menlo, Consolas, Monaco, monospace;
color: white;
font-size: 12px;
}
.log td:empty {
padding: 5px;
}
.size_30 {
font-size: 30px;
}
.query {
color: #cd6a51;
}
.right_15 {
margin-right: 15px;
}
.top_10 {
margin-top: 10px;
}
.input-group {
display: table;

& > .form-control {
display: table-cell;
margin-left: -3px;
}

& > span {
display: table-cell;
width: 1%;
padding: 0 3px;
}
}
.navbar-form-alt {
margin-top: 8px;

.form-group {
margin-bottom: 0px;
}
}
18 changes: 13 additions & 5 deletions app/controllers/tail/logs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,25 @@ def grep
end

def tail
@web_logger ||= Tail::Log.instance
@web_logger.n = params[:n]
params[:n] = @web_logger.n
log_file_name = params[:file_name] || "#{Rails.env}.log"
@web_logger.tail(log_file_name)
web_logger.n = params[:n]
params[:n] = web_logger.n
web_logger.tail(log_file_name)
end

def flush
web_logger ||= Tail::Log.instance
web_logger.flush(params[:file_name])
redirect_to action: :index
end

private

def web_logger
@web_logger ||= Tail::Log.instance
end

def log_file_name
@log_file_name ||= params[:file_name] || "#{Rails.env}.log"
end
end
end
17 changes: 8 additions & 9 deletions app/models/tail/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@ def initialize
end

def flush(file_name)
begin
f = File.open "log/#{Rails.env}.log", 'w'
f.close
Rails.logger.warn "#{Rails.env}.log flushed"
rescue => e
Rails.logger.error(e.message)
Rails.logger.error(e.backtrace[0..3].join("\n"))
end
log_name = "#{Rails.env}.log"
f = File.open Rails.root.join('log', log_name), 'w'
f.close
Rails.logger.warn "#{log_name} flushed"
rescue => e
Rails.logger.error(e.message)
Rails.logger.error(e.backtrace[0..3].join("\n"))
end

def n=(value)
if value.present? && value.to_i > 0
@n =value.to_i
@n = value.to_i
else
@n = N_VALUE
end
Expand Down
4 changes: 1 addition & 3 deletions app/views/layouts/tail/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
<%= csrf_meta_tags %>
</head>
<body>

<%= yield %>

<%= yield %>
</body>
</html>
9 changes: 0 additions & 9 deletions app/views/tail/logs/_icons.html.erb

This file was deleted.

Loading