From 7db60b85ef7c04ed87183476cba9f945a65e57e9 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 21 Jan 2021 15:25:38 -0800 Subject: [PATCH 01/12] add tags to timelines --- app/controllers/timelines_controller.rb | 31 +++++++++++- app/models/timelines/timeline.rb | 1 + app/views/timelines/edit.html.erb | 67 ++++++++++++++++++++++--- 3 files changed, 91 insertions(+), 8 deletions(-) diff --git a/app/controllers/timelines_controller.rb b/app/controllers/timelines_controller.rb index 3a3473fd..619762ee 100644 --- a/app/controllers/timelines_controller.rb +++ b/app/controllers/timelines_controller.rb @@ -32,6 +32,8 @@ class TimelinesController < ApplicationController # GET /timelines/1/edit def edit @page_title = "Editing " + @timeline.name + + @suggested_page_tags = [] raise "No Access" unless user_signed_in? && current_user == @timeline.user end @@ -55,6 +57,8 @@ class TimelinesController < ApplicationController return unless user_signed_in? && current_user == @timeline.user if @timeline.update(timeline_params) + update_page_tags + render status: 200, json: @timeline.reload else render status: 501, json: @timeline.errors @@ -69,6 +73,27 @@ class TimelinesController < ApplicationController private + # TODO: move this (and the copy in ContentController) into the has_page_tags concern? + def update_page_tags + tag_list = page_tag_params.split(PageTag::SUBMISSION_DELIMITER) + current_tags = @timeline.page_tags.pluck(:tag) + + tags_to_add = tag_list - current_tags + tags_to_remove = current_tags - tag_list + + tags_to_add.each do |tag| + @timeline.page_tags.find_or_create_by( + tag: tag, + slug: PageTagService.slug_for(tag), + user: @timeline.user + ) + end + + tags_to_remove.each do |tag| + @timeline.page_tags.find_by(tag: tag).destroy + end + end + # Use callbacks to share common setup or constraints between actions. def set_timeline @timeline = Timeline.find(params[:id]) @@ -76,7 +101,11 @@ class TimelinesController < ApplicationController # Only allow a trusted parameter "white list" through. def timeline_params - params.require(:timeline).permit(:name, :subtitle, :description, :notes, :private_notes, :universe_id, :deleted_at, :archived_at, :privacy) + params.require(:timeline).except(:page_tags).permit(:name, :subtitle, :description, :notes, :private_notes, :universe_id, :deleted_at, :archived_at, :privacy) + end + + def page_tag_params + params.require(:timeline).fetch(:page_tags, "") end def set_navbar_color diff --git a/app/models/timelines/timeline.rb b/app/models/timelines/timeline.rb index e84f2887..c78e8ff5 100644 --- a/app/models/timelines/timeline.rb +++ b/app/models/timelines/timeline.rb @@ -2,6 +2,7 @@ class Timeline < ApplicationRecord acts_as_paranoid include IsContentPage + include HasPageTags include Authority::Abilities self.authorizer_name = 'ExtendedContentAuthorizer' diff --git a/app/views/timelines/edit.html.erb b/app/views/timelines/edit.html.erb index c209fa87..3851a36e 100644 --- a/app/views/timelines/edit.html.erb +++ b/app/views/timelines/edit.html.erb @@ -1,6 +1,6 @@ <%= render partial: 'notice_dismissal/messages/13' %>
-<%= form_for @timeline, html: { class: 'autosave-form' }, remote: true do |f| %> +<%= form_for @timeline, html: { class: 'autosave-form timeline-meta-form' }, remote: true do |f| %>
@@ -38,8 +38,8 @@ <%= f.label :description, 'Description' %>
- <%= f.select :universe_id, current_user.universes.pluck(:name, :id), { include_blank: true }, class: 'materialize-textarea js-trigger-autosave-on-change' %> - <%= f.label 'Universe' %> + <%= f.select :universe_id, current_user.universes.pluck(:name, :id), { include_blank: true }, class: 'materialize-textarea js-trigger-autosave-on-change' %> + <%= f.label 'Universe' %>
- + <%= content_for :javascript do %> + function update_hidden_page_tag_value(e) { + var chips = M.Chips.getInstance($('.chips')).chipsData.map(function (c) { + return c['tag']; + }); + + var hidden_input = $('#hidden_page_tags_value').first(); + hidden_input.val(chips.join('<%= PageTag::SUBMISSION_DELIMITER %>')); + $('form.timeline-meta-form').submit(); + } + + var chips = $('.chips-autocomplete').chips({ + placeholder: 'Tag this page', + secondaryPlaceholder: '+ Tag', + autocompleteOptions: { + data: { + <% @timeline.page_tags.pluck(:tag).each do |tag| %> + '<%= tag %>': null, + <% end %> + }, + limit: 100, + minLength: 1 + }, + data: [ + <% @timeline.page_tags.pluck(:tag).each do |tag| %> + {tag: '<%= tag %>'}, + <% end %> + ], + onChipAdd: update_hidden_page_tag_value, + onChipDelete: update_hidden_page_tag_value + }); + <% end %> +
<%= f.text_area :notes, class: 'materialize-textarea js-trigger-autosave-on-change' %> <%= f.label :notes %> From d46f077883254d4cac7e1574010d5f793eccf92b Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 21 Jan 2021 15:35:23 -0800 Subject: [PATCH 02/12] show tags on timelines#index --- app/views/timelines/index.html.erb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/views/timelines/index.html.erb b/app/views/timelines/index.html.erb index a3779972..dddf9e04 100644 --- a/app/views/timelines/index.html.erb +++ b/app/views/timelines/index.html.erb @@ -50,7 +50,14 @@ Last edited <%= time_ago_in_words timeline.updated_at %> ago

+
+ <% timeline.page_tags.each do |page_tag| %> + + <% end %> +
+
+
<%= link_to timeline_path(timeline), class: 'blue-text left' do %> From a08bd05e09d6c9f31bd587162abe2ad1bd6b3eff Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 21 Jan 2021 15:50:17 -0800 Subject: [PATCH 03/12] add filter bar to timelines, allow filtering by tag --- app/controllers/timelines_controller.rb | 14 ++++++++++++++ app/views/timelines/index.html.erb | 4 ++++ config/routes.rb | 4 +++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/controllers/timelines_controller.rb b/app/controllers/timelines_controller.rb index 619762ee..257d4053 100644 --- a/app/controllers/timelines_controller.rb +++ b/app/controllers/timelines_controller.rb @@ -13,6 +13,20 @@ class TimelinesController < ApplicationController if @universe_scope @timelines = @timelines.where(universe: @universe_scope) end + + @page_tags = PageTag.where( + page_type: Timeline.name, + page_id: @timelines.pluck(:id) + ).order(:tag) + if params.key?(:slug) + @filtered_page_tags = @page_tags.where(slug: params[:slug]) + @timelines = @timelines.select { |timeline| @filtered_page_tags.pluck(:page_id).include?(timeline.id) } + end + + # if params.key?(:favorite_only) + # @content.select!(&:favorite?) + # end + end def show diff --git a/app/views/timelines/index.html.erb b/app/views/timelines/index.html.erb index dddf9e04..ee6afc21 100644 --- a/app/views/timelines/index.html.erb +++ b/app/views/timelines/index.html.erb @@ -12,6 +12,10 @@ Create another timeline <% end %>
+ +
+ <%= render partial: 'content/components/list_filter_bar', locals: { content_type: Timeline } %> +
<% @timelines.each do |timeline| %> diff --git a/config/routes.rb b/config/routes.rb index 16bf8dde..c4cf9faa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -215,7 +215,9 @@ Rails.application.routes.draw do get '/tagged/:slug', on: :collection, action: :index, as: :page_tag end end - resources :timelines, only: [:index, :show, :new, :update, :edit, :destroy] + resources :timelines, only: [:index, :show, :new, :update, :edit, :destroy] do + get '/tagged/:slug', action: :index, on: :collection, as: :page_tag + end resources :timeline_events do scope '/move', as: :move do get 'up', to: 'timeline_events#move_up', on: :member From bf8841803d0989e9904cb6d46ab4809d2a987c71 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 21 Jan 2021 15:56:46 -0800 Subject: [PATCH 04/12] allow filtering timelines by universe --- app/models/page_types/universe.rb | 1 + app/views/content/components/_list_filter_bar.html.erb | 2 +- app/views/timelines/index.html.erb | 9 ++++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models/page_types/universe.rb b/app/models/page_types/universe.rb index ca6d4884..9529f886 100644 --- a/app/models/page_types/universe.rb +++ b/app/models/page_types/universe.rb @@ -55,6 +55,7 @@ class Universe < ApplicationRecord has_many :contributors, dependent: :destroy has_many :documents + has_many :timelines scope :in_universe, ->(universe = nil) { where(id: universe.try(:id)) unless universe.nil? } diff --git a/app/views/content/components/_list_filter_bar.html.erb b/app/views/content/components/_list_filter_bar.html.erb index 6e2e92f7..db7c1c8a 100644 --- a/app/views/content/components/_list_filter_bar.html.erb +++ b/app/views/content/components/_list_filter_bar.html.erb @@ -9,7 +9,7 @@ <% if content_type.new.respond_to?(:universe) %> From 23d7b62c7d3ad3e1d430d3f2973fe71c0e3b4210 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 21 Jan 2021 16:14:55 -0800 Subject: [PATCH 05/12] filter timelines by name --- .../components/_list_filter_bar.html.erb | 18 ++++++++++-------- app/views/timelines/index.html.erb | 14 +++++++------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/views/content/components/_list_filter_bar.html.erb b/app/views/content/components/_list_filter_bar.html.erb index db7c1c8a..db31a900 100644 --- a/app/views/content/components/_list_filter_bar.html.erb +++ b/app/views/content/components/_list_filter_bar.html.erb @@ -78,14 +78,16 @@
<% end %> - black-text tooltipped' - href="<%= url_for(params.permit(:universe, :favorite_only).merge({favorite_only: params.key?(:favorite_only) ? nil : 1})) %>" - data-position="bottom" - data-delay="500" - data-tooltip="Filter by favorite"> - star_outline - <% if params.key?(:favorite_only) %>Favorites<% end %> - + <% if content_type.new.respond_to?(:favorite?) %> + black-text tooltipped' + href="<%= url_for(params.permit(:universe, :favorite_only).merge({favorite_only: params.key?(:favorite_only) ? nil : 1})) %>" + data-position="bottom" + data-delay="500" + data-tooltip="Filter by favorite"> + star_outline + <% if params.key?(:favorite_only) %>Favorites<% end %> + + <% end %>   diff --git a/app/views/timelines/index.html.erb b/app/views/timelines/index.html.erb index 3322bed5..279770e7 100644 --- a/app/views/timelines/index.html.erb +++ b/app/views/timelines/index.html.erb @@ -18,15 +18,15 @@ - <% @timelines.each do |timeline| %> -
-
+
+ <% @timelines.each do |timeline| %> +
<%= link_to edit_timeline_path(timeline) do %>
<%= image_tag timeline.random_public_image(format: :medium) %> - + <%= timeline.name.presence || 'Untitled Timeline' %>
-
+
<% if timeline.universe_id? %>

