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 |
@RolandStuder solved by adding data-id
@matedemorphy Glad you worked it out! Good luck with your further Stimulus Reflex endeavours!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@RolandStuder thanks for your answer. Putting jQuery aside, "sometimes" it means that: this is the paginator-> |1| |2| |3| |4| |5| |6| |7| |8| |9| |10|
If i click in the |2| it won't executes
afterReflex()
wich i need to remove the spinner, but if i click in any other page, then it will. When i click in a page next to the currentafterReflex()
won't fire, only in those cases it miss the callback. Thats what i mean with "sometimes".this is the repo: https://github.com/matedemorphy/pixcart-saas
you will need to install and run mailcatcher.