kms_catalog 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +37 -0
- data/app/assets/javascripts/kms_catalog/application/controllers/categories_controller.coffee +63 -0
- data/app/assets/javascripts/kms_catalog/application/controllers/option_types_controller.coffee +68 -0
- data/app/assets/javascripts/kms_catalog/application/controllers/option_values_controller.coffee +71 -0
- data/app/assets/javascripts/kms_catalog/application/controllers/products_controller.coffee +77 -0
- data/app/assets/javascripts/kms_catalog/application/controllers/properties_controller.coffee +38 -0
- data/app/assets/javascripts/kms_catalog/application/controllers/variants_controller.coffee +45 -0
- data/app/assets/javascripts/kms_catalog/application/routes.coffee.erb +97 -0
- data/app/assets/javascripts/kms_catalog/application.js +3 -0
- data/app/assets/javascripts/templates/categories/edit.html.slim +5 -0
- data/app/assets/javascripts/templates/categories/form.html.slim +32 -0
- data/app/assets/javascripts/templates/categories/index.html.slim +21 -0
- data/app/assets/javascripts/templates/categories/new.html.slim +5 -0
- data/app/assets/javascripts/templates/help/catalog_variables.html.slim +75 -0
- data/app/assets/javascripts/templates/products/edit.html.slim +25 -0
- data/app/assets/javascripts/templates/products/form.html.slim +34 -0
- data/app/assets/javascripts/templates/products/index.html.slim +22 -0
- data/app/assets/javascripts/templates/products/new.html.slim +5 -0
- data/app/assets/javascripts/templates/products/option_types.html.slim +47 -0
- data/app/assets/javascripts/templates/products/properties.html.slim +52 -0
- data/app/assets/javascripts/templates/products/variants/edit.html.slim +7 -0
- data/app/assets/javascripts/templates/products/variants/form.html.slim +18 -0
- data/app/assets/javascripts/templates/products/variants/index.html.slim +22 -0
- data/app/assets/javascripts/templates/products/variants/new.html.slim +5 -0
- data/app/assets/javascripts/templates/products/variants/option_types.html.slim +39 -0
- data/app/controllers/kms/catalog/categories_controller.rb +40 -0
- data/app/controllers/kms/catalog/option_types_controller.rb +42 -0
- data/app/controllers/kms/catalog/option_values_controller.rb +31 -0
- data/app/controllers/kms/catalog/products_controller.rb +40 -0
- data/app/controllers/kms/catalog/properties_controller.rb +41 -0
- data/app/controllers/kms/catalog/variants_controller.rb +46 -0
- data/app/models/kms/category.rb +23 -0
- data/app/models/kms/option_type.rb +12 -0
- data/app/models/kms/option_value.rb +9 -0
- data/app/models/kms/product.rb +20 -0
- data/app/models/kms/product_option_type.rb +6 -0
- data/app/models/kms/property.rb +6 -0
- data/app/models/kms/variant.rb +10 -0
- data/app/uploaders/category_logo_uploader.rb +51 -0
- data/app/uploaders/product_image_uploader.rb +51 -0
- data/config/initializers/ability.rb +4 -0
- data/config/initializers/externals.rb +2 -0
- data/config/initializers/help.rb +1 -0
- data/config/initializers/resources.rb +2 -0
- data/config/locales/en.yml +103 -0
- data/config/locales/ru.yml +102 -0
- data/config/routes.rb +24 -0
- data/db/migrate/20141112110053_create_categories.rb +9 -0
- data/db/migrate/20141112110205_add_ancestry_to_categories.rb +6 -0
- data/db/migrate/20141114085509_create_products.rb +11 -0
- data/db/migrate/20141114090047_create_categories_products.rb +11 -0
- data/db/migrate/20141115155853_add_slug_to_products.rb +6 -0
- data/db/migrate/20141115155858_add_slug_to_categories.rb +6 -0
- data/db/migrate/20150211160743_add_description_and_logo_to_categories.rb +6 -0
- data/db/migrate/20150212132208_add_preview_image_and_image_to_product.rb +6 -0
- data/db/migrate/20150212154511_create_properties.rb +11 -0
- data/db/migrate/20150213084534_create_option_types.rb +10 -0
- data/db/migrate/20150213084605_create_product_option_types.rb +12 -0
- data/db/migrate/20150216070337_create_variants.rb +12 -0
- data/db/migrate/20150216070829_create_option_values.rb +13 -0
- data/db/migrate/20150306060509_change_price_field_for_products.rb +6 -0
- data/db/migrate/20150310144540_add_position_to_category.rb +5 -0
- data/db/migrate/20150818073220_add_seo_fields_to_categories.rb +7 -0
- data/db/migrate/20150818073725_add_seo_fields_to_products.rb +7 -0
- data/db/migrate/20151001065303_add_image_to_variants.rb +5 -0
- data/lib/generators/kms_catalog/install/install_generator.rb +17 -0
- data/lib/kms/catalog/engine.rb +15 -0
- data/lib/kms/catalog/version.rb +5 -0
- data/lib/kms/drops/category_drop.rb +16 -0
- data/lib/kms/drops/product_drop.rb +35 -0
- data/lib/kms/drops/property_drop.rb +6 -0
- data/lib/kms/drops/variant_drop.rb +15 -0
- data/lib/kms_catalog.rb +6 -0
- data/lib/tasks/kms_catalog_tasks.rake +4 -0
- data/test/catalog_test.rb +7 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +77 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/fixtures/categories.yml +7 -0
- data/test/fixtures/option_types.yml +9 -0
- data/test/fixtures/option_values.yml +9 -0
- data/test/fixtures/product_option_types.yml +9 -0
- data/test/fixtures/products.yml +11 -0
- data/test/fixtures/properties.yml +11 -0
- data/test/fixtures/variants.yml +9 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/models/category_test.rb +7 -0
- data/test/models/option_type_test.rb +7 -0
- data/test/models/option_value_test.rb +7 -0
- data/test/models/product_option_type_test.rb +7 -0
- data/test/models/product_test.rb +7 -0
- data/test/models/property_test.rb +7 -0
- data/test/models/variant_test.rb +7 -0
- data/test/test_helper.rb +16 -0
- metadata +306 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 30844053e11e92d563963fdcf876d6b5991e3ebc
|
4
|
+
data.tar.gz: ed2c7a1f0f173c3a532b5de4196dadd9d51e43cd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fc6ca4ea3068bbe3f938b956e44ce6ba2ad16ceccc7d530ee8f2ef8d6179bf055fb8f69cc8cc071c2a2bb0ba2a93db00f45cbe521099ee405ea653ad1a7b8b6a
|
7
|
+
data.tar.gz: e9bed74cee7b334e6b767a9fdd4e6181407d76406db1bfbb3314733d007887fd8de7e9718e6dd0580b3326be4ac476e2dd1eab4e61749e550e817aec487eb677
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 Igor Petrov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Catalog'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'lib'
|
31
|
+
t.libs << 'test'
|
32
|
+
t.pattern = 'test/**/*_test.rb'
|
33
|
+
t.verbose = false
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
task default: :test
|
@@ -0,0 +1,63 @@
|
|
1
|
+
CategoriesController = ($scope, $state, $cookieStore, Restangular, $stateParams) ->
|
2
|
+
$scope.editorOptions =
|
3
|
+
filebrowserUploadUrl: '/assets/ckeditor'
|
4
|
+
$scope.store = Restangular.all('categories')
|
5
|
+
|
6
|
+
Restangular.all('users').customGET('kms_user').then (current_user) ->
|
7
|
+
$scope.currentUser = current_user
|
8
|
+
$scope.currentUser.admin = $scope.currentUser.role == 'admin'
|
9
|
+
|
10
|
+
$scope.exceptCurrentCategory = ->
|
11
|
+
new_categories = []
|
12
|
+
for p in $scope.categories
|
13
|
+
new_categories.push(p) if p.id != parseInt($stateParams.id)
|
14
|
+
new_categories
|
15
|
+
|
16
|
+
$scope.store.getList().then (categories)->
|
17
|
+
$scope.categories = categories
|
18
|
+
if $stateParams.id
|
19
|
+
$scope.categories = $scope.exceptCurrentCategory()
|
20
|
+
|
21
|
+
if $stateParams.id
|
22
|
+
$scope.store.get($stateParams.id).then (category)->
|
23
|
+
$scope.category = category
|
24
|
+
else
|
25
|
+
$scope.category = {}
|
26
|
+
|
27
|
+
$scope.create = ->
|
28
|
+
fd = new FormData
|
29
|
+
fd.append('category[name]', $scope.category.name || '')
|
30
|
+
fd.append('category[parent_id]', $scope.category.parent_id || '')
|
31
|
+
fd.append('category[description]', $scope.category.description || '')
|
32
|
+
fd.append('category[seo_title]', $scope.category.seo_title || '')
|
33
|
+
fd.append('category[seo_keywords]', $scope.category.seo_keywords || '')
|
34
|
+
fd.append('category[seo_description]', $scope.category.seo_description || '')
|
35
|
+
fd.append('category[logo]', $scope.category.logo)
|
36
|
+
$scope.store.withHttpConfig({ transformRequest: angular.identity }).post(fd, null, {"Content-Type": undefined}).then ->
|
37
|
+
$state.go('categories')
|
38
|
+
,->
|
39
|
+
console.log('bug')
|
40
|
+
|
41
|
+
$scope.update = ->
|
42
|
+
fd = new FormData
|
43
|
+
fd.append('category[name]', $scope.category.name || '')
|
44
|
+
fd.append('category[parent_id]', $scope.category.parent_id || '')
|
45
|
+
fd.append('category[description]', $scope.category.description || '')
|
46
|
+
fd.append('category[seo_title]', $scope.category.seo_title || '')
|
47
|
+
fd.append('category[seo_keywords]', $scope.category.seo_keywords || '')
|
48
|
+
fd.append('category[seo_description]', $scope.category.seo_description || '')
|
49
|
+
if $scope.category.logo.constructor.name == "File"
|
50
|
+
fd.append('category[logo]', $scope.category.logo)
|
51
|
+
$scope.category.withHttpConfig({ transformRequest: angular.identity }).post('', fd, '', {"Content-Type": undefined}).then ->
|
52
|
+
$state.go('categories')
|
53
|
+
,->
|
54
|
+
console.log('bug')
|
55
|
+
|
56
|
+
$scope.destroy = (category)->
|
57
|
+
category.remove().then ->
|
58
|
+
$scope.categories = _.without($scope.categories, category)
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
angular.module('KMS')
|
63
|
+
.controller('CategoriesController', ['$scope', '$state', '$cookieStore', 'Restangular', '$stateParams', CategoriesController])
|
data/app/assets/javascripts/kms_catalog/application/controllers/option_types_controller.coffee
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
OptionTypesController = ($scope, $state, $cookieStore, Restangular, $stateParams) ->
|
2
|
+
$scope.option_type = {}
|
3
|
+
# $scope.editorOptions =
|
4
|
+
# filebrowserUploadUrl: '/assets/ckeditor'
|
5
|
+
#
|
6
|
+
# Restangular.all('users').customGET('kms_user').then (current_user) ->
|
7
|
+
# $scope.currentUser = current_user
|
8
|
+
# $scope.currentUser.admin = $scope.currentUser.role == 'admin'
|
9
|
+
#
|
10
|
+
# $scope.categories = []
|
11
|
+
Restangular.all('option_types').getList().then (option_types) ->
|
12
|
+
$scope.global_option_types = option_types
|
13
|
+
|
14
|
+
$scope.store = Restangular.service('option_types', Restangular.one('products', $stateParams.id))
|
15
|
+
$scope.store.getList().then (option_types) ->
|
16
|
+
$scope.option_types = _.groupBy(option_types, 'tag')
|
17
|
+
$scope.tags = Object.keys($scope.option_types)
|
18
|
+
# $scope.store = Restangular.all('products')
|
19
|
+
# $scope.store.getList().then (products)->
|
20
|
+
# $scope.products = products
|
21
|
+
#
|
22
|
+
# if $stateParams.id
|
23
|
+
# $scope.store.get($stateParams.id).then (product)->
|
24
|
+
# $scope.product = product
|
25
|
+
# else
|
26
|
+
# $scope.product = {category_ids: []}
|
27
|
+
#
|
28
|
+
|
29
|
+
$scope.create = ->
|
30
|
+
$scope.store.post($scope.option_type).then ->
|
31
|
+
$scope.store.getList().then (option_types) ->
|
32
|
+
$scope.option_types = _.groupBy(option_types, 'tag')
|
33
|
+
$scope.tags = Object.keys($scope.option_types)
|
34
|
+
$scope.option_type = {}
|
35
|
+
console.log('option type created!')
|
36
|
+
,->
|
37
|
+
console.log('bug')
|
38
|
+
#
|
39
|
+
# $scope.update = ->
|
40
|
+
# fd = new FormData
|
41
|
+
# fd.append('product[name]', $scope.product.name || '')
|
42
|
+
# fd.append('product[description]', $scope.product.description || '')
|
43
|
+
# fd.append('product[price]', $scope.product.price || '')
|
44
|
+
# fd.append('product[category_ids]', $scope.product.category_ids)
|
45
|
+
# if $scope.product.image.constructor.name == "File"
|
46
|
+
# fd.append('product[image]', $scope.product.image)
|
47
|
+
# if $scope.product.preview_image.constructor.name == "File"
|
48
|
+
# fd.append('product[preview_image]', $scope.product.preview_image)
|
49
|
+
# $scope.product.withHttpConfig({ transformRequest: angular.identity }).post('', fd, '', {"Content-Type": undefined}).then ->
|
50
|
+
# $state.go('products')
|
51
|
+
# ,->
|
52
|
+
# console.log('bug')
|
53
|
+
#
|
54
|
+
$scope.destroy = (option_type)->
|
55
|
+
option_type.remove().then ->
|
56
|
+
$scope.store.getList().then (option_types) ->
|
57
|
+
$scope.option_types = _.groupBy(option_types, 'tag')
|
58
|
+
$scope.tags = Object.keys($scope.option_types)
|
59
|
+
#
|
60
|
+
# $scope.exceptCurrentCategory = ->
|
61
|
+
# new_products = []
|
62
|
+
# for p in $scope.products
|
63
|
+
# new_products.push(p) if p.id != ($scope.product && $scope.product.id)
|
64
|
+
# new_products
|
65
|
+
|
66
|
+
|
67
|
+
angular.module('KMS')
|
68
|
+
.controller('OptionTypesController', ['$scope', '$state', '$cookieStore', 'Restangular', '$stateParams', OptionTypesController])
|
data/app/assets/javascripts/kms_catalog/application/controllers/option_values_controller.coffee
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
OptionValuesController = ($scope, $state, $cookieStore, Restangular, $stateParams) ->
|
2
|
+
# $scope.editorOptions =
|
3
|
+
# filebrowserUploadUrl: '/assets/ckeditor'
|
4
|
+
#
|
5
|
+
# Restangular.all('users').customGET('kms_user').then (current_user) ->
|
6
|
+
# $scope.currentUser = current_user
|
7
|
+
# $scope.currentUser.admin = $scope.currentUser.role == 'admin'
|
8
|
+
#
|
9
|
+
# $scope.categories = []
|
10
|
+
$scope.option_value = {}
|
11
|
+
|
12
|
+
$scope.store = Restangular.one('products', $stateParams.product_id).one('variants', $stateParams.id).all('option_values')
|
13
|
+
$scope.store.getList().then (option_values) ->
|
14
|
+
$scope.option_values = _.groupBy(option_values, 'tag')
|
15
|
+
|
16
|
+
Restangular.one('products', $stateParams.product_id).one('variants', $stateParams.id).customGET('available_option_types').then (option_types) ->
|
17
|
+
$scope.available_option_types = option_types
|
18
|
+
|
19
|
+
# $scope.store = Restangular.all('products')
|
20
|
+
# $scope.store.getList().then (products)->
|
21
|
+
# $scope.products = products
|
22
|
+
#
|
23
|
+
# if $stateParams.id
|
24
|
+
# $scope.store.get($stateParams.id).then (product)->
|
25
|
+
# $scope.product = product
|
26
|
+
# else
|
27
|
+
# $scope.product = {category_ids: []}
|
28
|
+
#
|
29
|
+
|
30
|
+
$scope.create = ->
|
31
|
+
$scope.store.post($scope.option_value).then ->
|
32
|
+
$scope.store.getList().then (option_types) ->
|
33
|
+
$scope.option_values = _.groupBy(option_types, 'tag')
|
34
|
+
$scope.option_value = {}
|
35
|
+
Restangular.one('products', $stateParams.product_id).one('variants', $stateParams.id).customGET('available_option_types').then (option_types) ->
|
36
|
+
$scope.available_option_types = option_types
|
37
|
+
console.log('option value created!')
|
38
|
+
,->
|
39
|
+
console.log('bug')
|
40
|
+
|
41
|
+
# $scope.update = ->
|
42
|
+
# fd = new FormData
|
43
|
+
# fd.append('product[name]', $scope.product.name || '')
|
44
|
+
# fd.append('product[description]', $scope.product.description || '')
|
45
|
+
# fd.append('product[price]', $scope.product.price || '')
|
46
|
+
# fd.append('product[category_ids]', $scope.product.category_ids)
|
47
|
+
# if $scope.product.image.constructor.name == "File"
|
48
|
+
# fd.append('product[image]', $scope.product.image)
|
49
|
+
# if $scope.product.preview_image.constructor.name == "File"
|
50
|
+
# fd.append('product[preview_image]', $scope.product.preview_image)
|
51
|
+
# $scope.product.withHttpConfig({ transformRequest: angular.identity }).post('', fd, '', {"Content-Type": undefined}).then ->
|
52
|
+
# $state.go('products')
|
53
|
+
# ,->
|
54
|
+
# console.log('bug')
|
55
|
+
#
|
56
|
+
$scope.destroy = (option_value)->
|
57
|
+
option_value.remove().then ->
|
58
|
+
$scope.store.getList().then (option_values) ->
|
59
|
+
$scope.option_values = _.groupBy(option_values, 'tag')
|
60
|
+
Restangular.one('products', $stateParams.product_id).one('variants', $stateParams.id).customGET('available_option_types').then (option_types) ->
|
61
|
+
$scope.available_option_types = option_types
|
62
|
+
#
|
63
|
+
# $scope.exceptCurrentCategory = ->
|
64
|
+
# new_products = []
|
65
|
+
# for p in $scope.products
|
66
|
+
# new_products.push(p) if p.id != ($scope.product && $scope.product.id)
|
67
|
+
# new_products
|
68
|
+
|
69
|
+
|
70
|
+
angular.module('KMS')
|
71
|
+
.controller('OptionValuesController', ['$scope', '$state', '$cookieStore', 'Restangular', '$stateParams', OptionValuesController])
|
@@ -0,0 +1,77 @@
|
|
1
|
+
ProductsController = ($scope, $state, $cookieStore, Restangular, $stateParams) ->
|
2
|
+
$scope.editorOptions =
|
3
|
+
filebrowserUploadUrl: '/assets/ckeditor'
|
4
|
+
|
5
|
+
Restangular.all('users').customGET('kms_user').then (current_user) ->
|
6
|
+
$scope.currentUser = current_user
|
7
|
+
$scope.currentUser.admin = $scope.currentUser.role == 'admin'
|
8
|
+
|
9
|
+
$scope.categories = []
|
10
|
+
Restangular.all('categories').getList().then (categories)->
|
11
|
+
$scope.categories = categories
|
12
|
+
$scope.store = Restangular.all('products')
|
13
|
+
$scope.store.getList().then (products)->
|
14
|
+
$scope.products = products
|
15
|
+
|
16
|
+
if $stateParams.id
|
17
|
+
$scope.store.get($stateParams.id).then (product)->
|
18
|
+
$scope.product = product
|
19
|
+
else
|
20
|
+
$scope.product = {category_ids: []}
|
21
|
+
|
22
|
+
$scope.addCat = (item, model) ->
|
23
|
+
index = $scope.product.category_ids.indexOf(item.id)
|
24
|
+
unless index > -1
|
25
|
+
$scope.product.category_ids.push(item.id)
|
26
|
+
$scope.removeCat = (item, model) ->
|
27
|
+
index = $scope.product.category_ids.indexOf(item.id)
|
28
|
+
if index > -1
|
29
|
+
$scope.product.category_ids.splice(index, 1)
|
30
|
+
|
31
|
+
$scope.create = ->
|
32
|
+
fd = new FormData
|
33
|
+
fd.append('product[name]', $scope.product.name || '')
|
34
|
+
fd.append('product[description]', $scope.product.description || '')
|
35
|
+
fd.append('product[price]', $scope.product.price || '')
|
36
|
+
fd.append('product[category_ids]', $scope.product.category_ids)
|
37
|
+
fd.append('product[image]', $scope.product.image)
|
38
|
+
fd.append('product[preview_image]', $scope.product.preview_image)
|
39
|
+
fd.append('product[seo_title]', $scope.product.seo_title || '')
|
40
|
+
fd.append('product[seo_keywords]', $scope.product.seo_keywords || '')
|
41
|
+
fd.append('product[seo_description]', $scope.product.seo_description || '')
|
42
|
+
$scope.store.withHttpConfig({ transformRequest: angular.identity }).post(fd, null, {"Content-Type": undefined}).then ->
|
43
|
+
$state.go('products')
|
44
|
+
,->
|
45
|
+
console.log('bug')
|
46
|
+
|
47
|
+
$scope.update = ->
|
48
|
+
fd = new FormData
|
49
|
+
fd.append('product[name]', $scope.product.name || '')
|
50
|
+
fd.append('product[description]', $scope.product.description || '')
|
51
|
+
fd.append('product[price]', $scope.product.price || '')
|
52
|
+
fd.append('product[category_ids]', $scope.product.category_ids)
|
53
|
+
fd.append('product[seo_title]', $scope.product.seo_title || '')
|
54
|
+
fd.append('product[seo_keywords]', $scope.product.seo_keywords || '')
|
55
|
+
fd.append('product[seo_description]', $scope.product.seo_description || '')
|
56
|
+
if $scope.product.image.constructor.name == "File"
|
57
|
+
fd.append('product[image]', $scope.product.image)
|
58
|
+
if $scope.product.preview_image.constructor.name == "File"
|
59
|
+
fd.append('product[preview_image]', $scope.product.preview_image)
|
60
|
+
$scope.product.withHttpConfig({ transformRequest: angular.identity }).post('', fd, '', {"Content-Type": undefined}).then ->
|
61
|
+
$state.go('products')
|
62
|
+
,->
|
63
|
+
console.log('bug')
|
64
|
+
|
65
|
+
$scope.destroy = (product)->
|
66
|
+
product.remove().then ->
|
67
|
+
$scope.products = _.without($scope.products, product)
|
68
|
+
|
69
|
+
$scope.exceptCurrentCategory = ->
|
70
|
+
new_products = []
|
71
|
+
for p in $scope.products
|
72
|
+
new_products.push(p) if p.id != ($scope.product && $scope.product.id)
|
73
|
+
new_products
|
74
|
+
|
75
|
+
|
76
|
+
angular.module('KMS')
|
77
|
+
.controller('ProductsController', ['$scope', '$state', '$cookieStore', 'Restangular', '$stateParams', ProductsController])
|
@@ -0,0 +1,38 @@
|
|
1
|
+
PropertiesController = ($scope, $state, $cookieStore, Restangular, $stateParams) ->
|
2
|
+
$scope.property = {}
|
3
|
+
# $scope.editorOptions =
|
4
|
+
# filebrowserUploadUrl: '/assets/ckeditor'
|
5
|
+
#
|
6
|
+
# Restangular.all('users').customGET('kms_user').then (current_user) ->
|
7
|
+
# $scope.currentUser = current_user
|
8
|
+
# $scope.currentUser.admin = $scope.currentUser.role == 'admin'
|
9
|
+
#
|
10
|
+
# $scope.categories = []
|
11
|
+
$scope.store = Restangular.service('properties', Restangular.one('products', $stateParams.id))
|
12
|
+
$scope.store.getList().then (properties) ->
|
13
|
+
$scope.properties = _.groupBy(properties, 'tag')
|
14
|
+
$scope.tags = Object.keys($scope.properties)
|
15
|
+
|
16
|
+
$scope.create = ->
|
17
|
+
$scope.store.post($scope.property).then ->
|
18
|
+
$scope.store.getList().then (properties) ->
|
19
|
+
$scope.properties = _.groupBy(properties, 'tag')
|
20
|
+
$scope.tags = Object.keys($scope.properties)
|
21
|
+
$scope.property = {}
|
22
|
+
console.log('property created!')
|
23
|
+
,->
|
24
|
+
console.log('bug')
|
25
|
+
|
26
|
+
$scope.update = (data, property)->
|
27
|
+
property.name = data.name
|
28
|
+
property.value = data.value
|
29
|
+
property.save()
|
30
|
+
|
31
|
+
$scope.destroy = (property)->
|
32
|
+
property.remove().then ->
|
33
|
+
$scope.store.getList().then (properties) ->
|
34
|
+
$scope.properties = _.groupBy(properties, 'tag')
|
35
|
+
$scope.tags = Object.keys($scope.properties)
|
36
|
+
|
37
|
+
angular.module('KMS')
|
38
|
+
.controller('PropertiesController', ['$scope', '$state', '$cookieStore', 'Restangular', '$stateParams', PropertiesController])
|
@@ -0,0 +1,45 @@
|
|
1
|
+
VariantsController = ($scope, $state, $cookieStore, Restangular, $stateParams) ->
|
2
|
+
$scope.store = Restangular.one('products', $stateParams.product_id).all('variants')
|
3
|
+
$scope.store.getList().then (variants) ->
|
4
|
+
$scope.variants = variants#_.groupBy(option_types, 'tag')
|
5
|
+
|
6
|
+
if $stateParams.id
|
7
|
+
$scope.store.one($stateParams.id).get().then (variant)->
|
8
|
+
$scope.variant = variant
|
9
|
+
else
|
10
|
+
$scope.variant = {}
|
11
|
+
|
12
|
+
$scope.create = ->
|
13
|
+
fd = new FormData
|
14
|
+
fd.append('variant[name]', $scope.variant.name || '')
|
15
|
+
fd.append('variant[price]', $scope.variant.price || '')
|
16
|
+
fd.append('variant[image]', $scope.variant.image)
|
17
|
+
$scope.store.withHttpConfig({ transformRequest: angular.identity }).post(fd, null, {"Content-Type": undefined}).then (variant)->
|
18
|
+
$state.go('variants.edit', {product_id: $stateParams.product_id, id: variant.id})
|
19
|
+
,->
|
20
|
+
console.log('bug')
|
21
|
+
|
22
|
+
$scope.update = ->
|
23
|
+
fd = new FormData
|
24
|
+
fd.append('variant[name]', $scope.variant.name || '')
|
25
|
+
fd.append('variant[price]', $scope.variant.price || '')
|
26
|
+
if $scope.variant.image.constructor.name == "File"
|
27
|
+
fd.append('variant[image]', $scope.variant.image)
|
28
|
+
$scope.variant.withHttpConfig({ transformRequest: angular.identity }).post('', fd, '', {"Content-Type": undefined}).then ->
|
29
|
+
$state.go('variants')
|
30
|
+
,->
|
31
|
+
console.log('bug')
|
32
|
+
|
33
|
+
$scope.destroy = (variant)->
|
34
|
+
variant.remove().then ->
|
35
|
+
$scope.variants = _.without($scope.variants, variant)
|
36
|
+
|
37
|
+
# $scope.exceptCurrentCategory = ->
|
38
|
+
# new_products = []
|
39
|
+
# for p in $scope.products
|
40
|
+
# new_products.push(p) if p.id != ($scope.product && $scope.product.id)
|
41
|
+
# new_products
|
42
|
+
|
43
|
+
|
44
|
+
angular.module('KMS')
|
45
|
+
.controller('VariantsController', ['$scope', '$state', '$cookieStore', 'Restangular', '$stateParams', VariantsController])
|
@@ -0,0 +1,97 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
angular.module('KMS').config ['$stateProvider', '$urlRouterProvider', ($stateProvider, $urlRouterProvider) ->
|
4
|
+
|
5
|
+
# Application routes
|
6
|
+
$stateProvider
|
7
|
+
.state('categories', {
|
8
|
+
url: '/kms/categories',
|
9
|
+
views:
|
10
|
+
"header":
|
11
|
+
template: "<%= Kms::Category.model_name.human(count: 1.1) %>"
|
12
|
+
"@":
|
13
|
+
controller: 'CategoriesController',
|
14
|
+
controllerAs: 'categories',
|
15
|
+
templateUrl: 'categories/index.html',
|
16
|
+
})
|
17
|
+
.state('categories.new', {
|
18
|
+
url: '/new',
|
19
|
+
views:
|
20
|
+
"header@":
|
21
|
+
template: "<%= I18n.t(:new_category) %>"
|
22
|
+
"@":
|
23
|
+
controller: 'CategoriesController',
|
24
|
+
controllerAs: 'categories',
|
25
|
+
templateUrl: 'categories/new.html',
|
26
|
+
})
|
27
|
+
.state('categories.edit', {
|
28
|
+
url: '/:id/edit',
|
29
|
+
views:
|
30
|
+
"header@":
|
31
|
+
template: "<%= I18n.t(:edit_category) %>"
|
32
|
+
"@":
|
33
|
+
controller: 'CategoriesController',
|
34
|
+
controllerAs: 'categories',
|
35
|
+
templateUrl: 'categories/edit.html',
|
36
|
+
})
|
37
|
+
.state('products', {
|
38
|
+
url: '/kms/products',
|
39
|
+
views:
|
40
|
+
"header":
|
41
|
+
template: "<%= Kms::Product.model_name.human(count: 1.1) %>"
|
42
|
+
"@":
|
43
|
+
controller: 'ProductsController',
|
44
|
+
controllerAs: 'products',
|
45
|
+
templateUrl: 'products/index.html',
|
46
|
+
})
|
47
|
+
.state('products.new', {
|
48
|
+
url: '/new',
|
49
|
+
views:
|
50
|
+
"header@":
|
51
|
+
template: "<%= I18n.t(:new_product) %>"
|
52
|
+
"@":
|
53
|
+
controller: 'ProductsController',
|
54
|
+
controllerAs: 'products',
|
55
|
+
templateUrl: 'products/new.html',
|
56
|
+
})
|
57
|
+
.state('products.edit', {
|
58
|
+
url: '/:id/edit',
|
59
|
+
views:
|
60
|
+
"header@":
|
61
|
+
template: "<%= I18n.t(:edit_product) %>"
|
62
|
+
"@":
|
63
|
+
controller: 'ProductsController',
|
64
|
+
controllerAs: 'products',
|
65
|
+
templateUrl: 'products/edit.html',
|
66
|
+
})
|
67
|
+
.state('variants', {
|
68
|
+
url: '/kms/products/:product_id/variants',
|
69
|
+
views:
|
70
|
+
"header":
|
71
|
+
template: "<%= Kms::Variant.model_name.human(count: 1.1) %>"
|
72
|
+
"@":
|
73
|
+
controller: 'VariantsController',
|
74
|
+
controllerAs: 'variants',
|
75
|
+
templateUrl: 'products/variants/index.html'
|
76
|
+
})
|
77
|
+
.state('variants.new', {
|
78
|
+
url: '/new',
|
79
|
+
views:
|
80
|
+
"header@":
|
81
|
+
template: "<%= I18n.t(:new_variant) %>"
|
82
|
+
"@":
|
83
|
+
controller: 'VariantsController',
|
84
|
+
controllerAs: 'variants',
|
85
|
+
templateUrl: 'products/variants/new.html'
|
86
|
+
})
|
87
|
+
.state('variants.edit', {
|
88
|
+
url: '/:id/edit',
|
89
|
+
views:
|
90
|
+
"header@":
|
91
|
+
template: "<%= I18n.t(:edit_variant) %>"
|
92
|
+
"@":
|
93
|
+
controller: 'VariantsController',
|
94
|
+
controllerAs: 'variants',
|
95
|
+
templateUrl: 'products/variants/edit.html'
|
96
|
+
})
|
97
|
+
]
|
@@ -0,0 +1,32 @@
|
|
1
|
+
.form-group
|
2
|
+
label for="name" = Kms::Category.human_attribute_name(:name)
|
3
|
+
input#name.form-control type="text" ng-model="category.name"
|
4
|
+
.form-group
|
5
|
+
label for="parent_id" = Kms::Category.human_attribute_name(:parent)
|
6
|
+
select#parent_id.form-control ng-model="category.parent_id" ng-options="category.id as category.name for category in categories"
|
7
|
+
.form-group
|
8
|
+
label for="description" = Kms::Category.human_attribute_name(:description)
|
9
|
+
textarea#description.form-control ng-model="category.description" rows="15" ng-if="currentUser.admin" ui-codemirror="{lineNumbers: true, mode:'htmlmixed'}"
|
10
|
+
textarea#description.form-control ng-model="category.description" rows="15" ng-if="!currentUser.admin" ckeditor='editorOptions'
|
11
|
+
.form-group
|
12
|
+
label for="logo" = Kms::Category.human_attribute_name(:logo)
|
13
|
+
div flow-init="{singleFile: true, headers: setHeaders, fileParameterName: 'category[logo]'}" flow-files-submitted="category.logo = $flow.files[0].file" flow-file-added="!!{png:1,gif:1,jpg:1,jpeg:1}[$file.getExtension()]" flow-file-success="$file.msg = $message"
|
14
|
+
input type="file" flow-btn="" ng-model='category.logo'
|
15
|
+
div class="thumbnail" ng-show="!$flow.files.length"
|
16
|
+
img ng-src="{{category.logo.url}}"
|
17
|
+
div class="thumbnail" ng-show="$flow.files.length"
|
18
|
+
img flow-img="$flow.files[0]"
|
19
|
+
accordion close-others="true"
|
20
|
+
accordion-group is-open="status.open"
|
21
|
+
accordion-heading
|
22
|
+
i.pull-left.glyphicon ng-class="{'glyphicon-chevron-down': status.open, 'glyphicon-chevron-right': !status.open}"
|
23
|
+
| SEO
|
24
|
+
.form-group
|
25
|
+
label for="seo_title" = Kms::Category.human_attribute_name(:seo_title)
|
26
|
+
input#seo_title.form-control type="text" ng-model="category.seo_title"
|
27
|
+
.form-group
|
28
|
+
label for="seo_keywords" = Kms::Category.human_attribute_name(:seo_keywords)
|
29
|
+
input#seo_keywords.form-control type="text" ng-model="category.seo_keywords"
|
30
|
+
.form-group
|
31
|
+
label for="seo_description" = Kms::Category.human_attribute_name(:seo_description)
|
32
|
+
input#seo_description.form-control type="text" ng-model="category.seo_description"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
.row
|
2
|
+
.col-lg-12
|
3
|
+
.widget
|
4
|
+
.widget-header
|
5
|
+
i.fa.fa-list
|
6
|
+
= Kms::Category.model_name.human(count: 1.1)
|
7
|
+
a.btn.btn-sm.btn-primary.pull-right ui-sref="categories.new"
|
8
|
+
= I18n.t("add_category")
|
9
|
+
.widget-body.no-padding
|
10
|
+
.table-responsive
|
11
|
+
table.table
|
12
|
+
tbody
|
13
|
+
tr ng-repeat="category in categories"
|
14
|
+
td style="width: 80%"
|
15
|
+
| {{ category.name }}
|
16
|
+
td
|
17
|
+
.btn-group.pull-right
|
18
|
+
a.btn.btn-sm.btn-info ui-sref="categories.edit({id: category.id})"
|
19
|
+
i.fa.fa-pencil
|
20
|
+
a.btn.btn-sm.btn-danger ng-click="destroy(category)"
|
21
|
+
i.fa.fa-times
|