-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pagy calendar #2
Draft
yshmarov
wants to merge
6
commits into
main
Choose a base branch
from
pagy-calendar
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f1e35ad
pagy calendar
yshmarov b3e9176
fix typo
yshmarov 3de5e20
rescue if week or day is not defined
yshmarov 181b71b
use dev branch, fix errors if calendar not defined
yshmarov 7aafea5
use @calendar.showtime
yshmarov 99bd9d0
use new size option
yshmarov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,3 +67,5 @@ group :test do | |
end | ||
|
||
gem "tailwindcss-rails", "~> 2.1" | ||
|
||
gem "pagy", github: "ddnexus/pagy", branch: "master" |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,17 @@ | ||
class ApplicationController < ActionController::Base | ||
# enable pagy backend helpers globally | ||
include Pagy::Backend | ||
|
||
# start and end of calendar (first and last record in the list) | ||
def pagy_calendar_period(collection) | ||
# collection.minmax.map(&:start_date) | ||
start_date = collection.min_by(&:start_date).start_date | ||
end_date = Time.zone.now | ||
[start_date, end_date] | ||
end | ||
|
||
# query to paginate within start_date | ||
def pagy_calendar_filter(collection, from, to) | ||
collection.where(start_date: from..to) | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
module ApplicationHelper | ||
include Pagy::Frontend | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,41 @@ | ||
<p style="color: green"><%= notice %></p> | ||
|
||
<h1>Events</h1> | ||
<%= link_to "New event", new_event_path %> | ||
<%#= link_to "New event", new_event_path %> | ||
<%= link_to "New event", new_event_path(start_date: [@calendar[:day].label, @calendar[:month].label(format: '%m-%Y')].join('-')) %> | ||
yshmarov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<div id="events" class="space-y-4"> | ||
<% @events.each do |event| %> | ||
<%= render event %> | ||
<div> | ||
<% if params[:skip] %> | ||
<%= link_to 'Show Calendar', events_path %> | ||
<% else %> | ||
<%= link_to 'Hide Calendar', events_path(skip: true) %> | ||
<%= link_to 'Today', pagy_url_for(@calendar.send(:last_object_at, Time.zone.now), 1) %> | ||
<%#= link_to 'Today (does not work)', pagy_calendar_url_at(@calendar, Time.zone.now) %> | ||
yshmarov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<% end %> | ||
</div> | ||
|
||
<h1>Events</h1> | ||
|
||
<% if @calendar %> | ||
<%== pagy_info(@pagy) %> | ||
for | ||
<%#== @calendar[:year].label %> | ||
<%== @calendar[:day].label %> | ||
<%== @calendar[:month].label(format: '%B %Y') %> | ||
<%#== @calendar[:week].label %> | ||
yshmarov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<%== pagy_nav(@calendar[:year]) %> | ||
<%== pagy_nav(@calendar[:month]) %> | ||
<%== pagy_nav(@calendar[:week]) %> | ||
<%== pagy_nav(@calendar[:day]) %> | ||
<% end %> | ||
|
||
<%== pagy_nav(@pagy) %> | ||
|
||
<hr> | ||
<% if @events.any? %> | ||
<% @events.each do |event| %> | ||
<%= render 'event', event: event %> | ||
<% end %> | ||
<% elsif @events.empty? %> | ||
No events found | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'pagy/extras/calendar' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think that to make this redirect line work, we need to define
@calendar
and all the collection here.if the url params were fixed
the calendar pagination would be perfect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the
@calendar
should be created in the controllerIIUC you would like to use params to get to any page by time, instead by number.
To me that looks actually more complicated. If you use
pagy_calendar_url_at(@calendar, time)
you get directly the path/url at that time instead of tinkering with 3 params separately.Am I missing something?