diff --git a/app/javascript/vue/protocols/table.vue b/app/javascript/vue/protocols/table.vue
index 5da84b8d2..eb23a4bde 100644
--- a/app/javascript/vue/protocols/table.vue
+++ b/app/javascript/vue/protocols/table.vue
@@ -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 `${name}`;
}
return `${name}`;
+ },
+ usersFilterRenderer(option) {
+ return `
+
+
${option[1]}
+
`;
}
}
};
diff --git a/app/services/lists/protocols_service.rb b/app/services/lists/protocols_service.rb
index d567b9557..49bb3e924 100644
--- a/app/services/lists/protocols_service.rb
+++ b/app/services/lists/protocols_service.rb
@@ -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
diff --git a/app/views/protocols/index.html.erb b/app/views/protocols/index.html.erb
index 22a9ba984..728a1fcec 100644
--- a/app/views/protocols/index.html.erb
+++ b/app/views/protocols/index.html.erb
@@ -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 %>"
/>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index d6136695a..0b0d0f32d 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -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"