<%= link_to timeline.universe, class: "#{Universe.color}-text" do %> @@ -85,8 +85,8 @@ <% end %>

-
- <% end %> + <% end %> +
<% if @show_scope_notice %>

From 114873e15add07797821cb97879a8e4f6a1bb8f2 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 21 Jan 2021 16:24:51 -0800 Subject: [PATCH 06/12] add new#content button to filter bar --- .../content/components/_list_filter_bar.html.erb | 15 +++++++++++++-- app/views/timelines/index.html.erb | 7 ------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/views/content/components/_list_filter_bar.html.erb b/app/views/content/components/_list_filter_bar.html.erb index db31a900..ccc3a248 100644 --- a/app/views/content/components/_list_filter_bar.html.erb +++ b/app/views/content/components/_list_filter_bar.html.erb @@ -1,10 +1,13 @@

- +
+ --> <% if content_type.new.respond_to?(:universe) %>
@@ -124,4 +127,12 @@
+ +
+ <%= link_to send("new_#{content_type.name.downcase}_path"), class: "btn right #{content_type.color} white-text" do %> + add + New <%= content_type.name %> + <% end %> +
+
\ No newline at end of file diff --git a/app/views/timelines/index.html.erb b/app/views/timelines/index.html.erb index 279770e7..d8efd7c4 100644 --- a/app/views/timelines/index.html.erb +++ b/app/views/timelines/index.html.erb @@ -5,13 +5,6 @@ <% if @timelines.any? %>
-
-
- <%= link_to new_timeline_path, class: "hoverable btn right #{Timeline.color} white-text" do %> - add - Create another timeline - <% end %> -
<%= render partial: 'content/components/list_filter_bar', locals: { content_type: Timeline } %> From cbb786f7166cab51d63fc91f432e16b7ca874870 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 21 Jan 2021 16:36:31 -0800 Subject: [PATCH 07/12] add new#content quick links on show and edit pages --- app/controllers/content_controller.rb | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index 66f7f6b9..1d83cca7 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -89,7 +89,7 @@ class ContentController < ApplicationController }) end - if current_user + if user_signed_in? if @content.updated_at > 30.minutes.ago Mixpanel::Tracker.new(Rails.application.config.mixpanel_token).track(current_user.id, 'viewed content', { 'content_type': content_type.name, @@ -105,6 +105,14 @@ class ContentController < ApplicationController end end + if user_signed_in? && current_user.can_create?(content_type) + @navbar_actions << { + label: "New #{content_type.name.downcase}", + href: main_app.new_polymorphic_path(content_type), + class: 'right' + } + end + respond_to do |format| format.html { render 'content/show', locals: { content: @content } } format.json { render json: @serialized_content.data } @@ -168,6 +176,14 @@ class ContentController < ApplicationController return redirect_to @content, notice: t(:no_do_permission) end + if user_signed_in? && current_user.can_create?(content_type_class) + @navbar_actions << { + label: "New #{content_type_class.name.downcase}", + href: main_app.new_polymorphic_path(content_type_class), + class: 'right' + } + end + respond_to do |format| format.html { render 'content/edit', locals: { content: @content } } format.json { render json: @content } @@ -614,12 +630,6 @@ class ContentController < ApplicationController href: main_app.polymorphic_path(content_type) } end - - @navbar_actions << { - label: "New #{content_type.name.downcase}", - href: main_app.new_polymorphic_path(content_type), - class: 'right' - } end discussions_link = ForumsLinkbuilderService.worldbuilding_url(content_type) From 9148f8a7b7ec00d2ab6c8f429051553c464cc88f Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 21 Jan 2021 18:33:50 -0800 Subject: [PATCH 08/12] add tristan to notice#13 for timelines --- .../notice_dismissal/messages/_13.html.erb | 63 ++++++++++++------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/app/views/notice_dismissal/messages/_13.html.erb b/app/views/notice_dismissal/messages/_13.html.erb index 46993eba..b8dbeb5e 100644 --- a/app/views/notice_dismissal/messages/_13.html.erb +++ b/app/views/notice_dismissal/messages/_13.html.erb @@ -6,30 +6,45 @@
-

