<commit_before>import Ember from 'ember';

export default Ember.Controller.extend({
  modal: {},
  ctf: null,
  authController: null,
  session: {},
  sortCategory: ['name:asc'],
  sortChallenges: ['points:asc', 'id'],
  sortedChallengeboard: {},
  categories: {},
  setSolvedChallenges: function(){
    // Add new challenge to solved if it exists
    var chall_id = this.get('modal.solvedChallenge');
    if (chall_id || chall_id === 0){
      var challenge = this.store.peekRecord('challenge', chall_id);
      if (challenge){
        var points = this.get('session.team.points');
        if (points) {
          this.set('session.team.points', points+challenge.get('points'));
        }
      }
      
      var usersolved = this.get('session.team.solves');
      if (usersolved){
        var timestamp = [chall_id, Date.now() / 1000 | 0];
        usersolved.addObject(timestamp);
      }
      this.set('modal.solvedChallenge', false);
    }

    // Updated isSolved flag for challenges that are solved
    var solves = this.get('session.team.solves');
    var t = this;
    if(solves){
      solves.forEach(function(timestamp){
        var challenge_id = timestamp[0];
        var challenge = t.store.peekRecord('challenge', challenge_id);
        if (challenge){
          if(!challenge.get('isSolved')){
            challenge.set('isSolved', true);
          }
        }
      });
    } // TODO: set challenges isSolved back to false on logout
  }.observes('ctf.challengeboard.categories', 'session', 'modal.solvedChallenge'),
  actions: {
    openLoginModal: function() {
      this.set('modal.isLogin', true);
    },
    openChallenge: function(id) {
      this.store.find('challenge', id).then((challenge) => {<commit_msg>Updated challenges to handle different sessions<commit_after>import Ember from 'ember';

export default Ember.Controller.extend({
  modal: {},
  ctf: null,
  session: {},
  sortedChallengeboard: {},
  setSolvedChallenges: function(){
    // Add new challenge to solved if it exists
    var chall_id = this.get('modal.solvedChallenge');
    if (chall_id || chall_id === 0){
      var challenge = this.store.peekRecord('challenge', chall_id);
      if (challenge){
        var points = this.get('session.team.points');
        if (points) {
          this.set('session.team.points', points+challenge.get('points'));
        }
      }
      
      var usersolved = this.get('session.team.solves');
      if (usersolved){
        var timestamp = [chall_id, Date.now() / 1000 | 0];
        usersolved.addObject(timestamp);
      }
      this.set('modal.solvedChallenge', false);
    }

    // Updated isSolved for all challenges
    var solves = this.get('session.team.solves');
    if(solves){
      var challenges = this.store.peekAll('challenge');
      if(challenges){
        var teamSolves = [];
        var teamSolvesTuples = solves.toArray();
        for(var i = 0;i < teamSolvesTuples.length; i++){
          teamSolves.push(teamSolvesTuples[i][0]);
        }
        challenges.forEach(function(challenge){
          var challenge_id = Number(challenge.get('id'));
          if(teamSolves.indexOf(challenge_id) > -1){
            challenge.set('isSolved', true);
          } else {
            challenge.set('isSolved', false);
          }
        });
      }
    }
  }.observes('ctf.challengeboard.categories', 'session', 'modal.solvedChallenge'),
  actions: {
    openLoginModal: function() {
      this.set('modal.isLogin', true);
    },
    openChallenge: function(id) {
      this.store.find('challenge', id).then((challenge) => {
{'fraction_non_alphanumeric': 0.14781634938409854, 'fraction_numerical': 0.004479283314669653, 'mean_word_length': 2.72964509394572, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, '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': '3728224', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1069, 'n_words': 221}