Skip to content

Commit

Permalink
Adds the ability to search for an app. Counter still needs to be upda…
Browse files Browse the repository at this point in the history
…ted.
  • Loading branch information
creoludifico committed Jan 20, 2017
1 parent dc6bfbc commit 156631c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
11 changes: 11 additions & 0 deletions http/jscript/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,17 @@ webtools.dynamicSort = function(property) {
}
}

//Find in string - Wildcard and insentetive search
function _searchInString(str, value) {
return new RegExp(value.toLowerCase().trim()).test(str.toLowerCase().trim());
}
webtools.searchBundle = function (bundle, value) {
value.replace("*", "");
return $.grep(bundle, function (obj) {
return _searchInString(obj.title, value) || _searchInString(obj.description, value);
});
}

webtools.searchkeyword = function(tablename) {
webtools.keywordarray = [];
webtools.currentkeyword = 0;
Expand Down
1 change: 1 addition & 0 deletions http/modules/install/css/install.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
.aligncenter {text-align: center;}
.subheadline {font-weight: bold; margin-right: 5px;}
.installhidden {display: none;}
.search{max-width:250px}

.branch-dropdown {
margin-right: 4px;
Expand Down
50 changes: 44 additions & 6 deletions http/modules/install/jscript/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ webtools.functions.install = {
},
items_per_page_max: 50,
items_per_page_min: 5,
show_options: function() {},
search_apps: function () { },
show_options: function () { },
save_options: function() {},
initiatedownload: function() {},
loadChannels: function() {},
Expand All @@ -18,6 +19,7 @@ webtools.functions.install = {
removebundleconfirm: function() {},
removebundlework: function() {},
allBundles: {},
backupAllBundles: {},
initiatemigrate: function() {},
updatefrompreferences: function() {},
massiveupdateongoinginstalls: 0,
Expand Down Expand Up @@ -54,7 +56,7 @@ install.start = function() {

var submenu = ['<table class="table channeltable">',
'<tr>',
'<td id="installmenu" class="channelmenu"><button class="btn btn-default" onclick="javascript:install.show_quickjump();">Quick Jump To Bundle</button> <button type="button" class="btn btn-default" onClick="install.initiatemigrate();">Migrate manually/previously installed channels</button> <button type="button" class="btn btn-default" onClick="install.massiveupdatechecker();">Check for updates for all installed channels</button> <button type="button" class="btn btn-default" onClick="install.forceRepoUpdate();">Force repo update</button></td>',
'<td id="installmenu" class="channelmenu"><input type="text" class="form-control pull-left search" placeholder="Search..." id="search"><div class="input-group-btn pull-left"><button class="btn btn-secondary" type="button" onclick="javascript:install.search_apps();">Search</button></div><button class="btn btn-default" onclick="javascript:install.show_quickjump();">Quick Jump To Bundle</button> <button type="button" class="btn btn-default" onClick="install.initiatemigrate();">Migrate manually/previously installed channels</button> <button type="button" class="btn btn-default" onClick="install.massiveupdatechecker();">Check for updates for all installed channels</button> <button type="button" class="btn btn-default" onClick="install.forceRepoUpdate();">Force repo update</button></td>',
'</tr>',
'<tr>',
'<td id="channelmenu" class="channelmenu"></td>',
Expand Down Expand Up @@ -94,6 +96,43 @@ install.start = function() {
launcher.start();
};

//Hackz: Size of weird object received from backend. TODO: Get list from backend not object.
Object.size = function (obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};

//Searching in allBundles for keyword.
//Will look in description and title
install.search_apps = function () {
var searchValue = $("#search").val();

if (Object.size(install.backupAllBundles) > Object.size(install.allBundles)) install.allBundles = install.backupAllBundles;
var allBundles = install.allBundles;

install.backupAllBundles = install.allBundles;

//Temp array.. TODO: Get list from backend instead
var tempArray = [];
for (var key in allBundles) {
allBundles[key].key = key;
tempArray.push(allBundles[key]);
}

tempArray = webtools.searchBundle(tempArray, searchValue);

install.allBundles = {};
tempArray.forEach(function (object) {
var tempkey = object.key;
delete object.key;
install.allBundles[tempkey] = object;
})
install.showChannels($('#channelmenu>button.btn-active'), $('#channelmenu>button.btn-active').attr('id'));
}

install.show_options = function() {
webtools.loading();
$('#myModalLabel').html('Preferences');
Expand Down Expand Up @@ -141,7 +180,7 @@ install.installfromgit = function(github) {
},
type: 'GET',
dataType: 'text',
success: function(data) {
success: function (data) {
$('#myModalBody').html('Done. Your channel has been successfully installed. Data will be refreshed from the server.');
$('#myModalFoot').html('<button type="button" class="btn btn-default" onclick="$(\'#gitlink\').val(\'\');install.loadChannels();" data-dismiss="modal">Close</button>');
},
Expand All @@ -157,8 +196,7 @@ install.installfromgit = function(github) {
/*
Fetch channels and get a list of types (categories)
*/
install.loadChannels = function(InitalRun) {

install.loadChannels = function (InitalRun) {
webtools.loading();
$('#navfoot').html('');
if (typeof($('#channelmenu>button.btn-active').html()) != 'undefined') {
Expand Down Expand Up @@ -301,7 +339,7 @@ install.loadChannels = function(InitalRun) {
/*
Show channels that are of a specific type (category)
*/
install.showChannels = function(button, type, page, highlight) {
install.showChannels = function (button, type, page, highlight) {
webtools.loading();

if (typeof(highlight) != 'undefined') {
Expand Down

0 comments on commit 156631c

Please sign in to comment.