BigW Consortium Gitlab

Commit 74520f23 by Kamil Trzcinski

Encode state as base64 string

parent baef6728
class CiBuild
@interval: null
@state: null
constructor: (build_url, build_status) ->
constructor: (build_url, build_status, build_state) ->
clearInterval(CiBuild.interval)
@state = build_state
@initScrollButtonAffix()
if build_status == "running" || build_status == "pending"
......@@ -26,14 +29,18 @@ class CiBuild
CiBuild.interval = setInterval =>
if window.location.href.split("#").first() is build_url
$.ajax
url: build_url
url: build_url + "/trace.json?state=" + encodeURIComponent(@state)
dataType: "json"
success: (build) =>
if build.status == "running"
$('#build-trace code').html build.trace_html
$('#build-trace code').append '<i class="fa fa-refresh fa-spin"/>'
success: (log) =>
@state = log.state
if log.status is "running"
if log.append
$('.fa-refresh').before log.html
else
$('#build-trace code').html log.html
$('#build-trace code').append '<i class="fa fa-refresh fa-spin"/>'
@checkAutoscroll()
else if build.status != build_status
else if log.status isnt build_status
Turbolinks.visit build_url
, 4000
......
......@@ -41,7 +41,7 @@ class Projects::BuildsController < Projects::ApplicationController
def trace
respond_to do |format|
format.json do
render json: @build.trace_with_state(params_state).merge!(id: @build.id, status: @build.status)
render json: @build.trace_with_state(params[:state]).merge!(id: @build.id, status: @build.status)
end
end
end
......@@ -80,13 +80,6 @@ class Projects::BuildsController < Projects::ApplicationController
private
def params_state
begin
JSON.parse(params[:state], symbolize_names: true)
rescue
end
end
def build
@build ||= project.builds.unscoped.find_by!(id: params[:id])
end
......
- page_title "#{@build.name} (##{@build.id})", "Builds"
= render "header_title"
- trace = build.trace_for_state
- trace_with_state = @build.trace_with_state
.build-page
.row-content-block.top-block
......@@ -86,7 +86,7 @@
%pre.trace#build-trace
%code.bash
= preserve do
= raw trace[:html]
= raw trace_with_state[:html]
- if @build.active?
%i{:class => "fa fa-refresh fa-spin"}
......@@ -219,4 +219,4 @@
:javascript
new CiBuild("#{namespace_project_build_url(@project.namespace, @project, @build)}", "#{@build.status}", "#{trace[:state]}")
new CiBuild("#{namespace_project_build_url(@project.namespace, @project, @build)}", "#{@build.status}", "#{trace_with_state[:state]}")
......@@ -90,7 +90,7 @@ module Ci
def convert(raw, new_state)
reset_state
restore_state(new_state) if new_state && new_state[:offset].to_i < raw.length
restore_state(raw, new_state) if new_state
start = @offset
ansi = raw[@offset..-1]
......@@ -187,15 +187,20 @@ module Ci
end
def state
STATE_PARAMS.inject({}) do |h, param|
state = STATE_PARAMS.inject({}) do |h, param|
h[param] = send(param)
h
end
Base64.urlsafe_encode64(state.to_json)
end
def restore_state(new_state)
def restore_state(raw, new_state)
state = Base64.urlsafe_decode64(new_state)
state = JSON.parse(state, symbolize_names: true)
return if state[:offset].to_i > raw.length
STATE_PARAMS.each do |param|
send("#{param}=".to_sym, new_state[param])
send("#{param}=".to_sym, state[param])
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment