diff --git a/Makefile b/Makefile index 281bb55..a46b552 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,8 @@ COFFEE_FILES = \ webfrontend/ExampleDetailSidebarPlugin.coffee \ webfrontend/FylrExampleCustomDatamodelSettings.coffee \ webfrontend/FylrExampleTransition.coffee \ - webfrontend/FylrExampleExportPluginSleep.coffee + webfrontend/FylrExampleExportPluginSleep.coffee \ + webfrontend/FylrExampleSearchToolPlugin.coffee JS = webfrontend/FylrExample.js diff --git a/l10n/example-loca.csv b/l10n/example-loca.csv index e218a1d..a02e5f6 100644 --- a/l10n/example-loca.csv +++ b/l10n/example-loca.csv @@ -33,3 +33,16 @@ server.right.system.plugin.fylr_example.example_right.parm.eas-column-select,Ass example.detail.sidebar.plugin.render_object|icon,fa-cubes,fa-cubes,fa-cubes,fa-cubes,fa-cubes,fa-cubes,fa-cubes,fa-cubes,fa-cubes,fa-cubes example.detail.sidebar.plugin.render_object|hint,Example Plugin: Objekt rendern,Example Plugin: render object,Example Plugin: render object,Example Plugin: render object,Example Plugin: render object,Example Plugin: render object,Example Plugin: render object,Example Plugin: render object,Example Plugin: render object,Example Plugin: render object fylr_example.check.not_allowed,"""henk was here"" ist nicht erlaubt","""henk was here"" is not allowed","""henk was here"" is not allowed","""henk was here"" is not allowed","""henk was here"" is not allowed","""henk was here"" is not allowed","""henk was here"" is not allowed","""henk was here"" is not allowed","""henk was here"" is not allowed","""henk was here"" is not allowed" +tool.fylr.example.search.query_language|text,Zuletzt geändert,Modified last week,Modified last week,Modified last week,Modified last week,Modified last week,Modified last week,Modified last week,Modified last week,Modified last week +tool.fylr.example.search.query_language|icon,fa-filter,fa-filter,fa-filter,fa-filter,fa-filter,fa-filter,fa-filter,fa-filter,fa-filter,fa-filter +fylr.example.search.query_language.label,Letzte Woche,Last week,Last week,Last week,Last week,Last week,Última semana,Last week,Last week,Last week +tool.fylr.example.search.selection|text,Auswahl ausgeben,Dump selection,Dump selection,Dump selection,Dump selection,Dump selection,Dump selection,Dump selection,Dump selection,Dump selection +tool.fylr.example.search.selection|icon,fa-info-circle,fa-info-circle,fa-info-circle,fa-info-circle,fa-info-circle,fa-info-circle,fa-info-circle,fa-info-circle,fa-info-circle,fa-info-circle +fylr.example.search.selection.title,Ausgewählte Objekte,Selected objects,Selected objects,Selected objects,Selected objects,Selected objects,Selected objects,Selected objects,Selected objects,Selected objects +tool.fylr.example.search.filters|text,Schnellfilter,Quick filters,Quick filters,Quick filters,Quick filters,Quick filters,Quick filters,Quick filters,Quick filters,Quick filters +tool.fylr.example.search.filters|icon,fa-filter,fa-filter,fa-filter,fa-filter,fa-filter,fa-filter,fa-filter,fa-filter,fa-filter,fa-filter +tool.fylr.example.search.filters.created|text,Neu angelegt,Recently created,Recently created,Recently created,Recently created,Recently created,Recently created,Recently created,Recently created,Recently created +fylr.example.search.filters.created.label,Neu angelegt,Recently created,Recently created,Recently created,Recently created,Recently created,Recién creados,Recently created,Recently created,Recently created +tool.fylr.example.search.filters.today|text,Heute geändert,Modified today,Modified today,Modified today,Modified today,Modified today,Modified today,Modified today,Modified today,Modified today +fylr.example.search.filters.today.label,Heute,Today,Today,Today,Today,Today,Hoy,Today,Today,Today +toolbox.class.fylr_example,Beispiel-Plugin,Example plugin,Example plugin,Example plugin,Example plugin,Example plugin,Example plugin,Example plugin,Example plugin,Example plugin diff --git a/webfrontend/FylrExampleSearchToolPlugin.coffee b/webfrontend/FylrExampleSearchToolPlugin.coffee new file mode 100644 index 0000000..8635cf4 --- /dev/null +++ b/webfrontend/FylrExampleSearchToolPlugin.coffee @@ -0,0 +1,84 @@ +# Search tool plugin: adds tools to the three dot menu of the main search. +# +# Register the class on SearchMain.toolPlugins (see the bottom of this file). One +# instance is built per search, with the search injected, so a plugin can read the +# current result and the current selection. +# +# getTools() is called every time the menu is rebuilt, so it can return a different +# set of tools depending on the current state. Each entry is a plain object with +# ToolboxTool opts: +# +# name mandatory; also the l10n lookup: "tool.|text" and "|icon" +# text literal label, if you would rather not go through the CSV +# sort ":<1-99>"; a change of letter draws a divider +# hidden Boolean or function, evaluated every time the menu opens +# disabled same as hidden +# run what the tool does when clicked +# tools nested tools, turns the entry into a submenu; works at any depth +# +# Careful: `loading` does NOT take a function, unlike hidden/disabled. +# +# getGroup() gives the tools their own header in the menu instead of putting them +# under "Search". It needs "toolbox.class." in the l10n CSV. +# +# isAvailable() is checked once per search: return false to switch the whole plugin +# off there. The rest of the context is reachable from the plugin itself: +# getSearch(), getSearchInput(), getSearchManagers(), getSearchManager(cls), +# getCollection(), getSelectedObjects(), getSelectedCount(), getLastData(), +# getResultCount(), plus setQueryLanguageQuery() / addQueryLanguageQuery() to drop +# a query language element into the search input. +class FylrExampleSearchToolPlugin extends ez5.SearchToolPlugin + + getGroup: -> + "fylr_example" + + getTools: -> + [ + name: "fylr.example.search.query_language" + sort: "A:1" + hidden: => @getResultCount() == 0 + run: => + @setQueryLanguageQuery + string: '_last_modified > "$now-7d"' + label: $$("fylr.example.search.query_language.label") + name: "" + , + name: "fylr.example.search.selection" + sort: "A:2" + hidden: => @getSelectedCount() == 0 + run: => + ids = @getSelectedObjects().map (collectionObject) -> + collectionObject.getGlobalObjectId() + + CUI.alert + title: $$("fylr.example.search.selection.title") + text: ids.join("\n") + , + name: "fylr.example.search.filters" + sort: "A:3" + tools: @__getFilterTools() + ] + + # Built from data, to show that submenus can be generated dynamically. + # Only system fields here, so the queries work against any datamodel. + __getFilterTools: -> + filters = [ + key: "today" + query: '_last_modified > "$now-1d"' + , + key: "created" + query: '_created > "$now-30d"' + ] + + for filter in filters + do (filter) => + name: "fylr.example.search.filters.#{filter.key}" + run: => + @setQueryLanguageQuery + string: filter.query + label: $$("fylr.example.search.filters.#{filter.key}.label") + name: "" + + +ez5.session_ready -> + SearchMain.toolPlugins.registerPlugin(FylrExampleSearchToolPlugin)