<commit_before>Template.activities.created = function () {
  // Get reference to template instance
  var instance = this;

  instance.showLatestActivities = new ReactiveVar();

  // Get reference to template instance
  var instance = this;

  // Instance subscriptions
  // Activity types, residents, and homes
  instance.subscribe('allActivityTypes');
  instance.subscribe('allResidents');
  instance.subscribe('allHomes');

  // subscribe to all activities and related collections
  instance.autorun(function () {
    // Get the value of show latest activities toggle
    var showLatestActivities = instance.showLatestActivities.get();

    if (showLatestActivities === true) {
      instance.subscribe("residentLatestActivities");
    } else if (showLatestActivities === false){
      instance.subscribe("allActivities");
    }
  });
};

Template.activities.rendered = function () {
  // Get reference to template instance
  var instance = this;

  // Set options for toggle switch
  var options = {secondaryColor: 'silver'};
  instance.allOrLatestToggle = document.querySelector("[name='all-or-latest']");
  instance.switch = new Switchery(instance.allOrLatestToggle, options);

  // Get the value of latest activities toggle
  var allOrLatestToggle = instance.allOrLatestToggle.checked;

  // Set the value of show latest activities reactive variable
  instance.showLatestActivities.set(allOrLatestToggle);
};

Template.activities.events({
  "change [name='all-or-latest']": function (event, template) {
    // Get reference to template instance
    var instance = Template.instance();

    // Set reactive variable with value of all-or-latest toggle
    instance.showLatestActivities.set(instance.allOrLatestToggle.checked);
  }
});


Template.activities.helpers({
  "activities": function () {
    // Query Activities collection for all activities
    var activities = Activities.find().fetch();

    // Create a placeholder array for resident objects
    var activitiesArray = [];

    // Iterate through activities
    activities.forEach(function (activity) {
      // Get all resident IDs
      var residentIds = activity.residentIds;

      // Placeholder for resident names
      var homeNames = _.map(residentIds, function (residentId) {
        // Get the resident
        var resident = Residents.findOne(residentId);

        // Get resident home name
        var homeName = resident.homeName();

        return homeName;
      });

      // Get only unique home names
      var homeNamesUnique = _.uniq(homeNames);
<commit_msg>Show newActivity modal when click #add-activity<commit_after>Template.activities.created = function () {
  // Get reference to template instance
  var instance = this;

  instance.showLatestActivities = new ReactiveVar();

  // Get reference to template instance
  var instance = this;

  // Instance subscriptions
  // Activity types, residents, and homes
  instance.subscribe('allActivityTypes');
  instance.subscribe('allResidents');
  instance.subscribe('allHomes');

  // subscribe to all activities and related collections
  instance.autorun(function () {
    // Get the value of show latest activities toggle
    var showLatestActivities = instance.showLatestActivities.get();

    if (showLatestActivities === true) {
      instance.subscribe("residentLatestActivities");
    } else if (showLatestActivities === false){
      instance.subscribe("allActivities");
    }
  });
};

Template.activities.rendered = function () {
  // Get reference to template instance
  var instance = this;

  // Set options for toggle switch
  var options = {secondaryColor: 'silver'};
  instance.allOrLatestToggle = document.querySelector("[name='all-or-latest']");
  instance.switch = new Switchery(instance.allOrLatestToggle, options);

  // Get the value of latest activities toggle
  var allOrLatestToggle = instance.allOrLatestToggle.checked;

  // Set the value of show latest activities reactive variable
  instance.showLatestActivities.set(allOrLatestToggle);
};

Template.activities.events({
  "change [name='all-or-latest']": function (event, template) {
    // Get reference to template instance
    var instance = Template.instance();

    // Set reactive variable with value of all-or-latest toggle
    instance.showLatestActivities.set(instance.allOrLatestToggle.checked);
  },
  'click #add-activity': function () {
    // Show the add activity modal
    Modal.show('newActivity');
  }
});

Template.activities.helpers({
  "activities": function () {
    // Query Activities collection for all activities
    var activities = Activities.find().fetch();

    // Create a placeholder array for resident objects
    var activitiesArray = [];

    // Iterate through activities
    activities.forEach(function (activity) {
      // Get all resident IDs
      var residentIds = activity.residentIds;

      // Placeholder for resident names
      var homeNames = _.map(residentIds, function (residentId) {
        // Get the resident
        var resident = Residents.findOne(residentId);

        // Get resident home name
        var homeName = resident.homeName();

        return homeName;
      });

      // Get only unique home names
      var homeNamesUnique = _.uniq(homeNames);

{'fraction_non_alphanumeric': 0.10323073982030205, 'fraction_numerical': 0.0, 'mean_word_length': 3.5064599483204133, 'pattern_counts': {'":': 4, '<': 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': '4723208', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1347, 'n_words': 398}