Skip to content

Commit 3299829

Browse files
committed
feat: support showing wrapped of past years
Implements #4
1 parent c527e42 commit 3299829

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

octoprint_wrapped/static/js/wrapped.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ $(function () {
4747
: now.getFullYear() - 1; // already January
4848
const years = self.availableYears();
4949

50-
if (years.indexOf(year) !== -1 && self.withinWrappedSeason()) {
50+
if (years.indexOf(year) !== -1) {
5151
return year;
5252
} else {
5353
return false;
@@ -62,7 +62,14 @@ $(function () {
6262
const year = self.currentWrapped();
6363
if (!year) return false;
6464

65-
return OctoPrint.plugins.wrapped.getYearSvgUrl(year);
65+
return self.svgUrlForYear(year);
66+
});
67+
68+
self.pastYears = ko.pureComputed(() => {
69+
const now = new Date();
70+
const year = now.getFullYear();
71+
const years = self.availableYears();
72+
return years.filter((y) => y < year).sort((a, b) => b - a);
6673
});
6774

6875
self.withinWrappedSeason = ko.pureComputed(() => {
@@ -74,6 +81,10 @@ $(function () {
7481
);
7582
});
7683

84+
self.svgUrlForYear = (year) => {
85+
return OctoPrint.plugins.wrapped.getYearSvgUrl(year);
86+
};
87+
7788
self.requestData = () => {
7889
if (
7990
!self.loginState.hasPermission(

octoprint_wrapped/templates/wrapped_about.jinja2

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@
1919
</div>
2020
<p data-bind="visible: !withinWrappedSeason()">
2121
{% trans %}
22-
Nothing to see here at the moment! Come back between December 1st and January 10th!
22+
Nothing to see for this year yet! Come back between December 1st and January 10th!
2323
{% endtrans %}
2424
</p>
25+
26+
<div id="plugin_wrapped_pastyears"
27+
data-bind="visible: pastYears().length > 0">
28+
<h4>
29+
<a href="javascript:void()"
30+
data-bind="toggleContent: { class: 'fa-caret-right fa-caret-down', parent: '#plugin_wrapped_pastyears', container: '.hide' }"><i class="fas fa-caret-right"></i> {{ _("Past years") }}</a>
31+
</h4>
32+
33+
<div class="hide" data-bind="foreach: pastYears">
34+
<h5 data-bind="text: $data"></h5>
35+
<img data-bind="src.svgtopng: $root.svgUrlForYear($data)"
36+
alt="OctoPrint Wrapped sharepic"
37+
width="400"
38+
height="400" />
39+
</div>
40+
41+
</div>

0 commit comments

Comments
 (0)