Skip to content

Commit

Permalink
filter by date
Browse files Browse the repository at this point in the history
  • Loading branch information
calvin committed Dec 6, 2024
1 parent 329f8f5 commit 9279e32
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
5 changes: 4 additions & 1 deletion app/controllers/memos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

class MemosController < ApplicationController
def index
@tid = params[:query]
@tid = params[:tid]
@date = params[:date]
if @tid
# @memos = current_user.memos.find_by_sql("select memos.id,memos.body,memos.created_at,memos.attachment from memos inner join memos_tags on memos.id = memos_tags.memo_id where tag_id = #{@tid} order by memos.created_at desc")
@memos = Memo.filter_by_tag @tid
elsif @date
@memos = Memo.filter_by_date(@date).order("created_at")
else
@memos = current_user.memos
end
Expand Down
1 change: 1 addition & 0 deletions app/models/memo.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Memo < ApplicationRecord
scope :filter_by_tag, ->(tagid) { joins(:tags).where( tags: { id: tagid } ) }

Check failure on line 2 in app/models/memo.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideParens: Space inside parentheses detected.

Check failure on line 2 in app/models/memo.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideParens: Space inside parentheses detected.
scope :filter_by_date, lambda { |date| where("strftime('%m/%d/%Y',datetime(created_at,'localtime')) = ?", date) }
belongs_to :user
has_and_belongs_to_many :tags
def get_tags
Expand Down
8 changes: 2 additions & 6 deletions app/views/layouts/_memo.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<% end %>
<% memo.tag_ids.each do |tagid|
tag = Tag.find(tagid) %>
<%= link_to "#" + tag.name, memos_path(query: tagid) %>
<%= link_to "#" + tag.name, memos_path(tid: tagid) %>
<% end %>
</div>
</div>
Expand All @@ -44,11 +44,7 @@
<footer class="card-footer">
<div class="card-footer-item" style="width: 100%">
<div
class="
is-flex is-justify-content-space-between is-align-items-center
"
style="width: 100%;"
>
class="is-flex is-justify-content-space-between is-align-items-center" style="width: 100%;">
<%= button_to memo_path(memo), :action => "destroy", :method => :delete, :class => "button is-danger destroyMemo", data: { turbo_confirm: "Are you sure you want to delete?" } do %>
<i class="fa-regular fa-trash-can fa-fw fa-2x"></i>
<% end %>
Expand Down
2 changes: 2 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
<link rel="apple-touch-icon" href="/icon.png">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css" integrity="sha512-Kc323vGBEqzTmouAECnVceyQqyqdsSiqLQISBL29aUW4U/M7pSPA/gEUZQqv1cwx4OnYxTxve5UMg5GT6L4JJg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bulma-calendar.min.css">
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
<%= favicon_link_tag 'favicon.png' %>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bulma-calendar.min.js"></script>
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
</head>

Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/tags/_listing.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div>
<ul>
<% for tag in @tags %>
<li><%= h tag.name %></li>
<li><%= link_to "#" + tag.name, memos_path(query: tag.id) %></li>
<% end %>
</ul>
</div>
11 changes: 11 additions & 0 deletions app/views/memos/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,21 @@
</div>
</div>
<div class="column">
<input type="date" data-display-mode="inline" id="memoDate" />
<%= tag_cloud %>
</div>
</div>
<script>
bulmaCalendar.attach('[type="date"]');
var element = document.querySelector('#memoDate');
if (element) {
element.bulmaCalendar.on('select', function(datepicker) {
console.log(datepicker.data.value());
var url = "<%= memos_path %>?date=" + datepicker.data.value()
console.log(url);
window.location.href = url;
});
}
document.body.addEventListener('htmx:configRequest', function(evt) {
event.detail.headers['X-CSRF-Token'] = $('meta[name="csrf-token"]').attr('content');
})
Expand Down
3 changes: 2 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Application < Rails::Application
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
config.assets.paths << Rails.root.join('node_modules')
config.assets.paths << Rails.root.join("node_modules")
config.time_zone = "Mountain Time (US & Canada)"
end
end

0 comments on commit 9279e32

Please sign in to comment.