Skip to content

Commit

Permalink
Merge pull request #7443 from fjordllc/chore/niconico-calendar-non-vu…
Browse files Browse the repository at this point in the history
…e-conversion

ニコニコカレンダーを非Vue化
  • Loading branch information
komagata authored Jul 17, 2024
2 parents e7d4614 + fa7b6cb commit 378222c
Show file tree
Hide file tree
Showing 19 changed files with 223 additions and 301 deletions.
55 changes: 55 additions & 0 deletions app/components/calendar/nico_nico_calendar_component.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.a-card
header.card-header.is-sm
h2.card-header__title
| ニコニコカレンダー
hr.a-border-tint
.card-body
.card__description
.niconico-calendar-nav
- if prev_month?(current_date)
= link_to prev_month_path do
.niconico-calendar-nav__previous
i.fa-solid.fa-angle-left
- else
.niconico-calendar-nav__next.is-blank
.niconico-calendar-nav__year--month
= "#{current_date.year}年#{current_date.month}月"
- if next_month?(current_date)
= link_to next_month_path do
.niconico-calendar-nav__next
i.fa-solid.fa-angle-right
- else
.niconico-calendar-nav__next.is-blank
table.niconico-calendar
thead.niconico-calendar__header
tr
th.niconico-calendar__header-day.is-sunday
th.niconico-calendar__header-day
th.niconico-calendar__header-day
th.niconico-calendar__header-day
th.niconico-calendar__header-day
th.niconico-calendar__header-day
th.niconico-calendar__header-day.is-saturday
tbody.niconico-calendar__body
- user.niconico_calendar(current_calendar).each do |week|
tr.niconico-calendar__week
- week.each do |set|
- day_css_class = frame_and_background(set[:date], set[:emotion])
- day_label_html = capture do
.niconico-calendar__day-label
= set[:date]&.day
.niconico-calendar__day-value
- if set[:emotion]
img.niconico-calendar__emotion-image src="/images/emotion/#{set[:emotion]}.svg" alt="#{set[:emotion]}"
- elsif set[:date]
i.fa-solid.fa-minus
td.niconico-calendar__day class=day_css_class
- if set[:report]
= link_to report_path(set[:report]), class: 'niconico-calendar__day-inner' do
= day_label_html
- elsif set[:date] && !set[:date].future?
= link_to new_report_path(reported_on: set[:date]), class: 'niconico-calendar__day-inner' do
= day_label_html
- else
.niconico-calendar__day-inner
= day_label_html
36 changes: 36 additions & 0 deletions app/components/calendar/nico_nico_calendar_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

class Calendar::NicoNicoCalendarComponent < ViewComponent::Base
def initialize(user:, path:, current_date:, current_calendar:)
@user = user
@path = path
@current_date = current_date
@current_calendar = current_calendar
end

def prev_month?(month)
month.beginning_of_month > user.created_at.to_date.beginning_of_month
end

def prev_month_path
send(path, niconico_calendar: current_date.prev_month.strftime('%Y-%m'))
end

def frame_and_background(date, emotion)
day_class = emotion ? "is-#{emotion}" : 'is-blank'
day_class += ' is-today' if date&.today?
day_class
end

def next_month?(month)
month.beginning_of_month < Time.zone.today.to_date.beginning_of_month
end

def next_month_path
send(path, niconico_calendar: current_date.next_month.strftime('%Y-%m'))
end

private

attr_reader :user, :path, :current_date, :current_calendar
end
10 changes: 0 additions & 10 deletions app/controllers/api/niconico_calendars_controller.rb

This file was deleted.

1 change: 1 addition & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def display_dashboard
@collegue_trainees_recent_reports = collegue_trainees_reports.order(reported_on: :desc).limit(10)
@recent_reports = Report.with_avatar.where(wip: false).order(reported_on: :desc, created_at: :desc).limit(10)
@collegues = current_user.collegues_other_than_self
@calendar = NicoNicoCalendar.new(current_user, params[:niconico_calendar])
end

def display_events_on_dashboard
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def show
.where(status: 3)
.order(updated_at: :desc)

@calendar = NicoNicoCalendar.new(@user, params[:niconico_calendar])

if logged_in?
render :show
else
Expand Down
8 changes: 8 additions & 0 deletions app/decorators/user_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,12 @@ def editor_or_other_editor

editor == 'other_editor' ? other_editor : t("activerecord.enums.user.editor.#{editor}")
end

def niconico_calendar(dates_and_reports)
first_wday = dates_and_reports.first[:date].wday

blanks = Array.new(first_wday) { { date: nil } }

[*blanks, *dates_and_reports].each_slice(7).to_a
end
end
19 changes: 0 additions & 19 deletions app/javascript/niconico_calendar.js

This file was deleted.

Loading

0 comments on commit 378222c

Please sign in to comment.