Compare commits
1 commit
develop
...
feature/la
Author | SHA1 | Date | |
---|---|---|---|
|
97aca38d53 |
9 changed files with 62 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
class MapsController < ApplicationController
|
class MapsController < ApplicationController
|
||||||
|
include MapsHelper
|
||||||
|
|
||||||
before_filter :require_user, only: [:create, :update, :screenshot, :destroy]
|
before_filter :require_user, only: [:create, :update, :screenshot, :destroy]
|
||||||
|
|
||||||
|
@ -69,6 +70,8 @@ class MapsController < ApplicationController
|
||||||
redirect_to root_url, notice: "Access denied. That map is private." and return
|
redirect_to root_url, notice: "Access denied. That map is private." and return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
log_page_view(@current, params[:id])
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {
|
format.html {
|
||||||
@allmappers = @map.contributors
|
@allmappers = @map.contributors
|
||||||
|
@ -99,6 +102,8 @@ class MapsController < ApplicationController
|
||||||
redirect_to root_url, notice: "Access denied. That map is private." and return
|
redirect_to root_url, notice: "Access denied. That map is private." and return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
log_page_view(@current, params[:id])
|
||||||
|
|
||||||
@allmappers = @map.contributors
|
@allmappers = @map.contributors
|
||||||
@alltopics = @map.topics.delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) }
|
@alltopics = @map.topics.delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) }
|
||||||
@allsynapses = @map.synapses.delete_if {|s| s.permission == "private" && (!authenticated? || (authenticated? && @current.id != s.user_id)) }
|
@allsynapses = @map.synapses.delete_if {|s| s.permission == "private" && (!authenticated? || (authenticated? && @current.id != s.user_id)) }
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
module MapsHelper
|
module MapsHelper
|
||||||
|
|
||||||
|
def log_page_view(user, mapId)
|
||||||
|
if user
|
||||||
|
MapView.find_or_create_by_user_id_and_map_id(user.id, mapId).touch(:updated_at)
|
||||||
|
|
||||||
|
#limit records of map views for this user to ten
|
||||||
|
MapView.where(user_id: user.id).order('updated_at desc').offset(10).destroy_all
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
## this one is for building our custom JSON autocomplete format for typeahead
|
## this one is for building our custom JSON autocomplete format for typeahead
|
||||||
def autocomplete_map_array_json(maps)
|
def autocomplete_map_array_json(maps)
|
||||||
temp = []
|
temp = []
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
class Map < ActiveRecord::Base
|
class Map < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
has_many :map_views
|
||||||
|
|
||||||
has_many :topicmappings, :class_name => 'Mapping', :conditions => {:category => 'Topic'}
|
has_many :topicmappings, :class_name => 'Mapping', :conditions => {:category => 'Topic'}
|
||||||
has_many :synapsemappings, :class_name => 'Mapping', :conditions => {:category => 'Synapse'}
|
has_many :synapsemappings, :class_name => 'Mapping', :conditions => {:category => 'Synapse'}
|
||||||
|
|
4
app/models/map_view.rb
Normal file
4
app/models/map_view.rb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
class MapView < ActiveRecord::Base
|
||||||
|
belongs_to :user
|
||||||
|
belongs_to :map
|
||||||
|
end
|
|
@ -6,6 +6,7 @@ class User < ActiveRecord::Base
|
||||||
has_many :synapses
|
has_many :synapses
|
||||||
has_many :maps
|
has_many :maps
|
||||||
has_many :mappings
|
has_many :mappings
|
||||||
|
has_many :map_views
|
||||||
|
|
||||||
before_create :generate_code
|
before_create :generate_code
|
||||||
|
|
||||||
|
|
12
db/migrate/20150209013154_create_map_views.rb
Normal file
12
db/migrate/20150209013154_create_map_views.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
class CreateMapViews < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :map_views do |t|
|
||||||
|
t.references :user
|
||||||
|
t.references :map
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
add_index :map_views, :user_id
|
||||||
|
add_index :map_views, :map_id
|
||||||
|
end
|
||||||
|
end
|
12
db/schema.rb
12
db/schema.rb
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20141121204712) do
|
ActiveRecord::Schema.define(:version => 20150209003902) do
|
||||||
|
|
||||||
create_table "in_metacode_sets", :force => true do |t|
|
create_table "in_metacode_sets", :force => true do |t|
|
||||||
t.integer "metacode_id"
|
t.integer "metacode_id"
|
||||||
|
@ -23,6 +23,16 @@ ActiveRecord::Schema.define(:version => 20141121204712) do
|
||||||
add_index "in_metacode_sets", ["metacode_id"], :name => "index_in_metacode_sets_on_metacode_id"
|
add_index "in_metacode_sets", ["metacode_id"], :name => "index_in_metacode_sets_on_metacode_id"
|
||||||
add_index "in_metacode_sets", ["metacode_set_id"], :name => "index_in_metacode_sets_on_metacode_set_id"
|
add_index "in_metacode_sets", ["metacode_set_id"], :name => "index_in_metacode_sets_on_metacode_set_id"
|
||||||
|
|
||||||
|
create_table "map_views", :force => true do |t|
|
||||||
|
t.integer "user_id"
|
||||||
|
t.integer "map_id"
|
||||||
|
t.datetime "created_at", :null => false
|
||||||
|
t.datetime "updated_at", :null => false
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "map_views", ["map_id"], :name => "index_map_views_on_map_id"
|
||||||
|
add_index "map_views", ["user_id"], :name => "index_map_views_on_user_id"
|
||||||
|
|
||||||
create_table "mappings", :force => true do |t|
|
create_table "mappings", :force => true do |t|
|
||||||
t.text "category"
|
t.text "category"
|
||||||
t.integer "xloc"
|
t.integer "xloc"
|
||||||
|
|
11
test/fixtures/map_views.yml
vendored
Normal file
11
test/fixtures/map_views.yml
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
|
||||||
|
|
||||||
|
# This model initially had no columns defined. If you add columns to the
|
||||||
|
# model remove the '{}' from the fixture names and add the columns immediately
|
||||||
|
# below each fixture, per the syntax in the comments below
|
||||||
|
#
|
||||||
|
one: {}
|
||||||
|
# column: value
|
||||||
|
#
|
||||||
|
two: {}
|
||||||
|
# column: value
|
7
test/unit/map_view_test.rb
Normal file
7
test/unit/map_view_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class MapViewTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
Loading…
Reference in a new issue