Skip to content

Commit

Permalink
Create function for each doe block
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Nov 4, 2014
1 parent 3593bdd commit 2af9608
Showing 1 changed file with 79 additions and 65 deletions.
144 changes: 79 additions & 65 deletions app/scripts/controllers/table-search-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,27 @@
*/
angular.module('groongaAdminApp')
.controller('TableSearchController', function ($scope, $routeParams, $location, $http) {
$scope.table = $routeParams.table;
$scope.style = 'table';
$scope.rawData = [];
$scope.columns = [];
$scope.records = [];
$scope.indexedColumns = [];
$scope.outputColumns = [];
$scope.commandLine = '';
$scope.message = '';
$scope.elapsedTimeInMilliseconds = 0;
$scope.nTotalRecords = 0;
$scope.parameters = angular.copy($location.search());
var client = new GroongaClient($http);

function initialize() {
$scope.table = $routeParams.table;
$scope.style = 'table';
$scope.rawData = [];
$scope.columns = [];
$scope.records = [];
$scope.indexedColumns = [];
$scope.outputColumns = [];
$scope.commandLine = '';
$scope.message = '';
$scope.elapsedTimeInMilliseconds = 0;
$scope.nTotalRecords = 0;
$scope.parameters = angular.copy($location.search());

$scope.search = function() {
$scope.search = search;
$scope.clear = clear;
}

function search() {
var matchColumns = $scope.indexedColumns
.filter(function(indexedColumn) {
return indexedColumn.inUse;
Expand All @@ -46,17 +53,17 @@ angular.module('groongaAdminApp')
'output_columns': outputColumns
});
$location.search(parameters);
};
}

$scope.clear = function() {
function clear() {
$location.search({});
};
}

var client = new GroongaClient($http);
client.execute('table_list')
.success(function(response) {
response.tables().forEach(function(table) {
client.execute('column_list', {table: table.name})
function fillOptions() {
client.execute('table_list')
.success(function(response) {
response.tables().forEach(function(table) {
client.execute('column_list', {table: table.name})
.success(function(response) {
response.columns().forEach(function(column) {
if (!column.isIndex) {
Expand All @@ -76,54 +83,61 @@ angular.module('groongaAdminApp')
});
});
});
});
});
});

client.execute('column_list', {table: $scope.table})
.success(function(response) {
var outputColumns = $scope.parameters.output_columns;
console.log(response.columns());
response.columns().forEach(function(column) {
if (column.isIndex) {
return;
}
var inUse = true;
if (outputColumns) {
inUse = outputColumns.indexOf(column.name) !== -1;
}
$scope.outputColumns.push({name: column.name, inUse: inUse});
client.execute('column_list', {table: $scope.table})
.success(function(response) {
var outputColumns = $scope.parameters.output_columns;
console.log(response.columns());
response.columns().forEach(function(column) {
if (column.isIndex) {
return;
}
var inUse = true;
if (outputColumns) {
inUse = outputColumns.indexOf(column.name) !== -1;
}
$scope.outputColumns.push({name: column.name, inUse: inUse});
});
});
});
}

var parameters = {
table: $scope.table
};
angular.forEach($scope.parameters, function(value, key) {
if (key in parameters) {
return;
}
parameters[key] = value;
});
var request = client.execute('select', parameters);
request.success(function(response) {
$scope.rawData = response.rawData();
$scope.commandLine = request.commandLine();
$scope.elapsedTimeInMilliseconds = response.elapsedTime() * 1000;
if (!response.isSuccess()) {
$scope.message =
'Failed to call "select" command: ' + response.errorMessage();
$scope.nTotalRecords = 0;
return;
}
$scope.nTotalRecords = response.nTotalRecords();
$scope.columns = response.columns();
$scope.records = response.records().map(function(record) {
return record.map(function(value, index) {
return {
value: value,
column: $scope.columns[index]
};
function select() {
var parameters = {
table: $scope.table
};
angular.forEach($scope.parameters, function(value, key) {
if (key in parameters) {
return;
}
parameters[key] = value;
});
var request = client.execute('select', parameters);
request.success(function(response) {
$scope.rawData = response.rawData();
$scope.commandLine = request.commandLine();
$scope.elapsedTimeInMilliseconds = response.elapsedTime() * 1000;
if (!response.isSuccess()) {
$scope.message =
'Failed to call "select" command: ' + response.errorMessage();
$scope.nTotalRecords = 0;
return;
}
$scope.nTotalRecords = response.nTotalRecords();
$scope.columns = response.columns();
$scope.records = response.records().map(function(record) {
return record.map(function(value, index) {
return {
value: value,
column: $scope.columns[index]
};
});
});
});
});
}

initialize();
fillOptions();
select();
});

0 comments on commit 2af9608

Please sign in to comment.