Skip to content

Commit f20a5eb

Browse files
author
benpaquier
committed
feat: display detailled missions in a tooltip on calendar view
1 parent 5000a5c commit f20a5eb

File tree

9 files changed

+133
-46
lines changed

9 files changed

+133
-46
lines changed

src/Domain/FairCalendar/FairCalendarOverviewFactory.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ describe('FairCalendarOverviewFactory', () => {
9898
);
9999

100100
const expectedResult: ICalendarOverview = {
101-
mission: 1.57,
102-
dojo: 0.25,
103-
formationConference: 1,
104-
leave: 1,
105-
support: 0.5,
106-
other: 0.5
101+
mission: { days: 1.57, details: [{ days: 1.57, label: 'RadioFrance' }] },
102+
dojo: { days: 0.25 },
103+
formationConference: { days: 1 },
104+
leave: { days: 1 },
105+
support: { days: 0.5 },
106+
other: { days: 0.5 }
107107
};
108108

109109
expect(

src/Domain/FairCalendar/FairCalendarOverviewFactory.ts

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { FairCalendarView } from 'src/Application/FairCalendar/View/FairCalendar
33
import { CooperativeNotFoundException } from '../Settings/Repository/CooperativeNotFoundException';
44
import { ICooperativeRepository } from '../Settings/Repository/ICooperativeRepository';
55
import { ICalendarOverview } from './ICalendarOverview';
6+
import { EventType } from './Event.entity';
67

78
export class FairCalendarOverviewFactory {
89
constructor(
@@ -17,20 +18,51 @@ export class FairCalendarOverviewFactory {
1718
}
1819

1920
const overviewInDays: ICalendarOverview = {
20-
mission: 0,
21-
dojo: 0,
22-
formationConference: 0,
23-
leave: 0,
24-
support: 0,
25-
other: 0
21+
mission: {
22+
days: 0,
23+
details: []
24+
},
25+
dojo: {
26+
days: 0
27+
},
28+
formationConference: {
29+
days: 0
30+
},
31+
leave: {
32+
days: 0
33+
},
34+
support: {
35+
days: 0
36+
},
37+
other: {
38+
days: 0
39+
}
2640
};
2741

28-
for (const { time, type: itemType } of items) {
42+
for (const { time, type: itemType, project } of items) {
2943
const type = itemType.startsWith('leave_') ? 'leave' : itemType;
3044
const days = time / cooperative.getDayDuration();
3145

32-
overviewInDays[type] =
33-
Math.round((overviewInDays[type] + days) * 100) / 100;
46+
overviewInDays[type].days =
47+
Math.round((overviewInDays[type].days + days) * 100) / 100;
48+
49+
if (type === EventType.MISSION) {
50+
const missionDetail = overviewInDays[type].details.find(
51+
({ label }) => label === project.name
52+
);
53+
54+
if (missionDetail) {
55+
missionDetail.days =
56+
Math.round(
57+
(missionDetail.days + Math.round(days * 100) / 100) * 100
58+
) / 100;
59+
} else {
60+
overviewInDays[type].details.push({
61+
days,
62+
label: project.name
63+
});
64+
}
65+
}
3466
}
3567

3668
return overviewInDays;
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
export interface ICalendarOverview {
2-
mission: number;
3-
dojo: number;
4-
formationConference: number;
5-
leave: number;
6-
support: number;
7-
other: number;
2+
mission: {
3+
days: number;
4+
details: {
5+
days: number;
6+
label: string;
7+
}[];
8+
};
9+
dojo: { days: number };
10+
formationConference: { days: number };
11+
leave: { days: number };
12+
support: { days: number };
13+
other: { days: number };
814
}

src/Infrastructure/FairCalendar/Table/FairCalendarOverviewTableFactory.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export class FairCalendarOverviewTableFactory {
2626
);
2727
rowBuilder.template('pages/faircalendar/_overview_badge.njk', {
2828
type,
29-
days: overview[type]
29+
days: overview[type].days,
30+
details: overview[type].details
3031
});
3132
}
3233

src/assets/styles/components/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818
@import './shell.css';
1919
@import './table.css';
2020
@import './theme.css';
21+
@import './tooltip.css';

src/assets/styles/components/table.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ table.pc-table {
2525
text-align: left;
2626
}
2727

28+
.pc-table-wrapper-overflow-visible {
29+
overflow-x: visible;
30+
}
31+
2832
.pc-table--center {
2933
text-align: center;
3034
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.tooltip {
2+
position: relative;
3+
cursor: pointer;
4+
}
5+
6+
.tooltip .tooltip-content {
7+
--tooltip-background: var(--background-default);
8+
--tooltip-color: var(--text-default);
9+
10+
position: absolute;
11+
top: calc(100% + var(--w));
12+
left: 50%;
13+
transform: translateX(-50%);
14+
padding: calc(2 * var(--w));
15+
border-radius: var(--badge-radius, calc(1 * var(--w)));
16+
background: var(--tooltip-background);
17+
color: var(--tooltip-color);
18+
text-align: left;
19+
z-index: 10;
20+
display: none;
21+
}
22+
23+
.tooltip:hover .tooltip-content {
24+
display: flex;
25+
flex-direction: column;
26+
gap: var(--w);
27+
}
Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1-
<span class="pc-badge pc-bold" style="--badge-color: var(--event-{{ type }}-text); --badge-background: var(--event-{{ type }}-background)">
1+
{% import 'macros/icons.njk' as icons %}
2+
{% set hasDetails = details.length %}
3+
4+
<div class="{{ 'tooltip' if hasDetails }}">
5+
<span
6+
class="pc-badge pc-bold"
7+
style="--badge-color: var(--event-{{ type }}-text); --badge-background: var(--event-{{ type }}-background)">
28
{{ 'faircalendar-overview-days'|trans({ days: days }) }}
3-
</span>
9+
10+
{% if hasDetails %}
11+
&nbsp;{{ icons.eye() }}
12+
{% endif %}
13+
</span>
14+
15+
{% if hasDetails %}
16+
<ul class="tooltip-content pc-raw-list"
17+
style="--tooltip-color: var(--event-{{ type }}-text); --tooltip-background: var(--event-{{ type }}-background)">
18+
{% for detail in details %}
19+
<li>
20+
<span>{{ detail.label }}</span>
21+
<span class="pc-bold">{{ 'faircalendar-overview-days'|trans({ days: detail.days }) }}</span>
22+
</li>
23+
{% endfor %}
24+
</ul>
25+
{% endif %}
26+
</div>

src/templates/pages/faircalendar/index.njk

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,24 @@
44
{% from 'macros/breadcrumb.njk' import breadcrumb %}
55
{% from './_event_list.njk' import event_list with context %}
66
{% from './_filters_form.njk' import filters_form with context %}
7-
87
{% set title = 'faircalendar-page-title'|trans({ date: date }) %}
9-
108
{% block main %}
11-
<div class="pc-container">
9+
<div class="pc-container">
1210
<pc-frame class="pc-stack" id="faircalendar">
13-
{{ breadcrumb([{ title: title }]) }}
14-
15-
<div class="pc-cluster pc-gap" style="--cluster-justify: space-between; --cluster-align: center">
16-
<h1 class="pc-m" style="--m: 0">
17-
{{ title }}
18-
</h1>
19-
20-
{{ links.add(path('people_leave_requests_add'), text='leave-requests-add-title'|trans) }}
21-
</div>
22-
23-
<div class="pc-with-sidebar pc-with-sidebar-start pc-gap" style="--sidebar-size: 22ch; --non-sidebar-min-size: 80%">
24-
{{ filters_form() }}
25-
26-
<div id="faircalendar" class="pc-stack">
27-
{% table overviewTable, { attr: {class: 'pc-table--center pc-table--no-shadow'} } %}
28-
29-
{{ event_list() }}
30-
</div>
11+
{{ breadcrumb([{ title: title }]) }}
12+
<div class="pc-cluster pc-gap" style="--cluster-justify: space-between; --cluster-align: center">
13+
<h1 class="pc-m" style="--m: 0">
14+
{{ title }}
15+
</h1>
16+
{{ links.add(path('people_leave_requests_add'), text='leave-requests-add-title'|trans) }}
17+
</div>
18+
<div class="pc-with-sidebar pc-with-sidebar-start pc-gap" style="--sidebar-size: 22ch; --non-sidebar-min-size: 80%">
19+
{{ filters_form() }}
20+
<div id="faircalendar" class="pc-stack">
21+
{% table overviewTable, { attr: {class: 'pc-table--center pc-table--no-shadow pc-table-wrapper-overflow-visible'} } %}
22+
{{ event_list() }}
3123
</div>
24+
</div>
3225
</pc-frame>
33-
</div>
26+
</div>
3427
{% endblock main %}

0 commit comments

Comments
 (0)