Merge remote-tracking branch 'origin/szzh' into guange_dev

This commit is contained in:
guange 2015-05-05 11:46:15 +08:00
commit 31c78d295e
17 changed files with 225 additions and 72 deletions

View File

@ -240,6 +240,18 @@ module Mobile
present :status, 0
end
desc '课程学生'
params do
requires :token,type:String
requires :course_id,type:Integer,desc: '课程id'
end
get ":course_id/members" do
cs = CoursesService.new
count = cs.course_members params
present :data, count, with: Mobile::Entities::Member
present :status, 0
end
end
end
end

View File

@ -46,6 +46,7 @@ module Mobile
course_expose :term
course_expose :time
course_expose :updated_at
course_expose :course_student_num
expose :teacher, using: Mobile::Entities::User do |c, opt|
if c.is_a? ::Course
c.teacher

View File

@ -0,0 +1,33 @@
module Mobile
module Entities
class Member < Grape::Entity
include ApplicationHelper
include ApiHelper
def self.member_expose(f)
expose f do |u,opt|
if u.is_a?(Hash) && u.key?(f)
u[f]
elsif u.is_a?(::Member)
if u.respond_to?(f)
u.send(f)
else
case f
when :student_id
u.user.user_extensions.student_id
end
end
end
end
end
expose :user, using: Mobile::Entities::User do |c, opt|
if c.is_a?(::Member)
c.user
end
end
member_expose :student_id
member_expose :score
end
end
end

View File

@ -247,10 +247,9 @@ class ProjectsController < ApplicationController
# 1、自动注册
# 2、加入项目、创建角色
# 3、用户得分
if params[:login]
# 自动激活用户
user.status = 1
user.save
if params[:email]
user = User.find_by_mail(params[:email].to_s)
Member.create(:role_ids => [4], :user_id => user.id,:project_id => @project.id)
end
if params[:jump] && redirect_to_project_menu_item(@project, params[:jump])
return

View File

@ -329,12 +329,12 @@ module ApplicationHelper
imagesize = attachment.thumbnail(:size => "200*200")
imagepath = named_attachment_path(attachment, attachment.filename)
if imagesize
link_to image_tag(thumbnail_path(attachment), height: '73', width: '100', name: 'issue_attachment_picture'),
link_to image_tag(thumbnail_path(attachment), height: '73', width: '100', class: 'issue_attachment_picture'),
imagepath,
:title => attachment.filename
else
link_to image_tag(imagepath , height: '73', width: '100', name: 'issue_attachment_picture'),
link_to image_tag(imagepath , height: '73', width: '100', class: 'issue_attachment_picture'),
imagepath,
:title => attachment.filename
end

View File

@ -71,14 +71,14 @@ class Mailer < ActionMailer::Base
# 邀请已注册的用户加入项目
def request_member_to_project(email, project, invitor)
@subject = "#{invitor.name} #{l(:label_invite_project)}: #{project.name} "
user = User.find_by_mail(email.to_s)
Member.create(:role_ids => [4], :user_id => user.id,:project_id => project.id)
@invitor_name = "#{invitor.name}"
@project_name = "#{project.name}"
@user = user
@token = Token.get_token_from_user(user, 'autologin')
@project_url = url_for(:controller => 'projects', :action => 'show', :id => project.id,:user => user, :token => @token.value)
mail :to => email, :invitor_name => "#{@invitor_name}", :project_name => "#{@project_name}"
@invitor_name = "#{invitor.name}"
@project_name = "#{project.name}"
@user = user
@token = Token.get_token_from_user(user, 'autologin')
@project_url = url_for(:controller => 'projects', :action => 'show', :id => project.id, :email => email, :token => @token.value)
mail :to => email, :subject => @subject
end
# author: alan

View File

