diff --git a/back-office/Gemfile b/back-office/Gemfile index 3429cfa..f0d486c 100644 --- a/back-office/Gemfile +++ b/back-office/Gemfile @@ -56,4 +56,4 @@ group :development, :test do gem 'spring' end - +gem 'elasticsearch' diff --git a/back-office/Gemfile.lock b/back-office/Gemfile.lock index 5561909..f23ae4e 100644 --- a/back-office/Gemfile.lock +++ b/back-office/Gemfile.lock @@ -67,8 +67,18 @@ GEM columnize (0.9.0) debug_inspector (0.0.2) debugger-linecache (1.2.0) + elasticsearch (1.0.9) + elasticsearch-api (= 1.0.9) + elasticsearch-transport (= 1.0.9) + elasticsearch-api (1.0.9) + multi_json + elasticsearch-transport (1.0.9) + faraday + multi_json erubis (2.7.0) execjs (2.2.2) + faraday (0.9.1) + multipart-post (>= 1.2, < 3) font-awesome-rails (4.3.0.0) railties (>= 3.2, < 5.0) globalid (0.3.0) @@ -98,6 +108,7 @@ GEM mini_portile (0.6.2) minitest (5.5.1) multi_json (1.10.1) + multipart-post (2.0.0) nested_form (0.3.2) netrc (0.10.2) nokogiri (1.6.5) @@ -205,6 +216,7 @@ DEPENDENCIES byebug cloudinary coffee-rails (~> 4.1.0) + elasticsearch jbuilder (~> 2.0) jquery-rails jquery-ui-rails diff --git a/back-office/lib/tasks/ribica.rake b/back-office/lib/tasks/ribica.rake index 74d79ed..50783b1 100644 --- a/back-office/lib/tasks/ribica.rake +++ b/back-office/lib/tasks/ribica.rake @@ -333,3 +333,32 @@ namespace :ribica do do_import false end end + +namespace :ribica do + task reindex: :environment do + es_client = Elasticsearch::Client.new log: true + + # first delete the index + begin + es_client.indices.delete index: 'ribica' + rescue + logger.warn "Ribica index could not be deleted. Continuing with indexing operation..." + end + + # now index items + all_items = Item.includes(sub_category: { category: :section }).all.to_a + all_items.each do |item| + es_client.index index: 'ribica', type: 'items', id: item.id, body: { + title: 'Test', + name: item.name, + code: item.code, + description: item.description, + sub_category: item.sub_category.name, + category: item.sub_category.category.name, + section: item.sub_category.category.section.name + } + end + + puts "ok!" + end +end diff --git a/front-api/controllers/search.rb b/front-api/controllers/search.rb index 20dd909..784cb14 100644 --- a/front-api/controllers/search.rb +++ b/front-api/controllers/search.rb @@ -1,32 +1,3 @@ -# TODO: make this private, not-public facing. -# for now we keep this here for simplicity reasons -get '/search/index' do - es_client = Elasticsearch::Client.new log: true - - # first delete the index - begin - es_client.indices.delete index: 'ribica' - rescue - logger.warn "Ribica index could not be deleted. Continuing with indexing operation..." - end - - # now index items - all_items = Item.includes(sub_category: { category: :section }).all.to_a - all_items.each do |item| - es_client.index index: 'ribica', type: 'items', id: item.id, body: { - title: 'Test', - name: item.name, - code: item.code, - description: item.description, - sub_category: item.sub_category.name, - category: item.sub_category.category.name, - section: item.sub_category.category.section.name - } - end - - "ok".to_json -end - get '/search' do es_client = Elasticsearch::Client.new log: true q = params[:q] diff --git a/front-ui/Gruntfile.js b/front-ui/Gruntfile.js index 81723f1..7ddd326 100644 --- a/front-ui/Gruntfile.js +++ b/front-ui/Gruntfile.js @@ -78,16 +78,13 @@ module.exports = function(grunt) { concat: { css: { src: [ - 'node_modules/bootstrap/dist/css/bootstrap.min.css', 'app/css/*.css' ], dest: 'build/ribica.css' }, js: { - src: ['node_modules/jquery/dist/jquery.min.js', - 'app/js/bootstrap.min.js', - 'build/ribica.bundle.js'], + src: ['build/ribica.bundle.js'], dest: 'build/ribica.js' } } diff --git a/front-ui/app/components/cart/addToCart.js b/front-ui/app/components/cart/addToCart.js index 15cf1d2..9745860 100644 --- a/front-ui/app/components/cart/addToCart.js +++ b/front-ui/app/components/cart/addToCart.js @@ -3,18 +3,14 @@ var CartStore = require('../../stores/cartStore.js'); var CartActions = require('../../actions/cartActions.js'); var Globals = require('../../globals'); - - var buttonHolderStyle = { display: 'inline-block' }; var AddToCart = React.createClass({ - - render: function() { - + INITIAL_ITEM_COUNT: 1, + render: function() { var itemCount = this.state.count; - var amountAndAddButton = (
@@ -25,16 +21,14 @@ var AddToCart = React.createClass({
-
+
); - - return amountAndAddButton; - }, + }, // Add change listeners to stores componentDidMount: function() { - CartStore.addChangeListener(this._onChange); + CartStore.addChangeListener(this._onChange); if(!CartStore.dataStartedLoading()) { CartActions.load(); @@ -44,9 +38,9 @@ var AddToCart = React.createClass({ getInitialState: function() { var itemInCart = CartStore.getStateFor(this.props.item.get('id')); - return { + return { item: itemInCart, - count: 0 + count: this.INITIAL_ITEM_COUNT } }, @@ -54,12 +48,12 @@ var AddToCart = React.createClass({ _onChange: function () { if (this.isMounted()) { var item = CartStore.getStateFor(this.props.item.get('id')); - this.setState({ item: item, count: 0 }); + this.setState({ item: item, count: this.INITIAL_ITEM_COUNT }); } }, _onIncreaseClick: function () { - + if (this.state.count < Globals.MaxNumberOfItemsToBeAdded ) { this.state.count = this.state.count + 1; this.setState(this.state); @@ -67,8 +61,8 @@ var AddToCart = React.createClass({ }, _onDecreaseClick: function () { - - if (this.state.count > 0) { + + if (this.state.count > 1) { this.state.count = this.state.count - 1; this.setState(this.state); } @@ -81,7 +75,7 @@ var AddToCart = React.createClass({ componentWillUnmount: function () { CartStore.removeChangeListener(this._onChange); } - + }); -module.exports = AddToCart; +module.exports = AddToCart; diff --git a/front-ui/app/components/cart/cartIcon.js b/front-ui/app/components/cart/cartIcon.js index 23e4cca..4571968 100644 --- a/front-ui/app/components/cart/cartIcon.js +++ b/front-ui/app/components/cart/cartIcon.js @@ -5,16 +5,16 @@ var NavigationActions = require('../../actions/navigationActions.js'); var LoginStatus = require('../shared/loginStatus'); CartTotal = require('./cartTotal'); - - -var cartStyle = { + + +var cartStyle = { fontSize: '50px' }; var normalizeCount = function(count) { if (count >= 0 && count < 10) { - return "\u00a0" + count; + return "\u00a0" + count; } else { return count; } @@ -22,24 +22,33 @@ var normalizeCount = function(count) { var CartIcon = React.createClass({ - render: function() { + render: function() { var textNotificationStyle = (this.state.count > 0) ? { display: 'inline-block'} : { display: 'none'} ; - return ( + return ( +
+
); }, // Add change listeners to stores componentDidMount: function() { - CartStore.addChangeListener(this._onChange); + CartStore.addChangeListener(this._onChange); if(!CartStore.dataStartedLoading()) { CartActions.load(); }; @@ -54,7 +63,7 @@ var CartIcon = React.createClass({ _onChange: function () { if (this.isMounted()) { - this.setState(CartStore.getWholeCartState()); + this.setState(CartStore.getWholeCartState()); } }, @@ -69,7 +78,4 @@ var CartIcon = React.createClass({ }); -module.exports = CartIcon; - - - +module.exports = CartIcon; diff --git a/front-ui/app/components/rootApp.js b/front-ui/app/components/rootApp.js index 3e283ed..9c16320 100644 --- a/front-ui/app/components/rootApp.js +++ b/front-ui/app/components/rootApp.js @@ -42,14 +42,20 @@ var RootApp = React.createClass({ return (
loading...
); } - return ( + return (
-
+ +
-
+ +
+ +
+ +