From 9a238d259a5825fbc348cfb611f836bc1dc9f645 Mon Sep 17 00:00:00 2001 From: Luke Bennett Date: Sun, 17 Dec 2017 00:20:20 +0000 Subject: Fix subscribe button --- .../pipelines/components/header_component.vue | 11 ++++ .../pipelines/pipeline_details_bundle.js | 9 ++- .../pipelines/pipeline_details_mediatior.js | 1 + .../clients/pipeline_notification_client.js | 1 + .../workers/pipeline_notification_worker.js | 1 + .../vue_shared/components/header_ci_component.vue | 18 ++++-- ...ipeline_push_notifications_subscribe_button.vue | 75 ++++++++++++++++++++++ .../push_notifications_subscribe_button.vue | 56 ---------------- app/controllers/profiles_controller.rb | 14 +++- app/models/ci/pipeline.rb | 4 +- app/models/ci/pipeline_subscription.rb | 2 +- app/models/user.rb | 7 +- app/services/users/update_service.rb | 15 +++-- app/views/projects/pipelines/show.html.haml | 2 +- app/workers/pipeline_webpush_worker.rb | 11 +++- 15 files changed, 149 insertions(+), 78 deletions(-) create mode 100644 app/assets/javascripts/vue_shared/components/pipeline_push_notifications_subscribe_button.vue delete mode 100644 app/assets/javascripts/vue_shared/components/push_notifications_subscribe_button.vue (limited to 'app') diff --git a/app/assets/javascripts/pipelines/components/header_component.vue b/app/assets/javascripts/pipelines/components/header_component.vue index 2a1ecac3707..20dfe5ea649 100644 --- a/app/assets/javascripts/pipelines/components/header_component.vue +++ b/app/assets/javascripts/pipelines/components/header_component.vue @@ -14,6 +14,11 @@ export default { type: Boolean, required: true, }, + isSubscribed: { + type: Boolean, + required: false, + default: false, + }, }, components: { ciHeader, @@ -44,6 +49,10 @@ export default { eventHub.$emit('headerPostAction', action); }, + emitSetIsSubscribed(...args) { + eventHub.$emit('setIsSubscribed', ...args); + }, + getActions() { const actions = []; @@ -88,7 +97,9 @@ export default { :time="pipeline.created_at" :user="pipeline.user" :actions="actions" + :is-subscribed="isSubscribed" @actionClicked="postAction" + @setIsSubscribed="emitSetIsSubscribed" /> { const dataset = document.querySelector('.js-pipeline-details-vue').dataset; - const mediator = new PipelinesMediator({ endpoint: dataset.endpoint }); + const mediator = new PipelinesMediator({ endpoint: dataset.endpoint, isSubscribed: dataset.isSubscribed }); mediator.fetchPipeline(); @@ -46,9 +46,11 @@ document.addEventListener('DOMContentLoaded', () => { }, created() { eventHub.$on('headerPostAction', this.postAction); + eventHub.$on('setIsSubscribed', this.setIsSubscribed); }, beforeDestroy() { eventHub.$off('headerPostAction', this.postAction); + eventHub.$off('setIsSubscribed', this.setIsSubscribed); }, methods: { postAction(action) { @@ -56,11 +58,16 @@ document.addEventListener('DOMContentLoaded', () => { .then(() => this.mediator.refreshPipeline()) .catch(() => new Flash('An error occurred while making the request.')); }, + + setIsSubscribed(isSubscribed) { + this.mediator.state.isSubscribed = isSubscribed; + }, }, render(createElement) { return createElement('pipeline-header', { props: { isLoading: this.mediator.state.isLoading, + isSubscribed: this.mediator.state.isSubscribed, pipeline: this.mediator.store.state.pipeline, }, }); diff --git a/app/assets/javascripts/pipelines/pipeline_details_mediatior.js b/app/assets/javascripts/pipelines/pipeline_details_mediatior.js index 823ccd849f4..e63de175b0c 100644 --- a/app/assets/javascripts/pipelines/pipeline_details_mediatior.js +++ b/app/assets/javascripts/pipelines/pipeline_details_mediatior.js @@ -12,6 +12,7 @@ export default class pipelinesMediator { this.state = {}; this.state.isLoading = false; + this.state.isSubscribed = options.isSubscribed === 'true'; } fetchPipeline() { diff --git a/app/assets/javascripts/service_workers/clients/pipeline_notification_client.js b/app/assets/javascripts/service_workers/clients/pipeline_notification_client.js index ba0266a2991..5532abb12aa 100644 --- a/app/assets/javascripts/service_workers/clients/pipeline_notification_client.js +++ b/app/assets/javascripts/service_workers/clients/pipeline_notification_client.js @@ -29,6 +29,7 @@ export default { register() { return this.worker.register(this.workerPath) + .then(this.worker.ready) .then((registration) => { this.registration = registration; }); diff --git a/app/assets/javascripts/service_workers/workers/pipeline_notification_worker.js b/app/assets/javascripts/service_workers/workers/pipeline_notification_worker.js index bf332a0afdd..6da713960f1 100644 --- a/app/assets/javascripts/service_workers/workers/pipeline_notification_worker.js +++ b/app/assets/javascripts/service_workers/workers/pipeline_notification_worker.js @@ -1,5 +1,6 @@ function onPush(event) { console.log('PipelineNotificatinWorker onPush', event); + debugger; console.log('JSON', event.data.json()); console.log('logo', gon); console.log('test'); diff --git a/app/assets/javascripts/vue_shared/components/header_ci_component.vue b/app/assets/javascripts/vue_shared/components/header_ci_component.vue index f1ec9bcfda1..adc871a086e 100644 --- a/app/assets/javascripts/vue_shared/components/header_ci_component.vue +++ b/app/assets/javascripts/vue_shared/components/header_ci_component.vue @@ -4,7 +4,7 @@ import loadingIcon from './loading_icon.vue'; import timeagoTooltip from './time_ago_tooltip.vue'; import tooltip from '../directives/tooltip'; import userAvatarImage from './user_avatar/user_avatar_image.vue'; -import pushNotificationsSubscribeButton from './push_notifications_subscribe_button.vue'; +import pipelinePushNotificationsSubscribeButton from './pipeline_push_notifications_subscribe_button.vue'; /** * Renders header component for job and pipeline page based on UI mockups @@ -46,6 +46,11 @@ export default { required: false, default: false, }, + isSubscribed: { + type: Boolean, + required: false, + default: false, + }, }, directives: { @@ -57,7 +62,7 @@ export default { loadingIcon, timeagoTooltip, userAvatarImage, - pushNotificationsSubscribeButton, + pipelinePushNotificationsSubscribeButton, }, computed: { @@ -70,6 +75,10 @@ export default { onClickAction(action) { this.$emit('actionClicked', action); }, + + emitSetIsSubscribed(...args) { + this.$emit('setIsSubscribed', ...args); + }, }, }; @@ -143,9 +152,10 @@ export default { aria-hidden="true"> - - + + +