<commit_before>import Ember from 'ember';
import config from 'travis/config/environment';

const { alias } = Ember.computed;
const { service } = Ember.inject;

export default Ember.Controller.extend({
  auth: service(),
  store: service(),
  storage: service(),

  user: alias('auth.currentUser'),

  userName: function() {
    return this.get('user.name') || this.get('user.login');
  }.property('user.login', 'user.name'),

  isDashboard: false,

  defineTowerColor(broadcastArray) {
    if (!broadcastArray) {
      return '';
    }
    if (broadcastArray.length) {
      if (broadcastArray.findBy('category', 'warning')) {
        return 'warning';
      } else if (broadcastArray.findBy('category', 'announcement')) {
        return 'announcement';
      } else {
        return '';
      }
    }
  },

  broadcasts: function() {
    var apiEndpoint, broadcasts, options, seenBroadcasts;
    if (this.get('auth.signedIn')) {
      broadcasts = Ember.ArrayProxy.create({
        content: [],
        lastBroadcastStatus: '',
        isLoading: true
      });
      apiEndpoint = config.apiEndpoint;
      options = {};
      options.type = 'GET';
      options.headers = {
        Authorization: "token " + (this.auth.token())
      };
      seenBroadcasts = this.get('storage').getItem('travis.seen_broadcasts');
      if (seenBroadcasts) {
        seenBroadcasts = JSON.parse(seenBroadcasts);
      } else {
        seenBroadcasts = [];
      }
      $.ajax(apiEndpoint + "/v3/broadcasts", options).then((response) => {
        var receivedBroadcasts;
        if (response.broadcasts.length) {
          receivedBroadcasts = response.broadcasts.filter(function(broadcast) {
            if (!broadcast.expired) {
              if (seenBroadcasts.indexOf(broadcast.id.toString()) === -1) {
                return broadcast;
              }
            }
          }).map(function(broadcast) {
            return Ember.Object.create(broadcast);
          }).reverse();
        }
        broadcasts.set('lastBroadcastStatus', this.defineTowerColor(receivedBroadcasts));
        broadcasts.set('content', receivedBroadcasts);
        return broadcasts.set('isLoading', false);
      });
      return broadcasts;
    }
  }.property('broadcasts'),

  actions: {

    cheatcode() {
      $('body').toggleClass('cheatcode');
      this.toggleProperty('isDashboard');
    },

    toggleBurgerMenu() {
      this.toggleProperty('is-open');
      return false;
    },

    toggleBroadcasts() {
      this.toggleProperty('showBroadcasts');
      return false;
    },

    markBroadcastAsSeen(broadcast) {
      var id, seenBroadcasts;
      id = broadcast.get('id').toString();
      seenBroadcasts = this.get('storage').getItem('travis.seen_broadcasts');
      if (seenBroadcasts) {
        seenBroadcasts = JSON.parse(seenBroadcasts);
      } else {
        seenBroadcasts = [];
      }
      seenBroadcasts.push(id);
      this.get('storage').setItem('travis.seen_broadcasts', JSON.stringify(seenBroadcasts));
      this.get('broadcasts.content').removeObject(broadcast);<commit_msg>disable cheatcode for now<commit_after>import Ember from 'ember';
import config from 'travis/config/environment';

const { alias } = Ember.computed;
const { service } = Ember.inject;

export default Ember.Controller.extend({
  auth: service(),
  store: service(),
  storage: service(),

  user: alias('auth.currentUser'),

  userName: function() {
    return this.get('user.name') || this.get('user.login');
  }.property('user.login', 'user.name'),

  isDashboard: false,

  defineTowerColor(broadcastArray) {
    if (!broadcastArray) {
      return '';
    }
    if (broadcastArray.length) {
      if (broadcastArray.findBy('category', 'warning')) {
        return 'warning';
      } else if (broadcastArray.findBy('category', 'announcement')) {
        return 'announcement';
      } else {
        return '';
      }
    }
  },

  broadcasts: function() {
    var apiEndpoint, broadcasts, options, seenBroadcasts;
    if (this.get('auth.signedIn')) {
      broadcasts = Ember.ArrayProxy.create({
        content: [],
        lastBroadcastStatus: '',
        isLoading: true
      });
      apiEndpoint = config.apiEndpoint;
      options = {};
      options.type = 'GET';
      options.headers = {
        Authorization: "token " + (this.auth.token())
      };
      seenBroadcasts = this.get('storage').getItem('travis.seen_broadcasts');
      if (seenBroadcasts) {
        seenBroadcasts = JSON.parse(seenBroadcasts);
      } else {
        seenBroadcasts = [];
      }
      $.ajax(apiEndpoint + "/v3/broadcasts", options).then((response) => {
        var receivedBroadcasts;
        if (response.broadcasts.length) {
          receivedBroadcasts = response.broadcasts.filter(function(broadcast) {
            if (!broadcast.expired) {
              if (seenBroadcasts.indexOf(broadcast.id.toString()) === -1) {
                return broadcast;
              }
            }
          }).map(function(broadcast) {
            return Ember.Object.create(broadcast);
          }).reverse();
        }
        broadcasts.set('lastBroadcastStatus', this.defineTowerColor(receivedBroadcasts));
        broadcasts.set('content', receivedBroadcasts);
        return broadcasts.set('isLoading', false);
      });
      return broadcasts;
    }
  }.property('broadcasts'),

  actions: {

    // cheatcode() {
    //   $('body').toggleClass('cheatcode');
    //   this.toggleProperty('isDashboard');
    // },

    toggleBurgerMenu() {
      this.toggleProperty('is-open');
      return false;
    },

    toggleBroadcasts() {
      this.toggleProperty('showBroadcasts');
      return false;
    },

    markBroadcastAsSeen(broadcast) {
      var id, seenBroadcasts;
      id = broadcast.get('id').toString();
      seenBroadcasts = this.get('storage').getItem('travis.seen_broadcasts');
      if (seenBroadcasts) {
        seenBroadcasts = JSON.parse(seenBroadcasts);
      } else {
        seenBroadcasts = [];
      }
      seenBroadcasts.push(id);
      this.get('storage').setItem('travis.seen_broadcasts', JSON.stringify(seenBroadcasts));
      this.get('broadcasts.content').removeObject(broadcast);
{'fraction_non_alphanumeric': 0.14623099320608218, 'fraction_numerical': 0.0006470397929472663, 'mean_word_length': 2.654255319148936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1512155', 'n_tokens_mistral': 1856, 'n_tokens_neox': 1772, 'n_words': 292}