diff --git a/app/helpers/units_helper.rb b/app/helpers/units_helper.rb
index d8b2f3f..0bda873 100644
--- a/app/helpers/units_helper.rb
+++ b/app/helpers/units_helper.rb
@@ -1,2 +1,6 @@
module UnitsHelper
+ def type_options
+ translations = t('.types')
+ Unit.types.map { |k,v| [translations[k.to_sym], k] }
+ end
end
diff --git a/app/models/unit.rb b/app/models/unit.rb
index ee09039..c78467a 100644
--- a/app/models/unit.rb
+++ b/app/models/unit.rb
@@ -1,2 +1,24 @@
class Unit < ActiveRecord::Base
+ # https://en.wikipedia.org/wiki/International_System_of_Units
+ enum type: {
+ 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
+ }
end
diff --git a/app/views/units/_form.html.erb b/app/views/units/_form.html.erb
index 5c4e01e..04ef794 100644
--- a/app/views/units/_form.html.erb
+++ b/app/views/units/_form.html.erb
@@ -1,7 +1,13 @@
<%= error_messages_for @unit %>
-
<%= f.text_field :name, :required => true, :size => 40 %>
-
<%= f.text_field :shortname, :required => true, :size => 10 %>
-
<%#= f.select :summary, :cols => 60, :rows => 2 %>
+
+
+
<%= f.text_field :shortname, required: true, size: 10 %>
+
+
+
<%= f.select :type, type_options, required: true %>
+
+
+
<%= f.text_field :name, required: true, size: 40 %>
diff --git a/app/views/units/index.html.erb b/app/views/units/index.html.erb
index 44a0cfe..540c6ad 100644
--- a/app/views/units/index.html.erb
+++ b/app/views/units/index.html.erb
@@ -4,8 +4,7 @@
<% if @project && User.current.allowed_to?(:manage_units, @project) %>
- <%= link_to t(".heading_new_unit"), new_project_unit_path(@project),
- :class => 'icon icon-add',
+ <%= link_to t(".heading_new_unit"), '#', :class => 'icon icon-add',
:onclick => 'showAndScrollTo("add-unit", "unit_name"); return false;' %>
<% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 48bcbe2..77e7e84 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -14,3 +14,19 @@ en:
index:
heading: 'Units'
heading_new_unit: 'New unit'
+ form:
+ types:
+ 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'
diff --git a/db/migrate/001_create_units.rb b/db/migrate/001_create_units.rb
index e6e0333..58ac06b 100644
--- a/db/migrate/001_create_units.rb
+++ b/db/migrate/001_create_units.rb
@@ -1,7 +1,7 @@
class CreateUnits < ActiveRecord::Migration
def change
create_table :units do |t|
- t.references :project_id
+ t.references :project
t.string :name
t.string :shortname
t.integer :type