Removed Unit.group, added UnitsController#import
This commit is contained in:
parent
fea736bd36
commit
8e7385cdcb
@ -1,5 +1,5 @@
|
|||||||
class UnitsController < ApplicationController
|
class UnitsController < ApplicationController
|
||||||
before_action :find_project, only: [:new, :index, :create]
|
before_action :find_project, only: [:new, :index, :create, :import]
|
||||||
before_action :authorize
|
before_action :authorize
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@ -16,6 +16,9 @@ class UnitsController < ApplicationController
|
|||||||
def destroy
|
def destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def import
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# :find_* methods are called before :authorize,
|
# :find_* methods are called before :authorize,
|
||||||
|
@ -1,6 +1,2 @@
|
|||||||
module UnitsHelper
|
module UnitsHelper
|
||||||
def group_options
|
|
||||||
translations = t('.groups')
|
|
||||||
Unit.groups.map { |k,v| [translations[k.to_sym], k] }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -1,30 +1,6 @@
|
|||||||
class Unit < ActiveRecord::Base
|
class Unit < ActiveRecord::Base
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
|
|
||||||
# https://en.wikipedia.org/wiki/International_System_of_Units
|
|
||||||
enum group: {
|
|
||||||
number: 0,
|
|
||||||
share: 1,
|
|
||||||
|
|
||||||
length: 10,
|
|
||||||
mass: 11,
|
|
||||||
time: 12,
|
|
||||||
temperature: 13,
|
|
||||||
|
|
||||||
volume: 20,
|
|
||||||
density: 21,
|
|
||||||
ndensity: 22,
|
|
||||||
|
|
||||||
frequency: 30,
|
|
||||||
velocity: 31,
|
|
||||||
flow: 32,
|
|
||||||
|
|
||||||
energy: 30,
|
|
||||||
|
|
||||||
pressure: 40
|
|
||||||
}
|
|
||||||
|
|
||||||
validates :project, associated: true
|
validates :project, associated: true
|
||||||
validates :name, :shortname, presence: true
|
validates :name, :shortname, presence: true
|
||||||
validates :group, inclusion: groups.keys
|
|
||||||
end
|
end
|
||||||
|
@ -6,8 +6,7 @@
|
|||||||
<p><%= f.text_field :shortname, required: true, size: 10 %></p>
|
<p><%= f.text_field :shortname, required: true, size: 10 %></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="splitcontentright">
|
<div class="splitcontentright">
|
||||||
<p><%= f.select :group, group_options, required: true %></p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p><%= f.text_field :name, required: true, size: 40 %></p>
|
<p><%= f.text_field :name, required: true, size: 40 %></p>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@ -14,19 +14,3 @@ en:
|
|||||||
index:
|
index:
|
||||||
heading: 'Units'
|
heading: 'Units'
|
||||||
heading_new_unit: 'New unit'
|
heading_new_unit: 'New unit'
|
||||||
form:
|
|
||||||
groups:
|
|
||||||
number: 'count'
|
|
||||||
share: 'share'
|
|
||||||
length: 'length'
|
|
||||||
mass: 'mass'
|
|
||||||
time: 'time'
|
|
||||||
temperature: 'temperature'
|
|
||||||
volume: 'volume'
|
|
||||||
density: 'density'
|
|
||||||
ndensity: 'number density'
|
|
||||||
frequency: 'frequency'
|
|
||||||
velocity: 'velocity'
|
|
||||||
flow: 'flow rate'
|
|
||||||
energy: 'energy'
|
|
||||||
pressure: 'pressure'
|
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
resources :projects do
|
resources :projects do
|
||||||
shallow do
|
shallow do
|
||||||
resources :body_trackers, :only => [:index]
|
resources :body_trackers, :only => [:index]
|
||||||
resources :units, :only => [:new, :index, :create, :destroy]
|
resources :units, :only => [:new, :index, :create, :destroy] do
|
||||||
|
post 'import', on: :collection
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -4,19 +4,17 @@ class CreateUnits < ActiveRecord::Migration
|
|||||||
t.references :project
|
t.references :project
|
||||||
t.string :name
|
t.string :name
|
||||||
t.string :shortname
|
t.string :shortname
|
||||||
t.integer :group
|
|
||||||
end
|
end
|
||||||
|
|
||||||
reversible do |dir|
|
reversible do |dir|
|
||||||
dir.up do
|
dir.up do
|
||||||
Unit.create project: nil, shortname: "", name: "count", group: :number
|
Unit.create project: nil, shortname: "", name: "count"
|
||||||
Unit.create project: nil, shortname: "%", name: "percent", group: :share
|
Unit.create project: nil, shortname: "%", name: "percent"
|
||||||
Unit.create project: nil, shortname: "g", name: "gram", group: :mass
|
Unit.create project: nil, shortname: "g", name: "gram"
|
||||||
Unit.create project: nil, shortname: "kg", name: "kilogram", group: :mass
|
Unit.create project: nil, shortname: "kg", name: "kilogram"
|
||||||
end
|
end
|
||||||
|
|
||||||
dir.down do
|
dir.down do
|
||||||
Unit.delete_all
|
Unit.where(project: nil).delete_all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user