mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-11 06:16:32 +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-lock: "\f023";
|
||||||
$font-fas-angle-left: "\f104";
|
$font-fas-angle-left: "\f104";
|
||||||
$font-fas-angle-right: "\f105";
|
$font-fas-angle-right: "\f105";
|
||||||
|
$font-fas-angle-double-left: "\f100";
|
||||||
|
$font-fas-angle-double-right: "\f101";
|
||||||
$font-fas-exclamation-circle: "\f06a";
|
$font-fas-exclamation-circle: "\f06a";
|
||||||
|
|
||||||
@mixin font-h1 {
|
@mixin font-h1 {
|
||||||
|
|
|
@ -6,6 +6,7 @@ class MyModulesController < ApplicationController
|
||||||
include Rails.application.routes.url_helpers
|
include Rails.application.routes.url_helpers
|
||||||
include ActionView::Helpers::UrlHelper
|
include ActionView::Helpers::UrlHelper
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
|
include MyModulesHelper
|
||||||
|
|
||||||
before_action :load_vars
|
before_action :load_vars
|
||||||
before_action :load_projects_tree, only: %i(protocols results activities archive)
|
before_action :load_projects_tree, only: %i(protocols results activities archive)
|
||||||
|
@ -245,6 +246,7 @@ class MyModulesController < ApplicationController
|
||||||
.experiment
|
.experiment
|
||||||
.project
|
.project
|
||||||
.team)
|
.team)
|
||||||
|
@results = ordered_result_of(@my_module, params[:page])
|
||||||
end
|
end
|
||||||
|
|
||||||
def archive
|
def archive
|
||||||
|
|
|
@ -26,27 +26,13 @@ class ResultAssetsController < ApplicationController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
obj = create_multiple_results
|
obj = create_multiple_results
|
||||||
respond_to do |format|
|
if obj.fetch(:status)
|
||||||
if obj.fetch(:status)
|
flash[:success] = t('result_assets.create.success_flash',
|
||||||
format.html do
|
module: @my_module.name)
|
||||||
flash[:success] = t('result_assets.create.success_flash',
|
redirect_to results_my_module_path(@my_module)
|
||||||
module: @my_module.name)
|
else
|
||||||
redirect_to results_my_module_path(@my_module)
|
flash[:error] = t('result_assets.error_flash')
|
||||||
end
|
render json: {}, status: :bad_request
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -41,28 +41,12 @@ class ResultTablesController < ApplicationController
|
||||||
)
|
)
|
||||||
@result.last_modified_by = current_user
|
@result.last_modified_by = current_user
|
||||||
|
|
||||||
respond_to do |format|
|
if @result.save && @table.save
|
||||||
if (@result.save and @table.save) then
|
log_activity(:add_result)
|
||||||
log_activity(:add_result)
|
flash[:success] = t('result_tables.create.success_flash', module: @my_module.name)
|
||||||
|
redirect_to results_my_module_path(@my_module)
|
||||||
format.html {
|
else
|
||||||
flash[:success] = t(
|
render json: @result.errors, status: :bad_request
|
||||||
"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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -39,35 +39,16 @@ class ResultTextsController < ApplicationController
|
||||||
)
|
)
|
||||||
@result.last_modified_by = current_user
|
@result.last_modified_by = current_user
|
||||||
|
|
||||||
respond_to do |format|
|
if @result.save && @result_text.save
|
||||||
if @result.save && @result_text.save
|
# link tiny_mce_assets to the text result
|
||||||
# link tiny_mce_assets to the text result
|
TinyMceAsset.update_images(@result_text, params[:tiny_mce_images], current_user)
|
||||||
TinyMceAsset.update_images(@result_text, params[:tiny_mce_images], current_user)
|
|
||||||
|
|
||||||
result_annotation_notification
|
result_annotation_notification
|
||||||
log_activity(:add_result)
|
log_activity(:add_result)
|
||||||
|
flash[:success] = t('result_texts.create.success_flash', module: @my_module.name)
|
||||||
format.html {
|
redirect_to results_my_module_path(@my_module)
|
||||||
flash[:success] = t(
|
else
|
||||||
"result_texts.create.success_flash",
|
render json: @result.errors, status: :bad_request
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,9 @@ module MyModulesHelper
|
||||||
my_module.samples.count
|
my_module.samples.count
|
||||||
end
|
end
|
||||||
|
|
||||||
def ordered_result_of(my_module)
|
def ordered_result_of(my_module, page)
|
||||||
my_module.results.where(archived: false).order(created_at: :desc)
|
page ||= 1
|
||||||
|
my_module.results.where(archived: false).page(page).per(10).order(created_at: :desc)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_task_alert_color(my_module)
|
def get_task_alert_color(my_module)
|
||||||
|
|
|
@ -52,10 +52,13 @@
|
||||||
<div style="height: 15px;"></div>
|
<div style="height: 15px;"></div>
|
||||||
|
|
||||||
<div id="results" data-module-id="<%= @my_module.id %>">
|
<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 } %>
|
<%= render partial: "result", locals: { result: result } %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="kaminari-pagination">
|
||||||
|
<%= paginate @results, outer_window: 1, window: 1 %>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= javascript_include_tag "handsontable.full.min" %>
|
<%= javascript_include_tag "handsontable.full.min" %>
|
||||||
|
|
|
@ -2423,3 +2423,11 @@ en:
|
||||||
structure_placeholder: "Click here to enter Chemical Drawing name"
|
structure_placeholder: "Click here to enter Chemical Drawing name"
|
||||||
modal_name_title: "Chemical Drawing name:"
|
modal_name_title: "Chemical Drawing name:"
|
||||||
checmical_drawing: "Chemical drawings"
|
checmical_drawing: "Chemical drawings"
|
||||||
|
|
||||||
|
views:
|
||||||
|
pagination:
|
||||||
|
first: "First"
|
||||||
|
last: "Last"
|
||||||
|
previous: "Previous"
|
||||||
|
next: "Next"
|
||||||
|
truncate: "…"
|
||||||
|
|
Loading…
Add table
Reference in a new issue