Add search to current task widget

This commit is contained in:
aignatov-bio 2020-03-03 09:50:44 +01:00
parent 73623da02c
commit d9bfd8c28e
6 changed files with 75 additions and 8 deletions

View file

@ -6,7 +6,7 @@ var DasboardCurrentTasksWidget = (function() {
var viewFilter = '.curent-tasks-filters .view-filter'; var viewFilter = '.curent-tasks-filters .view-filter';
var projectFilter = '.curent-tasks-filters .project-filter'; var projectFilter = '.curent-tasks-filters .project-filter';
var experimentFilter = '.curent-tasks-filters .experiment-filter'; var experimentFilter = '.curent-tasks-filters .experiment-filter';
var emptyState = `<div class="no-tasks"> var emptyState = `<div class="no-tasks ">
<p class="text-1">${ I18n.t('dashboard.current_tasks.no_tasks.text_1') }</p> <p class="text-1">${ I18n.t('dashboard.current_tasks.no_tasks.text_1') }</p>
<p class="text-2">${ I18n.t('dashboard.current_tasks.no_tasks.text_2') }</p> <p class="text-2">${ I18n.t('dashboard.current_tasks.no_tasks.text_2') }</p>
<i class="fas fa-angle-double-down"></i> <i class="fas fa-angle-double-down"></i>
@ -19,18 +19,16 @@ var DasboardCurrentTasksWidget = (function() {
experiment_id: dropdownSelector.getValues(experimentFilter), experiment_id: dropdownSelector.getValues(experimentFilter),
sort: dropdownSelector.getValues(sortFilter), sort: dropdownSelector.getValues(sortFilter),
view: dropdownSelector.getValues(viewFilter), view: dropdownSelector.getValues(viewFilter),
query: $('.current-tasks-widget .task-search-field').val(),
mode: $('.current-tasks-navbar .active').data('mode') mode: $('.current-tasks-navbar .active').data('mode')
}; };
animateSpinner($currentTasksList, true); animateSpinner($currentTasksList, true);
$.get($currentTasksList.data('tasksListUrl'), params, function(data) { $.get($currentTasksList.data('tasksListUrl'), params, function(data) {
$currentTasksList.find('.current-task-item, .no-tasks').remove();
// Toggle empty state // Toggle empty state
if (data.tasks_list.length === 0) { if (data.tasks_list.length === 0) {
$currentTasksList.append(emptyState); $currentTasksList.append(emptyState);
} else {
$currentTasksList.find('.no-tasks').remove();
} }
// Clear the list
$currentTasksList.find('.current-task-item').remove();
$.each(data.tasks_list, (i, task) => { $.each(data.tasks_list, (i, task) => {
var currentTaskItem; var currentTaskItem;
var stepsPercentage = task.steps_state.percentage + '%'; var stepsPercentage = task.steps_state.percentage + '%';
@ -152,11 +150,24 @@ var DasboardCurrentTasksWidget = (function() {
}); });
} }
function initSearch() {
$('.current-tasks-widget').on('change', '.task-search-field', () => {
loadCurrentTasksList();
}).on('keydown', '.task-search-field', function(e) {
if (e.keyCode === 13) {
loadCurrentTasksList();
$(this).blur();
}
});
}
return { return {
init: () => { init: () => {
if ($('.current-tasks-widget').length) { if ($('.current-tasks-widget').length) {
initNavbar(); initNavbar();
initFilters(); initFilters();
initSearch();
loadCurrentTasksList(); loadCurrentTasksList();
} }
} }

View file

@ -15,6 +15,52 @@
padding-left: 10px; padding-left: 10px;
} }
.search-container {
flex-basis: 36px;
.fa-search {
animation-timing-function: $timing-function-sharp;
color: $color-alto;
transition: .3s;
width: 26px;
}
.task-search-field {
background: transparent;
border: $border-default;
padding-left: 36px;
position: relative;
width: 200px;
z-index: 2;
&:placeholder-shown {
border: $border-transparent;
cursor: pointer;
width: 36px;
+ .fa-search {
color: $color-volcano;
}
}
&:hover {
border: $border-default;
}
&:focus {
border: $border-focus;
cursor: auto;
width: 200px;
+ .fa-search {
color: $color-alto;
}
}
}
}
.filter-container { .filter-container {
height: 36px; height: 36px;
margin-right: 4px; margin-right: 4px;
@ -67,6 +113,7 @@
} }
} }
.no-tasks { .no-tasks {
color: $color-alto; color: $color-alto;
margin-left: 8px; margin-left: 8px;
@ -109,7 +156,7 @@
line-height: 14px; line-height: 14px;
} }
.item-row{ .item-row {
display: flex; display: flex;
.task-name { .task-name {

View file

@ -30,6 +30,10 @@
&:disabled { &:disabled {
background: transparent; background: transparent;
} }
&::placeholder {
color: $color-alto;
}
} }
.fas { .fas {

View file

@ -20,6 +20,7 @@ module Dashboard
tasks = tasks.left_outer_joins(:user_my_modules).where('user_my_modules.user_id': current_user.id) tasks = tasks.left_outer_joins(:user_my_modules).where('user_my_modules.user_id': current_user.id)
end end
tasks = tasks.where('my_modules.state': task_filters[:view]) tasks = tasks.where('my_modules.state': task_filters[:view])
.search_by_name(current_user, current_team, task_filters[:query])
case task_filters[:sort] case task_filters[:sort]
when 'date_desc' when 'date_desc'
@ -83,7 +84,7 @@ module Dashboard
private private
def task_filters def task_filters
params.permit(:project_id, :experiment_id, :mode, :view, :sort) params.permit(:project_id, :experiment_id, :mode, :view, :sort, :query)
end end
def load_project def load_project

View file

@ -45,7 +45,10 @@
</div> </div>
</div> </div>
<div class="search-container"> <div class="search-container">
<div class="btn btn-light icon-btn search-button"><i class="fas fa-search"></i></div> <div class="sci-input-container left-icon ">
<input type="text" class="sci-input-field task-search-field" placeholder="<%= t("dashboard.current_tasks.search") %>"></input>
<i class="fas fa-search"></i>
</div>
</div> </div>
</div> </div>

View file

@ -2,6 +2,7 @@ en:
dashboard: dashboard:
current_tasks: current_tasks:
title: "Current tasks" title: "Current tasks"
search: "Search tasks"
navbar: navbar:
assigned: "Assigned to me" assigned: "Assigned to me"
all: "All" all: "All"