erd 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +9 -11
  4. data/README.rdoc +1 -1
  5. data/app/controllers/erd/erd_controller.rb +100 -65
  6. data/app/views/erd/erd/_column.html.erb +8 -4
  7. data/app/views/erd/erd/_model.html.erb +23 -17
  8. data/app/views/erd/erd/edit.html.erb +87 -0
  9. data/app/views/erd/erd/erd.html.erb +1 -1
  10. data/app/views/erd/erd/index.html.erb +12 -81
  11. data/app/views/layouts/erd/application.html.erb +3 -2
  12. data/config/routes.rb +1 -0
  13. data/erd.gemspec +1 -1
  14. data/gemfiles/rails_32.gemfile +1 -1
  15. data/gemfiles/rails_40.gemfile +1 -0
  16. data/gemfiles/rails_41.gemfile +1 -0
  17. data/gemfiles/rails_42.gemfile +1 -0
  18. data/gemfiles/rails_50.gemfile +1 -0
  19. data/gemfiles/rails_51.gemfile +1 -0
  20. data/gemfiles/rails_52.gemfile +1 -0
  21. data/gemfiles/rails_60.gemfile +9 -0
  22. data/gemfiles/rails_edge.gemfile +1 -0
  23. data/lib/erd.rb +7 -1
  24. data/lib/erd/engine.rb +12 -0
  25. data/lib/erd/migrator.rb +3 -1
  26. data/lib/erd/version.rb +1 -1
  27. data/{vendor/assets/images → public}/erd/angle-left.png +0 -0
  28. data/{vendor/assets/images → public}/erd/angle-right.png +0 -0
  29. data/{vendor/assets/images → public}/erd/animated-overlay.gif +0 -0
  30. data/{vendor/assets/images → public}/erd/background.png +0 -0
  31. data/{vendor/assets/images → public}/erd/cancel.png +0 -0
  32. data/{vendor/assets/images → public}/erd/close.png +0 -0
  33. data/public/erd/erd.css +598 -0
  34. data/{app/assets/javascripts/erd/erd.js.js → public/erd/erd.js} +14 -3
  35. data/{app → src}/assets/stylesheets/erd/erd.css.scss +7 -7
  36. data/test/test_helper.rb +2 -0
  37. metadata +20 -21
  38. data/app/assets/javascripts/erd/application.js +0 -14
  39. data/app/assets/stylesheets/erd/application.css +0 -13
  40. data/lib/erd/railtie.rb +0 -21
  41. data/vendor/assets/javascripts/raphael-min.js +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9d85fe99c1f99f980306af0ec58827c2259b1669055460c5af1181ba344970a
4
- data.tar.gz: 39522c53587e660e2445c39a2931f167db10c09429e8a8c020d5e6e371fdf9b3
3
+ metadata.gz: 35c1ad5ad3318d07d2faeb5836b2ec12e8132088994985d6d0f0342addd7685d
4
+ data.tar.gz: 77ce179c5b2c8cbe58095320d012e5aab188c3aa0d23d73e9de5036564e2cf1f
5
5
  SHA512:
6
- metadata.gz: c2116ff57af688e72b0de8acd82c2b3aa107762cffb576323b79eb002cb895e103dda3286e34e23b3959e88106de7199d120a798ab3ee99495836caf00cf4fca
7
- data.tar.gz: 1b57a5dbe064649cbb4891bb079814faec9641d5fa1f2f7c37918895e0d36dfadd61e70dfff0cb441b13c3022ca66843a114e5ead333d785bbe8f5e36ab38046
6
+ metadata.gz: c02778a0c99593cd9ae3b8f5c27ccb0ea11f8ad6aa719a023f8de9ad40a51352ac33d17e92035afec8faad65ad7f1944eb032a65c98d9570f4840843121f65d5
7
+ data.tar.gz: 5f227492c2234358069825ca797188e6ec92e74cab71172de589077c1e52d4e3d104e04eedbd3e3e3b84b54dea911c8e61970893fdf9c7b4cd7ada16a2b98d31
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .sass-cache
6
7
  Gemfile.lock