@ -169,7 +169,7 @@ class CoursesService
unless (course.is_public == 1 || current_user.member_of_course?(course) || current_user.admin?)
raise '403'
end
{:course => course,:work_unit => work_unit, :img_url => url_to_avatar(course),:current_user_is_member => current_user.member_of_course?(course),:current_user_is_teacher => is_course_teacher(current_user,course)}
{:course => course,:work_unit => work_unit, :img_url => url_to_avatar(course),:current_user_is_member => current_user.member_of_course?(course),:current_user_is_teacher => is_course_teacher(current_user,course),:course_student_num => course ? course.student.count.to_s : 0}
end
#创建课程
@ -439,6 +439,11 @@ class CoursesService
result
end
# 课程学生列表
def course_members params
@all_members = student_homework_score(0,params[:course_id], 10,"desc")
end
private
def show_homework_info course,bid,current_user,is_course_teacher
author_real_name = bid.author.lastname + bid.author.firstname
@ -476,5 +481,52 @@ class CoursesService
end
def student_homework_score(groupid,course_id, nums, score_sort_by)
#teachers = find_course_teachers(@course)
#start_from = start_from * nums
sql_select = ""
if groupid == 0
if nums == 0
sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches
WHERE members.course_id = #{course_id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{course_id}) AND members.user_id = homework_attaches.user_id
AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id}) GROUP BY members.user_id
UNION all
SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{course_id} AND
students_for_courses.course_id = #{course_id} and members.user_id = students_for_courses.student_id AND
members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id} )
)
GROUP BY members.user_id ORDER BY score #{score_sort_by}"
else
sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches
WHERE members.course_id = #{course_id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{course_id}) AND members.user_id = homework_attaches.user_id
AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id}) GROUP BY members.user_id
UNION all
SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{course_id} AND
students_for_courses.course_id = #{course_id} and members.user_id = students_for_courses.student_id AND
members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id} )
)
GROUP BY members.user_id ORDER BY score #{score_sort_by} " #limit #{start_from}, #{nums}"
end
else
sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches
WHERE members.course_id = #{course_id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{course_id}) AND members.user_id = homework_attaches.user_id
and members.course_group_id = #{groupid} AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id})
GROUP BY members.user_id
UNION all
SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{course_id}
and members.course_group_id = #{groupid} AND
students_for_courses.course_id = #{course_id} and members.user_id = students_for_courses.student_id AND
members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id} )
)
GROUP BY members.user_id ORDER BY score #{score_sort_by}"
end
sql = ActiveRecord::Base.connection()
homework_scores = Member.find_by_sql(sql_select)
sql.close()
homework_scores
end
end

View File

