Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
6b4ddf2c
Commit
6b4ddf2c
authored
Feb 11, 2015
by
Marin Jankovski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add admin services templates.
parent
09d3d351
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
162 additions
and
15 deletions
+162
-15
app/controllers/admin/services_controller.rb
app/controllers/admin/services_controller.rb
+51
-0
app/models/project.rb
app/models/project.rb
+18
-3
app/models/project_services/issue_tracker_service.rb
app/models/project_services/issue_tracker_service.rb
+7
-5
app/models/service.rb
app/models/service.rb
+10
-3
app/views/admin/application_settings/_external_issues_tracker_template.html.haml
...tion_settings/_external_issues_tracker_template.html.haml
+22
-0
app/views/admin/services/_form.html.haml
app/views/admin/services/_form.html.haml
+25
-0
app/views/admin/services/edit.html.haml
app/views/admin/services/edit.html.haml
+1
-0
app/views/admin/services/index.html.haml
app/views/admin/services/index.html.haml
+22
-0
config/routes.rb
config/routes.rb
+6
-4
No files found.
app/controllers/admin/services_controller.rb
0 → 100644
View file @
6b4ddf2c
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 @
6b4ddf2c
...
...
@@ -353,14 +353,29 @@ class Project < ActiveRecord::Base
end
def
build_missing_services
services_templates
=
Service
.
where
(
template:
true
)
available_services_names
.
each
do
|
service_name
|
service
=
services
.
find
{
|
service
|
service
.
to_param
==
service_name
}
service
=
find_service
(
services
,
service_name
)
# 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
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
...
...
app/models/project_services/issue_tracker_service.rb
View file @
6b4ddf2c
...
...
@@ -77,12 +77,14 @@ class IssueTrackerService < Service
end
def
set_project_url
if
self
.
project
id
=
self
.
project
.
issues_tracker_id
if
id
issues_tracker
[
'project_url'
].
gsub
(
":issues_tracker_id"
,
id
)
else
issues_tracker
[
'project_url'
]
end
end
issues_tracker
[
'project_url'
]
end
end
app/models/service.rb
View file @
6b4ddf2c
...
...
@@ -25,7 +25,7 @@ class Service < ActiveRecord::Base
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 @@ class Service < ActiveRecord::Base
active
end
def
template?
template
end
def
category
:common
end
...
...
@@ -94,7 +98,10 @@ class Service < ActiveRecord::Base
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 @
6b4ddf2c
-
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 @
6b4ddf2c
%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 @
6b4ddf2c
=
render
'form'
app/views/admin/services/index.html.haml
0 → 100644
View file @
6b4ddf2c
%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 @
6b4ddf2c
...
...
@@ -131,7 +131,9 @@ Gitlab::Application.routes.draw do
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
Markdown
is supported
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