<commit_before>'use strict';

/**
 * @ngdoc function
 * @name cnodejs.services:TopicsService
 * @description
 * # TopicsService
 * Topics Service of the cnodejs app
 */

angular.module('cnodejs.services')
.factory('Topics', function(ENV, $resource, $log, User) {
  var topics = [];
  var currentTab = 'all';
  var currentPage = 1;
  var hasNextPage = true;
  var resource =  $resource(ENV.api + '/topics', {
  }, {
    query: {
      method: 'get',
      params: {
        tab: 'all',
        page: 1,
        limit: 10,
        mdrender: true
      }
    }
  });
  var getTopics = function(tab, page, callback) {
    resource.query({
      tab: tab,
      page: page
    }, function(r) {
      $log.debug('get topics tab:', tab, 'page:', page, 'data:', r.data);
      return callback && callback(r);
    });
  };
  return {
    refresh: function(callback) {
      getTopics(currentTab, 0, function(response) {
        currentPage = 1;
        topics = response.data;
        return callback && callback(response);
      });
    },
    pagination: function(callback) {
      getTopics(currentTab, currentPage, function(response) {
        if (response.data.length < 10) {
          $log.debug('response data length', response.data.length);
          hasNextPage = false;
        }
        currentPage++;
        topics = topics.concat(response.data);
        return callback && callback(response);
      });
    },
    currentTab: function(newTab) {
      if (typeof newTab !== 'undefined') {
        currentTab = newTab;
      }
      return currentTab;
    },
    hasNextPage: function(has) {
      if (typeof has !== 'undefined') {
        hasNextPage = has;
      }
      return hasNextPage;
    },
    resetData: function() {
      topics = [];
      currentPage = 0;
      hasNextPage = true;
    },
    getCurrentPage: function() {
      return currentPage;
    },
    getTopics: function() {
      return topics;
    },
    getById: function(id) {

      if (!!topics) {
        for (var i = 0; i < topics.length; i++) {
          if (topics[i].id === id) {
            return topics[i];
          }
        }
      } else {
        return null;
      }
    },
    saveNewTopic: function(newTopicData, callback) {<commit_msg>fix: Topic list refresh and pagination<commit_after>'use strict';

/**
 * @ngdoc function
 * @name cnodejs.services:TopicsService
 * @description
 * # TopicsService
 * Topics Service of the cnodejs app
 */

angular.module('cnodejs.services')
.factory('Topics', function(ENV, $resource, $log, User) {
  var topics = [];
  var currentTab = 'all';
  var nextPage = 1;
  var hasNextPage = true;
  var resource =  $resource(ENV.api + '/topics', {
  }, {
    query: {
      method: 'get',
      params: {
        tab: 'all',
        page: 1,
        limit: 10,
        mdrender: true
      }
    }
  });
  var getTopics = function(tab, page, callback) {
    resource.query({
      tab: tab,
      page: page
    }, function(r) {
      $log.debug('get topics tab:', tab, 'page:', page, 'data:', r.data);
      return callback && callback(r);
    });
  };
  return {
    refresh: function(callback) {
      getTopics(currentTab, 1, function(response) {
        nextPage = 2;
        hasNextPage = true;
        topics = response.data;
        return callback && callback(response);
      });
    },
    pagination: function(callback) {
      getTopics(currentTab, nextPage, function(response) {
        if (response.data.length < 10) {
          $log.debug('response data length', response.data.length);
          hasNextPage = false;
        }
        nextPage++;
        topics = topics.concat(response.data);
        return callback && callback(response);
      });
    },
    currentTab: function(newTab) {
      if (typeof newTab !== 'undefined') {
        currentTab = newTab;
      }
      return currentTab;
    },
    hasNextPage: function(has) {
      if (typeof has !== 'undefined') {
        hasNextPage = has;
      }
      return hasNextPage;
    },
    resetData: function() {
      topics = [];
      nextPage = 1;
      hasNextPage = true;
    },
    getTopics: function() {
      return topics;
    },
    getById: function(id) {

      if (!!topics) {
        for (var i = 0; i < topics.length; i++) {
          if (topics[i].id === id) {
            return topics[i];
          }
        }
      } else {
        return null;
      }
    },
    saveNewTopic: function(newTopicData, callback) {
{'fraction_non_alphanumeric': 0.14195583596214512, 'fraction_numerical': 0.004506534474988734, 'mean_word_length': 2.089074460681976, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5292057', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1370, 'n_words': 321}