mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-10 00:11:22 +08:00
Add advance filtering to protocol template table [SCI-10288]
This commit is contained in:
parent
3f4189445b
commit
db43c96619
4 changed files with 112 additions and 8 deletions
|
|
@ -9,6 +9,7 @@
|
||||||
:activePageUrl="activePageUrl"
|
:activePageUrl="activePageUrl"
|
||||||
:archivedPageUrl="archivedPageUrl"
|
:archivedPageUrl="archivedPageUrl"
|
||||||
:actionsUrl="actionsUrl"
|
:actionsUrl="actionsUrl"
|
||||||
|
:filters="filters"
|
||||||
@create="create"
|
@create="create"
|
||||||
@archive="archive"
|
@archive="archive"
|
||||||
@restore="restore"
|
@restore="restore"
|
||||||
|
|
@ -93,6 +94,10 @@ export default {
|
||||||
userRolesUrl: {
|
userRolesUrl: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
|
},
|
||||||
|
usersFilterUrl: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
|
|
@ -221,6 +226,48 @@ export default {
|
||||||
left,
|
left,
|
||||||
right: []
|
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: {
|
methods: {
|
||||||
|
|
@ -291,6 +338,12 @@ export default {
|
||||||
return `<a href="${urls.show}">${name}</a>`;
|
return `<a href="${urls.show}">${name}</a>`;
|
||||||
}
|
}
|
||||||
return `<span class="text-sn-grey">${name}</span>`;
|
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>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -66,8 +66,7 @@ module Lists
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_records
|
def filter_records
|
||||||
return if @params[:search].blank?
|
if @params[:search].present?
|
||||||
|
|
||||||
@records = @records.where(
|
@records = @records.where(
|
||||||
"LOWER(\"protocols\".\"name\") LIKE :search OR
|
"LOWER(\"protocols\".\"name\") LIKE :search OR
|
||||||
LOWER(\"protocol_keywords\".\"name\") LIKE :search OR
|
LOWER(\"protocol_keywords\".\"name\") LIKE :search OR
|
||||||
|
|
@ -76,6 +75,46 @@ module Lists
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
def sortable_columns
|
||||||
@sortable_columns ||= {
|
@sortable_columns ||= {
|
||||||
name: 'name',
|
name: 'name',
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@
|
||||||
:docx-parser-enabled="<%= Protocol.docx_parser_enabled? %>"
|
:docx-parser-enabled="<%= Protocol.docx_parser_enabled? %>"
|
||||||
user-roles-url="<%= user_roles_projects_path %>"
|
user-roles-url="<%= user_roles_projects_path %>"
|
||||||
:create-url="'<%= protocols_path if can_create_protocols_in_repository?(current_team) %>'"
|
:create-url="'<%= protocols_path if can_create_protocols_in_repository?(current_team) %>'"
|
||||||
|
users-filter-url="<%= users_filter_projects_path %>"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -2990,6 +2990,18 @@ en:
|
||||||
draft: "Draft"
|
draft: "Draft"
|
||||||
draft_name: "(Draft) %{name}"
|
draft_name: "(Draft) %{name}"
|
||||||
no_text_placeholder: 'No protocol description'
|
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:
|
reorder_steps:
|
||||||
button: "Rearrange steps"
|
button: "Rearrange steps"
|
||||||
modal:
|
modal:
|
||||||
|
|
@ -4101,7 +4113,6 @@ en:
|
||||||
title: "Filters"
|
title: "Filters"
|
||||||
text:
|
text:
|
||||||
label: "Contains text"
|
label: "Contains text"
|
||||||
label_name_and_keywords: "Name and keywords"
|
|
||||||
placeholder: "Enter search terms..."
|
placeholder: "Enter search terms..."
|
||||||
from_placeholder: "From"
|
from_placeholder: "From"
|
||||||
to_placeholder: "To"
|
to_placeholder: "To"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue