Skip to content

Commit

Permalink
react-searchkit: theme semantic-ui integration
Browse files Browse the repository at this point in the history
  • Loading branch information
kpsherva committed May 13, 2020
1 parent 97a46e2 commit ca96b7e
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 105 deletions.
2 changes: 1 addition & 1 deletion invenio_search_ui/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from __future__ import absolute_import, print_function

SEARCH_UI_APP_THEME = ['react', 'angular']
APP_THEME = ['semantic-ui', 'bootstrap3']

SEARCH_UI_SEARCH_API = '/api/records/'
"""Configure the search engine endpoint."""
Expand Down
17 changes: 0 additions & 17 deletions invenio_search_ui/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,6 @@ def init_config(self, app):
app.config.get('HEADER_TEMPLATE',
'invenio_search_ui/base_header.html')
)
app.config.setdefault(
'SEARCH_UI_JS_FRAMEWORK',
app.config.get('JS_FRAMEWORK',
'react')
)
if app.config.get('SEARCH_UI_JS_FRAMEWORK') == 'react':
app.config.setdefault(
'SEARCH_UI_SEARCH_TEMPLATE',
app.config.get('SEARCH_TEMPLATE',
'invenio_search_ui/react_search.html')
)
else:
app.config.setdefault(
'SEARCH_UI_SEARCH_TEMPLATE',
app.config.get('SEARCH_TEMPLATE',
'invenio_search_ui/search.html')
)

for k in dir(config):
if k.startswith('SEARCH_UI_'):
Expand Down
11 changes: 2 additions & 9 deletions invenio_search_ui/templates/invenio_search_ui/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,14 @@

{%- block css %}
{{ super() }}
{{ webpack['search_ui_theme'] }}
{{ webpack['search_ui_theme.css'] }}
{# assets "invenio_search_ui_search_css" %}<link href="{{ ASSET_URL }}" rel="stylesheet">{% endassets #}

{% block css_render %}
{{ webpack.render('.css') }}
{% endblock css_render %}
{%- endblock css %}

{%- block javascript %}
{{ super() }}
{{ webpack['search_ui_app'] }}
{{ webpack['search_ui_app.js'] }}
{# assets "invenio_search_ui_search_js" %}<script src="{{ ASSET_URL }}"></script>{% endassets #}
{% block javascript_render %}
{{ webpack.render('.js') }}
{% endblock javascript_render %}
{%- endblock javascript %}

{%- block body_inner %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
{% extends config.SEARCH_UI_BASE_TEMPLATE %}

{%- block css %}
{{ super() }}
{{ webpack['vendor.css'] }}

{% block css_render %}
{{ webpack.render('.css') }}
{% endblock css_render %}
{%- endblock css %}


{%- block javascript %}
{{ super() }}
{{ webpack['search_ui_app.js'] }}
<script type="text/javascript">window.initSearchApp("invenio-search-ui-app", {{ config|format_config("recid")|safe }});</script>
{% block javascript_render %}
{{ webpack.render('.js') }}
{% endblock javascript_render %}
{%- endblock javascript %}


Expand Down
6 changes: 4 additions & 2 deletions invenio_search_ui/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def format_sortoptions(sort_options):
def format_config(config, endpoint_name):
"""Create config JSON dump for Invenio-Search-JS."""

search_index = current_app.get('RECORDS_REST_ENDPOINTS', {}).get(
# TODO check what happens when search_index not defined
# in record_rest_endpoints
search_index = config.get('RECORDS_REST_ENDPOINTS', {}).get(
endpoint_name, {}).get('search_index', 'records')

config_sort_options = config.get('RECORDS_REST_SORT_OPTIONS', {}).get(
Expand All @@ -109,5 +111,5 @@ def format_config(config, endpoint_name):
config_sort_options, config_default_sort
),
"aggs": searchkit_aggs(config.get('RECORDS_REST_FACETS', {}).get(
endpoint_name).get("aggs", {})),
search_index).get("aggs", {})),
})
79 changes: 16 additions & 63 deletions invenio_search_ui/webpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,20 @@
"""

from flask import current_app
from flask_webpackext import WebpackBundle


def search_ui():
"""Create webpack asset endpoint."""
if current_app.config['SEARCH_UI_JS_FRAMEWORK'] == 'react':
return WebpackBundle(
__name__,
'assets',
from invenio_assets.webpack import WebpackThemeBundle

search_ui = WebpackThemeBundle(
__name__,
'assets',
default='semantic-ui',
themes={
'semantic-ui': dict(
entry={
'search_ui_app': './js/invenio_react_search_ui/index.js',
},
dependencies={
"axios": "^0.19.0",
"lodash": "^4.17.15",
"node-sass": "^4.12.0",
"qs": "^6.8.0",
"prop-types": "^15.7.2",
"react": "^16.9.0",
Expand All @@ -43,14 +40,9 @@ def search_ui():
"redux": "^4.0.4",
"redux-thunk": "^2.3.0",
'react-searchkit': '^0.19.0',
"semantic-ui-css": "^2.4.1",
"semantic-ui-react": "^0.88.0"
})

else:
return WebpackBundle(
__name__,
'assets',
}
),
'bootstrap3': dict(
entry={
'search_ui_app': './js/invenio_search_ui/app.js',
'search_ui_theme': './scss/invenio_search_ui/search.scss',
Expand All @@ -61,47 +53,8 @@ def search_ui():
'angular-loading-bar': '~0.9.0',
'd3': '^3.5.17',
'invenio-search-js': '^1.3.1',
'jquery': '~3.2.1',
})


# search_ui = WebpackBundle(
# __name__,
# 'assets',
# themes={
# 'react': dict(
# entry={
# 'search_ui_app': './js/invenio_react_search_ui/index.js',
# },
# dependencies={
# "axios": "^0.19.0",
# "lodash": "^4.17.15",
# "node-sass": "^4.12.0",
# "qs": "^6.8.0",
# "react": "^16.9.0",
# "react-dom": "^16.9.0",
# "react-redux": "^7.1",
# "react-scripts": "3.1.1",
# "redux": "^4.0.4",
# "redux-thunk": "^2.3.0",
# 'react-searchkit': '^0.19.0',
# "semantic-ui-css": "^2.4.1",
# "semantic-ui-react": "^0.88.0"
# }
# ),
# 'angular': dict(
# entry={
# 'search_ui_app': './js/invenio_search_ui/app.js',
# 'search_ui_theme': './scss/invenio_search_ui/search.scss',
# },
# dependencies={
# 'almond': '~0.3.1',
# 'angular': '~1.4.10',
# 'angular-loading-bar': '~0.9.0',
# 'd3': '^3.5.17',
# 'invenio-search-js': '^1.3.1',
# 'jquery': '~3.2.1',
# }
# )
# }
# )
'jquery': '~3.2.1'
}
),
},
)

0 comments on commit ca96b7e

Please sign in to comment.