<commit_before>'use strict';

/**
 * @ngdoc function
 * @name cnodejs.controllers:TopicCtrl
 * @description
 * # TopicCtrl
 * Topic Controller of the cnodejs app
 */

angular.module('cnodejs.controllers')
.controller('TopicCtrl', function($scope, $rootScope, $stateParams, $timeout, $ionicLoading, $ionicActionSheet, $ionicScrollDelegate, $log, Topics, Topic, User) {
  $log.debug('topic ctrl', $stateParams);
  var id = $stateParams.id;
  var topic = Topics.getById(id);
  $scope.topic = topic;

  // before enter view event
  $scope.$on('$ionicView.beforeEnter', function() {
    // track view
    if (window.analytics) {
      window.analytics.trackView('topic view');
    }
  });

  // load topic data
  $scope.loadTopic = function(reload) {
    var topicResource;
    if (reload === true) {
      topicResource = Topic.get(id);
    } else {
      topicResource = Topic.getById(id);
    }
    return topicResource.$promise.then(function(response) {
        $scope.topic = response.data;
      }, $rootScope.requestErrorHandler({
        noBackdrop: true
      }, function() {
        $scope.loadError = true;
      })
    );
  };
  $scope.loadTopic();

  // do refresh
  $scope.doRefresh = function() {
    return $scope.loadTopic(true).then(function(response) {
        $log.debug('do refresh complete');
      }, function() {
      }).finally(function() {
        $scope.$broadcast('scroll.refreshComplete');
      });
  };

  $scope.replyData = {
    content: ''
  };

  // save reply
  $scope.saveReply = function() {
    $log.debug('new reply data:', $scope.replyData);
    $ionicLoading.show();
    Topic.saveReply(id, $scope.replyData).$promise.then(function(response) {
      $ionicLoading.hide();
      $log.debug('post reply response:', response);
      $scope.loadTopic(true).then(function() {
        $ionicScrollDelegate.scrollBottom();
      });
    }, $rootScope.requestErrorHandler);
  };<commit_msg>chore: Reset reply content after reply<commit_after>'use strict';

/**
 * @ngdoc function
 * @name cnodejs.controllers:TopicCtrl
 * @description
 * # TopicCtrl
 * Topic Controller of the cnodejs app
 */

angular.module('cnodejs.controllers')
.controller('TopicCtrl', function($scope, $rootScope, $stateParams, $timeout, $ionicLoading, $ionicActionSheet, $ionicScrollDelegate, $log, Topics, Topic, User) {
  $log.debug('topic ctrl', $stateParams);
  var id = $stateParams.id;
  var topic = Topics.getById(id);
  $scope.topic = topic;

  // before enter view event
  $scope.$on('$ionicView.beforeEnter', function() {
    // track view
    if (window.analytics) {
      window.analytics.trackView('topic view');
    }
  });

  // load topic data
  $scope.loadTopic = function(reload) {
    var topicResource;
    if (reload === true) {
      topicResource = Topic.get(id);
    } else {
      topicResource = Topic.getById(id);
    }
    return topicResource.$promise.then(function(response) {
        $scope.topic = response.data;
      }, $rootScope.requestErrorHandler({
        noBackdrop: true
      }, function() {
        $scope.loadError = true;
      })
    );
  };
  $scope.loadTopic();

  // do refresh
  $scope.doRefresh = function() {
    return $scope.loadTopic(true).then(function(response) {
        $log.debug('do refresh complete');
      }, function() {
      }).finally(function() {
        $scope.$broadcast('scroll.refreshComplete');
      });
  };

  $scope.replyData = {
    content: ''
  };

  // save reply
  $scope.saveReply = function() {
    $log.debug('new reply data:', $scope.replyData);
    $ionicLoading.show();
    Topic.saveReply(id, $scope.replyData).$promise.then(function(response) {
      $ionicLoading.hide();
      $scope.replyData.content = '';
      $log.debug('post reply response:', response);
      $scope.loadTopic(true).then(function() {
        $ionicScrollDelegate.scrollBottom();
      });
    }, $rootScope.requestErrorHandler);
  };
{'fraction_non_alphanumeric': 0.16043054843669913, 'fraction_numerical': 0.0, 'mean_word_length': 3.165421558164354, 'pattern_counts': {'":': 0, '<': 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': '1975561', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1206, 'n_words': 224}