get events into the client on initial and later load

This commit is contained in:
Connor Turland 2016-12-15 08:38:29 -05:00
parent 223d31c4f4
commit 769b57cdd2
6 changed files with 9 additions and 3 deletions

View file

@ -16,6 +16,7 @@ class MapsController < ApplicationController
@allmessages = @map.messages.sort_by(&:created_at)
@allstars = @map.stars
@allrequests = @map.access_requests
@allevents = @map.events
end
format.json { render json: @map }
format.csv { redirect_to action: :export, format: :csv }

View file

@ -14,7 +14,7 @@ class Map < ApplicationRecord
has_many :collaborators, through: :user_maps, source: :user
has_many :webhooks, as: :hookable
has_many :events, -> { includes :user }, as: :eventable, dependent: :destroy
has_many :events, -> { includes :user }, dependent: :destroy
# This method associates the attribute ":image" with a file attachment
has_attached_file :screenshot,
@ -95,7 +95,8 @@ class Map < ApplicationRecord
collaborators: editors,
messages: messages.sort_by(&:created_at),
stars: stars,
requests: access_requests
requests: access_requests,
events: events.chronologically
}
end

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
class EventSerializer < ActiveModel::Serializer
attributes :id, :sequence_id, :kind, :map_id, :created_at
attributes :id, :kind, :map_id, :created_at
has_one :actor, serializer: Api::V2::UserSerializer, root: 'users'
has_one :map, serializer: Api::V2::MapSerializer

View file

@ -18,5 +18,6 @@
Metamaps.ServerData.Mappings = <%= @allmappings.to_json.html_safe %>;
Metamaps.ServerData.Messages = <%= @allmessages.to_json.html_safe %>;
Metamaps.ServerData.Stars = <%= @allstars.to_json.html_safe %>;
Metamaps.ServerData.Events = <%= @allevents.to_json.html_safe %>;
Metamaps.ServerData.VisualizeType = "ForceDirected";
</script>

View file

@ -35,6 +35,7 @@ const DataModel = {
Collaborators: new MapperCollection(),
Creators: new MapperCollection(),
Events: [],
Mappers: new MapperCollection(),
Mappings: new MappingCollection(),
Maps: {
@ -68,6 +69,7 @@ const DataModel = {
if (serverData.Collaborators) self.Collaborators = new MapperCollection(serverData.Collaborators)
if (serverData.Creators) self.Creators = new MapperCollection(serverData.Creators)
if (serverData.Events) self.Events = serverData.Events
if (serverData.Mappers) self.Mappers = new MapperCollection(serverData.Mappers)
if (serverData.Mappings) self.Mappings = new MappingCollection(serverData.Mappings)
if (serverData.Messages) self.Messages = serverData.Messages

View file

@ -80,6 +80,7 @@ const Map = {
DataModel.Mappings = new DataModel.MappingCollection(data.mappings)
DataModel.Messages = data.messages
DataModel.Stars = data.stars
DataModel.Events = data.events
DataModel.attachCollectionEvents()
var map = Active.Map