- Welcome to the new Timeline Editor! -

-

- This editor is still in beta, so any - <%= link_to 'feedback', 'https://docs.google.com/forms/d/e/1FAIpQLSfHHcOpU-CD9EFILPVMd4ZtgWIFkxmzLMW1mdvanJqqLKgMAA/viewform?usp=sf_link' %> - you have is highly appreciated. -

-

- You are starting with a blank timeline and can add as many events as you'd like. Each event allows you to - write a customized label for when it happens so you can be as exact or as vague as you'd like, and you can - fully control the ordering of events by clicking the links to move them up, down, to the top, or to the end - of your timeline. -

-

- You can also link your existing worldbuilding pages to each event. For example, if you create an event about - <%= example_character_name %> finding a mysterious egg, you can link <%= example_character_name %>'s page - directly, as well as any other pages relevant to that scene (such as an Item page for the egg, the location it's - happening at, or other characters there). Those worldbuilding pages will automatically have a "Timelines" tab - created (visible only to you) that lists all timelines they appear in. -

-

- <%= link_to 'Dismiss this message', notice_dismissal_dismiss_path(notice_id: 13) %>. -

+
+
+

+ Welcome to the new Timeline Editor! +

+

+ This editor is still in beta, so any + <%= link_to 'feedback', 'https://docs.google.com/forms/d/e/1FAIpQLSfHHcOpU-CD9EFILPVMd4ZtgWIFkxmzLMW1mdvanJqqLKgMAA/viewform?usp=sf_link' %> + you have is highly appreciated. +

