From 2beaa2e5be7eb1a852c97916df94d40484b27205 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Sun, 18 Dec 2016 14:18:58 -0500 Subject: [PATCH] track forks --- app/controllers/maps_controller.rb | 2 +- app/models/map.rb | 1 + db/migrate/20161218183817_add_source_to_maps.rb | 5 +++++ db/schema.rb | 5 ++++- frontend/src/Metamaps/GlobalUI/CreateMap.js | 1 + 5 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20161218183817_add_source_to_maps.rb diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index 6e1e0d77..189ae550 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -124,7 +124,7 @@ class MapsController < ApplicationController end def create_map_params - params.permit(:name, :desc, :permission) + params.permit(:name, :desc, :permission, :source_id) end def update_map_params diff --git a/app/models/map.rb b/app/models/map.rb index 899992c6..79b4ae35 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class Map < ApplicationRecord belongs_to :user + belongs_to :source, class_name: :Map has_many :topicmappings, -> { Mapping.topicmapping }, class_name: :Mapping, dependent: :destroy has_many :synapsemappings, -> { Mapping.synapsemapping }, class_name: :Mapping, dependent: :destroy diff --git a/db/migrate/20161218183817_add_source_to_maps.rb b/db/migrate/20161218183817_add_source_to_maps.rb new file mode 100644 index 00000000..d6ce5fbf --- /dev/null +++ b/db/migrate/20161218183817_add_source_to_maps.rb @@ -0,0 +1,5 @@ +class AddSourceToMaps < ActiveRecord::Migration[5.0] + def change + add_reference :maps, :source, foreign_key: {to_table: :maps} + end +end diff --git a/db/schema.rb b/db/schema.rb index b30d597e..7d146be5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161216174257) do +ActiveRecord::Schema.define(version: 20161218183817) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -151,6 +151,8 @@ ActiveRecord::Schema.define(version: 20161216174257) do t.string "screenshot_content_type", limit: 255 t.integer "screenshot_file_size" t.datetime "screenshot_updated_at" + t.integer "source_id" + t.index ["source_id"], name: "index_maps_on_source_id", using: :btree t.index ["user_id"], name: "index_maps_on_user_id", using: :btree end @@ -340,5 +342,6 @@ ActiveRecord::Schema.define(version: 20161216174257) do add_foreign_key "mailboxer_notifications", "mailboxer_conversations", column: "conversation_id", name: "notifications_on_conversation_id" add_foreign_key "mailboxer_receipts", "mailboxer_notifications", column: "notification_id", name: "receipts_on_notification_id" add_foreign_key "mappings", "users", column: "updated_by_id" + add_foreign_key "maps", "maps", column: "source_id" add_foreign_key "tokens", "users" end diff --git a/frontend/src/Metamaps/GlobalUI/CreateMap.js b/frontend/src/Metamaps/GlobalUI/CreateMap.js index 9a4d8770..e7db6219 100644 --- a/frontend/src/Metamaps/GlobalUI/CreateMap.js +++ b/frontend/src/Metamaps/GlobalUI/CreateMap.js @@ -61,6 +61,7 @@ const CreateMap = { if (GlobalUI.lightbox === 'forkmap') { self.newMap.set('topicsToMap', self.topicsToMap) self.newMap.set('synapsesToMap', self.synapsesToMap) + self.newMap.set('source_id', Active.Map.id) } var formId = GlobalUI.lightbox === 'forkmap' ? '#fork_map' : '#new_map'