Feature: Adds a button to print a topic
This commit is contained in:
parent
999f52954f
commit
c12e533273
|
@ -134,6 +134,10 @@ const Topic = RestModel.extend({
|
|||
return this.get('url') + (user ? '?u=' + user.get('username_lower') : '');
|
||||
}.property('url'),
|
||||
|
||||
printUrl: function(){
|
||||
return this.get('url') + '/print';
|
||||
}.property('url'),
|
||||
|
||||
url: function() {
|
||||
let slug = this.get('slug') || '';
|
||||
if (slug.trim().length === 0) {
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
import ButtonView from 'discourse/views/button';
|
||||
import { iconHTML } from 'discourse/helpers/fa-icon';
|
||||
|
||||
export default ButtonView.extend({
|
||||
classNames: ['print'],
|
||||
textKey: 'topic.print.title',
|
||||
helpKey: 'topic.print.help',
|
||||
|
||||
renderIcon(buffer) {
|
||||
buffer.push(iconHTML("print"));
|
||||
},
|
||||
|
||||
click() {
|
||||
window.open(this.get('controller.model.printUrl'), '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,width=600,height=315');
|
||||
}
|
||||
});
|
|
@ -32,6 +32,8 @@ export default ContainerView.extend({
|
|||
this.attachViewClass('invite-reply-button');
|
||||
}
|
||||
|
||||
this.attachViewClass('print-button');
|
||||
|
||||
if (topic.get('isPrivateMessage')) {
|
||||
this.attachViewClass('archive-button');
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def use_crawler_layout?
|
||||
@use_crawler_layout ||= (has_escaped_fragment? || CrawlerDetection.crawler?(request.user_agent))
|
||||
@use_crawler_layout ||= (has_escaped_fragment? || CrawlerDetection.crawler?(request.user_agent) || params.key?("print"))
|
||||
end
|
||||
|
||||
def add_readonly_header
|
||||
|
|
|
@ -58,6 +58,7 @@ class TopicsController < ApplicationController
|
|||
username_filters = opts[:username_filters]
|
||||
|
||||
opts[:slow_platform] = true if slow_platform?
|
||||
opts[:print] = true if params[:print].present?
|
||||
opts[:username_filters] = username_filters.split(',') if username_filters.is_a?(String)
|
||||
|
||||
# Special case: a slug with a number in front should look by slug first before looking
|
||||
|
|
|
@ -1459,6 +1459,10 @@ en:
|
|||
title: 'Share'
|
||||
help: 'share a link to this topic'
|
||||
|
||||
print:
|
||||
title: 'Print'
|
||||
help: 'Open a printer friendly version of this topic'
|
||||
|
||||
flag_topic:
|
||||
title: 'Flag'
|
||||
help: 'privately flag this topic for attention or send a private notification about it'
|
||||
|
|
|
@ -554,6 +554,7 @@ Discourse::Application.routes.draw do
|
|||
|
||||
# Topic routes
|
||||
get "t/id_for/:slug" => "topics#id_for_slug"
|
||||
get "t/:slug/:topic_id/print" => "topics#show", format: :html, print: true, constraints: {topic_id: /\d+/}
|
||||
get "t/:slug/:topic_id/wordpress" => "topics#wordpress", constraints: {topic_id: /\d+/}
|
||||
get "t/:topic_id/wordpress" => "topics#wordpress", constraints: {topic_id: /\d+/}
|
||||
get "t/:slug/:topic_id/moderator-liked" => "topics#moderator_liked", constraints: {topic_id: /\d+/}
|
||||
|
|
|
@ -12,6 +12,10 @@ class TopicView
|
|||
10
|
||||
end
|
||||
|
||||
def self.print_chunk_size
|
||||
1000
|
||||
end
|
||||
|
||||
def self.chunk_size
|
||||
20
|
||||
end
|
||||
|
@ -44,7 +48,11 @@ class TopicView
|
|||
end
|
||||
|
||||
@page = 1 if (!@page || @page.zero?)
|
||||
@chunk_size = options[:slow_platform] ? TopicView.slow_chunk_size : TopicView.chunk_size
|
||||
@chunk_size = case
|
||||
when options[:slow_platform] then TopicView.slow_chunk_size
|
||||
when options[:print] then 1000
|
||||
else TopicView.chunk_size
|
||||
end
|
||||
@limit ||= @chunk_size
|
||||
|
||||
setup_filtered_posts
|
||||
|
|
Loading…
Reference in New Issue