script.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. class StatisticsPage {
  2. constructor() {
  3. this.userMode = StatisticsUser != null;
  4. }
  5. openSocket() {
  6. this.socket = new Socket('/ws').onMessage(this.onSocketMessage.bind(this));
  7. }
  8. onSocketMessage(e) {
  9. this.statistics.load();
  10. }
  11. loadDocumentedInfo() {
  12. fetch('/docinfo', {
  13. method: 'POST'
  14. }).then(res => res.json()).then((res) => {
  15. const container = DOM.get('#statistics>.content>.documented-info-content');
  16. const table = DOM.create({ tag: DOM.Tags.Table }, container);
  17. const headers = DOM.create({ tag: DOM.Tags.Tr }, table);
  18. const tbody = DOM.create({ tag: DOM.Tags.Tbody }, table);
  19. DOM.create({ tag: DOM.Tags.Th, innerHTML: 'Repository' }, headers);
  20. DOM.create({ tag: DOM.Tags.Th, innerHTML: 'Status' }, headers);
  21. for(let root of Object.keys(res)) {
  22. const row = DOM.create({ tag: DOM.Tags.Tr }, tbody);
  23. DOM.create({ tag: DOM.Tags.Td, innerHTML: root }, row);
  24. DOM.create({ tag: DOM.Tags.Td, innerHTML: `${Math.round(res[root]['documented']/res[root]['documentable'] * 10000) / 100}%` }, row);
  25. }
  26. });
  27. }
  28. start() {
  29. this.openSocket();
  30. this.statistics = Statistics.init(DOM.get('#statistics>.content>.statistics-content'), this.userMode ? Statistics.Modes.USER : Statistics.Modes.ALL);
  31. if(!this.userMode)
  32. this.loadDocumentedInfo();
  33. return this;
  34. }
  35. }
  36. window_.on('load', (e) => {
  37. window.page = new StatisticsPage().start();
  38. });