Skip to content

Commit

Permalink
Allow to search components by endpoints. Resolve Wirecloud#242
Browse files Browse the repository at this point in the history
  • Loading branch information
jpajuelo committed Oct 18, 2016
1 parent b99ed03 commit 2c4b23b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/wirecloud/catalogue/searchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class CatalogueResourceSchema(fields.SchemaClass):
users = fields.KEYWORD(commas=True)
groups = fields.KEYWORD(commas=True)
content = fields.NGRAMWORDS()
input_friendcodes = fields.KEYWORD()
output_friendcodes = fields.KEYWORD()


class CatalogueResourceSearcher(BaseSearcher):
Expand All @@ -66,12 +68,16 @@ def build_compatible_fields(self, resource):
resource_info = resource.get_processed_info(process_urls=False)

endpoint_descriptions = ''
input_friendcodes = []
output_friendcodes = []

for endpoint in resource_info['wiring']['inputs']:
endpoint_descriptions += endpoint['description'] + ' '
input_friendcodes.extend(endpoint['friendcode'].split(' '))

for endpoint in resource_info['wiring']['outputs']:
endpoint_descriptions += endpoint['description'] + ' '
output_friendcodes.extend(endpoint['friendcode'].split(' '))

fields = {
'pk': '%s' % resource.pk,
Expand All @@ -90,6 +96,8 @@ def build_compatible_fields(self, resource):
'smartphoneimage': resource_info['smartphoneimage'],
'users': ', '.join(resource.users.all().values_list('username', flat=True)),
'groups': ', '.join(resource.groups.all().values_list('name', flat=True)),
'input_friendcodes': ' '.join(set(input_friendcodes)),
'output_friendcodes': ' '.join(set(output_friendcodes)),
}

return fields
Expand Down
4 changes: 4 additions & 0 deletions src/wirecloud/commons/static/js/wirecloud/ui/MACSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
};
utils.inherit(MACSearch, StyledElements.StyledElement);

MACSearch.prototype.search = function search(keywords) {
this.inputField.setValue(keywords);
};

MACSearch.prototype.paintInfo = function paintInfo(message, context) {
if (context != null) {
message = builder.parse(builder.DEFAULT_OPENING + message + builder.DEFAULT_CLOSING, context);
Expand Down
28 changes: 28 additions & 0 deletions src/wirecloud/platform/static/js/wirecloud/ui/WiringEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,34 @@ Wirecloud.ui = Wirecloud.ui || {};
component.forEachEndpoint(bindEndpoint.bind(this));
this.initialMessage.hide();

var subMenuItem = new se.SubMenuItem(utils.gettext("Search component..."));
subMenuItem.menuItem.addIconClass("fa fa-search");

var menuItem1 = new se.MenuItem(utils.gettext("For both endpoints"), function () {
if (!this.btnFindComponents.active) {
this.btnFindComponents.click();
}
this.componentManager.searchComponents.search("input_friendcodes:(" + component.sourceFriendcodes.join(" OR ") + ") OR " + "output_friendcodes:(" + component.targetFriendcodes.join(" OR ") + ")");
}.bind(this));
var menuItem2 = new se.MenuItem(utils.gettext("For input endpoints"), function () {
if (!this.btnFindComponents.active) {
this.btnFindComponents.click();
}
this.componentManager.searchComponents.search("output_friendcodes:(" + component.targetFriendcodes.join(" OR ") + ")");
}.bind(this));
var menuItem3 = new se.MenuItem(utils.gettext("For output endpoints"), function () {
if (!this.btnFindComponents.active) {
this.btnFindComponents.click();
}
this.componentManager.searchComponents.search("input_friendcodes:(" + component.sourceFriendcodes.join(" OR ") + ")");
}.bind(this));

subMenuItem.append(menuItem1);
subMenuItem.append(menuItem2);
subMenuItem.append(menuItem3);

component.btnPrefs.popup_menu.append(subMenuItem);

if (options.commit) {
this.layout.content.appendChild(component);
this.behaviourEngine.updateComponent(component, component.toJSON());
Expand Down

0 comments on commit 2c4b23b

Please sign in to comment.