<commit_before>app = FactlinkApp

class window.ProfileController extends Backbone.Factlink.BaseController

  routes: ['showProfile', 'showNotificationSettings', 'showFact']

  onShow:   -> @profile_views = new Backbone.Factlink.DetachedViewCache
  onClose:  -> @profile_views.cleanup()
  onAction: -> @unbindFrom @permalink_event if @permalink_event?

  # CACHE HELPERS
  restoreProfileView: (username, new_callback) ->
    if @last_profile_status?
      view = @profile_views.switchCacheView( username )
      $('body').scrollTo(@last_profile_status.scrollTop) if view == @last_profile_status?.view
      delete @last_profile_status
    @profile_views.clearUnshowedViews()
    
    @profile_views.renderCacheView( username, new_callback() ) unless view?

  # ACTIONS
  showProfile: (username) ->
    @showPage username, @profile_options(username)
  showNotificationSettings: (username) ->
    @showPage username, @notification_options(username)

  showFact: (slug, fact_id)->
    @main = new TabbedMainRegionLayout();
    app.mainRegion.show(@main)

    fact = new Fact(id: fact_id)
    fact.fetch
      success: (model, response) => @withFact(model)

  # HELPERS
  profile_options: (username) ->
    title: 'About ' + username
    active_tab: 'show'
    render: (main_region, user) =>
      @makePermalinkEvent()

      main_region.show @profile_views

      @restoreProfileView username, =>
        new ProfileView
          model: user
          collection: window.Channels
          created_facts_view: @getFactsView user.created_facts()<commit_msg>Changed about 'username' to Profile in channel header so it's more consistent with other parts of the application.<commit_after>app = FactlinkApp

class window.ProfileController extends Backbone.Factlink.BaseController

  routes: ['showProfile', 'showNotificationSettings', 'showFact']

  onShow:   -> @profile_views = new Backbone.Factlink.DetachedViewCache
  onClose:  -> @profile_views.cleanup()
  onAction: -> @unbindFrom @permalink_event if @permalink_event?

  # CACHE HELPERS
  restoreProfileView: (username, new_callback) ->
    if @last_profile_status?
      view = @profile_views.switchCacheView( username )
      $('body').scrollTo(@last_profile_status.scrollTop) if view == @last_profile_status?.view
      delete @last_profile_status
    @profile_views.clearUnshowedViews()
    
    @profile_views.renderCacheView( username, new_callback() ) unless view?

  # ACTIONS
  showProfile: (username) ->
    @showPage username, @profile_options(username)
  showNotificationSettings: (username) ->
    @showPage username, @notification_options(username)

  showFact: (slug, fact_id)->
    @main = new TabbedMainRegionLayout();
    app.mainRegion.show(@main)

    fact = new Fact(id: fact_id)
    fact.fetch
      success: (model, response) => @withFact(model)

  # HELPERS
  profile_options: (username) ->
    title: 'Profile'
    active_tab: 'show'
    render: (main_region, user) =>
      @makePermalinkEvent()

      main_region.show @profile_views

      @restoreProfileView username, =>
        new ProfileView
          model: user
          collection: window.Channels
          created_facts_view: @getFactsView user.created_facts()
{'fraction_non_alphanumeric': 0.10597061581744295, 'fraction_numerical': 0.0, 'mean_word_length': 3.984423676012461, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '4226092', 'n_tokens_mistral': 972, 'n_tokens_neox': 944, 'n_words': 205}