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,69 +104,97 @@ export default { ...@@ -46,69 +104,97 @@ export default {
{{ __('View jobs') }} {{ __('View jobs') }}
</button> </button>
</header> </header>
<div class="build-trace-container prepend-top-default"> <div
<div class="top-bar"
v-once >
class="top-bar js-top-bar" <div class="ide-job-details float-left">
> <ci-icon
<div class="controllers float-right"> class="append-right-4"
<a :status="detailJob.status"
v-tooltip :borderless="true"
:title="__('Show complete raw')" :size="24"
data-placement="top" />
data-container="body" {{ detailJob.name }}
class="js-raw-link-controller controllers-buttons" <a
:href="rawUrl" :href="detailJob.path"
> target="_blank"
<i class="ide-external-link prepend-left-4"
aria-hidden="true" >
class="fa fa-file-text-o" {{ jobId }}
></i> <icon
</a> name="external-link"
<div :size="12"
v-tooltip />
class="controllers-buttons" </a>
data-container="body" </div>
data-placement="top" <div class="controllers float-right">
:title="__('Scroll to top')" <a
v-tooltip
:title="__('Show complete raw')"
data-placement="top"
data-container="body"
class="controllers-buttons"
:href="rawUrl"
target="_blank"
>
<i
aria-hidden="true"
class="fa fa-file-text-o"
></i>
</a>
<div
v-tooltip
class="controllers-buttons"
data-container="body"
data-placement="top"
:title="__('Scroll to top')"
>
<button
class="btn-scroll btn-transparent btn-blank"
type="button"
:disabled="isScrolledToTop"
@click="scrollUp"
> >
<button <icon
class="js-scroll-up btn-scroll btn-transparent btn-blank" name="scroll_up"
disabled />
type="button" </button>
> </div>
<icon <div
name="scroll_up" v-tooltip
/> class="controllers-buttons"
</button> data-container="body"
</div> data-placement="top"
<div :title="__('Scroll to bottom')"
v-tooltip >
class="controllers-buttons" <button
data-container="body" class="btn-scroll btn-transparent btn-blank"
data-placement="top" type="button"
:title="__('Scroll to top')" :disabled="isScrolledToBottom"
@click="scrollDown"
> >
<button <icon
class="js-scroll-up btn-scroll btn-transparent btn-blank" name="scroll_down"
disabled />
type="button" </button>
>
<icon
name="scroll_down"
/>
</button>
</div>
</div> </div>
</div> </div>
<pre
class="build-trace"
id="build-trace"
>
<code class="bash js-build-output">
</code>
</pre>
</div> </div>
<pre
class="build-trace"
ref="buildTrace"
@scroll="scrollBuildLog"
>
<code
class="bash"
v-html="detailJob.output"
></code>
<div
v-show="loading"
class="build-loader-animation"
>
</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;
} }
</style>
\ No newline at end of file .ide-job-details {
display: flex;
}
.ide-job-details .ci-status-icon {
height: 0;
}
.build-trace {
margin-bottom: 0;
}
</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,23 +44,31 @@ export default class Job { ...@@ -46,23 +44,31 @@ 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
if (!this.isScrolledToBottom()) { .off('scroll')
this.toggleScrollAnimation(false); .on('scroll', () => {
} else if (this.isScrolledToBottom() && !this.isLogComplete) { if (!this.isScrolledToBottom()) {
this.toggleScrollAnimation(true); this.toggleScrollAnimation(false);
} } else if (this.isScrolledToBottom() && !this.isLogComplete) {
this.scrollThrottled(); this.toggleScrollAnimation(true);
}); }
this.scrollThrottled();
});
this.$window this.$window
.off('resize.build') .off('resize.build')
...@@ -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,8 +102,9 @@ export default class Job { ...@@ -100,8 +102,9 @@ 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 &&
// User is in the middle of the log (scrollHeight - currentPosition !== windowHeight)) {
// User is in the middle of the log
this.toggleDisableButton(this.$scrollTopBtn, false); this.toggleDisableButton(this.$scrollTopBtn, false);
this.toggleDisableButton(this.$scrollBottomBtn, false); this.toggleDisableButton(this.$scrollBottomBtn, 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