stats_view.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. const { div, h2, p, section, button, form, input, ul, li, a, h3, span, strong } = require("../server/node_modules/hyperaxe");
  2. const { template, i18n } = require('./main_views');
  3. exports.statsView = (stats, filter) => {
  4. const title = i18n.statsTitle;
  5. const description = i18n.statsDescription;
  6. const modes = ['ALL', 'MINE', 'TOMBSTONE'];
  7. const types = [
  8. 'bookmark', 'event', 'task', 'votes', 'report', 'feed',
  9. 'image', 'audio', 'video', 'document', 'transfer', 'post', 'tribe', 'market'
  10. ];
  11. const totalContent = types.reduce((sum, t) => sum + (stats.content[t] || 0), 0);
  12. const totalOpinions = types.reduce((sum, t) => sum + (stats.opinions[t] || 0), 0);
  13. const blockStyle = 'padding:16px;border:1px solid #ddd;border-radius:8px;margin-bottom:24px;';
  14. return template(
  15. title,
  16. section(
  17. div({ class: 'tags-header' },
  18. h2(title),
  19. p(description)
  20. ),
  21. div({ class: 'mode-buttons', style: 'display:grid;grid-template-columns:repeat(auto-fit,minmax(120px,1fr));gap:16px;margin-bottom:24px;' },
  22. modes.map(m =>
  23. form({ method: 'GET', action: '/stats' },
  24. input({ type: 'hidden', name: 'filter', value: m }),
  25. button({ type: 'submit', class: filter === m ? 'filter-btn active' : 'filter-btn' }, i18n[m + 'Button'])
  26. )
  27. )
  28. ),
  29. section(
  30. div({ style: 'background-color:#f8f9fa; padding:24px; border-radius:8px; border:1px solid #e0e0e0; box-shadow:0 2px 8px rgba(0,0,0,0.1);' },
  31. h3({ style: 'font-size:18px; color:#555; margin:8px 0;' }, `${i18n.statsCreatedAt}: `, span({ style: 'color:#888;' }, stats.createdAt)),
  32. h3({ style: 'font-size:18px; color:#555; margin:8px 0; font-weight:600;' }, a({ class: "user-link", href: `/author/${encodeURIComponent(stats.id)}`, style: 'color:#007bff; text-decoration:none;' }, stats.id)),
  33. div({ style: 'margin-bottom:16px;' },
  34. ul({ style: 'list-style-type:none; padding:0; margin:0;' },
  35. li({ style: 'font-size:18px; color:#555; margin:8px 0;' },
  36. `${i18n.statsBlobsSize}: `,
  37. span({ style: 'color:#888;' }, stats.statsBlobsSize)
  38. ),
  39. li({ style: 'font-size:18px; color:#555; margin:8px 0;' },
  40. `${i18n.statsBlockchainSize}: `,
  41. span({ style: 'color:#888;' }, stats.statsBlockchainSize)
  42. ),
  43. li({ style: 'font-size:18px; color:#555; margin:8px 0;' },
  44. strong(`${i18n.statsSize}: `,
  45. span({ style: 'color:#888;' },
  46. span({ style: 'color:#555;' }, stats.folderSize)
  47. )
  48. )
  49. )
  50. )
  51. )
  52. ),
  53. filter === 'ALL'
  54. ? div({ class: 'stats-container' }, [
  55. div({ style: blockStyle },
  56. h2(`${i18n.statsTotalInhabitants}: ${stats.inhabitants}`)
  57. ),
  58. div({ style: blockStyle },
  59. h2(`${i18n.statsDiscoveredTribes}: ${stats.content.tribe}`)
  60. ),
  61. div({ style: blockStyle },
  62. h2(`${i18n.statsDiscoveredMarket}: ${stats.content.market}`)
  63. ),
  64. div({ style: blockStyle },
  65. h2(`${i18n.statsNetworkOpinions}: ${totalOpinions}`),
  66. ul(types.map(t =>
  67. stats.opinions[t] > 0
  68. ? li(`${i18n[`stats${t.charAt(0).toUpperCase() + t.slice(1)}`]}: ${stats.opinions[t]}`)
  69. : null
  70. ).filter(Boolean))
  71. ),
  72. div({ style: blockStyle },
  73. h2(`${i18n.statsNetworkContent}: ${totalContent}`),
  74. ul(types.map(t =>
  75. stats.content[t] > 0
  76. ? li(`${i18n[`stats${t.charAt(0).toUpperCase() + t.slice(1)}`]}: ${stats.content[t]}`)
  77. : null
  78. ).filter(Boolean))
  79. )
  80. ])
  81. : filter === 'MINE'
  82. ? div({ class: 'stats-container' }, [
  83. div({ style: blockStyle },
  84. h2(`${i18n.statsDiscoveredTribes}: ${stats.memberTribes.length}`),
  85. ul(stats.memberTribes.map(name => li(name)))
  86. ),
  87. div({ style: blockStyle },
  88. h2(`${i18n.statsYourMarket}: ${stats.content.market}`)
  89. ),
  90. div({ style: blockStyle },
  91. h2(`${i18n.statsYourOpinions}: ${totalOpinions}`),
  92. ul(types.map(t =>
  93. stats.opinions[t] > 0
  94. ? li(`${i18n[`stats${t.charAt(0).toUpperCase() + t.slice(1)}`]}: ${stats.opinions[t]}`)
  95. : null
  96. ).filter(Boolean))
  97. ),
  98. div({ style: blockStyle },
  99. h2(`${i18n.statsYourContent}: ${totalContent}`),
  100. ul(types.map(t =>
  101. stats.content[t] > 0
  102. ? li(`${i18n[`stats${t.charAt(0).toUpperCase() + t.slice(1)}`]}: ${stats.content[t]}`)
  103. : null
  104. ).filter(Boolean))
  105. )
  106. ])
  107. : div({ class: 'stats-container' }, [
  108. div({ style: blockStyle },
  109. h2(`${i18n.TOMBSTONEButton}: ${stats.userTombstoneCount}`)
  110. )
  111. ])
  112. )
  113. )
  114. );
  115. };