<commit_before>import $ from 'jquery';
import C from 'ui/utils/constants';
import Route from '@ember/routing/route';
import Preload from 'ui/mixins/preload';
import { inject as service } from '@ember/service';
import { scheduleOnce, later, cancel } from '@ember/runloop';
import { resolve, all as PromiseAll } from 'rsvp';
import { get, set } from '@ember/object';

const CHECK_AUTH_TIMER = 60*10*1000;

export default Route.extend(Preload, {
  access:       service(),
  globalStore:  service(),
  clusterStore: service(),
  cookies:      service(),
  language:     service('user-language'),
  modalService: service('modal'),
  prefs:        service(),
  scope:        service(),
  settings:     service(),
  storeReset:   service(),
  intl:         service(),
  growl:        service(),
  userTheme:    service('user-theme'),

  testTimer:    null,

  beforeModel() {
    this._super(...arguments);

    set(this, 'testTimer', later(() => {
      this.testAuthToken();
    }, CHECK_AUTH_TIMER));

    return this.testAuthToken();
  },

  testAuthToken() {
    return get(this,'access').testAuth().catch(() => {
      this.transitionTo('login');
      this.send('logout',null);
    });
  },

  model(params, transition) {
    get(this,'session').set(C.SESSION.BACK_TO, undefined);

    const isPopup = this.controllerFor('application').get('isPopup');

    return get(this, 'scope').startSwitchToGlobal(!isPopup).then(() => {
      const list = [
        this.loadSchemas('globalStore'),
        this.loadClusters(),
        this.loadProjects(),
        this.loadPreferences(),
        this.loadPublicSettings(),
      ];

      const globalStore = get(this, 'globalStore');

      if ( !isPopup ) {
        list.addObjects([
          this.preload('roleTemplate', 'globalStore', {url: 'roleTemplates'}),
          this.preload('noedPool', 'globalStore', {url: 'nodePools'}),
          this.preload('noedTemplates', 'globalStore', {url: 'nodeTemplates'}),
          this.preload('clusterRoleTemplateBindings', 'globalStore', {url: 'clusterRoleTemplateBindings'}),
          this.preload('projectRoleTemplateBinding', 'globalStore', {url: 'projectRoleTemplateBinding'}),
          this.preload('globalRole', 'globalStore', {url: 'globalRole'}),
          this.preload('globalRoleBinding', 'globalStore', {url: 'globalRoleBinding'}),
          this.preload('user', 'globalStore', {url: 'user'}).then((users) => {
            users.forEach((u) => {
              globalStore._typeify({
                id: u.principalIds[0],
                type: 'principal',
                principalType: 'user',
                provider: 'local',
                name: get(u,'displayName'),
                loginName: get(u,'username'),
              });
            });
          }),

          globalStore.findAll('principal').then((principals) => {
            principals.forEach((p) => {
              set(p, '_mine', true);
            });
          }),
        ]);
      }

      return PromiseAll(list)
    }).catch((err) => {
      return this.loadingError(err, transition);
    });
  },

  setupController(/*controller, model*/) {
    this._super(...arguments);
    get(this, 'scope').finishSwitchToGlobal();
  },<commit_msg>Fix github username issue<commit_after>import $ from 'jquery';
import C from 'ui/utils/constants';
import Route from '@ember/routing/route';
import Preload from 'ui/mixins/preload';
import { inject as service } from '@ember/service';
import { scheduleOnce, later, cancel } from '@ember/runloop';
import { resolve, all as PromiseAll } from 'rsvp';
import { get, set } from '@ember/object';

const CHECK_AUTH_TIMER = 60*10*1000;

export default Route.extend(Preload, {
  access:       service(),
  globalStore:  service(),
  clusterStore: service(),
  cookies:      service(),
  language:     service('user-language'),
  modalService: service('modal'),
  prefs:        service(),
  scope:        service(),
  settings:     service(),
  storeReset:   service(),
  intl:         service(),
  growl:        service(),
  userTheme:    service('user-theme'),

  testTimer:    null,

  beforeModel() {
    this._super(...arguments);

    set(this, 'testTimer', later(() => {
      this.testAuthToken();
    }, CHECK_AUTH_TIMER));

    return this.testAuthToken();
  },

  testAuthToken() {
    return get(this,'access').testAuth().catch(() => {
      this.transitionTo('login');
      this.send('logout',null);
    });
  },

  model(params, transition) {
    get(this,'session').set(C.SESSION.BACK_TO, undefined);

    const isPopup = this.controllerFor('application').get('isPopup');

    return get(this, 'scope').startSwitchToGlobal(!isPopup).then(() => {
      const list = [
        this.loadSchemas('globalStore'),
        this.loadClusters(),
        this.loadProjects(),
        this.loadPreferences(),
        this.loadPublicSettings(),
      ];

      const globalStore = get(this, 'globalStore');

      if ( !isPopup ) {
        list.addObjects([
          this.preload('roleTemplate', 'globalStore', {url: 'roleTemplates'}),
          this.preload('noedPool', 'globalStore', {url: 'nodePools'}),
          this.preload('noedTemplates', 'globalStore', {url: 'nodeTemplates'}),
          this.preload('clusterRoleTemplateBindings', 'globalStore', {url: 'clusterRoleTemplateBindings'}),
          this.preload('projectRoleTemplateBinding', 'globalStore', {url: 'projectRoleTemplateBinding'}),
          this.preload('globalRole', 'globalStore', {url: 'globalRole'}),
          this.preload('globalRoleBinding', 'globalStore', {url: 'globalRoleBinding'}),
          this.preload('user', 'globalStore', {url: 'user'}).then((users) => {
            users.forEach((u) => {
              globalStore._typeify({
                id: u.principalIds[0],
                type: 'principal',
                principalType: 'user',
                provider: 'local',
                name: get(u,'displayName'),
                loginName: get(u,'username'),
              });
            });
          }),

          globalStore.findAll('principal').then((principals) => {
            const me = principals.filter(p => p.me === true);
            if (me.length > 0) {
              set(this, 'access.me', get(me, 'firstObject'));
            }
            principals.forEach((p) => {
              set(p, '_mine', true);
            });
          }),
        ]);
      }

      return PromiseAll(list)
    }).catch((err) => {
      return this.loadingError(err, transition);
    });
  },

  setupController(/*controller, model*/) {
    this._super(...arguments);
    get(this, 'scope').finishSwitchToGlobal();
  },
{'fraction_non_alphanumeric': 0.16704425313396767, 'fraction_numerical': 0.0028696571514876907, 'mean_word_length': 2.6707317073170733, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '6783727', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1906, 'n_words': 361}