Skip to content

Commit

Permalink
Update Global search
Browse files Browse the repository at this point in the history
  • Loading branch information
smurfpandey committed Mar 16, 2015
1 parent f2071a7 commit 3b6c5be
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
3 changes: 3 additions & 0 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<button class="btn btn-default" id="btnSearchDB" type="button">Go!</button>
</span>
</div><!-- /input-group -->
<div id="dvClearSearch" class="hide">
Search is on: <a href="#" id="btnClearSearch" class="btn btn-link">Clear</a>
</div>
</div>
<div id="database-tree">
<ul id="databases"></ul>
Expand Down
44 changes: 36 additions & 8 deletions static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1502,9 +1502,18 @@ $(document).ready(function() {
loadDatabases();
});

$('#txtSearch').on('keypress', function(e) {
if (e.keyCode === 13) {
$('#btnSearchDB').trigger('click');
}
});
$('#btnSearchDB').on('click', function(e) {
var searchQuery = $.trim($('#txtSearch').val());

if (searchQuery.length === 0) {
return;
}

apiSearchDatabase(searchQuery, function(data) {
if (data.error) {
return;
Expand Down Expand Up @@ -1535,48 +1544,56 @@ $(document).ready(function() {
var dbTable = {
label: 'Table',
type: 'tbl-holder',
children: []
children: [],
data_loaded: true
};
var dbProc = {
label: 'Procedure',
children: [],
type: 'sp-holder'
type: 'sp-holder',
data_loaded: true
};
var dbFunc = {
label: 'Function',
children: [],
type: 'fn-holder'
type: 'fn-holder',
data_loaded: true
};
var dbView = {
label: 'View',
children: [],
type: 'vw-holder'
type: 'vw-holder',
data_loaded: true
};


objData[dbName].forEach(function(val) {
if (val.type === 'TBL') {
dbTable.children.push({
label: val.name,
type: 'table'
type: 'table',
load_on_demand: true
});
} else if (val.type === 'PROC') {
dbProc.children.push({
label: val.name,
type: 'procedure'
type: 'procedure',
load_on_demand: true
});
} else if (val.type === 'FUNC') {
dbFunc.children.push({
label: val.name,
type: 'function'
type: 'function',
load_on_demand: true
});
}
});

objTree.push({
label: dbName,
type: 'database',
children: [dbTable, dbProc, dbFunc]
children: [dbTable, dbProc, dbFunc],
data_loaded: true
});
});
console.log(objTree);
Expand All @@ -1600,9 +1617,20 @@ $(document).ready(function() {
);

$tree.tree('selectNode', null);

//Show the clear search option
$('#dvClearSearch').removeClass('hide');
});
});

$('#btnClearSearch').on('click', function(e) {
loadDatabases();
//Show the clear search option
$('#dvClearSearch').addClass('hide');
$('#txtSearch').val('');
e.preventDefault();
});

initModals();

initEditor("custom_query");
Expand Down

0 comments on commit 3b6c5be

Please sign in to comment.