Skip to content

Commit

Permalink
Support for searching components using their endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
jpajuelo committed Oct 20, 2016
1 parent b99ed03 commit 46cadaa
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 2 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
Binary file not shown.
Binary file not shown.
6 changes: 4 additions & 2 deletions src/wirecloud/commons/utils/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -1881,13 +1881,15 @@ def has_behaviours(self):
class WiringComponentSidebarTester(BaseWiringViewTester):

def __enter__(self):
self.btn_components.click()
if not self.btn_components.is_active:
self.btn_components.click()
self.element = self.testcase.driver.find_element_by_css_selector(".wc-workspace-wiring .we-panel-components")
WebDriverWait(self.testcase.driver, timeout=5).until(WEC.element_be_still(self.element))
return self

def __exit__(self, type, value, traceback):
self.btn_components.click()
if self.btn_components.is_active:
self.btn_components.click()
WebDriverWait(self.testcase.driver, timeout=5).until(WEC.element_be_still(self.element))

@property
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 ") + ") NOT (vendor:" + component._component.meta.vendor + " AND name:" + component._component.meta.name + ")");
}.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 ") + ") NOT (vendor:" + component._component.meta.vendor + " AND name:" + component._component.meta.name + ")");
}.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 ") + ") NOT (vendor:" + component._component.meta.vendor + " AND name:" + component._component.meta.name + ")");
}.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
42 changes: 42 additions & 0 deletions src/wirecloud/platform/wiring/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1772,6 +1772,48 @@ def test_ordering_widget_endpoints(self):
self.assertEqual(targets_count, len(widget.find_endpoints('target')))
self.assertEqual(sources_count, len(widget.find_endpoints('source')))

@uses_extra_resources(('Wirecloud_TestOperator_FriendcodeList_2.1.zip','Wirecloud_Test_FriendcodeList_3.1.wgt'), shared=True)
def test_search_components_by_component_both_endpoints(self):
self.login(username='user_with_workspaces', next='/user_with_workspaces/ExistingWorkspace')

with self.wiring_view as wiring:
with wiring.component_sidebar as sidebar:
operator = sidebar.add_component('operator', "Wirecloud/TestOperator")

operator.show_preferences().click_entry(("Search component...", "For both endpoints"))

with wiring.component_sidebar as sidebar:
self.assertEqual(len(sidebar.find_component_groups('operator')), 0)
self.assertEqual(len(sidebar.find_component_groups('widget')), 1)

@uses_extra_resources(('Wirecloud_TestOperator_FriendcodeList_2.1.zip','Wirecloud_Test_FriendcodeList_3.1.wgt'), shared=True)
def test_search_components_by_component_input_endpoints(self):
self.login(username='user_with_workspaces', next='/user_with_workspaces/ExistingWorkspace')

with self.wiring_view as wiring:
with wiring.component_sidebar as sidebar:
operator = sidebar.add_component('operator', "Wirecloud/TestOperator")

operator.show_preferences().click_entry(("Search component...", "For input endpoints"))

with wiring.component_sidebar as sidebar:
self.assertEqual(len(sidebar.find_component_groups('operator')), 0)
self.assertEqual(len(sidebar.find_component_groups('widget')), 1)

@uses_extra_resources(('Wirecloud_TestOperator_FriendcodeList_2.1.zip','Wirecloud_Test_FriendcodeList_3.1.wgt'), shared=True)
def test_search_components_by_component_output_endpoints(self):
self.login(username='user_with_workspaces', next='/user_with_workspaces/ExistingWorkspace')

with self.wiring_view as wiring:
with wiring.component_sidebar as sidebar:
operator = sidebar.add_component('operator', "Wirecloud/TestOperator")

operator.show_preferences().click_entry(("Search component...", "For output endpoints"))

with wiring.component_sidebar as sidebar:
self.assertEqual(len(sidebar.find_component_groups('operator')), 0)
self.assertEqual(len(sidebar.find_component_groups('widget')), 1)


@wirecloud_selenium_test_case
class BehaviourManagementTestCase(WirecloudSeleniumTestCase):
Expand Down

0 comments on commit 46cadaa

Please sign in to comment.