ponytail 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.travis.yml +11 -0
  4. data/Gemfile +8 -0
  5. data/Gemfile.lock +191 -0
  6. data/README.md +6 -0
  7. data/Rakefile +10 -6
  8. data/app/assets/javascripts/ponytail/models/column.coffee +41 -0
  9. data/app/assets/javascripts/ponytail/models/command.coffee +5 -0
  10. data/app/assets/javascripts/ponytail/models/create_table_command.coffee +11 -0
  11. data/app/assets/javascripts/ponytail/models/drop_table_command.coffee +5 -0
  12. data/app/assets/javascripts/ponytail/models/migration_file.coffee +38 -0
  13. data/app/assets/javascripts/ponytail/models/rename_table_command.coffee +5 -0
  14. data/app/assets/javascripts/ponytail/models/table.coffee +42 -0
  15. data/app/assets/javascripts/ponytail/ponytail.coffee +5 -0
  16. data/app/assets/javascripts/ponytail/views/column.coffee +70 -0
  17. data/app/assets/javascripts/ponytail/views/index.coffee +29 -0
  18. data/app/assets/javascripts/ponytail/views/migration_file.coffee +25 -0
  19. data/app/assets/javascripts/ponytail/views/new.coffee +58 -0
  20. data/app/assets/javascripts/ponytail/views/table.coffee +56 -0
  21. data/app/assets/stylesheets/ponytail/_base.scss +38 -0
  22. data/app/assets/stylesheets/ponytail/_index.scss +68 -0
  23. data/app/assets/stylesheets/ponytail/_new.scss +133 -0
  24. data/app/assets/stylesheets/ponytail/application.scss +5 -0
  25. data/app/views/ponytail/migrations/index.html.erb +49 -9
  26. data/app/views/ponytail/migrations/new.html.erb +84 -13
  27. data/app/views/ponytail/{migrations/_column_view_template.html.erb → templates/_column.html.erb} +7 -5
  28. data/app/views/ponytail/templates/_table.html.erb +14 -0
  29. data/bin/rails +3 -0
  30. data/lib/ponytail/version.rb +1 -1
  31. data/lib/ponytail.rb +3 -0
  32. data/lib/rails/mapper.rb +2 -2
  33. data/ponytail.gemspec +4 -1
  34. data/spec/dummy/config/environments/production.rb +1 -1
  35. data/spec/dummy/config/initializers/ponytail_on_heroku.rb +21 -0
  36. data/spec/features/migrations/index_spec.rb +1 -0
  37. data/spec/javascripts/ponytail/models/command_spec.coffee +5 -0
  38. data/spec/javascripts/ponytail/models/create_command_spec.js +0 -1
  39. data/spec/javascripts/ponytail/models/migration_file_spec.js +1 -1
  40. data/spec/javascripts/support/boots/boot.coffee +16 -0
  41. data/spec/javascripts/support/coffee-script.js +12 -0
  42. data/spec/javascripts/support/jasmine.yml +6 -5
  43. data/spec/javascripts/support/jasmine_helper.rb +16 -0
  44. data/spec/javascripts/support/run.html.erb +22 -0
  45. data/spec/rails/mapper_spec.rb +1 -1
  46. metadata +79 -28
  47. data/app/assets/javascripts/ponytail/models/column.js +0 -43
  48. data/app/assets/javascripts/ponytail/models/command.js +0 -8
  49. data/app/assets/javascripts/ponytail/models/create_table_command.js +0 -16
  50. data/app/assets/javascripts/ponytail/models/drop_table_command.js +0 -8
  51. data/app/assets/javascripts/ponytail/models/migration_file.js +0 -40
  52. data/app/assets/javascripts/ponytail/models/rename_table_command.js +0 -9
  53. data/app/assets/javascripts/ponytail/models/table.js +0 -44
  54. data/app/assets/javascripts/ponytail/ponytail.js +0 -15
  55. data/app/assets/javascripts/ponytail/views/column.js +0 -36
  56. data/app/assets/javascripts/ponytail/views/migration_file.js +0 -24
  57. data/app/assets/javascripts/ponytail/views/new_migrations.js +0 -36
  58. data/app/assets/javascripts/ponytail/views/table.js +0 -61
  59. data/app/assets/stylesheets/ponytail/application.css +0 -126
  60. data/app/views/ponytail/migrations/_column.html.erb +0 -22
  61. data/app/views/ponytail/migrations/_migration.html.erb +0 -13
  62. data/app/views/ponytail/migrations/_migration_file.html.erb +0 -23
  63. data/app/views/ponytail/migrations/_new_errors.html.erb +0 -10
  64. data/app/views/ponytail/migrations/_notice.html.erb +0 -6
  65. data/app/views/ponytail/migrations/_table.html.erb +0 -18
  66. data/app/views/ponytail/migrations/_table_view_template.html.erb +0 -23
  67. data/spec/javascripts/ponytail/models/command_spec.js +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94132f249283a8a919796eec99b3660e6d29d678
