(source = 'all')
| 572 | } |
| 573 | |
| 574 | async listCssCategories(source = 'all') { |
| 575 | debugLog(`🏷️ Listing CSS categories (source: ${source})`); |
| 576 | |
| 577 | return new Promise((resolve, reject) => { |
| 578 | let promises = []; |
| 579 | |
| 580 | // iCSS categories |
| 581 | if (source === 'all' || source === 'icss') { |
| 582 | promises.push( |
| 583 | new Promise((resolve, reject) => { |
| 584 | this.db.all( |
| 585 | 'SELECT labels, COUNT(*) as count FROM issues WHERE labels IS NOT NULL GROUP BY labels', |
| 586 | (err, rows) => { |
| 587 | if (err) { |
| 588 | reject(err); |
| 589 | return; |
| 590 | } |
| 591 | |
| 592 | const categoryMap = new Map(); |
| 593 | rows.forEach(row => { |
| 594 | if (row.labels) { |
| 595 | const labels = JSON.parse(row.labels); |
| 596 | labels.forEach(label => { |
| 597 | categoryMap.set(label, (categoryMap.get(label) || 0) + row.count); |
| 598 | }); |
| 599 | } |
| 600 | }); |
| 601 | |
| 602 | const categories = Array.from(categoryMap.entries()) |
| 603 | .sort((a, b) => b[1] - a[1]) |
| 604 | .map(([label, count]) => ({ |
| 605 | label, |
| 606 | count, |
| 607 | source: 'iCSS', |
| 608 | type: 'article' |
| 609 | })); |
| 610 | |
| 611 | resolve(categories); |
| 612 | } |
| 613 | ); |
| 614 | }) |
| 615 | ); |
| 616 | } |
| 617 | |
| 618 | // CSS-Inspiration categories |
| 619 | if (source === 'all' || source === 'inspiration') { |
| 620 | promises.push( |
| 621 | new Promise((resolve, reject) => { |
| 622 | this.db.all( |
| 623 | 'SELECT category, COUNT(*) as count FROM css_inspiration GROUP BY category ORDER BY count DESC', |
| 624 | (err, rows) => { |
| 625 | if (err) { |
| 626 | reject(err); |
| 627 | return; |
| 628 | } |
| 629 | |
| 630 | const categories = rows.map(row => ({ |
| 631 | label: row.category, |
no test coverage detected