diff --git a/app/pages/lab/visibility.cjsx b/app/pages/lab/visibility.cjsx index 4c16d1073f..944e0dbce3 100644 --- a/app/pages/lab/visibility.cjsx +++ b/app/pages/lab/visibility.cjsx @@ -1,8 +1,10 @@ React = require 'react' +apiClient = require 'panoptes-client/lib/api-client' WorkflowToggle = require '../../components/workflow-toggle' SetToggle = require '../../lib/set-toggle' Dialog = require 'modal-form/dialog' getWorkflowsInOrder = require '../../lib/get-workflows-in-order' +uniq = require 'lodash.uniq' module.exports = React.createClass displayName: 'EditProjectVisibility' @@ -10,32 +12,31 @@ module.exports = React.createClass getDefaultProps: -> project: null - getInitialState: -> { - error: null, - setting: { - private: false, - beta_requested: false, - launch_requested: false, - }, - workflows: null - } + getInitialState: -> + error: null + setting: + private: false + beta_requested: false + launch_requested: false + workflows: null + validatingProject: false + validationErrors: [] mixins: [SetToggle] setterProperty: 'project' componentDidMount: -> - getWorkflowsInOrder(@props.project, fields: 'display_name,active,configuration') - .then((workflows) => - @setState({ workflows }) - ) + getWorkflowsInOrder @props.project + .then (workflows) => + @setState { workflows } isReviewable: -> not @props.project.private and - @props.project.live and not - @state.setting.beta_requested and not - @props.project.beta_requested and not - @props.project.beta_approved + @props.project.live and + not @state.setting.beta_requested and + not @props.project.beta_requested and + not @props.project.beta_approved canApplyForReview: -> @isReviewable() and @@ -43,6 +44,49 @@ module.exports = React.createClass @state.bestPracticesReviewed and @state.feedbackReviewed + applyForReview: -> + @validateProject() + .then () => @set 'beta_requested', true + .catch (errors) => @setState validationErrors: errors + + validateProjectPages: () -> + requiredPages = ['Research', 'FAQ'] + @props.project.get 'pages' + .then (projectPages) -> + requiredPages.reduce (missingPages, requiredPage) -> + pagePresent = projectPages.find (page) -> requiredPage is page.title + if !pagePresent or (pagePresent.content is null or '') + missingPages.push requiredPage + missingPages + , [] + + validateProject: -> + @setState validationErrors: [] + validationCriteria = + activeWorkflows: @state.workflows?.filter (workflow) -> workflow.active + + validations = [ + @validateProjectPages() + ] + + Promise.all validations + .catch (error) -> console.error 'Error requesting project info', error + .then ([missingPages]) -> + validationCriteria = Object.assign validationCriteria, + missingPages: missingPages + errors = [] + + if validationCriteria.activeWorkflows.length < 1 + errors.push 'Project must have at least one active workflow.' + + if validationCriteria.missingPages.length > 0 + errors.push 'The following About pages are missing: ' + validationCriteria.missingPages.join ', ' + + if errors.length + Promise.reject errors + else + return + setRadio: (property, value) -> @set property, value unless @isReviewable() @@ -161,8 +205,8 @@ module.exports = React.createClass {' '} {if @props.project.private @@ -174,6 +218,15 @@ module.exports = React.createClass

+ {if @state.validationErrors.length > 0 + +

The following problems with your project need to be fixed before it can be reviewed:

+ +
} + {unless @props.project.beta_approved

Pending approval, expose this project to users who have opted in to help test new projects.

}