Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/client/components/request-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class RequestForm extends Component {

if(titleEl){
focusDomElement(titleEl);
}
}
}, 50);

this.onCloseCTA = () => this.reset();
this.onCloseCTA = () => {};
this.onOpenCTA = () => this.focusTitle();
}

Expand Down
39 changes: 38 additions & 1 deletion src/server/routes/api/document/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,43 @@ const generateSitemap = () => {
);
};

/**
* Create a new, blank document JSON representation, with the same format and caveats
* as the POST /api/document/ route.
*/
const blankDocumentJson = () => {
const secret = uuid();
const handleDocCreation = ({ docDb, eleDb }) => {
const id = undefined;
const provided = {};
return createDoc({ docDb, eleDb, id, secret, provided });
};
const setStatus = async doc => {
await doc.initiate();
return doc;
};
const stubArticle = async doc => {
const article = createPubmedArticle({});
const error = new ArticleIDError('Blank paperId');
await doc.article( article );
await doc.issues({ paperId: { error, message: error.message } });
return doc;
};
const stubCorrespondence = async doc => {
const error = new EmailError('Blank email');
await doc.issues({ authorEmail: { error, message: error.message } });
return doc;
};

return tryPromise( () => createSecret({ secret }) )
.then( loadTables )
.then( handleDocCreation )
.then( setStatus )
.then( stubArticle )
.then( stubCorrespondence )
.then( getDocJson );
};

/**
* @swagger
*
Expand Down Expand Up @@ -2569,7 +2606,7 @@ const getRelatedPapersForNetwork = async doc => {
};

export default http;
export { getDocumentJson,
export { getDocumentJson, blankDocumentJson,
loadTables, loadDoc, fillDocArticle, updateRelatedPapers,
fillDocAuthorProfiles,
generateSitemap,
Expand Down
12 changes: 10 additions & 2 deletions src/server/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express from 'express';
import { generateSitemap, getDocumentJson } from './api/document';
import { generateSitemap, getDocumentJson, blankDocumentJson } from './api/document';
import { TWITTER_ACCOUNT_NAME, BASE_URL, EMAIL_ADDRESS_INFO, NODE_ENV, GTM_ID } from '../../config';

const http = express.Router();
Expand All @@ -18,9 +18,16 @@ const getDocumentPage = function(req, res) {
);
};

const newDocumentPage = function(req, res) {
( blankDocumentJson()
.then( doc => res.redirect( 302, doc.privateUrl ))
.catch( () => res.render( '404', { EMAIL_ADDRESS_INFO } ) )
);
};

http.get('/robots.txt', function( req, res ) {
res.set('Content-Type', 'text/plain');
const text = `User-agent: *\nAllow: /\n\nSitemap: ${BASE_URL}/sitemap.xml`;
const text = `User-agent: *\nAllow: /\nDisallow: /document/new\n\nSitemap: ${BASE_URL}/sitemap.xml`;
res.send( text );
});

Expand All @@ -31,6 +38,7 @@ http.get('/sitemap.xml', function( req, res, next ) {
.catch( next );
});

http.get('/document/new', newDocumentPage);
http.get('/document/:id/:secret', getDocumentPage);
http.get('/document/:id', getDocumentPage);

Expand Down