Skip to content

Commit 1f1b405

Browse files
authored
ROAD-536 Add VersionJump model and admin integration (#299)
* ROAD-536 Add VersionJump model and admin integration * ROAD-536 Remove uneeded partial * ROAD-536 Add version jump uniqueness validation * ROAD-536 Fix css issue, add more info in admin panel
1 parent 96ba4f8 commit 1f1b405

31 files changed

+202
-17
lines changed

app/assets/stylesheets/3-atoms/_badges.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
font-size: 11px;
1111

1212
&.archived {
13-
background-color: rgba(29,78,216,0.2);
13+
background-color: rgba(29, 78, 216, 0.2);
1414
border-color: #1d4ed8;
1515
}
1616

@@ -19,4 +19,7 @@
1919
border-color: #d77e72;
2020
}
2121

22+
&.version-jump {
23+
background-color: #57ce81;
24+
}
2225
}

app/assets/stylesheets/3-atoms/_forms.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ input[type="checkbox"] {
7070
}
7171

7272
.field,
73+
.select,
7374
.actions {
7475
margin-bottom: 10px;
7576
}

app/controllers/madmin/application_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Madmin
22
class ApplicationController < Madmin::BaseController
3+
include Pundit::Authorization
34
before_action :ensure_admin
45

56
def ensure_admin
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Madmin
2+
class VersionJumpsController < Madmin::ResourceController
3+
end
4+
end

app/controllers/projects_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def toggle_locked
4343
end
4444

4545
def new_clone
46-
@original = Project.includes(:projects, stories: :estimates).find(params[:id])
46+
@original = Project.includes(:projects, :version_jump, stories: :estimates).find(params[:id])
4747
end
4848

4949
def clone
@@ -111,11 +111,11 @@ def find_project
111111
end
112112

113113
def projects_params
114-
params.require(:project).permit(:title, :status, :parent_id)
114+
params.require(:project).permit(:title, :status, :parent_id, :version_jump_id)
115115
end
116116

117117
def clone_params
118-
params.require(:project).permit(:title, :parent_id)
118+
params.require(:project).permit(:title, :parent_id, :version_jump_id)
119119
end
120120

121121
def parent_id

app/helpers/projects_helper.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ def link_unless_archived(project, text, url, classes: nil, method: :get, remote:
1717
end
1818
end
1919

20+
def version_jump_badge(project)
21+
return "" unless project.version_jump
22+
23+
jump = project.version_jump
24+
content_tag(:span, jump.to_label, class: "status-badge version-jump")
25+
end
26+
2027
private
2128

2229
def text_content(icon, text)

app/madmin/resources/project_resource.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class ProjectResource < Madmin::Resource
1010
attribute :users
1111
attribute :parent
1212
attribute :projects
13+
attribute :version_jump
1314

1415
def self.display_name(record)
1516
record.title.truncate(20)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class VersionJumpResource < Madmin::Resource
2+
# Attributes
3+
attribute :id, form: false
4+
attribute :technology
5+
attribute :initial_version
6+
attribute :target_version
7+
8+
# Associations
9+
attribute :projects, form: false
10+
11+
# Uncomment this to customize the display name of records in the admin area.
12+
def self.display_name(record)
13+
record.to_label
14+
end
15+
16+
# Uncomment this to customize the default sort column and direction.
17+
# def self.default_sort_column
18+
# "created_at"
19+
# end
20+
#
21+
# def self.default_sort_direction
22+
# "desc"
23+
# end
24+
end

app/models/project.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class Project < ApplicationRecord
44
has_many :stories
55
has_many :estimates, through: :stories
66
has_many :users, through: :estimates
7+
belongs_to :version_jump, optional: true
78

89
belongs_to :parent, class_name: "Project", required: false
910
has_many :projects, class_name: "Project", foreign_key: :parent_id, dependent: :destroy
@@ -52,6 +53,10 @@ def archived?
5253
status == "archived"
5354
end
5455

56+
def locked?
57+
locked_at.present?
58+
end
59+
5560
def breadcrumb
5661
parent.present? ? "#{parent.breadcrumb} » #{title}" : title
5762
end

app/models/version_jump.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class VersionJump < ApplicationRecord
2+
has_many :projects
3+
4+
validates :technology, :initial_version, :target_version, presence: true
5+
validates :technology, uniqueness: {scope: [:initial_version, :target_version]}
6+
7+
def to_label
8+
"#{technology} / #{initial_version} - #{target_version}"
9+
end
10+
end

0 commit comments

Comments
 (0)