| @@ -7,7 +7,7 @@ class Admins::ProjectLicensesController < Admins::BaseController | |||||
| sort_by = License.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at' | 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' | sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc' | ||||
| q = License.ransack(name_cont: params[:search]) | 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) | @project_licenses = paginate(project_licenses) | ||||
| end | end | ||||
| @@ -96,7 +96,7 @@ class Admins::ProjectLicensesController < Admins::BaseController | |||||
| end | end | ||||
| def license_params | def license_params | ||||
| params.require(:license).permit(:name,:content) | |||||
| params.require(:license).permit(:name,:content,:position) | |||||
| end | end | ||||
| # def validate_params | # def validate_params | ||||
| @@ -7,10 +7,12 @@ | |||||
| # content :text(65535) | # content :text(65535) | ||||
| # created_at :datetime not null | # created_at :datetime not null | ||||
| # updated_at :datetime not null | # updated_at :datetime not null | ||||
| # is_secret :boolean default("0") | |||||
| # position :integer default("0") | |||||
| # | # | ||||
| class License < ApplicationRecord | class License < ApplicationRecord | ||||
| default_scope { order(position: :desc) } | |||||
| include Projectable | include Projectable | ||||
| validates :name, :content, presence: true | validates :name, :content, presence: true | ||||
| @@ -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> | ||||
| <div class="form-group"> | <div class="form-group"> | ||||
| <%= f.submit "确认", class: "btn btn-primary submit-btn" %> | <%= f.submit "确认", class: "btn btn-primary submit-btn" %> | ||||
| @@ -4,6 +4,7 @@ | |||||
| <th width="5%">序号</th> | <th width="5%">序号</th> | ||||
| <th width="15%">名称</th> | <th width="15%">名称</th> | ||||
| <th width="35%">简介</th> | <th width="35%">简介</th> | ||||
| <th width="10%"><%= sort_tag('排序等级', name: 'position', path: admins_project_licenses_path) %></th> | |||||
| <% | <% | ||||
| =begin%> | =begin%> | ||||
| <th width="10%"><%= sort_tag('项目数', name: 'projects_count', path: admins_project_licenses_path) %></th> | <th width="10%"><%= sort_tag('项目数', name: 'projects_count', path: admins_project_licenses_path) %></th> | ||||
| @@ -24,6 +25,7 @@ | |||||
| <td> | <td> | ||||
| <%= project_license.content.to_s.truncate(200) %> | <%= project_license.content.to_s.truncate(200) %> | ||||
| </td> | </td> | ||||
| <td><%= project_license.position %></td> | |||||
| <% | <% | ||||
| =begin%> | =begin%> | ||||
| <td><%= project_license.projects_count %></td> | <td><%= project_license.projects_count %></td> | ||||
| @@ -0,0 +1,5 @@ | |||||
| class AddPositionToLicenses < ActiveRecord::Migration[5.2] | |||||
| def change | |||||
| add_column :licenses, :position, :integer, default: 0 | |||||
| end | |||||
| end | |||||