diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-03-08 09:30:01 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-03-08 09:30:01 +0000 |
commit | 96a3847eb1bc18d6ea2d228fef488c0cee0e66ec (patch) | |
tree | 93cacd9f236a98caada90e98f5fa35a430f02d15 /app | |
parent | 9df3aaae69826209db91b970ceae0f2133d00980 (diff) | |
parent | c63afd30ed2c5a342c0c4d2347c948f622a66f00 (diff) | |
download | gitlab-ce-96a3847eb1bc18d6ea2d228fef488c0cee0e66ec.tar.gz |
Merge branch '43770-change-clear-runners-cache-ujs-action-to-an-axios-request' into 'master'
Resolve "Change Clear Runners cache UJS action to an API request"
Closes #43770
See merge request gitlab-org/gitlab-ce!17466
Diffstat (limited to 'app')
4 files changed, 50 insertions, 14 deletions
diff --git a/app/assets/javascripts/pipelines/components/nav_controls.vue b/app/assets/javascripts/pipelines/components/nav_controls.vue index 383ab51fe56..eba5678e3e5 100644 --- a/app/assets/javascripts/pipelines/components/nav_controls.vue +++ b/app/assets/javascripts/pipelines/components/nav_controls.vue @@ -1,6 +1,11 @@ <script> + import LoadingButton from '../../vue_shared/components/loading_button.vue'; + export default { name: 'PipelineNavControls', + components: { + LoadingButton, + }, props: { newPipelinePath: { type: String, @@ -19,6 +24,17 @@ required: false, default: null, }, + + isResetCacheButtonLoading: { + type: Boolean, + required: false, + default: false, + }, + }, + methods: { + onClickResetCache() { + this.$emit('resetRunnersCache', this.resetCachePath); + }, }, }; </script> @@ -32,14 +48,13 @@ {{ s__('Pipelines|Run Pipeline') }} </a> - <a + <loading-button v-if="resetCachePath" - data-method="post" - :href="resetCachePath" + @click="onClickResetCache" + :loading="isResetCacheButtonLoading" class="btn btn-default js-clear-cache" - > - {{ s__('Pipelines|Clear Runner Caches') }} - </a> + :label="s__('Pipelines|Clear Runner Caches')" + /> <a v-if="ciLintPath" diff --git a/app/assets/javascripts/pipelines/components/pipelines.vue b/app/assets/javascripts/pipelines/components/pipelines.vue index 6e5ee68eeb1..e0a7284124d 100644 --- a/app/assets/javascripts/pipelines/components/pipelines.vue +++ b/app/assets/javascripts/pipelines/components/pipelines.vue @@ -1,6 +1,7 @@ <script> import _ from 'underscore'; import { __, sprintf, s__ } from '../../locale'; + import createFlash from '../../flash'; import PipelinesService from '../services/pipelines_service'; import pipelinesMixin from '../mixins/pipelines'; import TablePagination from '../../vue_shared/components/table_pagination.vue'; @@ -92,6 +93,7 @@ scope: getParameterByName('scope') || 'all', page: getParameterByName('page') || '1', requestData: {}, + isResetCacheButtonLoading: false, }; }, stateMap: { @@ -265,6 +267,23 @@ this.poll.restart({ data: this.requestData }); }); }, + + handleResetRunnersCache(endpoint) { + this.isResetCacheButtonLoading = true; + + this.service.postAction(endpoint) + .then(() => { + this.isResetCacheButtonLoading = false; + createFlash( + s__('Pipelines|Project cache successfully reset.'), + 'notice', + ); + }) + .catch(() => { + this.isResetCacheButtonLoading = false; + createFlash(s__('Pipelines|Something went wrong while cleaning runners cache.')); + }); + }, }, }; </script> @@ -301,6 +320,8 @@ :new-pipeline-path="newPipelinePath" :reset-cache-path="resetCachePath" :ci-lint-path="ciLintPath" + @resetRunnersCache="handleResetRunnersCache" + :is-reset-cache-button-loading="isResetCacheButtonLoading" /> </div> diff --git a/app/assets/javascripts/pipelines/mixins/pipelines.js b/app/assets/javascripts/pipelines/mixins/pipelines.js index 9fcc07abee5..522a4277bd7 100644 --- a/app/assets/javascripts/pipelines/mixins/pipelines.js +++ b/app/assets/javascripts/pipelines/mixins/pipelines.js @@ -51,12 +51,10 @@ export default { } }); - eventHub.$on('refreshPipelines', this.fetchPipelines); eventHub.$on('postAction', this.postAction); }, beforeDestroy() { - eventHub.$off('refreshPipelines'); - eventHub.$on('postAction', this.postAction); + eventHub.$off('postAction', this.postAction); }, destroyed() { this.poll.stop(); @@ -92,7 +90,7 @@ export default { }, postAction(endpoint) { this.service.postAction(endpoint) - .then(() => eventHub.$emit('refreshPipelines')) + .then(() => this.fetchPipelines()) .catch(() => Flash(__('An error occurred while making the request.'))); }, }, diff --git a/app/controllers/projects/settings/ci_cd_controller.rb b/app/controllers/projects/settings/ci_cd_controller.rb index 86717bb7242..259809f3429 100644 --- a/app/controllers/projects/settings/ci_cd_controller.rb +++ b/app/controllers/projects/settings/ci_cd_controller.rb @@ -13,12 +13,14 @@ module Projects def reset_cache if ResetProjectCacheService.new(@project, current_user).execute - flash[:notice] = _("Project cache successfully reset.") + respond_to do |format| + format.json { head :ok } + end else - flash[:error] = _("Unable to reset project cache.") + respond_to do |format| + format.json { head :bad_request } + end end - - redirect_to project_pipelines_path(@project) end private |