ponytail 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/README.md +8 -0
  4. data/Rakefile +2 -0
  5. data/app/assets/javascripts/ponytail/application.js +9 -0
  6. data/app/assets/javascripts/ponytail/collections/.keep +0 -0
  7. data/app/assets/javascripts/ponytail/models/column.js +43 -6
  8. data/app/assets/javascripts/ponytail/models/command.js +8 -0
  9. data/app/assets/javascripts/ponytail/models/create_table_command.js +16 -0
  10. data/app/assets/javascripts/ponytail/models/drop_table_command.js +8 -0
  11. data/app/assets/javascripts/ponytail/models/migration_file.js +36 -20
  12. data/app/assets/javascripts/ponytail/models/rename_table_command.js +9 -0
  13. data/app/assets/javascripts/ponytail/models/table.js +32 -28
  14. data/app/assets/javascripts/ponytail/ponytail.js +15 -0
  15. data/app/assets/javascripts/ponytail/routers/.keep +0 -0
  16. data/app/assets/javascripts/ponytail/views/column.js +36 -0
  17. data/app/assets/javascripts/ponytail/views/migration_file.js +24 -0
  18. data/app/assets/javascripts/ponytail/views/new_migrations.js +36 -0
  19. data/app/assets/javascripts/ponytail/views/table.js +61 -0
  20. data/app/assets/stylesheets/ponytail/application.css +2 -2
  21. data/app/controllers/ponytail/migrations_controller.rb +7 -0
  22. data/app/views/ponytail/migrations/_column.html.erb +22 -0
  23. data/app/views/ponytail/migrations/_column_view_template.html.erb +22 -0
  24. data/app/views/ponytail/migrations/_migration.html.erb +1 -0
  25. data/app/views/ponytail/migrations/_migration_file.html.erb +23 -0
  26. data/app/views/ponytail/migrations/_table.html.erb +7 -6
  27. data/app/views/ponytail/migrations/_table_view_template.html.erb +23 -0
  28. data/app/views/ponytail/migrations/index.html.erb +1 -2
  29. data/app/views/ponytail/migrations/new.html.erb +6 -26
  30. data/lib/ponytail/migration.rb +4 -0
  31. data/lib/ponytail/version.rb +1 -1
  32. data/lib/rails/mapper.rb +1 -1
  33. data/ponytail.gemspec +4 -2
  34. data/spec/controllers/migrations_controller_spec.rb +1 -1
  35. data/spec/dummy/README.rdoc +28 -0
  36. data/spec/dummy/Rakefile +6 -0
  37. data/spec/dummy/app/assets/images/.keep +0 -0
  38. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  39. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  40. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  41. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  42. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  43. data/spec/dummy/app/mailers/.keep +0 -0
  44. data/spec/dummy/app/models/.keep +0 -0
  45. data/spec/dummy/app/models/concerns/.keep +0 -0
  46. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  47. data/spec/dummy/bin/bundle +3 -0
  48. data/spec/dummy/bin/rails +4 -0
  49. data/spec/dummy/bin/rake +4 -0
  50. data/spec/dummy/config/application.rb +23 -0
  51. data/spec/dummy/config/boot.rb +5 -0
  52. data/spec/dummy/config/database.yml +25 -0
  53. data/spec/dummy/config/environment.rb +5 -0
  54. data/spec/dummy/config/environments/development.rb +29 -0
  55. data/spec/dummy/config/environments/production.rb +80 -0
  56. data/spec/dummy/config/environments/test.rb +36 -0
  57. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  58. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  59. data/spec/dummy/config/initializers/inflections.rb +16 -0
  60. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  61. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  62. data/spec/dummy/config/initializers/session_store.rb +3 -0
  63. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  64. data/spec/dummy/config/locales/en.yml +23 -0
  65. data/spec/dummy/config/routes.rb +2 -0
  66. data/spec/dummy/config.ru +4 -0
  67. data/spec/dummy/db/migrate/20131202142657_create_users.rb +10 -0
  68. data/spec/dummy/db/migrate/20131202142714_create_books.rb +10 -0
  69. data/spec/dummy/db/schema.rb +30 -0
  70. data/spec/dummy/lib/assets/.keep +0 -0
  71. data/spec/dummy/log/.keep +0 -0
  72. data/spec/dummy/public/404.html +58 -0
  73. data/spec/dummy/public/422.html +58 -0
  74. data/spec/dummy/public/500.html +57 -0
  75. data/spec/dummy/public/favicon.ico +0 -0
  76. data/spec/features/migrations/index_spec.rb +8 -0
  77. data/spec/javascripts/helpers/build_model.js +11 -0
  78. data/spec/javascripts/ponytail/models/column_spec.js +0 -12
  79. data/spec/javascripts/ponytail/models/command_spec.js +8 -0
  80. data/spec/javascripts/ponytail/models/create_command_spec.js +16 -0
  81. data/spec/javascripts/ponytail/models/migration_file_spec.js +12 -5
  82. data/spec/javascripts/ponytail/models/table_spec.js +15 -24
  83. data/spec/javascripts/support/jasmine.yml +6 -1
  84. data/spec/spec_helper.rb +6 -1
  85. data/vendor/assets/javascripts/backbone-min.js +2 -0
  86. data/vendor/assets/javascripts/jquery.min.js +6 -0
  87. data/vendor/assets/javascripts/jquery_ujs.js +394 -0
  88. data/vendor/assets/javascripts/underscore-min.js +6 -0
  89. metadata +140 -15
  90. data/app/assets/javascripts/ponytail/index.js +0 -20
  91. data/app/assets/javascripts/ponytail/models/create_table.js +0 -13
  92. data/app/assets/javascripts/ponytail/models/rename_table.js +0 -8
  93. data/app/assets/javascripts/ponytail/views/migration_file_view.js +0 -39
  94. data/app/assets/javascripts/ponytail/views/new_migration_view.js +0 -60
  95. data/app/assets/javascripts/ponytail/views/table_view.js +0 -68
  96. data/spec/javascripts/ponytail/views/migration_file_view_spec.js +0 -17
  97. data/spec/javascripts/ponytail/views/new_migration_view_spec.js +0 -17
  98. data/spec/javascripts/ponytail/views/table_view_spec.js +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63ccf892a7224116f88fbfb4e4464ab153371fb2
4
- data.tar.gz: f793e36362e8aa589b1878ad6d32f9c1aa7e9f31
3
+ metadata.gz: 94132f249283a8a919796eec99b3660e6d29d678
4
+ data.tar.gz: 3de14204fe0395266f3fe963894066fcfb4f12dd
5
5
  SHA512:
6
- metadata.gz: f35510c6f836ea0a6c57ffc51fdfe246d60c030b09a31baac486c9bb75e8dc3197547d8c8c3174e2ab2822b247ba33ef2bc8edb15d6604438002ed861757cb0d
7
- data.tar.gz: 44ac79a3da84c19460800b52219301f796ebcb27d0ab47852053aa801db6071ac7f5eb02ad5ebbfca8da59ce6128580ed7d62dcca54076417f746fa5d4fce5f1
6
+ metadata.gz: f77a34fa6dcf200a6f472760dfc9e033bfd0fef33ac528b0fd0e3614225fc4f333a4a194f10899231435c9d446c681586f4f2aef00383659f6ccd141344c4829
7
+ data.tar.gz: 1cf8b14224488416a548eafd44f5d1deb69840a94972c797a5c0dec000ebecf8d8994d95ab3f9e633261b1b221d645c9751a951f8d692f1a2450b13683a567c5
data/.gitignore CHANGED
@@ -17,3 +17,5 @@ test/version_tmp
17
17
  tmp
18
18
 
19
19
  /vendor/bundle
