Skip to content

Commit

Permalink
数据库更改
Browse files Browse the repository at this point in the history
  • Loading branch information
xEasy committed Mar 22, 2012
1 parent 189b8bf commit 2886fa1
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 23 deletions.
3 changes: 2 additions & 1 deletion Gemfile
@@ -1,4 +1,5 @@
source 'http://rubygems.org'
#source 'http://rubygems.org'
source 'http://ruby.taobao.org'

gem 'rails', '3.0.3'

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,5 +1,5 @@
GEM
remote: http://rubygems.org/
remote: http://ruby.taobao.org/
specs:
abstract (1.0.0)
actionmailer (3.0.3)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/homes_controller.rb
Expand Up @@ -15,7 +15,7 @@ def student_detail
end

def student_score
render_json Student.find(params[:s_id]).provide params[:fields]
render_json Student.find(params[:s_id]).course_scores.collect &fields_provider
end

end
6 changes: 5 additions & 1 deletion app/models/course_score.rb
@@ -1,4 +1,8 @@
class CourseScore < ActiveRecord::Base
belongs_to :course
belongs_to :person
belongs_to :student

def score_type
ScoreType.where("begin <= ?", score).order("begin ASC").last.name
end
end
1 change: 1 addition & 0 deletions app/models/student.rb
@@ -1,5 +1,6 @@
class Student < Person
belongs_to :classes
has_many :course_scores

def detail

Expand Down
@@ -0,0 +1,9 @@
class RenamePersonToStudentInCourseScore < ActiveRecord::Migration
def self.up
rename_column :course_scores, :person_id, :student_id
end

def self.down
rename_column :course_scores, :student_id, :person_id
end
end
9 changes: 9 additions & 0 deletions db/migrate/20120322065109_add_grade_to_course_score.rb
@@ -0,0 +1,9 @@
class AddGradeToCourseScore < ActiveRecord::Migration
def self.up
add_column :course_scores, :grade, :string
end

def self.down
remove_column :course_scores, :grade
end
end
5 changes: 3 additions & 2 deletions db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120321161027) do
ActiveRecord::Schema.define(:version => 20120322065109) do

create_table "classes", :force => true do |t|
t.string "name"
Expand All @@ -32,11 +32,12 @@
end

create_table "course_scores", :force => true do |t|
t.integer "person_id"
t.integer "student_id"
t.integer "course_id"
t.integer "score"
t.datetime "created_at"
t.datetime "updated_at"
t.string "grade"
end

create_table "courses", :force => true do |t|
Expand Down
6 changes: 3 additions & 3 deletions lib/tasks/genrate_data.rake
Expand Up @@ -51,7 +51,7 @@ namespace :data do
:classes => Classes.all.last,
}
]
sts = Person.create(ps)
sts = Student.create(ps)
puts "====Person===="

cses = [
Expand All @@ -63,9 +63,9 @@ namespace :data do
puts "====Course==="

CourseScore.destroy_all
Person.all.each do |person|
Student.all.each do |student|
Course.all.each do |course|
CourseScore.create(:course => course, :person => person, :score => rand(100) )
CourseScore.create(:course => course, :student => student, :score => rand(100),:grade => "第一学期" )
end
end

Expand Down
35 changes: 21 additions & 14 deletions public/javascripts/PF/pages/home_index.js
Expand Up @@ -22,18 +22,18 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
id : 'form-tbar',
items : [
{ id : 'update-btn', text: '打印', handler: Pf.util.scope(this.printHandler,this) },
{ id : 'save-btn', text: '更新评语', handler: Pf.util.scope(this.updateHandler,this) },
]
}),
items : [ this.form ]
}];
},

createGrid : function() {
var scope = this;
var store = new Pf.util.FieldsJsonStore({
root : 'root',
url : '/homes/get_classes_students.json',
fields : ["id",'name','number']
fields : ["id",'name','number','phone','home','remark','sex','classes/name']
});

var cm = new Ext.grid.ColumnModel({
Expand Down Expand Up @@ -83,8 +83,15 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
}),
sm : new Ext.grid.RowSelectionModel({
listeners : {
rowselect : function (model, row, record) {
$("#image img").attr("src", record.get('image/url'));
rowselect : function (model, row, record) {
//加载成绩
var s_id = record.get("id");
var scoreGridStore = Ext.getCmp('score-grid').getStore();
scoreGridStore.load({ params : { s_id : s_id } });
//显示详细
var form = scope.form.getForm();
//加载头像
//$("#image img").attr("src", record.get('image/url'));
}
}
}),
Expand All @@ -96,20 +103,23 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
createForm : function() {
var store = new Pf.util.FieldsJsonStore({
root : 'root',
url : '#',
fields : ['course','grade','score','remark']
url : '/homes/student_score.json',
fields : ['course/name','grade','score','remark','score_type']
});
var cm = new Ext.grid.ColumnModel({
columns: [
{ header: '科目' , dataIndex: 'course', width : 50 },
{ header: '学期' , dataIndex: 'grade',width : 50 },
{ header: '科目' , dataIndex: 'course/name', width : 50 },
{ header: '学期' , dataIndex: 'grade',width : 50 },
{ header: '成绩' , dataIndex: 'score', width : 50 },
{ header: '成绩评级' , dataIndex: 'score_type', width : 50 },
{ header: '备注' , dataIndex: 'remark' },
],
defaults: { menuDisabled : true, sortable : true }
});
var grid = new Ext.grid.EditorGridPanel({
id : 'score-grid',
store: store,
loadMask :true,
cm : cm,
height : 200,
title : "学生成绩",
Expand Down Expand Up @@ -137,7 +147,7 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
}]
})]
}, {
defaults : { anchor : '95%' },
defaults : { anchor : '95%', readOnly : true },
defaultType : 'textfield',
columnWidth: .25,
layout: 'form',
Expand All @@ -155,7 +165,7 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
name: 'classes',
}]
},{
defaults : { anchor : '95%' },
defaults : { anchor : '95%' ,readOnly : true},
defaultType : 'textfield',
columnWidth: .45,
layout: 'form',
Expand All @@ -179,6 +189,7 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {
xtype: 'textarea',
id: 'bio',
height: 150,
readOnly : true,
anchor: '98%'
}]
}),
Expand All @@ -192,8 +203,4 @@ Pf.classes.homeIndex.MainPanel = Ext.extend(Ext.Panel, {

},

updateHandler : function () {
// body...
}

});

0 comments on commit 2886fa1

Please sign in to comment.