<commit_before>{div, ul, li, a, span, i} = React.DOM

classer = React.addons.classSet

RouterMixin          = require '../mixins/router_mixin'
LayoutActionCreator  = require '../actions/layout_action_creator'
MessageActionCreator = require '../actions/message_action_creator'
AccountStore         = require '../stores/account_store'

module.exports = Menu = React.createClass
    displayName: 'Menu'

    mixins: [RouterMixin]

    shouldComponentUpdate: (nextProps, nextState) ->
        return not(_.isEqual(nextState, @state)) or
               not(_.isEqual(nextProps, @props))

    getInitialState: ->
        return displayActiveAccount: true

    componentWillReceiveProps: (props) ->
        if not Immutable.is(props.selectedAccount, @props.selectedAccount)
            @setState displayActiveAccount: true

    render: ->

        if @props.accounts.length
            selectedAccountUrl = @buildUrl
                direction: 'first'
                action: 'account.mailbox.messages'
                parameters: @props.selectedAccount?.get 'id'
                fullWidth: true
        else
            selectedAccountUrl = @buildUrl
                direction: 'first'
                action: 'account.new'
                fullWidth: true

        # the button toggles the "compose" screen
        if @props.layout.firstPanel.action is 'compose' or
           @props.layout.secondPanel?.action is 'compose'
            composeClass = 'active'
            composeUrl = selectedAccountUrl
        else
            composeClass = ''
            composeUrl = @buildUrl
                direction: 'first'
                action: 'compose'
                parameters: null
                fullWidth: true

        # the button toggle the "new account" screen
        if @props.layout.firstPanel.action is 'account.new'
            newMailboxClass = 'active'
            newMailboxUrl = selectedAccountUrl
        else
            newMailboxClass = ''
            newMailboxUrl = @buildUrl
                direction: 'first'
                action: 'account.new'
                fullWidth: true

        # the button toggles the "settings" screen
        if @props.layout.firstPanel.action is 'settings' or
           @props.layout.secondPanel?.action is 'settings'
            settingsClass = 'active'
            settingsUrl = selectedAccountUrl
        else
            settingsClass = ''
            settingsUrl = @buildUrl
                direction: 'first'
                action: 'settings'
                fullWidth: true

        classes = classer
            'hidden-xs hidden-sm': not @props.isResponsiveMenuShown
            'col-xs-4 col-md-1': true

        div id: 'menu', className: classes,
            unless @props.accounts.length is 0
                a
                    href: composeUrl,
                    className: 'menu-item compose-action ' + composeClass,
                        i className: 'fa fa-edit'
                        span className: 'item-label', t 'menu compose'

            if @props.accounts.length isnt 0
                ul id: 'account-list', className: 'list-unstyled',
                    @props.accounts.map (account, key) =>
                        @getAccountRender account, key
                    .toJS()

            a
                href: newMailboxUrl,
                className: 'menu-item new-account-action ' + newMailboxClass,
                    i className: 'fa fa-inbox'
                    span className: 'item-label', t 'menu account new'

            a
                href: settingsUrl,
                className: 'menu-item settings-action ' + settingsClass,
                    i className: 'fa fa-cog'
                    span className: 'item-label', t 'menu settings'


    # renders a single mailbox and its submenu
    getAccountRender: (account, key) ->

        isSelected = (not @props.selectedAccount? and key is 0) \
                     or @props.selectedAccount?.get('id') is account.get('id')

        accountID = account.get 'id'
        defaultMailbox = AccountStore.getDefaultMailbox accountID

        if defaultMailbox?
            url = @buildUrl
                direction: 'first'
                action: 'account.mailbox.messages'
                parameters: [accountID, defaultMailbox?.get 'id']
                fullWidth: true # /!\ Hide second panel when switching account
        else
            # Go to account settings to add mailboxes
            url = @buildUrl
                direction: 'first'
                action: 'account.config'
                parameters: [accountID]
                fullWidth: true # /!\ Hide second panel when switching account

        toggleActive = =>
            if isSelected
                @setState displayActiveAccount: not @state.displayActiveAccount
            else
                @setState displayActiveAccount: true
        nbTotal  = 0
        nbUnread = 0
        nbNew    = 0
        account.get('mailboxes').map (mailbox) ->
            nbTotal  += mailbox.get('nbTotal') or 0
            nbUnread += mailbox.get('nbUnread') or 0
            nbNew    += mailbox.get('nbNew') or 0
        .toJS()
        title    = t "menu mailbox total", nbTotal
        if nbUnread > 0
            title += t "menu mailbox unread", nbUnread
        if nbNew > 0
            title += t "menu mailbox new", nbNew

        accountClasses = classer
            active: (isSelected and @state.displayActiveAccount)
            news: nbNew > 0

        li className: accountClasses, key: key,
            a
                href: url,
                className: 'menu-item account ' + accountClasses,
                onClick: toggleActive,
                title: title,
                'data-toggle': 'tooltip',
                'data-placement' : 'right',
                    i className: 'fa fa-inbox'
                    if nbUnread and nbUnread > 0
                        span className: 'badge', nbUnread
                    span
                        'data-account-id': key,
                        className: 'item-label',
                        account.get 'label'

            ul className: 'list-unstyled submenu mailbox-list',
                @props.favoriteMailboxes?.map (mailbox, key) =>
                    selectedMailboxID = @props.selectedMailboxID
                    MenuMailboxItem { account, mailbox, key, selectedMailboxID }
                .toJS()

    _initTooltips: ->
        jQuery('#account-list [data-toggle="tooltip"]').tooltip()

    componentDidMount: ->
        @_initTooltips()

    componentDidUpdate: ->
        @_initTooltips()


