<commit_before>import { Template } from 'meteor/templating';
import { CareerGoals } from '../../../api/career/CareerGoalCollection';
import { Interests } from '../../../api/interest/InterestCollection';
import { Slugs } from '../../../api/slug/SlugCollection';
import { Users } from '../../../api/user/UserCollection';
import { _ } from 'meteor/erasaur:meteor-lodash';

Template.List_Career_Goals_Widget.onCreated(function listCareerGoalsWidgetOnCreated() {
  this.subscribe(CareerGoals.getPublicationName());
  this.subscribe(Interests.getPublicationName());
  this.subscribe(Users.getPublicationName());
  this.subscribe(Slugs.getPublicationName());
});

function getReferences(careerGoalID) {
  let references = 0;
  Users.find().forEach(function (userDoc) {
    if (_.includes(userDoc.careerGoalIDs, careerGoalID)) {
      references += 1;
    }
  });
  return `Users: ${references}`;
}

function hasReferences(careerGoalID) {
  let references = 0;
  Users.find().forEach(function (userDoc) {
    if (_.includes(userDoc.careerGoalIDs, careerGoalID)) {
      references += 1;
    }
  });
  return references > 0;
}

Template.List_Career_Goals_Widget.helpers({
  careerGoals() {
    return CareerGoals.find({}, { sort: { name: 1 }});
  },
  count() {
    return CareerGoals.count();
  },
  slugName(slugID) {
    return Slugs.findDoc(slugID).name;
  },
  descriptionPairs(careerGoal) {
    return [
      { label: 'Description', value: careerGoal.description },
      { label: 'Interests', value: Interests.findNames(careerGoal.interestIDs) },
      { label: 'More Information', value: `<a href="${careerGoal.moreInformation}">${careerGoal.moreInformation}</a>` },
      { label: 'References', value: getReferences(careerGoal._id) },
    ];
  },
});

Template.List_Career_Goals_Widget.onRendered(function listCareerGoalsWidgetOnRendered() {
  // need setTimeout since accordion is within a subtemplate (#each).
  setTimeout(() => { this.$('.ui.accordion').accordion(); }, 300);
});


Template.List_Career_Goals_Widget.events({
  'click .jsUpdate': function (event, instance) {
    event.preventDefault();
    const careerGoalID = event.target.value;
    instance.data.updateID.set(careerGoalID);
  },
  'click .jsDelete': function (event, instance) {
    event.preventDefault();
    const careerGoalID = event.target.value;
    if (hasReferences(careerGoalID)) {<commit_msg>Print interests in sorted order<commit_after>import { Template } from 'meteor/templating';
import { CareerGoals } from '../../../api/career/CareerGoalCollection';
import { Interests } from '../../../api/interest/InterestCollection';
import { Slugs } from '../../../api/slug/SlugCollection';
import { Users } from '../../../api/user/UserCollection';
import { _ } from 'meteor/erasaur:meteor-lodash';

Template.List_Career_Goals_Widget.onCreated(function listCareerGoalsWidgetOnCreated() {
  this.subscribe(CareerGoals.getPublicationName());
  this.subscribe(Interests.getPublicationName());
  this.subscribe(Users.getPublicationName());
  this.subscribe(Slugs.getPublicationName());
});

function getReferences(careerGoalID) {
  let references = 0;
  Users.find().forEach(function (userDoc) {
    if (_.includes(userDoc.careerGoalIDs, careerGoalID)) {
      references += 1;
    }
  });
  return `Users: ${references}`;
}

function hasReferences(careerGoalID) {
  let references = 0;
  Users.find().forEach(function (userDoc) {
    if (_.includes(userDoc.careerGoalIDs, careerGoalID)) {
      references += 1;
    }
  });
  return references > 0;
}

Template.List_Career_Goals_Widget.helpers({
  careerGoals() {
    return CareerGoals.find({}, { sort: { name: 1 }});
  },
  count() {
    return CareerGoals.count();
  },
  slugName(slugID) {
    return Slugs.findDoc(slugID).name;
  },
  descriptionPairs(careerGoal) {
    return [
      { label: 'Description', value: careerGoal.description },
      { label: 'Interests', value: _.sortBy(Interests.findNames(careerGoal.interestIDs)) },
      { label: 'More Information', value: `<a href="${careerGoal.moreInformation}">${careerGoal.moreInformation}</a>` },
      { label: 'References', value: getReferences(careerGoal._id) },
    ];
  },
});

Template.List_Career_Goals_Widget.onRendered(function listCareerGoalsWidgetOnRendered() {
  // need setTimeout since accordion is within a subtemplate (#each).
  setTimeout(() => { this.$('.ui.accordion').accordion(); }, 300);
});


Template.List_Career_Goals_Widget.events({
  'click .jsUpdate': function (event, instance) {
    event.preventDefault();
    const careerGoalID = event.target.value;
    instance.data.updateID.set(careerGoalID);
  },
  'click .jsDelete': function (event, instance) {
    event.preventDefault();
    const careerGoalID = event.target.value;
    if (hasReferences(careerGoalID)) {
{'fraction_non_alphanumeric': 0.1600418410041841, 'fraction_numerical': 0.0037656903765690376, 'mean_word_length': 4.3240534521158125, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '414848', 'n_tokens_mistral': 1583, 'n_tokens_neox': 1531, 'n_words': 260}