cloudrider 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/cloudrider.gemspec +0 -3
- data/generica/app/assets/javascripts/adapters/admin/taxon.js.em +2 -0
- data/generica/app/assets/javascripts/components/hero-splash.js.em +1 -15
- data/generica/app/assets/javascripts/components/products-showcase.js.em +6 -0
- data/generica/app/assets/javascripts/components/select-locale.js.em +2 -2
- data/generica/app/assets/javascripts/components/tr-span.js.em +1 -0
- data/generica/app/assets/javascripts/components/tree/taxon-li.js.em +27 -2
- data/generica/app/assets/javascripts/components/tree/taxon-wrapper.js.em +5 -18
- data/generica/app/assets/javascripts/config/i18n-translations.js.ls +6 -2
- data/generica/app/assets/javascripts/config/router.js.ls +4 -1
- data/generica/app/assets/javascripts/controllers/admin/messages/index_controller.js.em +10 -0
- data/generica/app/assets/javascripts/controllers/admin/product/edit_controller.js.em +10 -1
- data/generica/app/assets/javascripts/controllers/admin/products/new_controller.js.em +6 -0
- data/generica/app/assets/javascripts/controllers/admin/taxon/edit_controller.js.em +17 -0
- data/generica/app/assets/javascripts/controllers/admin/taxons/new_controller.js.em +25 -0
- data/generica/app/assets/javascripts/controllers/messages/new_controller.js.em +16 -0
- data/generica/app/assets/javascripts/controllers/products/index_controller.js.em +5 -8
- data/generica/app/assets/javascripts/helpers/hash_ex.js.ls +6 -0
- data/generica/app/assets/javascripts/helpers/string_ex.js.ls +1 -1
- data/generica/app/assets/javascripts/models/admin/product.js.em +2 -0
- data/generica/app/assets/javascripts/models/admin/taxon.js.em +4 -1
- data/generica/app/assets/javascripts/models/message.js.em +7 -0
- data/generica/app/assets/javascripts/models/product.js.em +7 -2
- data/generica/app/assets/javascripts/models/taxon.js.em +3 -5
- data/generica/app/assets/javascripts/routes/admin/messages/index_route.js.em +1 -0
- data/generica/app/assets/javascripts/routes/admin/taxon_route.js.em +3 -0
- data/generica/app/assets/javascripts/routes/admin/taxons/index_route.js.em +1 -1
- data/generica/app/assets/javascripts/routes/admin/taxons/new_route.js.em +2 -0
- data/generica/app/assets/javascripts/routes/index_route.js.em +3 -2
- data/generica/app/assets/javascripts/routes/products/index_route.js.em +1 -1
- data/generica/app/assets/javascripts/templates/admin.emblem +17 -5
- data/generica/app/assets/javascripts/templates/admin/messages/index.emblem +19 -0
- data/generica/app/assets/javascripts/templates/admin/messages/slice.emblem +12 -0
- data/generica/app/assets/javascripts/templates/admin/product/edit.emblem +23 -6
- data/generica/app/assets/javascripts/templates/admin/products/new.emblem +17 -0
- data/generica/app/assets/javascripts/templates/admin/products/slice.emblem +6 -1
- data/generica/app/assets/javascripts/templates/admin/taxon/edit.emblem +36 -0
- data/generica/app/assets/javascripts/templates/admin/taxons/index.emblem +1 -1
- data/generica/app/assets/javascripts/templates/admin/taxons/new.emblem +40 -0
- data/generica/app/assets/javascripts/templates/admin/translations/index.emblem +1 -1
- data/generica/app/assets/javascripts/templates/components/product-display.emblem +4 -0
- data/generica/app/assets/javascripts/templates/components/product-listing.emblem +9 -0
- data/generica/app/assets/javascripts/templates/components/search-and-filter.emblem +1 -1
- data/generica/app/assets/javascripts/templates/components/site-nav/_top-nav.emblem +1 -1
- data/generica/app/assets/javascripts/templates/components/table-booths.emblem +3 -65
- data/generica/app/assets/javascripts/templates/components/tree-taxon-li.emblem +11 -3
- data/generica/app/assets/javascripts/templates/components/tree-taxon-ul.emblem +6 -7
- data/generica/app/assets/javascripts/templates/components/tree-taxon-wrapper.emblem +2 -2
- data/generica/app/assets/javascripts/templates/employees/index.emblem +32 -0
- data/generica/app/assets/javascripts/templates/index.emblem +2 -1
- data/generica/app/assets/javascripts/templates/messages/new.emblem +43 -0
- data/generica/app/assets/javascripts/templates/products/product/show.emblem +8 -0
- data/generica/app/assets/javascripts/transforms/form_data_transformer.js.ls +4 -0
- data/generica/app/assets/stylesheets/apiv1/_admin.css.scss +1 -0
- data/generica/app/assets/stylesheets/apiv1/admin/messages/_index.css.scss +34 -0
- data/generica/app/assets/stylesheets/apiv1/components/_product-display.css.scss +24 -0
- data/generica/app/assets/stylesheets/apiv1/components/_product-listing.css.scss +27 -2
- data/generica/app/assets/stylesheets/apiv1/components/_table-booths.css.scss +10 -0
- data/generica/app/assets/stylesheets/apiv1/components/_tree-taxon-wrapper.css.scss +37 -22
- data/generica/app/assets/stylesheets/apiv1/products/product/_show.css.scss +24 -0
- data/generica/app/assets/stylesheets/apiv1/shared/_constants.css.scss +2 -2
- data/generica/app/controllers/admin/taxons/create_controller.rb +26 -0
- data/generica/app/controllers/apiv1/i18n_translations/index_controller.rb +9 -5
- data/generica/app/controllers/apiv1/messages/create_controller.rb +17 -0
- data/generica/app/controllers/apiv1/messages/index_controller.rb +18 -0
- data/generica/app/controllers/apiv1/products/index_controller.rb +1 -1
- data/generica/app/controllers/apiv1/taxons/destroy_controller.rb +9 -0
- data/generica/app/controllers/apiv1/taxons/index_controller.rb +1 -0
- data/generica/app/controllers/apiv1/taxons/update_controller.rb +28 -0
- data/generica/app/controllers/apiv1/translations/create_controller.rb +5 -4
- data/generica/app/controllers/apiv1/translations/update_controller.rb +2 -2
- data/generica/app/models/admin/product_modifier.rb +16 -3
- data/generica/app/models/admin/taxon_factory.rb +23 -0
- data/generica/app/models/admin/taxon_relationships_factory.rb +32 -0
- data/generica/app/models/apiv1/employee.rb +1 -2
- data/generica/app/models/apiv1/message.rb +24 -0
- data/generica/app/models/apiv1/messages_machine.rb +31 -0
- data/generica/app/models/apiv1/product.rb +33 -13
- data/generica/app/models/apiv1/products_machine.rb +9 -1
- data/generica/app/models/apiv1/taxon.rb +8 -2
- data/generica/app/models/apiv1/translation.rb +73 -14
- data/generica/app/models/i18n/backend/active_record.rb +49 -0
- data/generica/app/varissets/javascripts/templates/components/introductory-lobby.emblem.erb +15 -1
- data/generica/app/varissets/javascripts/templates/components/table-booths.emblem.erb +39 -0
- data/generica/app/varissets/stylesheets/apiv1/components/_introductory-lobby.css.scss.erb +15 -1
- data/generica/app/varissets/stylesheets/apiv1/components/_table-booths.css.scss.erb +71 -0
- data/generica/config/initializers/i18n_backend.rb +7 -0
- data/generica/config/routes.rb +5 -2
- data/generica/db/migrate/20141010215459_create_apiv1_translations.rb +3 -1
- data/generica/db/migrate/20141105231548_add_showcase_priority_to_apiv1_products.rb +5 -0
- data/generica/db/migrate/20141107174821_create_apiv1_messages.rb +12 -0
- data/generica/db/schema.rb +11 -16
- data/generica/lib/tasks/production.rake +2 -1
- data/generica/spec/controllers/admin/taxons/create_controller_spec.rb +44 -0
- data/generica/spec/controllers/apiv1/messages/index_controller_spec.rb +5 -0
- data/generica/spec/controllers/apiv1/taxons/index_controller_spec.rb +59 -0
- data/generica/spec/controllers/apiv1/taxons/update_controller_spec.rb +54 -0
- data/generica/spec/controllers/apiv1/translations/create_controller_spec.rb +50 -0
- data/generica/spec/controllers/apiv1/translations/update_controller_spec.rb +54 -0
- data/generica/spec/factories/apiv1/product_factory.rb +12 -11
- data/generica/spec/models/admin/product_modifier_spec.rb +32 -0
- data/generica/spec/models/admin/taxon_relationships_factory_spec.rb +49 -0
- data/generica/spec/models/apiv1/message_spec.rb +16 -0
- data/generica/spec/models/apiv1/product_spec.rb +13 -12
- data/generica/spec/models/apiv1/translation_spec.rb +41 -0
- data/generica/spec/models/i18n/backend/active_record_spec.rb +27 -0
- data/lib/cloudrider/apiv1/base.rb +4 -4
- data/lib/cloudrider/apiv1/introductory_lobby_component.rb +1 -0
- data/lib/cloudrider/apiv1/introductory_lobby_sass.rb +9 -0
- data/lib/cloudrider/apiv1/table_booths_component.rb +6 -0
- data/lib/cloudrider/master_context.rb +105 -0
- data/lib/cloudrider/version.rb +1 -1
- metadata +43 -31
- data/generica/app/assets/javascripts/components/products-showcase.js.ls +0 -5
- data/generica/config/locales/ar.yml +0 -78
- data/generica/config/locales/ca.yml +0 -78
- data/generica/config/locales/cs.yml +0 -78
- data/generica/config/locales/da.yml +0 -78
- data/generica/config/locales/de.yml +0 -78
- data/generica/config/locales/el.yml +0 -78
- data/generica/config/locales/en.yml +0 -78
- data/generica/config/locales/es.yml +0 -78
- data/generica/config/locales/fi.yml +0 -78
- data/generica/config/locales/fr.yml +0 -78
- data/generica/config/locales/hu.yml +0 -78
- data/generica/config/locales/id.yml +0 -78
- data/generica/config/locales/is.yml +0 -78
- data/generica/config/locales/it.yml +0 -78
- data/generica/config/locales/ja.yml +0 -78
- data/generica/config/locales/ko.yml +0 -78
- data/generica/config/locales/ms.yml +0 -78
- data/generica/config/locales/nl.yml +0 -78
- data/generica/config/locales/no.yml +0 -78
- data/generica/config/locales/pl.yml +0 -78
- data/generica/config/locales/pt.yml +0 -78
- data/generica/config/locales/ru.yml +0 -78
- data/generica/config/locales/sv.yml +0 -78
- data/generica/config/locales/th.yml +0 -78
- data/generica/config/locales/tr.yml +0 -78
- data/generica/config/locales/zh-CN.yml +0 -78
- data/generica/config/locales/zh-TW.yml +0 -78
- data/lib/cloudrider/file_orders_maker.rb +0 -24
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
class Apiv1::I18nTranslations::IndexController < ApplicationController
|
|
2
2
|
def index
|
|
3
|
-
|
|
4
|
-
render json: { translations: I18n.backend.send(:translations), locale: I18n.locale }
|
|
3
|
+
render json: { translations: _translations, locale: _locale }
|
|
5
4
|
end
|
|
6
5
|
private
|
|
7
|
-
def
|
|
8
|
-
|
|
6
|
+
def _translations
|
|
7
|
+
{ _locale.to_s => _key_value_hash }
|
|
8
|
+
end
|
|
9
|
+
def _locale
|
|
10
|
+
params[:locale].present? ? params[:locale] : I18n.locale
|
|
11
|
+
end
|
|
12
|
+
def _key_value_hash
|
|
13
|
+
Apiv1::Translation.locale(_locale).map(&:tl_hash).reduce(&:merge)
|
|
9
14
|
end
|
|
10
|
-
|
|
11
15
|
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class Apiv1::Messages::CreateController < Apiv1::HomeController
|
|
2
|
+
def create
|
|
3
|
+
if _message.valid?
|
|
4
|
+
_message.save!
|
|
5
|
+
render json: { message: _message.to_ember_hash }
|
|
6
|
+
else
|
|
7
|
+
render json: _message.errors.to_h, status: :expectation_failed
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
private
|
|
11
|
+
def _message
|
|
12
|
+
@message ||= Apiv1::Message.new _message_params
|
|
13
|
+
end
|
|
14
|
+
def _message_params
|
|
15
|
+
params.require(:message).permit(:from_company, :sender_email, :subject_text, :message)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class Apiv1::Messages::IndexController < Admin::BaseController
|
|
2
|
+
def index
|
|
3
|
+
render json: { messages: _messages_hash, meta: _meta_hash }
|
|
4
|
+
end
|
|
5
|
+
private
|
|
6
|
+
def _messages_hash
|
|
7
|
+
_messages_machine.messages.map &:to_ember_hash
|
|
8
|
+
end
|
|
9
|
+
def _meta_hash
|
|
10
|
+
_messages_machine.meta
|
|
11
|
+
end
|
|
12
|
+
def _messages_machine
|
|
13
|
+
@messages_machine ||= Apiv1::MessagesMachine.new _query_params
|
|
14
|
+
end
|
|
15
|
+
def _query_params
|
|
16
|
+
params.permit(:page, :per, :order)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -16,6 +16,6 @@ class Apiv1::Products::IndexController < Apiv1::HomeController
|
|
|
16
16
|
@products_machine ||= Apiv1::ProductsMachine.new _query_params
|
|
17
17
|
end
|
|
18
18
|
def _query_params
|
|
19
|
-
params.permit(:page, :per, :query).merge taxons: params[:taxons]
|
|
19
|
+
params.permit(:page, :per, :query, :order).merge taxons: params[:taxons]
|
|
20
20
|
end
|
|
21
21
|
end
|
|
@@ -6,6 +6,7 @@ class Apiv1::Taxons::IndexController < Apiv1::HomeController
|
|
|
6
6
|
def _taxons
|
|
7
7
|
Apiv1::Taxon.pipeline -> (t) { t.by_root_genus(params[:root_genus]) if params[:root_genus].present? },
|
|
8
8
|
-> (t) { t.children_of_parent(params[:parent_id]) if params[:parent_id].present? },
|
|
9
|
+
-> (t) { t.root_generation if params.has_key?(:parent_id) && params[:parent_id].blank? },
|
|
9
10
|
-> (t) { t.all }
|
|
10
11
|
end
|
|
11
12
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
class Apiv1::Taxons::UpdateController < Admin::BaseController
|
|
2
|
+
def update
|
|
3
|
+
if _update_valid?
|
|
4
|
+
render json: { taxon: _update_taxon! }
|
|
5
|
+
else
|
|
6
|
+
render json: { taxon: _failure_hash }, status: :expectation_failed
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
private
|
|
10
|
+
def _failure_hash
|
|
11
|
+
_updated_taxon.errors.to_h
|
|
12
|
+
end
|
|
13
|
+
def _update_valid?
|
|
14
|
+
_updated_taxon.valid?
|
|
15
|
+
end
|
|
16
|
+
def _updated_taxon
|
|
17
|
+
@taxon ||= _taxon.tap { |t| t.assign_attributes _taxon_params }
|
|
18
|
+
end
|
|
19
|
+
def _update_taxon!
|
|
20
|
+
_updated_taxon.tap(&:save!)
|
|
21
|
+
end
|
|
22
|
+
def _taxon
|
|
23
|
+
Apiv1::Taxon.find params[:id]
|
|
24
|
+
end
|
|
25
|
+
def _taxon_params
|
|
26
|
+
params.require(:taxon).permit :taxon_name, :explanation
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -2,6 +2,7 @@ class Apiv1::Translations::CreateController < Admin::BaseController
|
|
|
2
2
|
|
|
3
3
|
def create
|
|
4
4
|
if _save_successful?
|
|
5
|
+
_translation.save!
|
|
5
6
|
render json: { translation: _translation_hash }
|
|
6
7
|
else
|
|
7
8
|
render json: { translation: _failure_hash }, status: :expectation_failed
|
|
@@ -10,19 +11,19 @@ class Apiv1::Translations::CreateController < Admin::BaseController
|
|
|
10
11
|
|
|
11
12
|
private
|
|
12
13
|
def _save_successful?
|
|
13
|
-
_translation.valid?
|
|
14
|
+
_translation.valid?
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
def _translation
|
|
17
|
-
@translation ||= Apiv1::Translation.
|
|
18
|
+
@translation ||= Apiv1::Translation.new _translation_params
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
def _translation_params
|
|
21
|
-
params.require(:translation).permit(:key, :locale, :translated_text)
|
|
22
|
+
params.require(:translation).permit(:key, :locale, :translated_text, :value)
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
def _translation_hash
|
|
25
|
-
_translation.
|
|
26
|
+
_translation.to_ember_hash
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
def _failure_hash
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
class Apiv1::Translations::UpdateController < Admin::BaseController
|
|
2
2
|
|
|
3
|
-
def
|
|
3
|
+
def update
|
|
4
4
|
if _update_successful?
|
|
5
5
|
render json: { translation: _translation_hash }
|
|
6
6
|
else
|
|
@@ -22,7 +22,7 @@ class Apiv1::Translations::UpdateController < Admin::BaseController
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def _translation_params
|
|
25
|
-
params.require(:translation).permit(:key, :locale, :translated_text)
|
|
25
|
+
params.require(:translation).permit(:key, :locale, :translated_text, :value)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def _translation_hash
|
|
@@ -13,11 +13,12 @@ class Admin::ProductModifier
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def update!
|
|
16
|
-
|
|
16
|
+
_bad_relationships.map(&:destroy)
|
|
17
|
+
_product.tap(&:save!)
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
def satisfy_specifications?
|
|
20
|
-
_pictures.all?(&:valid?) && _product.valid?
|
|
21
|
+
_pictures.all?(&:valid?) && _good_relationships.all?(&:valid?) && _product.valid?
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
private
|
|
@@ -26,13 +27,25 @@ class Admin::ProductModifier
|
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
def _assignable_attributes
|
|
29
|
-
@raw_params.permit
|
|
30
|
+
@raw_params.permit(*Apiv1::Product::Fields)
|
|
30
31
|
end
|
|
31
32
|
|
|
32
33
|
def _pictures
|
|
33
34
|
_pictures_factory.pictures
|
|
34
35
|
end
|
|
35
36
|
|
|
37
|
+
def _bad_relationships
|
|
38
|
+
_relationships_factory.bad_relationships
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def _good_relationships
|
|
42
|
+
_relationships_factory.good_relationships
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def _relationships_factory
|
|
46
|
+
@relationships_factory ||= Admin::TaxonRelationshipsFactory.new _product, @raw_params[:taxons]
|
|
47
|
+
end
|
|
48
|
+
|
|
36
49
|
def _pictures_factory
|
|
37
50
|
@pictures_factory ||= Admin::PicturesFactory.new _product, @raw_params[:pictures]
|
|
38
51
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class Admin::TaxonFactory
|
|
2
|
+
delegate :save!,
|
|
3
|
+
to: :_taxon
|
|
4
|
+
def initialize(params)
|
|
5
|
+
@params = params
|
|
6
|
+
end
|
|
7
|
+
def satisfy_specifications?
|
|
8
|
+
_taxon.valid?
|
|
9
|
+
end
|
|
10
|
+
def taxon_hash
|
|
11
|
+
{ taxon: _taxon.to_ember_hash }
|
|
12
|
+
end
|
|
13
|
+
def error_hash
|
|
14
|
+
_taxon.errors.to_h
|
|
15
|
+
end
|
|
16
|
+
private
|
|
17
|
+
def _taxon
|
|
18
|
+
@taxon ||= Apiv1::Taxon.new _taxon_params
|
|
19
|
+
end
|
|
20
|
+
def _taxon_params
|
|
21
|
+
@params.permit *Apiv1::Taxon::Fields
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
class Admin::TaxonRelationshipsFactory
|
|
2
|
+
def initialize(product, params)
|
|
3
|
+
@product = product
|
|
4
|
+
@taxons = Apiv1::Taxon.find _arrayify params
|
|
5
|
+
end
|
|
6
|
+
def good_relationships
|
|
7
|
+
@good_relationships ||= _good_taxon_ids.map { |id| _existing_relationship(id) || _new_relationship(id) }
|
|
8
|
+
end
|
|
9
|
+
def bad_relationships
|
|
10
|
+
@bad_relationships ||= @product.taxon_relationships.where taxon_id: _bad_taxon_ids
|
|
11
|
+
end
|
|
12
|
+
private
|
|
13
|
+
def _arrayify(array_like)
|
|
14
|
+
return array_like if array_like.is_a? Array
|
|
15
|
+
array_like.to_a.map(&:last)
|
|
16
|
+
end
|
|
17
|
+
def _existing_relationship(id)
|
|
18
|
+
@product.taxon_relationships.find_by_taxon_id id
|
|
19
|
+
end
|
|
20
|
+
def _new_relationship(id)
|
|
21
|
+
@product.taxon_relationships.new taxon_id: id
|
|
22
|
+
end
|
|
23
|
+
def _good_taxon_ids
|
|
24
|
+
@taxons.map(&:id)
|
|
25
|
+
end
|
|
26
|
+
def _bad_taxon_ids
|
|
27
|
+
_existing_taxon_ids - _good_taxon_ids
|
|
28
|
+
end
|
|
29
|
+
def _existing_taxon_ids
|
|
30
|
+
@product.taxons.map &:id
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
# employee_title :string(255)
|
|
8
8
|
# email :string(255)
|
|
9
9
|
# phone_number :string(255)
|
|
10
|
-
# picture_id :integer
|
|
11
10
|
# created_at :datetime
|
|
12
11
|
# updated_at :datetime
|
|
13
12
|
#
|
|
@@ -26,4 +25,4 @@ class Apiv1::Employee < ActiveRecord::Base
|
|
|
26
25
|
return attributes.merge mug_shot: pictures.first.pic(:thumb) if pictures.present?
|
|
27
26
|
attributes
|
|
28
27
|
end
|
|
29
|
-
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# == Schema Information
|
|
2
|
+
#
|
|
3
|
+
# Table name: apiv1_messages
|
|
4
|
+
#
|
|
5
|
+
# id :integer not null, primary key
|
|
6
|
+
# from_company :string(255)
|
|
7
|
+
# sender_email :string(255)
|
|
8
|
+
# subject_text :string(255)
|
|
9
|
+
# message :text
|
|
10
|
+
# created_at :datetime
|
|
11
|
+
# updated_at :datetime
|
|
12
|
+
#
|
|
13
|
+
|
|
14
|
+
class Apiv1::Message < ActiveRecord::Base
|
|
15
|
+
validates :from_company,
|
|
16
|
+
:sender_email,
|
|
17
|
+
:subject_text,
|
|
18
|
+
:message,
|
|
19
|
+
presence: true
|
|
20
|
+
|
|
21
|
+
def to_ember_hash
|
|
22
|
+
attributes
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
class Apiv1::MessagesMachine
|
|
2
|
+
def initialize(params)
|
|
3
|
+
@params = params
|
|
4
|
+
end
|
|
5
|
+
def messages
|
|
6
|
+
@messages ||= _filter_pipeline.call Apiv1::Message
|
|
7
|
+
end
|
|
8
|
+
def meta
|
|
9
|
+
{
|
|
10
|
+
total: Apiv1::Message.count,
|
|
11
|
+
per: _per_page,
|
|
12
|
+
page: _page
|
|
13
|
+
}
|
|
14
|
+
end
|
|
15
|
+
private
|
|
16
|
+
def _filter_pipeline
|
|
17
|
+
_order_by_created_at >> _paginate
|
|
18
|
+
end
|
|
19
|
+
def _order_by_created_at
|
|
20
|
+
-> (t) { t.order "created_at desc" }
|
|
21
|
+
end
|
|
22
|
+
def _paginate
|
|
23
|
+
-> (t) { t.page(_page).per(_per_page)}
|
|
24
|
+
end
|
|
25
|
+
def _per_page
|
|
26
|
+
@params[:per] || 15
|
|
27
|
+
end
|
|
28
|
+
def _page
|
|
29
|
+
@params[:page] || 1
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -2,23 +2,33 @@
|
|
|
2
2
|
#
|
|
3
3
|
# Table name: apiv1_products
|
|
4
4
|
#
|
|
5
|
-
# id
|
|
6
|
-
# permalink
|
|
7
|
-
# sku
|
|
8
|
-
# material
|
|
9
|
-
# quality
|
|
10
|
-
# price
|
|
11
|
-
# amount
|
|
12
|
-
# place
|
|
13
|
-
# others
|
|
14
|
-
# created_at
|
|
15
|
-
# updated_at
|
|
5
|
+
# id :integer not null, primary key
|
|
6
|
+
# permalink :string(255)
|
|
7
|
+
# sku :string(255)
|
|
8
|
+
# material :string(255)
|
|
9
|
+
# quality :string(255)
|
|
10
|
+
# price :string(255)
|
|
11
|
+
# amount :string(255)
|
|
12
|
+
# place :string(255)
|
|
13
|
+
# others :text
|
|
14
|
+
# created_at :datetime
|
|
15
|
+
# updated_at :datetime
|
|
16
|
+
# showcase_order :integer
|
|
16
17
|
#
|
|
17
18
|
|
|
18
19
|
class Apiv1::Product < ActiveRecord::Base
|
|
19
20
|
include ::Elasticsearch::Model
|
|
20
21
|
include ::Elasticsearch::Model::Callbacks
|
|
21
|
-
Fields = [
|
|
22
|
+
Fields = [
|
|
23
|
+
:sku,
|
|
24
|
+
:material,
|
|
25
|
+
:price,
|
|
26
|
+
:amount,
|
|
27
|
+
:place,
|
|
28
|
+
:others,
|
|
29
|
+
:quality,
|
|
30
|
+
:showcase_order
|
|
31
|
+
]
|
|
22
32
|
has_many :taxon_relationships,
|
|
23
33
|
class_name: 'Apiv1::Listings::TaxonRelationship',
|
|
24
34
|
as: :listing
|
|
@@ -46,11 +56,18 @@ class Apiv1::Product < ActiveRecord::Base
|
|
|
46
56
|
scope :order_by_created_at,
|
|
47
57
|
-> { order "#{self.table_name}.created_at desc"}
|
|
48
58
|
|
|
59
|
+
scope :worthy_of_showcase,
|
|
60
|
+
-> { where "#{self.table_name}.showcase_order is not null" }
|
|
61
|
+
|
|
62
|
+
scope :order_by_showcase,
|
|
63
|
+
-> { order "#{self.table_name}.showcase_order asc"}
|
|
64
|
+
|
|
49
65
|
validates :material,
|
|
50
66
|
:pictures,
|
|
51
67
|
presence: true
|
|
52
68
|
|
|
53
|
-
before_create :_make_permalink
|
|
69
|
+
before_create :_make_permalink,
|
|
70
|
+
:_make_showcase_order
|
|
54
71
|
|
|
55
72
|
class << self
|
|
56
73
|
def find_by_permalink_or_id!(permalink_or_id)
|
|
@@ -68,4 +85,7 @@ class Apiv1::Product < ActiveRecord::Base
|
|
|
68
85
|
def _make_permalink
|
|
69
86
|
self.permalink ||= Apiv1::Permalinkifier.permalinkify material
|
|
70
87
|
end
|
|
88
|
+
def _make_showcase_order
|
|
89
|
+
self.showcase_order ||= self.class.last.try(:id).to_i + 1
|
|
90
|
+
end
|
|
71
91
|
end
|
|
@@ -36,7 +36,12 @@ class Apiv1::ProductsMachine
|
|
|
36
36
|
-> (t) { t.page(_page).per(_per_page) }
|
|
37
37
|
end
|
|
38
38
|
def _process_ordering
|
|
39
|
-
|
|
39
|
+
case _order
|
|
40
|
+
when "showcase"
|
|
41
|
+
-> (product) { product.order_by_showcase }
|
|
42
|
+
else
|
|
43
|
+
-> (product) { product.order_by_created_at }
|
|
44
|
+
end
|
|
40
45
|
end
|
|
41
46
|
def _process_taxons
|
|
42
47
|
lambda do |product|
|
|
@@ -62,4 +67,7 @@ class Apiv1::ProductsMachine
|
|
|
62
67
|
def _per_page
|
|
63
68
|
params[:per] || 15
|
|
64
69
|
end
|
|
70
|
+
def _order
|
|
71
|
+
params[:order]
|
|
72
|
+
end
|
|
65
73
|
end
|
|
@@ -6,14 +6,15 @@
|
|
|
6
6
|
# parent_id :integer
|
|
7
7
|
# root_genus :string(255) not null
|
|
8
8
|
# taxon_name :string(255) not null
|
|
9
|
-
# permalink :string(255) not null
|
|
10
9
|
# explanation :string(255)
|
|
10
|
+
# permalink :string(255) not null
|
|
11
11
|
# first_child_at :datetime
|
|
12
12
|
# created_at :datetime
|
|
13
13
|
# updated_at :datetime
|
|
14
14
|
#
|
|
15
15
|
|
|
16
16
|
class Apiv1::Taxon < ActiveRecord::Base
|
|
17
|
+
Fields = [:taxon_name, :explanation, :parent_id]
|
|
17
18
|
class << self
|
|
18
19
|
def find_by_permalink_genus(str, genus)
|
|
19
20
|
permalink = Apiv1::Permalinkifier.permalinkify str
|
|
@@ -40,7 +41,8 @@ class Apiv1::Taxon < ActiveRecord::Base
|
|
|
40
41
|
class_name: 'Apiv1::Taxon',
|
|
41
42
|
foreign_key: 'parent_id'
|
|
42
43
|
|
|
43
|
-
before_validation :_create_permalink
|
|
44
|
+
before_validation :_create_permalink,
|
|
45
|
+
:_create_root_genus
|
|
44
46
|
before_create :_inform_parent
|
|
45
47
|
|
|
46
48
|
validates :root_genus,
|
|
@@ -82,6 +84,10 @@ class Apiv1::Taxon < ActiveRecord::Base
|
|
|
82
84
|
def _create_permalink
|
|
83
85
|
self.permalink ||= Apiv1::Permalinkifier.permalinkify taxon_name
|
|
84
86
|
end
|
|
87
|
+
def _create_root_genus
|
|
88
|
+
self.root_genus ||= parent.try :root_genus
|
|
89
|
+
self.root_genus ||= Apiv1::Permalinkifier.permalinkify taxon_name
|
|
90
|
+
end
|
|
85
91
|
def _inform_parent
|
|
86
92
|
parent.try :have_first_child!
|
|
87
93
|
end
|