Created
July 1, 2020 23:57
-
-
Save matedemorphy/94c6ad13b6aebd89862b5b14120c98df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// javascript/stylesheets/applications.scss | |
body.wait, body.wait * { | |
cursor: wait !important; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// javascript/controllers/application_controller.js | |
import Turbolinks from 'turbolinks' | |
import { Controller } from 'stimulus' | |
import StimulusReflex from 'stimulus_reflex' | |
export default class extends Controller { | |
connect () { | |
StimulusReflex.register(this) | |
} | |
beforeReflex (element, reflex) { | |
//adding cursor spinner | |
document.body.classList.add('wait') | |
} | |
afterReflex (element, reflex) { | |
//some jquery plugins reinitialization | |
$('[data-toggle="tooltip"]').tooltip() | |
$('[data-toggle="popover"]').popover() | |
$("[type='checkbox']").bootstrapSwitch() | |
document.querySelectorAll('[data-uppy]').forEach(element => setupUppy(element)) | |
OverlayScrollbars(document.querySelectorAll(".sidebar"), {}) | |
//removing spinner | |
document.body.classList.remove('wait') | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# controllers/categories_controller.rb | |
class CategoriesController < ApplicationController | |
before_action :authenticate_user! | |
def index | |
@page = (session[:page] || 1).to_i | |
categories = Category.includes(:products) | |
pages = (categories.count / Pagy::VARS[:items].to_f).ceil | |
@page = 1 if @page > pages | |
@pagy, @categories = pagy(categories, page: @page) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/views/categories/index.html.slim | |
/...categories table body & paginator partial | |
tbody | |
= render @categories | |
== render 'shared/paginator_nav', pagy: @pagy if @pagy.pages > 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# reflexes/tabular_reflex.rb | |
class TabularReflex < ApplicationReflex | |
before_reflex :switch_tenant | |
def paginate | |
session[:page] = element.dataset[:page].to_i | |
end | |
private | |
def switch_tenant | |
Apartment::Tenant.switch! tenant | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@RolandStuder solved by adding
data-id