4
- data.tar.gz: 3de14204fe0395266f3fe963894066fcfb4f12dd
3
+ metadata.gz: 9553f78286daeb6dc406f9e022908bc3ac78ecae
4
+ data.tar.gz: e81493dda4b5607c352910c9cb65750535cc0b30
5
5
  SHA512:
6
- metadata.gz: f77a34fa6dcf200a6f472760dfc9e033bfd0fef33ac528b0fd0e3614225fc4f333a4a194f10899231435c9d446c681586f4f2aef00383659f6ccd141344c4829
7
- data.tar.gz: 1cf8b14224488416a548eafd44f5d1deb69840a94972c797a5c0dec000ebecf8d8994d95ab3f9e633261b1b221d645c9751a951f8d692f1a2450b13683a567c5
6
+ metadata.gz: 1fd9a32b54437ce171f4926898036523b024ab7a2887d7f563bc8beed55a626898b30c55cf069238a0f07371707064e6c8ad6af132f46b4124f84859747264f2
7
+ data.tar.gz: 6b103807b2e771c6542d9f185c021b6df345c6796938a7f30d5100c015f2d0242bb8e8eeb75bd40128a604d0a5f77a83dd2e7b69211922257c51a0b138819de9
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
data/.travis.yml CHANGED
@@ -8,3 +8,14 @@ branches:
8
8
  - feature/travis
9
9
  notifications:
10
10
  email: false
11
+ deploy:
12
+ provider: heroku
13
+ api_key:
14
+ secure: KNrZiAeHZ0ZX2QtRKYsgPeY9f+LGHw8AJOnKkQJ2/rJi7r4sWqFFkvqq6Kr9KzzjMwf+rtYyaRoF0e6iBEiETlBTpLD7HRKqNpL9EHMiWf1xYBt3C89MyOdyvP46lGp6Z8Bkc8HfYiPTkFc20XatIv/qH6qlMWSpBTyPg1DIQTw=
15
+ app: ponytail
16
+ on:
17
+ repo: sinsoku/ponytail
18
+ branch: develop
19
+ run:
20
+ - "rake db:migrate"
21
+ - restart
data/Gemfile CHANGED
@@ -1,4 +1,12 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ ruby '2.0.0'
4
+
3
5
  # Specify your gem's dependencies in ponytail.gemspec
4
6
  gemspec
