From bb9e7a3f2cf80c09b64156988abb9ffba1de6d2c Mon Sep 17 00:00:00 2001 From: Filipa Lacerda Date: Fri, 16 Feb 2018 12:07:04 +0000 Subject: CE port of changes made to the pipeline bundle in EE - Fixes typos and adds i18n Backport common class name for the tab content Backport more changes --- .../pipelines/pipeline_details_mediator.js | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 app/assets/javascripts/pipelines/pipeline_details_mediator.js (limited to 'app/assets/javascripts/pipelines/pipeline_details_mediator.js') 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()); + } +} -- cgit v1.2.1