Skip to content

Commit

Permalink
Merge pull request #52 from ploneintranet/sidebar-search
Browse files Browse the repository at this point in the history
This is working really great!
  • Loading branch information
Alessandro Pisa committed Feb 5, 2015
2 parents 96715ec + de9bdd5 commit 3ab441d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
35 changes: 27 additions & 8 deletions src/ploneintranet/workspace/browser/sidebar.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# from plone import api
from plone.tiles import Tile
from zope.publisher.browser import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from plone.tiles import Tile
from ploneintranet.workspace.utils import TYPE_MAP
from zope.publisher.browser import BrowserView

FOLDERISH_TYPES = ['folder']

Expand Down Expand Up @@ -36,10 +36,25 @@ def children(self):
""" returns a list of dicts of items in the current context
"""
items = []
for item in self.context.getFolderContents():
catalog = self.context.portal_catalog
current_path = '/'.join(self.context.getPhysicalPath())

sidebar_search = self.request.get('sidebar-search', None)
if sidebar_search:
st = '%s*' % sidebar_search # XXX plone only allows * as postfix.
# With solr we might want to do real substr
results = catalog.searchResults(SearchableText=st,
path=current_path)
else:
results = self.context.getFolderContents()

for item in results:
# Do some checks to set the right classes for icons and candy
desc = item['Description'] and 'has-description' \
desc = (
item['Description']
and 'has-description'
or 'has-no-description'
)

content_type = TYPE_MAP.get(item['portal_type'], 'none')

Expand All @@ -48,10 +63,14 @@ def children(self):
typ = 'folder' # XXX: This needs to get dynamic later

if content_type in FOLDERISH_TYPES:
dpi = "source: #items; target: #items && " \
"source: #selector-contextual-functions; " \
"target: #selector-contextual-functions && " \
"source: #context-title; target: #context-title"
dpi = (
"source: #items; target: #items && "
"source: #selector-contextual-functions; "
"target: #selector-contextual-functions && "
"source: #context-title; target: #context-title && "
"source: #sidebar-search-form; "
"target: #sidebar-search-form"
)
url = item.getURL() + '/@@sidebar.default#items'
content_type = 'group'
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@
<a class="selector-toggle-select more-menu-trigger">Functions</a>
</div>

<form class="search-box pat-inject pat-autosubmit" action="/feedback/workspace-search-results-min.html#items">
<form class="search-box pat-inject pat-autosubmit" id="sidebar-search-form"
action="/feedback/workspace-search-results-min.html#items"
tal:attributes="action string:${context/absolute_url}/@@sidebar.default#items">
<label>
<input name="" type="search" placeholder="Search" />
<input name="sidebar-search" type="search" placeholder="Search" />
<button type="submit">Search</button>
</label>
</form>
Expand Down
20 changes: 17 additions & 3 deletions src/ploneintranet/workspace/tests/test_sidebar.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# coding=utf-8
from ploneintranet.workspace.tests.base import BaseTestCase
from plone import api
from zope.component import provideAdapter
from zope.interface import Interface
from plone.tiles.interfaces import IBasicTile
from ploneintranet.workspace.browser.sidebar import ContentItemsTile
from ploneintranet.workspace.tests.base import BaseTestCase
from zope.component import getMultiAdapter
from zope.component import provideAdapter
from zope.interface import Interface


class TestSidebar(BaseTestCase):
Expand Down Expand Up @@ -76,3 +76,17 @@ def test_sidebar_children(self):
self.assertIn('example-subdocument',
ids,
"No such IDs found in sidebar navigation")

# Check if search works
from zope.publisher.browser import TestRequest
TR = TestRequest(form={'sidebar-search': 'Folder'})
sidebar = getMultiAdapter((ws, TR), name=u"sidebar.default")
children = sidebar.children()
self.assertEqual(len(children), 1)
self.assertTrue(children[0]['id'] == 'myfolder')

# Assert that substr works and we find all
TR = TestRequest(form={'sidebar-search': 'exampl'})
sidebar = getMultiAdapter((ws, TR), name=u"sidebar.default")
children = sidebar.children()
self.assertEqual(len(children), 3)

0 comments on commit 3ab441d

Please sign in to comment.