Merge pull request #7161 from rekonder/aj_SCI_10288

Add advance filtering to protocol template table [SCI-10288]
This commit is contained in:
aignatov-bio 2024-02-28 18:46:46 +01:00 committed by GitHub
commit 1e4fb7d580
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 112 additions and 8 deletions

View file

@ -9,6 +9,7 @@
:activePageUrl="activePageUrl"
:archivedPageUrl="archivedPageUrl"
:actionsUrl="actionsUrl"
:filters="filters"
@create="create"
@archive="archive"
@restore="restore"
@ -93,6 +94,10 @@ export default {
userRolesUrl: {
type: String,
required: true
},
usersFilterUrl: {
type: String,
required: true
}
},
data() {
@ -221,6 +226,48 @@ export default {
left,
right: []
};
},
filters() {
return [
{
key: 'name_and_keywords',
type: 'Text',
label: this.i18n.t('protocols.table.filters.label_name_and_keywords')
},
{
key: 'published_on',
type: 'DateRange',
label: this.i18n.t('protocols.table.filters.published_on')
},
{
key: 'modified_on',
type: 'DateRange',
label: this.i18n.t('protocols.table.filters.modified_on')
},
{
key: 'published_by',
type: 'Select',
optionsUrl: this.usersFilterUrl,
optionRenderer: this.usersFilterRenderer,
labelRenderer: this.usersFilterRenderer,
label: this.i18n.t('protocols.table.filters.published_by.label'),
placeholder: this.i18n.t('protocols.table.filters.published_by.placeholder')
},
{
key: 'members',
type: 'Select',
optionsUrl: this.usersFilterUrl,
optionRenderer: this.usersFilterRenderer,
labelRenderer: this.usersFilterRenderer,
label: this.i18n.t('protocols.table.filters.members.label'),
placeholder: this.i18n.t('protocols.table.filters.members.placeholder')
},
{
key: 'has_draft',
type: 'Checkbox',
label: this.i18n.t('protocols.table.filters.has_draft')
}
];
}
},
methods: {
@ -291,6 +338,12 @@ export default {
return `<a href="${urls.show}">${name}</a>`;
}
return `<span class="text-sn-grey">${name}</span>`;
},
usersFilterRenderer(option) {
return `<div class="flex items-center gap-2">
<img src="${option[2].avatar_url}" class="rounded-full w-6 h-6" />
<span>${option[1]}</span>
</div>`;
}
}
};

View file

@ -66,14 +66,53 @@ module Lists
end
def filter_records
return if @params[:search].blank?
if @params[:search].present?
@records = @records.where(
"LOWER(\"protocols\".\"name\") LIKE :search OR
LOWER(\"protocol_keywords\".\"name\") LIKE :search OR
LOWER(#{PREFIXED_ID_SQL}) LIKE :search",
search: "%#{@params[:search].to_s.downcase}%"
)
end
@records = @records.where(
"LOWER(\"protocols\".\"name\") LIKE :search OR
LOWER(\"protocol_keywords\".\"name\") LIKE :search OR
LOWER(#{PREFIXED_ID_SQL}) LIKE :search",
search: "%#{@params[:search].to_s.downcase}%"
)
if @filters[:name_and_keywords].present?
@records = @records.where_attributes_like(['protocols.name', 'protocol_keywords.name'],
@filters[:name_and_keywords])
end
if @filters[:published_on_from].present?
@records = @records.where('protocols.published_on > ?', @filters[:published_on_from])
end
if @filters[:published_on_to].present?
@records = @records.where('protocols.published_on < ?', @filters[:published_on_to])
end
if @filters[:modified_on_from].present?
@records = @records.where('protocols.updated_at > ?', @filters[:modified_on_from])
end
if @filters[:modified_on_to].present?
@records = @records.where('protocols.updated_at < ?', @filters[:modified_on_to])
end
if @filters[:published_by].present?
@records = @records.where(protocols: { published_by_id: @filters[:published_by].values })
end
if @filters[:members].present?
@records = @records.where(all_user_assignments: { user_id: @filters[:members].values })
end
if @filters[:has_draft].present?
@records =
@records
.joins("LEFT OUTER JOIN protocols protocol_drafts " \
"ON protocol_drafts.protocol_type = #{Protocol.protocol_types[:in_repository_draft]} " \
"AND (protocol_drafts.parent_id = protocols.id OR protocol_drafts.parent_id = protocols.parent_id)")
.where('protocols.protocol_type = ? OR protocol_drafts.id IS NOT NULL',
Protocol.protocol_types[:in_repository_draft])
end
end
def sortable_columns

View file

@ -36,6 +36,7 @@
:docx-parser-enabled="<%= Protocol.docx_parser_enabled? %>"
user-roles-url="<%= user_roles_projects_path %>"
:create-url="'<%= protocols_path if can_create_protocols_in_repository?(current_team) %>'"
users-filter-url="<%= users_filter_projects_path %>"
/>
</div>
</div>

View file

@ -2990,6 +2990,18 @@ en:
draft: "Draft"
draft_name: "(Draft) %{name}"
no_text_placeholder: 'No protocol description'
table:
filters:
label_name_and_keywords: 'Name and keywords'
published_on: 'Published on'
modified_on: 'Modified on'
has_draft: 'Has draft'
published_by:
label: 'Published by'
placeholder: 'Select a publisher'
members:
label: 'Access'
placeholder: 'Select who has access'
reorder_steps:
button: "Rearrange steps"
modal:
@ -4101,7 +4113,6 @@ en:
title: "Filters"
text:
label: "Contains text"
label_name_and_keywords: "Name and keywords"
placeholder: "Enter search terms..."
from_placeholder: "From"
to_placeholder: "To"