1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-24 06:59:52 +01:00

vue ui bug fix: bugs in capture list on calendar day click

had to add a single-snapshot check for each period of each type: year/month/day/hour, at end of snapshot loop; as all snapshots are now added to the period hierarchy;  bug was that the last period of each type did not have the calculation "isContainsSingleSnapshotOnly" run on it
This commit is contained in:
Ivan Velev 2022-02-02 15:23:53 -08:00
parent 24223bcda5
commit 46cc04bafd
2 changed files with 186 additions and 142 deletions

File diff suppressed because one or more lines are too long

View File

@ -8,24 +8,37 @@ export function PywbData(rawSnaps) {
rawSnaps.forEach((rawSnap, i) => { rawSnaps.forEach((rawSnap, i) => {
const snap = new PywbSnapshot(rawSnap, i); const snap = new PywbSnapshot(rawSnap, i);
let year, month, day, hour, single; let year, month, day, hour, single;
// Year Period
// if year did not exist in "all time", create it
if (!(year = allTimePeriod.getChildById(snap.year))) { if (!(year = allTimePeriod.getChildById(snap.year))) {
if (lastYear) lastYear.checkIfSingleSnapshotOnly(); if (lastYear) lastYear.checkIfSingleSnapshotOnly(); // check last year for containing single snapshot
lastYear = year = new PywbPeriod({type: PywbPeriod.Type.year, id: snap.year}); lastYear = year = new PywbPeriod({type: PywbPeriod.Type.year, id: snap.year});
allTimePeriod.addChild(year); allTimePeriod.addChild(year);
} }
// Month Period
// if month did not exist in "year" period, create it
if (!(month = year.getChildById(snap.month))) { if (!(month = year.getChildById(snap.month))) {
if (lastMonth) lastMonth.checkIfSingleSnapshotOnly(); if (lastMonth) lastMonth.checkIfSingleSnapshotOnly();// check last month for containing single snapshot
lastMonth = month = new PywbPeriod({type: PywbPeriod.Type.month, id: snap.month}); lastMonth = month = new PywbPeriod({type: PywbPeriod.Type.month, id: snap.month});
year.addChild(month); year.addChild(month);
} }
// Day Period
// if day did not exist in "month" period, create it
if (!(day = month.getChildById(snap.day))) { if (!(day = month.getChildById(snap.day))) {
if (lastDay) lastDay.checkIfSingleSnapshotOnly(); if (lastDay) lastDay.checkIfSingleSnapshotOnly(); // check last day for containing single snapshot
lastDay = day = new PywbPeriod({type: PywbPeriod.Type.day, id: snap.day}); lastDay = day = new PywbPeriod({type: PywbPeriod.Type.day, id: snap.day});
month.addChild(day); month.addChild(day);
} }
// Hour Period
const hourValue = Math.ceil((snap.hour + .0001) / (24/8)); // divide day in 4 six-hour periods (aka quarters) const hourValue = Math.ceil((snap.hour + .0001) / (24/8)); // divide day in 4 six-hour periods (aka quarters)
// if hour did not exist in "day" period, create it
if (!(hour = day.getChildById(hourValue))) { if (!(hour = day.getChildById(hourValue))) {
if (lastHour) lastHour.checkIfSingleSnapshotOnly(); if (lastHour) lastHour.checkIfSingleSnapshotOnly(); // check last hour for containing single snapshot
lastHour = hour = new PywbPeriod({type: PywbPeriod.Type.hour, id: hourValue}); lastHour = hour = new PywbPeriod({type: PywbPeriod.Type.hour, id: hourValue});
day.addChild(hour); day.addChild(hour);
} }
@ -41,6 +54,15 @@ export function PywbData(rawSnaps) {
lastSingle = single; lastSingle = single;
snapshots.push(snap); snapshots.push(snap);
// At end of snapshot loop, check period of each type: year/month/day/hour
// as all snapshots are now added to the period hierarchy
if (i === rawSnaps.length - 1) { // is last snapshot
year.checkIfSingleSnapshotOnly();
month.checkIfSingleSnapshotOnly();
day.checkIfSingleSnapshotOnly();
hour.checkIfSingleSnapshotOnly();
}
}); });
this.timeline = allTimePeriod; this.timeline = allTimePeriod;