Skip to content

Commit

Permalink
Merge ce34fbe into 876e59a
Browse files Browse the repository at this point in the history
  • Loading branch information
akhilesh26 committed Feb 23, 2018
2 parents 876e59a + ce34fbe commit b136d13
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 4 deletions.
2 changes: 2 additions & 0 deletions scripts/build-client-js.sh
Expand Up @@ -12,6 +12,7 @@ cross-env BABEL_ENV="browser" browserify -t [babelify] \
registrationDetails.js \
revision.js \
search.js \
statistics.js \
-p [ factor-bundle \
-o ../../../static/js/entity-editor.js \
-o ../../../static/js/editor/edit.js \
Expand All @@ -23,5 +24,6 @@ cross-env BABEL_ENV="browser" browserify -t [babelify] \
-o ../../../static/js/registrationDetails.js \
-o ../../../static/js/revision.js \
-o ../../../static/js/search.js \
-o ../../../static/js/statistics.js \
] > ../../../static/js/bundle.js
popd
2 changes: 2 additions & 0 deletions scripts/watch-client-js.sh
Expand Up @@ -12,6 +12,7 @@ cross-env BABEL_ENV="browser" watchify -t [babelify] \
registrationDetails.js \
revision.js \
search.js \
statistics.js \
-p [ factor-bundle \
-o ../../../static/js/entity-editor.js \
-o ../../../static/js/editor/edit.js \
Expand All @@ -23,5 +24,6 @@ cross-env BABEL_ENV="browser" watchify -t [babelify] \
-o ../../../static/js/registrationDetails.js \
-o ../../../static/js/revision.js \
-o ../../../static/js/search.js \
-o ../../../static/js/statistics.js \
] -o ../../../static/js/bundle.js -dv
popd
2 changes: 1 addition & 1 deletion src/client/components/forms/profile.js
Expand Up @@ -71,7 +71,7 @@ class ProfileForm extends React.Component {
const birthDate = this.birthDate.getValue();

const data = {
areaId: area ? parseInt(area.id, 10) : null,
areaId: area ? parseInt(area, 10) : null,
bio,
birthDate,
genderId: gender ? parseInt(gender, 10) : null,
Expand Down
15 changes: 12 additions & 3 deletions src/client/components/pages/index.js
Expand Up @@ -91,7 +91,7 @@ class IndexPage extends React.Component {
</div>
</form>
<Row className="margin-top-4">
<Col sm={4}>
<Col sm={3}>
<Button
block
bsSize="large"
Expand All @@ -100,7 +100,7 @@ class IndexPage extends React.Component {
About
</Button>
</Col>
<Col sm={4}>
<Col sm={3}>
<Button
block
bsSize="large"
Expand All @@ -109,7 +109,7 @@ class IndexPage extends React.Component {
Contribute
</Button>
</Col>
<Col sm={4}>
<Col sm={3}>
<Button
block
bsSize="large"
Expand All @@ -118,6 +118,15 @@ class IndexPage extends React.Component {
Develop
</Button>
</Col>
<Col sm={3}>
<Button
block
bsSize="large"
href="/statistics"
>
Statistics
</Button>
</Col>
</Row>
<div className="margin-top-3">
<h4 className="contact-text">
Expand Down
96 changes: 96 additions & 0 deletions src/client/components/pages/statistics.js
@@ -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&apos;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;
34 changes: 34 additions & 0 deletions src/client/controllers/statistics.js
@@ -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'));
2 changes: 2 additions & 0 deletions src/server/routes.js
Expand Up @@ -27,6 +27,7 @@ import publisherRouter from './routes/entity/publisher';
import registerRouter from './routes/register';
import revisionRouter from './routes/revision';
import searchRouter from './routes/search';
import statisticsRouter from './routes/statistics';
import workRouter from './routes/entity/work';


Expand All @@ -35,6 +36,7 @@ function initRootRoutes(app) {
app.use('/', authRouter);
app.use('/search', searchRouter);
app.use('/register', registerRouter);
app.use('/statistics', statisticsRouter);
}

function initPublicationRoutes(app) {
Expand Down
69 changes: 69 additions & 0 deletions src/server/routes/statistics.js
@@ -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;

0 comments on commit b136d13

Please sign in to comment.