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
6 changes: 5 additions & 1 deletion src/client/components/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import _ from 'lodash';
import { formatDistanceToNow } from 'date-fns';
import queryString from 'query-string';

import Document from '../../model/document';

export const CAROUSEL_CONTENT = {
FIGURE: 'figure',
ABSTRACT: 'abstract'
Expand All @@ -14,6 +16,8 @@ export class Carousel extends Component {
constructor(props){
super(props);

const DOCUMENT_STATUS_FIELDS = Document.statusFields();

this.state = {
pagerLeftAvailable: false,
pagerRightAvailable: false,
Expand All @@ -23,7 +27,7 @@ export class Carousel extends Component {
refresh: props.refresh || (() => { // get all docs from service by default
const url = `/api/document`;
const params = queryString.stringify({
status: ['published'].join(','),
status: [DOCUMENT_STATUS_FIELDS.PUBLIC].join(','),
limit: 20
});
const doFetch = () => fetch(`${url}?${params}`);
Expand Down
6 changes: 3 additions & 3 deletions src/client/components/document-management-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class DocumentManagementDocumentComponent extends React.Component {
className: makeClassList({ 'show': hasIssues( doc ) })
}, 'warning' ),
h( 'i.material-icons.hide-by-default.complete', {
className: makeClassList({ 'show': doc.submitted() || doc.published() })
className: makeClassList({ 'show': doc.submitted() || doc.isPublic() })
}, 'check_circle' ),
h( 'i.material-icons.hide-by-default.mute', {
className: makeClassList({ 'show': doc.trashed() })
Expand Down Expand Up @@ -477,15 +477,15 @@ class DocumentManagementDocumentComponent extends React.Component {
buttonKey: EMAIL_TYPE_INVITE,
value: EMAIL_TYPE_INVITE,
label: _.capitalize( EMAIL_TYPE_INVITE ),
disableWhen: doc.requested() || doc.trashed()
disableWhen: doc.initiated() || doc.trashed()
}),
h( DocumentEmailButtonComponent, {
params: { doc, apiKey },
workingMessage: 'Sending...',
buttonKey: EMAIL_TYPE_FOLLOWUP,
value: EMAIL_TYPE_FOLLOWUP,
label: _.upperFirst( EMAIL_TYPE_FOLLOWUP.replace(/([A-Z])/g, (match, letter) => '-' + letter) ),
disableWhen: doc.requested() || doc.trashed()
disableWhen: doc.initiated() || doc.trashed()
})
]);
}
Expand Down
4 changes: 0 additions & 4 deletions src/client/components/document-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ class DocumentManagement extends DirtyComponent {
.catch( () => {} );
}

handleApproveRequest( doc ){
doc.approve();
}

handleStatusChange( e ){
const { value, checked } = e.target;
const status = this.state.status.slice();
Expand Down
4 changes: 2 additions & 2 deletions src/client/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class Editor extends DataComponent {

doc.on('update', change => {
if( _.has( change, 'status' ) ){
const isDone = this.data.document.submitted() || this.data.document.published();
const isDone = this.data.document.submitted() || this.data.document.isPublic();
this.done( isDone );
}
});
Expand Down Expand Up @@ -218,7 +218,7 @@ class Editor extends DataComponent {
this.setData({
initted: true,
showHelp: this.data.document.editable(),
done: this.data.document.submitted() || this.data.document.published()
done: this.data.document.submitted() || this.data.document.isPublic()
});

const title = _.get(this.data.document.citation(), ['title']);
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class TaskView extends DataComponent {
const id = this.props.document.id();
const secret = this.props.document.secret();
const params = [
{ op: 'replace', path: 'status', value: DOCUMENT_STATUS_FIELDS.PUBLISHED }
{ op: 'replace', path: 'status', value: DOCUMENT_STATUS_FIELDS.PUBLIC }
];
const url = `/api/document/${id}/${secret}`;
return fetch( url, {
Expand Down
15 changes: 6 additions & 9 deletions src/model/document/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ const DEFAULTS = Object.freeze({
const METADATA_FIELDS = ['provided', 'article', 'correspondence', 'createdDate', 'lastEditedDate', 'status', 'verified' ];
const READONLY_METADATA_FIELDS = _.difference( METADATA_FIELDS, ['provided', 'correspondence'] );
const DOCUMENT_STATUS_FIELDS = Object.freeze({
REQUESTED: 'requested',
APPROVED: 'approved',
INITIATED: 'initiated',
SUBMITTED: 'submitted',
PUBLISHED: 'published',
PUBLIC: 'public',
TRASHED: 'trashed'
});

Expand Down Expand Up @@ -419,14 +418,12 @@ class Document {
}

static statusFields(){ return DOCUMENT_STATUS_FIELDS; }
request(){ return this.status( DOCUMENT_STATUS_FIELDS.REQUESTED ); }
requested(){ return this.status() === DOCUMENT_STATUS_FIELDS.REQUESTED ? true : false; }
approve(){ return this.status( DOCUMENT_STATUS_FIELDS.APPROVED ); }
approved(){ return this.status() === DOCUMENT_STATUS_FIELDS.APPROVED ? true : false; }
initiate(){ return this.status( DOCUMENT_STATUS_FIELDS.INITIATED ); }
initiated(){ return this.status() === DOCUMENT_STATUS_FIELDS.INITIATED ? true : false; }
submit(){ return this.status( DOCUMENT_STATUS_FIELDS.SUBMITTED ); }
submitted(){ return this.status() === DOCUMENT_STATUS_FIELDS.SUBMITTED ? true : false; }
publish(){ return this.status( DOCUMENT_STATUS_FIELDS.PUBLISHED ); }
published(){ return this.status() === DOCUMENT_STATUS_FIELDS.PUBLISHED ? true : false; }
makePublic(){ return this.status( DOCUMENT_STATUS_FIELDS.PUBLIC ); }
isPublic(){ return this.status() === DOCUMENT_STATUS_FIELDS.PUBLIC ? true : false; }
trash(){ return this.status( DOCUMENT_STATUS_FIELDS.TRASHED ); }
trashed(){ return this.status() === DOCUMENT_STATUS_FIELDS.TRASHED ? true : false; }

Expand Down
5 changes: 4 additions & 1 deletion src/server/routes/api/document/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import JSZip from 'jszip';
import _ from 'lodash';
import fs from 'fs';

import Document from '../../../../model/document';

import { convertDocumentToBiopax,
convertDocumentToJson,
convertDocumentToSbgn,
checkHTTPStatus } from '../../../../util';

const DOCUMENT_STATUS_FIELDS = Document.statusFields();
const CHUNK_SIZE = 20;
const EXPORT_TYPES = Object.freeze({
'JS': 'js',
Expand All @@ -26,7 +29,7 @@ const exportToZip = (baseUrl, zipPath, types) => {
.then( res => {
offset += res.length;
if ( res.length > 0 ) {
const includedStatuses = ['published'];
const includedStatuses = [DOCUMENT_STATUS_FIELDS.PUBLIC];
const shouldInclude = doc => _.includes(includedStatuses, doc.status);
let ids = res.filter( shouldInclude ).map( doc => doc.id );
return addToZip( ids ).then( processNext );
Expand Down
33 changes: 13 additions & 20 deletions src/server/routes/api/document/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,10 +711,9 @@ http.get('/zip/biopax', function( req, res, next ){
* status:
* type: string
* enum:
* - requested
* - approved
* - initiated
* - submitted
* - published
* - public
* - trashed
*
* Document:
Expand Down Expand Up @@ -1240,8 +1239,7 @@ http.post('/', function( req, res, next ){
const id = paperId === DEMO_ID ? DEMO_ID: undefined;
const secret = paperId === DEMO_ID ? DEMO_SECRET: uuid();

const setRequestStatus = doc => tryPromise( () => doc.request() ).then( () => doc );
const setApprovedStatus = doc => tryPromise( () => doc.approve() ).then( () => doc );
const setStatus = doc => tryPromise( () => doc.initiate() ).then( () => doc );
const handleDocCreation = async ({ docDb, eleDb }) => {
if( id === DEMO_ID ) await deleteTableRows( API_KEY, secret );
return await createDoc({ docDb, eleDb, id, secret, provided });
Expand All @@ -1253,9 +1251,8 @@ http.post('/', function( req, res, next ){
tryPromise( () => createSecret({ secret }) )
.then( loadTables )
.then( handleDocCreation )
.then( setRequestStatus )
.then( setStatus )
.then( fillDoc )
.then( setApprovedStatus )
.then( tryVerify )
.then( sendJSONResponse )
.then( updateRelatedPapers )
Expand Down Expand Up @@ -1364,17 +1361,13 @@ http.post('/email/:id/:secret', function( req, res, next ){
http.patch('/:id/:secret', function( req, res, next ){
const { id, secret } = req.params;

// Publish criteria: non-empty; all entities complete
const tryPublish = async doc => {
let didPublish = false;
// Public criteria: non-empty; all entities complete
const tryMakePublic = async doc => {
const hasEles = doc => doc.elements().length > 0;
const hasIncompleteEles = doc => doc.elements().some( ele => !ele.completed() && !ele.isInteraction() && ele.type() !== ENTITY_TYPE.COMPLEX );
const isPublishable = doc => hasEles( doc ) && !hasIncompleteEles( doc );
if( isPublishable( doc ) ){
await doc.publish();
didPublish = true;
}
return didPublish;
const shouldMakePublic = doc => hasEles( doc ) && !hasIncompleteEles( doc );
if( shouldMakePublic( doc ) ) await doc.makePublic();
return;
};

const sendFollowUpNotification = async doc => await configureAndSendMail( EMAIL_TYPE_FOLLOWUP, doc.id(), doc.secret() );
Expand All @@ -1388,9 +1381,9 @@ http.patch('/:id/:secret', function( req, res, next ){
}
}
};
const handlePublishRequest = async doc => {
const didPublish = await tryPublish( doc );
if( didPublish ) {
const handleMakePublicRequest = async doc => {
await tryMakePublic( doc );
if( doc.isPublic() ) {
updateRelatedPapers( doc );
await tryTweetingDoc( doc );
sendFollowUpNotification( doc );
Expand All @@ -1404,7 +1397,7 @@ http.patch('/:id/:secret', function( req, res, next ){

switch ( path ) {
case 'status':
if( op === 'replace' && value === DOCUMENT_STATUS_FIELDS.PUBLISHED ) await handlePublishRequest( doc );
if( op === 'replace' && value === DOCUMENT_STATUS_FIELDS.PUBLIC ) await handleMakePublicRequest( doc );
break;
case 'article':
if( op === 'replace' ) await fillDocArticle( doc );
Expand Down