修改课程活跃度排序方式,解决课程列表文件链接错误
This commit is contained in:
parent
22ce616a78
commit
adf8a7bc92
|
@ -130,7 +130,7 @@ class ProjectsController < ApplicationController
|
||||||
|
|
||||||
|
|
||||||
@offset, @limit = api_offset_and_limit({:limit => 10})
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
||||||
@projects_status = ProjectStatus.visible.where("project_type <> ? or project_type is null", 1)
|
@projects_status = ProjectStatus.visible.where("project_statuses.project_type <> ? or project_statuses.project_type is null", 1)
|
||||||
# @projects_status = ProjectStatus.visible
|
# @projects_status = ProjectStatus.visible
|
||||||
# @projects_status.each do |project|
|
# @projects_status.each do |project|
|
||||||
# if Project.visible.find_by_id("#{project.project_id}")
|
# if Project.visible.find_by_id("#{project.project_id}")
|
||||||
|
@ -174,13 +174,13 @@ class ProjectsController < ApplicationController
|
||||||
when '0'
|
when '0'
|
||||||
@offset ||= @project_pages.reverse_offset
|
@offset ||= @project_pages.reverse_offset
|
||||||
unless @offset == 0
|
unless @offset == 0
|
||||||
@projects_status = @projects_status.offset(@offset).limit(@limit).all.reverse
|
@projects_status = @projects_status.joins(:project).reorder("projects.created_on").offset(@offset).limit(@limit).all.reverse
|
||||||
else
|
else
|
||||||
limit = @project_count % @limit
|
limit = @project_count % @limit
|
||||||
if limit == 0
|
if limit == 0
|
||||||
limit = @limit
|
limit = @limit
|
||||||
end
|
end
|
||||||
@projects_status = @projects_status.offset(@offset).limit(limit).all.reverse
|
@projects_status = @projects_status.joins(:project).reorder("projects.created_on").offset(@offset).limit(@limit).all.reverse
|
||||||
end
|
end
|
||||||
@s_type = 0
|
@s_type = 0
|
||||||
# @projects = @projects.sort {|x,y| y.created_on <=> x.created_on }
|
# @projects = @projects.sort {|x,y| y.created_on <=> x.created_on }
|
||||||
|
@ -302,13 +302,13 @@ class ProjectsController < ApplicationController
|
||||||
when '1'
|
when '1'
|
||||||
@offset ||= @project_pages.reverse_offset
|
@offset ||= @project_pages.reverse_offset
|
||||||
unless @offset == 0
|
unless @offset == 0
|
||||||
@projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(@limit).all.reverse
|
@projects_status = @projects_status.reorder('course_ac_para').offset(@offset).limit(@limit).all.reverse
|
||||||
else
|
else
|
||||||
limit = @project_count % @limit
|
limit = @project_count % @limit
|
||||||
if limit == 0
|
if limit == 0
|
||||||
limit = @limit
|
limit = @limit
|
||||||
end
|
end
|
||||||
@projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(limit).all.reverse
|
@projects_status = @projects_status.reorder('course_ac_para').offset(@offset).limit(limit).all.reverse
|
||||||
end
|
end
|
||||||
@s_type = 1
|
@s_type = 1
|
||||||
|
|
||||||
|
|
|
@ -68,17 +68,17 @@ module ProjectsHelper
|
||||||
when 0
|
when 0
|
||||||
content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:project_sort_type => '0', :project_type => project_type), :class=>"selected"), :class=>"selected")
|
content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:project_sort_type => '0', :project_type => project_type), :class=>"selected"), :class=>"selected")
|
||||||
content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:project_sort_type => '1', :project_type => project_type)))
|
content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:project_sort_type => '1', :project_type => project_type)))
|
||||||
content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:project_sort_type => '2', :project_type => project_type)))
|
# content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:project_sort_type => '2', :project_type => project_type)))
|
||||||
|
|
||||||
when 1
|
when 1
|
||||||
content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:project_sort_type => '0', :project_type => project_type)))
|
content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:project_sort_type => '0', :project_type => project_type)))
|
||||||
content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:project_sort_type => '1', :project_type => project_type), :class=>"selected"), :class=>"selected")
|
content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:project_sort_type => '1', :project_type => project_type), :class=>"selected"), :class=>"selected")
|
||||||
content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:project_sort_type => '2', :project_type => project_type)))
|
# content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:project_sort_type => '2', :project_type => project_type)))
|
||||||
|
|
||||||
when 2
|
when 2
|
||||||
content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:project_sort_type => '0', :project_type => project_type)))
|
content << content_tag('li', link_to(l(:label_sort_by_time), course_path(:project_sort_type => '0', :project_type => project_type)))
|
||||||
content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:project_sort_type => '1', :project_type => project_type)))
|
content << content_tag('li', link_to(l(:label_sort_by_active), course_path(:project_sort_type => '1', :project_type => project_type)))
|
||||||
content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:project_sort_type => '2', :project_type => project_type), :class=>"selected"), :class=>"selected")
|
# content << content_tag('li', link_to(l(:label_sort_by_influence), course_path(:project_sort_type => '2', :project_type => project_type), :class=>"selected"), :class=>"selected")
|
||||||
|
|
||||||
end
|
end
|
||||||
content = content_tag('ul', content)
|
content = content_tag('ul', content)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class ProjectStatus < ActiveRecord::Base
|
class ProjectStatus < ActiveRecord::Base
|
||||||
attr_accessible :changesets_count, :watchers_count, :project_id, :project_type
|
attr_accessible :changesets_count, :watchers_count, :project_id, :project_type
|
||||||
belongs_to :projects
|
belongs_to :project
|
||||||
belongs_to :watchers
|
belongs_to :watchers
|
||||||
belongs_to :changesets
|
belongs_to :changesets
|
||||||
validates_presence_of :project_id
|
validates_presence_of :project_id
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
<% @project.versions.each do |version| %>
|
<% @project.versions.each do |version| %>
|
||||||
<% files_count += version.attachments.count %>
|
<% files_count += version.attachments.count %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= content_tag('span', link_to(files_count, file_project_path(@project)), :class => "info") %>
|
<%= content_tag('span', link_to(files_count, project_files_path(@project)), :class => "info") %>
|
||||||
<%= content_tag('span', l(:label_x_data,:count => files_count)) %>
|
<%= content_tag('span', l(:label_x_data,:count => files_count)) %>
|
||||||
</p>
|
</p>
|
||||||
<p class="stats">
|
<p class="stats">
|
||||||
|
|
|
@ -34,20 +34,6 @@
|
||||||
<!-- end -->
|
<!-- end -->
|
||||||
|
|
||||||
<%= sort_course(@s_type, @project_type)%>
|
<%= sort_course(@s_type, @project_type)%>
|
||||||
<!-- <div class="pagination_list">
|
|
||||||
<ul>
|
|
||||||
<li>
|
|
||||||
<%= link_to l(:label_sort_by_time), projects_path(:project_sort_type => '0'),:class=>"test_new" %>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<%= link_to l(:label_sort_by_active), projects_path(:project_sort_type => '1'),:class=>"test_new" %>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<%= link_to l(:label_sort_by_influence), projects_path(:project_sort_type => '2'),:class=>"test_new" %>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div> -->
|
|
||||||
|
|
||||||
|
|
||||||
<div id="projects-index">
|
<div id="projects-index">
|
||||||
<%= render_project_hierarchy(@projects)%>
|
<%= render_project_hierarchy(@projects)%>
|
||||||
|
|
|
@ -32,23 +32,6 @@
|
||||||
<!-- end -->
|
<!-- end -->
|
||||||
|
|
||||||
<%= sort_project(@s_type, @project_type) %>
|
<%= sort_project(@s_type, @project_type) %>
|
||||||
|
|
||||||
<!--end-->
|
|
||||||
<!-- <div class="pagination_list">
|
|
||||||
<ul>
|
|
||||||
<li>
|
|
||||||
<%= link_to l(:label_sort_by_time), projects_path(:project_sort_type => '0'),:class=>"test_new" %>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<%= link_to l(:label_sort_by_active), projects_path(:project_sort_type => '1'),:class=>"test_new" %>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<%= link_to l(:label_sort_by_influence), projects_path(:project_sort_type => '2'),:class=>"test_new" %>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div> -->
|
|
||||||
|
|
||||||
|
|
||||||
<div id="projects-index">
|
<div id="projects-index">
|
||||||
<%= render_project_hierarchy(@projects)%>
|
<%= render_project_hierarchy(@projects)%>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,57 +2,88 @@ class StoredStatusProcedure < ActiveRecord::Migration
|
||||||
def up
|
def up
|
||||||
#sql = <<- END_OF_SQL_CODE
|
#sql = <<- END_OF_SQL_CODE
|
||||||
execute "
|
execute "
|
||||||
create procedure `sp_user_status_cursor`()
|
CREATE PROCEDURE `sp_user_status_cursor` ()
|
||||||
begin
|
BEGIN
|
||||||
declare user_uid bigint(22);
|
DECLARE user_uid bigint(22);
|
||||||
declare user_changesets_count int(10);
|
DECLARE user_changesets_count int(10);
|
||||||
declare _done tinyint(1) default 0;
|
DECLARE _done tinyint(1) DEFAULT 0;
|
||||||
declare cur_user cursor for select user_id, count(*) from changesets where user_id != '' group by user_id;
|
DECLARE cur_user CURSOR FOR
|
||||||
declare continue handler for not found set _done = 1;
|
SELECT
|
||||||
open cur_user;
|
user_id,
|
||||||
loop_xxx:loop
|
COUNT(*)
|
||||||
fetch cur_user into user_uid,user_changesets_count;
|
FROM changesets
|
||||||
if _done=1 then
|
WHERE user_id != ''
|
||||||
leave loop_xxx;
|
GROUP BY user_id;
|
||||||
end if;
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET _done = 1;
|
||||||
begin
|
OPEN cur_user;
|
||||||
declare journals_for_messages_count int(10);
|
loop_xxx:
|
||||||
declare journals_count int(10);
|
LOOP
|
||||||
declare comments_count int(10);
|
FETCH cur_user INTO user_uid, user_changesets_count;
|
||||||
declare messages_count int(10);
|
IF _done = 1 THEN
|
||||||
declare news_count int(10);
|
LEAVE loop_xxx;
|
||||||
declare wiki_contents_count int(10);
|
END IF;
|
||||||
declare activities_count int(10);
|
BEGIN
|
||||||
declare total_count numeric(8,2);
|
DECLARE journals_for_messages_count int(10);
|
||||||
|
DECLARE journals_count int(10);
|
||||||
select count(*) into journals_for_messages_count from journals_for_messages where user_id = user_uid;
|
DECLARE comments_count int(10);
|
||||||
select count(*) into journals_count from journals where user_id = user_uid;
|
DECLARE messages_count int(10);
|
||||||
select count(*) into comments_count from comments where author_id = user_uid;
|
DECLARE news_count int(10);
|
||||||
select count(*) into messages_count from messages where author_id = user_uid;
|
DECLARE wiki_contents_count int(10);
|
||||||
select count(*) into news_count from news where author_id = user_uid;
|
DECLARE activities_count int(10);
|
||||||
select count(*) into wiki_contents_count from wiki_contents where author_id = user_uid;
|
DECLARE total_count numeric(8, 2);
|
||||||
select count(*) into activities_count from activities where user_id = user_uid;
|
|
||||||
|
SELECT
|
||||||
set total_count = journals_for_messages_count*0.05 +
|
COUNT(*) INTO journals_for_messages_count
|
||||||
journals_count*0.1 +
|
FROM journals_for_messages
|
||||||
comments_count*0.1 +
|
WHERE user_id = user_uid;
|
||||||
messages_count*0.05 +
|
SELECT
|
||||||
news_count*0.1 +
|
COUNT(*) INTO journals_count
|
||||||
wiki_contents_count*0.1 +
|
FROM journals
|
||||||
activities_count*0.2 +
|
WHERE user_id = user_uid;
|
||||||
user_changesets_count*0.3;
|
SELECT
|
||||||
|
COUNT(*) INTO comments_count
|
||||||
update user_statuses set changesets_count = user_changesets_count, grade = total_count where user_id = user_uid;
|
FROM comments
|
||||||
commit;
|
WHERE author_id = user_uid;
|
||||||
end;
|
SELECT
|
||||||
end loop;
|
COUNT(*) INTO messages_count
|
||||||
end;
|
FROM messages
|
||||||
|
WHERE author_id = user_uid;
|
||||||
|
SELECT
|
||||||
|
COUNT(*) INTO news_count
|
||||||
|
FROM news
|
||||||
|
WHERE author_id = user_uid;
|
||||||
|
SELECT
|
||||||
|
COUNT(*) INTO wiki_contents_count
|
||||||
|
FROM wiki_contents
|
||||||
|
WHERE author_id = user_uid;
|
||||||
|
SELECT
|
||||||
|
COUNT(*) INTO activities_count
|
||||||
|
FROM activities
|
||||||
|
WHERE user_id = user_uid;
|
||||||
|
|
||||||
|
SET total_count = journals_for_messages_count * 0.05 +
|
||||||
|
journals_count * 0.1 +
|
||||||
|
comments_count * 0.1 +
|
||||||
|
messages_count * 0.05 +
|
||||||
|
news_count * 0.1 +
|
||||||
|
wiki_contents_count * 0.1 +
|
||||||
|
activities_count * 0.2 +
|
||||||
|
user_changesets_count * 0.3;
|
||||||
|
|
||||||
|
UPDATE user_statuses
|
||||||
|
SET changesets_count = user_changesets_count,
|
||||||
|
grade = total_count
|
||||||
|
WHERE user_id = user_uid;
|
||||||
|
COMMIT;
|
||||||
|
END;
|
||||||
|
END LOOP;
|
||||||
|
END;
|
||||||
"
|
"
|
||||||
execute "
|
execute "
|
||||||
create event if not exists e_test
|
CREATE EVENT IF NOT EXISTS e_test
|
||||||
on schedule every 1 day starts'2013-08-27 01:50:00'
|
ON SCHEDULE EVERY 1 DAY STARTS '2013-08-27 01:50:00'
|
||||||
on completion preserve
|
ON COMPLETION PRESERVE
|
||||||
do call `sp_user_status_cursor`();
|
DO CALL `sp_user_status_cursor`();
|
||||||
"
|
"
|
||||||
execute "
|
execute "
|
||||||
CREATE PROCEDURE `sp_project_status_cursor` ()
|
CREATE PROCEDURE `sp_project_status_cursor` ()
|
||||||
|
@ -323,27 +354,27 @@ END LOOP;
|
||||||
END;
|
END;
|
||||||
"
|
"
|
||||||
execute "
|
execute "
|
||||||
create event if not exists e_project_status_test
|
CREATE EVENT IF NOT EXISTS e_project_status_test
|
||||||
on schedule every 1 day starts'2013-08-27 01:50:00'
|
ON SCHEDULE EVERY 1 DAY STARTS '2013-08-27 01:50:00'
|
||||||
on completion preserve
|
ON COMPLETION PRESERVE
|
||||||
do call `sp_project_status_cursor`();
|
DO CALL `sp_project_status_cursor`();
|
||||||
"
|
"
|
||||||
execute "
|
execute "
|
||||||
set global event_scheduler = on;
|
SET GLOBAL event_scheduler = ON;
|
||||||
"
|
"
|
||||||
end
|
end
|
||||||
|
|
||||||
def down
|
def down
|
||||||
execute " drop procedure if exists `sp_user_status_cursor`;
|
execute " DROP PROCEDURE IF EXISTS `sp_user_status_cursor`;
|
||||||
"
|
"
|
||||||
execute "
|
execute "
|
||||||
drop event if exists e_test;
|
DROP EVENT IF EXISTS e_test;
|
||||||
"
|
"
|
||||||
execute "
|
execute "
|
||||||
drop procedure if exists `sp_project_status_cursor`;
|
DROP PROCEDURE IF EXISTS `sp_project_status_cursor`;
|
||||||
"
|
"
|
||||||
execute "
|
execute "
|
||||||
drop event if exists e_project_status_test;
|
DROP EVENT IF EXISTS e_project_status_test;
|
||||||
"
|
"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class AddDescriptionToShare < ActiveRecord::Migration
|
class AddDescriptionToShare < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
add_column :shares, :description, :string
|
# add_column :shares, :description, :string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,63 @@
|
||||||
class StoredCourseProcess < ActiveRecord::Migration
|
class StoredCourseProcess < ActiveRecord::Migration
|
||||||
def up
|
def up
|
||||||
|
execute "
|
||||||
|
CREATE PROCEDURE sp_course_cursor ()
|
||||||
|
BEGIN
|
||||||
|
DECLARE course_uid int(10);
|
||||||
|
DECLARE _done tinyint(1) DEFAULT 0;
|
||||||
|
DECLARE cur_course CURSOR FOR
|
||||||
|
SELECT
|
||||||
|
`projects`.id
|
||||||
|
FROM `projects`
|
||||||
|
WHERE projects.status <> 9 AND projects.is_public = 1 AND projects.project_type = 1;
|
||||||
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET _done = 1;
|
||||||
|
|
||||||
|
OPEN cur_course;
|
||||||
|
loop_course:
|
||||||
|
LOOP
|
||||||
|
FETCH cur_course INTO course_uid;
|
||||||
|
IF _done = 1 THEN
|
||||||
|
LEAVE loop_course;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
BEGIN
|
||||||
|
DECLARE members_count int(4) DEFAULT 0;
|
||||||
|
DECLARE attachments_count int(4) DEFAULT 0;
|
||||||
|
DECLARE total_count int(4) DEFAULT 0;
|
||||||
|
SELECT
|
||||||
|
COUNT(*) INTO members_count
|
||||||
|
FROM `members` inner join `users`
|
||||||
|
WHERE `members`.`project_id` = course_uid AND `members`.`user_id` = `users`.`id` AND `users`.`type` = 'User' AND `users`.`status` = 1;
|
||||||
|
SELECT
|
||||||
|
COUNT(*) INTO attachments_count
|
||||||
|
FROM `attachments`
|
||||||
|
WHERE `attachments`.`container_id` = course_uid AND `attachments`.`container_type` = 'Project';
|
||||||
|
SET total_count = members_count + attachments_count;
|
||||||
|
UPDATE project_statuses
|
||||||
|
SET course_ac_para = total_count
|
||||||
|
WHERE project_statuses.project_id = course_uid;
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
|
END;
|
||||||
|
END LOOP;
|
||||||
|
END;
|
||||||
|
"
|
||||||
|
execute "
|
||||||
|
CREATE EVENT IF NOT EXISTS e_project_status_course
|
||||||
|
ON SCHEDULE EVERY 1 DAY STARTS '2013-08-27 01:50:00'
|
||||||
|
ON COMPLETION PRESERVE
|
||||||
|
DO CALL sp_course_cursor();
|
||||||
|
"
|
||||||
|
execute "
|
||||||
|
SET GLOBAL event_scheduler = ON;
|
||||||
|
"
|
||||||
end
|
end
|
||||||
|
|
||||||
def down
|
def down
|
||||||
|
execute " DROP PROCEDURE IF EXISTS sp_course_cursor;
|
||||||
|
"
|
||||||
|
execute "
|
||||||
|
DROP EVENT IF EXISTS e_project_status_course;
|
||||||
|
"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddCourseAcParaToProjectStatuses < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :project_statuses, :course_ac_para, :integer, :default => 0;
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20131031093317) do
|
ActiveRecord::Schema.define(:version => 20131108133857) do
|
||||||
|
|
||||||
create_table "a_user_watchers", :force => true do |t|
|
create_table "a_user_watchers", :force => true do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
|
@ -510,11 +510,11 @@ ActiveRecord::Schema.define(:version => 20131031093317) do
|
||||||
t.integer "project_id"
|
t.integer "project_id"
|
||||||
t.integer "project_type"
|
t.integer "project_type"
|
||||||
t.integer "gitlab_group_id", :limit => 8
|
t.integer "gitlab_group_id", :limit => 8
|
||||||
t.float "grade"
|
t.float "grade", :default => 0.0
|
||||||
|
t.integer "course_ac_para", :default => 0
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "project_statuses", ["changesets_count"], :name => "index_project_statuses_on_changesets_count"
|
add_index "project_statuses", ["changesets_count"], :name => "index_project_statuses_on_changesets_count"
|
||||||
add_index "project_statuses", ["grade"], :name => "index_project_statuses_on_grade"
|
|
||||||
add_index "project_statuses", ["watchers_count"], :name => "index_project_statuses_on_watchers_count"
|
add_index "project_statuses", ["watchers_count"], :name => "index_project_statuses_on_watchers_count"
|
||||||
|
|
||||||
create_table "project_tags", :force => true do |t|
|
create_table "project_tags", :force => true do |t|
|
||||||
|
|
Loading…
Reference in New Issue