Browse Source

新增:许可证排序字段

pull/347/head
yystopf 1 year ago
parent
commit
bd9ca0439c
5 changed files with 24 additions and 3 deletions
  1. +2
    -2
      app/controllers/admins/project_licenses_controller.rb
  2. +3
    -1
      app/models/license.rb
  3. +12
    -0
      app/views/admins/project_licenses/_form.html.erb
  4. +2
    -0
      app/views/admins/project_licenses/_list.html.erb
  5. +5
    -0
      db/migrate/20240809030936_add_position_to_licenses.rb

+ 2
- 2
app/controllers/admins/project_licenses_controller.rb View File

@@ -7,7 +7,7 @@ class Admins::ProjectLicensesController < Admins::BaseController
sort_by = License.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
q = License.ransack(name_cont: params[:search])
project_licenses = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
project_licenses = q.result(distinct: true).reorder("#{sort_by} #{sort_direction}")
@project_licenses = paginate(project_licenses)
end

@@ -96,7 +96,7 @@ class Admins::ProjectLicensesController < Admins::BaseController
end

def license_params
params.require(:license).permit(:name,:content)
params.require(:license).permit(:name,:content,:position)
end

# def validate_params


+ 3
- 1
app/models/license.rb View File

@@ -7,10 +7,12 @@
# content :text(65535)
# created_at :datetime not null
# updated_at :datetime not null
# is_secret :boolean default("0")
# position :integer default("0")
#

class License < ApplicationRecord
default_scope { order(position: :desc) }

include Projectable

validates :name, :content, presence: true


+ 12
- 0
app/views/admins/project_licenses/_form.html.erb View File

@@ -30,6 +30,18 @@



</div>
<div class="form-group">
<label>
<span class="color-grey-6 pt10">
排序等级
<span class="ml10 color-orange mr20">*</span>
</span>
</label>
<div class="mt-10">
<%= f.number_field :position, class: "form-control",placeholder: ""%>
</div>

</div>
<div class="form-group">
<%= f.submit "确认", class: "btn btn-primary submit-btn" %>


+ 2
- 0
app/views/admins/project_licenses/_list.html.erb View File

@@ -4,6 +4,7 @@
<th width="5%">序号</th>
<th width="15%">名称</th>
<th width="35%">简介</th>
<th width="10%"><%= sort_tag('排序等级', name: 'position', path: admins_project_licenses_path) %></th>
<%
=begin%>
<th width="10%"><%= sort_tag('项目数', name: 'projects_count', path: admins_project_licenses_path) %></th>
@@ -24,6 +25,7 @@
<td>
<%= project_license.content.to_s.truncate(200) %>
</td>
<td><%= project_license.position %></td>
<%
=begin%>
<td><%= project_license.projects_count %></td>


+ 5
- 0
db/migrate/20240809030936_add_position_to_licenses.rb View File

@@ -0,0 +1,5 @@
class AddPositionToLicenses < ActiveRecord::Migration[5.2]
def change
add_column :licenses, :position, :integer, default: 0
end
end

Loading…
Cancel
Save