angular
  .module('Dbview.DbController', ['ui.router'])
  .controller('DbController', ['$scope', '$http', '$location', 'dbService', 'tableService', '$state', '$timeout', dbController])

function dbController($scope, $http, $location, dbService, tableService, $state, $timeout) {
  $scope.tablenames = dbService.tables;
  $scope.tableData = {};
  $scope.onlineTables = tableService.activeTables

  // make post request to download a specific table
  $scope.requestTable = function (table) {
    console.log(table);
    $http({
      method: 'POST',
      url: '/requestTable',
      headers: {
        'Content-Type': 'application/json'
      },
      data: { creds: dbService.creds, table }
    })
      .then((response) => {

        // add this table to the nav bar
        activateTable($scope, table, tableService);

         // save the data in table service
        tableService.addTableData(table, response.data);
      });
  }
  // view a specific table (actual tablename is passed via $stateParams)
  $scope.viewTable = function (table) {
    tableService.currentTable = table;
  }
  // add table to nav bar if not already there
  function activateTable($scope, table, tableService) {
    if (!$scope.onlineTables.includes(table)) {
      tableService.activateTable(table);
      $scope.onlineTables = tableService.activeTables
    }
  }
  // add table data to table service
  function addTableData($scope, table, data) {
    console.log(data);
    if ($scope.tableData[table] === undefined) {
      $scope.tableData[table] = data;
    }
  }
}








@@ -769,16 +769,23 @@
         
+$scope.
 activate
@@ -820,16 +820,16 @@
 rvice);%0A
-
 %0A       
@@ -1140,25 +1140,23 @@
 there%0A  
-function 
+$scope.
 activate
@@ -1152,32 +1152,43 @@
 pe.activateTable
+ = function
 ($scope, table, 
@@ -1360,211 +1360,8 @@
   %7D%0A
-  // add table data to table service%0A  function addTableData($scope, table, data) %7B%0A    console.log(data);%0A    if ($scope.tableData%5Btable%5D === undefined) %7B%0A      $scope.tableData%5Btable%5D = data;%0A    %7D%0A  %7D
 %0A%7D%0A%0A

Move dbController fns onto scope