mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-09 13:28:53 +08:00
fixes typos, fixes pdf rendering
This commit is contained in:
parent
4573655ec8
commit
ca0c8cbb71
12 changed files with 45 additions and 47 deletions
|
@ -210,8 +210,7 @@ var HelperModule = (function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
helpers.flashAlertMsg = function(message, type) {
|
helpers.flashAlertMsg = function(message, type) {
|
||||||
var alertType;
|
var alertType, glyphSign;
|
||||||
var glyphSign;
|
|
||||||
|
|
||||||
$('#notifications').html('');
|
$('#notifications').html('');
|
||||||
if (type === 'success') {
|
if (type === 'success') {
|
||||||
|
|
|
@ -36,12 +36,7 @@
|
||||||
{
|
{
|
||||||
value: el.id,
|
value: el.id,
|
||||||
text: el.name,
|
text: el.name,
|
||||||
disabled: false,
|
disabled: false
|
||||||
data: {
|
|
||||||
hasFile: el.hasOwnProperty('has_file_attached') ?
|
|
||||||
el.has_file_attached :
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
@ -167,7 +162,7 @@
|
||||||
.selectpicker({liveSearch: true})
|
.selectpicker({liveSearch: true})
|
||||||
.ajaxSelectPicker({
|
.ajaxSelectPicker({
|
||||||
ajax: {
|
ajax: {
|
||||||
url: '<%= Rails.application.routes.url_helpers.file_columns_path %>',
|
url: '<%= Rails.application.routes.url_helpers.available_asset_type_columns_path %>',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
data: function () {
|
data: function () {
|
||||||
|
@ -197,7 +192,7 @@
|
||||||
clearDropdownResultsCallback(COLUMN_PICKER);
|
clearDropdownResultsCallback(COLUMN_PICKER);
|
||||||
}
|
}
|
||||||
|
|
||||||
function initInvenoriesSelectPicker() {
|
function initInventoriesSelectPicker() {
|
||||||
INVENTORY_PICKER =
|
INVENTORY_PICKER =
|
||||||
$('#selectInventory')
|
$('#selectInventory')
|
||||||
.selectpicker({liveSearch: true})
|
.selectpicker({liveSearch: true})
|
||||||
|
@ -256,9 +251,9 @@
|
||||||
* INITIALIZERS
|
* INITIALIZERS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function initializeSavePDFtoInvenotryModal() {
|
function initializeSavePDFtoInventoryModal() {
|
||||||
$('#savePDFtoInventory').off().on('shown.bs.modal', function() {
|
$('#savePDFtoInventory').off().on('shown.bs.modal', function() {
|
||||||
initInvenoriesSelectPicker();
|
initInventoriesSelectPicker();
|
||||||
initializeSubmitAction();
|
initializeSubmitAction();
|
||||||
clearErrors();
|
clearErrors();
|
||||||
// refresh the dropdown state
|
// refresh the dropdown state
|
||||||
|
@ -283,5 +278,5 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(initializeSavePDFtoInvenotryModal);
|
$(document).ready(initializeSavePDFtoInventoryModal);
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -168,14 +168,14 @@ class ReportsController < ApplicationController
|
||||||
# Generation action
|
# Generation action
|
||||||
# Currently, only .PDF is supported
|
# Currently, only .PDF is supported
|
||||||
def generate
|
def generate
|
||||||
|
content = params[:html]
|
||||||
|
content = I18n.t('projects.reports.new.no_content_for_PDF_html') if content.blank?
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.pdf do
|
format.pdf do
|
||||||
@html = params[:html]
|
render pdf: 'report', header: { right: '[page] of [topage]' },
|
||||||
@html = I18n.t('projects.reports.new.no_content_for_PDF_html') if @html.blank?
|
locals: { content: content },
|
||||||
render pdf: 'report',
|
template: 'reports/report.pdf.erb',
|
||||||
header: { right: '[page] of [topage]' },
|
disable_javascript: true
|
||||||
template: 'reports/report.pdf.erb',
|
|
||||||
disable_javascript: true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -196,7 +196,7 @@ class ReportsController < ApplicationController
|
||||||
render json: { message: cell_value.errors.full_messages.join },
|
render json: { message: cell_value.errors.full_messages.join },
|
||||||
status: :unprocessable_entity
|
status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
rescue ReportActions::RepostioryPermissionError => error
|
rescue ReportActions::RepositoryPermissionError => error
|
||||||
render json: { message: error },
|
render json: { message: error },
|
||||||
status: :unprocessable_entity
|
status: :unprocessable_entity
|
||||||
rescue Exception => error
|
rescue Exception => error
|
||||||
|
@ -487,17 +487,18 @@ class ReportsController < ApplicationController
|
||||||
.select(:id, :name)
|
.select(:id, :name)
|
||||||
@visible_projects = projects.collect do |project|
|
@visible_projects = projects.collect do |project|
|
||||||
VisibleProject.new(new_project_reports_path(project),
|
VisibleProject.new(new_project_reports_path(project),
|
||||||
ellipsisize(project.name, 75, 50))
|
ellipsize(project.name, 75, 50))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_available_repositories
|
def load_available_repositories
|
||||||
repositories = current_team.repositories
|
repositories = current_team.repositories
|
||||||
.name_like(search_params[:q])
|
.name_like(search_params[:q])
|
||||||
|
.limit(Constants::SEARCH_LIMIT)
|
||||||
.select(:id, :name)
|
.select(:id, :name)
|
||||||
@available_repositories = repositories.collect do |repository|
|
@available_repositories = repositories.collect do |repository|
|
||||||
AvailableRepository.new(repository.id,
|
AvailableRepository.new(repository.id,
|
||||||
ellipsisize(repository.name, 75, 50))
|
ellipsize(repository.name, 75, 50))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
class RepositoryColumnsController < ApplicationController
|
class RepositoryColumnsController < ApplicationController
|
||||||
include InputSanitizeHelper
|
include InputSanitizeHelper
|
||||||
|
ACTIONS = %i(create index create_html available_asset_type_columns).freeze
|
||||||
before_action :load_vars, except: %i(create index create_html file_columns)
|
before_action :load_vars,
|
||||||
|
except: ACTIONS
|
||||||
before_action :load_vars_nested,
|
before_action :load_vars_nested,
|
||||||
only: %i(create index create_html file_columns)
|
only: ACTIONS
|
||||||
before_action :check_create_permissions, only: :create
|
before_action :check_create_permissions, only: :create
|
||||||
before_action :check_manage_permissions,
|
before_action :check_manage_permissions,
|
||||||
except: %i(create index create_html file_columns)
|
except: ACTIONS
|
||||||
before_action :load_repository_columns, only: :index
|
before_action :load_repository_columns, only: :index
|
||||||
before_action :load_asset_type_columns, only: :file_columns
|
before_action :load_asset_type_columns, only: :available_asset_type_columns
|
||||||
|
|
||||||
def index; end
|
def index; end
|
||||||
|
|
||||||
|
@ -142,7 +143,7 @@ class RepositoryColumnsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_columns
|
def available_asset_type_columns
|
||||||
if @asset_columns.empty?
|
if @asset_columns.empty?
|
||||||
render json: {
|
render json: {
|
||||||
no_items: t(
|
no_items: t(
|
||||||
|
@ -207,7 +208,7 @@ class RepositoryColumnsController < ApplicationController
|
||||||
.collect do |column|
|
.collect do |column|
|
||||||
AvailableRepositoryColumn.new(
|
AvailableRepositoryColumn.new(
|
||||||
column.id,
|
column.id,
|
||||||
ellipsisize(column.name)
|
ellipsize(column.name, 75, 50)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -376,7 +376,7 @@ class RepositoryRowsController < ApplicationController
|
||||||
search_params[:repository_column_id]
|
search_params[:repository_column_id]
|
||||||
)
|
)
|
||||||
AvailableRepositoryRow.new(row.id,
|
AvailableRepositoryRow.new(row.id,
|
||||||
ellipsisize(row.name),
|
ellipsize(row.name, 75, 50),
|
||||||
with_asset_cell.present?)
|
with_asset_cell.present?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module StringUtility
|
module StringUtility
|
||||||
def ellipsisize(
|
def ellipsize(
|
||||||
string,
|
string,
|
||||||
minimum_length = Constants::MAX_NAME_TRUNCATION,
|
minimum_length = Constants::MAX_NAME_TRUNCATION,
|
||||||
edge_length = Constants::MAX_EDGE_LENGTH
|
edge_length = Constants::MAX_EDGE_LENGTH
|
||||||
|
|
|
@ -59,8 +59,8 @@ class Repository < ApplicationRecord
|
||||||
|
|
||||||
def self.name_like(query)
|
def self.name_like(query)
|
||||||
where('repositories.name ILIKE ?', "%#{query}%")
|
where('repositories.name ILIKE ?', "%#{query}%")
|
||||||
.limit(Constants::SEARCH_LIMIT)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def importable_repository_fields
|
def importable_repository_fields
|
||||||
fields = {}
|
fields = {}
|
||||||
# First and foremost add record name
|
# First and foremost add record name
|
||||||
|
|
|
@ -33,22 +33,23 @@ module ReportActions
|
||||||
@params[:repository_item_id]
|
@params[:repository_item_id]
|
||||||
)
|
)
|
||||||
unless can_create_repository_rows?(@user, @repository.team)
|
unless can_create_repository_rows?(@user, @repository.team)
|
||||||
raise ReportActions::RepostioryPermissionError,
|
raise ReportActions::RepositoryPermissionError,
|
||||||
I18n.t('projects.reports.new.no_permissions')
|
I18n.t('projects.reports.new.no_permissions')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_pdf(html)
|
def generate_pdf(content)
|
||||||
ac = ActionView::Base.new(ActionController::Base.view_paths, {})
|
ac = ActionView::Base.new(ActionController::Base.view_paths, {})
|
||||||
ac.extend ReportsHelper # include reports helper methods to view
|
ac.extend ReportsHelper # include reports helper methods to view
|
||||||
ac.extend InputSanitizeHelper # include input sanitize methods to view
|
ac.extend InputSanitizeHelper # include input sanitize methods to view
|
||||||
no_content_label = I18n.t('projects.reports.new.no_content_for_PDF_html')
|
no_content_label = I18n.t('projects.reports.new.no_content_for_PDF_html')
|
||||||
save_path = Tempfile.open('report', Rails.root.join('tmp'))
|
save_path = Tempfile.open(['report', '.pdf'], Rails.root.join('tmp'))
|
||||||
@html = html
|
content = no_content_label if content.blank?
|
||||||
@html = no_content_label if @html.blank?
|
|
||||||
pdf_file = WickedPdf.new.pdf_from_string(
|
pdf_file = WickedPdf.new.pdf_from_string(
|
||||||
ac.render(template: 'reports/report.pdf.erb'),
|
ac.render(template: 'reports/report.pdf.erb',
|
||||||
header: { right: '[page] of [topage]' }, disable_javascript: true
|
locals: { content: content }),
|
||||||
|
header: { right: '[page] of [topage]' },
|
||||||
|
disable_javascript: true
|
||||||
)
|
)
|
||||||
File.open(save_path, 'wb') do |file|
|
File.open(save_path, 'wb') do |file|
|
||||||
file << pdf_file
|
file << pdf_file
|
||||||
|
@ -83,5 +84,5 @@ module ReportActions
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
RepostioryPermissionError = Class.new(StandardError)
|
RepositoryPermissionError = Class.new(StandardError)
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
disabled>
|
disabled>
|
||||||
</select>
|
</select>
|
||||||
<div id="save-PDF-to-inventory-column-warnings"></div>
|
<div id="save-PDF-to-inventory-column-warnings"></div>
|
||||||
<label><%=t 'projects.reports.new.save_PDF_to_inventory_modal.inventory_column' %></label>
|
<label><%=t 'projects.reports.new.save_PDF_to_inventory_modal.inventory_item' %></label>
|
||||||
<select
|
<select
|
||||||
id="selectInventoryItem"
|
id="selectInventoryItem"
|
||||||
class="form-control selectpicker"
|
class="form-control selectpicker"
|
||||||
|
@ -44,13 +44,13 @@
|
||||||
<div class="save-PDF-to-inventory-alerts" id="save-PDF-to-inventory-warnings"></div>
|
<div class="save-PDF-to-inventory-alerts" id="save-PDF-to-inventory-warnings"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-default" data-dismiss="modal"><%=t 'general.close' %></button>
|
<button type="button" class="btn btn-default" data-dismiss="modal"><%=t 'general.cancel' %></button>
|
||||||
<button
|
<button
|
||||||
id="savePDFtoInventorySubmit"
|
id="savePDFtoInventorySubmit"
|
||||||
type="button"
|
type="button"
|
||||||
class="btn btn-primary"
|
class="btn btn-primary"
|
||||||
disabled
|
disabled
|
||||||
>Save changes</button>
|
><%=t 'general.save' %></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<body class="print-report-body">
|
<body class="print-report-body">
|
||||||
<div class="print-report">
|
<div class="print-report">
|
||||||
<% # Also whitelist <img> and <input type="checkbox"> tags %>
|
<% # Also whitelist <img> and <input type="checkbox"> tags %>
|
||||||
<%= sanitize_input(fix_smart_annotation_image(@html),
|
<%= sanitize_input(fix_smart_annotation_image(content),
|
||||||
%w(img input),
|
%w(img input),
|
||||||
%w(type disabled checked)) %>
|
%w(type disabled checked)) %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -329,7 +329,7 @@ en:
|
||||||
no_permissions: "You don't have permissions on that repository"
|
no_permissions: "You don't have permissions on that repository"
|
||||||
save_PDF_to_inventory_modal:
|
save_PDF_to_inventory_modal:
|
||||||
description_one: "Here you can save PDF report to an inventory item."
|
description_one: "Here you can save PDF report to an inventory item."
|
||||||
description_two: "First select an inventory, then a column and finally the item within tne inventory to which you would like to save the PDF report to. Note that the column has to be of type \"file\"."
|
description_two: "First select an inventory, then a column and finally the item within the inventory to which you would like to save the PDF report to. Note that the column has to be of type \"file\"."
|
||||||
inventory: "Select inventory:"
|
inventory: "Select inventory:"
|
||||||
inventory_column: "Select inventory column:"
|
inventory_column: "Select inventory column:"
|
||||||
inventory_item: "Select inventory item:"
|
inventory_item: "Select inventory item:"
|
||||||
|
|
|
@ -198,8 +198,9 @@ Rails.application.routes.draw do
|
||||||
post 'reports/save_pdf_to_inventory_item',
|
post 'reports/save_pdf_to_inventory_item',
|
||||||
to: 'reports#save_pdf_to_inventory_item',
|
to: 'reports#save_pdf_to_inventory_item',
|
||||||
defaults: { format: 'json' }
|
defaults: { format: 'json' }
|
||||||
post 'file_columns', to: 'repository_columns#file_columns',
|
post 'available_asset_type_columns',
|
||||||
defaults: { format: 'json' }
|
to: 'repository_columns#available_asset_type_columns',
|
||||||
|
defaults: { format: 'json' }
|
||||||
post 'reports/destroy', to: 'reports#destroy'
|
post 'reports/destroy', to: 'reports#destroy'
|
||||||
|
|
||||||
resources :projects, except: [:new, :destroy] do
|
resources :projects, except: [:new, :destroy] do
|
||||||
|
|
Loading…
Add table
Reference in a new issue