<commit_before>React = require 'react'
Translate = require 'react-translate-component'
{IndexLink, Link} = require 'react-router'
{Markdown} = require 'markdownz'
{sugarClient} = require 'panoptes-client/lib/sugar'
Thumbnail = require('../../components/thumbnail').default
classnames = require 'classnames'
PotentialFieldGuide = require './potential-field-guide'
`import SOCIAL_ICONS from '../../lib/social-icons'`
`import isAdmin from '../../lib/is-admin';`

AVATAR_SIZE = 100

ProjectPage = React.createClass
  contextTypes:
    geordi: React.PropTypes.object

  propTypes:
    owner: React.PropTypes.object.isRequired
    preferences: React.PropTypes.object
    project: React.PropTypes.object.isRequired
    loading: React.PropTypes.bool

  getInitialState: ->
    backgroundHeight: null

  getDefaultProps: ->
    background: null
    guide: null
    guideIcons: null
    loading: false
    owner: {}
    preferences: null
    pages: null
    project: {}
    projectAvatar: null
    projectRoles: null
    splits: null

  componentDidMount: ->
    this.resizeBackground()
    addEventListener "resize", this.resizeBackground
    document.documentElement.classList.add 'on-project-page'
    @updateSugarSubscription @props.project
    @context.geordi?.remember projectToken: @props.project?.slug

  componentWillUnmount: ->
    removeEventListener "resize", this.resizeBackground
    document.documentElement.classList.remove 'on-project-page'
    @updateSugarSubscription null
    @context.geordi?.forget ['projectToken']

  componentWillReceiveProps: (nextProps, nextContext) ->
    if nextProps.project isnt @props.project
      @updateSugarSubscription nextProps.project
      @context.geordi?.remember projectToken: nextProps.project?.slug

  resizeBackground: ->
    finishedBannerHeight = 70
    projLanding = document.getElementById('projectLandingIntro')
    if projLanding
      sectionBottom = projLanding.getBoundingClientRect().bottom;
      sectionHeight = document.body.scrollTop + sectionBottom
      if @state.backgroundHeight isnt sectionHeight + finishedBannerHeight
        @setState backgroundHeight: sectionHeight + finishedBannerHeight

  _lastSugarSubscribedID: null

  updateSugarSubscription: (project) ->
    if @_lastSugarSubscribedID?
      sugarClient.unsubscribeFrom "project-#{@_lastSugarSubscribedID}"
    if project?
      sugarClient.subscribeTo "project-#{project.id}"

  redirectClassifyLink: (redirect) ->
    "#{redirect.replace(/\/?#?\/+$/, "")}/#/classify"

  renderProjectName: (betaApproved) ->
    if betaApproved
      <div>
        <p>Under Review</p>
        {@props.project.display_name}
      </div>
    else
      @props.project.display_name

  userHasLabAccess: ->
    userRoles = @props.projectRoles.some ({roles}) =>
      roles.includes('owner') || roles.includes('collaborator')
<commit_msg>actually check i am the user with the roles (#4152)<commit_after>React = require 'react'
Translate = require 'react-translate-component'
{IndexLink, Link} = require 'react-router'
{Markdown} = require 'markdownz'
{sugarClient} = require 'panoptes-client/lib/sugar'
Thumbnail = require('../../components/thumbnail').default
classnames = require 'classnames'
PotentialFieldGuide = require './potential-field-guide'
`import SOCIAL_ICONS from '../../lib/social-icons'`
`import isAdmin from '../../lib/is-admin';`

AVATAR_SIZE = 100

ProjectPage = React.createClass
  contextTypes:
    geordi: React.PropTypes.object

  propTypes:
    owner: React.PropTypes.object.isRequired
    preferences: React.PropTypes.object
    project: React.PropTypes.object.isRequired
    loading: React.PropTypes.bool

  getInitialState: ->
    backgroundHeight: null

  getDefaultProps: ->
    background: null
    guide: null
    guideIcons: null
    loading: false
    owner: {}
    preferences: null
    pages: null
    project: {}
    projectAvatar: null
    projectRoles: null
    splits: null

  componentDidMount: ->
    this.resizeBackground()
    addEventListener "resize", this.resizeBackground
    document.documentElement.classList.add 'on-project-page'
    @updateSugarSubscription @props.project
    @context.geordi?.remember projectToken: @props.project?.slug

  componentWillUnmount: ->
    removeEventListener "resize", this.resizeBackground
    document.documentElement.classList.remove 'on-project-page'
    @updateSugarSubscription null
    @context.geordi?.forget ['projectToken']

  componentWillReceiveProps: (nextProps, nextContext) ->
    if nextProps.project isnt @props.project
      @updateSugarSubscription nextProps.project
      @context.geordi?.remember projectToken: nextProps.project?.slug

  resizeBackground: ->
    finishedBannerHeight = 70
    projLanding = document.getElementById('projectLandingIntro')
    if projLanding
      sectionBottom = projLanding.getBoundingClientRect().bottom;
      sectionHeight = document.body.scrollTop + sectionBottom
      if @state.backgroundHeight isnt sectionHeight + finishedBannerHeight
        @setState backgroundHeight: sectionHeight + finishedBannerHeight

  _lastSugarSubscribedID: null

  updateSugarSubscription: (project) ->
    if @_lastSugarSubscribedID?
      sugarClient.unsubscribeFrom "project-#{@_lastSugarSubscribedID}"
    if project?
      sugarClient.subscribeTo "project-#{project.id}"

  redirectClassifyLink: (redirect) ->
    "#{redirect.replace(/\/?#?\/+$/, "")}/#/classify"

  renderProjectName: (betaApproved) ->
    if betaApproved
      <div>
        <p>Under Review</p>
        {@props.project.display_name}
      </div>
    else
      @props.project.display_name

  userHasLabAccess: ->
    userRoles = @props.projectRoles.some (role) =>
      if role.links.owner.id == @props.user.id
        role.roles.includes('owner') || role.roles.includes('collaborator')

{'fraction_non_alphanumeric': 0.11339316534345875, 'fraction_numerical': 0.002416292716603383, 'mean_word_length': 3.873843566021867, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4720645', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1694, 'n_words': 332}