<commit_before>class MainViewController extends KDViewController

  constructor:->

    super

    {repeat, killRepeat} = KD.utils

    mainView         = @getView()
    mainController   = KD.getSingleton 'mainController'
    appManager       = KD.getSingleton 'appManager'
    @registerSingleton 'mainViewController', this, yes
    @registerSingleton 'mainView', mainView, yes

    warn "FIXME Add tell to Login app ~ GG @ kodingrouter (if needed)"
    # mainController.on 'accountChanged.to.loggedIn', (account)->
    #   mainController.loginScreen.hide()

    mainController.on "ShowInstructionsBook", (index)->
      book = mainView.addBook()
      book.fillPage index
      book.checkBoundaries()

    mainController.on "ToggleChatPanel", -> mainView.chatPanel.toggle()

    if KD.checkFlag 'super-admin'
    then $('body').addClass 'super'
    else $('body').removeClass 'super'

    mainViewController = this
    window.onscroll = do ->
      lastRatio = 0
      threshold = 50
      (event)->
        el = document.body
        {scrollHeight, scrollTop} = el

        dynamicThreshold = if threshold > 1
        then (scrollHeight - threshold) / scrollHeight
        else threshold

        ratio = (scrollTop + window.innerHeight) / scrollHeight

        if dynamicThreshold < ratio > lastRatio
          # mainViewController.emit 'LazyLoadThresholdReached', {ratio}
          app = appManager.getFrontApp()
          if app.feedController
            log 'fix: fake loading feed for', app.getOption('name'), ratio, lastRatio
            # app.feedController.loadFeed()

        lastRatio = ratio


  loadView:(mainView)->

    mainView.mainTabView.on "MainTabPaneShown", (pane)=>
      @mainTabPaneChanged mainView, pane

  mainTabPaneChanged:(mainView, pane)->

    cdController    = KD.getSingleton 'contentDisplayController'
    dockController  = KD.getSingleton 'dockController'
    appManager      = KD.getSingleton 'appManager'
    app             = appManager.getFrontApp()
    {mainTabView}   = mainView
    {navController} = dockController

    cdController.emit "ContentDisplaysShouldBeHidden"
    # temp fix
    # until fixing the original issue w/ the dnd this should be kept here
    if pane
    then @setViewState pane.getOptions()
    else mainTabView.getActivePane().show()

    {title} = app.getOption('navItem')

    if title
    then navController.selectItemByName title
    else navController.deselectAllItems()


  setViewState: do ->

    (options = {})->

      {behavior, name} = options
      html             = document.getElementsByTagName('html')[0]
      body             = document.body
      mainView         = @getView()
      { mainTabView
        sidebar }      = mainView
      o                = {name}

      KDView.setElementClass html, 'remove', 'app'
      switch behavior
        when 'hideTabs'
          o.hideTabs = yes
          o.type     = 'social'
        when 'application'
          o.hideTabs = no
          o.type     = 'develop'
          KDView.setElementClass html, 'add', 'app'
        else
          o.hideTabs = no
          o.type     = 'social'

      @emit "UILayoutNeedsToChange", o

      # if options.name is 'Activity'
      # if KD.introView

      KDView.setElementClass body, 'remove', 'intro'
      mainView.unsetClass 'home'
      KD.introView?.unsetClass 'in'
      KD.introView?.setClass 'out'

  #     group = KD.getSingleton('groupsController').getCurrentGroup()

  #     if group.slug is 'koding'
  #     then @decorateHome()
  #     else @clearHome()

  # decorateHome:->
  #   mainView = @getView()
  #   {logo, chatPanel, chatHandler} = mainView

  #   chatHandler.hide()
  #   chatPanel.hide()
  #   mainView.setClass 'home'
  #   logo.setClass 'large'
  #   KD.introView?.show()

  # clearHome:->
  #   mainView = @getView()
  #   {homeIntro, logo, chatPanel, chatHandler} = mainView

  #   KD.introView.hide()
  #   KD.utils.wait 300, ->
  #     chatHandler.show()
  #     chatPanel.show()
  #   mainView.unsetClass 'home'
  #   logo.unsetClass 'large'
  #   KD.introView?.hide()
