Faceted Navigation
應用情境: 課程分類搜尋 圖檔分類搜尋 Matomo Analytics collective.contact.facetednav 階層式關鍵字 (Taxonomic Checkbox) 建置管理員介面顯示項目清單 取代傳統搜尋介面
EEA FacetedNavigation 有兩個版本,https://github.com/eea/eea.facetednavigation 針對 EEA 單位自身的開發需求,https://github.com/collective/eea.facetednavigation 則是方便社群自行維護的版本。在 4.1 版本之際,支援 Faceted Settings 設定選單,會新增選項在 Action 下拉選單裡,在 5.2 版本之際,支援 plone.app.folder 和 plone.app.collection,10.0 版本後改用 z3c.form。過往程式碼的位置範例 https://svn.eionet.europa.eu/repositories/Zope/trunk/eea.faceted.inheritance/trunk,討論區在 http://groups.google.com/forum/#!forum/eea-facetednavigation
eea.facetednavigation depends on eea.jquery which provides a jquery.tree.js package. This package is in conflict with the jqtree module that mockup uses (for related items) as they both register against the global $.tree jquery plugin. 2018/08/08: 啟用 eea.facetednavigation 會連帶啟用 collective.js.jqueryui 但沒啟用 eea.jquery
新式功能由 eea.elasticsearch 實作,成果是 PAM 資料庫。
擴充模組範例: collective.contact.facetednav collective.eeafaceted.collectionwidget and collective.eeafaceted.z3ctable collective.portlet.collectionfilter
Plone5 Deprecated: Search Widget (SearchableText) Ignore Path Filter Faceted Widget in Plone5 第13版開始支援 Python 3 相依套件collective.js.jqueryui 要留意是否支援
安裝方式
Plone 4.3.4 之後的 develop.cfg 設定方式:
eggs += eea.facetednavigation
為了避免 CSFS 干擾,也有人採 AngularJS 方案。在 10.0 版本之際,會同時相容 Plone4 和 Plone5,做為過渡 Plone5 的準備,Plone5 支援正式完成。
下列是 Plone 4.3.4 之前的 develop.cfg 參考設定值:
eggs += eea.facetednavigation # Plone 4.3.4+ needs the above only, the followings seem for older Plone
zcml += eea.facetednavigation-meta eea.facetednavigation-overrides eea.facetednavigation # use eea.facetednavigation-minimal instead if don't want default ATContentTypes # from eea.fn 4.2 can dynamically register custom facted views eea.facetednavigation.views.example
eea.facetednavigation 相依於 collective.js.jqueryui 模組,依照 Plone 版本,必須選擇適用的 collective.js.jqueryui 版本:
- Plone 5.1: collective.js.jqueryui 2.0.1 - plone.app.jquery 1.11.2 (可能遇到 jQuery UI profile 3203 upgrade 訊息)
- Plone 5.0: collective.js.jqueryui 2.0.1 - plone.app.jquery 1.9.1.2
- Plone 4.3: collective.js.jqueryui > 1.9.x - plone.app.jquery == 1.7.2
- Plone 4.2: collective.js.jqueryui 1.8.x - plone.app.jquery == 1.4.4 (IDs with spaces problem)
搭配 CSRF 會造成設定介面無法生效,透過 IDisableCSRFProtection 可以先避過這問題。
不合適的版本,會遇到類似下列的 buildout 或 JavaScript 錯誤:
Got collective.js.jqueryui 1.10.3. The constraint, 1.4.4, is not consistent with the requirement, 'plone.app.jquery>1.6'. While: Installing instance. Error: Bad constraint 1.4.4 plone.app.jquery>1.6
Uncaught TypeError: Object #<Object> has no method 'prop'
Plone 4.2.6 的 develop.cfg 範例:
eggs += Products.DocFinderTab plone.reload eea.facetednavigation collective.js.jqueryui==1.8.16.9 zcml += eea.facetednavigation-meta eea.facetednavigation-overrides eea.facetednavigation eea.facetednavigation.views.example
8.9 版本在 Plone 5.0.x 環境,會遇到 KeyError: 'global_defines' 錯誤,來自檔案 eea/facetednavigation/browser/template/query.pt 的 use-macro="here/global_defines/macros/defines" 段落。
新建 custom type 的場合,要在 configuration.zcml 裡加上:
<class class="my.package.content.MyType" zcml:condition="installed my.package.content.MyType"> <implements interface="eea.facetednavigation.interfaces.IPossibleFacetedNavigable" /> </class>
1. edit.css / edit.js is used in edit mode: => configure-faceted.html 2. view.css / view.js is used in view mode: => facetednavigation_view 3. widget.pt / widget.py - the view and the controller of the widget. 4. tree.js / tree.py - specific files for path widget, you may not need them for your widget
只使用 Template 裡 content-core 的 METAL Slot 其他都沒用。利用 Faceted Specific Events 來觸發動態控制的功能。
eea.tool was meant to store more faceted navigation settings, but in the end it only allows you to define custom mappings between interfaces and portal_types.
辭彙表 Vocabulary 利用 Tag 欄位自動建立索引 alphabet widget issue Fix Double Empty Entry of First Term in Vocabulary eea.faceted.vocabulary py3
Hard Dependency with Archetypes
預設的排序方式在 #44 被取消,可用 TAL Expression Widget 來處理 Sort On 和 Sort Order:
# Sort On: python:'effective' if 'c14' not in form else "FACET-EMPTY" # Sort Order: python:'descending' if 'c14' not in form else "FACET-EMPTY"
TAL Expression Widget 如果使用 FACET-EMPTY 當輸入值,代表 Query 沒有條件值。
Dexterity Support Registry Property to Disable Diazo Rules
create new widgets in custom package
TAL Expression Facet Filter for Current Folder
# select 'Location' for catalog field and use the following TAL expression
python:context.absolute_url(1) # if this doesn't work try python:'/Plone/' + context.absolute_url(1)
python: 'published' if context.portal_membership.isAnonymousUser() else "FACET-EMPTY"
python:'URL0' in request and 'configure_faceted.html' in request['URL0']
使用 Intranet Workflow 時,可改成 python: ('internal', 'external') 語法。
jstree eea.jquery 與 Folder Contents 衝突
4.6 版 Smart Facets Hiding, 5.2 版預設取消顯示
Path Depth Level: 0 is only the brain of the given path, 1 is it and its children
使用 select2 取代 jQuery Autocomplete Do Not Restrict select2 Resources to Authenticated Users 設定 Widget 的預設值 ?searchableText=fun
eea.tags 支援 Dexterity 使用 remove all 的注意事項 jQuery 1.9 不再使用 jquery.browser
Layout
CSS Class for Widget Identification based on Widget Title
eea.facetednavigation/subtypes/wrapper.py 蓋掉 atctListAlbum script
Widget
wid python:view.data.getId() 像 c1, c2 之類的屬性值,會再搭配 string:${wid}_widget 指定成 id 傳給 tal:attributes。
Checkbox:
- widgets/checkbox/view.js
- widgets/checkbox/edit.js
- widgets/checkbox/widget.pt : <div class="faceted-widget faceted-checkboxes-widget faceted-count" ...>
Alphabetic widget does not work with "all, standard or tabular" views
DateRange Date Format
Filter Widget Countable Checkbox Issue
Widget I18N
把標題的英文填到 plone.po 完成翻譯,就可以看到中英對照的標題效果。
當顯示方式的程式碼有誤時,會出現 This site encountered an error trying to fulfill your request 訊息,造成無法操作的狀況,可在網址後面加上 @@faceted_layout?layout=folder_listing 或 layout=faceted-preview-items 來調整設定值。
photoAlbumEntry CSS
在 thumbs.plone.less:12 設定 width: 220px height: 240px
類似 http://localhost:8080/mysite/myfolder/@@faceted_subtyper/disable 可以停用
Sorting widget breaks on missing indices Title for "No Selected Sorting Method"
Responsive Design Examples: www.mountaineers.org/explore/activities, www.eea.europa.eu/publications
folder_contents jquery is breaking folder_contents view on Plone 5: $.tree 名稱換掉
Programatical Configuration
eea.relations
海量資料效能
Infinite Loop of JavaScript Spinner
Enable PloneAdmin
Traceback (innermost last):
- Module ZPublisher.Publish, line 196, in publish_module_standard
- Module Products.PlacelessTranslationService.PatchStringIO, line 34, in new_publish
- Module ZPublisher.Publish, line 146, in publish
- Module Zope2.App.startup, line 222, in zpublisher_exception_hook
- Module ZPublisher.Publish, line 115, in publish
- Module ZPublisher.mapply, line 88, in mapply
- Module ZPublisher.Publish, line 41, in call_object
- Module Shared.DC.Scripts.Bindings, line 311, in __call__
- Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec
- Module Products.CMFCore.FSPageTemplate, line 195, in _exec
- Module Products.CacheSetup.patch_cmf, line 29, in FSPT_pt_render
- Module Products.CacheSetup.patch_utils, line 9, in call_pattern
- Module Products.CMFCore.FSPageTemplate, line 134, in pt_render
- Module Products.CacheSetup.patch_cmf, line 77, in PT_pt_render
- Module Products.CacheSetup.patch_utils, line 9, in call_pattern
- Module Products.PageTemplates.PageTemplate, line 104, in pt_render
<FSPageTemplate at /Plone/prefs_install_products_form> - Module TAL.TALInterpreter, line 238, in __call__
- Module TAL.TALInterpreter, line 281, in interpret
- Module TAL.TALInterpreter, line 749, in do_useMacro
- Module TAL.TALInterpreter, line 281, in interpret
- Module TAL.TALInterpreter, line 457, in do_optTag_tal
- Module TAL.TALInterpreter, line 442, in do_optTag
- Module TAL.TALInterpreter, line 437, in no_tag
- Module TAL.TALInterpreter, line 281, in interpret
- Module TAL.TALInterpreter, line 749, in do_useMacro
- Module TAL.TALInterpreter, line 281, in interpret
- Module TAL.TALInterpreter, line 457, in do_optTag_tal
- Module TAL.TALInterpreter, line 442, in do_optTag
- Module TAL.TALInterpreter, line 437, in no_tag
- Module TAL.TALInterpreter, line 281, in interpret
- Module TAL.TALInterpreter, line 339, in do_startTag
- Module TAL.TALInterpreter, line 405, in attrAction_tal
- Module Products.PageTemplates.TALES, line 227, in evaluateText
- Module Products.PageTemplates.TALES, line 221, in evaluate
URL: file:design/skins/eea_design/main_template.pt
Line 58, Column 8
Expression: <PythonExpr here.getSectionFromURL(plone_view)>
Names:{'container': <PloneSite at /Plone>,
'context': <PloneSite at /Plone>,
'default': <Products.PageTemplates.TALES.Default instance at 0x7f22304935a8>,
'here': <PloneSite at /Plone>,
'loop': <Products.PageTemplates.TALES.SafeMapping object at 0x17823dd0>,
'modules': <Products.PageTemplates.ZRPythonExpr._SecureModuleImporter instance at 0x7f22304939e0>,
'nothing': None,
'options': {'args': ()},
'repeat': <Products.PageTemplates.TALES.SafeMapping object at 0x17823dd0>,
'request': <HTTPRequest, URL=http://dev1:8080/Plone/prefs_install_products_form>,
'root': <Application at >,
'template': <FSPageTemplate at /Plone/prefs_install_products_form>,
'traverse_subpath': [],
'user': <PropertiedUser 'admin'>} - Module Products.PageTemplates.ZRPythonExpr, line 47, in __call__
__traceback_info__: here.getSectionFromURL(plone_view) - Module Python expression "here.getSectionFromURL(plone_view)", line 1, in <expression>
- Module Products.CMFCore.FSPythonScript, line 108, in __call__
- Module Shared.DC.Scripts.Bindings, line 311, in __call__
- Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec
- Module Products.CMFCore.FSPythonScript, line 164, in _exec
TypeError: <exceptions.TypeError instance at 0x176c0320> (Also, the following error occurred while attempting to render the standard error message, please see the event log for full details: getSectionFromURL() takes no arguments (1 given))
Tag Cloud Widget 如果沒有任何項目有選項被儲存,系統會記錄錯誤訊息,但不影響運作。
ERROR eea.facetednavigation.browser.error {'__name__': 'c11', 'catalog': u'portal_catalog', 'cloud': u'list', 'colormax': u'95B229', 'colormin': u'A1BE7E', 'count': False, 'default': u'', 'height': u'200', 'hidezerocount': False, 'index': u'origin', 'maxchars': u'', 'maxitems': u'50', 'position': u'right', 'section': u'default', 'sizemax': u'20', 'sizemin': u'10', 'sortcountable': False, 'sortreversed': False, 'title': u'\u610f\u898b\u53cd\u6620\u4f86\u6e90', 'vocabulary': u'origin', 'widget': u'tagscloud'} Traceback (most recent call last): File "/home/marr/shiji/buildout-cache/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 965, in do_onError_tal self.interpret(block) File "/home/marr/shiji/buildout-cache/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 343, in interpret handlers[opcode](self, args) File "/home/marr/shiji/buildout-cache/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 583, in do_setLocal_tal self.engine.setLocal(name, self.engine.evaluateValue(expr)) File "/home/marr/shiji/buildout-cache/eggs/zope.tales-3.5.3-py2.7.egg/zope/tales/tales.py", line 696, in evaluate return expression(self) File "/home/marr/shiji/buildout-cache/eggs/zope.tales-3.5.3-py2.7.egg/zope/tales/pythonexpr.py", line 59, in __call__ return eval(self._code, vars) File "", line 1, in File "/home/marr/shiji/zinstance/src/eea.facetednavigation/eea/facetednavigation/widgets/tagscloud/counter.py", line 40, in query res = widget.count(brains, sequence=vocabulary.keys()) File "/home/marr/shiji/zinstance/src/eea.facetednavigation/eea/facetednavigation/widgets/widget.py", line 351, in count sequence = [key for key, value in self.vocabulary()] ValueError: too many values to unpack
eea.facetednavigation 4.0 的 minimal.zcml 包含了 collective.js.jqueryui,但 3.5 沒有 minimal.zcml 這個檔,也沒包含 collective.js.jqueryui。
faceted_counter - TypeError: expected integer key Incorrect href in pagination
Import was failing with List has not attrinute .fromUnicode UnicodeDecode Error when Catalog Names containing Unicode Characters Encode index before apply if necessary
沒有 reindexObject() 的話,會造成 Faceted View 沒有顯示結果。
Adding New View
cp view/preview-items.pt view/wy-preview-items.pt
vi view/wy-preview-items.pt main_template -> wgye_template
vi view/configure.zcml add wy-preview-items
eea.jquery 4.0 會依照 Plone 的不同版本,搭配提供 jQuery 1.3.2 或 1.4.2 的函式庫功能,包括 bbq, cookie, fancybox, galleryview, jqzoom 等特效。 eea-mediacentre.js 程式碼裡有 href = href + "/video_popup_view" 片段。
<metal:block use-macro="here/global_defines/macros/defines" /> <metal:block tal:define="plone_view python:context.restrictedTraverse('@@plone')"> <tal:main define=" batch_base_url here/absolute_url; folderContents view/brains; contentFilter python: {'portal_type': 'FACET-EMPTY'} if not folderContents else {}; here python:view.get_context(folderContents)"> <tal:def define=" kssClassesView context/@@kss_field_decorator_view | nothing; getKssClasses nocall:kssClassesView/getKssClassesInlineEditable | nothing; templateId template/getId | nothing"> <metal:block use-macro="view/macros" /> </tal:def> </tal:main> </metal:block>
Move autocomplete widget to select2 to support multiple selection Fix issue where subtyper views raised insufficient permissions on Zope 4 and Python 3, because its publishTraverse endpoints returned None for ZPublisher https://github.com/eea/eea.facetednavigation/commit/9662cf20dd4a6ad9e201435cbd56344df30dcfd9