<commit_before>// Copyright 2011 Friday Film Club All Rights Reserved.

/**
 * @fileoverview The leaderboard view/controller.
 *
 * @author <EMAIL> (<NAME>)
 */

goog.provide('ffc.leaderboard.LeaderBoard');

goog.require('ffc.leaderboard.LeaderBoardModel');
goog.require('ffc.template.leaderboard');

goog.require('goog.array');
goog.require('goog.dom');
goog.require('goog.dom.classes');
goog.require('goog.dom.dataset');
goog.require('goog.dom.TagName');
goog.require('goog.string');
goog.require('goog.ui.Component');
goog.require('goog.uri.utils');

goog.require('soy');



/**
 * LeaderBoard constructor.
 * @param {ffc.leaderboard.LeaderBoardModel} model The leaderboard model.
 * @param {String} opt_channelToken Token for the Channel API.
 * @constructor
 */
ffc.leaderboard.LeaderBoard = function(model, opt_channelToken) {
  goog.base(this);

  if (opt_channelToken) {
    var channel = new appengine.Channel(opt_channelToken),
      socket = channel.open();
    socket.onmessage = this.onMessage_.bind(this);
  }

  /**
   * Event handler for this object.
   * @type {goog.events.EventHandler}
   * @private
   */
  this.eh_ = this.getHandler();

  /**
   * The dom helper.
   * @type {goog.dom.DomHelper}
   * @private
   */
  this.dh_ = this.getDomHelper();

  this.setModel(model);
};
goog.inherits(ffc.leaderboard.LeaderBoard, goog.ui.Component);
goog.exportSymbol('ffc.leaderboard.LeaderBoard', ffc.leaderboard.LeaderBoard);
goog.exportProperty(ffc.leaderboard.LeaderBoard.prototype, 'render',
    ffc.leaderboard.LeaderBoard.prototype.render);


/**
 * @type {ffc.leaderboard.LeaderBoardModel}
 * @private
 */
ffc.leaderboard.LeaderBoard.prototype.model_ = null;


/**
 * @return {string} The type of leaderboard, 'all' or 'week'.
 */
ffc.leaderboard.LeaderBoard.prototype.getType = function() {
  return this.model_.id;
};


/**
 * @override
 */
ffc.leaderboard.LeaderBoard.prototype.createDom = function() {
  var el = this.dh_.createDom(goog.dom.TagName.DIV);
  this.dh_.append(el, soy.renderAsElement(ffc.template.leaderboard.table));
  this.dh_.append(el,
      soy.renderAsElement(ffc.template.leaderboard.pagination));
  this.decorateInternal(el);
};


/**
 * @override
 */
ffc.leaderboard.LeaderBoard.prototype.decorateInternal = function(el) {
  goog.base(this, 'decorateInternal', el);
  this.tBodyEl_ = this.getElementByClass('leaderboard-users');
  this.paginationEl_ = this.getElementByClass('pagination');
};


/**
 * @override
 */
ffc.leaderboard.LeaderBoard.prototype.enterDocument = function() {
  goog.base(this, 'enterDocument');

  this.model_.subscribe(ffc.leaderboard.LeaderBoardModel.TOTAL_UPDATED_EVENT,
      this.fillPagination_, this);
  this.model_.subscribe(ffc.leaderboard.LeaderBoardModel.USERS_UPDATED_EVENT,
      this.fillLeaderBoard_, this);

  this.eh_.listen(this.paginationEl_, goog.events.EventType.CLICK,
      this.handlePaginationClick_, true, this);
  this.eh_.listen(this.element_, goog.events.EventType.CLICK,
      this.handleMainClick_, true, this);

  this.model_.sort('score', 'dsc');

  this.element_.style.display = 'block';
  goog.dom.classes.add(this.element_, 'loading');
};


/**
 * @override
 */
ffc.leaderboard.LeaderBoard.prototype.exitDocument = function() {
  goog.base(this, 'exitDocument');

  this.model_.clear();
  this.eh_.removeAll();

  this.dh_.removeChildren(this.element_);
  this.element_ = null;
};


/**
 * @private
 */
