-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-8171] [Web UI] Javascript based infinite scrolling for the log page #10910
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
Changes from all commits
4d7c433
ab20345
f37fa32
35e08c7
03d16aa
0f49738
293f1a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| var baseParams; | ||
|
|
||
| var curLogLength; | ||
| var startByte; | ||
| var endByte; | ||
| var totalLogLength; | ||
|
|
||
| var byteLength; | ||
|
|
||
| function setLogScroll(oldHeight) { | ||
| var logContent = $(".log-content"); | ||
| logContent.scrollTop(logContent[0].scrollHeight - oldHeight); | ||
| } | ||
|
|
||
| function tailLog() { | ||
| var logContent = $(".log-content"); | ||
| logContent.scrollTop(logContent[0].scrollHeight); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not good to repeat a query for the same dom-objects like |
||
|
|
||
| function setLogData() { | ||
| $('#log-data').html("Showing " + curLogLength + " Bytes: " + startByte | ||
| + " - " + endByte + " of " + totalLogLength); | ||
| } | ||
|
|
||
| function disableMoreButton() { | ||
| var moreBtn = $(".log-more-btn"); | ||
| moreBtn.attr("disabled", "disabled"); | ||
| moreBtn.html("Top of Log"); | ||
| } | ||
|
|
||
| function noNewAlert() { | ||
| var alert = $(".no-new-alert"); | ||
| alert.css("display", "block"); | ||
| window.setTimeout(function () {alert.css("display", "none");}, 4000); | ||
| } | ||
|
|
||
| function loadMore() { | ||
| var offset = Math.max(startByte - byteLength, 0); | ||
| var moreByteLength = Math.min(byteLength, startByte); | ||
|
|
||
| $.ajax({ | ||
| type: "GET", | ||
| url: "/log" + baseParams + "&offset=" + offset + "&byteLength=" + moreByteLength, | ||
| success: function (data) { | ||
| var oldHeight = $(".log-content")[0].scrollHeight; | ||
| var newlineIndex = data.indexOf('\n'); | ||
| var dataInfo = data.substring(0, newlineIndex).match(/\d+/g); | ||
| var retStartByte = dataInfo[0]; | ||
| var retLogLength = dataInfo[2]; | ||
|
|
||
| var cleanData = data.substring(newlineIndex + 1); | ||
| if (retStartByte == 0) { | ||
| disableMoreButton(); | ||
| } | ||
| $("pre", ".log-content").prepend(cleanData); | ||
|
|
||
| curLogLength = curLogLength + (startByte - retStartByte); | ||
| startByte = retStartByte; | ||
| totalLogLength = retLogLength; | ||
| setLogScroll(oldHeight); | ||
| setLogData(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| function loadNew() { | ||
| $.ajax({ | ||
| type: "GET", | ||
| url: "/log" + baseParams + "&byteLength=0", | ||
| success: function (data) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All we need to do here is to check whether the log size is bigger. So, can we somehow check it without receiving the first 100 KB of the log?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added |
||
| var dataInfo = data.substring(0, data.indexOf('\n')).match(/\d+/g); | ||
| var newDataLen = dataInfo[2] - totalLogLength; | ||
| if (newDataLen != 0) { | ||
| $.ajax({ | ||
| type: "GET", | ||
| url: "/log" + baseParams + "&byteLength=" + newDataLen, | ||
| success: function (data) { | ||
| var newlineIndex = data.indexOf('\n'); | ||
| var dataInfo = data.substring(0, newlineIndex).match(/\d+/g); | ||
| var retStartByte = dataInfo[0]; | ||
| var retEndByte = dataInfo[1]; | ||
| var retLogLength = dataInfo[2]; | ||
|
|
||
| var cleanData = data.substring(newlineIndex + 1); | ||
| $("pre", ".log-content").append(cleanData); | ||
|
|
||
| curLogLength = curLogLength + (retEndByte - retStartByte); | ||
| endByte = retEndByte; | ||
| totalLogLength = retLogLength; | ||
| tailLog(); | ||
| setLogData(); | ||
| } | ||
| }); | ||
| } else { | ||
| noNewAlert(); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| function initLogPage(params, logLen, start, end, totLogLen, defaultLen) { | ||
| baseParams = params; | ||
| curLogLength = logLen; | ||
| startByte = start; | ||
| endByte = end; | ||
| totalLogLength = totLogLen; | ||
| byteLength = defaultLen; | ||
| tailLog(); | ||
| if (startByte == 0) { | ||
| disableMoreButton(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to append
;to all the variable declarations above.Also, I think
btnHehgitis not used anywhere.