-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ROAD-536 Add VersionJump model and admin integration #299
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ input[type="checkbox"] { | |
} | ||
|
||
.field, | ||
.select, | ||
.actions { | ||
margin-bottom: 10px; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Madmin | ||
class VersionJumpsController < Madmin::ResourceController | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class VersionJumpResource < Madmin::Resource | ||
# Attributes | ||
attribute :id, form: false | ||
attribute :technology | ||
attribute :initial_version | ||
attribute :target_version | ||
|
||
# Associations | ||
attribute :projects, form: false | ||
|
||
# Uncomment this to customize the display name of records in the admin area. | ||
def self.display_name(record) | ||
record.to_label | ||
end | ||
|
||
# Uncomment this to customize the default sort column and direction. | ||
# def self.default_sort_column | ||
# "created_at" | ||
# end | ||
# | ||
# def self.default_sort_direction | ||
# "desc" | ||
# end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ class Project < ApplicationRecord | |
has_many :stories | ||
has_many :estimates, through: :stories | ||
has_many :users, through: :estimates | ||
belongs_to :version_jump, optional: true | ||
|
||
belongs_to :parent, class_name: "Project", required: false | ||
has_many :projects, class_name: "Project", foreign_key: :parent_id, dependent: :destroy | ||
|
@@ -52,6 +53,10 @@ def archived? | |
status == "archived" | ||
end | ||
|
||
def locked? | ||
locked_at.present? | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can revert this change, but was really simple to add (I updated some code that was using |
||
|
||
def breadcrumb | ||
parent.present? ? "#{parent.breadcrumb} » #{title}" : title | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class VersionJump < ApplicationRecord | ||
has_many :projects | ||
|
||
validates :technology, :initial_version, :target_version, presence: true | ||
validates :technology, uniqueness: {scope: [:initial_version, :target_version]} | ||
|
||
def to_label | ||
"#{technology} / #{initial_version} - #{target_version}" | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class EstimatePolicy < ApplicationPolicy | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class StoryPolicy < ApplicationPolicy | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to create all the policies to be able to use this Pundit feature in the admin panel |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class UserPolicy < ApplicationPolicy | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class VersionJumpPolicy < ApplicationPolicy | ||
def update? | ||
true | ||
end | ||
|
||
def create? | ||
true | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,12 @@ | |
</svg> | ||
<% end %> | ||
</form> | ||
|
||
<% if policy(resource).create? %> | ||
<%= link_to resource.new_path, class: "bg-white hover:bg-gray-100 text-gray-800 font-semibold py-2 px-4 border border-gray-400 rounded shadow" do %> | ||
New <span class="hidden md:inline"><%= resource.friendly_name %></span> | ||
<% end %> | ||
<% end %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took this back from the original gem There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the original gem? madmin? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, sorry, from this file of madmin https://github.com/excid3/madmin/blob/14599a85f0fb687d6ad9bf30ee38db9f8b1abe3c/app/views/madmin/application/index.html.erb#L15 |
||
</div> | ||
</div> | ||
|
||
|
@@ -48,7 +54,9 @@ | |
|
||
<td class="px-4 py-2 text-center"> | ||
<%= link_to "View", resource.show_path(record), class: "text-indigo-500" %> | ||
<%# = link_to "Edit", resource.edit_path(record), class: "text-indigo-500" %> | ||
<% if policy(resource).update? %> | ||
<%= link_to "Edit", resource.edit_path(record), class: "text-indigo-500" %> | ||
<% end %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateVersionJumps < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :version_jumps do |t| | ||
t.string :technology | ||
t.string :initial_version | ||
t.string :target_version | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddVersionJumpToProjects < ActiveRecord::Migration[7.0] | ||
def change | ||
add_reference :projects, :version_jump | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FactoryBot.define do | ||
factory :version_jump do | ||
sequence(:technology) { |n| ["Rails", "Ruby", "Node", "React"].sample + n.to_s } | ||
initial_version { ["2.3", "3.0", "3.1", "3.2", "4.0", "4.1", "4.2"].sample } | ||
target_version { ["5.0", "5.1", "5.2", "6.0", "6.1", "7.0"].sample } | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can/should we get rid of these comments if we aren't customizing the
default_sort_column
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was already there commented out in the other resources. Not sure why that was not removed before, so I'd say to note remove it just for this resource (maybe some low-priority story can be about cleaning up these comments, I don't want to change files that I don't need to change for a comment)