Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
cc0bdbfa43a8
Commit
cc0bdbfa
authored
Feb 11, 2015
by
Marin Jankovski
Browse files
Add admin services templates.
parent
ed7909ccf160
Changes
9
Hide whitespace changes
Inline
Side-by-side
app/controllers/admin/services_controller.rb
0 → 100644
View file @
cc0bdbfa
class
Admin::ServicesController
<
Admin
::
ApplicationController
before_filter
:service
,
only:
[
:edit
,
:update
]
def
index
@services
=
services_templates
end
def
edit
unless
service
.
present?
redirect_to
admin_application_settings_services_path
,
alert:
"Service is unknown or it doesn't exist"
end
end
def
update
if
service
.
update_attributes
(
application_services_params
[
:service
])
redirect_to
admin_application_settings_services_path
,
notice:
'Application settings saved successfully'
else
render
:edit
end
end
private
def
services_templates
templates
=
[]
allowed_templates
.
each
do
|
service
|
service_template
=
service
.
constantize
templates
<<
service_template
.
where
(
template:
true
).
first_or_create
end
templates
end
def
allowed_templates
%w( JiraService RedmineService CustomIssueTrackerService )
end
def
service
@service
||=
Service
.
where
(
id:
params
[
:id
],
template:
true
).
first
end
def
application_services_params
params
.
permit
(
:id
,
service:
[
:title
,
:project_url
,
:description
,
:issues_url
,
:new_issue_url
])
end
end
app/models/project.rb
View file @
cc0bdbfa
...
...
@@ -353,4 +353,6 @@
end
def
build_missing_services
services_templates
=
Service
.
where
(
template:
true
)
available_services_names
.
each
do
|
service_name
|
...
...
@@ -356,4 +358,4 @@
available_services_names
.
each
do
|
service_name
|
service
=
services
.
find
{
|
service
|
service
.
to_param
==
service_name
}
service
=
find_
service
(
service
s
,
service_name
)
# If service is available but missing in db
...
...
@@ -358,7 +360,16 @@
# If service is available but missing in db
# we should create an instance. Ex `create_gitlab_ci_service`
service
=
self
.
send
:"create_
#{
service_name
}
_service"
if
service
.
nil?
if
service
.
nil?
# We should check if template for the service exists
template
=
find_service
(
services_templates
,
service_name
)
if
template
.
nil?
# If no template, we should create an instance. Ex `create_gitlab_ci_service`
service
=
self
.
send
:"create_
#{
service_name
}
_service"
else
Service
.
create_from_template
(
self
.
id
,
template
)
end
end
end
end
...
...
@@ -362,6 +373,10 @@
end
end
def
find_service
(
list
,
name
)
list
.
find
{
|
service
|
service
.
to_param
==
name
}
end
def
available_services_names
%w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla asana
emails_on_push gemnasium slack pushover buildbox bamboo teamcity jira redmine custom_issue_tracker)
...
...
app/models/project_services/issue_tracker_service.rb
View file @
cc0bdbfa
...
...
@@ -77,5 +77,6 @@
end
def
set_project_url
id
=
self
.
project
.
issues_tracker_id
if
self
.
project
id
=
self
.
project
.
issues_tracker_id
...
...
@@ -81,6 +82,5 @@
if
id
issues_tracker
[
'project_url'
].
gsub
(
":issues_tracker_id"
,
id
)
else
issues_tracker
[
'project_url'
]
if
id
issues_tracker
[
'project_url'
].
gsub
(
":issues_tracker_id"
,
id
)
end
end
...
...
@@ -86,3 +86,5 @@
end
issues_tracker
[
'project_url'
]
end
end
app/models/service.rb
View file @
cc0bdbfa
...
...
@@ -25,7 +25,7 @@
belongs_to
:project
has_one
:service_hook
validates
:project_id
,
presence:
true
validates
:project_id
,
presence:
true
,
unless:
Proc
.
new
{
|
service
|
service
.
template?
}
scope
:visible
,
->
{
where
.
not
(
type:
'GitlabIssueTrackerService'
)
}
...
...
@@ -33,6 +33,10 @@
active
end
def
template?
template
end
def
category
:common
end
...
...
@@ -94,7 +98,10 @@
self
.
category
==
:issue_tracker
end
def
self
.
issue_tracker_service_list
Service
.
select
(
&
:issue_tracker?
).
map
{
|
s
|
s
.
to_param
}
def
self
.
create_from_template
(
project_id
,
template
)
service
=
template
.
dup
service
.
template
=
false
service
.
project_id
=
project_id
service
if
service
.
save
end
end
app/views/admin/application_settings/_external_issues_tracker_template.html.haml
0 → 100644
View file @
cc0bdbfa
-
service
.
fields
.
each
do
|
field
|
TOPD
/ - name = field[:name]
/ - value = "V"#@service.send(name) unless field[:type] == 'password'
/ - type = field[:type]
/ - placeholder = field[:placeholder]
/ - choices = field[:choices]
/ - default_choice = field[:default_choice]
/ .form-group
/ = f.label name, class: "control-label"
/ .col-sm-10
/ - if type == 'text'
/ = f.text_field name, class: "form-control", placeholder: placeholder
/ - elsif type == 'textarea'
/ = f.text_area name, rows: 5, class: "form-control", placeholder: placeholder
/ - elsif type == 'checkbox'
/ = f.check_box name
/ - elsif type == 'select'
/ = f.select name, options_for_select(choices, value ? value : default_choice), {}, { class: "form-control" }
/ - elsif type == 'password'
/ = f.password_field name, class: 'form-control'
app/views/admin/services/_form.html.haml
0 → 100644
View file @
cc0bdbfa
%h3
.page-title
=
@service
.
title
=
boolean_to_icon
@service
.
activated?
%p
#{
@service
.
description
}
template
=
form_for
:service
,
url:
admin_application_settings_service_path
,
method: :put
,
html:
{
class:
'form-horizontal fieldset-form'
}
do
|
f
|
-
if
@service
.
errors
.
any?
#error_explanation
.alert.alert-danger
-
@service
.
errors
.
full_messages
.
each
do
|
msg
|
%p
=
msg
-
@service
.
fields
.
each
do
|
field
|
-
name
=
field
[
:name
]
-
type
=
field
[
:type
]
-
placeholder
=
field
[
:placeholder
]
.form-group
=
f
.
label
name
,
class:
"control-label"
.col-sm-10
=
f
.
text_field
name
,
class:
"form-control"
,
placeholder:
placeholder
.form-actions
=
f
.
submit
'Save'
,
class:
'btn btn-save'
app/views/admin/services/edit.html.haml
0 → 100644
View file @
cc0bdbfa
=
render
'form'
app/views/admin/services/index.html.haml
0 → 100644
View file @
cc0bdbfa
%h3
.page-title
Service templates
%p
.light
Service template allows you to set default values for project services
%table
.table
%thead
%tr
%th
%th
Service
%th
Desription
%th
Last edit
-
@services
.
sort_by
(
&
:title
).
each
do
|
service
|
%tr
%td
=
icon
(
"copy"
,
class:
'clgray'
)
%td
=
link_to
edit_admin_application_settings_service_path
(
service
.
id
)
do
%strong
=
service
.
title
%td
=
service
.
description
%td
.light
=
time_ago_in_words
service
.
updated_at
ago
config/routes.rb
View file @
cc0bdbfa
...
...
@@ -51,7 +51,7 @@
end
get
'/s/:username'
=>
'snippets#user_index'
,
as: :user_snippets
,
constraints:
{
username:
/.*/
}
#
# Import
#
...
...
@@ -68,8 +68,8 @@
get
:jobs
end
end
#
# Explore area
...
...
@@ -131,7 +131,9 @@
end
end
resource
:application_settings
,
only:
[
:show
,
:update
]
resource
:application_settings
,
only:
[
:show
,
:update
]
do
resources
:services
end
root
to:
'dashboard#index'
end
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment