Feature: Adds a button to print a topic

This commit is contained in:
Rafael dos Santos Silva 2016-08-01 01:45:05 -03:00
parent 999f52954f
commit c12e533273
8 changed files with 38 additions and 2 deletions

View File

@ -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) {

View File

@ -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');
}
});

View File

@ -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');
}

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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+/}

View File

@ -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