Skip to content
This repository was archived by the owner on Dec 4, 2021. It is now read-only.

Commit b98a439

Browse files
committed
remove tail logs
1 parent 760fa9f commit b98a439

File tree

8 files changed

+140
-221
lines changed

8 files changed

+140
-221
lines changed

app/assets/javascripts/logs.js.coffee

+24-40
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,10 @@ root.MongodbLoggerMain =
1212
$(document).ajaxStart => $('#ajaxLoader').show()
1313
$(document).ajaxStop => $('#ajaxLoader').hide()
1414
# tail logs buttons
15-
$(document).on 'click', '#tailLogsLink', (event) =>
16-
event.preventDefault()
17-
MongodbLoggerMain.tailLogsUrl = $(event.currentTarget).data('url')
18-
$('#tailLogsBlock').addClass('started')
19-
MongodbLoggerMain.tailLogs(null)
20-
$(document).on 'click', '#tailLogsStopLink', (event) =>
21-
event.preventDefault()
22-
MongodbLoggerMain.tailLogStarted = false
23-
$('#tailLogsBlock').removeClass('started')
15+
$(document).on 'click', '#filterLogsLink', (event) =>
16+
@showFilters(event)
17+
$(document).on 'click', '#filterLogsStopLink', (event) =>
18+
@hideFilters(event)
2419
# log info click
2520
$(document).on 'click', '.log_info', (event) =>
2621
event.preventDefault()
@@ -30,9 +25,7 @@ root.MongodbLoggerMain =
3025
$('#logInfo').html(MustacheTemplates["logs/info"]({ log: element.data('info') }))
3126
# filter tougle
3227
$(document).on 'click', 'div.filter_toggle', (event) =>
33-
event.preventDefault()
34-
$('div.filter').slideToggle()
35-
$('div.filter_toggle span.arrow-down').toggleClass('rotate')
28+
@toggleFilters(event)
3629
# additional filters
3730
$(document).on 'click', '#addMoreFilter', (event) =>
3831
event.preventDefault()
@@ -90,8 +83,23 @@ root.MongodbLoggerMain =
9083
when 40 # down
9184
MongodbLoggerMain.moveByLogs('down')
9285
# init pjax
93-
this.initPjax()
94-
this.initOnPages()
86+
@initPjax()
87+
@initOnPages()
88+
showFilters: (e) ->
89+
e.preventDefault()
90+
$('div.filter').slideDown()
91+
$('div.filter_toggle span.arrow-down').addClass('rotate')
92+
$('#filterLogsBlock').addClass('started')
93+
hideFilters: (e) ->
94+
e.preventDefault()
95+
$('div.filter').slideUp()
96+
$('div.filter_toggle span.arrow-down').removeClass('rotate')
97+
$('#filterLogsBlock').removeClass('started')
98+
toggleFilters: (e) ->
99+
if $('div.filter_toggle span.arrow-down').hasClass('rotate')
100+
@hideFilters(e)
101+
else
102+
@showFilters(e)
95103
initPjax: ->
96104
# pjax
97105
$(document).pjax('a[data-pjax]', '#mainPjax')
@@ -124,29 +132,6 @@ root.MongodbLoggerMain =
124132
else
125133
$("#logInfo").stop().animate
126134
marginTop: 0
127-
# tail logs function
128-
tailLogs: (logLastId = null) ->
129-
url = MongodbLoggerMain.tailLogsUrl
130-
if logLastId? and logLastId.length
131-
url = "#{MongodbLoggerMain.tailLogsUrl}/#{logLastId}"
132-
else
133-
MongodbLoggerMain.tailLogStarted = true
134-
return false unless MongodbLoggerMain.tailLogStarted
135-
$.ajax
136-
url: url
137-
dataType: "json"
138-
success: (data) ->
139-
if data.time
140-
$('#tailLogsTime').text(data.time)
141-
if data.log_last_id?
142-
logLastId = data.log_last_id
143-
if data.content? && data.content.length > 0
144-
elements = $(data.content)
145-
elements.addClass('newlog')
146-
$('#logsList tr:first').after(elements).effect("highlight", {}, 1000)
147-
if data.collection_stats && $("#collection_stats").length > 0
148-
$("#collection_stats").html(data.collection_stats)
149-
setTimeout((-> MongodbLoggerMain.tailLogs(logLastId)), 2000) if MongodbLoggerMain.tailLogStarted
150135
# move using keys by logs
151136
moveByLogs: (direction) ->
152137
if $('#logsList').length and $('#logsList').find('tr.current').length
@@ -189,6 +174,5 @@ root.MongodbLoggerMain =
189174
elemTop = $(elem).offset().top
190175
elemBottom = elemTop + $(elem).height()
191176
return ((docViewTop < elemTop) && (docViewBottom > elemBottom))
192-
193-
$ ->
194-
MongodbLoggerMain.init()
177+
# init
178+
$ -> MongodbLoggerMain.init()

app/assets/stylesheets/library.css.erb

+6-6
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ code {
144144
background: -ms-linear-gradient(top, rgba(238,238,238,1) 0%,rgba(211,211,211,1) 100%);
145145
background: linear-gradient(top, rgba(238,238,238,1) 0%,rgba(211,211,211,1) 100%);
146146
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#d3d3d3',GradientType=0 );
147-
147+
148148
}
149149

