class StatisticsPage { constructor() { this.userMode = StatisticsUser != null; } openSocket() { this.socket = new Socket('/ws').onMessage(this.onSocketMessage.bind(this)); } onSocketMessage(e) { this.statistics.load(); } loadDocumentedInfo() { fetch('/docinfo', { method: 'POST' }).then(res => res.json()).then((res) => { const container = DOM.get('#statistics>.content>.documented-info-content'); const table = DOM.create({ tag: DOM.Tags.Table }, container); const headers = DOM.create({ tag: DOM.Tags.Tr }, table); const tbody = DOM.create({ tag: DOM.Tags.Tbody }, table); DOM.create({ tag: DOM.Tags.Th, innerHTML: 'Repository' }, headers); DOM.create({ tag: DOM.Tags.Th, innerHTML: 'Status' }, headers); for(let root of Object.keys(res)) { const row = DOM.create({ tag: DOM.Tags.Tr }, tbody); DOM.create({ tag: DOM.Tags.Td, innerHTML: root }, row); DOM.create({ tag: DOM.Tags.Td, innerHTML: `${Math.round(res[root]['documented']/res[root]['documentable'] * 10000) / 100}%` }, row); } }); } start() { this.openSocket(); this.statistics = Statistics.init(DOM.get('#statistics>.content>.statistics-content'), this.userMode ? Statistics.Modes.USER : Statistics.Modes.ALL); if(!this.userMode) this.loadDocumentedInfo(); return this; } } window_.on('load', (e) => { window.page = new StatisticsPage().start(); });