Translate zuulStartStream into typescript

Make log streaming code typescript. While doing that, update the url query
parameter code to use the ActivatedRoute. The next patch will shift the
code directly into the component, but that diff would be hard to read.

Change-Id: I6d7f5ccf9c26e275c86fe5886fc172bb48395ade
This commit is contained in:
Monty Taylor 2018-04-03 14:52:06 -05:00
parent 56f9d37813
commit 1ecf594138
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
2 changed files with 20 additions and 16 deletions

View File

@ -27,6 +27,6 @@ export default class StreamComponent implements OnInit {
constructor(private route: ActivatedRoute, private zuul: ZuulService) {}
ngOnInit() {
zuulStartStream(this.route.snapshot.paramMap.get('tenant'), this.zuul)
zuulStartStream(this.route, this.zuul)
}
}

View File

@ -14,6 +14,11 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
declare var BuiltinConfig: object
import { ActivatedRoute } from '@angular/router'
import ZuulService from '../zuul/zuul.service'
function escapeLog (text) {
const pattern = /[<>&"']/g
@ -23,8 +28,8 @@ function escapeLog (text) {
})
}
function zuulStartStream (tenant, zuulService) {
let pageUpdateInMS = 250
function zuulStartStream (route: ActivatedRoute, zuulService: ZuulService) {
const pageUpdateInMS = 250
let receiveBuffer = ''
setInterval(function () {
@ -32,32 +37,31 @@ function zuulStartStream (tenant, zuulService) {
if (receiveBuffer !== '') {
document.getElementById('zuulstreamcontent').innerHTML += receiveBuffer
receiveBuffer = ''
if (document.getElementById('autoscroll').checked) {
if ((<HTMLInputElement>document.getElementById('autoscroll')).checked) {
window.scrollTo(0, document.body.scrollHeight)
}
}
}, pageUpdateInMS)
let url = new URL(window.location)
const queryParamMap = route.snapshot.queryParamMap
const tenant = route.snapshot.paramMap.get('tenant')
let params = {
uuid: url.searchParams.get('uuid')
const params = {
uuid: queryParamMap.get('uuid')
}
document.getElementById('pagetitle').innerHTML = params['uuid']
if (url.searchParams.has('logfile')) {
params['logfile'] = url.searchParams.get('logfile')
let logfileSuffix = `(${params['logfile']})`
document.getElementById('pagetitle').innerHTML += logfileSuffix
if (queryParamMap.has('logfile')) {
params['logfile'] = queryParamMap.get('logfile')
const logfileSuffix = `(${params['logfile']})`
}
if (typeof BuiltinConfig !== 'undefined') {
params['websocket_url'] = BuiltinConfig.websocket_url
} else if (url.searchParams.has('websocket_url')) {
params['websocket_url'] = url.searchParams.get('websocket_url')
params['websocket_url'] = BuiltinConfig['websocket_url']
} else if (queryParamMap.has('websocket_url')) {
params['websocket_url'] = queryParamMap.get('websocket_url')
} else {
params['websocket_url'] = zuulService.getWebsocketUrl(
'console-stream', tenant)
}
let ws = new WebSocket(params['websocket_url'])
const ws = new WebSocket(params['websocket_url'])
ws.onmessage = function (event) {
console.log('onmessage')