diff --git a/app/assets/javascripts/experiments/table.js b/app/assets/javascripts/experiments/table.js index 977712d81..7a9aaa45b 100644 --- a/app/assets/javascripts/experiments/table.js +++ b/app/assets/javascripts/experiments/table.js @@ -1,31 +1,56 @@ -/* global I18n */ +/* global I18n GLOBAL_CONSTANTS InfiniteScroll */ const ExperimnetTable = { selectedId: [], table: '.experiment-table', render: {}, - init: function() { - $.get($('.experiment-table').data('my-modules-url'), (result) => { - $.each(result, (id, data) => { - // Checkbox selector - let row = ` + pageSize: GLOBAL_CONSTANTS.DEFAULT_ELEMENTS_PER_PAGE, + loadPlaceholder: function() { + let placeholder = ''; + $.each(Array(this.pageSize), function() { + placeholder += $('#experimentTablePlaceholder').html(); + }); + $(placeholder).insertAfter($(this.table).find('.table-body')); + }, + appendRows: function(result) { + $.each(result, (id, data) => { + // Checkbox selector + let row = ` +
+
+ + +
+
`; + // Task columns + $.each(data, (_i, cell) => { + row += `
-
- - + ${ExperimnetTable.render[cell.column_type](cell.data)}
-
`; - // Task columns - $.each(data, (_i, cell) => { - row += ` -
- ${ExperimnetTable.render[cell.column_type](cell.data)} -
- `; - }); - // Menu - row += '
'; - $(`
${row}
`).appendTo(`${this.table} .table-body`); + `; + }); + // Menu + row += '
'; + $(`
${row}
`).appendTo(`${this.table} .table-body`); + }); + }, + init: function() { + var dataUrl = $(this.table).data('my-modules-url'); + this.loadPlaceholder(); + $.get(dataUrl, (result) => { + $(this.table).find('.table-row').remove(); + this.appendRows(result.data); + InfiniteScroll.init(this.table, { + url: dataUrl, + eventTarget: window, + placeholderTemplate: '#experimentTablePlaceholder', + endOfListTemplate: '#experimentTableEndOfList', + pageSize: this.pageSize, + lastPage: !result.next_page, + customResponse: (response) => { + this.appendRows(response.data); + } }); }); } diff --git a/app/assets/stylesheets/experiment/table.scss b/app/assets/stylesheets/experiment/table.scss index 098c7ab20..3bd1205a3 100644 --- a/app/assets/stylesheets/experiment/table.scss +++ b/app/assets/stylesheets/experiment/table.scss @@ -114,6 +114,118 @@ white-space: nowrap; } + .table-row-placeholder { + align-items: center; + background-color: $color-white; + border-radius: $border-radius-default; + box-shadow: $flyout-shadow; + display: contents; + + .placeholder-cell { + animation-duration: 2s; + animation-iteration-count: infinite; + animation-name: placeholder-pulsing; + background-color: $color-alto; + border-radius: $border-radius-default; + height: 18px; + margin: auto; + + &.line-0 { + display: block; + grid-column: 2; + width: 90%; + } + + &.line-1 { + display: block; + grid-column: 3; + width: 90%; + } + + &.line-2 { + display: block; + grid-column: 4; + width: 90%; + } + + &.line-3 { + display: block; + grid-column: 5; + width: 90%; + } + + &.line-4 { + display: block; + grid-column: 6; + width: 90%; + } + + &.line-5 { + display: block; + grid-column: 7; + width: 90%; + } + + &.line-6 { + display: block; + grid-column: 9; + width: 90%; + } + + &.line-7 { + display: block; + grid-column: 10; + width: 90%; + } + + &.circle-0 { + border-radius: 100%; + display: block; + grid-column: 8; + height: 24px; + margin-left: 8px; + width: 24px; + } + + + @keyframes placeholder-pulsing { + 0% { + opacity: 1; + } + + 50% { + opacity: .5; + } + + 100% { + opacity: 1; + } + } + } + } + + &.last-page { + padding-bottom: 5em; + position: relative; + } + + .experiment-table-list-end-placeholder { + align-items: center; + background-color: $color-concrete; + bottom: 1em; + display: flex; + height: 3em; + left: calc(50% - 150px); + margin: 0 auto; + padding: 1em; + position: absolute; + width: 300px; + + > * { + flex-grow: 1; + text-align: center; + } + } } .unseen-comments { diff --git a/app/controllers/experiments_controller.rb b/app/controllers/experiments_controller.rb index f22207758..14c260a30 100644 --- a/app/controllers/experiments_controller.rb +++ b/app/controllers/experiments_controller.rb @@ -96,7 +96,7 @@ class ExperimentsController < ApplicationController def load_table active_modules = @experiment.my_modules.active - render json: Experiments::TableViewService.new(active_modules, current_user).call + render json: Experiments::TableViewService.new(active_modules, current_user, params[:page]).call end def edit diff --git a/app/services/experiments/table_view_service.rb b/app/services/experiments/table_view_service.rb index 56a34ed3a..192e7ad1a 100644 --- a/app/services/experiments/table_view_service.rb +++ b/app/services/experiments/table_view_service.rb @@ -37,7 +37,11 @@ module Experiments def call result = {} - @my_modules.includes(PRELOAD).each do |my_module| + + my_module_list = @my_modules.includes(PRELOAD) + .page(@page || 1) + .per(Constants::DEFAULT_ELEMENTS_PER_PAGE) + my_module_list.each do |my_module| prepared_my_module = [] COLUMNS.each do |col| column_data = { @@ -49,7 +53,11 @@ module Experiments result[my_module.id] = prepared_my_module end - result + + { + next_page: my_module_list.next_page, + data: result + } end private diff --git a/app/views/experiments/table.html.erb b/app/views/experiments/table.html.erb index 997fd220d..d6b47e142 100644 --- a/app/views/experiments/table.html.erb +++ b/app/views/experiments/table.html.erb @@ -34,6 +34,27 @@ + + + + <%= render partial: "my_modules/modals/manage_module_tags_modal", locals: { my_module: nil } %> <%= javascript_include_tag("my_modules/tags") %>