@ -1,62 +1,28 @@
<script type="text/javascript">
document.addEventListener('DOMContentLoaded',function(){
var img = document.getElementsByName('issue_attachment_picture');
function getImgNaturalStyle(img, callback) {
var nWidth, nHeight;
if (typeof img.naturalWidth == "undefined"|| img.naturalWidth == 0) {
var image = new Image();
image.src = img.src;
if (image.complete) {
callback(image);
} else {
image.onload = function () {
callback(image);
image.onload = null;
};
};
jQuery(window).load(function () {
jQuery(".issue_attachment_picture").each(function () {
DrawImage(this, 100, 73);
});
});
function DrawImage(ImgD, FitWidth, FitHeight) {
var image = new Image();
image.src = ImgD.src;
if (image.width > 100 || image.height > 73)
{
rateWidth = image.width / 100;
rateHeight = image.height / 73;
if (rateWidth > rateHeight) {
ImgD.width = 100;
ImgD.height = Math.round(image.height/rateWidth);
}
else
{
if (img.complete) {
nWidth = img.naturalWidth;
nHeight = img.naturalHeight;
} else {
img.onload = function () {
nWidth = img.naturalWidth;
nHeight = img.naturalHeight;
image.onload = null;
};
};
}
return [nWidth, nHeight];
}
function UpdateImageInformation(image) {
return [image.width,image.height];
}
for(i=0;i<img.length;i++)
{
imgNatural = getImgNaturalStyle(img[i],UpdateImageInformation);
var width = imgNatural[0];
var height = imgNatural[1];
if (width<100)
{
img[i].width = width;
}
if (height<73) {
img[i].height = height;
ImgD.width = Math.round(image.width/rateHeight);
ImgD.height = 73;
}
}
});
}
</script>
<div class="attachments" style="font-weight:normal;">

View File

@ -0,0 +1,66 @@
<style type="text/css">
#preview{width:360px;height:360px;border:1px solid #000;overflow:hidden;}
#imghead {filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image);}
</style>
<script type="text/javascript">
function previewImage(file)
{
var MAXWIDTH = 360;
var MAXHEIGHT = 360;
var div = document.getElementById('preview');
if (file.files && file.files[0])
{
div.innerHTML = '<img id=imghead>';
var img = document.getElementById('imghead');
img.onload = function(){
var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
img.width = rect.width;
img.height = rect.height;
img.style.marginLeft = rect.left+'px';
img.style.marginTop = rect.top+'px';
}
var reader = new FileReader();
reader.onload = function(evt){img.src = evt.target.result;}
reader.readAsDataURL(file.files[0]);
}
else
{
var sFilter='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
file.select();
var src = document.selection.createRange().text;
div.innerHTML = '<img id=imghead>';
var img = document.getElementById('imghead');
img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
status =('rect:'+rect.top+','+rect.left+','+rect.width+','+rect.height);
div.innerHTML = "<div id=divhead style='width:"+rect.width+"px;height:"+rect.height+"px;margin-top:"+rect.top+"px;margin-left:"+rect.left+"px;"+sFilter+src+"\"'></div>";
}
}
function clacImgZoomParam( maxWidth, maxHeight, width, height ){
var param = {top:0, left:0, width:width, height:height};
if( width>maxWidth || height>maxHeight )
{
rateWidth = width / maxWidth;
rateHeight = height / maxHeight;
if( rateWidth > rateHeight )
{
param.width = maxWidth;
param.height = Math.round(height / rateWidth);
}else
{
param.width = Math.round(width / rateHeight);
param.height = maxHeight;
}
}
param.left = Math.round((maxWidth - param.width) / 2);
param.top = Math.round((maxHeight - param.height) / 2);
return param;
}
</script>
<div id="preview">
<img id="imghead" width=100 height=100 border=0 src="file:///C:/Users/whimlex/Downloads/1.jpg">
</div>
<br/>
<input type="file" onchange="previewImage(this)" />

View File

@ -4,7 +4,7 @@
<% html_title "#{@issue.tracker.name} #{@issue.source_from}'#'#{@issue.project_index}: #{@issue.subject}" %>
<div class="pro_page_box">
<div class="pro_page_top break_word">
<a href="javascript:void(0)"><%= @issue.project.name %></a> >
<%= link_to "#{@issue.project.name}"+">", project_issues_path(@issue.project) %>
<a href="javascript:void(0)"><%= "#" + @issue.project_index %></a>
</div>
<div class="problem_main">

View File

@ -89,7 +89,7 @@
<%=l(:label_project_hosting_platform) %>
</a>
>
<%= link_to @project.name, nil %>
<%= link_to @project.name, project_path(@project.id) %>
</p>
</div>
<div class="search fl">
@ -122,13 +122,12 @@
<!-- 项目得分 -->
<div class="cl"></div>
<div>
<a class="pr_info_name fl c_dark fb break_word" href="javascript:void(0)" target="_blank" >
<%= l(:label_project_name) %><%= @project.name %>
<%= link_to l(:label_project_name)+"#{@project.name}", project_path(@project.id), :class=>"pr_info_name fl c_dark fb break_word" %>
<% if @project.is_public? %>
<span class="img_private"><%= l(:label_public)%></span>
<% else %>
<span class="img_private"><%= l(:label_private)%></span>
<% end %></a>
<% end %>
</div>
<div class="cl"></div>
<div>

View File

@ -0,0 +1,5 @@
class AddIndexToHomeworkattachBidId < ActiveRecord::Migration
def change
add_index(:homework_attaches,:bid_id)
end
end

View File

@ -0,0 +1,5 @@
class AddIndexToStudentforcourseStudentId < ActiveRecord::Migration
def change
add_index(:students_for_courses,:student_id)
end
end

View File

@ -0,0 +1,5 @@
class AddIndexToStudentforcourseCourseId < ActiveRecord::Migration
def change
add_index(:students_for_courses,:course_id)
end
end

View File

@ -0,0 +1,5 @@
class AddIndexToHomeworkattachCourseId < ActiveRecord::Migration
def change
add_index(:homework_for_courses,:course_id)
end
end

View File

@ -0,0 +1,5 @@
class AddIndexToHomeworkforcourseBidId < ActiveRecord::Migration
def change
add_index(:homework_for_courses,:bid_id)
end
end

View File

@ -87,7 +87,7 @@ a.pro_mes_w{ height:20px; float:left;display:block; color:#999999;}
.pro_page_top{ font-size:14px; border-bottom:2px solid #64bdd9; margin-bottom:10px; padding-bottom:5px;}
.pro_page_tit{color:#3e4040; font-weight:bold;width:480px; float:left; font-size:14px; margin-bottom:5px;}
.pro_pic_box{ margin-left:60px; }
.pro_pic{ width:100px; height:73px;line-height:73px;border:2px solid #CCC; margin:10px 0;}
.pro_pic{ width:100px; height:75px;line-height:73px;border:2px solid #CCC; margin:10px 0; text-align: center;}
.pro_info_box{ margin-left:60px; background:#f0fbff; height:80px; padding:10px 0;}
.pro_info_box ul{}
.pro_info_box ul li{ margin-bottom:10px;}