ffc.leaderboard.LeaderBoard.prototype.fillLeaderBoard_ = function() {
  this.dh_.removeChildren(this.tBodyEl_);
  var args = [this.tBodyEl_],
      users = this.model_.users,
      TagName = goog.dom.TagName,
      i, len;
  for (i = 0, len = users.getCount(); i < len; i++) {
    var user = users.getByIndex(i);
    args.push(this.dh_.createDom(TagName.TR, user.getChildNodeValue('live') ? 'live' : '',
        this.dh_.createDom(TagName.TD, null, this.dh_.createDom(TagName.IMG, user.picAttrs())),
        this.dh_.createDom(TagName.TD, null, this.dh_.createDom(TagName.A, {href: '/u/' + user.getDataName()}, user.getDataName())),
        this.dh_.createDom(TagName.TD, 'leaderboard-clues', user.getChildNodeValue('clues') + ''),
        this.dh_.createDom(TagName.TD, 'leaderboard-score', user.getScore() + ''),
        this.dh_.createDom(TagName.TD, 'leaderboard-answered', user.getChildNodeValue('answered') + ''),
        this.dh_.createDom(TagName.TD, 'leaderboard-averageclues', user.averageClues() + ''),
        this.dh_.createDom(TagName.TD, 'leaderboard-average', user.averageScore() + '')))
    user.setChildNode('live', false);
  }
  goog.dom.classes.remove(this.element_, 'loading');<commit_msg>Fix semi-colon<commit_after>// Copyright 2011 Friday Film Club All Rights Reserved.

/**
 * @fileoverview The leaderboard view/controller.
 *
 * @author <EMAIL> (<NAME>)
 */

goog.provide('ffc.leaderboard.LeaderBoard');

goog.require('ffc.leaderboard.LeaderBoardModel');
goog.require('ffc.template.leaderboard');

goog.require('goog.array');
goog.require('goog.dom');
goog.require('goog.dom.classes');
goog.require('goog.dom.dataset');
goog.require('goog.dom.TagName');
goog.require('goog.string');
goog.require('goog.ui.Component');
goog.require('goog.uri.utils');

goog.require('soy');



/**
 * LeaderBoard constructor.
 * @param {ffc.leaderboard.LeaderBoardModel} model The leaderboard model.
 * @param {String} opt_channelToken Token for the Channel API.
 * @constructor
 */
ffc.leaderboard.LeaderBoard = function(model, opt_channelToken) {
  goog.base(this);

  if (opt_channelToken) {
    var channel = new appengine.Channel(opt_channelToken),
      socket = channel.open();
    socket.onmessage = this.onMessage_.bind(this);
  }

  /**
   * Event handler for this object.
   * @type {goog.events.EventHandler}
   * @private
   */
  this.eh_ = this.getHandler();

  /**
   * The dom helper.
   * @type {goog.dom.DomHelper}
   * @private
   */
  this.dh_ = this.getDomHelper();

  this.setModel(model);
};
goog.inherits(ffc.leaderboard.LeaderBoard, goog.ui.Component);
goog.exportSymbol('ffc.leaderboard.LeaderBoard', ffc.leaderboard.LeaderBoard);
goog.exportProperty(ffc.leaderboard.LeaderBoard.prototype, 'render',
    ffc.leaderboard.LeaderBoard.prototype.render);


/**
 * @type {ffc.leaderboard.LeaderBoardModel}
 * @private
 */
ffc.leaderboard.LeaderBoard.prototype.model_ = null;


/**
 * @return {string} The type of leaderboard, 'all' or 'week'.
 */
ffc.leaderboard.LeaderBoard.prototype.getType = function() {
  return this.model_.id;
};


/**
 * @override
 */
ffc.leaderboard.LeaderBoard.prototype.createDom = function() {
  var el = this.dh_.createDom(goog.dom.TagName.DIV);
  this.dh_.append(el, soy.renderAsElement(ffc.template.leaderboard.table));
  this.dh_.append(el,
      soy.renderAsElement(ffc.template.leaderboard.pagination));
  this.decorateInternal(el);
};


/**
 * @override
 */
ffc.leaderboard.LeaderBoard.prototype.decorateInternal = function(el) {
  goog.base(this, 'decorateInternal', el);
  this.tBodyEl_ = this.getElementByClass('leaderboard-users');
  this.paginationEl_ = this.getElementByClass('pagination');
};


/**
 * @override
 */
ffc.leaderboard.LeaderBoard.prototype.enterDocument = function() {
  goog.base(this, 'enterDocument');

  this.model_.subscribe(ffc.leaderboard.LeaderBoardModel.TOTAL_UPDATED_EVENT,
      this.fillPagination_, this);
  this.model_.subscribe(ffc.leaderboard.LeaderBoardModel.USERS_UPDATED_EVENT,
      this.fillLeaderBoard_, this);

  this.eh_.listen(this.paginationEl_, goog.events.EventType.CLICK,
      this.handlePaginationClick_, true, this);
  this.eh_.listen(this.element_, goog.events.EventType.CLICK,
      this.handleMainClick_, true, this);

  this.model_.sort('score', 'dsc');

  this.element_.style.display = 'block';
  goog.dom.classes.add(this.element_, 'loading');
};


/**
 * @override
 */
ffc.leaderboard.LeaderBoard.prototype.exitDocument = function() {
  goog.base(this, 'exitDocument');

  this.model_.clear();
  this.eh_.removeAll();

  this.dh_.removeChildren(this.element_);
  this.element_ = null;
};


/**
 * @private
 */
ffc.leaderboard.LeaderBoard.prototype.fillLeaderBoard_ = function() {
  this.dh_.removeChildren(this.tBodyEl_);
  var args = [this.tBodyEl_],
      users = this.model_.users,
      TagName = goog.dom.TagName,
      i, len;
  for (i = 0, len = users.getCount(); i < len; i++) {
    var user = users.getByIndex(i);
    args.push(this.dh_.createDom(TagName.TR, user.getChildNodeValue('live') ? 'live' : '',
        this.dh_.createDom(TagName.TD, null, this.dh_.createDom(TagName.IMG, user.picAttrs())),
        this.dh_.createDom(TagName.TD, null, this.dh_.createDom(TagName.A, {href: '/u/' + user.getDataName()}, user.getDataName())),
        this.dh_.createDom(TagName.TD, 'leaderboard-clues', user.getChildNodeValue('clues') + ''),
        this.dh_.createDom(TagName.TD, 'leaderboard-score', user.getScore() + ''),
        this.dh_.createDom(TagName.TD, 'leaderboard-answered', user.getChildNodeValue('answered') + ''),
        this.dh_.createDom(TagName.TD, 'leaderboard-averageclues', user.averageClues() + ''),
        this.dh_.createDom(TagName.TD, 'leaderboard-average', user.averageScore() + '')));
    user.setChildNode('live', false);
  }
  goog.dom.classes.remove(this.element_, 'loading');
{'fraction_non_alphanumeric': 0.16598138930967324, 'fraction_numerical': 0.0010820168794633195, 'mean_word_length': 4.352055587724378, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '6333201', 'n_tokens_mistral': 3278, 'n_tokens_neox': 3105, 'n_words': 436}