Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Better search functionality
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Oct 11, 2016
commit d831156d78d953ebc3cd16ea03f508649fdc1a9c
28 changes: 23 additions & 5 deletions settings/js/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,24 @@ OC.Settings.Apps = OC.Settings.Apps || {
);
},

/**
* Splits the query by spaces and tries to find all substring in the app
* @param {string} string
* @param {string} query
* @returns {boolean}
*/
_search: function(string, query) {
var keywords = query.split(' '),
stringLower = string.toLowerCase(),
found = true;

_.each(keywords, function(keyword) {
found = found && stringLower.indexOf(keyword) !== -1;
});

return found;
},

filter: function(query) {
var $appList = $('#apps-list'),
$emptyList = $('#apps-list-empty');
Expand All @@ -510,17 +528,17 @@ OC.Settings.Apps = OC.Settings.Apps || {

// App Name
var apps = _.filter(OC.Settings.Apps.State.apps, function (app) {
return app.name.toLowerCase().indexOf(query) !== -1;
return OC.Settings.Apps._search(app.name, query);
});

// App ID
apps = apps.concat(_.filter(OC.Settings.Apps.State.apps, function (app) {
return app.id.toLowerCase().indexOf(query) !== -1;
return OC.Settings.Apps._search(app.id, query);
}));

// App Description
apps = apps.concat(_.filter(OC.Settings.Apps.State.apps, function (app) {
return app.description.toLowerCase().indexOf(query) !== -1;
return OC.Settings.Apps._search(app.description, query);
}));

// Author Name
Expand All @@ -540,9 +558,9 @@ OC.Settings.Apps = OC.Settings.Apps || {
}
}
});
return authors.join(' ').toLowerCase().indexOf(query) !== -1;
return OC.Settings.Apps._search(authors.join(' '), query);
}
return app.author.toLowerCase().indexOf(query) !== -1;
return OC.Settings.Apps._search(app.author, query);
}));

// App status
Expand Down