20
+ *.sqlite3
21
+ log
data/README.md CHANGED
@@ -34,6 +34,14 @@ Comment out `config.active_record.migration_error` in `config/environments/devel
34
34
 
35
35
  Visit `/rails/migrations` in your app.
36
36
 
37
+ ## How to work dummy app
38
+
39
+ ```bash
40
+ $ rake db:migrate:reset
41
+ $ cd spec/dummy
42
+ $ rails s
43
+ ```
44
+
37
45
  ## Contributing
38
46
 
39
47
  1. Fork it
data/Rakefile CHANGED
@@ -3,6 +3,8 @@ require "rspec/core/rake_task"
3
3
  load "jasmine/tasks/jasmine.rake"
4
4
  ENV['JASMINE_SPEC_FORMAT'] = 'documentation'
5
5
 
6
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
7
+ load 'rails/tasks/engine.rake'
6
8
  RSpec::Core::RakeTask.new(:spec)
7
9
 
8
10
  task :default => [:spec, 'jasmine:ci']
@@ -1 +1,10 @@
1
+ //= require jquery.min
2
+ //= require jquery_ujs
3
+ //= require underscore-min
4
+ //= require backbone-min
5
+ //= require ./ponytail
6
+ //= require_tree ./models
7
+ //= require_tree ./collections
8
+ //= require_tree ./views
9
+ //= require_tree ./routers
1
10
  //= require_tree .
File without changes
@@ -1,6 +1,43 @@
1
- function Column(option) {
2
- this.name = option.name;
3
- this.type = option.type;
4
- }
5
- Column.prototype = {
6
- };
1
+ Ponytail.Models.Column = Backbone.Model.extend({
2
+ defaults: {
3
+ type: "string",
4
+ name: "new_column",
5
+ isRemoved: false,
6
+ isAdded: false,
7
+ },
8
+ initialize: function (attrs, options) {
9
+ this.beforeType = attrs.type || "";
10
+ this.beforeName = attrs.name || "";
11
+ var func = _.bind(attrs.table.trigger, attrs.table, "change");
12
+ this.bind("change", func);
13
+ },
14
+ isRemoved: function() {
15
+ return this.get("isRemoved") === true;
16
+ },
17
+ isAdded: function() {
18
+ return this.get("isAdded") === true;
19
+ },
20
+ isRename: function() {
21
+ return this.beforeName != this.get("name");
22
+ },
23
+ isChangeType: function() {
24
+ return this.beforeType != this.get("type");
25
+ },
26
+ getCommands: function() {
27
+ var table = this.get("table");
28
+ if (this.isRemoved()) {
29
+ return [new Ponytail.Models.Command("remove_column", ":" + table.get("name"), ":" + this.beforeName)];
30
+ } else if (this.isAdded()) {
31
+ return [new Ponytail.Models.Command("add_column", ":" + table.get("name"), ":" + this.get("name"), ":" + this.get("type"))];
32
+ } else {
33
+ var commands = [];
34
+ if (this.isRename()) {
35
+ commands.push(new Ponytail.Models.Command("rename_column", ":" + table.get("name"), ":" + this.beforeName, ":" + this.get("name")));
36
+ }
37
+ if (this.isChangeType()) {
38
+ commands.push(new Ponytail.Models.Command("change_column", ":" + table.get("name"), ":" + this.get("name"), ":" + this.get("type")));
39
+ }
40
+ return commands;
41
+ }
42
+ },
43
+ });
@@ -0,0 +1,8 @@
1
+ Ponytail.Models.Command = function() {
2
+ this.args = Array.prototype.slice.call(arguments);
3
+ };
4
+ Ponytail.Models.Command.prototype = {
5
+ toString: function() {
6
+ return this.args.shift() + " " + this.args.join(", ");
7
+ }
8
+ };
@@ -0,0 +1,16 @@
1
+ Ponytail.Models.CreateTableCommand = function(tableName, columns) {
2
+ this.tableName = tableName;
3
+ this.columns = columns;
4
+ };
5
+ Ponytail.Models.CreateTableCommand.prototype = {
6
+ toString: function() {
7
+ return [
8
+ "create_table :" + this.tableName + " do |t|",
9
+ this.columns.map(function(column) {
10
+ return "t." + column.get("type") + " :" + column.get("name");
11
+ }).join("\n").replace(/^/, " ").replace(/\n/g, "\n "),
12
+ " t.timestamps",
13
+ "end",
14
+ ].join("\n");
15
+ }
16
+ };
@@ -0,0 +1,8 @@
1
+ Ponytail.Models.DropTableCommand = function(tableName) {
2
+ this.tableName = tableName;
3
+ };
4
+ Ponytail.Models.DropTableCommand.prototype = {
5
+ toString: function() {
6
+ return new Ponytail.Models.Command("drop_table", ":" + this.tableName);
7
+ }
8
+ };
@@ -1,24 +1,40 @@
1
- function MigrationFile() {
2
- this.className = "";
3
- this.commands = [];
4
- }
5
- MigrationFile.prototype = {
6
- setClassName: function(className) {
7
- this.className = className;
1
+ Ponytail.Models.MigrationFile = Backbone.Model.extend({
2
+ defaults: {
3
+ className: "",
4
+ rawContent: "",
8
5
  },
9
- toString: function() {
10
- return ["class " + this.className + " < ActiveRecord::Migration",
11
- " def change",
12
- this.toStringOfCommands(),
13
- " end",
14
- "end"].join("\n");
6
+ initialize: function(attrs, options) {
7
+ this.tables = [];
8
+ this.bind("change:className", this.update);
15
9
  },
16
- addCommand: function(command) {
17
- this.commands.push(command);
10
+ updateByTables: function(tables) {
11
+ this.tables = tables;
12
+ this.update();
18
13
  },
19
- toStringOfCommands: function() {
20
- return this.commands.map(function(command) {
14
+ update: function() {
15
+ var rawContent = [
16
+ "class " + this.get("className") + " < ActiveRecord::MigrationFile",
17
+ this.getContentOfClass(),
18
+ "end",
19
+ ].join("\n");
20
+ this.set({"rawContent": rawContent});
21
+ },
22
+ getContentOfClass: function() {
23
+ return _.compact([
24
+ "def change",
25
+ this.getStringOfCommands(),
26
+ "end",
27
+ ]).join("\n").replace(/^/, " ").replace(/\n/g, "\n ");
28
+ },
29
+ getStringOfCommands: function() {
30
+ var commands = this.getCommands();
31
+ return commands.map(function(command) {
21
32
  return command.toString();
22
- }).join("\n").replace(/^/, " ").replace(/\n/g, "\n ");
23
- }
24
- };
33
+ }).join("\n").replace(/^/, " ").replace(/\n/g, "\n ");
34
+ },
35
+ getCommands: function() {
36
+ return _.flatten(this.tables.map(function(table) {
37
+ return table.getCommands();
38
+ }));
39
+ },
40
+ });
@@ -0,0 +1,9 @@
1
+ Ponytail.Models.RenameTableCommand = function(tableName, newName) {
2
+ this.tableName = tableName;
3
+ this.newName = newName;
4
+ };
5
+ Ponytail.Models.RenameTableCommand.prototype = {
6
+ toString: function() {
7
+ return new Ponytail.Models.Command("rename_table", ":" + this.tableName, ":" + this.newName);
8
+ }
9
+ };
@@ -1,40 +1,44 @@
1
- function Table(option) {
2
- if (option === undefined) { option = {}; }
3
- this.beforeTableName = option.tableName;
4
- this.tableName = option.tableName;
5
- this._isSaved = option.isSaved;
6
- this._drop = false;
7
- this.columns = [];
8
- }
9
- Table.prototype = {
10
- isSaved: function() {
11
- return this._isSaved ? true : false;
1
+ Ponytail.Models.Table = Backbone.Model.extend({
2
+ defaults: {
3
+ name: "new_table",
4
+ columns: [],
5
+ isDrop: false,
6
+ isCreated: false,
7
+ },
8
+ initialize: function (attrs, options) {
9
+ this.beforeName = attrs.name || "";
10
+ },
11
+ isCreated: function() {
12
+ return this.get("isCreated") === true;
12
13
  },
13
14
  isDrop: function() {
14
- return this._drop;
15
+ return this.get("isDrop") === true;
15
16
  },
16
- drop: function() {
17
- this._drop = true;
17
+ isRename: function() {
18
+ return this.beforeName != this.get("name");
18
19
  },
19
20
  addColumn: function(column) {
20
- this.columns.push(column);
21
+ var columns = this.get("columns");
22
+ columns.push(column);
23
+ this.set({columns: columns});
24
+ this.trigger("change");
21
25
  },
22
26
  getCommands: function() {
23
- if (this.isDrop() && this.isSaved()) {
24
- return [new Command("drop_table", ":" + this.beforeTableName)];
25
- } else if (this.isDrop() && !this.isSaved()) {
27
+ if (this.isCreated() && this.isDrop()) {
26
28
  return [];
27
- } else if (this.isSaved()) {
29
+ } else if (this.isCreated() && !this.isDrop()) {
30
+ return [new Ponytail.Models.CreateTableCommand(this.get("name"), this.get("columns"))];
31
+ } else if (!this.isCreated() && this.isDrop()) {
32
+ return [new Ponytail.Models.DropTableCommand(this.beforeName)];
33
+ } else {
28
34
  var commands = [];
29
- if (this.beforeTableName != this.tableName) {
30
- commands.push(new Command("rename_table", ":" + this.beforeTableName, ":" + this.tableName));
35
+ if (this.isRename()) {
36
+ commands.push(new Ponytail.Models.RenameTableCommand(this.beforeName, this.get("name")));
31
37
  }
32
- // TODO: add_column, ...etc
33
- return commands;
34
- } else {
35
- var command = new CreateTable();
36
- command.setTableName(this.tableName);
37
- return [command];
38
+ this.get("columns").forEach(function(column) {
39
+ commands.push(column.getCommands());
40
+ });
41
+ return _.compact(_.flatten(commands));
38
42
  }
39
43
  }
40
- };
44
+ });
@@ -0,0 +1,15 @@
1
+ window.Ponytail = {
2
+ Models: {},
3
+ Collections: {},
4
+ Views: {},
5
+ Routers: {},
6
+ };
7
+
8
+ function setupIndex() {
9
+ $(".pt_close_notice").click(function() {
10
+ $(".pt_notice").hide();
11
+ });
12
+ $(".pt_name, .pt_filename").click(function() {
13
+ $(".pt_raw_content", $(this).parent().parent()).toggle();
14
+ });
15
+ }
File without changes
@@ -0,0 +1,36 @@
1
+ Ponytail.Views.ColumnView = Backbone.View.extend({
2
+ className: 'pt_column',
3
+ events: {
4
+ "click .pt_column_type span": "toggleColumnType",
5
+ "blur .pt_column_type select": "changeColumnType",
6
+ "click .pt_column_name span": "toggleColumnName",
7
+ "keyup .pt_column_name input": function(e) { this.model.set({name: e.target.value}); },
8
+ "blur .pt_column_name input": "toggleColumnName",
9
+ },
10
+ initialize: function(options) {
11
+ _.bindAll(this, "render");
12
+ this.model.bind("change", this.render);
13
+ },
14
+ render: function() {
15
+ if (this.el.parentNode === null) {
16
+ $(this.el).html(_.template($("#column_view_template").html(), this.model.attributes));
17
+ } else {
18
+ $(this.el).find(".pt_column_type span").text(this.model.get("type"));
19
+ $(this.el).find(".pt_column_name span").text(this.model.get("name"));
20
+ }
21
+ $(this.el).find(".pt_column_type option[value='" + this.model.get("type") + "']").attr("selected", true);
22
+ return this;
23
+ },
24
+ toggleColumnType: function() {
25
+ $(this.el).find(".pt_column_type span").toggle();
26
+ $(this.el).find(".pt_column_type select").toggle();
27
+ },
28
+ changeColumnType: function(e) {
29
+ this.model.set({type: e.target.value});
30
+ this.toggleColumnType();
31
+ },
32
+ toggleColumnName: function() {
33
+ $(this.el).find(".pt_column_name span").toggle();
34
+ $(this.el).find(".pt_column_name input").toggle();
35
+ }
36
+ });
@@ -0,0 +1,24 @@
1
+ Ponytail.Views.MigrationFileView = Backbone.View.extend({
2
+ events: {
3
+ "click .pt_edit_checkbox input": "toggleRawContent",
4
+ "click .pt_submit": function() { this.setRawContentEnabled(true); },
5
+ "keyup .pt_class_name input": function(e) { this.model.set({className: e.target.value}); },
6
+ },
7
+ initialize: function(options) {
8
+ _.bindAll(this, "render");
9
+ this.model.bind("change", this.render);
10
+ },
11
+ render: function() {
12
+ $(".pt_raw_content textarea").text(this.model.get("rawContent"));
13
+ },
14
+ toggleRawContent: function() {
15
+ this.setRawContentEnabled($(".pt_raw_content textarea").attr("disabled"));
16
+ },
17
+ setRawContentEnabled: function(enabled) {
18
+ if (enabled) {
19
+ $(".pt_raw_content textarea").removeAttr("disabled");
20
+ } else {
21
+ $(".pt_raw_content textarea").attr("disabled", "disabled");
22
+ }
23
+ },
24
+ });
@@ -0,0 +1,36 @@
1
+ Ponytail.Views.NewMigrationView = Backbone.View.extend({
2
+ events: {
3
+ "click .pt_new_table a": "appendTableView"
4
+ },
5
+ initialize: function() {
6
+ var tables = [];
7
+ $(".pt_table").each(function() {
8
+ var name = $(this).find(".pt_table_name span").text();
9
+ var m = new Ponytail.Models.Table({name: name});
10
+ tables.push(m);
11
+ new Ponytail.Views.TableView({el: $(this), model: m});
12
+ });
13
+ var migrationFile = new Ponytail.Models.MigrationFile();
14
+ new Ponytail.Views.MigrationFileView({el: $(".migration_file_view"), model: migrationFile});
15
+ tables.forEach(function(table) {
16
+ table.bind("change", function() {
17
+ migrationFile.updateByTables(tables);
18
+ });
19
+ });
20
+ this.tables = tables;
21
+ this.migrationFile = migrationFile;
22
+ },
23
+ appendTableView: function() {
24
+ var tables = this.tables;
25
+ var migrationFile = this.migrationFile;
26
+ var m = new Ponytail.Models.Table({isCreated: true});
27
+ tables.push(m);
28
+ m.bind("change", function() {
29
+ migrationFile.updateByTables(tables);
30
+ });
31
+ m.trigger("change");
32
+ var v = new Ponytail.Views.TableView({model: m});
33
+ $(".pt_new_table").before(v.render().el);
34
+ return false;
35
+ }
36
+ });
@@ -0,0 +1,61 @@
1
+ Ponytail.Views.TableView = Backbone.View.extend({
2
+ className: "pt_table",
3
+ events: {
4
+ "click .pt_table_name span": "toggleTableName",
5
+ "keyup .pt_table_name input": function(e) { this.model.set({name: e.target.value}); },
6
+ "blur .pt_table_name input": "toggleTableName",
7
+ "click .pt_drop_table": "dropTable",
8
+ "click .pt_restore_table": "restoreTable",
9
+ "click .pt_add_column": "addColumn",
10
+ },
11
+ initialize: function(options) {
12
+ _.bindAll(this, "render");
13
+ this.model.bind("change", this.render);
14
+ var table = this.model;
15
+ var columns = [];
16
+ _.each($(this.el).find(".pt_column"), function(elem) {
17
+ var type = $(elem).find(".pt_column_type span").text();
18
+ var name = $(elem).find(".pt_column_name span").text();
19
+ var m = new Ponytail.Models.Column({table: table, type: type, name: name});
20
+ new Ponytail.Views.ColumnView({el: elem, model: m}).render();
21
+ columns.push(m);
22
+ });
23
+ this.model.set({columns: columns}, {silent: true});
24
+ },
25
+ render: function() {
26
+ if (this.el.parentNode === null) {
27
+ $(this.el).html(_.template($("#table_view_template").html(), this.model.attributes));
28
+ } else {
29
+ $(this.el).find(".pt_table_name span").text(this.model.get("name"));
30
+ }
31
+ return this;
32
+ },
33
+ updateTableName: function() {
34
+ var v = $(this.el).find(".pt_table_name input")[0].value;
35
+ $(this.el).find(".pt_table_name span").text(v);
36
+ this.model.set({name: v});
37
+ },
38
+ toggleTableName: function() {
39
+ $(this.el).find(".pt_table_name span").toggle();
40
+ $(this.el).find(".pt_table_name input").toggle();
41
+ },
42
+ dropTable: function(e) {
43
+ this.model.set({isDrop: true});
44
+ $(this.el).find(".pt_drop_table").hide();
45
+ $(this.el).find(".pt_restore_table").show();
46
+ return false;
47
+ },
48
+ restoreTable: function(e) {
49
+ this.model.set({isDrop: false});
50
+ $(this.el).find(".pt_drop_table").show();
51
+ $(this.el).find(".pt_restore_table").hide();
52
+ return false;
53
+ },
54
+ addColumn: function(e) {
55
+ var column = new Ponytail.Models.Column({table: this.model, isAdded: true});
56
+ var view = new Ponytail.Views.ColumnView({model: column});
57
+ $(this.el).find(".pt_columns").append(view.render().el);
58
+ this.model.addColumn(column);
59
+ return false;
60
+ }
61
+ });
@@ -87,8 +87,8 @@
87
87
  font-weight: bold;
88
88
  }
89
89
 
90
- .pt_new .pt_schema .pt_table_name input {
91
- display: none;
90
+ .pt_new .pt_schema span {
91
+ cursor: pointer;
92
92
  }
93
93
 
94
94
  .pt_new .pt_schema .pt_new_table {
@@ -23,6 +23,13 @@ module Ponytail
23
23
  end
24
24
  end
25
25
 
26
+ def destroy
27
+ # TODO: fix params[:id]
28
+ @migration = Migration.all.select { |x| x.version == params[:id].to_i }.first
29
+ @migration.destroy
30
+ redirect_to :migrations, notice: 'Migration was successfully deleted.'
31
+ end
32
+
26
33
  def migrate
27
34
  if Migration.migrate
28
35
  redirect_to :migrations, notice: 'Migrate was succeed.'
@@ -0,0 +1,22 @@
1
+ <div class="pt_column">
2
+ <div class="pt_column_type">
3
+ <span><%= column.type %></span>
4
+ <select style="display: none;">
5
+ <option value="string">string</option>
6
+ <option value="text">text</option>
7
+ <option value="integer">integer</option>
8
+ <option value="float">float</option>
9
+ <option value="decimal">decimal</option>
10
+ <option value="datetime">datetime</option>
11
+ <option value="timestamp">timestamp</option>
12
+ <option value="time">time</option>
13
+ <option value="date">date</option>
14
+ <option value="binary">binary</option>
15
+ <option value="boolean">boolean</option>
16
+ </select>
17
+ </div>
18
+ <div class="pt_column_name">
19
+ <span><%= column.name %></span>
20
+ <input type="text" value="<%= column.name %>" style="display: none;" />
21
+ </div>
22
+ </div>
@@ -0,0 +1,22 @@
1
+ <script type="text/template" id="column_view_template">
2
+ <div class="pt_column_type">
3
+ <span style="display: none;"><%%= type %></span>
4
+ <select>
5
+ <option value="string">string</option>
6
+ <option value="text">text</option>
7
+ <option value="integer">integer</option>
8
+ <option value="float">float</option>
9
+ <option value="decimal">decimal</option>
10
+ <option value="datetime">datetime</option>
11
+ <option value="timestamp">timestamp</option>
12
+ <option value="time">time</option>
13
+ <option value="date">date</option>
14
+ <option value="binary">binary</option>
15
+ <option value="boolean">boolean</option>
16
+ </select>
17
+ </div>
18
+ <div class="pt_column_name">
19
+ <span style="display: none;"><%%= name %></span>
20
+ <input type="text" value="<%%= name %>" />
21
+ </div>
22
+ </script>
@@ -4,6 +4,7 @@
4
4
  <div class="pt_migration_header">
5
5
  <span class="pt_name"><%= migration.name %></span>
6
6
  <span class="pt_filename"><%= migration.filename %></span>
7
+ <%= link_to 'delete', migration_path(migration.version), method: :delete, confirm: 'Are you sure?' %>
7
8
  </div>
8
9
  <div class="pt_raw_content">
9
10
  <pre><%= migration.raw_content %></pre>
@@ -0,0 +1,23 @@
1
+ <%= form_for migration, url: migrations_path do |f| %>
2
+ <%= render 'new_errors', migration: migration %>
3
+
4
+ <div class="pt_form_header">
5
+ <div class="pt_class_name">
6
+ <span>Class Name</span>
7
+ <%= f.text_field :name %>
8
+ </div>
9
+
10
+ <div class="pt_edit_checkbox">
11
+ <input type="checkbox" class="pt_checkbox" />
12
+ <span>edit</span>
13
+ </div>
14
+ </div>
15
+
16
+ <div class="pt_raw_content">
17
+ <%= f.text_area :raw_content, size: '60x20', disabled: true %>
18
+ </div>
19
+
20
+ <%= f.submit 'Create File', class: :pt_submit %>
21
+ <% end %>
22
+
23
+ <%= button_to 'Cancel', migrations_path, method: :get %>
@@ -1,17 +1,18 @@
1
1
  <div class="pt_table">
2
2
  <div class="pt_table_name">
3
3
  <span><%= table.name %></span>
4
- <input type="text" />
4
+ <input type="text" value="<%= table.name %>" style="display: none;" />
5
5
  </div>
6
6
  <div>
7
7
  <a href="#" class="pt_drop_table">drop</a>
8
+ <a href="#" class="pt_restore_table" style="display: none;">restore</a>
8
9
  </div>
9
10
  <div class="pt_columns">
10
11
  <% table.columns.each do |column| %>
11
- <div class="pt_column">
12
- <div class="pt_column_type"><%= column.type %></div>
13
- <div class="pt_column_name"><%= column.name %></div>
14
- </div>
15
- <% end %>
12
+ <%= render 'column', column: column %>
13
+ <% end %>
14
+ </div>
15
+ <div>
16
+ <a href="#" class="pt_add_column">Add Column</a>
16
17
  </div>
17
18
  </div>
@@ -0,0 +1,23 @@
1
+ <script type="text/template" id="table_view_template">
2
+ <div class="pt_table">
3
+ <div class="pt_table_name">
4
+ <span style="display: none;"><%%= name %></span>
5
+ <input type="text" value="<%%= name %>" />
6
+ </div>
7
+ <div>
8
+ <a href="#" class="pt_drop_table">drop</a>
9
+ <a href="#" class="pt_restore_table" style="display: none;">restore</a>
10
+ </div>
11
+ <div class="pt_columns">
12
+ <%% _.each(columns, function(column) { %>
13
+ <div class="pt_column">
14
+ <div class="pt_column_type"><%%= column.type %></div>
15
+ <div class="pt_column_name"><%%= column.name %></div>
16
+ </div>
17
+ <%% }); %>
18
+ <div>
19
+ <a href="#" class="pt_add_column">Add Column</a>
20
+ </div>
21
+ </div>
22
+ </div>
23
+ </script>
@@ -13,6 +13,5 @@
13
13
  </div>
14
14
 
15
15
  <script type='text/javascript'>
16
- toggleMigrationRawContent();
17
- closeNotice();
16
+ setupIndex();
18
17
  </script>