Commit e59d9a0c authored by Phil Hughes's avatar Phil Hughes

removed need for job.js

it was a super hacky implementation that just wasn't working as intended

current sitatuon is still super hacky, but getting better!
parent 90216b20
<script> <script>
import { mapState } from 'vuex'; import { mapState } from 'vuex';
import _ from 'underscore';
import axios from '../../../lib/utils/axios_utils';
import CiIcon from '../../../vue_shared/components/ci_icon.vue';
import tooltip from '../../../vue_shared/directives/tooltip'; import tooltip from '../../../vue_shared/directives/tooltip';
import Icon from '../../../vue_shared/components/icon.vue'; import Icon from '../../../vue_shared/components/icon.vue';
import Job from '../../../job';
const scrollPositions = {
top: 'top',
bottom: 'bottom',
};
export default { export default {
directives: { directives: {
tooltip, tooltip,
}, },
components: { components: {
CiIcon,
Icon, Icon,
}, },
data() {
return {
scrollPos: scrollPositions.top,
loading: true,
};
},
computed: { computed: {
...mapState('pipelines', ['detailJob']), ...mapState('pipelines', ['detailJob']),
rawUrl() { rawUrl() {
return `${this.detailJob.path}/raw`; return `${this.detailJob.path}/raw`;
}, },
isScrolledToBottom() {
return this.scrollPos === scrollPositions.bottom;
},
isScrolledToTop() {
return this.scrollPos === scrollPositions.top;
},
jobId() {
return `#${this.detailJob.id}`;
},
}, },
mounted() { mounted() {
this.job = new Job({ this.getTrace();
buildStage: 'a',
buildState: this.detailJob.status.text,
pagePath: this.detailJob.path,
redirectToJob: false,
});
}, },
beforeDestroy() { beforeDestroy() {
this.job.destroy(); clearTimeout(this.timeout);
},
methods: {
scrollDown() {
this.$refs.buildTrace.scrollTo(0, this.$refs.buildTrace.scrollHeight);
}, },
scrollUp() {
this.$refs.buildTrace.scrollTo(0, 0);
},
scrollBuildLog: _.throttle(function scrollDebounce() {
const scrollTop = this.$refs.buildTrace.scrollTop;
const offsetHeight = this.$refs.buildTrace.offsetHeight;
const scrollHeight = this.$refs.buildTrace.scrollHeight;
if (scrollTop + offsetHeight === scrollHeight) {
this.scrollPos = scrollPositions.bottom;
} else if (scrollTop === 0) {
this.scrollPos = scrollPositions.top;
} else {
this.scrollPos = '';
}
}),
getTrace(state = null) {
return axios
.get(`${this.detailJob.path}/trace`, {
params: {
state,
},
})
.then(({ data }) => {
this.loading = !data.complete;
this.detailJob.output = data.append ? `${this.detailJob.output}${data.html}` : data.html;
if (!data.complete) {
this.timeout = setTimeout(() => this.getTrace(data.state), 4000);
}
})
.then(() => this.$nextTick())
.then(() => this.scrollDown());
},
},
scrollPositions,
}; };
</script> </script>
...@@ -46,19 +104,38 @@ export default { ...@@ -46,19 +104,38 @@ export default {
{{ __('View jobs') }} {{ __('View jobs') }}
</button> </button>
</header> </header>
<div class="build-trace-container prepend-top-default">
<div <div
v-once class="top-bar"
class="top-bar js-top-bar"
> >
<div class="ide-job-details float-left">
<ci-icon
class="append-right-4"
:status="detailJob.status"
:borderless="true"
:size="24"
/>
{{ detailJob.name }}
<a
:href="detailJob.path"
target="_blank"
class="ide-external-link prepend-left-4"
>
{{ jobId }}
<icon
name="external-link"
:size="12"
/>
</a>
</div>
<div class="controllers float-right"> <div class="controllers float-right">
<a <a
v-tooltip v-tooltip
:title="__('Show complete raw')" :title="__('Show complete raw')"
data-placement="top" data-placement="top"
data-container="body" data-container="body"
class="js-raw-link-controller controllers-buttons" class="controllers-buttons"
:href="rawUrl" :href="rawUrl"
target="_blank"
> >
<i <i
aria-hidden="true" aria-hidden="true"
...@@ -73,9 +150,10 @@ export default { ...@@ -73,9 +150,10 @@ export default {
:title="__('Scroll to top')" :title="__('Scroll to top')"
> >
<button <button
class="js-scroll-up btn-scroll btn-transparent btn-blank" class="btn-scroll btn-transparent btn-blank"
disabled
type="button" type="button"
:disabled="isScrolledToTop"
@click="scrollUp"
> >
<icon <icon
name="scroll_up" name="scroll_up"
...@@ -87,12 +165,13 @@ export default { ...@@ -87,12 +165,13 @@ export default {
class="controllers-buttons" class="controllers-buttons"
data-container="body" data-container="body"
data-placement="top" data-placement="top"
:title="__('Scroll to top')" :title="__('Scroll to bottom')"
> >
<button <button
class="js-scroll-up btn-scroll btn-transparent btn-blank" class="btn-scroll btn-transparent btn-blank"
disabled
type="button" type="button"
:disabled="isScrolledToBottom"
@click="scrollDown"
> >
<icon <icon
name="scroll_down" name="scroll_down"
...@@ -103,12 +182,19 @@ export default { ...@@ -103,12 +182,19 @@ export default {
</div> </div>
<pre <pre
class="build-trace" class="build-trace"
id="build-trace" ref="buildTrace"
@scroll="scrollBuildLog"
>
<code
class="bash"
v-html="detailJob.output"
></code>
<div
v-show="loading"
class="build-loader-animation"
> >
<code class="bash js-build-output">
</code>
</pre>
</div> </div>
</pre>
</div> </div>
</template> </template>
...@@ -122,4 +208,16 @@ export default { ...@@ -122,4 +208,16 @@ export default {
.ide-tree-header .btn { .ide-tree-header .btn {
display: flex; display: flex;
} }
.ide-job-details {
display: flex;
}
.ide-job-details .ci-status-icon {
height: 0;
}
.build-trace {
margin-bottom: 0;
}
</style> </style>
...@@ -5,4 +5,5 @@ export const normalizeJob = job => ({ ...@@ -5,4 +5,5 @@ export const normalizeJob = job => ({
status: job.status, status: job.status,
path: job.build_path, path: job.build_path,
started: job.started, started: job.started,
output: '',
}); });
...@@ -22,8 +22,6 @@ export default class Job { ...@@ -22,8 +22,6 @@ export default class Job {
this.$window = $(window); this.$window = $(window);
this.logBytes = 0; this.logBytes = 0;
this.updateDropdown = this.updateDropdown.bind(this); this.updateDropdown = this.updateDropdown.bind(this);
this.redirectToJob =
this.options.redirectToJob !== undefined ? this.options.redirectToJob : true;
this.$buildTrace = $('#build-trace'); this.$buildTrace = $('#build-trace');
this.$buildRefreshAnimation = $('.js-build-refresh'); this.$buildRefreshAnimation = $('.js-build-refresh');
...@@ -46,16 +44,24 @@ export default class Job { ...@@ -46,16 +44,24 @@ export default class Job {
.off('click', '.js-sidebar-build-toggle') .off('click', '.js-sidebar-build-toggle')
.on('click', '.js-sidebar-build-toggle', this.sidebarOnClick.bind(this)); .on('click', '.js-sidebar-build-toggle', this.sidebarOnClick.bind(this));
this.$document.off('click', '.stage-item').on('click', '.stage-item', this.updateDropdown); this.$document
.off('click', '.stage-item')
.on('click', '.stage-item', this.updateDropdown);
// add event listeners to the scroll buttons // add event listeners to the scroll buttons
this.$scrollTopBtn.off('click').on('click', this.scrollToTop.bind(this)); this.$scrollTopBtn
.off('click')
.on('click', this.scrollToTop.bind(this));
this.$scrollBottomBtn.off('click').on('click', this.scrollToBottom.bind(this)); this.$scrollBottomBtn
.off('click')
.on('click', this.scrollToBottom.bind(this));
this.scrollThrottled = _.throttle(this.toggleScroll.bind(this), 100); this.scrollThrottled = _.throttle(this.toggleScroll.bind(this), 100);
this.$window.off('scroll').on('scroll', () => { this.$window
.off('scroll')
.on('scroll', () => {
if (!this.isScrolledToBottom()) { if (!this.isScrolledToBottom()) {
this.toggleScrollAnimation(false); this.toggleScrollAnimation(false);
} else if (this.isScrolledToBottom() && !this.isLogComplete) { } else if (this.isScrolledToBottom() && !this.isLogComplete) {
...@@ -73,10 +79,6 @@ export default class Job { ...@@ -73,10 +79,6 @@ export default class Job {
this.getBuildTrace(); this.getBuildTrace();
} }
destroy() {
clearTimeout(this.timeout);
}
initAffixTopArea() { initAffixTopArea() {
/** /**
If the browser does not support position sticky, it returns the position as static. If the browser does not support position sticky, it returns the position as static.
...@@ -100,7 +102,8 @@ export default class Job { ...@@ -100,7 +102,8 @@ export default class Job {
const windowHeight = $(window).height(); const windowHeight = $(window).height();
if (this.canScroll()) { if (this.canScroll()) {
if (currentPosition > 0 && scrollHeight - currentPosition !== windowHeight) { if (currentPosition > 0 &&
(scrollHeight - currentPosition !== windowHeight)) {
// User is in the middle of the log // User is in the middle of the log
this.toggleDisableButton(this.$scrollTopBtn, false); this.toggleDisableButton(this.$scrollTopBtn, false);
...@@ -166,11 +169,10 @@ export default class Job { ...@@ -166,11 +169,10 @@ export default class Job {
} }
getBuildTrace() { getBuildTrace() {
return axios return axios.get(`${this.pagePath}/trace.json`, {
.get(`${this.pagePath}/trace.json`, {
params: { state: this.state }, params: { state: this.state },
}) })
.then(res => { .then((res) => {
const log = res.data; const log = res.data;
if (!this.fetchingStatusFavicon) { if (!this.fetchingStatusFavicon) {
...@@ -220,7 +222,7 @@ export default class Job { ...@@ -220,7 +222,7 @@ export default class Job {
this.toggleScrollAnimation(false); this.toggleScrollAnimation(false);
} }
if (log.status !== this.buildStatus && this.redirectToJob) { if (log.status !== this.buildStatus) {
visitUrl(this.pagePath); visitUrl(this.pagePath);
} }
}) })
......
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