Skip to content

Commit

Permalink
Only group if elements are on the same day
Browse files Browse the repository at this point in the history
  • Loading branch information
bosschaert committed Mar 22, 2024
1 parent 7e24645 commit b10f165
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
45 changes: 23 additions & 22 deletions blocks/edit/da-versions/da-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,10 @@ export default class DaVersions extends LitElement {
li.classList.add('auditlog-expanded');
}

const lis = li.parentNode.querySelectorAll('li');

let found = false;
for (let i = 0; i < lis.length; i += 1) {
if (lis[i].id === li.id) {
found = true;
continue;
}
if (found && (lis[i].id || lis[i].dataset.href)) {
// Found the next non-hidden ID, we are done.
return;
}
if (found) {
lis[i].classList = newClass;
}
}
const lis = li.parentNode.querySelectorAll(`li[data-parent="${li.id}"`);
lis.forEach((l) => {
l.classList = newClass;
});
}

versionSelected(event) {
Expand All @@ -97,30 +85,43 @@ export default class DaVersions extends LitElement {

for (let i = start; i < end; i += 1) {
list[i].authors.forEach((e) => authors.add(e));
list[i].detail = true;
list[i].parent = agg.aggregateID;
}
agg.authors = [...authors];

list.splice(start, 0, agg);
}

sameDays(d1, d2) {
const ds1 = new Date(d1).toLocaleDateString([], { dateStyle: 'short' });
const ds2 = new Date(d2).toLocaleDateString([], { dateStyle: 'short' });
return ds1 === ds2;
}

aggregateList(list) {
let noResStart;
for (let i = 0; i < list.length; i += 1) {
if (!list[i].resource && noResStart === undefined) {
noResStart = i;
}

if (list[i].resource && noResStart !== undefined) {
const sameDays = this.sameDays(list[noResStart].timestamp, list[i].timestamp);
if (noResStart !== undefined && (list[i].resource || !sameDays)) {
if (i - noResStart > 1) {
// only if more than 1 element
this.insertAggregate(list, noResStart, i);
// Increase i with 1 as we added an element
i += 1;
}
noResStart = undefined;

if (!sameDays) {
noResStart = i;
} else {
noResStart = undefined;
}
}

// This is if it's at the end of the list
if (i === list.length - 1 && noResStart !== undefined) {
if (i - noResStart >= 1) {
this.insertAggregate(list, noResStart, i + 1);
Expand Down Expand Up @@ -171,11 +172,11 @@ export default class DaVersions extends LitElement {
}

versions.push(html`
<li tabindex="1" data-href="${ifDefined(verURL)}"
<li tabindex="1" data-href="${ifDefined(verURL)}" data-parent="${ifDefined(l.parent)}"
id=${ifDefined(l.aggregateID)}
class="${l.detail ? 'auditlog-hidden' : ''}">
class="${l.parent ? 'auditlog-hidden' : ''}">
${fromDate}${toDate}
<br/>${l.authors.join(', ')}</li>`);
<br/>${l.authors.join(', ')} ${l.aggregatedTo ? '...' : ''}</li>`);
}
return versions;
}
Expand Down
10 changes: 9 additions & 1 deletion mock-versions/list/bosschaert/da-aem-boilerplate/blah3.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@
"timestamp": 1711037201100,
"authors": ["Karl Pauls", "Anonymous"]
},
{
"timestamp": 1710912809000,
"authors": ["Karl Pauls"]
},
{
"timestamp": 1710912300000,
"authors": ["Karl Pauls"]
},
{
"timestamp": 1710892800000,
"authors": ["Chris Millar"],
"resource": "/mock-versions/resources/72398245211/1.html"
},
{
"timestamp": 1710891802000,
"timestamp": 1700892802000,
"authors": ["Anonymous"]
},
{
Expand Down

0 comments on commit b10f165

Please sign in to comment.