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 = {
mergeRequestsPath: '/api/:version/merge_requests',
groupLabelsPath: '/groups/:namespace_path/-/labels',
issuableTemplatePath: '/:namespace_path/:project_path/templates/:type/:key',
issuableTemplatesPath: '/:namespace_path/:project_path/templates/:type',
projectTemplatePath: '/api/:version/projects/:id/templates/:type/:key',
projectTemplatesPath: '/api/:version/projects/:id/templates/:type',
userCountsPath: '/api/:version/user_counts',
......@@ -471,6 +472,17 @@ const Api = {
.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) {
const url = Api.buildUrl(this.usersPath);
return axios.get(url, {
......
<script>
import { GlModal } from '@gitlab/ui';
import { __, s__, sprintf } from '~/locale';
import Api from '~/api';
import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue';
import EditMetaControls from './edit_meta_controls.vue';
......@@ -18,6 +19,14 @@ export default {
type: String,
required: true,
},
namespace: {
type: String,
required: true,
},
project: {
type: String,
required: true,
},
},
data() {
return {
......@@ -49,10 +58,19 @@ export default {
};
},
},
mounted() {
this.initTemplates();
},
methods: {
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() {
this.$refs.modal.show();
},
......
......@@ -148,6 +148,8 @@ export default {
<edit-meta-modal
ref="editMetaModal"
:source-path="appData.sourcePath"
:namespace="appData.project.split('/')[0]"
:project="appData.project.split('/')[1]"
@primary="onSubmit"
@hide="onHideModal"
/>
......
......@@ -7,6 +7,14 @@ class Projects::TemplatesController < Projects::ApplicationController
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
template = @template_type.find(params[:key], project)
......
......@@ -403,6 +403,11 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
#
# 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
as: :template,
defaults: { format: 'json' },
......
......@@ -105,6 +105,20 @@ module Gitlab
files.map { |t| { name: t.name } }
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
......
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