Skip to content

Commit

Permalink
Merge pull request #7675 from fjordllc/chore/announcements-list-non-v…
Browse files Browse the repository at this point in the history
…ue-conversion

お知らせ一覧ページを非Vue化
  • Loading branch information
komagata authored Apr 29, 2024
2 parents afc0b97 + 45575bb commit 97563cc
Show file tree
Hide file tree
Showing 17 changed files with 169 additions and 520 deletions.
43 changes: 17 additions & 26 deletions app/controllers/announcements_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# frozen_string_literal: true

class AnnouncementsController < ApplicationController
PAGER_NUMBER = 25
before_action :set_announcement, only: %i[show edit update destroy]
before_action :rewrite_announcement, only: %i[update]

def index; end
def index
@announcements = Announcement.with_avatar
.preload(:comments)
.order(published_at: :desc, created_at: :desc)
.page(params[:page])
.per(PAGER_NUMBER)
end

def show
@announcements = Announcement.with_avatar.where(wip: false).order(published_at: :desc).limit(10)
Expand All @@ -14,23 +21,21 @@ def new
@announcement = Announcement.new(target: 'students')

if params[:id]
copy_announcement(params[:id])
@announcement = Announcement.copy_announcement(params[:id])
flash.now[:notice] = 'お知らせをコピーしました。'
elsif params[:page_id]
page = Page.find(params[:page_id])
copy_template_by_resource('page_announcements.yml', page:)
@announcement = Announcement.copy_template_by_resource('page_announcements.yml', page:)
elsif params[:event_id]
event = Event.find(params[:event_id])
copy_template_by_resource('event_announcements.yml', event:)
@announcement = Announcement.copy_template_by_resource('event_announcements.yml', event:)
elsif params[:regular_event_id]
regular_event = RegularEvent.find(params[:regular_event_id])
organizers = regular_event.organizers.map { |organizer| "@#{organizer.login_name}" }.join("\n - ")
holding_cycles = ActiveDecorator::Decorator.instance.decorate(regular_event).holding_cycles
hold_national_holiday = "(祝日#{regular_event.hold_national_holiday ? 'も開催' : 'は休み'})"
copy_template_by_resource('regular_event_announcements.yml',
regular_event:,
organizers:,
holding_cycles:,
hold_national_holiday:)
params = { regular_event:,
organizers: regular_event.organizers.map { |organizer| "@#{organizer.login_name}" }.join("\n - "),
holding_cycles: ActiveDecorator::Decorator.instance.decorate(regular_event).holding_cycles,
hold_national_holiday: "(祝日#{regular_event.hold_national_holiday ? 'も開催' : 'は休み'})" }
@announcement = Announcement.copy_template_by_resource('regular_event_announcements.yml', params)
end
end

Expand Down Expand Up @@ -107,18 +112,4 @@ def set_entered_announcement
description: params['announcement']['description'], \
target: params['announcement']['target'])
end

def copy_announcement(announcement_id)
announcement = Announcement.find(announcement_id)
@announcement.title = announcement.title
@announcement.description = announcement.description
@announcement.target = announcement.target
flash.now[:notice] = 'お知らせをコピーしました。'
end

def copy_template_by_resource(template_file, params = {})
template = MessageTemplate.load(template_file, params:)
@announcement.title = template['title']
@announcement.description = template['description']
end
end
53 changes: 0 additions & 53 deletions app/controllers/api/announcements_controller.rb

This file was deleted.

50 changes: 0 additions & 50 deletions app/javascript/components/announcement.vue

This file was deleted.

137 changes: 0 additions & 137 deletions app/javascript/components/announcements.vue

This file was deleted.

2 changes: 0 additions & 2 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import '../editor-selection-form.js'
import '../user_mentor_memo.js'

import VueMounter from '../VueMounter.js'
import Announcements from '../components/announcements.vue'
import Books from '../components/books.vue'
import ExternalEntries from '../components/external-entries.vue'
import Questions from '../components/questions.vue'
Expand All @@ -78,7 +77,6 @@ import CourseBooks from '../components/course-books.vue'
import '../stylesheets/application'

const mounter = new VueMounter()
mounter.addComponent(Announcements)
mounter.addComponent(Books)
mounter.addComponent(ExternalEntries)
mounter.addComponent(Questions)
Expand Down
10 changes: 10 additions & 0 deletions app/models/announcement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@ class Announcement < ApplicationRecord
columns_for_keyword_search :title, :description

scope :wip, -> { where(wip: true) }

def self.copy_announcement(announcement_id)
original = find(announcement_id)
new(title: original.title, description: original.description, target: original.target)
end

def self.copy_template_by_resource(template_file, params = {})
template = MessageTemplate.load(template_file, params:)
new(title: template['title'], description: template['description'])
end
end
Loading

0 comments on commit 97563cc

Please sign in to comment.