<commit_before>//spice.service.js
angular
  .module('allSpiceApp')
  .factory('spiceApi', spiceApi);

spiceApi.$inject = ['$firebaseArray', '$firebaseRef', 'authService'];

function spiceApi($firebaseArray, $firebaseRef, authService) {
  var 
  _spiceObj = null,
      timestamp = new Date(),
      arr = $firebaseArray($firebaseRef.spices),
      tagList,
      spiceApi = {
        getAll: getAll,
        getObj: getObj,
        setObj: setObj,
        add: add,
        update: update,
        remove: remove,
        togglePin: togglePin,
        getTagList: getTagList
      };      

  return spiceApi;
  ////////////
  
  function getAll() {
    //var query = ref.orderByKey().limitToLast(100);      
    //return $firebaseArray(query);    
    return arr;
  };

  function getObj() {
    return _spiceObj;
  };

  function setObj(spiceObj) {
    _spiceObj = spiceObj;
  };

  function add(spiceObj) {
    var spiceArr = spiceApi.getAll();      
    spiceObj.timestamp = Firebase.ServerValue.TIMESTAMP;
    spiceObj.user = authService.getUser();

    console.log(spiceObj);
    return spiceArr.$add(spiceObj);
  };

  function update(spiceObj) {
    var spiceArr = spiceApi.getAll();
    spiceObj.timestamp = Firebase.ServerValue.TIMESTAMP;

    console.log(spiceObj);
    spiceArr.$save(spiceObj)
  };

  function remove(spiceObj) {
    var spiceArr = spiceApi.getAll();

    console.log(spiceObj);
    spiceArr.$remove(spiceObj);      
  };

  function togglePin(spiceObj) {
    var user = authService.getUser();

    if (spiceObj.user.uid !== user.uid) {
      if (!spiceObj.pinnedUsers) 
        spiceObj.pinnedUsers = {};    

      spiceObj.pinnedUsers[user.uid] = !(spiceObj.pinnedUsers[user.uid] === true);       
      spiceApi.update(spiceObj);
    }
  };
  
  function getTagList() {
    /*return $firebaseRef.tags.once('value').then(function (data) {
      return Object.keys(data).map(function (item) {
        return { "text": item };
      });
      
      //if (!tagList) {
      //  tagList = ;
      //}
      
      //return tagList;
    });*/
    return [{ 'text': 'appetizer' }, { 'text': 'dessert' }];
  };
};<commit_msg>fixed taglist<commit_after>//spice.service.js
angular
  .module('allSpiceApp')
  .factory('spiceApi', spiceApi);

spiceApi.$inject = ['$firebaseArray', '$firebaseRef', '$q', 'authService'];

function spiceApi($firebaseArray, $firebaseRef, $q, authService) {
  var 
    _spiceObj = null,
    timestamp = new Date(),
    arr = $firebaseArray($firebaseRef.spices),
    tagRef = $firebaseRef.tags,
    tagList,
    spiceApi = {
      getAll: getAll,
      getObj: getObj,
      setObj: setObj,
      add: add,
      update: update,
      remove: remove,
      togglePin: togglePin,
      getTagList: getTagList
    };

  return spiceApi;
  ////////////
  
  function getAll() {
    //var query = ref.orderByKey().limitToLast(100);      
    //return $firebaseArray(query);    
    return arr;
  };

  function getObj() {
    return _spiceObj;
  };

  function setObj(spiceObj) {
    _spiceObj = spiceObj;
  };

  function add(spiceObj) {
    var spiceArr = spiceApi.getAll();      
    spiceObj.timestamp = Firebase.ServerValue.TIMESTAMP;
    spiceObj.user = authService.getUser();

    console.log(spiceObj);
    return spiceArr.$add(spiceObj);
  };

  function update(spiceObj) {
    var spiceArr = spiceApi.getAll();
    spiceObj.timestamp = Firebase.ServerValue.TIMESTAMP;

    console.log(spiceObj);
    spiceArr.$save(spiceObj)
  };

  function remove(spiceObj) {
    var spiceArr = spiceApi.getAll();

    console.log(spiceObj);
    spiceArr.$remove(spiceObj);      
  };

  function togglePin(spiceObj) {
    var user = authService.getUser();

    if (spiceObj.user.uid !== user.uid) {
      if (!spiceObj.pinnedUsers) 
        spiceObj.pinnedUsers = {};    

      spiceObj.pinnedUsers[user.uid] = !(spiceObj.pinnedUsers[user.uid] === true);       
      spiceApi.update(spiceObj);
    }
  };
  
  function getTagList() {
    if (!tagList) {
      return tagRef.once('value').then(function (data) {
        tagList = Object.keys(data.val()).map(function (item) {
          return { "text": item };
        }); 
        
        return tagList;
      });
    }
    else {
      var deferred = $q.defer();
      deferred.resolve(tagList);
      return deferred.promise;
    }
  };
};
{'fraction_non_alphanumeric': 0.1466451464145723, 'fraction_numerical': 0.001383444777495965, 'mean_word_length': 2.504038772213247, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '4803188', 'n_tokens_mistral': 1514, 'n_tokens_neox': 1458, 'n_words': 250}