From 0d8a5800f615ac7678efb56545d85fd164450e59 Mon Sep 17 00:00:00 2001 From: agbilotia1998 Date: Wed, 17 Jan 2018 01:05:06 +0530 Subject: [PATCH 1/2] Fix(Area field of editor not getting edited):Area field of editor getting edited. The areaId now is been sent as data to server instead of null. Fixes #BB234 --- src/client/components/forms/profile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/components/forms/profile.js b/src/client/components/forms/profile.js index 3347b9e9a3..eb2fea4d1c 100644 --- a/src/client/components/forms/profile.js +++ b/src/client/components/forms/profile.js @@ -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, From ce34fbe14bdfd57c8bb7d6ab957a2395612e5a98 Mon Sep 17 00:00:00 2001 From: Akhilesh Kumar Date: Fri, 23 Feb 2018 22:48:56 +0530 Subject: [PATCH 2/2] Add(Statistics Page): Initial statistics page with top 10 editors --- scripts/build-client-js.sh | 2 + scripts/watch-client-js.sh | 2 + src/client/components/pages/index.js | 15 +++- src/client/components/pages/statistics.js | 96 +++++++++++++++++++++++ src/client/controllers/statistics.js | 34 ++++++++ src/server/routes.js | 2 + src/server/routes/statistics.js | 69 ++++++++++++++++ 7 files changed, 217 insertions(+), 3 deletions(-) create mode 100644 src/client/components/pages/statistics.js create mode 100644 src/client/controllers/statistics.js create mode 100644 src/server/routes/statistics.js diff --git a/scripts/build-client-js.sh b/scripts/build-client-js.sh index 6d83d74301..afcbf26811 100755 --- a/scripts/build-client-js.sh +++ b/scripts/build-client-js.sh @@ -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 \ @@ -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 diff --git a/scripts/watch-client-js.sh b/scripts/watch-client-js.sh index 95c4f69c86..e985025705 100755 --- a/scripts/watch-client-js.sh +++ b/scripts/watch-client-js.sh @@ -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 \ @@ -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 diff --git a/src/client/components/pages/index.js b/src/client/components/pages/index.js index a1591a4612..e6fe1caf76 100644 --- a/src/client/components/pages/index.js +++ b/src/client/components/pages/index.js @@ -91,7 +91,7 @@ class IndexPage extends React.Component { - + +

diff --git a/src/client/components/pages/statistics.js b/src/client/components/pages/statistics.js new file mode 100644 index 0000000000..4c1e970472 --- /dev/null +++ b/src/client/components/pages/statistics.js @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2018 Akhilesh Kumar + * + * 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 ( +
+
+

Top 10 Editors

+
+ + + + + + + + + + { + topEditors.map((entity, i) => ( + + + + + + )) + } + +
#Editor's NameTotal Revisions
{i + 1} + + {entity.name} + + {entity.totalRevisions}
+
+ ); + } + + render() { + const {topEditors} = this.props; + return ( +
+ Statistics of BookBrainz + {topEditors.length && +
+ {this.renderTopEditorsTable(topEditors)} +
+ } +
+ ); + } +} + +StatisticsPage.displayName = 'StatisticsPage'; +StatisticsPage.propTypes = { + topEditors: PropTypes.array.isRequired +}; + +export default StatisticsPage; diff --git a/src/client/controllers/statistics.js b/src/client/controllers/statistics.js new file mode 100644 index 0000000000..85b1c74eba --- /dev/null +++ b/src/client/controllers/statistics.js @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2018 Akhilesh Kumar + * + * 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 = ( + + + +); + +ReactDOM.hydrate(markup, document.getElementById('target')); diff --git a/src/server/routes.js b/src/server/routes.js index 193f654bda..20e4fec9b3 100644 --- a/src/server/routes.js +++ b/src/server/routes.js @@ -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'; @@ -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) { diff --git a/src/server/routes/statistics.js b/src/server/routes/statistics.js new file mode 100644 index 0000000000..7b7e9e11f3 --- /dev/null +++ b/src/server/routes/statistics.js @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2018 Akhilesh Kumar + * + * 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( + + + + ); + res.render('target', { + markup, + props: escapeProps(props), + script: '/js/statistics.js', + title: 'Statistics' + }); + }); +}); + +export default router;