ADD web footer companies sort

This commit is contained in:
Jasder 2019-10-26 18:06:52 +08:00
parent b8c67ef297
commit 50047d1e1c
7 changed files with 66 additions and 19 deletions

View File

@ -5,14 +5,17 @@ class WebFooterCompaniesController < ApplicationController
menu_item :info, :only => :info
before_filter :require_admin
before_filter :get_type
before_filter :find_company, :except => [:index, :new, :create]
def index
@companys =
scope =
if @type == WebFooterCompany::RELATION_TYPE[1]
WebFooterCompany.dedicators
else
WebFooterCompany.partners
end
@pages, @companies = paginate scope, :per_page => 25
end
def new
@ -36,18 +39,24 @@ class WebFooterCompaniesController < ApplicationController
end
end
def move
if request.put? and @company.update_attributes(params[:company])
flash[:notice] = l(:notice_successful_update)
redirect_to web_footer_companies_url(type: @type)
else
render :action => 'edit'
end
end
def destroy
@company = WebFooterCompany.find(params[:id])
@company.destroy
redirect_to web_footer_companies_url(type: @type)
end
def edit
@company = WebFooterCompany.find(params[:id])
end
def update
@company = WebFooterCompany.find(params[:id])
if @company.update_attributes(params[:web_footer_company])
flash[:notice] = l(:notice_successful_update)
redirect_to web_footer_companies_url(type: @type)
@ -59,6 +68,10 @@ class WebFooterCompaniesController < ApplicationController
private
def find_company
@company = WebFooterCompany.find(params[:id])
end
def get_type
@type = params[:type].to_s.strip
end

View File

@ -1,13 +1,16 @@
class WebFooterCompany < ActiveRecord::Base
RELATION_TYPE = %w(partner dedicator) # partner: 首页的开源生态模块中的单位; partner与平台的合作单位
attr_accessible :logo_size, :name, :url
# dedicator: 首页技术合作单位; partner与平台的合作单位, opensource: 首页共建开源单位
RELATION_TYPE = %w(partner dedicator opensource)
acts_as_list
attr_accessible :logo_size, :name, :url, :position, :move_to
validates :name, presence: true, length: { maximum: 500 }
validates :url, length: { maximum: 500 },
format: { with: /(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:\/~\+#]*[\w\-\@?^=%&amp;\/~\+#])?/,
message: :invalid
}
scope :partners, -> { where(:key => WebFooterCompany::RELATION_TYPE[0]) }
scope :dedicators, -> { where(:key => WebFooterCompany::RELATION_TYPE[1]) }
scope :partners, -> { desc.where(:key => WebFooterCompany::RELATION_TYPE[0]) }
scope :dedicators, -> { desc.where(:key => WebFooterCompany::RELATION_TYPE[1]) }
scope :desc, -> { order('position ASC') }
end

View File

@ -1,6 +1,6 @@
<div class="navHomepage">
<div class="navHomepageLogo fl">
<%= link_to image_tag("../images/logo_blue.png",width:"51px", height: "45px",class: "mt3"), home_path %>
<%= link_to image_tag("../images/logo_blue.png",width:"51px", height: "45px",class: "mt3"), homes_path %>
</div>
<div class="fl">
<ul>

View File

@ -1,11 +1,30 @@
<div class="contextual"><%= link_to label_new_button_name(@type), new_web_footer_company_path(type: @type),:class => "icon icon-add" %></div>
<h3><%= label_title_name(@type) %></h3>
<div id="logo_link">
<% @companys.each do |company| %>
<span class="footer_logo_link"><%= link_to image_tag(url_to_avatar(company),:size=>"100x30",:alt=>company.name),company.url, :target => "_blank" %></span>
<%= link_to l(:button_edit),edit_web_footer_company_path(company, type: @type) %>
<%= delete_link web_footer_company_path(company, type: @type) %>
<hr/>
<% end %>
</div>
<table class="list">
<thead><tr>
<th>LOGO</th>
<th>单位名称</th>
<th>排序</th>
<th></th>
</tr></thead>
<tbody>
<% @companies.each do |company| %>
<tr class="<%= cycle("odd", "even")%>" align="center">
<td> <%= link_to image_tag(url_to_avatar(company),:size=>"30x30",:alt=>company.name),company.url, :target => "_blank" %> </td>
<td style="vertical-align: middle;"><%= company.name %></td>
<td style="width:15%; vertical-align: middle;">
<%= reorder_links('company', {:action => 'move', :id => company, type: @type}, :put) %>
</td>
<td class="buttons" style="vertical-align: middle;">
<%= link_to l(:button_edit),edit_web_footer_company_path(company, type: @type) %>
<%= delete_link web_footer_company_path(company, type: @type) %>
</td>
</tr>
<% end %>
</tbody>
</table>
<div class="pagination"><%= pagination_links_full @pages %></div>
<% html_title(l(:label_role_plural)) -%>

View File

@ -1309,7 +1309,9 @@ RedmineApp::Application.routes.draw do
match 'permissions', :via => [:get, :post]
end
end
resources :web_footer_companies, :except => :show
resources :web_footer_companies, :except => :show do
put 'move', :on => :member
end
resources :enumerations, :except => :show
match 'enumerations/:type', :to => 'enumerations#index', :via => :get

View File

@ -0,0 +1,9 @@
class AddPositionToWebFooterCompanies < ActiveRecord::Migration
def change
add_column :web_footer_companies, :position, :integer
WebFooterCompany.order(:updated_at).each.with_index(1) do |item, index|
item.update_attributes(position: index)
end
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20191023031103) do
ActiveRecord::Schema.define(:version => 20191026074211) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -2808,6 +2808,7 @@ ActiveRecord::Schema.define(:version => 20191023031103) do
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "key"
t.integer "position"
end
add_index "web_footer_companies", ["key"], :name => "index_web_footer_companies_on_key"