<commit_before>#
# Handles / (authenticated gets feed, otherwise about) and /explore
#
Q = require 'q'
_ = require 'underscore'
Backbone = require "backbone"
Feed = require "../../collections/feed"
Channel = require "../../models/channel"
ExploreBlocks = require "../../collections/explore_blocks"
Blocks = require "../../collections/blocks"
CurrentUser = require '../../models/current_user'
sd = require("sharify").data

@index = (req, res, next) ->
  if req.params.block_id
    res.locals.sd.CLIENT_PATH = "block/#{req.params.block_id}"

  if req.user
    res.locals.sd.FEED_TYPE = 'primary'
    res.render 'feed', path: 'feed'
  else

    render = _.after 2, ->
      res.render 'index', example_channel: channel, stats: stats

    channel = new Channel()
    channel.url = "#{sd.API_URL}/channels/arena-front-example-channels"

    channel.parse = (data) ->
      for c_channel in data.contents
        c_channel.contents = new Blocks c_channel.contents
      return data

    channel.fetch
      data:
        per: 10
      cache: true
      success: render

    stats = new Backbone.Model
    stats.url = "#{sd.API_URL}/utilities/statistics"
    stats.formatNumber = (attr) -> @get(attr).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")

    stats.fetch cache: true, success: render

@notifications = (req, res, next) ->
  res.locals.sd.FEED_TYPE = 'notifications'
  res.render 'feed', path: 'notifications'

@explore = (req, res, next) ->
  channels = new ExploreBlocks

  channels.fetch
    data:
      per: 20
    cache: true
    success: ->
      promises = _.compact _.flatten [
        channels.map (channel) ->
          channel.fetch
            cache: true
            success: (model)->
              blocks = new Blocks _.take(model.get('contents'), 4)
              model.set 'contents', blocks
            error: (model, error) ->
              console.log 'error fetching', error
        ]
      Q.allSettled(promises).then(->
        res.locals.sd.CHANNELS = channels.toJSON()
        res.render "explore", channels: channels.models, path: 'explore'
      ).done()
    error: (m, err) -> next err

<commit_msg>handles error on the front page<commit_after>#
# Handles / (authenticated gets feed, otherwise about) and /explore
#
Q = require 'q'
_ = require 'underscore'
Backbone = require "backbone"
Feed = require "../../collections/feed"
Channel = require "../../models/channel"
ExploreBlocks = require "../../collections/explore_blocks"
Blocks = require "../../collections/blocks"
CurrentUser = require '../../models/current_user'
sd = require("sharify").data

@index = (req, res, next) ->
  if req.params.block_id
    res.locals.sd.CLIENT_PATH = "block/#{req.params.block_id}"

  if req.user
    res.locals.sd.FEED_TYPE = 'primary'
    res.render 'feed', path: 'feed'
  else

    render = _.after 2, ->
      res.render 'index', example_channel: channel, stats: stats

    channel = new Channel()
    channel.url = "#{sd.API_URL}/channels/arena-front-example-channels"

    channel.parse = (data) ->
      for c_channel in data.contents
        c_channel.contents = new Blocks c_channel.contents
      return data

    channel.fetch
      data:
        per: 10
      cache: true
      success: render
      error: next

    stats = new Backbone.Model
    stats.url = "#{sd.API_URL}/utilities/statistics"
    stats.formatNumber = (attr) -> @get(attr).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")

    stats.fetch cache: true, success: render, error: next

@notifications = (req, res, next) ->
  res.locals.sd.FEED_TYPE = 'notifications'
  res.render 'feed', path: 'notifications'

@explore = (req, res, next) ->
  channels = new ExploreBlocks

  channels.fetch
    data:
      per: 20
    cache: true
    success: ->
      promises = _.compact _.flatten [
        channels.map (channel) ->
          channel.fetch
            cache: true
            success: (model)->
              blocks = new Blocks _.take(model.get('contents'), 4)
              model.set 'contents', blocks
            error: (model, error) ->
              console.log 'error fetching', error
        ]
      Q.allSettled(promises).then(->
        res.locals.sd.CHANNELS = channels.toJSON()
        res.render "explore", channels: channels.models, path: 'explore'
      ).done()
    error: (m, err) -> next err


{'fraction_non_alphanumeric': 0.1502662653391989, 'fraction_numerical': 0.0037045612410280156, 'mean_word_length': 2.523654159869494, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '2095603', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1348, 'n_words': 335}