<commit_before>class ConsiderIt.UserDashboardView extends Backbone.View

  template : _.template( $('#tpl_dashboard_container').html())

  initialize : (options) ->  
    @$dashboard_el = @$el.find('#m-dashboard')

    @templates = {}
    @admin_template_loaded = false
    @rendered = false


    ConsiderIt.router.on 'route:Profile', (id) => 
      @model = ConsiderIt.users[id]
      #@render()
      @access_dashboard_profile(parseInt(id))

    ConsiderIt.router.on 'route:EditProfile', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_edit_profile()
    ConsiderIt.router.on 'route:AccountSettings', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_account_settings()
    ConsiderIt.router.on 'route:EmailNotifications', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_email_notifications()


    ConsiderIt.router.on 'route:AppSettings', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_app_settings()
    ConsiderIt.router.on 'route:ManageProposals', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_manage_proposals()
    ConsiderIt.router.on 'route:UserRoles', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_user_roles()

    ConsiderIt.router.on 'route:Analyze', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_analyze()
    ConsiderIt.router.on 'route:Moderate', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_moderate()
    ConsiderIt.router.on 'route:Assess', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_assess()
    ConsiderIt.router.on 'route:Database', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_database()


    # Is there a better way than just doing this for all other routes?

    ConsiderIt.router.on 'route:Root', => @close() if @$dashboard_el.is(':visible')
    ConsiderIt.router.on 'route:Aggregate', => @close(false) if @$dashboard_el.is(':visible')
    ConsiderIt.router.on 'route:Consider', => @close(false) if @$dashboard_el.is(':visible')
    ConsiderIt.router.on 'route:PointDetails', => @close(false) if @$dashboard_el.is(':visible')    


    @listenTo ConsiderIt.router, 'user:signin', => 
      @model = ConsiderIt.current_user
      if @$dashboard_el.is(':visible') && @current_context
        @render()
        Backbone.history.loadUrl(Backbone.history.fragment)
    
    @listenTo ConsiderIt.router, 'user:signout', => @close() if @$dashboard_el.is(':visible') && @current_context

  render : ->
    visible = @$dashboard_el.is(':visible')

    @$dashboard_el.hide()
    is_self = @model.id == ConsiderIt.current_user.id
    @$dashboard_el.html(
      @template( $.extend( {}, {
        is_self : is_self
        user : @model.attributes
        avatar : window.PaperClip.get_avatar_url(@model, 'original')
        is_admin : is_self && ConsiderIt.roles.is_admin
        is_moderator : is_self && ConsiderIt.roles.is_moderator
        is_analyst : is_self && ConsiderIt.roles.is_analyst
        is_evaluator : is_self && ConsiderIt.roles.is_evaluator
        is_manager : is_self && ConsiderIt.roles.is_manager
      } ) )
    )

    @$content_area = @$dashboard_el.find('.m-dashboard-content')

    if !visible
      @$dashboard_el.fadeIn() 

      @hidden_els = $("[data-role='m-proposal']:visible")
      @hidden_els_visible_before = $("[data-role='m-proposal']:visible")

      #@hidden_els = $('#m-proposals-container, .l-content-wrap:visible:not(#m-dashboard)')

      @hidden_els.css('display', 'none')

    else
      @$dashboard_el.show()

    @rendered = true

    this

  access_dashboard_app_settings : -> 
    options = 
      data_uri : Routes.account_path()
      admin_template_needed: true
      data_callback : (data, params) => 
        ConsiderIt.current_tenant.set(data.account.account)
        params['account'] = ConsiderIt.current_tenant.attributes
        params
      render_callback : =>
        @_check_box(ConsiderIt.current_tenant, 'assessment_enabled', 'account_assessment_enabled')
        @_check_box(ConsiderIt.current_tenant, 'enable_moderation', 'account_enable_moderation')
        @_check_box(ConsiderIt.current_tenant, 'enable_position_statement', 'account_enable_position_statement')
        @_check_box(ConsiderIt.current_tenant, 'enable_user_conversations', 'account_enable_user_conversations')

    @_process_dashboard_context('app_settings', options)

  access_dashboard_manage_proposals : -> 
    options = 
      admin_template_needed: true
      params : { 
        active_proposals: ConsiderIt.all_proposals.where {active: true}
        inactive_proposals: ConsiderIt.all_proposals.where {active: false}
      }
    @_process_dashboard_context('manage_proposals', options)

  access_dashboard_user_roles : -> 
    options = 
      data_uri : Routes.manage_roles_path()
      admin_template_needed: true            
      data_callback : (data, params) =>
        @users_by_roles_mask = new Backbone.Collection( (new ConsiderIt.User(user.user) for user in data.users_by_roles_mask)  )
        _.extend params, { users_by_roles_mask: @users_by_roles_mask }

    @_process_dashboard_context('user_roles', options)

  access_dashboard_analyze : -> 
    options = 
      data_uri : Routes.analytics_path()
      admin_template_needed: true            
      view_class: -> ConsiderIt.UserDashboardViewAnalyze
    @_process_dashboard_context('analyze', options)
  <commit_msg>auto resizing for app description<commit_after>class ConsiderIt.UserDashboardView extends Backbone.View

  template : _.template( $('#tpl_dashboard_container').html())

  initialize : (options) ->  
    @$dashboard_el = @$el.find('#m-dashboard')

    @templates = {}
    @admin_template_loaded = false
    @rendered = false


    ConsiderIt.router.on 'route:Profile', (id) => 
      @model = ConsiderIt.users[id]
      #@render()
      @access_dashboard_profile(parseInt(id))

    ConsiderIt.router.on 'route:EditProfile', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_edit_profile()
    ConsiderIt.router.on 'route:AccountSettings', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_account_settings()
    ConsiderIt.router.on 'route:EmailNotifications', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_email_notifications()


    ConsiderIt.router.on 'route:AppSettings', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_app_settings()
    ConsiderIt.router.on 'route:ManageProposals', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_manage_proposals()
    ConsiderIt.router.on 'route:UserRoles', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_user_roles()

    ConsiderIt.router.on 'route:Analyze', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_analyze()
    ConsiderIt.router.on 'route:Moderate', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_moderate()
    ConsiderIt.router.on 'route:Assess', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_assess()
    ConsiderIt.router.on 'route:Database', => 
      @model = ConsiderIt.current_user if @model.id != ConsiderIt.current_user
      @access_dashboard_database()


    # Is there a better way than just doing this for all other routes?

    ConsiderIt.router.on 'route:Root', => @close() if @$dashboard_el.is(':visible')
    ConsiderIt.router.on 'route:Aggregate', => @close(false) if @$dashboard_el.is(':visible')
    ConsiderIt.router.on 'route:Consider', => @close(false) if @$dashboard_el.is(':visible')
    ConsiderIt.router.on 'route:PointDetails', => @close(false) if @$dashboard_el.is(':visible')    


    @listenTo ConsiderIt.router, 'user:signin', => 
      @model = ConsiderIt.current_user
      if @$dashboard_el.is(':visible') && @current_context
        @render()
        Backbone.history.loadUrl(Backbone.history.fragment)
    
    @listenTo ConsiderIt.router, 'user:signout', => @close() if @$dashboard_el.is(':visible') && @current_context

  render : ->
    visible = @$dashboard_el.is(':visible')

    @$dashboard_el.hide()
    is_self = @model.id == ConsiderIt.current_user.id
    @$dashboard_el.html(
      @template( $.extend( {}, {
        is_self : is_self
        user : @model.attributes
        avatar : window.PaperClip.get_avatar_url(@model, 'original')
        is_admin : is_self && ConsiderIt.roles.is_admin
        is_moderator : is_self && ConsiderIt.roles.is_moderator
        is_analyst : is_self && ConsiderIt.roles.is_analyst
        is_evaluator : is_self && ConsiderIt.roles.is_evaluator
        is_manager : is_self && ConsiderIt.roles.is_manager
      } ) )
    )

    @$content_area = @$dashboard_el.find('.m-dashboard-content')

    if !visible
      @$dashboard_el.fadeIn() 

      @hidden_els = $("[data-role='m-proposal']:visible")
      @hidden_els_visible_before = $("[data-role='m-proposal']:visible")

      #@hidden_els = $('#m-proposals-container, .l-content-wrap:visible:not(#m-dashboard)')

      @hidden_els.css('display', 'none')

    else
      @$dashboard_el.show()

    @rendered = true

    this

  access_dashboard_app_settings : -> 
    options = 
      data_uri : Routes.account_path()
      admin_template_needed: true
      data_callback : (data, params) => 
        ConsiderIt.current_tenant.set(data.account.account)
        params['account'] = ConsiderIt.current_tenant.attributes
        params
      render_callback : =>
        @_check_box(ConsiderIt.current_tenant, 'assessment_enabled', 'account_assessment_enabled')
        @_check_box(ConsiderIt.current_tenant, 'enable_moderation', 'account_enable_moderation')
        @_check_box(ConsiderIt.current_tenant, 'enable_position_statement', 'account_enable_position_statement')
        @_check_box(ConsiderIt.current_tenant, 'enable_user_conversations', 'account_enable_user_conversations')

        @$el.find('#account_header_text').autoResize {extraSpace: 10, minHeight: 50}
        @$el.find('#account_header_details_text').autoResize {extraSpace: 10, minHeight: 100}


    @_process_dashboard_context('app_settings', options)

  access_dashboard_manage_proposals : -> 
    options = 
      admin_template_needed: true
      params : { 
        active_proposals: ConsiderIt.all_proposals.where {active: true}
        inactive_proposals: ConsiderIt.all_proposals.where {active: false}
      }
    @_process_dashboard_context('manage_proposals', options)

  access_dashboard_user_roles : -> 
    options = 
      data_uri : Routes.manage_roles_path()
      admin_template_needed: true            
      data_callback : (data, params) =>
        @users_by_roles_mask = new Backbone.Collection( (new ConsiderIt.User(user.user) for user in data.users_by_roles_mask)  )
        _.extend params, { users_by_roles_mask: @users_by_roles_mask }

    @_process_dashboard_context('user_roles', options)

  access_dashboard_analyze : -> 
    options = 
      data_uri : Routes.analytics_path()
      admin_template_needed: true            
      view_class: -> ConsiderIt.UserDashboardViewAnalyze
    @_process_dashboard_context('analyze', options)
  
{'fraction_non_alphanumeric': 0.12263754724905501, 'fraction_numerical': 0.0007559848803023939, 'mean_word_length': 3.707789640173982, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 57, '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': '5995755', 'n_tokens_mistral': 3807, 'n_tokens_neox': 3747, 'n_words': 576}