mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-27 01:05:21 +08:00
Add pagination to results page
This commit is contained in:
parent
41ceba11b8
commit
7c4bfad09b
9 changed files with 112 additions and 74 deletions
71
app/assets/stylesheets/shared/kaminari_pagination.scss
Normal file
71
app/assets/stylesheets/shared/kaminari_pagination.scss
Normal file
|
@ -0,0 +1,71 @@
|
|||
.kaminari-pagination {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
|
||||
.page a,
|
||||
.page.current,
|
||||
.page.gap {
|
||||
align-items: center;
|
||||
border: $border-transparent;
|
||||
border-radius: $border-radius-default;
|
||||
color: inherit;
|
||||
display: inline-flex;
|
||||
height: 3em;
|
||||
justify-content: center;
|
||||
margin: 0 .25em;
|
||||
outline: 0;
|
||||
text-decoration: none;
|
||||
width: 3em;
|
||||
|
||||
&.current {
|
||||
border: $border-primary;
|
||||
}
|
||||
}
|
||||
|
||||
.prev a {
|
||||
&::before {
|
||||
@include font-awesome;
|
||||
content: $font-fas-angle-left;
|
||||
}
|
||||
}
|
||||
|
||||
.first a {
|
||||
&::before {
|
||||
@include font-awesome;
|
||||
content: $font-fas-angle-double-left;
|
||||
}
|
||||
}
|
||||
|
||||
.next a {
|
||||
&::after {
|
||||
@include font-awesome;
|
||||
content: $font-fas-angle-right;
|
||||
}
|
||||
}
|
||||
|
||||
.last a {
|
||||
&::after {
|
||||
@include font-awesome;
|
||||
content: $font-fas-angle-double-right;
|
||||
}
|
||||
}
|
||||
|
||||
.first,
|
||||
.prev,
|
||||
.next,
|
||||
.last {
|
||||
a {
|
||||
color: inherit;
|
||||
line-height: 3em;
|
||||
margin: 0 .25em;
|
||||
padding: .5em;
|
||||
text-decoration: none;
|
||||
|
||||
&:before,
|
||||
&:after {
|
||||
margin: 0 .25em;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,6 +19,8 @@ $font-fas-exclamation-triangle: "\f071";
|
|||
$font-fas-lock: "\f023";
|
||||
$font-fas-angle-left: "\f104";
|
||||
$font-fas-angle-right: "\f105";
|
||||
$font-fas-angle-double-left: "\f100";
|
||||
$font-fas-angle-double-right: "\f101";
|
||||
$font-fas-exclamation-circle: "\f06a";
|
||||
|
||||
@mixin font-h1 {
|
||||
|
|
|
@ -6,6 +6,7 @@ class MyModulesController < ApplicationController
|
|||
include Rails.application.routes.url_helpers
|
||||
include ActionView::Helpers::UrlHelper
|
||||
include ApplicationHelper
|
||||
include MyModulesHelper
|
||||
|
||||
before_action :load_vars
|
||||
before_action :load_projects_tree, only: %i(protocols results activities archive)
|
||||
|
@ -245,6 +246,7 @@ class MyModulesController < ApplicationController
|
|||
.experiment
|
||||
.project
|
||||
.team)
|
||||
@results = ordered_result_of(@my_module, params[:page])
|
||||
end
|
||||
|
||||
def archive
|
||||
|
|
|
@ -26,27 +26,13 @@ class ResultAssetsController < ApplicationController
|
|||
|
||||
def create
|
||||
obj = create_multiple_results
|
||||
respond_to do |format|
|
||||
if obj.fetch(:status)
|
||||
format.html do
|
||||
flash[:success] = t('result_assets.create.success_flash',
|
||||
module: @my_module.name)
|
||||
redirect_to results_my_module_path(@my_module)
|
||||
end
|
||||
format.json do
|
||||
render json: {
|
||||
html: render_to_string(
|
||||
partial: 'my_modules/results.html.erb',
|
||||
locals: { results: obj.fetch(:results) }
|
||||
)
|
||||
}, status: :ok
|
||||
end
|
||||
else
|
||||
flash[:error] = t('result_assets.error_flash')
|
||||
format.json do
|
||||
render json: {}, status: :bad_request
|
||||
end
|
||||
end
|
||||
if obj.fetch(:status)
|
||||
flash[:success] = t('result_assets.create.success_flash',
|
||||
module: @my_module.name)
|
||||
redirect_to results_my_module_path(@my_module)
|
||||
else
|
||||
flash[:error] = t('result_assets.error_flash')
|
||||
render json: {}, status: :bad_request
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -41,28 +41,12 @@ class ResultTablesController < ApplicationController
|
|||
)
|
||||
@result.last_modified_by = current_user
|
||||
|
||||
respond_to do |format|
|
||||
if (@result.save and @table.save) then
|
||||
log_activity(:add_result)
|
||||
|
||||
format.html {
|
||||
flash[:success] = t(
|
||||
"result_tables.create.success_flash",
|
||||
module: @my_module.name)
|
||||
redirect_to results_my_module_path(@my_module)
|
||||
}
|
||||
format.json {
|
||||
render json: {
|
||||
html: render_to_string({
|
||||
partial: "my_modules/result.html.erb", locals: {result: @result}
|
||||
})
|
||||
}, status: :ok
|
||||
}
|
||||
else
|
||||
format.json {
|
||||
render json: @result.errors, status: :bad_request
|
||||
}
|
||||
end
|
||||
if @result.save && @table.save
|
||||
log_activity(:add_result)
|
||||
flash[:success] = t('result_tables.create.success_flash', module: @my_module.name)
|
||||
redirect_to results_my_module_path(@my_module)
|
||||
else
|
||||
render json: @result.errors, status: :bad_request
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -39,35 +39,16 @@ class ResultTextsController < ApplicationController
|
|||
)
|
||||
@result.last_modified_by = current_user
|
||||
|
||||
respond_to do |format|
|
||||
if @result.save && @result_text.save
|
||||
# link tiny_mce_assets to the text result
|
||||
TinyMceAsset.update_images(@result_text, params[:tiny_mce_images], current_user)
|
||||
if @result.save && @result_text.save
|
||||
# link tiny_mce_assets to the text result
|
||||
TinyMceAsset.update_images(@result_text, params[:tiny_mce_images], current_user)
|
||||
|
||||
result_annotation_notification
|
||||
log_activity(:add_result)
|
||||
|
||||
format.html {
|
||||
flash[:success] = t(
|
||||
"result_texts.create.success_flash",
|
||||
module: @my_module.name)
|
||||
redirect_to results_my_module_path(@my_module)
|
||||
}
|
||||
format.json {
|
||||
render json: {
|
||||
html: render_to_string({
|
||||
partial: "my_modules/result.html.erb",
|
||||
locals: {
|
||||
result: @result
|
||||
}
|
||||
})
|
||||
}, status: :ok
|
||||
}
|
||||
else
|
||||
format.json {
|
||||
render json: @result.errors, status: :bad_request
|
||||
}
|
||||
end
|
||||
result_annotation_notification
|
||||
log_activity(:add_result)
|
||||
flash[:success] = t('result_texts.create.success_flash', module: @my_module.name)
|
||||
redirect_to results_my_module_path(@my_module)
|
||||
else
|
||||
render json: @result.errors, status: :bad_request
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -33,8 +33,9 @@ module MyModulesHelper
|
|||
my_module.samples.count
|
||||
end
|
||||
|
||||
def ordered_result_of(my_module)
|
||||
my_module.results.where(archived: false).order(created_at: :desc)
|
||||
def ordered_result_of(my_module, page)
|
||||
page ||= 1
|
||||
my_module.results.where(archived: false).page(page).per(10).order(created_at: :desc)
|
||||
end
|
||||
|
||||
def get_task_alert_color(my_module)
|
||||
|
|
|
@ -52,10 +52,13 @@
|
|||
<div style="height: 15px;"></div>
|
||||
|
||||
<div id="results" data-module-id="<%= @my_module.id %>">
|
||||
<% ordered_result_of(@my_module).each do |result| %>
|
||||
<% @results.each do |result| %>
|
||||
<%= render partial: "result", locals: { result: result } %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="kaminari-pagination">
|
||||
<%= paginate @results, outer_window: 1, window: 1 %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= javascript_include_tag "handsontable.full.min" %>
|
||||
|
|
|
@ -2423,3 +2423,11 @@ en:
|
|||
structure_placeholder: "Click here to enter Chemical Drawing name"
|
||||
modal_name_title: "Chemical Drawing name:"
|
||||
checmical_drawing: "Chemical drawings"
|
||||
|
||||
views:
|
||||
pagination:
|
||||
first: "First"
|
||||
last: "Last"
|
||||
previous: "Previous"
|
||||
next: "Next"
|
||||
truncate: "…"
|
||||
|
|
Loading…
Reference in a new issue