150150
.logs-time {
@@ -162,11 +162,11 @@ code {
162162
}
163163

164164

165-
#tailLogsBlock.started .info, #tailLogsBlock .initial {
165+
#filterLogsBlock.started .info, #filterLogsBlock .initial {
166166
display: inline-block;
167167
}
168168

169-
#tailLogsBlock .info, #tailLogsBlock.started .initial {
169+
#filterLogsBlock .info, #filterLogsBlock.started .initial {
170170
display: none;
171171
}
172172

@@ -204,7 +204,7 @@ li.message_tab {
204204
padding: 0 20px;
205205
height: 30px;
206206
line-height: 30px;
207-
font-size: 14px;
207+
font-size: 14px;
208208
border-right: 1px solid #bbb;
209209
border-top: 0;
210210
color: #333;
@@ -219,7 +219,7 @@ li.message_tab {
219219
background: -ms-linear-gradient(top, rgba(255,255,255,0.62) 0%,rgba(23,146,212,0.5) 100%);
220220
background: linear-gradient(top, rgba(255,255,255,0.62) 0%,rgba(23,146,212,0.5) 100%);
221221
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#9effffff', endColorstr='#801792d4',GradientType=0 );
222-
222+
223223
}
224224

225225
.message_tabs li.active {
@@ -285,7 +285,7 @@ a[target="_blank"] {
285285
background: -ms-linear-gradient(top, rgba(191,210,85,1) 0%,rgba(142,185,42,1) 50%,rgba(114,170,0,1) 51%,rgba(158,203,45,1) 100%);
286286
background: linear-gradient(top, rgba(191,210,85,1) 0%,rgba(142,185,42,1) 50%,rgba(114,170,0,1) 51%,rgba(158,203,45,1) 100%);
287287
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#bfd255', endColorstr='#9ecb2d',GradientType=0 );
288-
288+
289289
}
290290

291291
.size {

lib/mongodb_logger/adapters/mongo.rb

+1-22
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,13 @@ def rename_collection(to, drop_target = false)
4040

4141
# filter
4242
def filter_by_conditions(filter)
43-
@collection.find(filter.get_mongo_conditions).sort('$natural', -1).limit(filter.get_mongo_limit)
43+
@collection.find(filter.get_mongo_conditions).limit(filter.get_mongo_limit).sort('$natural', -1)
4444
end
4545

4646
def find_by_id(id)
4747
@collection.find_one(::BSON::ObjectId.from_string(id))
4848
end
4949

50-
def tail_log_from_params(params = {})
51-
logs = []
52-
last_id = nil
53-
if params[:log_last_id] && !params[:log_last_id].blank?
54-
log_last_id = params[:log_last_id]
55-
@collection.find({'_id' => { '$gt' => ::BSON::ObjectId.from_string(log_last_id) }}).sort('$natural', -1).each do |log|
56-
logs << log
57-
log_last_id = log["_id"].to_s
58-
end
59-
logs.reverse!
60-
else
61-
log = @collection.find_one({}, { sort: ['$natural', -1] })
62-
log_last_id = log["_id"].to_s unless log.blank?
63-
end
64-
{
65-
log_last_id: log_last_id,
66-
time: Time.now.strftime("%F %T"),
67-
logs: logs
68-
}
69-
end
70-
7150
def calculate_mapreduce(map, reduce, params = {})
7251
@collection.map_reduce(map, reduce, { query: params[:conditions], sort: ['$natural', -1], out: { inline: true }, raw: true }).find()
7352
end

lib/mongodb_logger/adapters/moped.rb

+1-22
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,13 @@ def rename_collection(to, drop_target = false)
4242

4343
# filter
4444
def filter_by_conditions(filter)
45-
@collection.find(filter.get_mongo_conditions).sort('$natural' => -1).limit(filter.get_mongo_limit)
45+
@collection.find(filter.get_mongo_conditions).limit(filter.get_mongo_limit).sort('$natural' => -1)
4646
end
4747

4848
def find_by_id(id)
4949
@collection.find("_id" => ::BSON::ObjectId.from_string(id)).first
5050
end
5151

52-
def tail_log_from_params(params = {})
53-
logs = []
54-
last_id = nil
55-
if params[:log_last_id] && !params[:log_last_id].blank?
56-
log_last_id = params[:log_last_id]
57-
@collection.find({'_id' => { '$gt' => ::BSON::ObjectId.from_string(log_last_id) }}).sort('$natural' => -1).each do |log|
58-
logs << log
59-
log_last_id = log["_id"].to_s
60-
end
61-
logs.reverse!
62-
else
63-
log = @collection.find.sort('$natural' => -1).first
64-
log_last_id = log["_id"].to_s unless log.blank?
65-
end
66-
{
67-
log_last_id: log_last_id,
68-
time: Time.now.strftime("%F %T"),
69-
logs: logs
70-
}
71-
end
72-
7352
def calculate_mapreduce(map, reduce, params = {})
7453
@connection.command(
7554
mapreduce: collection_name,

0 commit comments

Comments
 (0)