|
|
@@ -15,6 +15,19 @@ class ScaleResult < ActiveRecord::Base
|
|
|
contact.blank? ? "-" : contact
|
|
|
end
|
|
|
|
|
|
+ # 从测量结果中获取时间戳
|
|
|
+ def measurement_time
|
|
|
+ return nil if result.blank?
|
|
|
+ begin
|
|
|
+ data = JSON.parse(result)
|
|
|
+ timestamp = data['timestamp']
|
|
|
+ return nil if timestamp.blank?
|
|
|
+ Time.parse(timestamp)
|
|
|
+ rescue => e
|
|
|
+ nil
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
rails_admin do
|
|
|
navigation_label '测量记录'
|
|
|
parent ScaleDevice
|
|
|
@@ -43,11 +56,13 @@ class ScaleResult < ActiveRecord::Base
|
|
|
field :result do
|
|
|
label '测量结果'
|
|
|
end
|
|
|
- field :created_at do
|
|
|
- label '创建时间'
|
|
|
- end
|
|
|
- field :updated_at do
|
|
|
- label '更新时间'
|
|
|
+ field :measurement_time do
|
|
|
+ label '测量时间'
|
|
|
+ pretty_value do
|
|
|
+ time = bindings[:object].measurement_time
|
|
|
+ time.present? ? time.strftime('%Y-%m-%d %H:%M:%S') : '-'
|
|
|
+ end
|
|
|
+ sortable false
|
|
|
end
|
|
|
end
|
|
|
|
|
|
@@ -73,11 +88,12 @@ class ScaleResult < ActiveRecord::Base
|
|
|
field :result do
|
|
|
label '测量结果'
|
|
|
end
|
|
|
- field :created_at do
|
|
|
- label '创建时间'
|
|
|
- end
|
|
|
- field :updated_at do
|
|
|
- label '更新时间'
|
|
|
+ field :measurement_time do
|
|
|
+ label '测量时间'
|
|
|
+ pretty_value do
|
|
|
+ time = bindings[:object].measurement_time
|
|
|
+ time.present? ? time.strftime('%Y-%m-%d %H:%M:%S') : '-'
|
|
|
+ end
|
|
|
end
|
|
|
end
|
|
|
|
|
|
@@ -91,12 +107,6 @@ class ScaleResult < ActiveRecord::Base
|
|
|
field :result do
|
|
|
label '测量结果'
|
|
|
end
|
|
|
- field :created_at do
|
|
|
- label '创建时间'
|
|
|
- end
|
|
|
- field :updated_at do
|
|
|
- label '更新时间'
|
|
|
- end
|
|
|
end
|
|
|
end
|
|
|
end
|