7
8
  gemfiles/*.lock
8
9
  InstalledFiles
@@ -13,16 +13,15 @@ cache:
13
13
  - bundler
14
14
 
15
15
  before_install:
16
- - sudo apt update -qq
17
16
  - sudo apt install -y chromium-chromedriver
18
- - sudo ln -s /usr/lib/chromium-browser/chromedriver /usr/bin/
19
- - gem install bundler
17
+ - gem i bundler -v '<2'
20
18
 
21
19
  rvm:
22
- - 2.5.3
20
+ - 2.6.0
23
21
  - 2.0.0
24
22
 
25
23
  gemfile:
24
+ - gemfiles/rails_60.gemfile
26
25
  - gemfiles/rails_52.gemfile
27
26
  - gemfiles/rails_51.gemfile
28
27
  - gemfiles/rails_50.gemfile
@@ -33,20 +32,19 @@ gemfile:
33
32
 
34
33
  matrix:
35
34
  exclude:
35
+ - rvm: 2.0.0
36
+ gemfile: gemfiles/rails_60.gemfile
36
37
  - rvm: 2.0.0
37
38
  gemfile: gemfiles/rails_52.gemfile
38
39
  - rvm: 2.0.0
39
40
  gemfile: gemfiles/rails_51.gemfile
40
41
  - rvm: 2.0.0
41
42
  gemfile: gemfiles/rails_50.gemfile
42
- - rvm: 2.5.3
43
+ - rvm: 2.6.0
43
44
  gemfile: gemfiles/rails_42.gemfile
44
- - rvm: 2.5.3
45
+ - rvm: 2.6.0
45
46
  gemfile: gemfiles/rails_41.gemfile
46
- - rvm: 2.5.3
47
+ - rvm: 2.6.0
47
48
  gemfile: gemfiles/rails_40.gemfile
48
- - rvm: 2.5.3
49
- gemfile: gemfiles/rails_32.gemfile
50
- include:
51
- - rvm: 1.8.7
49
+ - rvm: 2.6.0
52
50
  gemfile: gemfiles/rails_32.gemfile
@@ -43,7 +43,7 @@ Browse at your http://localhost:3000/erd
43
43
 
44
44
  * drop column (need to think of the UI)
45
45
 
46
- * stop depending on rails-erd and Graphviz
46
+ * stop depending on Graphviz
47
47
 
48
48
  * tests
49
49
 
@@ -1,70 +1,69 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'nokogiri'
4
- require 'rails_erd/diagram/graphviz'
4
+ require 'ruby-graphviz'
5
5
  require 'erd/application_controller'
6
6
 
7
7
  module Erd
8
8
  class ErdController < ::Erd::ApplicationController
9
+ POSITIONS_JSON_FILE = Rails.root.join('tmp/erd_positions.json').freeze
10
+
9
11
  def index
10
- Rails.application.eager_load!
11
- RailsERD.options[:filename], RailsERD.options[:filetype] = Rails.root.join('tmp/erd'), 'plain'
12
- RailsERD::Diagram::Graphviz.create
13
- plain = Rails.root.join('tmp/erd.plain').read
14
- positions = if (json = Rails.root.join('tmp/erd_positions.json')).exist?
15
- ActiveSupport::JSON.decode json.read
16
- else
17
- {}
18
- end
19
- @erd = render_plain plain, positions
12
+ @erd = render_plain generate_plain, saved_positions
13
+ end
20
14
 
15
+ def edit
16
+ @erd = render_plain generate_plain, saved_positions, true
21
17
  @migrations = Erd::Migrator.status
22
18
  end
23
19
 
24
20
  def update
25
- changes = ActiveSupport::JSON.decode(params[:changes])
21
+ if params[:position_changes].present?
22
+ position_changes = ActiveSupport::JSON.decode(params[:position_changes])
23
+ positions = saved_positions
24
+ positions.merge! position_changes.transform_keys(&:tableize)
25
+ POSITIONS_JSON_FILE.open('w') {|f| f.write positions.to_json }
26
+ end
27
+
28
+ changes = params[:changes].present? ? ActiveSupport::JSON.decode(params[:changes]) : []
26
29
  executed_migrations, failed_migrations = [], []
27
30
  changes.each do |row|
28
31
  begin
29
32
  action, model, column, from, to = row['action'], row['model'], row['column'], row['from'], row['to']
30
- if action == 'move'
33
+
34
+ case action
35
+ when 'create_model'
36
+ columns = column.split(' ').compact
37
+ generated_migration_file = Erd::GenaratorRunner.execute_generate_model model, columns
38
+ when 'remove_model'
31
39
  model = model.tableize
32
- json_file = Rails.root.join('tmp', 'erd_positions.json')
33
- positions = json_file.exist? ? ActiveSupport::JSON.decode(json_file.read) : {}
34
- positions[model] = to
35
- json_file.open('w') {|f| f.write positions.to_json}
40
+ generated_migration_file = Erd::GenaratorRunner.execute_generate_migration "drop_#{model}"
41
+ gsub_file generated_migration_file, /def (up|change).* end/m, "def change\n drop_table :#{model}\n end"
42
+ when 'rename_model'
43
+ _model, from, to = from.tableize, to.tableize, model.tableize
44
+ generated_migration_file = Erd::GenaratorRunner.execute_generate_migration "rename_#{from}_to_#{to}"
45
+ gsub_file generated_migration_file, /def (up|change).* end/m, "def change\n rename_table :#{from}, :#{to}\n end"
46
+ when 'add_column'
47
+ model = model.tableize
48
+ name_and_type = column.scan(/(.*)\((.*?)\)/).first
49
+ name, type = name_and_type[0], name_and_type[1]
50
+ generated_migration_file = Erd::GenaratorRunner.execute_generate_migration "add_#{name}_to_#{model}", ["#{name}:#{type}"]
51
+ when 'rename_column'
52
+ model = model.tableize
53
+ generated_migration_file = Erd::GenaratorRunner.execute_generate_migration "rename_#{model}_#{from}_to_#{to}"
54
+ gsub_file generated_migration_file, /def (up|change).* end/m, "def change\n rename_column :#{model}, :#{from}, :#{to}\n end"
55
+ when 'alter_column'
56
+ model = model.tableize
57
+ generated_migration_file = Erd::GenaratorRunner.execute_generate_migration "change_#{model}_#{column}_type_to_#{to}"
58
+ gsub_file generated_migration_file, /def (up|change).* end/m, "def change\n change_column :#{model}, :#{column}, :#{to}\n end"
59
+ when 'move'
60
+ # do nothing
36
61
  else
37
- case action
38
- when 'create_model'
39
- columns = column.split(' ').compact
40
- generated_migration_file = Erd::GenaratorRunner.execute_generate_model model, columns
41
- when 'remove_model'
42
- model = model.tableize
43
- generated_migration_file = Erd::GenaratorRunner.execute_generate_migration "drop_#{model}"
44
- gsub_file generated_migration_file, /def (up|change).* end/m, "def change\n drop_table :#{model}\n end"
45
- when 'rename_model'
46
- _model, from, to = from.tableize, to.tableize, model.tableize
47
- generated_migration_file = Erd::GenaratorRunner.execute_generate_migration "rename_#{from}_to_#{to}"
48
- gsub_file generated_migration_file, /def (up|change).* end/m, "def change\n rename_table :#{from}, :#{to}\n end"
49
- when 'add_column'
50
- model = model.tableize
51
- name_and_type = column.scan(/(.*)\((.*?)\)/).first
52
- name, type = name_and_type[0], name_and_type[1]
53
- generated_migration_file = Erd::GenaratorRunner.execute_generate_migration "add_#{name}_to_#{model}", ["#{name}:#{type}"]
54
- when 'rename_column'
55
- model = model.tableize
56
- generated_migration_file = Erd::GenaratorRunner.execute_generate_migration "rename_#{model}_#{from}_to_#{to}"
57
- gsub_file generated_migration_file, /def (up|change).* end/m, "def change\n rename_column :#{model}, :#{from}, :#{to}\n end"
58
- when 'alter_column'
59
- model = model.tableize
60
- generated_migration_file = Erd::GenaratorRunner.execute_generate_migration "change_#{model}_#{column}_type_to_#{to}"
61
- gsub_file generated_migration_file, /def (up|change).* end/m, "def change\n change_column :#{model}, :#{column}, :#{to}\n end"
62
- else
63
- raise "unexpected action: #{action}"
64
- end
65
- Erd::Migrator.run_migrations :up => generated_migration_file
66
- executed_migrations << generated_migration_file
62
+ raise "unexpected action: #{action}"
67
63
  end
64
+
65
+ Erd::Migrator.run_migrations :up => generated_migration_file
66
+ executed_migrations << generated_migration_file
68
67
  rescue ::Erd::MigrationError => e
69
68
  failed_migrations << e.message
70
69
  end
@@ -79,28 +78,64 @@ module Erd
79
78
  end
80
79
 
81
80
  private
82
- def render_plain(plain, positions)
83
- _scale, svg_width, svg_height = plain.scan(/\Agraph ([0-9\.]+) ([0-9\.]+) ([0-9\.]+)$/).first
84
- # node name x y width height label style shape color fillcolor
85
- max_model_x, max_model_y = 0, 0
86
- models = plain.scan(/^node ([^ ]+) ([0-9\.]+) ([0-9\.]+) ([0-9\.]+) ([0-9\.]+) <\{?(<((?!^\}?>).)*)^\}?> [^ ]+ [^ ]+ [^ ]+ [^ ]+\n/m).map {|node_name, x, y, width, height, label|
87
- label_doc = Nokogiri::HTML::DocumentFragment.parse(label)
88
- model_name = node_name.dup
89
- model_name[0] = model_name[-1] = '' if (model_name.first == '"') && (model_name.last == '"')
90
- model_name = model_name.sub(/^m_/, '')
91
- next if model_name.in? ['ActiveRecord::SchemaMigration', 'ActiveRecord::InternalMetadata']
92
- columns = []
93
- if (cols_table = label_doc.search('table')[1])
94
- columns = cols_table.search('tr > td').map {|col| col_name, col_type = col.text.split(' '); {:name => col_name, :type => col_type}}
81
+
82
+ def saved_positions
83
+ POSITIONS_JSON_FILE.exist? ? ActiveSupport::JSON.decode(POSITIONS_JSON_FILE.read) : {}
84
+ end
85
+
86
+ def generate_plain
87
+ if Rails.respond_to?(:autoloaders) && Rails.autoloaders.try(:zeitwerk_enabled?)
88
+ Zeitwerk::Loader.eager_load_all
89
+ else
90
+ Rails.application.eager_load!
91
+ end
92
+ ar_descendants = ActiveRecord::Base.descendants.reject {|m| m.name.in?(%w(ActiveRecord::SchemaMigration ActiveRecord::InternalMetadata ApplicationRecord)) }
93
+ ar_descendants.reject! {|m| !m.table_exists? }
94
+
95
+ g = GraphViz.new('ERD', :type => :digraph, :rankdir => 'LR', :labelloc => :t, :ranksep => '1.5', :nodesep => '1.8', :margin => '0,0', :splines => 'spline') {|g|
96
+ nodes = ar_descendants.each_with_object({}) do |model, hash|
97
+ next if model.name.start_with? 'HABTM_'
98
+ hash[model.name] = model.columns.reject {|c| c.name.in? %w(id created_at updated_at) }.map {|c| [c.name, c.type]}
99
+ end
100
+
101
+ edges = []
102
+ ar_descendants.each do |model|
103
+ model.reflect_on_all_associations.each do |reflection|
104
+ next unless nodes.key? model.name
105
+ next if reflection.macro == :belongs_to
106
+ next unless nodes.key?(reflection.klass.name)
107
+
108
+ edges << [model.name, reflection.klass.name]
109
+ # don't include the FKs in the diagram
110
+ nodes[reflection.klass.name].delete_if {|col, _type| col == reflection.foreign_key }
111
+ end
112
+ end
113
+
114
+ nodes.each_pair do |model_name, cols|
115
+ g.add_nodes model_name, 'shape' => 'record', 'label' => "#{model_name}|#{cols.map {|name, type| "#{name}(#{type})"}.join('\l')}"
116
+ end
117
+ edges.each do |from, to|
118
+ g.add_edge g.search_node(from), g.search_node(to)
95
119
  end
120
+ }
121
+ g.output('plain' => String)
122
+ end
123
+
124
+ def render_plain(plain, positions, edit_mode = false)
125
+ _scale, svg_width, svg_height = plain.scan(/\Agraph ([\d\.]+) ([\d\.]+) ([\d\.]+)$/).first
126
+ # node name x y width height label style shape color fillcolor
127
+ models = plain.scan(/^node ([^ ]+) ([\d\.]+) ([\d\.]+) ([\d\.]+) ([\d\.]+) ([^ ]+) [^ ]+ [^ ]+ [^ ]+ [^ ]+\n/m).map {|model_name, x, y, width, height, label|
128
+ columns = label.gsub("\\\n", '').split('|')[1].split('\l').map {|name_and_type| name_and_type.scan(/(.*?)\((.*?)\)/).first }.map {|n, t| {:name => n, :type => t} }
96
129
  custom_x, custom_y = positions[model_name.tableize].try(:split, ',')
97
- h = {:model => model_name, :x => (custom_x || (BigDecimal(x) * 72).round), :y => (custom_y || (BigDecimal(y) * 72).round), :width => (BigDecimal(width) * 72).round, :height => height, :columns => columns}
98
- max_model_x, max_model_y = [h[:x].to_i + h[:width].to_i, max_model_x, 1024].max, [h[:y].to_i + h[:height].to_i, max_model_y, 768].max
99
- h
130
+ {:model => model_name, :x => (custom_x || (BigDecimal(x) * 72).round), :y => (custom_y || (BigDecimal(y) * 72).round), :width => (BigDecimal(width) * 72).round, :height => (BigDecimal(height) * 72).round, :columns => columns}
100
131
  }.compact
132
+ max_model_x = models.map {|m| m[:x].to_f + m[:width].to_f }.max
133
+ erd_width = [[(BigDecimal(svg_width) * 72).round, max_model_x].min + 150, 1024].max
134
+ max_model_y = models.map {|m| m[:y].to_f + m[:height].to_f }.max
135
+ erd_height = [[(BigDecimal(svg_height) * 72).round, max_model_y].min + 150, 768].max
101
136
  # edge tail head n x1 y1 .. xn yn [label xl yl] style color
102
- edges = plain.scan(/^edge ([^ ]+)+ ([^ ]+)/).map {|from, to| {:from => from.sub(/^m_/, ''), :to => to.sub(/^m_/, '')}}
103
- render_to_string 'erd/erd/erd', :layout => nil, :locals => {:width => [(BigDecimal(svg_width) * 72).round, max_model_x].max, :height => [(BigDecimal(svg_height) * 72).round, max_model_y].max, :models => models, :edges => edges}
137
+ edges = plain.scan(/^edge ([^ ]+)+ ([^ ]+)/).map {|from, to| {:from => from, :to => to}}
138
+ render_to_string 'erd/erd/erd', :layout => nil, :locals => {:width => erd_width, :height => erd_height, :models => models, :edges => edges, :edit_mode => edit_mode}
104
139
  end
105
140
 
106
141
  def gsub_file(path, flag, *args, &block)
@@ -2,12 +2,16 @@
2
2
  <table>
3
3
  <tr>
4
4
  <td>
5
- <span class="column_name_text"><%= column[:name] %></span>
6
- <form class="rename_column_form"><span><input name="model" type="hidden" value="<%= model[:model] %>" /><input name="column" type="hidden" value="<%= column[:name] %>" /><input name="to" type="text" /><input type="submit" value="Change" /></span><a href="#!" class="cancel">Cancel</a></form>
5
+ <span class="column_name_text<%= "#{' edit' if edit_mode}" %>"><%= column[:name] %></span>
6
+ <% if edit_mode %>
7
+ <form class="rename_column_form"><span><input name="model" type="hidden" value="<%= model[:model] %>" /><input name="column" type="hidden" value="<%= column[:name] %>" /><input name="to" type="text" /><input type="submit" value="Change" /></span><a href="#!" class="cancel">Cancel</a></form>
8
+ <% end %>
7
9
  </td>
8
10
  <td>
9
- <span class="column_type_text <%= column[:type].delete(" ∗") %>"><%= column[:type] %></span>
10
- <form class="alter_column_form"><span><input name="model" type="hidden" value="<%= model[:model] %>" /><input name="column" type="hidden" value="<%= column[:name] %>" /><input name="type" type="hidden" value="<%= column[:type] %>" /><input name="to" type="text" /><input type="submit" value="Change" /></span><a href="#!" class="cancel">Cancel</a></form>
11
+ <span class="column_type_text <%= column[:type] %><%= "#{' edit' if edit_mode}" %>"><%= column[:type] %></span>
12
+ <% if edit_mode %>
13
+ <form class="alter_column_form"><span><input name="model" type="hidden" value="<%= model[:model] %>" /><input name="column" type="hidden" value="<%= column[:name] %>" /><input name="type" type="hidden" value="<%= column[:type] %>" /><input name="to" type="text" /><input type="submit" value="Change" /></span><a href="#!" class="cancel">Cancel</a></form>
14
+ <% end %>
11
15
  </td>
12
16
  </tr>
13
17
  </table>
@@ -1,28 +1,34 @@
1
1
  <div id="erd-<%= model[:model] %>" class="model" style="top: <%= model[:y] %>px; left: <%= model[:x] %>px;" data-model_name="<%= model[:model] %>">
2
- <a href="#!" class="close"><%= image_tag("/assets/erd/close.png") %></a>
3
- <div class="model_name">
2
+ <% if edit_mode %>
3
+ <a href="#!" class="close"><%= image_tag '/erd/close.png' %></a>
4
+ <% end %>
5
+ <div class="model_name<%= "#{' edit' if edit_mode}" %>">
4
6
  <div class="model_name_text"><%= model[:model] %></div>
5
- <form class="rename_model_form">
6
- <table>
7
- <tr>
8
- <td>
9
- <input name="model" type="hidden" value="<%= model[:model] %>"/>
10
- </td>
11
- <td>
12
- <input name="to" type="text" /><input type="submit" value="Change"/>
13
- </td>
14
- </tr>
15
- </table>
16
- <a href="#!" class="cancel">Cancel</a>
17
- </form>
7
+ <% if edit_mode %>
8
+ <form class="rename_model_form">
9
+ <table>
10
+ <tr>
11
+ <td>
12
+ <input name="model" type="hidden" value="<%= model[:model] %>"/>
13
+ </td>
14
+ <td>
15
+ <input name="to" type="text" /><input type="submit" value="Change"/>
16
+ </td>
17
+ </tr>
18
+ </table>
19
+ <a href="#!" class="cancel">Cancel</a>
20
+ </form>
21
+ <% end %>
18
22
  </div>
19
23
  <div class="columns">
20
24
  <ul>
21
- <%= render :partial => 'erd/erd/column', :collection => model[:columns], :locals => {:model => model} -%>
25
+ <%= render :partial => 'erd/erd/column', :collection => model[:columns], :locals => {:model => model, :edit_mode => edit_mode} -%>
22
26
  </ul>
23
27
  </div>
24
28
  <div class="add_column_box">
25
- <a href="#!" class="add_column">add column</a>
29
+ <% if edit_mode %>
30
+ <a href="#!" class="add_column">add column</a>
31
+ <% end %>
26
32
  <form class="add_column_form">
27
33
  <input name="model" type="hidden" value="<%= model[:model] %>" />
28
34
  <table>
@@ -0,0 +1,87 @@
1
+ <div id="erd_box">
2
+ <div id="erd_container">
3
+ <%=raw @erd %>
4
+ </div>
5
+ <div id="open_migration"><%= image_tag '/erd/angle-left.png' %></div>
6
+ <div id="migration">
7
+ <div id="close_migration"><%= image_tag '/erd/angle-right.png' %></div>
8
+ <%- if flash[:executed_migrations].present? -%>
9
+ <div id="executed">
10
+ <h2>Successfully executed following <%= flash[:executed_migrations].values.flatten.count %> migrations!</h2>
11
+ <%- [:up, :down].each do |direction| -%>
12
+ <%- if flash[:executed_migrations][direction].present? -%>
13
+ <h3><%= direction %></h3>
14
+ <ul>
15
+ <%- flash[:executed_migrations][direction].each do |m| -%>
16
+ <li><%= File.basename m.to_s %></li>
17
+ <%- end -%>
18
+ </ul>
19
+ <%- end -%>
20
+ <%- end -%>
21
+ </div>
22
+ <%- end -%>
23
+ <%- if flash[:failed_migrations].present? -%>
24
+ <div id="failed">
25
+ <h2>failed migrations</h2>
26
+ <ul>
27
+ <%- flash[:failed_migrations].each do |m| -%>
28
+ <li><%= m %></li>
29
+ <%- end -%>
30
+ </ul>
31
+ </div>
32
+ <%- end -%>
33
+ <table id="changes">
34
+ <caption>schema changes</caption>
35
+ <thead><tr><th>action</th><th>model</th><th>column</th><th>from</th><th>to</th></tr></thead>
36
+ <tbody></tbody>
37
+ </table>
38
+ <%= form_tag '/erd', :method => :put, :id => 'changes_form' do %>
39
+ <%= hidden_field_tag 'changes' %>
40
+ <%= hidden_field_tag 'position_changes' %>
41
+ <%= submit_tag 'save changes' %>
42
+ <% end %>
43
+ <%= form_tag '/erd/migrate', :method => :put, :id => 'migrate_form' do %>
44
+ <ul id="open_buttons">
45
+ <li><button id="open_up" type="button">up</button></li>
46
+ <li><button id="open_down" type="button">down</button></li>
47
+ <li><button id="close_all" type="button">close</button></li>
48
+ </ul>
49
+ <table id="migration_status">
50
+ <caption>migration status</caption>
51
+ <thead>
52
+ <tr><th class="status">status</th><th class="version">version</th><th class="name">name</th></tr>
53
+ <tr><td colspan="3" class="migrations">
54
+ <button>UNFOLD ALL</button>
55
+ <%= @migrations.count %> migrations in total (up: <%= @migrations.count {|m| m[:status] == 'up'} %>, down: <%= @migrations.count {|m| m[:status] == 'down'} %>)
56
+ </td></tr>
57
+ </thead>
58
+ <tbody>
59
+ <%- @migrations.each do |m| -%>
60
+ <tr class="<%= m[:status] %>">
61
+ <td><label><%= check_box_tag (m[:status] == 'up' ? 'down[]' : 'up[]'), m[:filename], false, :id => "check_#{m[:filename]}" %><%= m[:status] %></label></td>
62
+ <td><%= m[:version] %></td>
63
+ <td class="migration_file_name"><%= m[:name] %></td>
64
+ </tr>
65
+ <%- end -%>
66
+ </tbody>
67
+ </table>
68
+ <%= submit_tag 'run migrations' %>
69
+ <% end %>
70
+ </div>
71
+ <a href="#" id='open_create_model_dialog'%>Create Model</a>
72
+ <div id="create_model_form">
73
+ <form>
74
+ Model Name: <input id="new_model_name" name="new_model_name" type="text" /><br>
75
+ <table id="create_model_table">
76
+ <tbody>
77
+ <tr>
78
+ <td><input name="new_model_column_name_1" type="text" /></td>
79
+ <td class="separator">:</td>
80
+ <td><input name="new_model_column_type_1" type="text" value="string" /></td>
81
+ </tr>
82
+ </tbody>
83
+ </table>
84
+ <div><a href="#" id="new_model_add_column" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"><span class="ui-button-text">Add More Column</span></a></div>
85
+ </form>
86
+ </div>
87
+ </div>
@@ -1,4 +1,4 @@
1
1
  <div id="erd" data-svg_width="<%= width %>" data-svg_height="<%= height %>">
2
- <%= render :partial => 'erd/erd/model', :collection => models -%>
2
+ <%= render :partial => 'erd/erd/model', :collection => models, :locals => {:edit_mode => edit_mode} -%>
3
3
  <script>window.raw_edges = <%= edges.to_json.html_safe %>;</script>
4
4
  </div>
@@ -2,85 +2,16 @@
2
2
  <div id="erd_container">
3
3
  <%=raw @erd %>
4
4
  </div>
5
- <div id="open_migration"><%= image_tag("/assets/erd/angle-left.png") %></div>
6
- <div id="migration">
7
- <div id="close_migration"><%= image_tag("/assets/erd/angle-right.png") %></div>
8
- <%- if flash[:executed_migrations].present? -%>
9
- <div id="executed">
10
- <h2>Successfully executed following <%= flash[:executed_migrations].values.flatten.count %> migrations!</h2>
11
- <%- [:up, :down].each do |direction| -%>
12
- <%- if flash[:executed_migrations][direction].present? -%>
13
- <h3><%= direction %></h3>
14
- <ul>
15
- <%- flash[:executed_migrations][direction].each do |m| -%>
16
- <li><%= File.basename m.to_s %></li>
17
- <%- end -%>
18
- </ul>
19
- <%- end -%>
20
- <%- end -%>
21
- </div>
22
- <%- end -%>
23
- <%- if flash[:failed_migrations].present? -%>
24
- <div id="failed">
25
- <h2>failed migrations</h2>
26
- <ul>
27
- <%- flash[:failed_migrations].each do |m| -%>
28
- <li><%= m %></li>
29
- <%- end -%>
30
- </ul>
31
- </div>
32
- <%- end -%>
33
- <table id="changes">
34
- <caption>schema changes</caption>
35
- <thead><tr><th>action</th><th>model</th><th>column</th><th>from</th><th>to</th></tr></thead>
36
- <tbody></tbody>
37
- </table>
38
- <%= form_tag '/erd', :method => :put, :id => 'changes_form' do %>
39
- <%= hidden_field_tag 'changes' %>
40
- <%= submit_tag 'save changes' %>
41
- <% end %>
42
- <%= form_tag '/erd/migrate', :method => :put, :id => 'migrate_form' do %>
43
- <ul id="open_buttons">
44
- <li><button id="open_up" type="button">up</button></li>
45
- <li><button id="open_down" type="button">down</button></li>
46
- <li><button id="close_all" type="button">close</button></li>
47
- </ul>
48
- <table id="migration_status">
49
- <caption>migration status</caption>
50
- <thead>
51
- <tr><th class="status">status</th><th class="version">version</th><th class="name">name</th></tr>
52
- <tr><td colspan="3" class="migrations">
53
- <button>UNFOLD ALL</button>
54
- <%= @migrations.count %> migrations in total (up: <%= @migrations.count {|m| m[:status] == 'up'} %>, down: <%= @migrations.count {|m| m[:status] == 'down'} %>)
55
- </td></tr>
56
- </thead>
57
- <tbody>
58
- <%- @migrations.each do |m| -%>
59
- <tr class="<%= m[:status] %>">
60
- <td><label><%= check_box_tag (m[:status] == 'up' ? 'down[]' : 'up[]'), m[:filename] %><%= m[:status] %></label></td>
61
- <td><%= m[:version] %></td>
62
- <td class="migration_file_name"><%= m[:name] %></td>
63
- </tr>
64
- <%- end -%>
65
- </tbody>
66
- </table>
67
- <%= submit_tag 'run migrations' %>
68
- <% end %>
69
- </div>
70
- <a href="#" id='open_create_model_dialog'%>Create Model</a>
71
- <div id="create_model_form">
72
- <form>
73
- Model Name: <input id="new_model_name" name="new_model_name" type="text" /><br>
74
- <table id="create_model_table">
75
- <tbody>
76
- <tr>
77
- <td><input name="new_model_column_name_1" type="text" /></td>
78
- <td class="separator">:</td>
79
- <td><input name="new_model_column_type_1" type="text" value="string" /></td>
80
- </tr>
81
- </tbody>
82
- </table>
83
- <div><a href="#" id="new_model_add_column" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"><span class="ui-button-text">Add More Column</span></a></div>
84
- </form>
85
- </div>
5
+ <%= form_tag '/erd', :method => :put, :id => 'changes_form' do %>
6
+ <%= hidden_field_tag 'position_changes' %>
7
+ <% end %>
8
+ <input id="drawer_switch" type="checkbox">
9
+ <label id="drawer_hide_label" class="drawer_switch_label" for="drawer_switch">&gt;&nbsp;&nbsp;Hide Buttons</label>
10
+ <label id="drawer_show_label" class="drawer_switch_label" for="drawer_switch">&lt;</label>
11
+ <nav id="buttons">
12
+ <ul>
13
+ <li><a href="#!" id="save_position_changes" class="menu_button">Save Position Changes</a></li>
14
+ <li><%= link_to 'Edit the Database', :edit, :id => 'link_to_edit', :class => 'menu_button' %></li>
15
+ </ul>
16
+ </nav>
86
17
  </div>