MenuMailboxItem = React.createClass
    displayName: 'MenuMailboxItem'
<commit_msg>remove wrong sum from account<commit_after>{div, ul, li, a, span, i} = React.DOM

classer = React.addons.classSet

RouterMixin          = require '../mixins/router_mixin'
LayoutActionCreator  = require '../actions/layout_action_creator'
MessageActionCreator = require '../actions/message_action_creator'
AccountStore         = require '../stores/account_store'

module.exports = Menu = React.createClass
    displayName: 'Menu'

    mixins: [RouterMixin]

    shouldComponentUpdate: (nextProps, nextState) ->
        return not(_.isEqual(nextState, @state)) or
               not(_.isEqual(nextProps, @props))

    getInitialState: ->
        return displayActiveAccount: true

    componentWillReceiveProps: (props) ->
        if not Immutable.is(props.selectedAccount, @props.selectedAccount)
            @setState displayActiveAccount: true

    render: ->

        if @props.accounts.length
            selectedAccountUrl = @buildUrl
                direction: 'first'
                action: 'account.mailbox.messages'
                parameters: @props.selectedAccount?.get 'id'
                fullWidth: true
        else
            selectedAccountUrl = @buildUrl
                direction: 'first'
                action: 'account.new'
                fullWidth: true

        # the button toggles the "compose" screen
        if @props.layout.firstPanel.action is 'compose' or
           @props.layout.secondPanel?.action is 'compose'
            composeClass = 'active'
            composeUrl = selectedAccountUrl
        else
            composeClass = ''
            composeUrl = @buildUrl
                direction: 'first'
                action: 'compose'
                parameters: null
                fullWidth: true

        # the button toggle the "new account" screen
        if @props.layout.firstPanel.action is 'account.new'
            newMailboxClass = 'active'
            newMailboxUrl = selectedAccountUrl
        else
            newMailboxClass = ''
            newMailboxUrl = @buildUrl
                direction: 'first'
                action: 'account.new'
                fullWidth: true

        # the button toggles the "settings" screen
        if @props.layout.firstPanel.action is 'settings' or
           @props.layout.secondPanel?.action is 'settings'
            settingsClass = 'active'
            settingsUrl = selectedAccountUrl
        else
            settingsClass = ''
            settingsUrl = @buildUrl
                direction: 'first'
                action: 'settings'
                fullWidth: true

        classes = classer
            'hidden-xs hidden-sm': not @props.isResponsiveMenuShown
            'col-xs-4 col-md-1': true

        div id: 'menu', className: classes,
            unless @props.accounts.length is 0
                a
                    href: composeUrl,
                    className: 'menu-item compose-action ' + composeClass,
                        i className: 'fa fa-edit'
                        span className: 'item-label', t 'menu compose'

            if @props.accounts.length isnt 0
                ul id: 'account-list', className: 'list-unstyled',
                    @props.accounts.map (account, key) =>
                        @getAccountRender account, key
                    .toJS()

            a
                href: newMailboxUrl,
                className: 'menu-item new-account-action ' + newMailboxClass,
                    i className: 'fa fa-inbox'
                    span className: 'item-label', t 'menu account new'

            a
                href: settingsUrl,
                className: 'menu-item settings-action ' + settingsClass,
                    i className: 'fa fa-cog'
                    span className: 'item-label', t 'menu settings'


    # renders a single mailbox and its submenu
    getAccountRender: (account, key) ->

        isSelected = (not @props.selectedAccount? and key is 0) \
                     or @props.selectedAccount?.get('id') is account.get('id')

        accountID = account.get 'id'
        defaultMailbox = AccountStore.getDefaultMailbox accountID

        if defaultMailbox?
            url = @buildUrl
                direction: 'first'
                action: 'account.mailbox.messages'
                parameters: [accountID, defaultMailbox?.get 'id']
                fullWidth: true # /!\ Hide second panel when switching account
        else
            # Go to account settings to add mailboxes
            url = @buildUrl
                direction: 'first'
                action: 'account.config'
                parameters: [accountID]
                fullWidth: true # /!\ Hide second panel when switching account

        toggleActive = =>
            if isSelected
                @setState displayActiveAccount: not @state.displayActiveAccount
            else
                @setState displayActiveAccount: true

        accountClasses = classer
            active: (isSelected and @state.displayActiveAccount)

        li className: accountClasses, key: key,
            a
                href: url,
                className: 'menu-item account ' + accountClasses,
                onClick: toggleActive,
                'data-toggle': 'tooltip',
                'data-placement' : 'right',
                    i className: 'fa fa-inbox'
                    span
                        'data-account-id': key,
                        className: 'item-label',
                        account.get 'label'

            ul className: 'list-unstyled submenu mailbox-list',
                @props.favoriteMailboxes?.map (mailbox, key) =>
                    selectedMailboxID = @props.selectedMailboxID
                    MenuMailboxItem { account, mailbox, key, selectedMailboxID }
                .toJS()

    _initTooltips: ->
        jQuery('#account-list [data-toggle="tooltip"]').tooltip()

    componentDidMount: ->
        @_initTooltips()

    componentDidUpdate: ->
        @_initTooltips()


MenuMailboxItem = React.createClass
    displayName: 'MenuMailboxItem'

{'fraction_non_alphanumeric': 0.08726359569959978, 'fraction_numerical': 0.001569489131287766, 'mean_word_length': 1.5860389610389611, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 30, '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': '648118', 'n_tokens_mistral': 3325, 'n_tokens_neox': 3123, 'n_words': 835}