<commit_before>app.controller('SideBarController', ['$scope', '$http', '$timeout', '$rootScope', '$log', 'pageStateService', 'retryHttp', function($scope, $http, $timeout, $rootScope, $log, pageStateService, retryHttp) {
  $scope.query = "";
  $scope.selectedPageInTree = function(branch) {
    $log.debug("CLICKED ON");
    $log.debug(branch);
    changePage($http,branch.fqn,pageStateService,null);
  };
  $scope.my_data = [];
  $scope.my_tree = {};
  $scope.queryPageExists = false;
  $scope.showMenu = true;

  // The user has pressed enter on a query.  Go to the page or create
  // a new page if it does not exist.
  $scope.submit = function() {
    if ($scope.query.length==0) {
      return;
    }

    // TODO: queryPageExists is updated too late, make a new check for
    // this when we switch to ajax page changes.
    if ($scope.queryPageExists) {
      window.location = "/view/"+$scope.query;
    } else {
      var user = pageStateService.get('user');
      if (user) {
        var pageDetails = pageStateService.get('pageDetails');
        var newParentId = null;
        if (pageDetails) {
          newParentId = pageDetails.page._id;
        }
        $log.debug("Creating page");
        retryHttp.post(
          '/service/createPage',
          {name:$scope.query, parentId:newParentId},
          function(data, status, headers, config) {
            $log.debug("Created page");
            var newPageFQN = data;
            $scope.query = '';
            changePage($http,newPageFQN,pageStateService, function() {
              pageStateService.set('settingsActive', true);
              pageStateService.set('editMode',true);
            });
          });
      } else {
        window.location = "/login";
      }
    }
  };

  $scope.$on('pageStateServiceUpdate', function(event, response) {
    var key = response.key;
    var value = response.value;
    
    if (key == 'editMode' || key == 'pageMode') {
      // editmode/pagemode changed.  Maybe remove the query or hide
      // the whole menu.
      var editMode = pageStateService.get('editMode');
      var pageMode = pageStateService.get('pageMode');
      if (editMode || pageMode=='diff') {
        $log.debug("NOT SHOWING MENU: " + editMode + " " + pageMode);
        $scope.showMenu = false;
      }

      if (editMode && pageStateService.get('query')) {
        query = null;
        pageStateService.set('query',null);
      }
      if (editMode && pageStateService.get('searchContentResults')) {
        pageStateService.set('searchContentResults',null);
      }
    }

    else if (key == 'query' || key == 'user' || key == 'pageDetails') {
      if (key == 'pageDetails') {
        var pageDetails = value;
        $log.debug("Selecting branch " + pageDetails.page.name);
        $scope.my_tree.select_branch_by_name(pageDetails.page.name);<commit_msg>Fix bug where sidebar was not returning after an edit completed.<commit_after>app.controller('SideBarController', ['$scope', '$http', '$timeout', '$rootScope', '$log', 'pageStateService', 'retryHttp', function($scope, $http, $timeout, $rootScope, $log, pageStateService, retryHttp) {
  $scope.query = "";
  $scope.selectedPageInTree = function(branch) {
    $log.debug("CLICKED ON");
    $log.debug(branch);
    changePage($http,branch.fqn,pageStateService,null);
  };
  $scope.my_data = [];
  $scope.my_tree = {};
  $scope.queryPageExists = false;
  $scope.showMenu = true;

  // The user has pressed enter on a query.  Go to the page or create
  // a new page if it does not exist.
  $scope.submit = function() {
    if ($scope.query.length==0) {
      return;
    }

    // TODO: queryPageExists is updated too late, make a new check for
    // this when we switch to ajax page changes.
    if ($scope.queryPageExists) {
      window.location = "/view/"+$scope.query;
    } else {
      var user = pageStateService.get('user');
      if (user) {
        var pageDetails = pageStateService.get('pageDetails');
        var newParentId = null;
        if (pageDetails) {
          newParentId = pageDetails.page._id;
        }
        $log.debug("Creating page");
        retryHttp.post(
          '/service/createPage',
          {name:$scope.query, parentId:newParentId},
          function(data, status, headers, config) {
            $log.debug("Created page");
            var newPageFQN = data;
            $scope.query = '';
            changePage($http,newPageFQN,pageStateService, function() {
              pageStateService.set('settingsActive', true);
              pageStateService.set('editMode',true);
            });
          });
      } else {
        window.location = "/login";
      }
    }
  };

  $scope.$on('pageStateServiceUpdate', function(event, response) {
    var key = response.key;
    var value = response.value;
    
    if (key == 'editMode' || key == 'pageMode') {
      // editmode/pagemode changed.  Maybe remove the query or hide
      // the whole menu.
      var editMode = pageStateService.get('editMode');
      var pageMode = pageStateService.get('pageMode');
      if (editMode || pageMode=='diff') {
        $log.debug("NOT SHOWING MENU: " + editMode + " " + pageMode);
        $scope.showMenu = false;
      } else {
        $scope.showMenu = true;
      }

      if (editMode && pageStateService.get('query')) {
        query = null;
        pageStateService.set('query',null);
      }
      if (editMode && pageStateService.get('searchContentResults')) {
        pageStateService.set('searchContentResults',null);
      }
    }

    else if (key == 'query' || key == 'user' || key == 'pageDetails') {
      if (key == 'pageDetails') {
        var pageDetails = value;
        $log.debug("Selecting branch " + pageDetails.page.name);
        $scope.my_tree.select_branch_by_name(pageDetails.page.name);
{'fraction_non_alphanumeric': 0.14677474991376338, 'fraction_numerical': 0.00034494653328734045, 'mean_word_length': 2.5730129390018486, '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': '1847143', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1719, 'n_words': 386}