mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 19:02:40 +08:00
Feature: Adds a button to print a topic
This commit is contained in:
@ -134,6 +134,10 @@ const Topic = RestModel.extend({
|
|||||||
return this.get('url') + (user ? '?u=' + user.get('username_lower') : '');
|
return this.get('url') + (user ? '?u=' + user.get('username_lower') : '');
|
||||||
}.property('url'),
|
}.property('url'),
|
||||||
|
|
||||||
|
printUrl: function(){
|
||||||
|
return this.get('url') + '/print';
|
||||||
|
}.property('url'),
|
||||||
|
|
||||||
url: function() {
|
url: function() {
|
||||||
let slug = this.get('slug') || '';
|
let slug = this.get('slug') || '';
|
||||||
if (slug.trim().length === 0) {
|
if (slug.trim().length === 0) {
|
||||||
|
16
app/assets/javascripts/discourse/views/print-button.js.es6
Normal file
16
app/assets/javascripts/discourse/views/print-button.js.es6
Normal 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');
|
||||||
|
}
|
||||||
|
});
|
@ -32,6 +32,8 @@ export default ContainerView.extend({
|
|||||||
this.attachViewClass('invite-reply-button');
|
this.attachViewClass('invite-reply-button');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.attachViewClass('print-button');
|
||||||
|
|
||||||
if (topic.get('isPrivateMessage')) {
|
if (topic.get('isPrivateMessage')) {
|
||||||
this.attachViewClass('archive-button');
|
this.attachViewClass('archive-button');
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ class ApplicationController < ActionController::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def use_crawler_layout?
|
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
|
end
|
||||||
|
|
||||||
def add_readonly_header
|
def add_readonly_header
|
||||||
|
@ -58,6 +58,7 @@ class TopicsController < ApplicationController
|
|||||||
username_filters = opts[:username_filters]
|
username_filters = opts[:username_filters]
|
||||||
|
|
||||||
opts[:slow_platform] = true if slow_platform?
|
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)
|
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
|
# Special case: a slug with a number in front should look by slug first before looking
|
||||||
|
@ -1459,6 +1459,10 @@ en:
|
|||||||
title: 'Share'
|
title: 'Share'
|
||||||
help: 'share a link to this topic'
|
help: 'share a link to this topic'
|
||||||
|
|
||||||
|
print:
|
||||||
|
title: 'Print'
|
||||||
|
help: 'Open a printer friendly version of this topic'
|
||||||
|
|
||||||
flag_topic:
|
flag_topic:
|
||||||
title: 'Flag'
|
title: 'Flag'
|
||||||
help: 'privately flag this topic for attention or send a private notification about it'
|
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
|
# Topic routes
|
||||||
get "t/id_for/:slug" => "topics#id_for_slug"
|
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/:slug/:topic_id/wordpress" => "topics#wordpress", constraints: {topic_id: /\d+/}
|
||||||
get "t/: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+/}
|
get "t/:slug/:topic_id/moderator-liked" => "topics#moderator_liked", constraints: {topic_id: /\d+/}
|
||||||
|
@ -12,6 +12,10 @@ class TopicView
|
|||||||
10
|
10
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.print_chunk_size
|
||||||
|
1000
|
||||||
|
end
|
||||||
|
|
||||||
def self.chunk_size
|
def self.chunk_size
|
||||||
20
|
20
|
||||||
end
|
end
|
||||||
@ -44,7 +48,11 @@ class TopicView
|
|||||||
end
|
end
|
||||||
|
|
||||||
@page = 1 if (!@page || @page.zero?)
|
@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
|
@limit ||= @chunk_size
|
||||||
|
|
||||||
setup_filtered_posts
|
setup_filtered_posts
|
||||||
|
Reference in New Issue
Block a user