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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
57d00130
Commit
57d00130
authored
Sep 03, 2015
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CRUD for admin labels
parent
28219ea9
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
275 additions
and
39 deletions
+275
-39
app/controllers/admin/labels_controller.rb
app/controllers/admin/labels_controller.rb
+59
-0
app/models/label.rb
app/models/label.rb
+7
-1
app/views/admin/labels/_form.html.haml
app/views/admin/labels/_form.html.haml
+35
-0
app/views/admin/labels/_label.html.haml
app/views/admin/labels/_label.html.haml
+5
-0
app/views/admin/labels/destroy.js.haml
app/views/admin/labels/destroy.js.haml
+2
-0
app/views/admin/labels/edit.html.haml
app/views/admin/labels/edit.html.haml
+9
-0
app/views/admin/labels/index.html.haml
app/views/admin/labels/index.html.haml
+16
-0
app/views/admin/labels/new.html.haml
app/views/admin/labels/new.html.haml
+7
-0
app/views/layouts/nav/_admin.html.haml
app/views/layouts/nav/_admin.html.haml
+6
-0
config/routes.rb
config/routes.rb
+2
-0
db/migrate/20150902001023_add_template_to_label.rb
db/migrate/20150902001023_add_template_to_label.rb
+5
-0
db/schema.rb
db/schema.rb
+122
-38
No files found.
app/controllers/admin/labels_controller.rb
0 → 100644
View file @
57d00130
class
Admin::LabelsController
<
Admin
::
ApplicationController
before_action
:set_label
,
only:
[
:show
,
:edit
,
:update
,
:destroy
]
def
index
@labels
=
Label
.
templates
.
page
(
params
[
:page
]).
per
(
PER_PAGE
)
end
def
show
end
def
new
@label
=
Label
.
new
end
def
edit
end
def
create
@label
=
Label
.
new
(
label_params
)
@label
.
template
=
true
if
@label
.
save
redirect_to
admin_labels_url
,
notice:
"Label was created"
else
render
:new
end
end
def
update
if
@label
.
update
(
label_params
)
redirect_to
admin_labels_path
,
notice:
'label was successfully updated.'
else
render
:edit
end
end
def
destroy
@label
.
destroy
@labels
=
Label
.
templates
respond_to
do
|
format
|
format
.
html
do
redirect_to
(
admin_labels_path
,
notice:
'Label was removed'
)
end
format
.
js
end
end
private
def
set_label
@label
=
Label
.
find
(
params
[
:id
])
end
def
label_params
params
[
:label
].
permit
(
:title
,
:color
)
end
end
app/models/label.rb
View file @
57d00130
...
...
@@ -24,7 +24,7 @@ class Label < ActiveRecord::Base
validates
:color
,
format:
{
with:
/\A#[0-9A-Fa-f]{6}\Z/
},
allow_blank:
false
validates
:project
,
presence:
true
validates
:project
,
presence:
true
,
unless:
Proc
.
new
{
|
service
|
service
.
template?
}
# Don't allow '?', '&', and ',' for label titles
validates
:title
,
...
...
@@ -34,6 +34,8 @@ class Label < ActiveRecord::Base
default_scope
{
order
(
title: :asc
)
}
scope
:templates
,
->
{
where
(
template:
true
)
}
alias_attribute
:name
,
:title
def
self
.
reference_prefix
...
...
@@ -78,4 +80,8 @@ class Label < ActiveRecord::Base
def
open_issues_count
issues
.
opened
.
count
end
def
template?
template
end
end
app/views/admin/labels/_form.html.haml
0 → 100644
View file @
57d00130
=
form_for
[
:admin
,
@label
],
html:
{
class:
'form-horizontal label-form js-requires-input'
}
do
|
f
|
-
if
@label
.
errors
.
any?
.row
.col-sm-offset-2.col-sm-10
.alert.alert-danger
-
@label
.
errors
.
full_messages
.
each
do
|
msg
|
%span
=
msg
%br
.form-group
=
f
.
label
:title
,
class:
'control-label'
.col-sm-10
=
f
.
text_field
:title
,
class:
"form-control"
,
required:
true
.form-group
=
f
.
label
:color
,
"Background Color"
,
class:
'control-label'
.col-sm-10
.input-group
.input-group-addon.label-color-preview
=
f
.
color_field
:color
,
class:
"form-control"
.help-block
Choose any color.
%br
Or you can choose one of suggested colors below
.suggest-colors
-
suggested_colors
.
each
do
|
color
|
=
link_to
'#'
,
style:
"background-color:
#{
color
}
"
,
data:
{
color:
color
}
do
.form-actions
=
f
.
submit
'Save'
,
class:
'btn btn-save js-save-button'
=
link_to
"Cancel"
,
admin_labels_path
,
class:
'btn btn-cancel'
:coffeescript
new Labels
app/views/admin/labels/_label.html.haml
0 → 100644
View file @
57d00130
%li
{
id:
dom_id
(
label
)}
=
render_colored_label
(
label
)
.pull-right
=
link_to
'Edit'
,
edit_admin_label_path
(
label
),
class:
'btn btn-sm'
=
link_to
'Remove'
,
admin_label_path
(
label
),
class:
'btn btn-sm btn-remove remove-row'
,
method: :delete
,
remote:
true
,
data:
{
confirm:
"Remove this label? Are you sure?"
}
app/views/admin/labels/destroy.js.haml
0 → 100644
View file @
57d00130
-
if
@labels
.
size
==
0
$('.labels').load(document.URL + ' .light-well').hide().fadeIn(1000)
app/views/admin/labels/edit.html.haml
0 → 100644
View file @
57d00130
-
page_title
"Edit"
,
@label
.
name
,
"Labels"
%h3
Edit label
%span
.light
#{
@label
.
name
}
.back-link
=
link_to
admin_labels_path
do
←
To labels list
%hr
=
render
'form'
app/views/admin/labels/index.html.haml
0 → 100644
View file @
57d00130
-
page_title
"Labels"
=
link_to
new_admin_label_path
,
class:
"pull-right btn btn-new"
do
New label
%h3
.page-title
Labels
%hr
.labels
-
if
@labels
.
present?
%ul
.bordered-list.manage-labels-list
=
render
@labels
=
paginate
@labels
,
theme:
'gitlab'
-
else
.light-well
.nothing-here-block
There are no any labels yet
\ No newline at end of file
app/views/admin/labels/new.html.haml
0 → 100644
View file @
57d00130
-
page_title
"New Label"
%h3
New label
.back-link
=
link_to
admin_labels_path
do
←
To labels list
%hr
=
render
'form'
app/views/layouts/nav/_admin.html.haml
View file @
57d00130
...
...
@@ -57,6 +57,12 @@
%span
Service Templates
=
nav_link
(
controller: :labels
)
do
=
link_to
admin_labels_path
,
title:
'Labels'
,
data:
{
placement:
'right'
}
do
=
icon
(
'tags fw'
)
%span
Labels
=
nav_link
(
controller: :abuse_reports
)
do
=
link_to
admin_abuse_reports_path
,
title:
"Abuse reports"
do
=
icon
(
'exclamation-circle fw'
)
...
...
config/routes.rb
View file @
57d00130
...
...
@@ -201,6 +201,8 @@ Gitlab::Application.routes.draw do
resources
:services
end
resources
:labels
root
to:
'dashboard#index'
end
...
...
db/migrate/20150902001023_add_template_to_label.rb
0 → 100644
View file @
57d00130
class
AddTemplateToLabel
<
ActiveRecord
::
Migration
def
change
add_column
:labels
,
:template
,
:boolean
,
default:
false
end
end
\ No newline at end of file
db/schema.rb
View file @
57d00130
This diff is collapsed.
Click to expand it.
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