<commit_before>'use strict';

/**
 * @namespace globals
 * @description get and set application global data
 */
const globals = (function() {

  const module    = {};
  const self      = module;

  module.allStates    = [];
  module.allTexts     = {};
  module.allEndPoints = {};

  module.currentState = {
		'state': 'main',
  	'section': ''
	};

  module.getAllStates = ()=> {
    return self.allStates;
  };

  module.loadAllStates = ()=> {
    let instanceRest = new ApiRest();
    let deferred     = Q.defer();
    let uri          = './shell/theme/states.json';

    instanceRest.getResource(uri).then(
      (data)=> {
        self.allStates = data.states;
        deferred.resolve(data);
      },
      (error) => {
        log.error('error get states: '+ error);
        deferred.reject();
      });
    return deferred.promise;
  };

  module.setCurrentState = (_state_, _section_)=> {
    if ( !_state_) {
      log.warning('dont set state if stage is not defined');
      return;
    }
    self.currentState.state    = _state_;
    self.currentState.section  =  _section_ ? _section_ : '';
  };

  module.getCurrentState = ()=> {
    return self.currentState;
  };

  module.getTexts = ()=> {
    return self.allTexts;
  };

  module.loadTexts = ()=> {
    let instanceRest = new ApiRest();
    let deferred     = Q.defer();
    let lang         = config.getLang();
    let uri          = './shell/theme/langs/' + lang + '.json';

    instanceRest.getResource(uri).then(
      (data)=> {
        self.allTexts = data;
        deferred.resolve(data);
      },
      (error) => {
        log.error('error loadTexts: '+ error);
        deferred.reject();
      });
    return deferred.promise;
  };

  module.loadRest = ()=> {
    let instanceRest = new ApiRest();
    let deferred     = Q.defer();
    let lang         = config.getLang();
    let uri          = './shell/theme/rest.json';

    instanceRest.getResource(uri).then(
      (data)=> {
        self.prepareRest(data);
        deferred.resolve();
      },
      (error) => {
        log.error('error load config rest: '+ error);
        deferred.reject();
      });
    return deferred.promise;
  };

  module.prepareRest = (data)=> {
    let environment = config.getEnvironment();
    let prefix      = data.generalData.baseUrl[environment];
    let suffix      = data.generalData.type[environment];

    for (let prop in data.endPoints) {
      self.allEndPoints[prop] = prefix + data.endPoints[prop] + suffix;
    }

  };

  module.getRest = ()=> {
    return self.allEndPoints;
  };

  return {
    getAllStates:     module.getAllStates,
    loadAllStates:    module.loadAllStates,
    getCurrentState:  module.getCurrentState,
    setCurrentState:  module.setCurrentState,<commit_msg>modificación para que los endpoints de distintos environments puedan ser diferentes<commit_after>'use strict';

/**
 * @namespace globals
 * @description get and set application global data
 */
const globals = (function() {

  const module    = {};
  const self      = module;

  module.allStates    = [];
  module.allTexts     = {};
  module.allEndPoints = {};

  module.currentState = {
		'state': 'main',
  	'section': ''
	};

  module.getAllStates = ()=> {
    return self.allStates;
  };

  module.loadAllStates = ()=> {
    let instanceRest = new ApiRest();
    let deferred     = Q.defer();
    let uri          = './shell/theme/states.json';

    instanceRest.getResource(uri).then(
      (data)=> {
        self.allStates = data.states;
        deferred.resolve(data);
      },
      (error) => {
        log.error('error get states: '+ error);
        deferred.reject();
      });
    return deferred.promise;
  };

  module.setCurrentState = (_state_, _section_)=> {
    if ( !_state_) {
      log.warning('dont set state if stage is not defined');
      return;
    }
    self.currentState.state    = _state_;
    self.currentState.section  =  _section_ ? _section_ : '';
  };

  module.getCurrentState = ()=> {
    return self.currentState;
  };

  module.getTexts = ()=> {
    return self.allTexts;
  };

  module.loadTexts = ()=> {
    let instanceRest = new ApiRest();
    let deferred     = Q.defer();
    let lang         = config.getLang();
    let uri          = './shell/theme/langs/' + lang + '.json';

    instanceRest.getResource(uri).then(
      (data)=> {
        self.allTexts = data;
        deferred.resolve(data);
      },
      (error) => {
        log.error('error loadTexts: '+ error);
        deferred.reject();
      });
    return deferred.promise;
  };

  module.loadRest = ()=> {
    let instanceRest = new ApiRest();
    let deferred     = Q.defer();
    let lang         = config.getLang();
    let uri          = './shell/theme/rest.json';

    instanceRest.getResource(uri).then(
      (data)=> {
        self.prepareRest(data);
        deferred.resolve();
      },
      (error) => {
        log.error('error load config rest: '+ error);
        deferred.reject();
      });
    return deferred.promise;
  };

  module.prepareRest = (data)=> {
    let environment = config.getEnvironment();
    let prefix      = data.generalData.baseUrl[environment];
    let suffix      = data.generalData.type[environment];

    for (let prop in data.endPoints[environment]) {
      self.allEndPoints[prop] = prefix + data.endPoints[environment][prop] + suffix;
    }

  };

  module.getRest = ()=> {
    return self.allEndPoints;
  };

  return {
    getAllStates:     module.getAllStates,
    loadAllStates:    module.loadAllStates,
    getCurrentState:  module.getCurrentState,
    setCurrentState:  module.setCurrentState,
{'fraction_non_alphanumeric': 0.14677591734948345, 'fraction_numerical': 0.0, 'mean_word_length': 2.320520402128918, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '6591505', 'n_tokens_mistral': 1759, 'n_tokens_neox': 1731, 'n_words': 339}