unidom-score 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -1
- data/app/models/unidom/score/score_item.rb +2 -2
- data/app/models/unidom/score/score_sheet.rb +1 -1
- data/app/models/unidom/score/score_sheet_template.rb +21 -0
- data/db/migrate/20060101000000_create_unidom_score_sheet_templates.rb +30 -0
- data/db/migrate/20060112000000_create_unidom_score_items.rb +3 -3
- data/lib/unidom/score/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c9e9abc9735560e70d40caaaab8208a16dc313e
|
4
|
+
data.tar.gz: 455934053a55e4826d4a250de25764f214af6ee8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b335368d1bddabf333377fefb56a9a72158a66000ddf91f0af06b9ba5fdba0e97d0b7b55815e6277e693e35e48992046774309c58b61c22bc7ec6c6a7d6998e3
|
7
|
+
data.tar.gz: 361ff3c5a773d5c322065b6e5cc7dfb12ac6368f267f7f1edec93a589432a3896cb9382d5584d7c62e47c94646a27a0408f525b6c48e02778fa91e070321a40f
|
data/README.md
CHANGED
@@ -36,7 +36,14 @@ The migration versions start with 200601.
|
|
36
36
|
## Call the Model
|
37
37
|
|
38
38
|
```ruby
|
39
|
+
company = Unidom::Party::Company.create! name: 'Xerox'
|
40
|
+
template = Unidom::Score::ScoreSheetTemplate.create! subject: company, name: 'Survey 2003', total_score: 100
|
41
|
+
|
39
42
|
scorer = Unidom::Party::Person.create! name: 'Tim'
|
40
43
|
score_keeper = Unidom::Party::Shop.create! name: 'WalMart'
|
41
|
-
score_sheet = Unidom::Score::ScoreSheet.score! scorer: scorer, score_keeper: score_keeper, template:
|
44
|
+
score_sheet = Unidom::Score::ScoreSheet.score! scorer: scorer, score_keeper: score_keeper, template: template, name: nil, score: 98, scored_on: Date.current, opened_at: Time.now, description: nil, instruction: nil
|
45
|
+
# The template could be nil
|
46
|
+
|
47
|
+
item_1 = Unidom::Score::ScoreItem.score! sheet: score_sheet, scorer: score_sheet.try(:scorer), template: nil, title: template.try(:title), score: 59, scored_on: Date.current, opened_at: Time.now, description: nil, instruction: nil
|
48
|
+
item_2 = Unidom::Score::ScoreItem.score! sheet: score_sheet, scorer: score_sheet.try(:scorer), template: nil, title: template.try(:title), score: 39, scored_on: Date.current, opened_at: Time.now, description: nil, instruction: nil
|
42
49
|
```
|
@@ -20,8 +20,8 @@ class Unidom::Score::ScoreItem < Unidom::Score::ApplicationRecord
|
|
20
20
|
scope :template_is, ->(template) { where template_id: to_id(template) }
|
21
21
|
scope :scored_by, ->(scorer) { where scorer: scorer }
|
22
22
|
|
23
|
-
def self.score!(sheet: nil, scorer:
|
24
|
-
create! sheet: sheet, scorer: scorer, template: template,
|
23
|
+
def self.score!(sheet: nil, scorer: sheet.try(:scorer), template: nil, title: template.try(:title), score: 0, scored_on: Date.current, opened_at: Time.now, description: nil, instruction: nil)
|
24
|
+
create! sheet: sheet, scorer: scorer, template: template, title: title, score: score, scored_on: scored_on, opened_at: opened_at, description: description, instruction: instruction
|
25
25
|
end
|
26
26
|
|
27
27
|
end
|
@@ -16,7 +16,7 @@ class Unidom::Score::ScoreSheet < Unidom::Score::ApplicationRecord
|
|
16
16
|
belongs_to :scorer, polymorphic: true
|
17
17
|
belongs_to :score_keeper, polymorphic: true
|
18
18
|
|
19
|
-
has_many :
|
19
|
+
has_many :items, class_name: 'Unidom::Score::ScoreItem', foreign_key: :score_sheet_id
|
20
20
|
|
21
21
|
scope :template_is, ->(template) { where template_id: to_id(template) }
|
22
22
|
scope :scored_by, ->(scorer) { where scorer: scorer }
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Score Sheet Tempalte 是评分表模版。
|
2
|
+
# #template 是评分表模版。
|
3
|
+
# #scorer 是评分者。
|
4
|
+
# #score_keeper 是得分者。
|
5
|
+
|
6
|
+
class Unidom::Score::ScoreSheetTemplate < Unidom::Score::ApplicationRecord
|
7
|
+
|
8
|
+
self.table_name = 'unidom_score_sheet_templates'
|
9
|
+
|
10
|
+
include Unidom::Common::Concerns::ModelExtension
|
11
|
+
|
12
|
+
validates :name, allow_blank: true, length: { in: 2..columns_hash['name'].limit }
|
13
|
+
validates :total_score, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1_000_000_000 }
|
14
|
+
|
15
|
+
belongs_to :subject, polymorphic: true
|
16
|
+
|
17
|
+
has_many :sheets, class_name: 'Unidom::Score::ScoreSheet'
|
18
|
+
|
19
|
+
scope :subject_is, ->(subject) { where subject: subject }
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class CreateUnidomScoreSheetTemplates < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def change
|
4
|
+
|
5
|
+
create_table :unidom_score_sheet_templates, id: :uuid do |t|
|
6
|
+
|
7
|
+
t.references :subject, type: :uuid, null: false,
|
8
|
+
polymorphic: { null: false, default: '', limit: 200 }
|
9
|
+
|
10
|
+
t.string :name, null: true, default: nil, limit: 200
|
11
|
+
t.decimal :total_score, null: false, default: 0.0, precision: 12, scale: 2
|
12
|
+
|
13
|
+
t.text :description
|
14
|
+
t.text :instruction
|
15
|
+
|
16
|
+
t.column :state, 'char(1)', null: false, default: 'C'
|
17
|
+
t.datetime :opened_at, null: false, default: Time.utc(1970)
|
18
|
+
t.datetime :closed_at, null: false, default: Time.utc(3000)
|
19
|
+
t.boolean :defunct, null: false, default: false
|
20
|
+
t.jsonb :notation, null: false, default: {}
|
21
|
+
|
22
|
+
t.timestamps null: false
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
add_index :unidom_score_sheet_templates, :subject_id
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -26,9 +26,9 @@ class CreateUnidomScoreItems < ActiveRecord::Migration
|
|
26
26
|
|
27
27
|
end
|
28
28
|
|
29
|
-
add_index :
|
30
|
-
add_index :
|
31
|
-
add_index :
|
29
|
+
add_index :unidom_score_items, :score_sheet_id
|
30
|
+
add_index :unidom_score_items, :score_item_template_id
|
31
|
+
add_index :unidom_score_items, :scorer_id
|
32
32
|
|
33
33
|
end
|
34
34
|
|
data/lib/unidom/score/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unidom-score
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unidom-common
|
@@ -46,8 +46,10 @@ files:
|
|
46
46
|
- app/models/unidom/score/application_record.rb
|
47
47
|
- app/models/unidom/score/score_item.rb
|
48
48
|
- app/models/unidom/score/score_sheet.rb
|
49
|
+
- app/models/unidom/score/score_sheet_template.rb
|
49
50
|
- app/views/layouts/unidom/score/application.html.erb
|
50
51
|
- config/routes.rb
|
52
|
+
- db/migrate/20060101000000_create_unidom_score_sheet_templates.rb
|
51
53
|
- db/migrate/20060111000000_create_unidom_score_sheets.rb
|
52
54
|
- db/migrate/20060112000000_create_unidom_score_items.rb
|
53
55
|
- lib/tasks/score_tasks.rake
|