Skip to content

Commit

Permalink
Merge pull request #1809 from MushroomObserver/nimmo-matrix_table-js
Browse files Browse the repository at this point in the history
Move spacers to `matrix-table_controller.js`
  • Loading branch information
nimmolo committed Jan 16, 2024
2 parents 528bde5 + 61d315e commit 4d1db88
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 37 deletions.
38 changes: 38 additions & 0 deletions app/javascript/controllers/matrix-table_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,49 @@ export default class extends Controller {
connect() {
this.element.dataset.stimulus = "connected";

this.matrixBoxes = document.querySelectorAll('.matrix-box')
this.boxes = document.querySelectorAll('.matrix-box .panel-sizing')
this.footers = document.querySelectorAll('.matrix-box .log-footer')

this.add_spacers()
this.rearrange()
}

add_spacers() {
this.matrixBoxes.forEach((element, i) => {
if (i % 2 == 0) {
element.insertAdjacentElement('beforebegin', this.smSpacer())
}
if (i % 3 == 0) {
element.insertAdjacentElement('beforebegin', this.mdSpacer())
}
if (i % 4 == 0) {
element.insertAdjacentElement('beforebegin', this.lgSpacer())
}
})
}

smSpacer() {
const spacer = document.createElement('div')
spacer.classList.add('hidden', 'visible-sm-block')
spacer.style.clear = "left"
return spacer
}

mdSpacer() {
const spacer = document.createElement('div')
spacer.classList.add('hidden', 'visible-md-block')
spacer.style.clear = "left"
return spacer
}

lgSpacer() {
const spacer = document.createElement('div')
spacer.classList.add('hidden', 'visible-lg-block')
spacer.style.clear = "left"
return spacer
}

rearrange() {
this.breakpoint =
Array.from(document.querySelectorAll('[data-breakpoint]')).filter(s =>
Expand Down
4 changes: 1 addition & 3 deletions app/views/controllers/images/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ flash_error(@error) if @error && @objects.empty?
data: { controller: "matrix-table",
action: "resize@window->matrix-table#rearrange" }) do %>
<%= render(partial: "shared/matrix_box",
layout: "shared/matrix_table",
collection: @objects,
as: :object) %>
collection: @objects, as: :object) %>
<div style="clear:left"></div>
<% end %>
<% end %>
3 changes: 1 addition & 2 deletions app/views/controllers/observations/identify/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ flash_error(@error) if @error && @objects.empty?
data: { controller: "matrix-table",
action: "resize@window->matrix-table#rearrange" }) do %>
<%= render(partial: "shared/matrix_box",
layout: "shared/matrix_table",
locals: { link_method: :get, identify: true },
locals: { identify: true },
collection: @objects, as: :object) %>
<div style="clear:left"></div>
<% end %>
Expand Down
1 change: 0 additions & 1 deletion app/views/controllers/observations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ flash_error(@error) if @error && @objects.empty?
data: { controller: "matrix-table",
action: "resize@window->matrix-table#rearrange" }) do %>
<%= render(partial: "shared/matrix_box",
layout: "shared/matrix_table",
collection: @objects, as: :object) %>
<div style="clear:left"></div>
<% end %>
Expand Down
1 change: 0 additions & 1 deletion app/views/controllers/rss_logs/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ flash_error(@error) if @error && @objects.empty?
data: { controller: "matrix-table",
action: "resize@window->matrix-table#rearrange" }) do %>
<%= render(partial: "shared/matrix_box",
layout: "shared/matrix_table",
collection: @objects, as: :object) %>
<div style="clear:left"></div>
<% end %>
Expand Down
3 changes: 1 addition & 2 deletions app/views/controllers/shared/_images_to_remove.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
data: { controller: "matrix-table",
action: "resize@window->matrix-table#rearrange" }) do %>
<%= render(layout: "shared/matrix_table",
locals: { objects: @object.images }) do |image| %>
<% @object.images.each do |image| %>
<%= matrix_box(id: image.id) do %>
<%= tag.div(class: "py-3 text-center") do %>
Expand Down
3 changes: 1 addition & 2 deletions app/views/controllers/shared/_images_to_reuse.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ query = query_images_to_reuse(@all_users, @user)
data: { controller: "matrix-table",
action: "resize@window->matrix-table#rearrange" }) do %>
<%= render(layout: "shared/matrix_table",
locals: { objects: @objects }) do |image| %>
<% @objects.each do |image| %>
<%= matrix_box(class: "text-center", id: image.id) do %>
<%= panel_block do %>
<%= interactive_image(image, votes: false, original: true,
Expand Down
20 changes: 0 additions & 20 deletions app/views/controllers/shared/_matrix_table.erb

This file was deleted.

4 changes: 1 addition & 3 deletions app/views/controllers/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ flash_error(@error) if @error && @objects.empty?
data: { controller: "matrix-table",
action: "resize@window->matrix-table#rearrange" }) do %>
<%= render(partial: "shared/matrix_box",
layout: "shared/matrix_table",
collection: @objects,
as: :object) %>
collection: @objects, as: :object) %>
<% end %>
<% end %>
<% end %>
Expand Down
5 changes: 2 additions & 3 deletions app/views/controllers/visual_groups/_image_matrix.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<%= tag.ul(class: "row list-unstyled mt-3",
data: { controller: "matrix-table",
action: "resize@window->matrix-table#rearrange" }) do %>
<%= render(layout: "shared/matrix_table",
locals: { objects: @subset }) do |row| %>
<% @subset.each do |row| %>
<%= matrix_box(id: row[0]) do %>
<%= tag.div(class: "panel panel-default") do %>
<%= tag.div(class: "thumbnail-container") do
Expand All @@ -17,7 +16,7 @@
)
end %>
<% end %>
<% end %><!-- .matrix-box -->
<% end %>
<% end %>
<% end %>
<% end %>
Expand Down

0 comments on commit 4d1db88

Please sign in to comment.