From b7d3b9fd33d4ea2ee796eb566ccccdea64bf68f0 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Sat, 11 Jul 2020 02:15:39 -0700 Subject: [PATCH] finish timeline#show page --- app/controllers/timelines_controller.rb | 6 ++ app/views/timelines/show.html.erb | 128 +++++++++++++++++++++++- config/routes.rb | 2 +- 3 files changed, 132 insertions(+), 4 deletions(-) diff --git a/app/controllers/timelines_controller.rb b/app/controllers/timelines_controller.rb index 3e8b396b..4deb5f63 100644 --- a/app/controllers/timelines_controller.rb +++ b/app/controllers/timelines_controller.rb @@ -14,6 +14,12 @@ class TimelinesController < ApplicationController end end + def show + unless @timeline.privacy == 'public' || (user_signed_in? && current_user == @timeline.user) + return redirect_back(fallback_location: root_path, notice: "You don't have permission to view that timeline!") + end + end + # GET /timelines/new def new timeline = current_user.timelines.create.reload diff --git a/app/views/timelines/show.html.erb b/app/views/timelines/show.html.erb index 290d3824..ed993067 100644 --- a/app/views/timelines/show.html.erb +++ b/app/views/timelines/show.html.erb @@ -1,4 +1,126 @@ -

<%= notice %>

+<%= form_for @timeline, html: { class: 'autosave-form' }, remote: true do |f| %> +
+
+

+ <% if @timeline.universe %> + <%= link_to @timeline.universe do %> + <%= Universe.icon %> + <% end %> + <% end %> + <% if user_signed_in? && current_user == @timeline.user %> + <%= link_to edit_timeline_path(@timeline) do %> + edit + <% end %> + <% end %> + <%= @timeline.name %>
+ <%= @timeline.subtitle %> +

+ <%= simple_format @timeline.description %> +
+
+ <% if @timeline.notes.present? || (@timeline.private_notes.present? && user_signed_in && current_user == @timeline.user) %> +
    +
  • +
    + <%= Timeline.icon %> + Timeline notes +
    +
    + <% if @timeline.notes.present? %> +
    Notes
    + <%= simple_format @timeline.notes %> + <% end %> + + <% if @timeline.private_notes.present? && user_signed_in? && current_user == @timeline.user %> +
    Private notes (only visible to you)
    + <%= simple_format @timeline.private_notes %> + <% end %> +
    +
    +
  • +
+ <% end %> +
+
+<% end %> + +
+ + +
+ <% @timeline.timeline_events.includes(:timeline_event_entities).each do |event| %> +
+ <%= form_for event, html: { class: 'autosave-form' }, remote: true do |f| %> + <%= f.hidden_field :timeline_id %> +
+
+ <% if event.time_label.present? %> +
Time label
+ <%= simple_format event.time_label %> + <% end %> +
+
+ <%= image_tag 'graphics/timeline-line.png' %> +
+
+
+
+ + <%= simple_format(event.title.presence || 'Untitled event') %> + + <% if event.description.present? %> +
Description
+ <%= simple_format(event.description) %> + <% end %> + +
+ + <% if event.notes.present? %> +
Notes
+ <%= simple_format(event.notes) %> + <% end %> +
+
+
+
+ <% + event_entities = event.timeline_event_entities.order('entity_type').preload(:entity).group_by(&:entity_type) + %> + <% unless event_entities == {} %> +
+ In this event +
+
    + <% event_entities.each do |entity_type, entity_list| %> +
  • + <% klass = entity_type.constantize %> +
    + <%= klass.icon %> + <%= entity_type.pluralize %> + <%= entity_list.count %> +
    +
    + <% entity_list.each do |te_entity| %> +
    + <%= link_to(te_entity.entity.name.presence || "Untitled #{te_entity.entity_type}", te_entity.entity) %> +
    + <% end %> +
    +
  • + <% end %> +
+ <% end %> + +
+
+ <% end %> +
+ <% end %> +
+ +
-<%= link_to 'Edit', edit_timeline_path(@timeline) %> | -<%= link_to 'Back', timelines_path %> diff --git a/config/routes.rb b/config/routes.rb index a86844d0..7768435e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -193,7 +193,7 @@ Rails.application.routes.draw do get '/tagged/:slug', on: :collection, action: :index, as: :page_tag end end - resources :timelines, only: [:index, :new, :update, :edit, :destroy] + resources :timelines, only: [:index, :show, :new, :update, :edit, :destroy] resources :timeline_events do scope '/move', as: :move do get 'up', to: 'timeline_events#move_up', on: :member