Skip to content

Commit

Permalink
アラートの期限を変更した際に、メンター全員のダッシュボードの期限を変更できるようにした
Browse files Browse the repository at this point in the history
未アサインの提出物の期限を保持するモデル、コントローラーを作成した
  • Loading branch information
nakamu-kazu222 committed Jun 3, 2024
1 parent e29cfbd commit 0cc5a2a
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/product_deadlines_controller.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion app/javascript/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ 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) =>
h(Products, {
props: {
title: title,
isMentor: isMentor === 'true',
currentUserId: currentUserId
currentUserId: currentUserId,
productDeadlineDays: productDeadlineDays
}
})
}).$mount(selector)
Expand Down
29 changes: 25 additions & 4 deletions app/javascript/products.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions app/models/product_deadline.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion app/views/home/_mentor_dashboard.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20240530042450_create_product_deadlines.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 0cc5a2a

Please sign in to comment.