@@ -12,15 +12,10 @@ root.MongodbLoggerMain =
12
12
$ (document ).ajaxStart => $ (' #ajaxLoader' ).show ()
13
13
$ (document ).ajaxStop => $ (' #ajaxLoader' ).hide ()
14
14
# 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)
24
19
# log info click
25
20
$ (document ).on ' click' , ' .log_info' , (event ) =>
26
21
event .preventDefault ()
@@ -30,9 +25,7 @@ root.MongodbLoggerMain =
30
25
$ (' #logInfo' ).html (MustacheTemplates[" logs/info" ]({ log : element .data (' info' ) }))
31
26
# filter tougle
32
27
$ (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)
36
29
# additional filters
37
30
$ (document ).on ' click' , ' #addMoreFilter' , (event ) =>
38
31
event .preventDefault ()
@@ -90,8 +83,23 @@ root.MongodbLoggerMain =
90
83
when 40 # down
91
84
MongodbLoggerMain .moveByLogs (' down' )
92
85
# 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)
95
103
initPjax : ->
96
104
# pjax
97
105
$ (document ).pjax (' a[data-pjax]' , ' #mainPjax' )
@@ -124,29 +132,6 @@ root.MongodbLoggerMain =
124
132
else
125
133
$ (" #logInfo" ).stop ().animate
126
134
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
150
135
# move using keys by logs
151
136
moveByLogs : (direction ) ->
152
137
if $ (' #logsList' ).length and $ (' #logsList' ).find (' tr.current' ).length
@@ -189,6 +174,5 @@ root.MongodbLoggerMain =
189
174
elemTop = $ (elem).offset ().top
190
175
elemBottom = elemTop + $ (elem).height ()
191
176
return ((docViewTop < elemTop) && (docViewBottom > elemBottom))
192
-
193
- $ ->
194
- MongodbLoggerMain .init ()
177
+ # init
178
+ $ -> MongodbLoggerMain .init ()
0 commit comments