Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow collapsing series on a course page #5650

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion app/assets/javascripts/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@
return this._bottom;
}

private get cardId(): string {
return `series-card-${this.id}`;
}

private get card(): HTMLElement {
return document.getElementById(this.cardId);
}

private get scrollspy(): HTMLElement {
const anchor = this.card.querySelector(".anchor");
return document.querySelector(`#scrollspy-nav a[href="#${anchor.id}"]`);
}

static findAll(cardsSelector = ".series.card"): Array<Series> {
const cards = document.querySelectorAll(cardsSelector);
return Array.from(cards, card => new Series(card));
Expand All @@ -79,6 +92,7 @@
this.loading = false;
this._top = card.getBoundingClientRect().top + window.scrollY;
this._bottom = this.top + card.getBoundingClientRect().height;
this.initCollapse();
}

needsLoading(): boolean {
Expand All @@ -93,10 +107,37 @@
if (response.ok) {
eval(await response.text());
this.loading = false;
this.reselect(document.getElementById(`series-card-${this.id}`));
this.reselect(this.card);
}
});
}

collapse(): void {
localStorage.setItem(this.cardId, "collapsed");
this.renderCollapsed();

Check warning on line 117 in app/assets/javascripts/course.ts

View check run for this annotation

Codecov / codecov/patch

app/assets/javascripts/course.ts#L115-L117

Added lines #L115 - L117 were not covered by tests
}

expand(): void {
localStorage.removeItem(this.cardId);
this.renderCollapsed();

Check warning on line 122 in app/assets/javascripts/course.ts

View check run for this annotation

Codecov / codecov/patch

app/assets/javascripts/course.ts#L120-L122

Added lines #L120 - L122 were not covered by tests
}

initCollapse(): void {
this.renderCollapsed();

if (this.loaded) {
const expandButton = this.card.querySelector(".expand-button");
expandButton.addEventListener("click", this.expand.bind(this));
const collapseButton = this.card.querySelector(".collapse-button");
collapseButton.addEventListener("click", this.collapse.bind(this));
}
}

renderCollapsed(): void {
const collapsed = localStorage.getItem(this.cardId) === "collapsed";
this.card.classList.toggle("collapsed", collapsed);
this.scrollspy.classList.toggle("d-none", collapsed);
}
}

function initCourseShow(): void {
Expand Down
45 changes: 45 additions & 0 deletions app/assets/stylesheets/models/series.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,51 @@
.series-icon {
margin-right: 16px;
}

.expand-button {
display: none;
}

&.collapsed {
.card-subtitle {
margin-bottom: 0;
}

.btn-group {
display: none !important;
}

.tab-content {
display: none;
}

.card-actions {
display: none;
}

d-series-icon {
svg {
width: 24px !important;
height: 24px !important;
}
}

h4 {
small {
display: none;
}
}

.series-dropdown {
display: none;
}

.expand-button {
display: block;
margin-top: -7px;
margin-bottom: -9px;
}
}
}

.series-icon {
Expand Down
13 changes: 13 additions & 0 deletions app/views/series/_series.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<%= render partial: 'deadlines/absolute', locals: {deadline: series.deadline, met: user && loaded ? series.completed_before_deadline?(user) : false} %>
</h4>
<div class="flex-spacer"></div>
<button class="btn btn-text expand-button">
<%= t "series.show.expand" %>
</button>
<% if policy(series).statistics? %>
<div id="series-view-<%= series.id %>" class="btn-group btn-toggle nav d-none d-sm-flex" role="tablist">
<button class="btn active" data-bs-target="#series-content-<%= series.id %>" data-bs-toggle="tab" role="tab" title="<%= t("series.show.series_overview") %>">
Expand Down Expand Up @@ -68,6 +71,11 @@
<% end %>
</li>
<% end %>
<li>
<a class="dropdown-item collapse-button">
<i class='mdi mdi-eye-off mdi-18'></i> <%= t "series.show.collapse" %>
</a>
</li>
</ul>
</div>
</div>
Expand Down Expand Up @@ -247,6 +255,11 @@
<% end %>
</li>
<% end %>
<li>
<a class="dropdown-item collapse-button">
<i class='mdi mdi-eye-off mdi-18'></i> <%= t "series.show.collapse" %>
</a>
</li>
</ul>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions config/locales/views/series/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ en:
series_overview: Series overview
apply: apply
hidden_not_registered: You are not registered for this course. You must register before you can start solving the exercises.
collapse: Collapse
expand: Expand
edit:
title: Edit series
add_activities: Add activities
Expand Down
2 changes: 2 additions & 0 deletions config/locales/views/series/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ nl:
series_overview: Reeksoverzicht
apply: toepassen
hidden_not_registered: Je bent niet ingeschreven voor deze cursus. Je kan de oefeningen pas oplossen nadat je je ingeschreven hebt.
collapse: Inklappen
expand: Uitklappen
edit:
title: Reeks bewerken
add_activities: Activiteiten toevoegen
Expand Down