removed last_edited from map model, and set up code to update map updated_at column whenever certain events happen that update the map

This commit is contained in:
Connor Turland 2014-02-26 12:23:29 -08:00
parent c9aea733ad
commit 2cf04f96cb
7 changed files with 23 additions and 16 deletions

View file

@ -25,6 +25,7 @@ class MappingsController < ApplicationController
if params[:map]
if params[:map][:id]
@map = Map.find(params[:map][:id])
@map.touch(:updated_at)
@mapping.map = @map
end
end

View file

@ -217,6 +217,7 @@ class MapsController < ApplicationController
end
end
@map.arranged = true
@map.touch(:updated_at)
@map.save
end
end

View file

@ -41,6 +41,8 @@ class SynapsesController < ApplicationController
if params[:synapse][:map]
@map = Map.find(params[:synapse][:map])
@map.touch(:updated_at)
@mapping = Mapping.new()
@mapping.category = "Synapse"
@mapping.user = @user
@ -104,12 +106,14 @@ class SynapsesController < ApplicationController
end
end
# POST mappings/:map_id/:synapse_id/removefrommap
# POST synapses/:map_id/:synapse_id/removefrommap
def removefrommap
@user = current_user
@mapping = Mapping.find_by_synapse_id_and_map_id(params[:synapse_id],params[:map_id])
Map.find(params[:map_id]).touch(:updated_at)
#push notify to anyone viewing same map in realtime (see mapping.rb to understand the 'message' action)
@mapping.message 'destroy',@user.id
@ -126,6 +130,9 @@ class SynapsesController < ApplicationController
@synapse = Synapse.find(params[:id]).authorize_to_edit(@current)
@synapse.mappings.each do |m|
m.map.touch(:updated_at)
#push notify to anyone viewing same map in realtime (see mapping.rb to understand the 'message' action)
m.message 'destroy',@current.id

View file

@ -94,6 +94,7 @@ class TopicsController < ApplicationController
@mapping = nil
if params[:topic][:map]
@map = Map.find(params[:topic][:map])
@map.touch(:updated_at)
@mapping = Mapping.new()
@mapping.category = "Topic"
@ -150,12 +151,13 @@ class TopicsController < ApplicationController
end
end
# GET mappings/:map_id/:topic_id/removefrommap
# POST topics/:map_id/:topic_id/removefrommap
def removefrommap
@current = current_user
@mapping = Mapping.find_by_topic_id_and_map_id(params[:topic_id],params[:map_id])
@map = Map.find(params[:map_id])
@map.touch(:updated_at)
@topic = Topic.find(params[:topic_id])
@mappings = @map.mappings.select{|m|
if m.synapse != nil
@ -194,6 +196,10 @@ class TopicsController < ApplicationController
@synapses.each do |synapse|
synapse.mappings.each do |m|
@map = m.map
@map.touch(:updated_at)
#push notify to anyone viewing same map in realtime (see mapping.rb to understand the 'message' action)
m.message 'destroy',@current.id
@ -204,6 +210,10 @@ class TopicsController < ApplicationController
end
@mappings.each do |mapping|
@map = mapping.map
@map.touch(:updated_at)
#push notify to anyone viewing a map with this topic in realtime (see mapping.rb to understand the 'message' action)
mapping.message 'destroy',@current.id

View file

@ -33,18 +33,6 @@ end
return contributors
end
#return the date of the last edit (mapping updated) to the map
def last_edited
date = self.created_at
self.mappings.each do |m|
if m.updated_at > date
date = m.updated_at
end
end
return date
end
###### JSON ######
#build a json object of a map

View file

@ -22,7 +22,7 @@
<%= best_in_place map, :desc, :type => :textarea, :nil => "<span class='gray'>Click to add description.</span>", :classes => 'best_in_place_desc' %>
</div>
</div>
<span><%= pluralize(map.contributors.count, 'contributor') %></span><span>Last edit <%= time_ago_in_words( map.last_edited ) %> ago</span>
<span><%= pluralize(map.contributors.count, 'contributor') %></span><span>Last edit <%= time_ago_in_words( map.updated_at ) %> ago</span>
</div>
</div>

View file

@ -37,7 +37,7 @@
<div class="mapInfoMeta">
<p>Created by <%= @map.user.name %> on <%= @map.created_at.strftime("%m/%d/%Y") %></p>
<p>Last edited <%= @map.last_edited.strftime("%m/%d/%Y") %></p>
<p>Last edited <%= @map.updated_at.strftime("%m/%d/%Y") %></p>
</div>
<div class="mapInfoDelete">