Skip to content

Commit

Permalink
Frontend cleanups (dragging-item highlighting, hiding of sorting-fiel…
Browse files Browse the repository at this point in the history
…d, d&d cursor) & no limit for search-results
  • Loading branch information
aschulzstudent authored and adrianschulz committed Nov 8, 2017
1 parent 34da82f commit 011f7f4
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 6 deletions.
5 changes: 5 additions & 0 deletions buildout.cfg
Expand Up @@ -55,6 +55,10 @@ eggs = ${instance:eggs}
defaults = ['-s', 'collective.sortedlisting', '--auto-color', '--auto-progress']


[sources]
plone.app.z3cform = git https://github.com/plone/plone.app.z3cform.git branch=master


[zopepy]
recipe = zc.recipe.egg
eggs =
Expand Down Expand Up @@ -113,6 +117,7 @@ python-coveralls = 2.7.0
requests-toolbelt = 0.7.1
testfixtures = 4.13.4
zope.component = 3.12.1
zc.buildout = 2.9.5
watchdog = 0.8.3
sh = 1.12.14

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,2 +1,2 @@
setuptools==33.1.1
zc.buildout==2.8.0
zc.buildout==2.9.5
9 changes: 8 additions & 1 deletion src/collective/sortedlisting/behavior.py
Expand Up @@ -7,6 +7,7 @@
from plone.batching import Batch
from plone.dexterity.interfaces import IDexterityContent
from plone.supermodel import model
from plone.z3cform.textlines import TextLinesFieldWidget
from zope import schema
from zope.component import adapter
from zope.interface import implementer_only
Expand All @@ -30,7 +31,9 @@ class ISortableCollectionBehavior(model.Schema):
missing_value=''
)
# override QueryString widget with our sortable version
form.widget('query', SortableQueryStringFieldWidget)
form.widget('query',
SortableQueryStringFieldWidget,
wrapper_css_class='sortableCollection-query')

sort_on = schema.TextLine(
title=_(u'label_sort_on', default=u'Sort on'),
Expand Down Expand Up @@ -80,6 +83,10 @@ class ISortableCollectionBehavior(model.Schema):
value_type=schema.TextLine(),
required=False,
)
# We have to set the widget to update the widget-settings
form.widget('sorting',
TextLinesFieldWidget,
wrapper_css_class='sortableCollection-sorting')


@implementer_only(ISortableCollectionBehavior)
Expand Down
3 changes: 1 addition & 2 deletions src/collective/sortedlisting/browser/querybuilder.py
Expand Up @@ -14,8 +14,7 @@ def html_results(self, query):
used in the live update results"""
options = dict(original_context=self.context)
results = self(query, sort_on=self.request.get('sort_on', None),
sort_order=self.request.get('sort_order', None),
limit=10)
sort_order=self.request.get('sort_order', None),)
return getMultiAdapter(
(results, self.request),
name='sortable_query_results'
Expand Down
2 changes: 1 addition & 1 deletion src/collective/sortedlisting/browser/results.pt
Expand Up @@ -24,7 +24,7 @@
</strong>
</p>

<ul class="searchResults" tal:condition="limited_results">
<ul class="searchResults sortedListing-results" tal:condition="limited_results">
<li tal:repeat="item limited_results" tal:attributes="data-uid item/UID">
<tal:entry tal:define="author python:pas_member.info(item.Creator());
item_state python:'state-'+item.review_state();
Expand Down
@@ -0,0 +1,18 @@
@queryField: ~"div.sortableCollection-query";
@sortingField: ~"div.sortableCollection-sorting";
@searchResults: ~"ul.sortedListing-results";

/* Hide preview-description and sorting*/
@{sortingField}, @{queryField} div.querystring-preview-description {
display: none;
}

/* Set cursor for drag & drop. */
@{searchResults} li {
cursor: move;
}

@{searchResults} li.item-dragging { /* Highlight the selected item. */
border-color: @plone-link-color;
border-style: dashed;
}
10 changes: 10 additions & 0 deletions src/collective/sortedlisting/tests/test_tile.py
Expand Up @@ -33,4 +33,14 @@ def test_sortedlisting_tile(self):
expected = '<p class="discreet">There are currently no items in this folder.</p>' # noqa
self.assertIn(expected, browser.contents)

def test_added_classes(self):
browser = Browser(self.layer['app'])
auth = 'Basic {0}:{1}'.format(TEST_USER_NAME, TEST_USER_PASSWORD)
browser.addHeader('Authorization', auth)
browser.open(
self.portal.absolute_url() +
'/@@collective.sortablequerystring.contentlisting')
expected = '<p class="discreet">There are currently no items in this folder.</p>' # noqa
self.assertIn(expected, browser.contents)

# EOF
23 changes: 23 additions & 0 deletions src/collective/sortedlisting/tests/test_widget.py
Expand Up @@ -50,6 +50,12 @@ def test_html_query_result_list(self):
self.view.html_results(self.query)
)

# Test if a necessary css-class is added
self.assertIn(
'<ul class="searchResults sortedListing-results">',
self.view.html_results(self.query)
)

def test_querybuilder_batch(self):
""" Test querybuilder with batch
"""
Expand All @@ -60,3 +66,20 @@ def test_querybuilder_batch(self):
results = qb(sc.query, batch=True)
self.assertIsInstance(results, Batch)
self.assertEqual(len(results), 0)

def test_querybulider_default_batch(self):
""" Test if it the results will be batched if it's not implicity given.
"""

setRoles(self.portal, TEST_USER_ID, ['Manager', ])

# default batch size is 10 for querystring
for counter in range(11):
obj = api.content.create(self.portal, 'Document',
title='A doc - {0}'.format(counter))
obj.reindexObject()

self.assertIn(
'<a href="http://nohost/plone/a-doc-10" class="link-location">',
self.view.html_results(self.query)
)
6 changes: 5 additions & 1 deletion src/collective/sortedlisting/tile.py
Expand Up @@ -13,8 +13,12 @@

class ISortableContentListingTile(contentlisting.IContentListingTile):

form.widget('query', SortableQueryStringFieldWidget)
form.widget('query',
SortableQueryStringFieldWidget,
wrapper_css_class='sortableCollection-query')

form.widget('sorting',
wrapper_css_class='sortableCollection-sorting')
sorting = schema.List(
title=_(u'Sorting'),
description=_(u'Widget specific sorting of the search results'),
Expand Down

0 comments on commit 011f7f4

Please sign in to comment.