<commit_msg>resurrection: `MainViewController` emits "LazyLoadThresholdReached" event to front app<commit_after>class MainViewController extends KDViewController

  constructor:->

    super

    {repeat, killRepeat} = KD.utils

    mainView         = @getView()
    mainController   = KD.getSingleton 'mainController'
    appManager       = KD.getSingleton 'appManager'
    @registerSingleton 'mainViewController', this, yes
    @registerSingleton 'mainView', mainView, yes

    warn "FIXME Add tell to Login app ~ GG @ kodingrouter (if needed)"
    # mainController.on 'accountChanged.to.loggedIn', (account)->
    #   mainController.loginScreen.hide()

    mainController.on "ShowInstructionsBook", (index)->
      book = mainView.addBook()
      book.fillPage index
      book.checkBoundaries()

    mainController.on "ToggleChatPanel", -> mainView.chatPanel.toggle()

    if KD.checkFlag 'super-admin'
    then $('body').addClass 'super'
    else $('body').removeClass 'super'

    mainViewController = this
    window.onscroll = do ->
      lastRatio = 0
      threshold = 50
      (event)->
        el = document.body
        {scrollHeight, scrollTop} = el

        dynamicThreshold = if threshold > 1
        then (scrollHeight - threshold) / scrollHeight
        else threshold

        ratio = (scrollTop + window.innerHeight) / scrollHeight

        if dynamicThreshold < ratio > lastRatio
          appManager.getFrontApp()?.emit "LazyLoadThresholdReached"

        lastRatio = ratio

  loadView:(mainView)->

    mainView.mainTabView.on "MainTabPaneShown", (pane)=>
      @mainTabPaneChanged mainView, pane

  mainTabPaneChanged:(mainView, pane)->

    cdController    = KD.getSingleton 'contentDisplayController'
    dockController  = KD.getSingleton 'dockController'
    appManager      = KD.getSingleton 'appManager'
    app             = appManager.getFrontApp()
    {mainTabView}   = mainView
    {navController} = dockController

    cdController.emit "ContentDisplaysShouldBeHidden"
    # temp fix
    # until fixing the original issue w/ the dnd this should be kept here
    if pane
    then @setViewState pane.getOptions()
    else mainTabView.getActivePane().show()

    {title} = app.getOption('navItem')

    if title
    then navController.selectItemByName title
    else navController.deselectAllItems()


  setViewState: do ->

    (options = {})->

      {behavior, name} = options
      html             = document.getElementsByTagName('html')[0]
      body             = document.body
      mainView         = @getView()
      { mainTabView
        sidebar }      = mainView
      o                = {name}

      KDView.setElementClass html, 'remove', 'app'
      switch behavior
        when 'hideTabs'
          o.hideTabs = yes
          o.type     = 'social'
        when 'application'
          o.hideTabs = no
          o.type     = 'develop'
          KDView.setElementClass html, 'add', 'app'
        else
          o.hideTabs = no
          o.type     = 'social'

      @emit "UILayoutNeedsToChange", o

      # if options.name is 'Activity'
      # if KD.introView

      KDView.setElementClass body, 'remove', 'intro'
      mainView.unsetClass 'home'
      KD.introView?.unsetClass 'in'
      KD.introView?.setClass 'out'

  #     group = KD.getSingleton('groupsController').getCurrentGroup()

  #     if group.slug is 'koding'
  #     then @decorateHome()
  #     else @clearHome()

  # decorateHome:->
  #   mainView = @getView()
  #   {logo, chatPanel, chatHandler} = mainView

  #   chatHandler.hide()
  #   chatPanel.hide()
  #   mainView.setClass 'home'
  #   logo.setClass 'large'
  #   KD.introView?.show()

  # clearHome:->
  #   mainView = @getView()
  #   {homeIntro, logo, chatPanel, chatHandler} = mainView

  #   KD.introView.hide()
  #   KD.utils.wait 300, ->
  #     chatHandler.show()
  #     chatPanel.show()
  #   mainView.unsetClass 'home'
  #   logo.unsetClass 'large'
  #   KD.introView?.hide()

{'fraction_non_alphanumeric': 0.10783215041713361, 'fraction_numerical': 0.0019922799153281037, 'mean_word_length': 2.4605773373545885, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '3396326', 'n_tokens_mistral': 2521, 'n_tokens_neox': 2358, 'n_words': 538}