From 66e0bdc053f32380fee601caa61cfbe197576294 Mon Sep 17 00:00:00 2001 From: Mark VanLandingham Date: Fri, 1 Nov 2019 14:19:10 -0500 Subject: [PATCH] FEATURE: Create New Topic button on embed with params (#8280) * FEATURE: Create New Topic button on embed with params --- app/assets/stylesheets/embed.scss | 27 +++++++++++++++++++++++++++ app/controllers/embed_controller.rb | 9 +++++++++ app/views/embed/topics.html.erb | 8 ++++++++ config/locales/server.en.yml | 1 + 4 files changed, 45 insertions(+) diff --git a/app/assets/stylesheets/embed.scss b/app/assets/stylesheets/embed.scss index c4c7046463d..d0acdb1e6fc 100644 --- a/app/assets/stylesheets/embed.scss +++ b/app/assets/stylesheets/embed.scss @@ -3,6 +3,7 @@ @import "./common/foundation/variables"; @import "./common/foundation/colors"; @import "./common/foundation/mixins"; +@import "./common/components/buttons"; article.post { border-bottom: 1px solid #ddd; @@ -176,6 +177,32 @@ div.lightbox-wrapper { margin-bottom: 20px; } +.new-topic-btn { + margin: 0.5rem; + + &:hover { + background: #006da3; + } + + span { + display: inline-block; + vertical-align: middle; + padding-bottom: 2px; + } + + .new-topic-btn__icon { + width: 16px; + height: 16px; + margin-right: 2px; + background-image: svg-uri( + '' + ); + background-repeat: no-repeat; + background-size: 100%; + background-position: top center; + } +} + .topics-list { width: 100%; diff --git a/app/controllers/embed_controller.rb b/app/controllers/embed_controller.rb index 0d8f53eed2c..04e6a2ec89f 100644 --- a/app/controllers/embed_controller.rb +++ b/app/controllers/embed_controller.rb @@ -42,6 +42,15 @@ class EmbedController < ApplicationController list_options = build_topic_list_options list_options[:per_page] = params[:per_page].to_i if params.has_key?(:per_page) + + if params[:allow_create] + @allow_create = true + create_url_params = {} + create_url_params[:category_id] = params[:category] if params[:category].present? + create_url_params[:tags] = params[:tags] if params[:tags].present? + @create_url = "#{Discourse.base_url}/new-topic?#{create_url_params.to_query}" + end + topic_query = TopicQuery.new(current_user, list_options) @list = topic_query.list_latest end diff --git a/app/views/embed/topics.html.erb b/app/views/embed/topics.html.erb index 2aaf3267969..10b825f7273 100644 --- a/app/views/embed/topics.html.erb +++ b/app/views/embed/topics.html.erb @@ -1,4 +1,12 @@ <%- if @list && @list.topics.present? %> + <%- if @allow_create %> + <%= link_to @create_url, target: "_blank" do |link| %> + + <%- end %> + <%- end %>
data-embed-id="<%= @embed_id %>"<%- end %>> <%- @list.topics.each do |t| %>
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index c7e926513aa..bc323fbb774 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -296,6 +296,7 @@ en: other: "%{count} likes" last_reply: "Last reply" created: "Created" + new_topic: "Create new topic" no_mentions_allowed: "Sorry, you can't mention other users." too_many_mentions: