Commit 31823c83 authored by Justin Ho's avatar Justin Ho

Move gitlab_slack_application to integrations

- Add new projects dropdown that includes project's
avatar and name with namespace.
- Update backend and helper to pass in more data
that is needed on the frontend.
parent 1c86cc58
...@@ -364,7 +364,7 @@ table.u2f-registrations { ...@@ -364,7 +364,7 @@ table.u2f-registrations {
} }
.gitlab-slack-body { .gitlab-slack-body {
max-width: 600px; max-width: 420px;
} }
.gitlab-slack-slack-logo { .gitlab-slack-slack-logo {
......
import axios from '~/lib/utils/axios_utils';
export default {
addToSlack(url, projectId) {
return axios.get(url, {
params: {
project_id: projectId,
},
});
},
};
import axios from '~/lib/utils/axios_utils';
export const addProjectToSlack = (url, projectId) => {
return axios.get(url, {
params: { project_id: projectId },
});
};
...@@ -5,72 +5,66 @@ import createFlash from '~/flash'; ...@@ -5,72 +5,66 @@ import createFlash from '~/flash';
import { redirectTo } from '~/lib/utils/url_utility'; import { redirectTo } from '~/lib/utils/url_utility';
import { __ } from '~/locale'; import { __ } from '~/locale';
import GitlabSlackService from '../services/gitlab_slack_service'; import { addProjectToSlack } from '../api';
import ProjectsDropdown from './projects_dropdown.vue';
export default { export default {
components: { components: {
GlButton, GlButton,
GlIcon, GlIcon,
ProjectsDropdown,
}, },
props: { props: {
projects: { projects: {
type: Array, type: Array,
required: false, required: false,
default: () => [], default: () => [],
}, },
isSignedIn: { isSignedIn: {
type: Boolean, type: Boolean,
required: true, required: true,
}, },
gitlabForSlackGifPath: { gitlabForSlackGifPath: {
type: String, type: String,
required: true, required: true,
}, },
signInPath: { signInPath: {
type: String, type: String,
required: true, required: true,
}, },
slackLinkPath: { slackLinkPath: {
type: String, type: String,
required: true, required: true,
}, },
gitlabLogoPath: { gitlabLogoPath: {
type: String, type: String,
required: true, required: true,
}, },
slackLogoPath: { slackLogoPath: {
type: String, type: String,
required: true, required: true,
}, },
docsPath: { docsPath: {
type: String, type: String,
required: true, required: true,
}, },
}, },
data() { data() {
return { return {
selectedProjectId: this.projects && this.projects.length ? this.projects[0].id : 0, selectedProject: null,
}; };
}, },
computed: { computed: {
hasProjects() { hasProjects() {
return this.projects.length > 0; return this.projects.length > 0;
}, },
}, },
methods: { methods: {
selectProject(project) {
this.selectedProject = project;
},
addToSlack() { addToSlack() {
GitlabSlackService.addToSlack(this.slackLinkPath, this.selectedProjectId) addProjectToSlack(this.slackLinkPath, this.selectedProject.id)
.then((response) => redirectTo(response.data.add_to_slack_link)) .then((response) => redirectTo(response.data.add_to_slack_link))
.catch(() => .catch(() =>
createFlash({ createFlash({
...@@ -91,31 +85,43 @@ export default { ...@@ -91,31 +85,43 @@ export default {
</div> </div>
<h1>{{ s__('SlackIntegration|GitLab for Slack') }}</h1> <h1>{{ s__('SlackIntegration|GitLab for Slack') }}</h1>
<p>{{ s__('SlackIntegration|Select a GitLab project to link with your Slack workspace.') }}</p>
<div class="mx-auto prepend-top-20 text-center"> <div class="gl-mt-6">
<div v-if="isSignedIn && hasProjects"> <template v-if="isSignedIn">
<select v-model="selectedProjectId" class="js-project-select form-control gl-mt-3 gl-mb-3"> <template v-if="hasProjects">
<option v-for="project in projects" :key="project.id" :value="project.id"> <p>
{{ project.name }} {{ s__('SlackIntegration|Select a GitLab project to link with your Slack workspace.') }}
</option> </p>
</select>
<projects-dropdown
:projects="projects"
:selected-project="selectedProject"
@projectSelected="selectProject"
/>
<div class="gl-display-flex gl-justify-content-end"> <div class="gl-display-flex gl-justify-content-end">
<gl-button category="primary" variant="confirm" class="float-right" @click="addToSlack"> <gl-button
category="primary"
variant="confirm"
class="float-right"
:disabled="!selectedProject"
@click="addToSlack"
>
{{ __('Continue') }} {{ __('Continue') }}
</gl-button> </gl-button>
</div> </div>
</div> </template>
<template v-else>
<span v-else-if="isSignedIn && !hasProjects" class="js-no-projects">{{ <p class="js-no-projects">{{ __("You don't have any projects available.") }}</p>
__("You don't have any projects available.") </template>
}}</span> </template>
<span v-else> <template v-else>
You have to <p>{{ s__('JiraService|Sign in to GitLab.com to get started.') }}</p>
<a v-once :href="signInPath" class="js-gitlab-slack-sign-in-link">{{ __('log in') }}</a> <gl-button category="primary" variant="confirm" :href="signInPath">{{
</span> __('Sign in to GitLab')
}}</gl-button>
</template>
</div> </div>
<div class="center prepend-top-20 gl-mb-3 gl-mr-2 gl-ml-2"> <div class="center prepend-top-20 gl-mb-3 gl-mr-2 gl-ml-2">
...@@ -125,7 +131,7 @@ export default { ...@@ -125,7 +131,7 @@ export default {
<div v-once class="text-center"> <div v-once class="text-center">
<h3>{{ __('How it works') }}</h3> <h3>{{ __('How it works') }}</h3>
<div class="well gitlab-slack-well mx-auto"> <div class="mx-auto">
<code class="code mx-auto gl-mb-3" <code class="code mx-auto gl-mb-3"
>/gitlab &lt;project-alias&gt; issue show &lt;id&gt;</code >/gitlab &lt;project-alias&gt; issue show &lt;id&gt;</code
> >
......
<script>
import { GlDropdown } from '@gitlab/ui';
import { __ } from '~/locale';
import ProjectListItem from '~/vue_shared/components/project_selector/project_list_item.vue';
export default {
components: {
GlDropdown,
ProjectListItem,
},
props: {
projectDropdownText: {
type: String,
required: false,
default: __('Select a project'),
},
projects: {
type: Array,
required: false,
default: () => [],
},
selectedProject: {
type: Object,
required: false,
default: null,
},
},
computed: {
dropdownText() {
return this.selectedProject
? this.selectedProject.name_with_namespace
: this.projectDropdownText;
},
},
methods: {
onClick(project) {
this.$emit('projectSelected', project);
this.$refs.dropdown.hide(true);
},
},
};
</script>
<template>
<gl-dropdown ref="dropdown" block :text="dropdownText" menu-class="gl-w-full!">
<project-list-item
v-for="project in projects"
:key="project.id"
:project="project"
:selected="false"
@click="onClick(project)"
/>
</gl-dropdown>
</template>
import Vue from 'vue'; import Vue from 'vue';
import AddGitlabSlackApplication from './components/add_gitlab_slack_application.vue'; import { parseBoolean } from '~/lib/utils/common_utils';
import GitlabSlackApplication from './components/gitlab_slack_application.vue';
export default () => { export default () => {
const el = document.querySelector('.js-add-gitlab-slack-application'); const el = document.querySelector('.js-gitlab-slack-application');
if (!el) return null; if (!el) return null;
...@@ -20,10 +21,10 @@ export default () => { ...@@ -20,10 +21,10 @@ export default () => {
return new Vue({ return new Vue({
el, el,
render(createElement) { render(createElement) {
return createElement(AddGitlabSlackApplication, { return createElement(GitlabSlackApplication, {
props: { props: {
projects: JSON.parse(projects), projects: JSON.parse(projects),
isSignedIn, isSignedIn: parseBoolean(isSignedIn),
gitlabForSlackGifPath, gitlabForSlackGifPath,
signInPath, signInPath,
slackLinkPath, slackLinkPath,
......
import mountAddGitlabSlackApplication from 'ee/add_gitlab_slack_application'; import initGitlabSlackApplication from 'ee/integrations/gitlab_slack_application';
mountAddGitlabSlackApplication(); initGitlabSlackApplication();
...@@ -10,7 +10,7 @@ class Profiles::SlacksController < Profiles::ApplicationController ...@@ -10,7 +10,7 @@ class Profiles::SlacksController < Profiles::ApplicationController
feature_category :users feature_category :users
def edit def edit
@projects = disabled_projects.select([:id, :name]) if current_user @projects = disabled_projects if current_user
end end
def slack_link def slack_link
......
...@@ -36,9 +36,9 @@ module EE ...@@ -36,9 +36,9 @@ module EE
def add_to_slack_data(projects) def add_to_slack_data(projects)
{ {
projects: projects.as_json(only: [:id, :name]).to_json, projects: (projects || []).map { |p| serialize_project(p) }.to_json,
sign_in_path: new_session_path(:user, redirect_to_referer: 'yes'), sign_in_path: new_session_path(:user, redirect_to_referer: 'yes'),
is_signed_in: current_user.present?, is_signed_in: current_user.present?.to_s,
slack_link_path: slack_link_profile_slack_path, slack_link_path: slack_link_profile_slack_path,
gitlab_for_slack_gif_path: image_path('gitlab_for_slack.gif'), gitlab_for_slack_gif_path: image_path('gitlab_for_slack.gif'),
gitlab_logo_path: image_path('illustrations/gitlab_logo.svg'), gitlab_logo_path: image_path('illustrations/gitlab_logo.svg'),
...@@ -64,5 +64,16 @@ module EE ...@@ -64,5 +64,16 @@ module EE
super super
end end
private
def serialize_project(project)
{
id: project.id,
name: project.name,
avatar_url: project.avatar.url,
name_with_namespace: project.name_with_namespace
}
end
end end
end end
...@@ -3,4 +3,4 @@ ...@@ -3,4 +3,4 @@
- @content_class = 'limit-container-width' - @content_class = 'limit-container-width'
- page_title s_('SlackIntegration|GitLab for Slack') - page_title s_('SlackIntegration|GitLab for Slack')
.js-add-gitlab-slack-application{ data: add_to_slack_data(@projects) } .js-gitlab-slack-application{ data: add_to_slack_data(@projects) }
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