mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-05 20:54:27 +08:00
removes asset_helper, fixes loading of processed thumbnails in results and steps and when loading protocols from repository
This commit is contained in:
parent
40fdfef67f
commit
de3099e4d1
13 changed files with 117 additions and 86 deletions
|
@ -1,6 +1,6 @@
|
|||
function setupAssetsLoading() {
|
||||
var DELAY = 2000;
|
||||
var REPETITIONS = 15;
|
||||
var DELAY = 2500;
|
||||
var REPETITIONS = 60;
|
||||
|
||||
function refreshAssets() {
|
||||
var elements = $("[data-status='asset-loading']");
|
||||
|
@ -12,7 +12,6 @@ function setupAssetsLoading() {
|
|||
$.each(elements, function(_, el) {
|
||||
var $el = $(el);
|
||||
var spinner = $el.find(".asset-loading-spinner");
|
||||
var type = $el.data("type");
|
||||
|
||||
// Perform an AJAX call to present URL
|
||||
// to check if file already exists
|
||||
|
@ -22,36 +21,41 @@ function setupAssetsLoading() {
|
|||
dataType: "json",
|
||||
success: function (data) {
|
||||
$el.attr("data-status", "asset-loaded");
|
||||
$el.find(".asset-loading-spinner").spin(false);
|
||||
$el.find('img').hide();
|
||||
$el.next().hide();
|
||||
$el.html("");
|
||||
|
||||
if (type === "image") {
|
||||
if (data.type === "image") {
|
||||
$el.html(
|
||||
"<a href='" + $el.data("download-url") + "'>" +
|
||||
"<img src='" + $el.data("preview-url") + "'><br>" +
|
||||
$el.data("filename") + "</a>"
|
||||
"<a href='" + data['download-url'] + "'>" +
|
||||
"<img src='" + data['preview-url'] + "'><p>" +
|
||||
data.filename + "</p></a>"
|
||||
);
|
||||
} else {
|
||||
$el.html(
|
||||
"<a href='" + $el.data("download-url") + "'>" +
|
||||
$el.data("filename") + "</a>"
|
||||
"<a href='" + data['download-url'] + "'><p>" +
|
||||
data.filename + "</p></a>"
|
||||
);
|
||||
}
|
||||
animateSpinner(null, false);
|
||||
},
|
||||
error: function (ev) {
|
||||
if (ev.status == 403) {
|
||||
$el.find('img').hide();
|
||||
$el.next().hide();
|
||||
// Image/file exists, but user doesn't have
|
||||
// rights to download it
|
||||
if (type === "image") {
|
||||
$el.html(
|
||||
"<img src='" + $el.data("preview-url") + "'><br>" +
|
||||
$el.data("filename")
|
||||
"<img src='" + $data['preview-url'] + "'><p>" +
|
||||
data.filename + "</p>"
|
||||
);
|
||||
} else {
|
||||
$el.html($el.data("filename"));
|
||||
$el.html("<p>" + data.filename + "</p>");
|
||||
}
|
||||
} else {
|
||||
// Do nothing, file is not yet present
|
||||
animateSpinner(null, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -21,6 +21,7 @@ function init() {
|
|||
Comments.bindNewElement();
|
||||
Comments.initialize();
|
||||
initTutorial();
|
||||
setupAssetsLoading();
|
||||
}
|
||||
|
||||
// Initialize edit description modal window
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
//= require assets
|
||||
//= require comments
|
||||
|
||||
/**
|
||||
|
@ -108,6 +109,8 @@ function expandResult(result) {
|
|||
$(this).removeClass("glyphicon-collapse-down");
|
||||
});
|
||||
renderTable($(result).find("div.step-result-hot-table"));
|
||||
animateSpinner(null, false);
|
||||
setupAssetsLoading();
|
||||
}
|
||||
|
||||
function renderTable(table) {
|
||||
|
|
|
@ -102,6 +102,7 @@ function applyEditCallBack() {
|
|||
formEditAjax($form);
|
||||
toggleButtons(false);
|
||||
initializeCheckboxSorting();
|
||||
animateSpinner(null, false);
|
||||
|
||||
$("#new-step-checklists fieldset.nested_step_checklists ul").each(function () {
|
||||
enableCheckboxSorting(this);
|
||||
|
@ -209,6 +210,7 @@ function formEditAjax($form) {
|
|||
$new_step.find("[data-role='step-hot-table']").each(function() {
|
||||
renderTable($(this));
|
||||
});
|
||||
setupAssetsLoading();
|
||||
})
|
||||
.on("ajax:error", function(e, xhr, status, error) {
|
||||
$form.renderFormErrors('step', xhr.responseJSON, true, e);
|
||||
|
@ -245,6 +247,8 @@ function formNewAjax($form) {
|
|||
$new_step.find("div.step-result-hot-table").each(function() {
|
||||
$(this).handsontable("render");
|
||||
});
|
||||
animateSpinner(null, false);
|
||||
setupAssetsLoading();
|
||||
})
|
||||
.on("ajax:error", function(e, xhr, status, error) {
|
||||
$(this).after(xhr.responseJSON.html);
|
||||
|
@ -257,6 +261,7 @@ function formNewAjax($form) {
|
|||
formCallback($form);
|
||||
formNewAjax($form);
|
||||
applyCancelOnNew();
|
||||
animateSpinner(null, false);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,37 +1,39 @@
|
|||
class AssetsController < ApplicationController
|
||||
include ActionView::Helpers::TextHelper
|
||||
before_action :load_vars
|
||||
before_action :check_read_permission, except: :file_present
|
||||
|
||||
def file_present
|
||||
respond_to do |format|
|
||||
format.json {
|
||||
if @asset.file_present
|
||||
format.json do
|
||||
if @asset.file.processing?
|
||||
render json: {}, status: 404
|
||||
else
|
||||
# Only if file is present,
|
||||
# check_read_permission
|
||||
check_read_permission
|
||||
|
||||
# If check_read_permission already rendered error,
|
||||
# stop execution
|
||||
if performed? then
|
||||
return
|
||||
end
|
||||
return if performed?
|
||||
|
||||
# If check permission passes, return :ok
|
||||
render json: {}, status: 200
|
||||
else
|
||||
render json: {}, status: 404
|
||||
render json: {
|
||||
'preview-url' => @asset.url(:medium),
|
||||
'filename' => truncate(@asset.file_file_name,
|
||||
length:
|
||||
Constants::FILENAME_TRUNCATION_LENGTH),
|
||||
'download-url' => download_asset_path(@asset),
|
||||
'type' => (@asset.is_image? ? 'image' : 'file')
|
||||
}, status: 200
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def preview
|
||||
if @asset.is_image?
|
||||
if @asset.file.processing?
|
||||
redirect_to image_url('/images/processing.gif'), status: 307
|
||||
else
|
||||
redirect_to @asset.url(:medium), status: 307
|
||||
end
|
||||
redirect_to @asset.url(:medium), status: 307
|
||||
else
|
||||
render_400
|
||||
end
|
||||
|
|
|
@ -67,12 +67,15 @@ class StepsController < ApplicationController
|
|||
# Update protocol timestamp
|
||||
update_protocol_ts(@step)
|
||||
|
||||
format.json {
|
||||
format.json do
|
||||
render json: {
|
||||
html: render_to_string({
|
||||
partial: "steps/step.html.erb", locals: {step: @step}
|
||||
})}, status: :ok
|
||||
}
|
||||
html: render_to_string(
|
||||
partial: 'steps/step.html.erb',
|
||||
locals: { step: @step }
|
||||
)
|
||||
},
|
||||
status: :ok
|
||||
end
|
||||
else
|
||||
# On error, delete the newly added files from S3, as they were
|
||||
# uploaded on client-side (in case of client-side hacking of
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
module AssetsHelper
|
||||
|
||||
def asset_loading_span(asset)
|
||||
res = <<-eos
|
||||
<span
|
||||
data-status='asset-loading'
|
||||
data-filename='#{asset.file_file_name}'
|
||||
data-type='#{asset.is_image? ? "image" : "asset"}'
|
||||
data-present-url='#{file_present_asset_path(asset, format: :json)}'
|
||||
#{asset.is_image? ? "data-preview-url='" + preview_asset_path(asset) + "'" : ""}'
|
||||
data-download-url='#{download_asset_path(asset)}'
|
||||
>
|
||||
<span class='asset-loading-spinner' id='asset-loading-spinner-#{asset.id}'></span>
|
||||
#{t('general.file.uploading', fileName: asset.file_file_name)}
|
||||
</span>
|
||||
<script type='text/javascript'>
|
||||
$('#asset-loading-spinner-#{asset.id}').spin(
|
||||
{ lines: 9, length: 4, width: 3, radius: 4, scale: 1, corners: 1,
|
||||
color: #{Constants::COLOR_BLACK}, opacity: 0.25, rotate: 0, direction: 1, speed: 1,
|
||||
trail: 60, fps: 20, zIndex: 100, className: 'spinner', top: '75%',
|
||||
left: '50%', shadow: false, hwaccel: false, position: 'relative' }
|
||||
);
|
||||
</script>
|
||||
eos
|
||||
res.html_safe
|
||||
end
|
||||
end
|
|
@ -8,7 +8,7 @@ class Asset < ActiveRecord::Base
|
|||
# Paperclip validation
|
||||
has_attached_file :file,
|
||||
styles: { medium: [Constants::MEDIUM_PIC_FORMAT, :jpg] },
|
||||
convert_options: { medium: '-quality 20 -strip' }
|
||||
convert_options: { medium: '-quality 70 -strip' }
|
||||
|
||||
validates_attachment :file,
|
||||
presence: true,
|
||||
|
@ -33,7 +33,7 @@ class Asset < ActiveRecord::Base
|
|||
{}
|
||||
end
|
||||
},
|
||||
processing_image_url: '/images/medium/processing.gif'
|
||||
processing_image_url: '/images/:style/processing.gif'
|
||||
|
||||
# Asset validation
|
||||
# This could cause some problems if you create empty asset and want to
|
||||
|
|
|
@ -265,6 +265,7 @@ class Protocol < ActiveRecord::Base
|
|||
asset2.save
|
||||
|
||||
step2.assets << asset2
|
||||
asset2.file.delay.reprocess!(:medium)
|
||||
assets_to_clone << [asset.id, asset2.id]
|
||||
end
|
||||
|
||||
|
|
|
@ -1,10 +1,24 @@
|
|||
<% if can_view_or_download_result_assets(result.my_module) %>
|
||||
<%= link_to download_asset_path(result.asset), data: {no_turbolink: true} do %>
|
||||
<%= image_tag(preview_asset_path result.asset) if result.asset.is_image? %>
|
||||
<p><%= truncate(result.asset.file_file_name,
|
||||
length: Constants::FILENAME_TRUNCATION_LENGTH) %></p>
|
||||
<% if result.asset.file.processing? %>
|
||||
<span data-status='asset-loading'
|
||||
data-present-url='<%= file_present_asset_path(result.asset) %>'>
|
||||
<%= image_tag 'medium/processing.gif' %>
|
||||
</span>
|
||||
<% else %>
|
||||
<%= link_to download_asset_path(result.asset), data: {no_turbolink: true} do %>
|
||||
<%= image_tag(preview_asset_path result.asset) if result.asset.is_image? %>
|
||||
<p><%= truncate(result.asset.file_file_name,
|
||||
length: Constants::FILENAME_TRUNCATION_LENGTH) %></p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= image_tag(preview_asset_path result.asset) if result.asset.is_image? %>
|
||||
<p><%= result.asset.file_file_name %></p>
|
||||
<% if result.asset.file.processing? %>
|
||||
<span data-status='asset-loading'
|
||||
data-present-url='<%= file_present_asset_path(result.asset) %>'>
|
||||
<%= image_tag 'medium/processing.gif' %>
|
||||
</span>
|
||||
<% else %>
|
||||
<%= image_tag(preview_asset_path result.asset) if result.asset.is_image? %>
|
||||
<p><%= result.asset.file_file_name %></p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
|
|
@ -67,15 +67,32 @@
|
|||
<% if can_view_or_download_step_assets(@protocol) %>
|
||||
<% if asset.file_present %>
|
||||
<%= link_to download_asset_path(asset), data: {no_turbolink: true, id: true, status: "asset-present"} do %>
|
||||
<%= image_tag preview_asset_path(asset) if asset.is_image? %>
|
||||
<% if asset.file.processing? %>
|
||||
<span data-status='asset-loading'
|
||||
data-present-url='<%= file_present_asset_path(asset) %>'>
|
||||
<%= image_tag 'medium/processing.gif' %>
|
||||
</span>
|
||||
<% else %>
|
||||
<%= image_tag preview_asset_path(asset) if asset.is_image? %>
|
||||
<% end %>
|
||||
<p><%= truncate(asset.file_file_name,
|
||||
length: Constants::FILENAME_TRUNCATION_LENGTH) %></p>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= asset_loading_span(asset) %>
|
||||
<span data-status='asset-loading'
|
||||
data-present-url='<%= file_present_asset_path(asset) %>'>
|
||||
<%= image_tag 'medium/processing.gif' %>
|
||||
</span>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= image_tag preview_asset_path(asset) if asset.is_image? %>
|
||||
<% if asset.file.processing? %>
|
||||
<span data-status='asset-loading'
|
||||
data-present-url='<%= file_present_asset_path(asset) %>'>
|
||||
<%= image_tag 'medium/processing.gif' %>
|
||||
</span>
|
||||
<% else %>
|
||||
<%= image_tag preview_asset_path(asset) if asset.is_image? %>
|
||||
<% end %>
|
||||
<p><%= truncate(asset.file_file_name,
|
||||
length: Constants::FILENAME_TRUNCATION_LENGTH) %></p>
|
||||
<% end %>
|
||||
|
|
5
db/migrate/20161208145354_add_processing_to_assets.rb
Normal file
5
db/migrate/20161208145354_add_processing_to_assets.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AddProcessingToAssets < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :assets, :file_processing, :boolean
|
||||
end
|
||||
end
|
35
db/schema.rb
35
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20161012112900) do
|
||||
ActiveRecord::Schema.define(version: 20161208145354) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -56,6 +56,7 @@ ActiveRecord::Schema.define(version: 20161012112900) do
|
|||
t.integer "last_modified_by_id"
|
||||
t.integer "estimated_size", default: 0, null: false
|
||||
t.boolean "file_present", default: false, null: false
|
||||
t.boolean "file_processing"
|
||||
end
|
||||
|
||||
add_index "assets", ["created_at"], name: "index_assets_on_created_at", using: :btree
|
||||
|
@ -628,20 +629,20 @@ ActiveRecord::Schema.define(version: 20161012112900) do
|
|||
add_index "user_projects", ["user_id"], name: "index_user_projects_on_user_id", using: :btree
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "full_name", null: false
|
||||
t.string "initials", null: false
|
||||
t.string "email", default: "", null: false
|
||||
t.string "encrypted_password", default: "", null: false
|
||||
t.string "full_name", null: false
|
||||
t.string "initials", null: false
|
||||
t.string "email", default: "", null: false
|
||||
t.string "encrypted_password", default: "", null: false
|
||||
t.string "reset_password_token"
|
||||
t.datetime "reset_password_sent_at"
|
||||
t.datetime "remember_created_at"
|
||||
t.integer "sign_in_count", default: 0, null: false
|
||||
t.integer "sign_in_count", default: 0, null: false
|
||||
t.datetime "current_sign_in_at"
|
||||
t.datetime "last_sign_in_at"
|
||||
t.string "current_sign_in_ip"
|
||||
t.string "last_sign_in_ip"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "avatar_file_name"
|
||||
t.string "avatar_content_type"
|
||||
t.integer "avatar_file_size"
|
||||
|
@ -650,7 +651,7 @@ ActiveRecord::Schema.define(version: 20161012112900) do
|
|||
t.datetime "confirmed_at"
|
||||
t.datetime "confirmation_sent_at"
|
||||
t.string "unconfirmed_email"
|
||||
t.string "time_zone", default: "UTC"
|
||||
t.string "time_zone", default: "UTC"
|
||||
t.string "invitation_token"
|
||||
t.datetime "invitation_created_at"
|
||||
t.datetime "invitation_sent_at"
|
||||
|
@ -658,16 +659,18 @@ ActiveRecord::Schema.define(version: 20161012112900) do
|
|||
t.integer "invitation_limit"
|
||||
t.integer "invited_by_id"
|
||||
t.string "invited_by_type"
|
||||
t.integer "invitations_count", default: 0
|
||||
t.integer "tutorial_status", default: 0, null: false
|
||||
t.boolean "assignments_notification", default: true
|
||||
t.boolean "recent_notification", default: true
|
||||
t.boolean "assignments_notification_email", default: false
|
||||
t.boolean "recent_notification_email", default: false
|
||||
t.integer "invitations_count", default: 0
|
||||
t.integer "tutorial_status", default: 0, null: false
|
||||
t.boolean "assignments_notification", default: true
|
||||
t.boolean "recent_notification", default: true
|
||||
t.boolean "assignments_notification_email", default: false
|
||||
t.boolean "recent_notification_email", default: false
|
||||
t.integer "current_organization_id"
|
||||
t.boolean "system_message_notification_email", default: false
|
||||
t.boolean "system_message_notification_email", default: false
|
||||
t.string "authentication_token", limit: 30
|
||||
end
|
||||
|
||||
add_index "users", ["authentication_token"], name: "index_users_on_authentication_token", unique: true, using: :btree
|
||||
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree
|
||||
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
|
||||
add_index "users", ["invitation_token"], name: "index_users_on_invitation_token", unique: true, using: :btree
|
||||
|
|
Loading…
Add table
Reference in a new issue