mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-26 05:57:06 +08:00
Add status to project and experiment [SCI-11797]
This commit is contained in:
parent
8982329132
commit
38c379d065
5 changed files with 69 additions and 4 deletions
63
app/models/concerns/time_trackable.rb
Normal file
63
app/models/concerns/time_trackable.rb
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module TimeTrackable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
scope :not_started, -> { where(started_at: nil).where(completed_at: nil) }
|
||||
scope :started, -> { where.not(started_at: nil).where(completed_at: nil) }
|
||||
scope :completed, -> { where.not(completed_at: nil) }
|
||||
end
|
||||
|
||||
def status=(status)
|
||||
case status
|
||||
when :not_started
|
||||
self.started_at = nil
|
||||
self.completed_at = nil
|
||||
when :started
|
||||
self.completed_at = nil
|
||||
start
|
||||
when :completed
|
||||
complete
|
||||
else
|
||||
raise ArgumentError, 'Wrong status for TimeTrackable model!'
|
||||
end
|
||||
end
|
||||
|
||||
def not_started?
|
||||
started_at.blank? && completed_at.blank?
|
||||
end
|
||||
|
||||
def not_started
|
||||
self.started_at = nil
|
||||
self.completed_at = nil
|
||||
end
|
||||
|
||||
def not_started!
|
||||
update!(started_at: nil, completed_at: nil)
|
||||
end
|
||||
|
||||
def started?
|
||||
started_at.present? && completed_at.blank?
|
||||
end
|
||||
|
||||
def start
|
||||
self.started_at = DateTime.now
|
||||
end
|
||||
|
||||
def start!
|
||||
update!(started_at: DateTime.now)
|
||||
end
|
||||
|
||||
def completed?
|
||||
completed_at.present?
|
||||
end
|
||||
|
||||
def complete
|
||||
self.completed_at = DateTime.now
|
||||
end
|
||||
|
||||
def complete!
|
||||
update!(completed_at: DateTime.now)
|
||||
end
|
||||
end
|
||||
|
|
@ -13,6 +13,7 @@ class Experiment < ApplicationRecord
|
|||
include PermissionCheckableModel
|
||||
include Assignable
|
||||
include Cloneable
|
||||
include TimeTrackable
|
||||
|
||||
before_save -> { report_elements.destroy_all }, if: -> { !new_record? && project_id_changed? }
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ class Project < ApplicationRecord
|
|||
include ViewableModel
|
||||
include PermissionCheckableModel
|
||||
include Assignable
|
||||
include TimeTrackable
|
||||
|
||||
enum visibility: { hidden: 0, visible: 1 }
|
||||
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@
|
|||
class AddManagementColumnsToProjectAndExperiment < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :projects, :started_at, :datetime
|
||||
add_column :projects, :ended_at, :datetime
|
||||
add_column :projects, :completed_at, :datetime
|
||||
add_column :projects, :start_on, :date
|
||||
add_column :projects, :description, :text
|
||||
add_reference :projects, :supervised_by, foreign_key: { to_table: :users }
|
||||
|
||||
add_column :experiments, :started_at, :datetime
|
||||
add_column :experiments, :ended_at, :datetime
|
||||
add_column :experiments, :completed_at, :datetime
|
||||
add_column :experiments, :due_date, :date
|
||||
add_column :experiments, :start_on, :date
|
||||
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ ActiveRecord::Schema[7.0].define(version: 2025_04_10_093420) do
|
|||
t.datetime "updated_at", precision: nil, null: false
|
||||
t.uuid "uuid"
|
||||
t.datetime "started_at"
|
||||
t.datetime "ended_at"
|
||||
t.datetime "completed_at"
|
||||
t.date "due_date"
|
||||
t.date "start_on"
|
||||
t.index "(('EX'::text || id)) gin_trgm_ops", name: "index_experiments_on_experiment_code", using: :gin
|
||||
|
|
@ -577,7 +577,7 @@ ActiveRecord::Schema[7.0].define(version: 2025_04_10_093420) do
|
|||
t.bigint "project_folder_id"
|
||||
t.bigint "default_public_user_role_id"
|
||||
t.datetime "started_at"
|
||||
t.datetime "ended_at"
|
||||
t.datetime "completed_at"
|
||||
t.date "start_on"
|
||||
t.text "description"
|
||||
t.bigint "supervised_by_id"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue