Commit a5438f30 authored by derek-knox's avatar derek-knox Committed by Chad Woolley

Initial mr template API setup

Add endpoint to get desired payload
Add namespace and project props
parent 8d9b0d04
...@@ -34,6 +34,7 @@ const Api = { ...@@ -34,6 +34,7 @@ const Api = {
mergeRequestsPath: '/api/:version/merge_requests', mergeRequestsPath: '/api/:version/merge_requests',
groupLabelsPath: '/groups/:namespace_path/-/labels', groupLabelsPath: '/groups/:namespace_path/-/labels',
issuableTemplatePath: '/:namespace_path/:project_path/templates/:type/:key', issuableTemplatePath: '/:namespace_path/:project_path/templates/:type/:key',
issuableTemplatesPath: '/:namespace_path/:project_path/templates/:type',
projectTemplatePath: '/api/:version/projects/:id/templates/:type/:key', projectTemplatePath: '/api/:version/projects/:id/templates/:type/:key',
projectTemplatesPath: '/api/:version/projects/:id/templates/:type', projectTemplatesPath: '/api/:version/projects/:id/templates/:type',
userCountsPath: '/api/:version/user_counts', userCountsPath: '/api/:version/user_counts',
...@@ -471,6 +472,17 @@ const Api = { ...@@ -471,6 +472,17 @@ const Api = {
.catch(callback); .catch(callback);
}, },
issueTemplates(namespacePath, projectPath, type, callback) {
const url = Api.buildUrl(Api.issuableTemplatesPath)
.replace(':type', type)
.replace(':project_path', projectPath)
.replace(':namespace_path', namespacePath);
return axios
.get(url)
.then(({ data }) => callback(null, data))
.catch(callback);
},
users(query, options) { users(query, options) {
const url = Api.buildUrl(this.usersPath); const url = Api.buildUrl(this.usersPath);
return axios.get(url, { return axios.get(url, {
......
<script> <script>
import { GlModal } from '@gitlab/ui'; import { GlModal } from '@gitlab/ui';
import { __, s__, sprintf } from '~/locale'; import { __, s__, sprintf } from '~/locale';
import Api from '~/api';
import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue'; import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue';
import EditMetaControls from './edit_meta_controls.vue'; import EditMetaControls from './edit_meta_controls.vue';
...@@ -18,6 +19,14 @@ export default { ...@@ -18,6 +19,14 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
namespace: {
type: String,
required: true,
},
project: {
type: String,
required: true,
},
}, },
data() { data() {
return { return {
...@@ -49,10 +58,19 @@ export default { ...@@ -49,10 +58,19 @@ export default {
}; };
}, },
}, },
mounted() {
this.initTemplates();
},
methods: { methods: {
hide() { hide() {
this.$refs.modal.hide(); this.$refs.modal.hide();
}, },
initTemplates() {
Api.issueTemplates(this.namespace, this.project, 'merge_request', (err, templates) => {
if (err) return; // Error handled by global AJAX error handler
this.mergeRequestTemplates = templates;
});
},
show() { show() {
this.$refs.modal.show(); this.$refs.modal.show();
}, },
......
...@@ -148,6 +148,8 @@ export default { ...@@ -148,6 +148,8 @@ export default {
<edit-meta-modal <edit-meta-modal
ref="editMetaModal" ref="editMetaModal"
:source-path="appData.sourcePath" :source-path="appData.sourcePath"
:namespace="appData.project.split('/')[0]"
:project="appData.project.split('/')[1]"
@primary="onSubmit" @primary="onSubmit"
@hide="onHideModal" @hide="onHideModal"
/> />
......
...@@ -7,6 +7,14 @@ class Projects::TemplatesController < Projects::ApplicationController ...@@ -7,6 +7,14 @@ class Projects::TemplatesController < Projects::ApplicationController
feature_category :templates feature_category :templates
def index
templates = @template_type.template_subsets(project)
respond_to do |format|
format.json { render json: templates.to_json }
end
end
def show def show
template = @template_type.find(params[:key], project) template = @template_type.find(params[:key], project)
......
...@@ -403,6 +403,11 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -403,6 +403,11 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
# #
# Templates # Templates
# #
get '/templates/:template_type' => 'templates#index', # rubocop:todo Cop/PutProjectRoutesUnderScope
as: :templates,
defaults: { format: 'json' },
constraints: { template_type: %r{issue|merge_request}, format: 'json' }
get '/templates/:template_type/:key' => 'templates#show', # rubocop:todo Cop/PutProjectRoutesUnderScope get '/templates/:template_type/:key' => 'templates#show', # rubocop:todo Cop/PutProjectRoutesUnderScope
as: :template, as: :template,
defaults: { format: 'json' }, defaults: { format: 'json' },
......
...@@ -105,6 +105,20 @@ module Gitlab ...@@ -105,6 +105,20 @@ module Gitlab
files.map { |t| { name: t.name } } files.map { |t| { name: t.name } }
end end
end end
def template_subsets(project = nil)
return [] if project && !project.repository.exists?
if categories.any?
categories.keys.map do |category|
files = self.by_category(category, project)
[category, files.map { |t| { key: t.key, name: t.name, content: t.content} }]
end.to_h
else
files = self.all(project)
files.map { |t| { key: t.key, name: t.name, content: t.content} }
end
end
end end
end end
end end
......
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