<commit_before>'use strict';
$(function () {
	var activityPlanner, unitTemplate;
  activityPlanner = $('#activity-planner')[0];
	if (activityPlanner) {
		var props = {
			analytics: new EC.AnalyticsWrapper()
		};
		React.render(React.createElement(EC.LessonPlanner, props), activityPlanner);
  }
});



EC.LessonPlanner = React.createClass({
	propTypes: {
		analytics: React.PropTypes.object.isRequired
	},

	getInitialState: function () {
		this.modules = {
			fnl: new EC.modules.fnl(),
			updaterGenerator: new EC.modules.updaterGenerator(this),
			unitTemplatesServer: new EC.modules.Server('unit_template', 'unit_templates', '/teachers'),
      windowPosition: new EC.modules.WindowPosition(),
		};

    this.deepExtendState = this.modules.updaterGenerator.updater(null)
		this.updateCreateUnit = this.modules.updaterGenerator.updater('createUnit');
		this.updateCreateUnitModel = this.modules.updaterGenerator.updater('createUnit.model');
		this.updateUnitTemplatesManager = this.modules.updaterGenerator.updater('unitTemplatesManager');

		var state = {
			tab: 'manageUnits', // 'manageUnits', 'createUnit'
			createUnit: {
				stage: 1,
				options: {
					classrooms: []
				},
				model: {
					name: null,
					selectedActivities: []
				}
			},
			unitTemplatesManager: {
	      models: [],
	      categories: [],
	      stage: 'index', // index, profile,
	      model: null,
        model_id: null,
	      relatedModels: [],
	      displayedModels: [],
	      selectedCategoryId: null
			}
		}

    //FIXME: this concern should be handled with a react-router
    var individualUnitTemplate = $('.teachers-unit-template')[0]
    if (individualUnitTemplate) {
      state.tab = 'exploreActivityPacks';
      state.unitTemplatesManager.model_id = $('.teachers-unit-template').data('id');
    }
    return state;
	},


  selectModel: function (ut) {
    var relatedModels = this._modelsInCategory(ut.unit_template_category.id)
    this.updateUnitTemplatesManager({stage: 'profile', model: ut, relatedModels: relatedModels})
    this.modules.windowPosition.reset();
  },

  _modelsInCategory: function (categoryId) {
    return _.where(this.state.unitTemplatesManager.models, {unit_template_category: {id: categoryId}})
  },

  updateUnitTemplateModels: function (models) {
  	var categories =  _.chain(models)
					              .pluck('unit_template_category')
					              .uniq(_.property('id'))
					              .value();

    var newHash = {
    	models: models,
    	displayedModels: models,
    	categories: categories
    }
    var model_id = this.state.unitTemplatesManager.model_id // would be set if we arrived here from a deep link
    if (model_id) {
      newHash.model = _.findWhere(models, {id: model_id});
      newHash.stage = 'profile'
    }
    this.updateUnitTemplatesManager(newHash)
  },

  returnToIndex: function () {
  	this.updateUnitTemplatesManager({stage: 'index'})
  },

  filterByCategory: function (categoryId) {
    if (categoryId) {
      var uts = this._modelsInCategory(categoryId)
    } else {
      var uts = this.state.unitTemplatesManager.models;
    }
    this.updateUnitTemplatesManager({stage: 'index', displayedModels: uts, selectedCategoryId: categoryId});
  },<commit_msg>Return scroll position when clicking on “see all activities”<commit_after>'use strict';
$(function () {
	var activityPlanner, unitTemplate;
  activityPlanner = $('#activity-planner')[0];
	if (activityPlanner) {
		var props = {
			analytics: new EC.AnalyticsWrapper()
		};
		React.render(React.createElement(EC.LessonPlanner, props), activityPlanner);
  }
});



EC.LessonPlanner = React.createClass({
	propTypes: {
		analytics: React.PropTypes.object.isRequired
	},

	getInitialState: function () {
		this.modules = {
			fnl: new EC.modules.fnl(),
			updaterGenerator: new EC.modules.updaterGenerator(this),
			unitTemplatesServer: new EC.modules.Server('unit_template', 'unit_templates', '/teachers'),
      windowPosition: new EC.modules.WindowPosition(),
		};

    this.deepExtendState = this.modules.updaterGenerator.updater(null)
		this.updateCreateUnit = this.modules.updaterGenerator.updater('createUnit');
		this.updateCreateUnitModel = this.modules.updaterGenerator.updater('createUnit.model');
		this.updateUnitTemplatesManager = this.modules.updaterGenerator.updater('unitTemplatesManager');

		var state = {
			tab: 'manageUnits', // 'manageUnits', 'createUnit'
			createUnit: {
				stage: 1,
				options: {
					classrooms: []
				},
				model: {
					name: null,
					selectedActivities: []
				}
			},
			unitTemplatesManager: {
	      models: [],
	      categories: [],
	      stage: 'index', // index, profile,
	      model: null,
        model_id: null,
	      relatedModels: [],
	      displayedModels: [],
	      selectedCategoryId: null
			}
		}

    //FIXME: this concern should be handled with a react-router
    var individualUnitTemplate = $('.teachers-unit-template')[0]
    if (individualUnitTemplate) {
      state.tab = 'exploreActivityPacks';
      state.unitTemplatesManager.model_id = $('.teachers-unit-template').data('id');
    }
    return state;
	},


  selectModel: function (ut) {
    var relatedModels = this._modelsInCategory(ut.unit_template_category.id)
    this.updateUnitTemplatesManager({stage: 'profile', model: ut, relatedModels: relatedModels})
    this.modules.windowPosition.reset();
  },

  _modelsInCategory: function (categoryId) {
    return _.where(this.state.unitTemplatesManager.models, {unit_template_category: {id: categoryId}})
  },

  updateUnitTemplateModels: function (models) {
  	var categories =  _.chain(models)
					              .pluck('unit_template_category')
					              .uniq(_.property('id'))
					              .value();

    var newHash = {
    	models: models,
    	displayedModels: models,
    	categories: categories
    }
    var model_id = this.state.unitTemplatesManager.model_id // would be set if we arrived here from a deep link
    if (model_id) {
      newHash.model = _.findWhere(models, {id: model_id});
      newHash.stage = 'profile'
    }
    this.updateUnitTemplatesManager(newHash)
  },

  returnToIndex: function () {
  	this.updateUnitTemplatesManager({stage: 'index'})
    window.scrollTo(0, 0);
  },

  filterByCategory: function (categoryId) {
    if (categoryId) {
      var uts = this._modelsInCategory(categoryId)
    } else {
      var uts = this.state.unitTemplatesManager.models;
    }
    this.updateUnitTemplatesManager({stage: 'index', displayedModels: uts, selectedCategoryId: categoryId});
  },
{'fraction_non_alphanumeric': 0.1269089798411729, 'fraction_numerical': 0.0012217470983506415, 'mean_word_length': 3.4672578444747613, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1885999', 'n_tokens_mistral': 2147, 'n_tokens_neox': 1979, 'n_words': 372}