7
+
8
+ group :production do
9
+ gem 'pg'
10
+ gem 'rails_12factor'
11
+ gem 'uglifier'
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,191 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ponytail (0.4.0)
5
+ coffee-rails (~> 4.0.0)
6
+ compass-rails
7
+ rails (~> 4.0.0)
8
+ sass-rails (~> 4.0.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ actionmailer (4.0.2)
14
+ actionpack (= 4.0.2)
15
+ mail (~> 2.5.4)
16
+ actionpack (4.0.2)
17
+ activesupport (= 4.0.2)
18
+ builder (~> 3.1.0)
19
+ erubis (~> 2.7.0)
20
+ rack (~> 1.5.2)
21
+ rack-test (~> 0.6.2)
22
+ activemodel (4.0.2)
23
+ activesupport (= 4.0.2)
24
+ builder (~> 3.1.0)
25
+ activerecord (4.0.2)
26
+ activemodel (= 4.0.2)
27
+ activerecord-deprecated_finders (~> 1.0.2)
28
+ activesupport (= 4.0.2)
29
+ arel (~> 4.0.0)
30
+ activerecord-deprecated_finders (1.0.3)
31
+ activesupport (4.0.2)
32
+ i18n (~> 0.6, >= 0.6.4)
33
+ minitest (~> 4.2)
34
+ multi_json (~> 1.3)
35
+ thread_safe (~> 0.1)
36
+ tzinfo (~> 0.3.37)
37
+ arel (4.0.1)
38
+ atomic (1.1.14)
39
+ builder (3.1.4)
40
+ capybara (2.2.0)
41
+ mime-types (>= 1.16)
42
+ nokogiri (>= 1.3.3)
43
+ rack (>= 1.0.0)
44
+ rack-test (>= 0.5.4)
45
+ xpath (~> 2.0)
46
+ childprocess (0.3.9)
47
+ ffi (~> 1.0, >= 1.0.11)
48
+ chunky_png (1.2.9)
49
+ coffee-rails (4.0.1)
50
+ coffee-script (>= 2.2.0)
51
+ railties (>= 4.0.0, < 5.0)
52
+ coffee-script (2.2.0)
53
+ coffee-script-source
54
+ execjs
55
+ coffee-script-source (1.6.3)
56
+ compass (0.12.2)
57
+ chunky_png (~> 1.2)
58
+ fssm (>= 0.2.7)
59
+ sass (~> 3.1)
60
+ compass-rails (1.1.3)
61
+ compass (>= 0.12.2)
62
+ coveralls (0.7.0)
63
+ multi_json (~> 1.3)
64
+ rest-client
65
+ simplecov (>= 0.7)
66
+ term-ansicolor
67
+ thor
68
+ diff-lcs (1.2.5)
69
+ docile (1.1.1)
70
+ erubis (2.7.0)
71
+ execjs (2.0.2)
72
+ ffi (1.9.3)
73
+ fssm (0.2.10)
74
+ hike (1.2.3)
75
+ i18n (0.6.9)
76
+ jasmine (1.3.2)
77
+ jasmine-core (~> 1.3.1)
78
+ rack (~> 1.0)
79
+ rspec (>= 1.3.1)
80
+ selenium-webdriver (>= 0.1.3)
81
+ jasmine-core (1.3.1)
82
+ json (1.8.1)
83
+ mail (2.5.4)
84
+ mime-types (~> 1.16)
85
+ treetop (~> 1.4.8)
86
+ mime-types (1.25.1)
87
+ mini_portile (0.5.2)
88
+ minitest (4.7.5)
89
+ multi_json (1.8.2)
90
+ nokogiri (1.6.1)
91
+ mini_portile (~> 0.5.0)
92
+ pg (0.17.1)
93
+ polyglot (0.3.3)
94
+ rack (1.5.2)
95
+ rack-test (0.6.2)
96
+ rack (>= 1.0)
97
+ rails (4.0.2)
98
+ actionmailer (= 4.0.2)
99
+ actionpack (= 4.0.2)
100
+ activerecord (= 4.0.2)
101
+ activesupport (= 4.0.2)
102
+ bundler (>= 1.3.0, < 2.0)
103
+ railties (= 4.0.2)
104
+ sprockets-rails (~> 2.0.0)
105
+ rails_12factor (0.0.2)
106
+ rails_serve_static_assets
107
+ rails_stdout_logging
108
+ rails_serve_static_assets (0.0.2)
109
+ rails_stdout_logging (0.0.3)
110
+ railties (4.0.2)
111
+ actionpack (= 4.0.2)
112
+ activesupport (= 4.0.2)
113
+ rake (>= 0.8.7)
114
+ thor (>= 0.18.1, < 2.0)
115
+ rake (10.1.1)
116
+ rest-client (1.6.7)
117
+ mime-types (>= 1.16)
118
+ rspec (2.14.1)
119
+ rspec-core (~> 2.14.0)
120
+ rspec-expectations (~> 2.14.0)
121
+ rspec-mocks (~> 2.14.0)
122
+ rspec-core (2.14.7)
123
+ rspec-expectations (2.14.4)
124
+ diff-lcs (>= 1.1.3, < 2.0)
125
+ rspec-mocks (2.14.4)
126
+ rspec-rails (2.14.0)
127
+ actionpack (>= 3.0)
128
+ activesupport (>= 3.0)
129
+ railties (>= 3.0)
130
+ rspec-core (~> 2.14.0)
131
+ rspec-expectations (~> 2.14.0)
132
+ rspec-mocks (~> 2.14.0)
133
+ rubyzip (1.1.0)
134
+ sass (3.2.13)
135
+ sass-rails (4.0.1)
136
+ railties (>= 4.0.0, < 5.0)
137
+ sass (>= 3.1.10)
138
+ sprockets-rails (~> 2.0.0)
139
+ selenium-webdriver (2.39.0)
140
+ childprocess (>= 0.2.5)
141
+ multi_json (~> 1.0)
142
+ rubyzip (~> 1.0)
143
+ websocket (~> 1.0.4)
144
+ simplecov (0.8.2)
145
+ docile (~> 1.1.0)
146
+ multi_json
147
+ simplecov-html (~> 0.8.0)
148
+ simplecov-html (0.8.0)
149
+ sprockets (2.10.1)
150
+ hike (~> 1.2)
151
+ multi_json (~> 1.0)
152
+ rack (~> 1.0)
153
+ tilt (~> 1.1, != 1.3.0)
154
+ sprockets-rails (2.0.1)
155
+ actionpack (>= 3.0)
156
+ activesupport (>= 3.0)
157
+ sprockets (~> 2.8)
158
+ sqlite3 (1.3.8)
159
+ term-ansicolor (1.2.2)
160
+ tins (~> 0.8)
161
+ thor (0.18.1)
162
+ thread_safe (0.1.3)
163
+ atomic
164
+ tilt (1.4.1)
165
+ tins (0.13.1)
166
+ treetop (1.4.15)
167
+ polyglot
168
+ polyglot (>= 0.3.1)
169
+ tzinfo (0.3.38)
170
+ uglifier (2.4.0)
171
+ execjs (>= 0.3.0)
172
+ json (>= 1.8.0)
173
+ websocket (1.0.7)
174
+ xpath (2.0.0)
175
+ nokogiri (~> 1.3)
176
+
177
+ PLATFORMS
178
+ ruby
179
+
180
+ DEPENDENCIES
181
+ bundler (~> 1.3)
182
+ capybara
183
+ coveralls
184
+ jasmine (~> 1.3)
185
+ pg
186
+ ponytail!
187
+ rails_12factor
188
+ rake
189
+ rspec-rails
190
+ sqlite3
191
+ uglifier
data/README.md CHANGED
@@ -42,6 +42,12 @@ $ cd spec/dummy
42
42
  $ rails s
43
43
  ```
44
44
 
45
+ ## Example site
46
+
47
+ Dummy app is deploying on heroku. However, you can not change the migration files and databases.
48
+
49
+ http://ponytail.herokuapp.com/rails/migrations
50
+
45
51
  ## Contributing
46
52
 
47
53
  1. Fork it
data/Rakefile CHANGED
@@ -1,10 +1,14 @@
1
1
  require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
- load "jasmine/tasks/jasmine.rake"
4
- ENV['JASMINE_SPEC_FORMAT'] = 'documentation'
2
+
3
+ if ENV['RAILS_ENV'] != "production"
4
+ require "rspec/core/rake_task"
5
+ load "jasmine/tasks/jasmine.rake"
6
+ ENV['JASMINE_SPEC_FORMAT'] = 'documentation'
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ task :default => [:spec, 'jasmine:ci']
11
+ end
5
12
 
6
13
  APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
7
14
  load 'rails/tasks/engine.rake'
8
- RSpec::Core::RakeTask.new(:spec)
9
-
10
- task :default => [:spec, 'jasmine:ci']
@@ -0,0 +1,41 @@
1
+ class Ponytail.Models.Column extends Backbone.Model
2
+ defaults:
3
+ type: "string",
4
+ name: "new_column",
5
+ isRemoved: false,
6
+ isAdded: false,
7
+
8
+ initialize: (attrs, options) ->
9
+ @beforeType = attrs.type || ""
10
+ @beforeName = attrs.name || ""
11
+ func = _.bind(attrs.table.trigger, attrs.table, "change")
12
+ @.bind("change", func)
13
+
14
+ isRemoved: ->
15
+ @.get("isRemoved") == true
16
+
17
+ isAdded: ->
18
+ @.get("isAdded") == true
19
+
20
+ isRename: ->
21
+ @beforeName != @.get("name")
22
+
23
+ isChangeType: ->
24
+ @beforeType != @.get("type")
25
+
26
+ getCommands: ->
27
+ table = @.get("table")
28
+ if @.isRemoved() && @.isAdded()
29
+ []
30
+ else if @.isRemoved()
31
+ [new Ponytail.Models.Command("remove_column", ":" + table.get("name"), ":" + @beforeName)]
32
+ else if @.isAdded()
33
+ [new Ponytail.Models.Command("add_column", ":" + table.get("name"), ":" + @.get("name"), ":" + @.get("type"))]
34
+ else
35
+ commands = []
36
+ if @.isRename()
37
+ commands.push(new Ponytail.Models.Command("rename_column", ":" + table.get("name"), ":" + @beforeName, ":" + @.get("name")))
38
+ if @.isChangeType()
39
+ commands.push(new Ponytail.Models.Command("change_column", ":" + table.get("name"), ":" + @.get("name"), ":" + @.get("type")))
40
+
41
+ commands
@@ -0,0 +1,5 @@
1
+ class Ponytail.Models.Command
2
+ constructor: (@args...) ->
3
+
4
+ toString: ->
5
+ "#{@args[0]} #{@args[1..].join(', ')}"
@@ -0,0 +1,11 @@
1
+ class Ponytail.Models.CreateTableCommand
2
+ constructor: (@tableName, @columns) ->
3
+
4
+ toString: ->
5
+ column_defs = ("t.#{column.get("type")} :#{column.get("name")}" for column in @columns)
6
+ return [
7
+ "create_table :#{@tableName} do |t|",
8
+ column_defs.join("\n").replace(/^/, " ").replace(/\n/g, "\n "),
9
+ " t.timestamps",
10
+ "end",
11
+ ].join("\n")
@@ -0,0 +1,5 @@
1
+ class Ponytail.Models.DropTableCommand
2
+ constructor: (@tableName) ->
3
+
4
+ toString: ->
5
+ new Ponytail.Models.Command("drop_table", ":#{@tableName}")
@@ -0,0 +1,38 @@
1
+ class Ponytail.Models.MigrationFile extends Backbone.Model
2
+ defaults:
3
+ className: ""
4
+ rawContent: ""
5
+
6
+ initialize: (attrs, options) ->
7
+ @tables = []
8
+ @.bind("change:className", @.update)
9
+
10
+ updateByTables: (tables) ->
11
+ @tables = tables
12
+ @.update()
13
+
14
+ update: =>
15
+ rawContent = [
16
+ "class #{@.get("className")} < ActiveRecord::Migration",
17
+ @.getContentOfClass(),
18
+ "end",
19
+ ].join("\n")
20
+ @.set({rawContent: rawContent})
21
+
22
+ getContentOfClass: ->
23
+ _.compact([
24
+ "def change",
25
+ @.getStringOfCommands(),
26
+ "end",
27
+ ]).join("\n").replace(/^/, " ").replace(/\n/g, "\n ")
28
+
29
+ getStringOfCommands: ->
30
+ commands = @.getCommands()
31
+ commands.map((command) ->
32
+ command.toString()
33
+ ).join("\n").replace(/^/, " ").replace(/\n/g, "\n ")
34
+
35
+ getCommands: ->
36
+ _.flatten(@tables.map((table) ->
37
+ table.getCommands()
38
+ ))
@@ -0,0 +1,5 @@
1
+ class Ponytail.Models.RenameTableCommand
2
+ constructor: (@tableName, @newName) ->
3
+
4
+ toString: ->
5
+ new Ponytail.Models.Command("rename_table", ":#{@tableName}", ":#{@newName}")
@@ -0,0 +1,42 @@
1
+ class Ponytail.Models.Table extends Backbone.Model
2
+ defaults:
3
+ name: "new_table"
4
+ columns: []
5
+ isDrop: false
6
+ isCreated: false
7
+
8
+ initialize: (attrs, options) ->
9
+ @beforeName = attrs.name || ""
10
+
11
+ isCreated: ->
12
+ @.get("isCreated") == true
13
+
14
+ isDrop: ->
15
+ @.get("isDrop") == true
16
+
17
+ isRename: ->
18
+ @.beforeName != @.get("name")
19
+
20
+ addColumn: (column) ->
21
+ columns = @.get("columns")
22
+ columns.push(column)
23
+ @.set({columns: columns})
24
+ @.trigger("change")
25
+
26
+ getCommands: ->
27
+ if (@.isCreated() && @.isDrop())
28
+ []
29
+ else if (@.isCreated() && !@.isDrop())
30
+ columns = (column for column in @.get("columns") when !column.isRemoved())
31
+ [new Ponytail.Models.CreateTableCommand(@.get("name"), columns)]
32
+ else if (!@.isCreated() && @.isDrop())
33
+ [new Ponytail.Models.DropTableCommand(@.beforeName)]
34
+ else
35
+ commands = []
36
+ if @.isRename()
37
+ commands.push(new Ponytail.Models.RenameTableCommand(@beforeName, @.get("name")))
38
+
39
+ for column in @.get("columns")
40
+ commands.push(column.getCommands())
41
+
42
+ _.compact(_.flatten(commands))
@@ -0,0 +1,5 @@
1
+ window.Ponytail =
2
+ Models: {}
3
+ Collections: {}
4
+ Views: {}
5
+ Routers: {}
@@ -0,0 +1,70 @@
1
+ class Ponytail.Views.Column extends Backbone.View
2
+ className: "column"
3
+ events:
4
+ "click .column_type": "clickColumnType"
5
+ "change .column_type select": "changeColumnTypeSelect"
6
+ "keyup .column_type select": "keyupColumnTypeSelect"
7
+ "blur .column_type": "blurColumnType"
8
+ "click .column_name": "clickColumnName"
9
+ "keyup .column_name input": "keyupColumnNameInput"
10
+ "blur .column_name": "blurColumnName"
11
+ "click .remove_column": "clickRemoveColumn"
12
+ "click .restore_column": "clickRestoreColumn"
13
+
14
+ initialize: ->
15
+ @model.bind("change", @render)
16
+
17
+ render: =>
18
+ if @el.parentNode == null
19
+ $(@el).html(_.template($("#column_template").html(), @model.attributes))
20
+ else
21
+ @$(".column_type span").text(@model.get("type"))
22
+ @$(".column_name span").text(@model.get("name"))
23
+ @
24
+
25
+ clickColumnType: ->
26
+ if @$(".column_type span").is(":visible")
27
+ @$("option[value='#{@model.get("type")}']").attr("selected", true)
28
+ @$(".column_type span").toggle()
29
+ @$(".column_type select").toggle()
30
+
31
+ changeColumnTypeSelect: (e) ->
32
+ @model.set({type: e.target.value})
33
+
34
+ keyupColumnTypeSelect: (e) ->
35
+ # 13(ENTER_KEY)
36
+ if e.which == 13
37
+ @.blurColumnType()
38
+
39
+ blurColumnType: ->
40
+ if @$(".column_type select").is(":visible")
41
+ @$(".column_type span").toggle()
42
+ @$(".column_type select").toggle()
43
+
44
+ clickColumnName: ->
45
+ if @$(".column_name span").is(":visible")
46
+ @$(".column_name span").toggle()
47
+ @$(".column_name input").toggle()
48
+
49
+ keyupColumnNameInput: (e) ->
50
+ @model.set({name: e.target.value})
51
+ # 13(ENTER_KEY)
52
+ if e.which == 13
53
+ @.blurColumnName()
54
+
55
+ blurColumnName: ->
56
+ if @$(".column_name input").is(":visible")
57
+ @$(".column_name span").toggle()
58
+ @$(".column_name input").toggle()
59
+
60
+ clickRemoveColumn: ->
61
+ @model.set({isRemoved: true})
62
+ @$(".remove_column").hide()
63
+ @$(".restore_column").show()
64
+ false
65
+
66
+ clickRestoreColumn: ->
67
+ @model.set({isRemoved: false})
68
+ @$(".remove_column").show()
69
+ @$(".restore_column").hide()
70
+ false
@@ -0,0 +1,29 @@
1
+ class Ponytail.Views.Index extends Backbone.View
2
+ events:
3
+ "click .close a": "closeNotice"
4
+ "click .migration_files .filename": "clickFileName"
5
+ "click .new_button": "clickNewButton"
6
+ "click .migrate_button": "clickMigrateButton"
7
+ "click .rollback_button": "clickRollbackButton"
8
+
9
+ closeNotice: ->
10
+ $(".notice").hide()
11
+ false
12
+
13
+ clickFileName: (e) ->
14
+ @$(".migration_file .migration_filename").text(e.target.innerHTML)
15
+ @$(".migration_file .migration_filename").removeClass("highlight")
16
+ setTimeout( ->
17
+ @$(".migration_file .migration_filename").addClass("highlight")
18
+ , 100)
19
+ raw_content = $(e.target).parent().find(".raw_content").text()
20
+ @$(".migration_file .raw_content pre").text(raw_content)
21
+
22
+ clickNewButton: ->
23
+ window.location.href = "migrations/new"
24
+
25
+ clickMigrateButton: ->
26
+ window.location.href = "migrations/migrate"
27
+
28
+ clickRollbackButton: ->
29
+ window.location.href = "migrations/rollback"
@@ -0,0 +1,25 @@
1
+ class Ponytail.Views.MigrationFile extends Backbone.View
2
+ events:
3
+ "click .edit_checkbox input": "clickEditCheckbox"
4
+ "keyup .classname input": (e) ->
5
+ @model.set({className: e.target.value})
6
+ "click .create_button": "clickCreateButton"
7
+
8
+ initialize: ->
9
+ @model.bind("change", @render)
10
+
11
+ render: =>
12
+ @$(".raw_content textarea").text(@model.get("rawContent"))
13
+
14
+ clickEditCheckbox: ->
15
+ disabled = @$(".raw_content textarea").is(":disabled")
16
+ @.setRawContentEnabled(disabled)
17
+
18
+ setRawContentEnabled: (enabled) ->
19
+ if enabled
20
+ @$(".raw_content textarea").removeAttr("disabled")
21
+ else
22
+ @$(".raw_content textarea").attr("disabled", "disabled")
23
+
24
+ clickCreateButton: ->
25
+ @.setRawContentEnabled(true)
@@ -0,0 +1,58 @@
1
+ class Ponytail.Views.New extends Backbone.View
2
+ events:
3
+ "click .close a": "closeNotice"
4
+ "click .table_name": "clickTableName"
5
+ "click .new_table a": "clickNewTable"
6
+
7
+ initialize: ->
8
+ @tables = []
9
+
10
+ render: =>
11
+ for el in @$(".table")
12
+ name = $(el).find('.table_name span').text()
13
+ table = new Ponytail.Models.Table({name: name})
14
+ new Ponytail.Views.Table({el: el, model: table})
15
+ columns = []
16
+ for el2 in $(el).find(".column")
17
+ column_type = $(el2).find(".column_type span").text()
18
+ column_name = $(el2).find(".column_name span").text()
19
+ column = new Ponytail.Models.Column({table: table, type: column_type, name: column_name})
20
+ new Ponytail.Views.Column({el: el2, model: column})
21
+ columns.push(column)
22
+ table.set({columns: columns}, {silent: true})
23
+ @tables.push(table)
24
+
25
+ class_name = @$(".classname input")[0].value
26
+ @migrationFile = new Ponytail.Models.MigrationFile({className: class_name})
27
+ new Ponytail.Views.MigrationFile({el: @$(".migration_file"), model: @migrationFile})
28
+ @migrationFile.update()
29
+
30
+ for table in @tables
31
+ table.bind("change", =>
32
+ @migrationFile.updateByTables(@tables)
33
+ )
34
+ @
35
+
36
+ closeNotice: ->
37
+ $(".notice").hide()
38
+ false
39
+
40
+ clickTableName: (e) ->
41
+ tableElem = $(e.target).parent().parent()
42
+ columnsElem = tableElem.find(".columns")
43
+ if columnsElem.is(':visible')
44
+ columnsElem.slideUp()
45
+ else
46
+ columnsElem.slideDown()
47
+
48
+ clickNewTable: ->
49
+ table = new Ponytail.Models.Table({isCreated: true})
50
+ @tables.push(table)
51
+ table.bind("change", =>
52
+ @migrationFile.updateByTables(@tables)
53
+ )
54
+ table.trigger("change")
55
+
56
+ view = new Ponytail.Views.Table({model: table})
57
+ @$(".new_table").before(view.render().el)
58
+ false
@@ -0,0 +1,56 @@
1
+ class Ponytail.Views.Table extends Backbone.View
2
+ className: "table"
3
+ events:
4
+ "click .edit_table": "clickEditTable"
5
+ "click .table_name span": "clickEditTable"
6
+ "keyup .table_name input": "keyupTableNameInput"
7
+ "blur .table_name input": "blurTableName"
8
+ "click .drop_table": "clickDropTable"
9
+ "click .restore_table": "clickRestoreTable"
10
+ "click .add_column a": "clickAddColumn"
11
+
12
+ initialize: ->
13
+ @model.bind("change", @render)
14
+
15
+ render: =>
16
+ if @el.parentNode == null
17
+ $(@el).html(_.template($("#table_template").html(), @model.attributes))
18
+ else
19
+ @$(".table_name span").text(@model.get("name"))
20
+ @
21
+
22
+ clickEditTable: ->
23
+ if @$(".table_name span").is(":visible")
24
+ @$(".table_name span").toggle()
25
+ @$(".table_name input").toggle()
26
+ false
27
+
28
+ keyupTableNameInput: (e) ->
29
+ @model.set({name: e.target.value})
30
+ # 13(ENTER_KEY)
31
+ if e.which == 13
32
+ @.blurTableName()
33
+
34
+ blurTableName: ->
35
+ if @$(".table_name input").is(":visible")
36
+ @$(".table_name span").toggle()
37
+ @$(".table_name input").toggle()
38
+
39
+ clickDropTable: ->
40
+ @model.set({isDrop: true})
41
+ @$(".drop_table").hide()
42
+ @$(".restore_table").show()
43
+ false
44
+
45
+ clickRestoreTable: ->
46
+ @model.set({isDrop: false})
47
+ @$(".drop_table").show()
48
+ @$(".restore_table").hide()
49
+ false
50
+
51
+ clickAddColumn: ->
52
+ column = new Ponytail.Models.Column({table: @model, isAdded: true})
53
+ view = new Ponytail.Views.Column({model: column})
54
+ @$(".add_column").before(view.render().el)
55
+ @model.addColumn(column)
56
+ false