diff options
author | Phil Hughes <me@iamphill.com> | 2018-02-21 14:39:04 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-02-21 14:39:04 +0000 |
commit | 48b1455566a51f4dea6b3b86553d2f239266a1f9 (patch) | |
tree | 02fb323f1a3137351d3128a0d2de74efde8f9e7d /app/assets/javascripts/pipelines/pipeline_details_mediator.js | |
parent | 4e3f7a56054d0113b223276ce2360fc53c08b954 (diff) | |
parent | bb9e7a3f2cf80c09b64156988abb9ffba1de6d2c (diff) | |
download | gitlab-ce-48b1455566a51f4dea6b3b86553d2f239266a1f9.tar.gz |
Merge branch 'ce-3776-ci-view-for-sast' into 'master'
CE port of changes made to the pipeline bundle in EE - Fixes typos and adds i18n
See merge request gitlab-org/gitlab-ce!17176
Diffstat (limited to 'app/assets/javascripts/pipelines/pipeline_details_mediator.js')
-rw-r--r-- | app/assets/javascripts/pipelines/pipeline_details_mediator.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/app/assets/javascripts/pipelines/pipeline_details_mediator.js b/app/assets/javascripts/pipelines/pipeline_details_mediator.js new file mode 100644 index 00000000000..10f238fe73b --- /dev/null +++ b/app/assets/javascripts/pipelines/pipeline_details_mediator.js @@ -0,0 +1,59 @@ +import Visibility from 'visibilityjs'; +import Flash from '../flash'; +import Poll from '../lib/utils/poll'; +import { __ } from '../locale'; +import PipelineStore from './stores/pipeline_store'; +import PipelineService from './services/pipeline_service'; + +export default class pipelinesMediator { + constructor(options = {}) { + this.options = options; + this.store = new PipelineStore(); + this.service = new PipelineService(options.endpoint); + + this.state = {}; + this.state.isLoading = false; + } + + fetchPipeline() { + this.poll = new Poll({ + resource: this.service, + method: 'getPipeline', + successCallback: this.successCallback.bind(this), + errorCallback: this.errorCallback.bind(this), + }); + + if (!Visibility.hidden()) { + this.state.isLoading = true; + this.poll.makeRequest(); + } else { + this.refreshPipeline(); + } + + Visibility.change(() => { + if (!Visibility.hidden()) { + this.poll.restart(); + } else { + this.poll.stop(); + } + }); + } + + successCallback(response) { + return response.json().then((data) => { + this.state.isLoading = false; + this.store.storePipeline(data); + }); + } + + errorCallback() { + this.state.isLoading = false; + Flash(__('An error occurred while fetching the pipeline.')); + } + + refreshPipeline() { + this.service.getPipeline() + .then(response => this.successCallback(response)) + .catch(() => this.errorCallback()); + } +} |