mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-27 10:08:11 +08:00
Archiving: add 'archived' flag on folder [SCI-5268]
This commit is contained in:
parent
ba3db65437
commit
f150a11c4f
5 changed files with 56 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ProjectFolder < ApplicationRecord
|
||||
include ArchivableModel
|
||||
include SearchableModel
|
||||
include SearchableByNameModel
|
||||
|
||||
|
@ -14,6 +15,14 @@ class ProjectFolder < ApplicationRecord
|
|||
|
||||
belongs_to :team, inverse_of: :project_folders, touch: true
|
||||
belongs_to :parent_folder, class_name: 'ProjectFolder', optional: true
|
||||
belongs_to :archived_by, foreign_key: 'archived_by_id',
|
||||
class_name: 'User',
|
||||
inverse_of: :archived_project_folders,
|
||||
optional: true
|
||||
belongs_to :restored_by, foreign_key: 'restored_by_id',
|
||||
class_name: 'User',
|
||||
inverse_of: :restored_project_folders,
|
||||
optional: true
|
||||
has_many :projects, inverse_of: :project_folder, dependent: :nullify
|
||||
has_many :project_folders, foreign_key: 'parent_folder_id', inverse_of: :parent_folder, dependent: :destroy
|
||||
|
||||
|
|
|
@ -125,6 +125,14 @@ class User < ApplicationRecord
|
|||
has_many :restored_projects,
|
||||
class_name: 'Project',
|
||||
foreign_key: 'restored_by_id'
|
||||
has_many :archived_project_folders,
|
||||
class_name: 'ProjectFolder',
|
||||
foreign_key: 'archived_by_id',
|
||||
inverse_of: :arhived_by
|
||||
has_many :restored_project_folders,
|
||||
class_name: 'ProjectFolder',
|
||||
foreign_key: 'restored_by_id',
|
||||
inverse_of: :restored_by
|
||||
has_many :modified_reports,
|
||||
class_name: 'Report',
|
||||
foreign_key: 'last_modified_by_id'
|
||||
|
|
|
@ -107,6 +107,8 @@ class ProjectsOverviewService
|
|||
end
|
||||
|
||||
def filter_project_folder_records(records)
|
||||
records = records.where(archived: true) if @params[:filter] == 'archived'
|
||||
records = records.where(archived: false) if @params[:filter] == 'active'
|
||||
records = records.where_attributes_like('project_folders.name', @params[:search]) if @params[:search].present?
|
||||
records
|
||||
end
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddArchivedFlagToProjectFolders < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
change_table :project_folders, bulk: true do |t|
|
||||
t.boolean :archived, default: false
|
||||
t.references :archived_by, foreign_key: { to_table: :users }, index: false
|
||||
t.datetime :archived_on
|
||||
t.references :restored_by, foreign_key: { to_table: :users }, index: false
|
||||
t.datetime :restored_on
|
||||
end
|
||||
end
|
||||
end
|
|
@ -996,7 +996,12 @@ CREATE TABLE public.project_folders (
|
|||
team_id bigint NOT NULL,
|
||||
parent_folder_id bigint,
|
||||
created_at timestamp(6) without time zone NOT NULL,
|
||||
updated_at timestamp(6) without time zone NOT NULL
|
||||
updated_at timestamp(6) without time zone NOT NULL,
|
||||
archived boolean DEFAULT false,
|
||||
archived_by_id bigint,
|
||||
archived_on timestamp without time zone,
|
||||
restored_by_id bigint,
|
||||
restored_on timestamp without time zone
|
||||
);
|
||||
|
||||
|
||||
|
@ -6111,6 +6116,14 @@ ALTER TABLE ONLY public.repository_status_items
|
|||
ADD CONSTRAINT fk_rails_74e5e4cacc FOREIGN KEY (repository_column_id) REFERENCES public.repository_columns(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: project_folders fk_rails_7931975dd0; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.project_folders
|
||||
ADD CONSTRAINT fk_rails_7931975dd0 FOREIGN KEY (restored_by_id) REFERENCES public.users(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: project_folders fk_rails_795296de66; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -6807,6 +6820,14 @@ ALTER TABLE ONLY public.protocol_protocol_keywords
|
|||
ADD CONSTRAINT fk_rails_f04cc911dd FOREIGN KEY (protocol_id) REFERENCES public.protocols(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: project_folders fk_rails_f27fa590f4; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.project_folders
|
||||
ADD CONSTRAINT fk_rails_f27fa590f4 FOREIGN KEY (archived_by_id) REFERENCES public.users(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: report_elements fk_rails_f36eac136b; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -7064,6 +7085,5 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||
('20200826143431'),
|
||||
('20200909121441'),
|
||||
('20201028103608'),
|
||||
('20201126203713');
|
||||
|
||||
|
||||
('20201126203713'),
|
||||
('20201209165626');
|
||||
|
|
Loading…
Reference in a new issue