mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-27 10:08:11 +08:00
Rename filter_timestamps_range to timestamp_filters [SCI-8738]
This commit is contained in:
parent
8e96c2427a
commit
1e64a246fe
38 changed files with 93 additions and 95 deletions
|
@ -48,26 +48,5 @@ module Api
|
|||
end
|
||||
render json: response, status: :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def filter_timestamp_range(records)
|
||||
from = params.dig(:create_date_start)
|
||||
to = params.dig(:create_date_end)
|
||||
column = 'created_at'
|
||||
if from.blank? || to.blank?
|
||||
from = params.dig(:update_date_start)
|
||||
to = params.dig(:update_date_end)
|
||||
column = 'updated_at'
|
||||
end
|
||||
|
||||
return records if from.blank? || to.blank?
|
||||
|
||||
if column == 'created_at'
|
||||
records.where(created_at: (from..to))
|
||||
else
|
||||
records.where(updated_at: (from..to))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,8 +9,8 @@ module Api
|
|||
|
||||
def index
|
||||
attachments =
|
||||
filter_timestamp_range(@step.assets).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
timestamps_filter(@step.assets).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
|
||||
render jsonapi: attachments, each_serializer: AssetSerializer
|
||||
end
|
||||
|
|
|
@ -244,6 +244,25 @@ module Api
|
|||
raise FilterParamError
|
||||
end
|
||||
end
|
||||
|
||||
def timestamps_filter(records)
|
||||
from = params.dig(:created_at, :from)
|
||||
to = params.dig(:created_at, :to)
|
||||
return records.where(created_at: (from..to)) if
|
||||
valid_date?(*from&.split('-')&.map(&:to_i)) && valid_date?(*to&.split('-')&.map(&:to_i))
|
||||
|
||||
from = params.dig(:updated_at, :from)
|
||||
to = params.dig(:updated_at, :to)
|
||||
|
||||
return records.where(updated_at: (from..to)) if
|
||||
valid_date?(*from&.split('-')&.map(&:to_i)) && valid_date?(*to&.split('-')&.map(&:to_i))
|
||||
|
||||
records
|
||||
end
|
||||
|
||||
def valid_date?(year = '', month = '', day = '')
|
||||
Date.new(year, month, day) rescue false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,8 +13,8 @@ module Api
|
|||
|
||||
def index
|
||||
checklist_items =
|
||||
filter_timestamp_range(@checklist.checklist_items).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
timestamps_filter(@checklist.checklist_items).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
|
||||
render jsonapi: checklist_items, each_serializer: ChecklistItemSerializer
|
||||
end
|
||||
|
|
|
@ -11,8 +11,8 @@ module Api
|
|||
|
||||
def index
|
||||
checklists =
|
||||
filter_timestamp_range(@step.checklists).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
timestamps_filter(@step.checklists).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
|
||||
render jsonapi: checklists, each_serializer: ChecklistSerializer, include: include_params
|
||||
end
|
||||
|
|
|
@ -12,9 +12,9 @@ module Api
|
|||
|
||||
def index
|
||||
user_assignments =
|
||||
filter_timestamp_range(@experiment.user_assignments).includes(:user_role)
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
timestamps_filter(@experiment.user_assignments).includes(:user_role)
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
|
||||
render jsonapi: user_assignments,
|
||||
each_serializer: UserAssignmentSerializer,
|
||||
|
|
|
@ -11,7 +11,7 @@ module Api
|
|||
before_action :load_experiment_for_managing, only: %i(update)
|
||||
|
||||
def index
|
||||
experiments = filter_timestamp_range(@project.experiments)
|
||||
experiments = timestamps_filter(@project.experiments)
|
||||
experiments = archived_filter(experiments).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: experiments, each_serializer: ExperimentSerializer
|
||||
|
|
|
@ -12,9 +12,9 @@ module Api
|
|||
|
||||
def index
|
||||
inventories =
|
||||
filter_timestamp_range(@team.repositories).active
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
timestamps_filter(@team.repositories).active
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
|
||||
render jsonapi: inventories, each_serializer: InventorySerializer
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ module Api
|
|||
|
||||
def index
|
||||
cells =
|
||||
filter_timestamp_range(
|
||||
timestamps_filter(
|
||||
@inventory_item.repository_cells
|
||||
)
|
||||
.preload(:repository_column, value: @inventory.cell_preload_includes)
|
||||
|
|
|
@ -12,8 +12,8 @@ module Api
|
|||
|
||||
def index
|
||||
checklist_items =
|
||||
filter_timestamp_range(@inventory_column.repository_checklist_items).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
timestamps_filter(@inventory_column.repository_checklist_items).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
|
||||
render jsonapi: checklist_items, each_serializer: InventoryChecklistItemSerializer
|
||||
end
|
||||
|
|
|
@ -12,12 +12,12 @@ module Api
|
|||
before_action :check_create_permissions, only: %i(create)
|
||||
|
||||
def index
|
||||
columns = filter_timestamp_range(@inventory.repository_columns).includes(:repository_list_items)
|
||||
.includes(:repository_status_items)
|
||||
.includes(:repository_checklist_items)
|
||||
.includes(:repository_stock_unit_items)
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
columns = timestamps_filter(@inventory.repository_columns).includes(:repository_list_items)
|
||||
.includes(:repository_status_items)
|
||||
.includes(:repository_checklist_items)
|
||||
.includes(:repository_stock_unit_items)
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
|
||||
render jsonapi: columns,
|
||||
each_serializer: InventoryColumnSerializer,
|
||||
|
|
|
@ -13,7 +13,7 @@ module Api
|
|||
|
||||
def index
|
||||
items =
|
||||
filter_timestamp_range(
|
||||
timestamps_filter(
|
||||
@inventory.repository_rows
|
||||
)
|
||||
.active
|
||||
|
|
|
@ -11,8 +11,8 @@ module Api
|
|||
before_action :check_manage_permissions, only: %i(create update destroy)
|
||||
|
||||
def index
|
||||
list_items = filter_timestamp_range(@inventory_column.repository_list_items).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
list_items = timestamps_filter(@inventory_column.repository_list_items).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
|
||||
render jsonapi: list_items, each_serializer: InventoryListItemSerializer
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ module Api
|
|||
|
||||
def index
|
||||
status_items =
|
||||
filter_timestamp_range(
|
||||
timestamps_filter(
|
||||
@inventory_column.repository_status_items
|
||||
)
|
||||
.repository_status_items
|
||||
|
|
|
@ -12,7 +12,7 @@ module Api
|
|||
|
||||
def index
|
||||
stock_unit_items =
|
||||
filter_timestamp_range(
|
||||
timestamps_filter(
|
||||
@inventory_column.repository_stock_unit_items
|
||||
)
|
||||
.page(params.dig(:page, :number))
|
||||
|
|
|
@ -9,8 +9,8 @@ module Api
|
|||
before_action :load_project_comment, only: :show
|
||||
|
||||
def index
|
||||
project_comments = filter_timestamp_range(@project.project_comments).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
project_comments = timestamps_filter(@project.project_comments).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
|
||||
render jsonapi: project_comments,
|
||||
each_serializer: CommentSerializer,
|
||||
|
|
|
@ -7,8 +7,8 @@ module Api
|
|||
before_action :load_project_folder, only: %i(show update)
|
||||
|
||||
def index
|
||||
project_folders = filter_timestamp_range(@team.project_folders).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
project_folders = timestamps_filter(@team.project_folders).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
|
||||
render jsonapi: project_folders, each_serializer: ProjectFolderSerializer
|
||||
end
|
||||
|
|
|
@ -19,9 +19,9 @@ module Api
|
|||
end
|
||||
|
||||
def index
|
||||
user_assignments = filter_timestamp_range(@project.user_assignments).includes(:user_role)
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
user_assignments = timestamps_filter(@project.user_assignments).includes(:user_role)
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
|
||||
render jsonapi: user_assignments,
|
||||
each_serializer: UserAssignmentSerializer,
|
||||
|
|
|
@ -11,7 +11,7 @@ module Api
|
|||
before_action :load_project_for_managing, only: %i(update)
|
||||
|
||||
def index
|
||||
projects = filter_timestamp_range(@team.projects.visible_to(current_user, @team))
|
||||
projects = timestamps_filter(@team.projects.visible_to(current_user, @team))
|
||||
projects = archived_filter(projects).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ module Api
|
|||
|
||||
def index
|
||||
protocol_templates =
|
||||
filter_timestamp_range(
|
||||
timestamps_filter(
|
||||
Protocol.latest_available_versions(@team)
|
||||
)
|
||||
.viewable_by_user(current_user, @team)
|
||||
|
|
|
@ -11,8 +11,8 @@ module Api
|
|||
end
|
||||
|
||||
def index
|
||||
protocols = filter_timestamp_range(@task.protocols).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
protocols = timestamps_filter(@task.protocols).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: protocols,
|
||||
each_serializer: ProtocolSerializer, rte_rendering: render_rte?, team: @team
|
||||
end
|
||||
|
|
|
@ -8,8 +8,8 @@ module Api
|
|||
before_action :load_report, only: :show
|
||||
|
||||
def index
|
||||
reports = filter_timestamp_range(@project.reports).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
reports = timestamps_filter(@project.reports).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: reports,
|
||||
each_serializer: ReportSerializer,
|
||||
hide_project: true
|
||||
|
|
|
@ -8,8 +8,8 @@ module Api
|
|||
before_action :check_manage_permissions, only: %i(create update)
|
||||
|
||||
def index
|
||||
results = filter_timestamp_range(@task.results).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
results = timestamps_filter(@task.results).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: results, each_serializer: ResultSerializer,
|
||||
include: (%i(text table file) << include_params).flatten.compact
|
||||
end
|
||||
|
|
|
@ -10,8 +10,8 @@ module Api
|
|||
before_action :load_step_text_for_managing, only: %i(update destroy)
|
||||
|
||||
def index
|
||||
step_texts = filter_timestamp_range(@step.step_texts).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
step_texts = timestamps_filter(@step.step_texts).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
|
||||
render jsonapi: step_texts, each_serializer: StepTextSerializer, include: include_params
|
||||
end
|
||||
|
|
|
@ -13,8 +13,8 @@ module Api
|
|||
before_action :check_delete_permissions, only: :destroy
|
||||
|
||||
def index
|
||||
steps = filter_timestamp_range(@protocol.steps).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
steps = timestamps_filter(@protocol.steps).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
|
||||
render jsonapi: steps, each_serializer: StepSerializer,
|
||||
include: include_params,
|
||||
|
|
|
@ -10,8 +10,8 @@ module Api
|
|||
before_action :load_table_for_managing, only: %i(update destroy)
|
||||
|
||||
def index
|
||||
tables = filter_timestamp_range(@step.tables).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
tables = timestamps_filter(@step.tables).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
|
||||
render jsonapi: tables, each_serializer: TableSerializer
|
||||
end
|
||||
|
|
|
@ -10,10 +10,10 @@ module Api
|
|||
before_action :check_manage_permissions, only: %i(create destroy)
|
||||
|
||||
def index
|
||||
users = filter_timestamp_range(User).joins(:user_my_modules)
|
||||
.where(user_my_modules: { my_module_id: @task.id })
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
users = timestamps_filter(User).joins(:user_my_modules)
|
||||
.where(user_my_modules: { my_module_id: @task.id })
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: users, each_serializer: UserSerializer
|
||||
end
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ module Api
|
|||
before_action :load_task_group, only: :show
|
||||
|
||||
def index
|
||||
task_groups = filter_timestamp_range(@experiment.my_module_groups).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
task_groups = timestamps_filter(@experiment.my_module_groups).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: task_groups, each_serializer: TaskGroupSerializer, include: include_params
|
||||
end
|
||||
|
||||
|
|
|
@ -12,10 +12,10 @@ module Api
|
|||
|
||||
def index
|
||||
items =
|
||||
filter_timestamp_range(@task.repository_rows).includes(repository_cells: :repository_column)
|
||||
.preload(repository_cells: :value)
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
timestamps_filter(@task.repository_rows).includes(repository_cells: :repository_column)
|
||||
.preload(repository_cells: :value)
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: items,
|
||||
each_serializer: TaskInventoryItemSerializer,
|
||||
show_repository: true,
|
||||
|
|
|
@ -10,8 +10,8 @@ module Api
|
|||
before_action :load_tag, only: :show
|
||||
|
||||
def index
|
||||
tags = filter_timestamp_range(@task.tags).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
tags = timestamps_filter(@task.tags).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: tags, each_serializer: TagSerializer
|
||||
end
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ module Api
|
|||
before_action :load_user_assignment_for_managing, only: %i(update show)
|
||||
|
||||
def index
|
||||
user_assignments = filter_timestamp_range(@task.user_assignments).includes(:user_role)
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
user_assignments = timestamps_filter(@task.user_assignments).includes(:user_role)
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
|
||||
render jsonapi: user_assignments,
|
||||
each_serializer: UserAssignmentSerializer,
|
||||
|
|
|
@ -10,8 +10,8 @@ module Api
|
|||
before_action :load_user, only: :show
|
||||
|
||||
def index
|
||||
users = filter_timestamp_range(@task.users).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
users = timestamps_filter(@task.users).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: users, each_serializer: UserSerializer
|
||||
end
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ module Api
|
|||
|
||||
def index
|
||||
tasks =
|
||||
filter_timestamp_range(
|
||||
timestamps_filter(
|
||||
@experiment.my_modules
|
||||
).includes(:my_module_status, :my_modules, :my_module_antecessors)
|
||||
tasks = archived_filter(tasks).page(params.dig(:page, :number))
|
||||
|
|
|
@ -8,8 +8,8 @@ module Api
|
|||
end
|
||||
|
||||
def index
|
||||
teams = filter_timestamp_range(current_user.teams).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
teams = timestamps_filter(current_user.teams).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: teams, each_serializer: TeamSerializer
|
||||
end
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ module Api
|
|||
before_action :load_user_identity, only: %i(show update destroy)
|
||||
|
||||
def index
|
||||
identities = filter_timestamp_range(@user.user_identities).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
identities = timestamps_filter(@user.user_identities).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: identities, each_serializer: UserIdentitySerializer
|
||||
end
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ module Api
|
|||
before_action :load_user, only: :show
|
||||
|
||||
def index
|
||||
users = filter_timestamp_range(@team.users).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
users = timestamps_filter(@team.users).page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: users, each_serializer: UserSerializer
|
||||
end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ module Api
|
|||
before_action :load_workflow
|
||||
|
||||
def index
|
||||
statuses = filter_timestamp_range(@workflow.my_module_statuses)
|
||||
statuses = timestamps_filter(@workflow.my_module_statuses)
|
||||
render jsonapi: statuses, each_serializer: WorkflowStatusSerializer
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ module Api
|
|||
end
|
||||
|
||||
def index
|
||||
workflows = filter_timestamp_range(MyModuleStatusFlow.all)
|
||||
workflows = timestamps_filter(MyModuleStatusFlow.all)
|
||||
render jsonapi: workflows, each_serializer: WorkflowSerializer
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue