Add calendar widget

This commit is contained in:
aignatov-bio 2020-02-20 17:02:38 +01:00
parent 01868fff23
commit cf4dbd5ff4
9 changed files with 276 additions and 7 deletions

View file

@ -1,4 +1,5 @@
/* global I18n */
/* eslint-disable no-underscore-dangle */
var DasboardCalendarWidget = (function() {
function calendarTemplate() {
@ -17,12 +18,29 @@ var DasboardCalendarWidget = (function() {
<div class="day-header"><%= day %></div>
<% }); %>
<% _.each(days, function(day) { %>
<div class="<%= day.classes %>" id="<%= day.id %>"><%= day.day %></div>
<% if (day.classes.includes('event')){ %>
<div class="<%= day.classes %>" id="<%= day.id %>">
<div class="event-day" data-toggle="dropdown"><%= day.day %></div>
<div class="dropdown-menu events-container dropdown-menu-right" role="menu">
<div class="title">Due on <%= day.date.format(formatJS) %></div>
<div class="tasks"></div>
</div>
</div>
<% } else { %>
<div class="<%= day.classes %>" id="<%= day.id %>"><%= day.day %></div>
<% } %>
<% }); %>
</div>
</script>`;
}
function getMonthEventsList(date, clndrInstance) {
var getUrl = $('.dashboard-calendar').data('month-events-url');
$.get(getUrl, { date: date }, function(result) {
clndrInstance.setEvents(result.events);
});
}
function initCalendar() {
var dayOfWeek = [
I18n.t('dashboard.calendar.dow.su'),
@ -33,12 +51,26 @@ var DasboardCalendarWidget = (function() {
I18n.t('dashboard.calendar.dow.fr'),
I18n.t('dashboard.calendar.dow.sa')
];
$('.dashboard-calendar').clndr({
var clndrInstance = $('.dashboard-calendar').clndr({
template: $(calendarTemplate()).html(),
adjacentDaysChangeMonth: true,
daysOfTheWeek: dayOfWeek,
forceSixRows: true
forceSixRows: true,
clickEvents: {
click: function(target) {
var getDayUrl = $('.dashboard-calendar').data('day-events-url');
if ($(target.element).hasClass('event')) {
$.get(getDayUrl, { date: target.date._i }, function(result) {
$(target.element).find('.tasks').html(result.html);
});
}
},
onMonthChange: function(month) {
getMonthEventsList(month._d, clndrInstance);
}
}
});
getMonthEventsList((new Date()), clndrInstance);
}

View file

@ -50,9 +50,13 @@
.day {
@include font-button;
align-items: center;
animation-timing-function: $timing-function-sharp;
border-radius: 50%;
display: flex;
height: 32px;
justify-content: center;
position: relative;
transition: .3s;
user-select: none;
width: 32px;
@ -62,7 +66,47 @@
&.today {
border: $border-primary;
border-radius: 50%;
}
&.event {
.event-day {
align-items: center;
border-radius: 50%;
cursor: pointer;
display: flex;
height: 32px;
justify-content: center;
width: 32px;
&:hover {
background: $color-alto;
color: inherit;
}
}
&::after {
background: $brand-danger;
border-radius: 50%;
content: "";
height: 4px;
left: 14px;
position: absolute;
top: 24px;
width: 4px;
}
}
.events-container {
color: $color-black;
padding: 8px;
width: 280px;
.title {
@include font-h3;
margin-bottom: 8px;
}
}
}
}
@ -79,5 +123,12 @@
.dashboard-container .calendar-widget {
grid-column: 1 / span 6;
grid-row: 5 / span 4;
.clndr {
.events-container {
left: 0;
right: auto;
}
}
}
}

View file

@ -0,0 +1,51 @@
// scss-lint:disable SelectorDepth
// scss-lint:disable NestingDepth
.my-modules-list-partial {
width: 100%;
.task-group:not(:first-child) {
border-top: $border-tertiary;
}
.header {
@include font-small;
align-items: center;
color: $color-silver-chalice;
display: flex;
height: 20px;
margin: 5px 0;
width: 100%;
.project,
.experiment {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.slash {
flex-basis: 20px;
text-align: center;
}
}
.tasks {
@include font-button;
margin-bottom: 5px;
.task {
align-items: center;
display: flex;
line-height: 25px;
}
.task-icon {
margin-right: 9px;
path {
fill: $brand-primary;
}
}
}
}

View file

@ -0,0 +1,21 @@
# frozen_string_literal: true
module Dashboard
class CalendarsController < ApplicationController
def show
date = DateTime.parse(params[:date])
start_date = date.at_beginning_of_month.utc - 7.days
end_date = date.at_end_of_month.utc + 14.days
due_dates = current_user.my_modules.where('due_date > ? AND due_date < ?', start_date, end_date).pluck(:due_date)
render json: { events: due_dates.map { |i| { date: i } } }
end
def day
date = DateTime.parse(params[:date]).utc
my_modules = current_user.my_modules.where('DATE(my_modules.due_date) = DATE(?)', date).my_modules_list_partial
render json: {
html: render_to_string(partial: 'shared/my_modules_list_partial.html.erb', locals: { task_groups: my_modules })
}
end
end
end

View file

@ -514,6 +514,21 @@ class MyModule < ApplicationRecord
self.completed_on = nil
end
def self.my_modules_list_partial
ungrouped_tasks = joins(experiment: :project)
.select('experiments.name as experiment_name,
projects.name as project_name,
my_modules.name as task_name,
my_modules.id')
ungrouped_tasks.group_by { |i| [i[:project_name], i[:experiment_name]] }.map do |group, tasks|
{
project_name: group[0],
experiment_name: group[1],
tasks: tasks.map { |task| { id: task.id, task_name: task.task_name } }
}
end
end
private
def create_blank_protocol

View file

@ -1,3 +1,21 @@
<div class="calendar-widget basic-widget">
<div class="dashboard-calendar"></div>
</div>
<div class="dashboard-calendar"
data-month-events-url="<%= dashboard_calendar_path %>"
data-day-events-url="<%= day_dashboard_calendar_path %>"
></div>
</div>
<script type="text/javascript" charset="utf-8">
<%
js_format = I18n.backend.date_format.dup
js_format.gsub!(/%-d/, 'D')
js_format.gsub!(/%d/, 'DD')
js_format.gsub!(/%-m/, 'M')
js_format.gsub!(/%m/, 'MM')
js_format.gsub!(/%b/, 'MMM')
js_format.gsub!(/%B/, 'MMMM')
js_format.gsub!('%Y', 'YYYY')
%>
var formatJS = "<%= js_format %>"
</script>

View file

@ -0,0 +1,19 @@
<div class="my-modules-list-partial">
<% task_groups.each do |task_group| %>
<div class="task-group">
<div class="header">
<span class="project" title="<%= task_group[:project_name] %>"><%= task_group[:project_name] %></span>
<span class="slash">/</span>
<span class="experiment" title="<%= task_group[:experiment_name] %>"><%= task_group[:experiment_name] %></span>
</div>
<div class="tasks">
<% task_group[:tasks].each do |task| %>
<div class="task">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" class="task-icon"><path d="M6.646 14V7.215H4V5h7.938v2.215H9.292V14h4.144c.26 0 .434-.009.542-.022.013-.107.022-.282.022-.542V2.564c0-.26-.009-.435-.022-.542A4.762 4.762 0 0 0 13.436 2H2.564c-.26 0-.435.009-.542.022A4.762 4.762 0 0 0 2 2.564v10.872c0 .26.009.434.022.542.107.013.282.022.542.022h4.082zM2.564 0h10.872c.892 0 1.215.093 1.54.267.327.174.583.43.757.756.174.326.267.65.267 1.54v10.873c0 .892-.093 1.215-.267 1.54-.174.327-.43.583-.756.757-.326.174-.65.267-1.54.267H2.563c-.892 0-1.215-.093-1.54-.267a1.817 1.817 0 0 1-.757-.756C.093 14.65 0 14.327 0 13.437V2.563c0-.892.093-1.215.267-1.54.174-.327.43-.583.756-.757C1.35.093 1.673 0 2.563 0z" fill="#B3B3B3" fill-rule="evenodd"/></svg>
<%= link_to(task[:task_name], protocols_my_module_path(task[:id]), {class: "task-link", title: task[:task_name]}) %>
</div>
<% end %>
</div>
<% end %>
</div>
</div>

View file

@ -245,6 +245,10 @@ Rails.application.routes.draw do
get :project_filter
get :experiment_filter
end
resource :calendar, module: 'dashboard', only: [:show] do
get :day
end
end
resources :projects, except: [:new, :destroy] do

View file

@ -147,6 +147,7 @@ CREATE TABLE public.activities (
--
CREATE SEQUENCE public.activities_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -192,6 +193,7 @@ CREATE TABLE public.asset_text_data (
--
CREATE SEQUENCE public.asset_text_data_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -231,6 +233,7 @@ CREATE TABLE public.assets (
--
CREATE SEQUENCE public.assets_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -267,6 +270,7 @@ CREATE TABLE public.checklist_items (
--
CREATE SEQUENCE public.checklist_items_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -301,6 +305,7 @@ CREATE TABLE public.checklists (
--
CREATE SEQUENCE public.checklists_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -336,6 +341,7 @@ CREATE TABLE public.comments (
--
CREATE SEQUENCE public.comments_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -366,6 +372,7 @@ CREATE TABLE public.connections (
--
CREATE SEQUENCE public.connections_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -400,6 +407,7 @@ CREATE TABLE public.custom_fields (
--
CREATE SEQUENCE public.custom_fields_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -491,6 +499,7 @@ CREATE TABLE public.delayed_jobs (
--
CREATE SEQUENCE public.delayed_jobs_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -532,6 +541,7 @@ CREATE TABLE public.experiments (
--
CREATE SEQUENCE public.experiments_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -564,6 +574,7 @@ CREATE TABLE public.my_module_groups (
--
CREATE SEQUENCE public.my_module_groups_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -597,6 +608,7 @@ CREATE TABLE public.my_module_repository_rows (
--
CREATE SEQUENCE public.my_module_repository_rows_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -628,6 +640,7 @@ CREATE TABLE public.my_module_tags (
--
CREATE SEQUENCE public.my_module_tags_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -676,6 +689,7 @@ CREATE TABLE public.my_modules (
--
CREATE SEQUENCE public.my_modules_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -710,6 +724,7 @@ CREATE TABLE public.notifications (
--
CREATE SEQUENCE public.notifications_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -863,6 +878,7 @@ CREATE TABLE public.projects (
--
CREATE SEQUENCE public.projects_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -896,6 +912,7 @@ CREATE TABLE public.protocol_keywords (
--
CREATE SEQUENCE public.protocol_keywords_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -926,6 +943,7 @@ CREATE TABLE public.protocol_protocol_keywords (
--
CREATE SEQUENCE public.protocol_protocol_keywords_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -971,6 +989,7 @@ CREATE TABLE public.protocols (
--
CREATE SEQUENCE public.protocols_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1015,6 +1034,7 @@ CREATE TABLE public.report_elements (
--
CREATE SEQUENCE public.report_elements_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1051,6 +1071,7 @@ CREATE TABLE public.reports (
--
CREATE SEQUENCE public.reports_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1086,6 +1107,7 @@ CREATE TABLE public.repositories (
--
CREATE SEQUENCE public.repositories_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1153,6 +1175,7 @@ CREATE TABLE public.repository_cells (
--
CREATE SEQUENCE public.repository_cells_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1287,6 +1310,7 @@ CREATE TABLE public.repository_columns (
--
CREATE SEQUENCE public.repository_columns_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1356,6 +1380,7 @@ CREATE TABLE public.repository_date_time_values (
--
CREATE SEQUENCE public.repository_date_time_values_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1491,6 +1516,7 @@ CREATE TABLE public.repository_rows (
--
CREATE SEQUENCE public.repository_rows_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1593,6 +1619,7 @@ CREATE TABLE public.repository_table_states (
--
CREATE SEQUENCE public.repository_table_states_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1626,6 +1653,7 @@ CREATE TABLE public.repository_text_values (
--
CREATE SEQUENCE public.repository_text_values_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1656,6 +1684,7 @@ CREATE TABLE public.result_assets (
--
CREATE SEQUENCE public.result_assets_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1686,6 +1715,7 @@ CREATE TABLE public.result_tables (
--
CREATE SEQUENCE public.result_tables_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1716,6 +1746,7 @@ CREATE TABLE public.result_texts (
--
CREATE SEQUENCE public.result_texts_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1755,6 +1786,7 @@ CREATE TABLE public.results (
--
CREATE SEQUENCE public.results_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1788,6 +1820,7 @@ CREATE TABLE public.sample_custom_fields (
--
CREATE SEQUENCE public.sample_custom_fields_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1823,6 +1856,7 @@ CREATE TABLE public.sample_groups (
--
CREATE SEQUENCE public.sample_groups_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1855,6 +1889,7 @@ CREATE TABLE public.sample_my_modules (
--
CREATE SEQUENCE public.sample_my_modules_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1889,6 +1924,7 @@ CREATE TABLE public.sample_types (
--
CREATE SEQUENCE public.sample_types_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1926,6 +1962,7 @@ CREATE TABLE public.samples (
--
CREATE SEQUENCE public.samples_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1959,6 +1996,7 @@ CREATE TABLE public.samples_tables (
--
CREATE SEQUENCE public.samples_tables_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -1998,6 +2036,7 @@ CREATE TABLE public.settings (
--
CREATE SEQUENCE public.settings_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -2028,6 +2067,7 @@ CREATE TABLE public.step_assets (
--
CREATE SEQUENCE public.step_assets_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -2058,6 +2098,7 @@ CREATE TABLE public.step_tables (
--
CREATE SEQUENCE public.step_tables_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -2096,6 +2137,7 @@ CREATE TABLE public.steps (
--
CREATE SEQUENCE public.steps_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -2170,6 +2212,7 @@ CREATE TABLE public.tables (
--
CREATE SEQUENCE public.tables_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -2205,6 +2248,7 @@ CREATE TABLE public.tags (
--
CREATE SEQUENCE public.tags_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -2257,6 +2301,7 @@ ALTER SEQUENCE public.team_repositories_id_seq OWNED BY public.team_repositories
--
CREATE SEQUENCE public.teams_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -2288,6 +2333,7 @@ CREATE TABLE public.temp_files (
--
CREATE SEQUENCE public.temp_files_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -2323,6 +2369,7 @@ CREATE TABLE public.tiny_mce_assets (
--
CREATE SEQUENCE public.tiny_mce_assets_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -2354,6 +2401,7 @@ CREATE TABLE public.tokens (
--
CREATE SEQUENCE public.tokens_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -2387,6 +2435,7 @@ CREATE TABLE public.user_identities (
--
CREATE SEQUENCE public.user_identities_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -2420,6 +2469,7 @@ CREATE TABLE public.user_my_modules (
--
CREATE SEQUENCE public.user_my_modules_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -2453,6 +2503,7 @@ CREATE TABLE public.user_notifications (
--
CREATE SEQUENCE public.user_notifications_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -2487,6 +2538,7 @@ CREATE TABLE public.user_projects (
--
CREATE SEQUENCE public.user_projects_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -2540,6 +2592,7 @@ ALTER SEQUENCE public.user_system_notifications_id_seq OWNED BY public.user_syst
--
CREATE SEQUENCE public.user_teams_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -2598,6 +2651,7 @@ CREATE TABLE public.users (
--
CREATE SEQUENCE public.users_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -2664,6 +2718,7 @@ CREATE TABLE public.wopi_actions (
--
CREATE SEQUENCE public.wopi_actions_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -2695,6 +2750,7 @@ CREATE TABLE public.wopi_apps (
--
CREATE SEQUENCE public.wopi_apps_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -2728,6 +2784,7 @@ CREATE TABLE public.wopi_discoveries (
--
CREATE SEQUENCE public.wopi_discoveries_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
@ -2760,6 +2817,7 @@ CREATE TABLE public.zip_exports (
--
CREATE SEQUENCE public.zip_exports_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE