From 0cc5a2abf05ffccc78ae9f1dddf22d7d669866ab Mon Sep 17 00:00:00 2001 From: nakamurakazuki Date: Mon, 3 Jun 2024 10:38:34 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=A2=E3=83=A9=E3=83=BC=E3=83=88=E3=81=AE?= =?UTF-8?q?=E6=9C=9F=E9=99=90=E3=82=92=E5=A4=89=E6=9B=B4=E3=81=97=E3=81=9F?= =?UTF-8?q?=E9=9A=9B=E3=81=AB=E3=80=81=E3=83=A1=E3=83=B3=E3=82=BF=E3=83=BC?= =?UTF-8?q?=E5=85=A8=E5=93=A1=E3=81=AE=E3=83=80=E3=83=83=E3=82=B7=E3=83=A5?= =?UTF-8?q?=E3=83=9C=E3=83=BC=E3=83=89=E3=81=AE=E6=9C=9F=E9=99=90=E3=82=92?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 未アサインの提出物の期限を保持するモデル、コントローラーを作成した --- app/controllers/home_controller.rb | 1 + .../product_deadlines_controller.rb | 8 +++++ app/javascript/products.js | 4 ++- app/javascript/products.vue | 29 ++++++++++++++++--- app/models/product_deadline.rb | 11 +++++++ app/views/home/_mentor_dashboard.html.slim | 2 +- config/routes.rb | 1 + ...20240530042450_create_product_deadlines.rb | 9 ++++++ db/schema.rb | 8 ++++- 9 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 app/controllers/product_deadlines_controller.rb create mode 100644 app/models/product_deadline.rb create mode 100644 db/migrate/20240530042450_create_product_deadlines.rb diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 159acfbffcb..dc0a6aa9bf1 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -46,6 +46,7 @@ def display_dashboard collegue_trainees_reports = Report.with_avatar.where(wip: false).where(user: current_user.collegue_trainees&.with_attached_avatar) @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) + @product_deadline_day = ProductDeadline.first_or_create(alert_day: 4).alert_day end def display_events_on_dashboard diff --git a/app/controllers/product_deadlines_controller.rb b/app/controllers/product_deadlines_controller.rb new file mode 100644 index 00000000000..49e11861fd7 --- /dev/null +++ b/app/controllers/product_deadlines_controller.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class ProductDeadlinesController < ApplicationController + def update + product_deadline = ProductDeadline.first_or_initialize + product_deadline.update(alert_day: params[:alert_day]) + end +end diff --git a/app/javascript/products.js b/app/javascript/products.js index b92721d6e1b..1d37b7e0b2c 100644 --- a/app/javascript/products.js +++ b/app/javascript/products.js @@ -9,6 +9,7 @@ document.addEventListener('DOMContentLoaded', () => { const title = products.getAttribute('data-title') const isMentor = products.getAttribute('data-mentor-login') const currentUserId = Number(products.getAttribute('data-current-user-id')) + const productDeadlineDays = Number(products.getAttribute('data-product-deadline-days')) new Vue({ store, render: (h) => @@ -16,7 +17,8 @@ document.addEventListener('DOMContentLoaded', () => { props: { title: title, isMentor: isMentor === 'true', - currentUserId: currentUserId + currentUserId: currentUserId, + productDeadlineDays: productDeadlineDays } }) }).$mount(selector) diff --git a/app/javascript/products.vue b/app/javascript/products.vue index e40a8800a79..29faaf1b9fb 100644 --- a/app/javascript/products.vue +++ b/app/javascript/products.vue @@ -136,14 +136,15 @@ export default { title: { type: String, required: true }, isMentor: { type: Boolean, required: true }, currentUserId: { type: Number, required: true }, - displayUserIcon: { type: Boolean, default: true } + displayUserIcon: { type: Boolean, default: true }, + productDeadlineDays: { type: Number, required: true } }, data() { return { products: [], loaded: false, productsGroupedByElapsedDays: null, - selectedDays: 4 + selectedDays: this.productDeadlineDays } }, computed: { @@ -231,8 +232,28 @@ export default { } }, onDaysSelectChange(event) { - this.selectedDays = parseInt(event.target.value) - this.getProductsPerPage() + const newDeadlineDays = parseInt(event.target.value); + this.updateProductDeadline(newDeadlineDays); + this.selectedDays = newDeadlineDays; + this.getProductsPerPage(); + }, + async updateProductDeadline(newDeadlineDays) { + try { + const response = await fetch('/product_deadline', { + method: 'PATCH', + headers: { + 'Content-Type': 'application/json; charset=utf-8', + 'X-CSRF-Token': CSRF.getToken() + }, + credentials: 'same-origin', + body: JSON.stringify({ alert_day: newDeadlineDays }) + }); + if (!response.ok) { + throw new Error('Failed to update product deadline'); + } + } catch (error) { + console.warn(error); + } }, getElementNdaysPassed(elapsedDays) { const element = this.productsGroupedByElapsedDays.find( diff --git a/app/models/product_deadline.rb b/app/models/product_deadline.rb new file mode 100644 index 00000000000..49cfb33840f --- /dev/null +++ b/app/models/product_deadline.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class ProductDeadline < ApplicationRecord + before_create :set_default_days + + private + + def set_default_days + self.alert_day ||= 4 + end +end diff --git a/app/views/home/_mentor_dashboard.html.slim b/app/views/home/_mentor_dashboard.html.slim index d73d17eb0ca..8338b4b9c4e 100644 --- a/app/views/home/_mentor_dashboard.html.slim +++ b/app/views/home/_mentor_dashboard.html.slim @@ -8,7 +8,7 @@ - if unchecked_report_count > 100 = render 'unchecked_report_alert', unchecked_report_count: unchecked_report_count .dashboard-category__body - #js-products(data-title="#{title}" data-mentor-login="#{mentor_login?}" data-current-user-id="#{current_user.id}") + #js-products(data-title="#{title}" data-mentor-login="#{mentor_login?}" data-current-user-id="#{current_user.id}" data-product-deadline-days="#{@product_deadline_day}") .dashboard-contents__col.is-main .dashboard-contents__categories .dashboard-category diff --git a/config/routes.rb b/config/routes.rb index a736b714e5e..8fa9605c925 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -89,6 +89,7 @@ resources :generations, only: %i(show index) resource :billing_portal, only: :create, controller: "billing_portal" resources :external_entries, only: %i(index) + resource :product_deadline, only: %i(update) get "articles/tags/:tag", to: "articles#index", as: :tag, tag: /.+/ get "pages/tags/:tag", to: "pages#index", as: :pages_tag, tag: /.+/, format: "html" get "questions/tags/:tag", to: "questions#index", as: :questions_tag, tag: /.+/, format: "html" diff --git a/db/migrate/20240530042450_create_product_deadlines.rb b/db/migrate/20240530042450_create_product_deadlines.rb new file mode 100644 index 00000000000..76f075b371e --- /dev/null +++ b/db/migrate/20240530042450_create_product_deadlines.rb @@ -0,0 +1,9 @@ +class CreateProductDeadlines < ActiveRecord::Migration[6.1] + def change + create_table :product_deadlines do |t| + t.integer :alert_day, default: 4 + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index d29a0601fa3..8b70a73c2b4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2024_05_02_051341) do +ActiveRecord::Schema.define(version: 2024_05_30_042450) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -496,6 +496,12 @@ t.index ["report_id", "practice_id"], name: "index_practices_reports_on_report_id_and_practice_id" end + create_table "product_deadlines", force: :cascade do |t| + t.integer "alert_day", default: 4 + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "products", force: :cascade do |t| t.bigint "practice_id" t.bigint "user_id"