From 769b57cdd2ceec96c9947605bb648524a1f2ead3 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Thu, 15 Dec 2016 08:38:29 -0500 Subject: [PATCH] get events into the client on initial and later load --- app/controllers/maps_controller.rb | 1 + app/models/map.rb | 5 +++-- app/serializers/event_serializer.rb | 2 +- app/views/maps/show.html.erb | 1 + frontend/src/Metamaps/DataModel/index.js | 2 ++ frontend/src/Metamaps/Map/index.js | 1 + 6 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index d66456b8..b72956d0 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -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 } diff --git a/app/models/map.rb b/app/models/map.rb index 36b2d284..7f2a68ec 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -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 diff --git a/app/serializers/event_serializer.rb b/app/serializers/event_serializer.rb index 4d994472..dae2f871 100644 --- a/app/serializers/event_serializer.rb +++ b/app/serializers/event_serializer.rb @@ -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 diff --git a/app/views/maps/show.html.erb b/app/views/maps/show.html.erb index 4ecbd274..2e3267bb 100644 --- a/app/views/maps/show.html.erb +++ b/app/views/maps/show.html.erb @@ -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"; diff --git a/frontend/src/Metamaps/DataModel/index.js b/frontend/src/Metamaps/DataModel/index.js index 6d41e19f..523ca40e 100644 --- a/frontend/src/Metamaps/DataModel/index.js +++ b/frontend/src/Metamaps/DataModel/index.js @@ -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 diff --git a/frontend/src/Metamaps/Map/index.js b/frontend/src/Metamaps/Map/index.js index 51038b87..7980ca38 100644 --- a/frontend/src/Metamaps/Map/index.js +++ b/frontend/src/Metamaps/Map/index.js @@ -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