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