Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
218 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright (C) 2018 Akhilesh Kumar <akhilesh5991@gmail.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
import * as bootstrap from 'react-bootstrap'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
|
||
const {PageHeader, Table} = bootstrap; | ||
|
||
/** | ||
* Renders the document and displays the 'Statistics' page. | ||
* @returns {ReactElement} a HTML document which displays the Statistics | ||
* page | ||
*/ | ||
class StatisticsPage extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.renderTopEditorsTable = this.renderTopEditorsTable.bind(this); | ||
} | ||
|
||
renderTopEditorsTable(topEditors) { | ||
return ( | ||
<div> | ||
<div> | ||
<h2 className="text-center">Top 10 Editors</h2> | ||
</div> | ||
<Table | ||
bordered | ||
striped | ||
> | ||
<thead> | ||
<tr> | ||
<th>#</th> | ||
<th>Editor's Name</th> | ||
<th>Total Revisions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{ | ||
topEditors.map((entity, i) => ( | ||
<tr key={entity.id}> | ||
<td>{i + 1}</td> | ||
<td> | ||
<a | ||
href={`/editor/${entity.id}`} | ||
> | ||
{entity.name} | ||
</a> | ||
</td> | ||
<td>{entity.totalRevisions}</td> | ||
</tr> | ||
)) | ||
} | ||
</tbody> | ||
</Table> | ||
</div> | ||
); | ||
} | ||
|
||
render() { | ||
const {topEditors} = this.props; | ||
return ( | ||
<div> | ||
<PageHeader>Statistics of BookBrainz</PageHeader> | ||
{topEditors.length && | ||
<div> | ||
{this.renderTopEditorsTable(topEditors)} | ||
</div> | ||
} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
StatisticsPage.displayName = 'StatisticsPage'; | ||
StatisticsPage.propTypes = { | ||
topEditors: PropTypes.array.isRequired | ||
}; | ||
|
||
export default StatisticsPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (C) 2018 Akhilesh Kumar <akhilesh5991@gmail.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
import Layout from '../containers/layout'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import StatisticsPage from '../components/pages/statistics'; | ||
import {extractLayoutProps} from '../helpers/props'; | ||
|
||
|
||
const propsTarget = document.getElementById('props'); | ||
const props = propsTarget ? JSON.parse(propsTarget.innerHTML) : {}; | ||
const markup = ( | ||
<Layout {...extractLayoutProps(props)}> | ||
<StatisticsPage topEditors={props.topEditors}/> | ||
</Layout> | ||
); | ||
|
||
ReactDOM.hydrate(markup, document.getElementById('target')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (C) 2018 Akhilesh Kumar <akhilesh5991@gmail.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
import * as propHelpers from '../../client/helpers/props'; | ||
import {escapeProps, generateProps} from '../helpers/props'; | ||
import Layout from '../../client/containers/layout'; | ||
import React from 'react'; | ||
import ReactDOMServer from 'react-dom/server'; | ||
import StatisticsPage from '../../client/components/pages/statistics'; | ||
import _ from 'lodash'; | ||
import express from 'express'; | ||
|
||
|
||
const router = express.Router(); | ||
|
||
/* Get Statistics Page */ | ||
router.get('/', (req, res) => { | ||
const {Editor} = req.app.locals.orm; | ||
|
||
/* | ||
* Here We are fetching top 10 Edirors | ||
* from database on Basis of totalRevisions | ||
*/ | ||
const getTopEditors = new Editor() | ||
.query((q) => | ||
q.orderBy(_.snakeCase('totalRevisions'), 'desc') | ||
.limit(10)) | ||
.fetchAll() | ||
.then((collection) => | ||
collection.models.map((model) => | ||
model.attributes | ||
)); | ||
|
||
getTopEditors.then((topEditors) => { | ||
const props = generateProps(req, res, { | ||
topEditors | ||
}); | ||
const markup = ReactDOMServer.renderToString( | ||
<Layout {...propHelpers.extractLayoutProps(props)}> | ||
<StatisticsPage | ||
topEditors={props.topEditors} | ||
/> | ||
</Layout> | ||
); | ||
res.render('target', { | ||
markup, | ||
props: escapeProps(props), | ||
script: '/js/statistics.js', | ||
title: 'Statistics' | ||
}); | ||
}); | ||
}); | ||
|
||
export default router; |