修改课程活跃度排序方式,解决课程列表文件链接错误
This commit is contained in:
parent
22ce616a78
commit
adf8a7bc92
|
@ -130,7 +130,7 @@ class ProjectsController < ApplicationController
|
|||
|
||||
|
||||
@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.each do |project|
|
||||
# if Project.visible.find_by_id("#{project.project_id}")
|
||||
|
@ -174,13 +174,13 @@ class ProjectsController < ApplicationController
|
|||
when '0'
|
||||
@offset ||= @project_pages.reverse_offset
|
||||
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
|
||||
limit = @project_count % @limit
|
||||
if limit == 0
|
||||
limit = @limit
|
||||
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
|
||||
@s_type = 0
|
||||
# @projects = @projects.sort {|x,y| y.created_on <=> x.created_on }
|
||||
|
@ -302,13 +302,13 @@ class ProjectsController < ApplicationController
|
|||
when '1'
|
||||
@offset ||= @project_pages.reverse_offset
|
||||
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
|
||||
limit = @project_count % @limit
|
||||
if limit == 0
|
||||
limit = @limit
|
||||
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
|
||||
@s_type = 1
|
||||
|
||||
|
|
|
@ -68,17 +68,17 @@ module ProjectsHelper
|
|||
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_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
|
||||
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_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
|
||||
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_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
|
||||
content = content_tag('ul', content)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class ProjectStatus < ActiveRecord::Base
|
||||
attr_accessible :changesets_count, :watchers_count, :project_id, :project_type
|
||||
belongs_to :projects
|
||||
belongs_to :project
|
||||
belongs_to :watchers
|
||||
belongs_to :changesets
|
||||
validates_presence_of :project_id
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
<% @project.versions.each do |version| %>
|
||||
<% files_count += version.attachments.count %>
|
||||
<% 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)) %>
|
||||
</p>
|
||||
<p class="stats">
|
||||
|
|
|
@ -34,20 +34,6 @@
|
|||
<!-- end -->
|
||||
|
||||
<%= 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">
|
||||
<%= render_project_hierarchy(@projects)%>
|
||||
|
|
|
@ -32,23 +32,6 @@
|
|||
<!-- end -->
|
||||
|
||||
<%= 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">
|
||||
<%= render_project_hierarchy(@projects)%>
|
||||
</div>
|
||||
|
|
|
@ -2,57 +2,88 @@ class StoredStatusProcedure < ActiveRecord::Migration
|
|||
def up
|
||||
#sql = <<- END_OF_SQL_CODE
|
||||
execute "
|
||||
create procedure `sp_user_status_cursor`()
|
||||
begin
|
||||
declare user_uid bigint(22);
|
||||
declare user_changesets_count int(10);
|
||||
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 continue handler for not found set _done = 1;
|
||||
open cur_user;
|
||||
loop_xxx:loop
|
||||
fetch cur_user into user_uid,user_changesets_count;
|
||||
if _done=1 then
|
||||
leave loop_xxx;
|
||||
end if;
|
||||
begin
|
||||
declare journals_for_messages_count int(10);
|
||||
declare journals_count int(10);
|
||||
declare comments_count int(10);
|
||||
declare messages_count int(10);
|
||||
declare news_count int(10);
|
||||
declare wiki_contents_count int(10);
|
||||
declare activities_count int(10);
|
||||
declare total_count numeric(8,2);
|
||||
|
||||
select count(*) into journals_for_messages_count from journals_for_messages where user_id = user_uid;
|
||||
select count(*) into journals_count from journals where user_id = user_uid;
|
||||
select count(*) into comments_count from comments where author_id = user_uid;
|
||||
select count(*) into messages_count 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;
|
||||
CREATE PROCEDURE `sp_user_status_cursor` ()
|
||||
BEGIN
|
||||
DECLARE user_uid bigint(22);
|
||||
DECLARE user_changesets_count int(10);
|
||||
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 CONTINUE HANDLER FOR NOT FOUND SET _done = 1;
|
||||
OPEN cur_user;
|
||||
loop_xxx:
|
||||
LOOP
|
||||
FETCH cur_user INTO user_uid, user_changesets_count;
|
||||
IF _done = 1 THEN
|
||||
LEAVE loop_xxx;
|
||||
END IF;
|
||||
BEGIN
|
||||
DECLARE journals_for_messages_count int(10);
|
||||
DECLARE journals_count int(10);
|
||||
DECLARE comments_count int(10);
|
||||
DECLARE messages_count int(10);
|
||||
DECLARE news_count int(10);
|
||||
DECLARE wiki_contents_count int(10);
|
||||
DECLARE activities_count int(10);
|
||||
DECLARE total_count numeric(8, 2);
|
||||
|
||||
SELECT
|
||||
COUNT(*) INTO journals_for_messages_count
|
||||
FROM journals_for_messages
|
||||
WHERE user_id = user_uid;
|
||||
SELECT
|
||||
COUNT(*) INTO journals_count
|
||||
FROM journals
|
||||
WHERE user_id = user_uid;
|
||||
SELECT
|
||||
COUNT(*) INTO comments_count
|
||||
FROM comments
|
||||
WHERE author_id = user_uid;
|
||||
SELECT
|
||||
COUNT(*) INTO messages_count
|
||||
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 "
|
||||
create event if not exists e_test
|
||||
on schedule every 1 day starts'2013-08-27 01:50:00'
|
||||
on completion preserve
|
||||
do call `sp_user_status_cursor`();
|
||||
CREATE EVENT IF NOT EXISTS e_test
|
||||
ON SCHEDULE EVERY 1 DAY STARTS '2013-08-27 01:50:00'
|
||||
ON COMPLETION PRESERVE
|
||||
DO CALL `sp_user_status_cursor`();
|
||||
"
|
||||
execute "
|
||||
CREATE PROCEDURE `sp_project_status_cursor` ()
|
||||
|
@ -323,27 +354,27 @@ END LOOP;
|
|||
END;
|
||||
"
|
||||
execute "
|
||||
create event if not exists e_project_status_test
|
||||
on schedule every 1 day starts'2013-08-27 01:50:00'
|
||||
on completion preserve
|
||||
do call `sp_project_status_cursor`();
|
||||
CREATE EVENT IF NOT EXISTS e_project_status_test
|
||||
ON SCHEDULE EVERY 1 DAY STARTS '2013-08-27 01:50:00'
|
||||
ON COMPLETION PRESERVE
|
||||
DO CALL `sp_project_status_cursor`();
|
||||
"
|
||||
execute "
|
||||
set global event_scheduler = on;
|
||||
SET GLOBAL event_scheduler = ON;
|
||||
"
|
||||
end
|
||||
|
||||
def down
|
||||
execute " drop procedure if exists `sp_user_status_cursor`;
|
||||
execute " DROP PROCEDURE IF EXISTS `sp_user_status_cursor`;
|
||||
"
|
||||
execute "
|
||||
drop event if exists e_test;
|
||||
DROP EVENT IF EXISTS e_test;
|
||||
"
|
||||
execute "
|
||||
drop procedure if exists `sp_project_status_cursor`;
|
||||
DROP PROCEDURE IF EXISTS `sp_project_status_cursor`;
|
||||
"
|
||||
execute "
|
||||
drop event if exists e_project_status_test;
|
||||
DROP EVENT IF EXISTS e_project_status_test;
|
||||
"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class AddDescriptionToShare < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :shares, :description, :string
|
||||
# add_column :shares, :description, :string
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,63 @@
|
|||
class StoredCourseProcess < ActiveRecord::Migration
|
||||
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
|
||||
|
||||
def down
|
||||
execute " DROP PROCEDURE IF EXISTS sp_course_cursor;
|
||||
"
|
||||
execute "
|
||||
DROP EVENT IF EXISTS e_project_status_course;
|
||||
"
|
||||
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.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20131031093317) do
|
||||
ActiveRecord::Schema.define(:version => 20131108133857) do
|
||||
|
||||
create_table "a_user_watchers", :force => true do |t|
|
||||
t.string "name"
|
||||
|
@ -510,11 +510,11 @@ ActiveRecord::Schema.define(:version => 20131031093317) do
|
|||
t.integer "project_id"
|
||||
t.integer "project_type"
|
||||
t.integer "gitlab_group_id", :limit => 8
|
||||
t.float "grade"
|
||||
t.float "grade", :default => 0.0
|
||||
t.integer "course_ac_para", :default => 0
|
||||
end
|
||||
|
||||
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"
|
||||
|
||||
create_table "project_tags", :force => true do |t|
|
||||
|
|
Loading…
Reference in New Issue