+

+ You are starting with a blank timeline and can add as many events as you'd like. Each event allows you to + write a customized label for when it happens so you can be as exact or as vague as you'd like, and you can + fully control the ordering of events by clicking the links to move them up, down, to the top, or to the end + of your timeline. +

+

+ You can also link your existing worldbuilding pages to each event. For example, if you create an event about + <%= example_character_name %> finding a mysterious egg, you can link <%= example_character_name %>'s page + directly, as well as any other pages relevant to that scene (such as an Item page for the egg, the location it's + happening at, or other characters there). Those worldbuilding pages will automatically have a "Timelines" tab + created (visible only to you) that lists all timelines they appear in. +

+

+ <%= link_to 'Dismiss this message', notice_dismissal_dismiss_path(notice_id: 13) %>. +

+
+ +
+ <%= image_tag 'tristan/small.png', + class: 'tooltipped tristan right', + data: { + position: 'bottom', + enterDelay: '500', + tooltip: "Hey, I'm Tristan! I'm here to help you around the site!" + } + %> +
+
From f4e3d581c42e83d655eabc25ca911bc1c8e70ed7 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Sat, 23 Jan 2021 15:24:00 -0800 Subject: [PATCH 09/12] feature the first uploaded image to content instead of a random one --- app/models/concerns/has_image_uploads.rb | 4 ++++ app/models/page_collections/page_collection.rb | 5 +++++ app/views/content/components/_collection_header.html.erb | 2 +- app/views/content/panels/_collections.html.erb | 2 +- app/views/content/panels/_timelines.html.erb | 2 +- app/views/content/show.html.erb | 2 +- .../_stream_added_to_page_collection.html.erb | 4 ++-- .../content_page_shares/_stream_document_share.html.erb | 2 +- .../_stream_new_page_collection.html.erb | 2 +- app/views/content_page_shares/_stream_page_share.html.erb | 2 +- .../content_page_shares/_stream_timeline_share.html.erb | 2 +- app/views/content_page_shares/show.html.erb | 2 +- app/views/page_collection_submissions/index.html.erb | 2 +- app/views/page_collections/_collection_grid.html.erb | 2 +- app/views/page_collections/_stream.html.erb | 2 +- app/views/page_collections/_tiles.html.erb | 2 +- app/views/users/profile/_recent_activity.html.erb | 2 +- app/views/users/show.html.erb | 6 +++--- lib/extensions/thredded/topic.rb | 5 +++++ 19 files changed, 33 insertions(+), 19 deletions(-) diff --git a/app/models/concerns/has_image_uploads.rb b/app/models/concerns/has_image_uploads.rb index ddb86f1f..8ec198ec 100644 --- a/app/models/concerns/has_image_uploads.rb +++ b/app/models/concerns/has_image_uploads.rb @@ -20,6 +20,10 @@ module HasImageUploads image_uploads.sample.try(:src, format).presence || "card-headers/#{self.class.name.downcase.pluralize}.jpg" end + def first_public_image(format: :medium) + public_image_uploads.first.try(:src, format).presence || "card-headers/#{self.class.name.downcase.pluralize}.jpg" + end + def random_public_image(format: :medium) public_image_uploads.sample.try(:src, format).presence || "card-headers/#{self.class.name.downcase.pluralize}.jpg" end diff --git a/app/models/page_collections/page_collection.rb b/app/models/page_collections/page_collection.rb index 75ecfa5c..4eb982e9 100644 --- a/app/models/page_collections/page_collection.rb +++ b/app/models/page_collections/page_collection.rb @@ -51,6 +51,11 @@ class PageCollection < ApplicationRecord # If all else fails, fall back on default header "card-headers/#{self.class.name.downcase.pluralize}.jpg" end + + def first_public_image + random_public_image + end + def name title end diff --git a/app/views/content/components/_collection_header.html.erb b/app/views/content/components/_collection_header.html.erb index fc9de293..d4b0e01e 100644 --- a/app/views/content/components/_collection_header.html.erb +++ b/app/views/content/components/_collection_header.html.erb @@ -1,7 +1,7 @@
  • - <%= image_tag(collection.random_public_image) %> + <%= image_tag(collection.first_public_image) %>
    <%= link_to collection, class: 'white-text' do %>

    diff --git a/app/views/content/panels/_collections.html.erb b/app/views/content/panels/_collections.html.erb index 9ecd6ea5..09023e0b 100644 --- a/app/views/content/panels/_collections.html.erb +++ b/app/views/content/panels/_collections.html.erb @@ -8,7 +8,7 @@ <%= link_to collection do %>
    - <%= image_tag collection.random_public_image, style: 'max-height: 300px;' %> + <%= image_tag collection.first_public_image, style: 'max-height: 300px;' %> <%= collection.title %>
    diff --git a/app/views/content/panels/_timelines.html.erb b/app/views/content/panels/_timelines.html.erb index c1251e14..0348e211 100644 --- a/app/views/content/panels/_timelines.html.erb +++ b/app/views/content/panels/_timelines.html.erb @@ -20,7 +20,7 @@ <%= link_to edit_timeline_path(timeline) do %>
    - <%= image_tag timeline.random_public_image(format: :medium), style: 'height: 140px' %> + <%= image_tag timeline.first_public_image(format: :medium), style: 'height: 140px' %> <%= timeline.name.presence || 'Untitled Timeline' %> diff --git a/app/views/content/show.html.erb b/app/views/content/show.html.erb index d3ebe19a..5021a2e9 100644 --- a/app/views/content/show.html.erb +++ b/app/views/content/show.html.erb @@ -1,7 +1,7 @@ <% set_meta_tags title: @content.name, description: "#{%w(a e i o u).include?(content.class.name.downcase[0]) ? "An" : "A"} #{@content.class.name.downcase} on Notebook.ai", - image_src: @content.random_public_image, + image_src: @content.first_public_image, og: { type: 'website' } %> diff --git a/app/views/content_page_shares/_stream_added_to_page_collection.html.erb b/app/views/content_page_shares/_stream_added_to_page_collection.html.erb index f0f0c4ba..78f0be25 100644 --- a/app/views/content_page_shares/_stream_added_to_page_collection.html.erb +++ b/app/views/content_page_shares/_stream_added_to_page_collection.html.erb @@ -28,11 +28,11 @@
    <% if share.user == content.user %> <%= link_to [share.user, share] do %> - <%= image_tag secondary_content.random_public_image %> + <%= image_tag secondary_content.first_public_image %> <% end %> <% else %> <%= link_to [share.user, share] do %> - <%= image_tag content.random_public_image %> + <%= image_tag content.first_public_image %> <% end %> <% end %> diff --git a/app/views/content_page_shares/_stream_document_share.html.erb b/app/views/content_page_shares/_stream_document_share.html.erb index bf53c6c6..f8f1dc92 100644 --- a/app/views/content_page_shares/_stream_document_share.html.erb +++ b/app/views/content_page_shares/_stream_document_share.html.erb @@ -23,7 +23,7 @@
    <%= link_to [share.user, share] do %> - <%= image_tag content.random_public_image(format: :small) %> + <%= image_tag content.first_public_image(format: :small) %> <% end %> <%= link_to content do %> diff --git a/app/views/content_page_shares/_stream_new_page_collection.html.erb b/app/views/content_page_shares/_stream_new_page_collection.html.erb index 8cfa9d52..45b50d33 100644 --- a/app/views/content_page_shares/_stream_new_page_collection.html.erb +++ b/app/views/content_page_shares/_stream_new_page_collection.html.erb @@ -23,7 +23,7 @@
    <%= link_to [share.user, share] do %> - <%= image_tag content.random_public_image %> + <%= image_tag content.first_public_image %> <% end %> <%= link_to content do %> diff --git a/app/views/content_page_shares/_stream_page_share.html.erb b/app/views/content_page_shares/_stream_page_share.html.erb index b2752486..9ba50507 100644 --- a/app/views/content_page_shares/_stream_page_share.html.erb +++ b/app/views/content_page_shares/_stream_page_share.html.erb @@ -23,7 +23,7 @@
    <%= link_to [share.user, share] do %> - <%= image_tag content.random_public_image(format: :small) %> + <%= image_tag content.first_public_image(format: :small) %> <% end %> <%= link_to content do %> diff --git a/app/views/content_page_shares/_stream_timeline_share.html.erb b/app/views/content_page_shares/_stream_timeline_share.html.erb index 71aff342..70d90b24 100644 --- a/app/views/content_page_shares/_stream_timeline_share.html.erb +++ b/app/views/content_page_shares/_stream_timeline_share.html.erb @@ -23,7 +23,7 @@
    <%= link_to [share.user, share] do %> - <%= image_tag content.random_public_image(format: :small) %> + <%= image_tag content.first_public_image(format: :small) %> <% end %> <%= link_to content do %> diff --git a/app/views/content_page_shares/show.html.erb b/app/views/content_page_shares/show.html.erb index 465259ad..fed788a9 100644 --- a/app/views/content_page_shares/show.html.erb +++ b/app/views/content_page_shares/show.html.erb @@ -7,7 +7,7 @@
    <%= link_to @share.content_page do %> - <%= image_tag @share.content_page.random_public_image %> + <%= image_tag @share.content_page.first_public_image %> <%= @share.content_page.class.icon %> <%= @share.content_page.name %> diff --git a/app/views/page_collection_submissions/index.html.erb b/app/views/page_collection_submissions/index.html.erb index 1182af51..cae1fa77 100644 --- a/app/views/page_collection_submissions/index.html.erb +++ b/app/views/page_collection_submissions/index.html.erb @@ -20,7 +20,7 @@
    <%= link_to content do %> - <%= image_tag content.random_public_image %> + <%= image_tag content.first_public_image %> <% end %>
    diff --git a/app/views/page_collections/_collection_grid.html.erb b/app/views/page_collections/_collection_grid.html.erb index 44f6c8c1..4dcb119d 100644 --- a/app/views/page_collections/_collection_grid.html.erb +++ b/app/views/page_collections/_collection_grid.html.erb @@ -7,7 +7,7 @@ <%= link_to collection do %>
    - <%= image_tag collection.random_public_image, style: 'max-height: 250px;' %> + <%= image_tag collection.first_public_image, style: 'max-height: 250px;' %> <%= collection.title %>
    diff --git a/app/views/page_collections/_stream.html.erb b/app/views/page_collections/_stream.html.erb index 4f28ad74..6a017648 100644 --- a/app/views/page_collections/_stream.html.erb +++ b/app/views/page_collections/_stream.html.erb @@ -4,7 +4,7 @@
    <%= link_to content do %> - <%= image_tag content.random_public_image %> + <%= image_tag content.first_public_image %> <% end %>
    diff --git a/app/views/page_collections/_tiles.html.erb b/app/views/page_collections/_tiles.html.erb index fccfd8b4..3996b7ec 100644 --- a/app/views/page_collections/_tiles.html.erb +++ b/app/views/page_collections/_tiles.html.erb @@ -5,7 +5,7 @@ <% next unless (current_user || User.new).can_read?(content) %>
    - <%= image_tag content.random_public_image, class: 'activator', style: "height: 300px;" %> + <%= image_tag content.first_public_image, class: 'activator', style: "height: 300px;" %>
    diff --git a/app/views/users/profile/_recent_activity.html.erb b/app/views/users/profile/_recent_activity.html.erb index 324a4d83..6e9b1b8d 100644 --- a/app/views/users/profile/_recent_activity.html.erb +++ b/app/views/users/profile/_recent_activity.html.erb @@ -4,7 +4,7 @@ <% next unless User.new.can_read?(entity) || (user_signed_in? && current_user.can_read?(entity)) %>
    - <%= image_tag entity.random_public_image(format: :large), style: 'max-width: 280px; object-fit: cover; min-height: 100%' %> + <%= image_tag entity.first_public_image(format: :large), style: 'max-width: 280px; object-fit: cover; min-height: 100%' %>
    diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index c5f3a4e8..8ffe663c 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -101,7 +101,7 @@ <%= link_to universe do %>
    - <%= image_tag universe.random_public_image %> + <%= image_tag universe.first_public_image %> <%= universe.name %>
    @@ -140,7 +140,7 @@ <%= link_to page_collection do %>
    - <%= image_tag page_collection.random_public_image %> + <%= image_tag page_collection.first_public_image %> <%= PageCollection.icon %> <%= page_collection.title %>
    @@ -166,7 +166,7 @@ <%= link_to page_collection do %>
    - <%= image_tag page_collection.random_public_image, height: 250 %> + <%= image_tag page_collection.first_public_image, height: 250 %> <%= PageCollection.icon %> <%= page_collection.title %>
    diff --git a/lib/extensions/thredded/topic.rb b/lib/extensions/thredded/topic.rb index 33ee5826..ecb82136 100644 --- a/lib/extensions/thredded/topic.rb +++ b/lib/extensions/thredded/topic.rb @@ -33,6 +33,11 @@ module Extensions def random_public_image "card-headers/discussions.jpg" end + + def first_public_image + "card-headers/discussions.jpg" + end + def name self.title end From 0f9ea29c31ec4a3a96ab6814496468f19949b6fb Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Sat, 23 Jan 2021 15:35:45 -0800 Subject: [PATCH 10/12] add nofollow to links in document#show --- app/helpers/application_helper.rb | 5 +++++ app/views/documents/show.html.erb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fbe61078..cfc59dfa 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -26,4 +26,9 @@ module ApplicationHelper def title(*parts) content_for(:title) { (parts << 'Notebook').join(' - ') } unless parts.empty? end + + def clean_links html + html.gsub!(/\(.*?)\<\/a\>/mi, '\2') + html.html_safe + end end diff --git a/app/views/documents/show.html.erb b/app/views/documents/show.html.erb index be5905c9..79f7005d 100644 --- a/app/views/documents/show.html.erb +++ b/app/views/documents/show.html.erb @@ -2,5 +2,5 @@ <%= content_for :full_width_page_header do %> <%= render partial: 'documents/components/document_name_bar', locals: { document: @document } %> -
    <%= ContentFormatterService.substitute_content_links(@document.body.try(:html_safe) || "", current_user).html_safe %>
    +
    <%= ContentFormatterService.substitute_content_links(clean_links(@document.body.try(:html_safe)) || "", current_user).html_safe %>
    <% end %> From 1d00f3c2035e15bac51449196e26e27c02a773e8 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Sat, 23 Jan 2021 16:16:48 -0800 Subject: [PATCH 11/12] don't link to private profiles from forums --- config/initializers/thredded.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/initializers/thredded.rb b/config/initializers/thredded.rb index d452cfea..f2de2460 100644 --- a/config/initializers/thredded.rb +++ b/config/initializers/thredded.rb @@ -20,6 +20,8 @@ Thredded.user_display_name_method = :forum_username # When linking to a user, Thredded will use this lambda to spit out # the path or url to your user. This lambda is evaluated in the view context. Thredded.user_path = lambda do |user| + return nil if user && user.private_profile? + user_path = :"#{Thredded.user_class_name.underscore}_path" main_app.respond_to?(user_path) ? main_app.send(user_path, user) : "/users/#{user.to_param}" end From 972d2735697765fe5ace0c2b1331371979cd46c1 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Sat, 23 Jan 2021 17:04:58 -0800 Subject: [PATCH 12/12] enable email updates to new threads again --- config/initializers/thredded.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/initializers/thredded.rb b/config/initializers/thredded.rb index f2de2460..8975d977 100644 --- a/config/initializers/thredded.rb +++ b/config/initializers/thredded.rb @@ -151,10 +151,10 @@ Thredded.layout = 'layouts/forum' # Change how users can choose to be notified, by adding notifiers here, or removing the initializer altogether # # default: -# Thredded.notifiers = [Thredded::EmailNotifier.new] +Thredded.notifiers = [Thredded::EmailNotifier.new] # # none: -Thredded.notifiers = [] +# Thredded.notifiers = [] # # add in (must install separate gem (under development) as well): # Thredded.notifiers = [Thredded::EmailNotifier.new, Thredded::PushoverNotifier.new(ENV['PUSHOVER_APP_ID'])]