添加超级管理员控制首页热门项目排序问题
This commit is contained in:
parent
fbc4cd1cf1
commit
cc4bf3b328
|
@ -244,6 +244,7 @@ class AdminController < ApplicationController
|
|||
@first_page.web_title = params[:web_title]
|
||||
@first_page.description = params[:description]
|
||||
@first_page.title = params[:title]
|
||||
@first_page.sort_type = params[:sort_type]
|
||||
if @first_page.save
|
||||
respond_to do |format|
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
|
|
|
@ -17,12 +17,40 @@
|
|||
|
||||
class WelcomeController < ApplicationController
|
||||
include ApplicationHelper
|
||||
include WelcomeHelper
|
||||
caches_action :robots
|
||||
# before_filter :fake, :only => [:index, :course]
|
||||
before_filter :entry_select, :only => [:index]
|
||||
|
||||
def index
|
||||
@first_page = FirstPage.where("page_type = 'project'").first
|
||||
@hot_projects = find_miracle_project(10, 3)
|
||||
@hot_projects_ids = []
|
||||
@hot_projects.each do |p|
|
||||
@hot_projects_ids << p
|
||||
end
|
||||
@projects_all = Project.active.visible.
|
||||
joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id").
|
||||
where("#{Project.table_name}.project_type = ? and #{Project.table_name}.id in (?)", Project::ProjectType_project,@hot_projects_ids)
|
||||
|
||||
case @first_page.sort_type
|
||||
when 0
|
||||
@projects = @projects_all.order("created_on desc")
|
||||
when 1
|
||||
@projects = @projects_all.order("grade desc")
|
||||
when 2
|
||||
@projects = @projects_all.order("watchers_count desc")
|
||||
|
||||
#gcm
|
||||
#when '3'
|
||||
#@projects=desc_sort_course_by_avtivity(@project_activity_count_array,@project_all_array)
|
||||
# @projects=handle_project @projects_all,@project_activity_count
|
||||
# @s_type = 3
|
||||
# @projects = @projects[@project_pages.offset, @project_pages.per_page]
|
||||
|
||||
else
|
||||
@projects = @projects_all.order("grade desc")
|
||||
end
|
||||
end
|
||||
|
||||
def robots
|
||||
|
|
|
@ -208,7 +208,7 @@ module WelcomeHelper
|
|||
#c1 = find_new_project(sum).to_a.dup
|
||||
#c2 = find_all_hot_project(sum).to_a.dup
|
||||
#(c2.take(sum-max)+c1.take(max)).take(sum)
|
||||
find_all_hot_project(sum).to_a.dup
|
||||
find_all_hot_project(sum).dup#.to_a.dup
|
||||
end
|
||||
|
||||
def find_new_course limit=15
|
||||
|
@ -433,7 +433,7 @@ module WelcomeHelper
|
|||
# FROM projects AS p LEFT OUTER JOIN (
|
||||
# SELECT project_id,grade FROM project_statuses
|
||||
# WHERE project_type = #{project_type} ORDER BY #{order_by} LIMIT #{limit} ) AS t ON p.id = t.project_id ")
|
||||
Project.visible.joins(:project_status).where("#{Project.table_name}.project_type = ?", project_type).order(order_by).limit(limit).all
|
||||
Project.visible.joins(:project_status).where("#{Project.table_name}.project_type = ?", project_type).order(order_by).limit(limit)#.all
|
||||
end
|
||||
|
||||
def sort_bid_by_hot_rails reward_type, limit = 10
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class FirstPage < ActiveRecord::Base
|
||||
attr_accessible :description, :title, :web_title,:page_type
|
||||
validates_presence_of :web_title, :title, :description,:page_type
|
||||
validates_presence_of :web_title, :title, :description,:page_type,:sort_type
|
||||
validates_length_of :web_title,:title, maximum: 30
|
||||
validates_length_of :description, maximum: 100
|
||||
end
|
||||
|
|
|
@ -28,6 +28,14 @@
|
|||
<label for='description' style="vertical-align: top"> <%= l(:label_site_description)%>:</label>
|
||||
<%= text_area_tag 'description',@first_page.description,:rows => 8, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %>
|
||||
</p>
|
||||
<p style="margin-left:60px;padding-right: 20px;">
|
||||
<label for='sort_type' style="vertical-align: top"> <%= l(:label_sort_type)%>:</label>
|
||||
<select name="sort_type" id="sort_type" style="font-size:small;width:496px;margin-left:80px;">
|
||||
<option value="1" <%= "selected=selected" if @first_page.sort_type == 1 %>><%= l(:label_sort_by_active) %></option>
|
||||
<option value="2" <%= "selected=selected" if @first_page.sort_type == 2 %>><%= l(:label_sort_by_influence) %></option>
|
||||
<option value="0" <%= "selected=selected" if @first_page.sort_type == 0 %>><%= l(:label_sort_by_time) %></option>
|
||||
</select>
|
||||
</p>
|
||||
|
||||
<%= submit_tag l(:button_save), :class => "small", :name => nil %>
|
||||
<% end %>
|
||||
|
|
|
@ -60,8 +60,8 @@
|
|||
<span style="margin-top: -20px;float: right; display: block;"><%= link_to "更多>>", { :controller => 'projects', :action => 'index', :project_type => 0, :host => Setting.project_domain}, :target => "_blank" %></span>
|
||||
<div class="d-p-projectlist-box">
|
||||
<ul class="d-p-projectlist">
|
||||
<% projects = find_miracle_project(10, 3) %>
|
||||
<% projects.map do |project| %>
|
||||
<% #projects = find_miracle_project(10, 3) %>
|
||||
<% @projects.map do |project| %>
|
||||
<!--<%# cache cache_key_for_project(project) do %> -->
|
||||
<li style="position:relative;height:6em;" class='<%= cycle("odd", "even") %>'>
|
||||
<div style="float: left;">
|
||||
|
|
|
@ -572,6 +572,7 @@ zh:
|
|||
label_site_title: 网站标题
|
||||
label_site_description: 网站简介
|
||||
label_site_image: 简介图片
|
||||
label_sort_type: 热门项目排序方式
|
||||
#by young
|
||||
label_requirement: 需求
|
||||
label_new_course: 课程列表
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddColumnForFirstPage < ActiveRecord::Migration
|
||||
def change
|
||||
add_column("first_pages","sort_type",:integer)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
class SetSortType < ActiveRecord::Migration
|
||||
def change
|
||||
FirstPage.all.each do |fp|
|
||||
fp.sort_type = 1
|
||||
fp.save
|
||||
end
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20140714081030) do
|
||||
ActiveRecord::Schema.define(:version => 20140716021558) do
|
||||
|
||||
create_table "activities", :force => true do |t|
|
||||
t.integer "act_id", :null => false
|
||||
|
@ -415,6 +415,7 @@ ActiveRecord::Schema.define(:version => 20140714081030) do
|
|||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "page_type"
|
||||
t.integer "sort_type"
|
||||
end
|
||||
|
||||
create_table "forums", :force => true do |t|
|
||||
|
|
Loading…
Reference in New Issue