kms_models 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +37 -0
  4. data/app/assets/javascripts/kms_models/application/controllers/entries_controller.coffee +91 -0
  5. data/app/assets/javascripts/kms_models/application/controllers/fields_controller.coffee.erb +42 -0
  6. data/app/assets/javascripts/kms_models/application/controllers/models_controller.coffee +42 -0
  7. data/app/assets/javascripts/kms_models/application/routes.coffee.erb +67 -0
  8. data/app/assets/javascripts/kms_models/application.js +15 -0
  9. data/app/assets/javascripts/templates/entries/edit.html.slim +9 -0
  10. data/app/assets/javascripts/templates/entries/form.html.slim +3 -0
  11. data/app/assets/javascripts/templates/entries/index.html.slim +21 -0
  12. data/app/assets/javascripts/templates/entries/new.html.slim +5 -0
  13. data/app/assets/javascripts/templates/fields/belongs_to_field.html.slim +7 -0
  14. data/app/assets/javascripts/templates/fields/checkbox_field.html.slim +4 -0
  15. data/app/assets/javascripts/templates/fields/file_field.html.slim +8 -0
  16. data/app/assets/javascripts/templates/fields/has_many_field.html.slim +7 -0
  17. data/app/assets/javascripts/templates/fields/string_field.html.slim +3 -0
  18. data/app/assets/javascripts/templates/fields/text_field.html.slim +3 -0
  19. data/app/assets/javascripts/templates/help/models_variables.html.slim +10 -0
  20. data/app/assets/javascripts/templates/models/edit.html.slim +6 -0
  21. data/app/assets/javascripts/templates/models/fields.html.slim +36 -0
  22. data/app/assets/javascripts/templates/models/form.html.slim +10 -0
  23. data/app/assets/javascripts/templates/models/index.html.slim +20 -0
  24. data/app/assets/javascripts/templates/models/new.html.slim +6 -0
  25. data/app/assets/stylesheets/kms_models/application.css +15 -0
  26. data/app/controllers/kms/models/entries_controller.rb +49 -0
  27. data/app/controllers/kms/models/models_controller.rb +51 -0
  28. data/app/helpers/kms_models/application_helper.rb +4 -0
  29. data/app/models/kms/belongs_to_field.rb +9 -0
  30. data/app/models/kms/checkbox_field.rb +4 -0
  31. data/app/models/kms/entry.rb +64 -0
  32. data/app/models/kms/field.rb +12 -0
  33. data/app/models/kms/file_field.rb +10 -0
  34. data/app/models/kms/has_many_field.rb +9 -0
  35. data/app/models/kms/model.rb +22 -0
  36. data/app/models/kms/models_wrapper.rb +14 -0
  37. data/app/models/kms/page_decorator.rb +18 -0
  38. data/app/models/kms/string_field.rb +4 -0
  39. data/app/models/kms/text_field.rb +4 -0
  40. data/app/serializers/kms/entry_serializer.rb +23 -0
  41. data/app/serializers/kms/simple_model_serializer.rb +5 -0
  42. data/app/uploaders/entry_file_uploader.rb +51 -0
  43. data/app/views/layouts/kms_models/application.html.erb +14 -0
  44. data/config/initializers/ability.rb +7 -0
  45. data/config/initializers/externals.rb +1 -0
  46. data/config/initializers/help.rb +1 -0
  47. data/config/initializers/resources.rb +6 -0
  48. data/config/locales/en.yml +52 -0
  49. data/config/locales/ru.yml +52 -0
  50. data/config/routes.rb +11 -0
  51. data/db/migrate/20150409124420_create_kms_models.rb +10 -0
  52. data/db/migrate/20150409125056_create_kms_fields.rb +13 -0
  53. data/db/migrate/20150413143711_create_kms_entries.rb +10 -0
  54. data/db/migrate/20150820080436_add_label_field_to_kms_models.rb +5 -0
  55. data/db/migrate/20150820132142_add_slug_to_kms_entries.rb +6 -0
  56. data/db/migrate/20150821201250_fix_models_column_name.rb +5 -0
  57. data/db/migrate/20150901115303_add_class_name_to_kms_fields.rb +5 -0
  58. data/db/migrate/20150910081440_add_position_to_kms_entries.rb +5 -0
  59. data/lib/drops/kms/entry_drop.rb +67 -0
  60. data/lib/drops/kms/models_wrapper_drop.rb +12 -0
  61. data/lib/generators/kms_models/install/install_generator.rb +17 -0
  62. data/lib/kms/models/engine.rb +15 -0
  63. data/lib/kms/models/version.rb +5 -0
  64. data/lib/kms_models.rb +6 -0
  65. data/lib/tasks/kms_models_tasks.rake +4 -0
  66. data/test/dummy/README.rdoc +28 -0
  67. data/test/dummy/Rakefile +6 -0
  68. data/test/dummy/app/assets/javascripts/application.js +13 -0
  69. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  70. data/test/dummy/app/controllers/application_controller.rb +5 -0
  71. data/test/dummy/app/helpers/application_helper.rb +2 -0
  72. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  73. data/test/dummy/bin/bundle +3 -0
  74. data/test/dummy/bin/rails +4 -0
  75. data/test/dummy/bin/rake +4 -0
  76. data/test/dummy/bin/setup +29 -0
  77. data/test/dummy/config/application.rb +26 -0
  78. data/test/dummy/config/boot.rb +5 -0
  79. data/test/dummy/config/database.yml +25 -0
  80. data/test/dummy/config/environment.rb +5 -0
  81. data/test/dummy/config/environments/development.rb +41 -0
  82. data/test/dummy/config/environments/production.rb +79 -0
  83. data/test/dummy/config/environments/test.rb +42 -0
  84. data/test/dummy/config/initializers/assets.rb +11 -0
  85. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  86. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  87. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  88. data/test/dummy/config/initializers/inflections.rb +16 -0
  89. data/test/dummy/config/initializers/mime_types.rb +4 -0
  90. data/test/dummy/config/initializers/session_store.rb +3 -0
  91. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  92. data/test/dummy/config/locales/en.yml +23 -0
  93. data/test/dummy/config/routes.rb +4 -0
  94. data/test/dummy/config/secrets.yml +22 -0
  95. data/test/dummy/config.ru +4 -0
  96. data/test/dummy/public/404.html +67 -0
  97. data/test/dummy/public/422.html +67 -0
  98. data/test/dummy/public/500.html +66 -0
  99. data/test/dummy/public/favicon.ico +0 -0
  100. data/test/integration/navigation_test.rb +10 -0
  101. data/test/kms_models_test.rb +7 -0
  102. data/test/test_helper.rb +19 -0
  103. metadata +238 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 496cd9fb9f09e6b246e7b892f0939b93e2bb06f7
4
+ data.tar.gz: f29b18459d001b37968da752bcaeb4b451c2f744
5
+ SHA512:
6
+ metadata.gz: 8cb33a3c0539f2899696077a9d22de3f82d04c1fac384a0b86914d5610b111f3a5fea001ca7f0d3ea09a12643f82712a86ed99611927b2c516a48dd13c10242b
7
+ data.tar.gz: c25c2ec429fc1e5ccec9cf34eab1f8a9c225411ab78eab53cf024d84bc217ebae32a59e14cb6312ec393c856b0cc879cf96e7a230336dcb18bd5f60231eb550a
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 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 = 'KmsModels'
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,91 @@
1
+ EntriesController = ($scope, $state, Restangular, $stateParams, Alertify, ErrorsService) ->
2
+ $scope.modelStore = Restangular.all('models')
3
+ $scope.store = Restangular.one("models", $stateParams.modelId).all("entries")
4
+ $scope.editorOptions =
5
+ filebrowserUploadUrl: '/kms/assets/ckeditor'
6
+
7
+ #Restangular.all('users').customGET('kms_user').then (current_user) ->
8
+ #$scope.currentUser = current_user
9
+ #$scope.currentUser.admin = $scope.currentUser.role == 'admin'
10
+
11
+ $scope.entriesSortableOptions =
12
+ orderChanged: (event)->
13
+ for entry, index in event.dest.sortableScope.modelValue
14
+ entry_copy =
15
+ id: entry.id
16
+ position: index
17
+ Restangular.restangularizeElement($scope.model, entry_copy, 'entries').put()
18
+
19
+ $scope.modelStore.get($stateParams.modelId).then (model)->
20
+ $scope.model = model
21
+ fields = $scope.getAssociationFields(model)
22
+ _.each fields, (field)->
23
+ $scope[field.liquor_name] = [] # pre-init
24
+ Restangular.one("models", field.class_name).all("entries").getList().then (entries)->
25
+ $scope[field.liquor_name] = entries
26
+ $scope.initAssociationField(field)
27
+
28
+ $scope.initAssociationField = (field)->
29
+ if field.type == 'Kms::HasManyField'
30
+ $scope.entry.values[field.liquor_name] = _.filter $scope[field.liquor_name], (element)->
31
+ _.contains $scope.entry.values[field.liquor_name], element.id.toString()
32
+ else
33
+ $scope.entry.values[field.liquor_name] = _.find $scope[field.liquor_name], (element)->
34
+ $scope.entry.values[field.liquor_name] == element.id.toString()
35
+
36
+ $scope.store.getList().then (entries)->
37
+ $scope.entries = entries
38
+
39
+ if $stateParams.id
40
+ $scope.store.get($stateParams.id).then (entry)->
41
+ $scope.entry = entry
42
+ else
43
+ $scope.entry = {values: {}}
44
+
45
+ $scope.getAssociationFields = (model)->
46
+ _.filter model.fields, (field) -> field.type == 'Kms::HasManyField' or field.type == 'Kms::BelongsToField'
47
+
48
+ $scope.getFieldTemplateName = (field)->
49
+ typeSplitted = field.type.split '::'
50
+ _.snakeCase(typeSplitted[typeSplitted.length - 1])
51
+
52
+ $scope.create = ->
53
+ fd = new FormData
54
+ if $scope.entry.slug
55
+ fd.append("entry[slug]", $scope.entry.slug)
56
+ for key, value of $scope.entry.values
57
+ fd.append("entry[values][#{key}]", value || '')
58
+ $scope.store.withHttpConfig({ transformRequest: angular.identity }).post(fd, null, {"Content-Type": undefined}).then ->
59
+ $state.go('models.entries', modelId: $scope.model.id)
60
+ ,(response)->
61
+ Alertify.error(ErrorsService.prepareErrorsString(response.data.errors))
62
+
63
+ $scope.update = ->
64
+ fd = new FormData
65
+ if $scope.entry.slug
66
+ fd.append("entry[slug]", $scope.entry.slug)
67
+ for key, value of $scope.entry.values
68
+ continue if value == undefined
69
+ if value
70
+ if value.constructor.name == 'Array'
71
+ for element in value
72
+ id = if element.constructor.name == 'Object' then element.id else element
73
+ fd.append("entry[values][#{key}][]", id)
74
+ else if value.constructor.name != 'Object'
75
+ fd.append("entry[values][#{key}]", value || '')
76
+ else
77
+ fd.append("entry[values][#{key}]", value || '')
78
+ $scope.entry.withHttpConfig({ transformRequest: angular.identity }).post('', fd, '', {"Content-Type": undefined}).then ->
79
+ $state.go('models.entries', modelId: $scope.model.id)
80
+ ,(response)->
81
+ Alertify.error(ErrorsService.prepareErrorsString(response.data.errors))
82
+
83
+ $scope.destroy = (entry)->
84
+ if(confirm('Вы уверены?'))
85
+ entry.remove().then ->
86
+ $scope.entries = _.without($scope.entries, entry)
87
+
88
+
89
+
90
+ angular.module('KMS')
91
+ .controller('EntriesController', ['$scope', '$state', 'Restangular', '$stateParams', 'Alertify', 'ErrorsService', EntriesController])
@@ -0,0 +1,42 @@
1
+ FieldsController = ($scope, $state, Restangular, $stateParams) ->
2
+ $scope.types = [
3
+ { id: 'Kms::StringField', name: "<%= I18n.t("field_types.string") %>"},
4
+ { id: 'Kms::TextField', name: "<%= I18n.t("field_types.text") %>"},
5
+ { id: 'Kms::CheckboxField', name: "<%= I18n.t("field_types.checkbox") %>"},
6
+ { id: 'Kms::FileField', name: "<%= I18n.t("field_types.file") %>"},
7
+ { id: 'Kms::HasManyField', name: "<%= I18n.t("field_types.has_many") %>"},
8
+ { id: 'Kms::BelongsToField', name: "<%= I18n.t("field_types.belongs_to") %>"},
9
+ ]
10
+
11
+ Restangular.all('resources').getList().then (templatable_types)->
12
+ $scope.templatable_types = templatable_types
13
+
14
+ Restangular.all('users').customGET('kms_user').then (current_user) ->
15
+ $scope.currentUser = current_user
16
+ $scope.currentUser.admin = $scope.currentUser.role == 'admin'
17
+
18
+ $scope.field = {}
19
+
20
+ $scope.formatType = (field)->
21
+ fieldType = _.find $scope.types, (type) -> type.id == field.type
22
+ if $scope.isAssociationField(field) then "#{fieldType.name} (#{$scope.getDisplayableTemplatableType(field)})" else fieldType.name
23
+
24
+ $scope.getDisplayableTemplatableType = (field)->
25
+ templatable_type = _.find $scope.templatable_types, (templatable_type) -> templatable_type.type == field.class_name
26
+ templatable_type.title
27
+
28
+ $scope.isAssociationField = (field)->
29
+ field.type == 'Kms::HasManyField' or field.type == 'Kms::BelongsToField'
30
+
31
+ $scope.addField = ->
32
+ if $scope.field.name and $scope.field.type
33
+ $scope.model.fields.push($scope.field)
34
+ $scope.field = {}
35
+
36
+ $scope.removeField = (field)->
37
+ field['_destroy'] = '1' # for rails deletion
38
+ #$scope.model.fields = _.without($scope.model.fields, field)
39
+
40
+
41
+ angular.module('KMS')
42
+ .controller('FieldsController', ['$scope', '$state', 'Restangular', '$stateParams', FieldsController])
@@ -0,0 +1,42 @@
1
+ ModelsController = ($scope, $state, Restangular, $stateParams) ->
2
+ $scope.store = Restangular.all('models')
3
+
4
+ Restangular.all('users').customGET('kms_user').then (current_user) ->
5
+ $scope.currentUser = current_user
6
+ $scope.currentUser.admin = $scope.currentUser.role == 'admin'
7
+
8
+ $scope.store.getList().then (models)->
9
+ $scope.models = models
10
+
11
+ if $stateParams.id
12
+ $scope.store.get($stateParams.id).then (model)->
13
+ $scope.model = model
14
+ else
15
+ $scope.model = {fields: []}
16
+
17
+ $scope.$watchCollection 'model.fields', (newFields, oldFields) ->
18
+ if newFields and newFields.length > 0 and oldFields and oldFields.length == 0
19
+ $scope.model.label_field =newFields[0].liquor_name
20
+
21
+ $scope.create = ->
22
+ $scope.store.post($scope.model).then ->
23
+ # for adding to Menu - better to render resources via js
24
+ window.location.reload()
25
+ #$state.go('models')
26
+ ,->
27
+ console.log('bug')
28
+
29
+ $scope.update = ->
30
+ $scope.model.put().then ->
31
+ $state.go('models')
32
+ ,->
33
+ console.log('bug')
34
+
35
+ $scope.destroy = (model)->
36
+ if confirm('Вы уверены?')
37
+ model.remove().then ->
38
+ window.location.reload()
39
+
40
+
41
+ angular.module('KMS')
42
+ .controller('ModelsController', ['$scope', '$state', 'Restangular', '$stateParams', ModelsController])
@@ -0,0 +1,67 @@
1
+ 'use strict'
2
+
3
+ angular.module('KMS').config ['$stateProvider', '$urlRouterProvider', ($stateProvider, $urlRouterProvider) ->
4
+
5
+ # Application routes
6
+ $stateProvider
7
+ .state('models', {
8
+ url: '/kms/models',
9
+ views:
10
+ "header":
11
+ template: "<%= Kms::Model.model_name.human(count: 1.1) %>"
12
+ "@":
13
+ controller: 'ModelsController',
14
+ controllerAs: 'models',
15
+ templateUrl: 'models/index.html',
16
+ })
17
+ .state('models.new', {
18
+ url: '/new',
19
+ views:
20
+ "header@":
21
+ template: "<%= I18n.t(:new_model) %>"
22
+ "@":
23
+ controller: 'ModelsController',
24
+ controllerAs: 'models',
25
+ templateUrl: 'models/new.html',
26
+ })
27
+ .state('models.edit', {
28
+ url: '/:id/edit',
29
+ views:
30
+ "header@":
31
+ template: "<%= I18n.t(:edit_model) %>"
32
+ "@":
33
+ controller: 'ModelsController',
34
+ controllerAs: 'models',
35
+ templateUrl: 'models/edit.html',
36
+ })
37
+ .state('models.entries', {
38
+ url: '/:modelId/entries',
39
+ views:
40
+ "header@":
41
+ template: "<%= Kms::Entry.model_name.human(count: 1.1) %>"
42
+ "@":
43
+ controller: 'EntriesController',
44
+ controllerAs: 'entries',
45
+ templateUrl: 'entries/index.html',
46
+ })
47
+ .state('models.entries.new', {
48
+ url: '/new',
49
+ views:
50
+ "header@":
51
+ template: "<%= I18n.t(:new_entry) %>"
52
+ "@":
53
+ controller: 'EntriesController',
54
+ controllerAs: 'entries',
55
+ templateUrl: 'entries/new.html'
56
+ })
57
+ .state('models.entries.edit', {
58
+ url: '/:id/edit',
59
+ views:
60
+ "header@":
61
+ template: "<%= I18n.t(:edit_entry) %>"
62
+ "@":
63
+ controller: 'EntriesController',
64
+ controllerAs: 'entries',
65
+ templateUrl: 'entries/edit.html'
66
+ })
67
+ ]
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require "kms_models/application/routes"
14
+ //= require_tree "../templates"
15
+ //= require_tree "./application/controllers"
@@ -0,0 +1,9 @@
1
+ .row
2
+ .col-lg-12
3
+ form role="form" ng-submit="update()" novalidate=""
4
+ ng-include src="'entries/form.html'"
5
+ .form-group
6
+ label for="slug"
7
+ = Kms::Entry.human_attribute_name(:slug)
8
+ input.form-control type="text" ng-model="entry.slug" id="entry[slug]"
9
+ button.btn.btn-default type="submit" = I18n.t(:update_entry)
@@ -0,0 +1,3 @@
1
+ .form-group ng-repeat="field in model.fields"
2
+ ng-include src="'fields/' + getFieldTemplateName(field) + '.html'"
3
+ /input.form-control type="text" ng-model="entry.values[field.liquor_name]" ng-attr-id="{{field.liquor_name}}"
@@ -0,0 +1,21 @@
1
+ .row
2
+ .col-lg-12
3
+ .widget
4
+ .widget-header
5
+ i.fa.fa-list
6
+ = Kms::Entry.model_name.human(count: 1.1)
7
+ a.btn.btn-sm.btn-primary.pull-right ui-sref="models.entries.new({modelId: model.id})"
8
+ = I18n.t("add_entry")
9
+ .widget-body.no-padding
10
+ .table-responsive
11
+ table.table
12
+ tbody as-sortable="entriesSortableOptions" ng-model="entries"
13
+ tr ng-repeat="entry in entries" as-sortable-item=""
14
+ td style="width: 80%"
15
+ i.fa.fa-bars as-sortable-item-handle="" &nbsp;
16
+ a ui-sref="models.entries.edit({modelId: model.id, id: entry.id})"
17
+ | {{ entry.values[model.label_field] || entry.id }}
18
+ td
19
+ .btn-group.pull-right
20
+ a.btn.btn-sm.btn-danger ng-click="destroy(entry)"
21
+ i.fa.fa-times
@@ -0,0 +1,5 @@
1
+ .row
2
+ .col-lg-12
3
+ form role="form" ng-submit="create()" novalidate=""
4
+ ng-include src="'entries/form.html'"
5
+ button.btn.btn-default type="submit" = I18n.t(:add_entry)
@@ -0,0 +1,7 @@
1
+ label for="{{ field.liquor_name }}"
2
+ | {{ field.name }}
3
+ ui-select ng-model="entry.values[field.liquor_name]" theme="bootstrap"
4
+ ui-select-match placeholder=I18n.t(:belongs_to_field_placeholder)
5
+ | {{ $select.selected.values[$select.selected.model.label_field] || $select.selected.id }}
6
+ ui-select-choices repeat="relatedEntry.id as relatedEntry in {{ field.liquor_name }}"
7
+ div ng-bind-html="relatedEntry.values[relatedEntry.model.label_field] | highlight: $select.search"
@@ -0,0 +1,4 @@
1
+ .checkbox
2
+ label
3
+ input type="checkbox" ng-model="entry.values[field.liquor_name]" ng-attr-id="{{field.liquor_name}}"
4
+ | {{ field.name }}
@@ -0,0 +1,8 @@
1
+ label for="{{ field.liquor_name }}"
2
+ | {{ field.name }}
3
+ div flow-init="{singleFile: true, headers: setHeaders, fileParameterName: 'entry.values[{{field.liquor_name}}]'}" flow-files-submitted="entry.values.{{field.liquor_name}} = $flow.files[0].file" flow-file-added="!!{png:1,gif:1,jpg:1,jpeg:1,doc:1,xls:1,xlsx:1,pdf:1,docx:1,mp4:1,webm:1}[$file.getExtension()]" flow-file-success="$file.msg = $message"
4
+ input type="file" flow-btn="" ng-model="entry.values[field.liquor_name]"
5
+ div class="thumbnail" ng-show="!$flow.files.length"
6
+ img ng-src="{{entry.values[field.liquor_name].url}}"
7
+ div class="thumbnail" ng-show="$flow.files.length"
8
+ img flow-img="$flow.files[0]"
@@ -0,0 +1,7 @@
1
+ label for="{{ field.liquor_name }}"
2
+ | {{ field.name }}
3
+ ui-select multiple="" ng-model="entry.values[field.liquor_name]" theme="bootstrap" on-select="addObject($item, field)" on-remove='removeObject($item, field)'
4
+ ui-select-match placeholder=I18n.t(:has_many_field_placeholder)
5
+ | {{ $item.values[$item.model.label_field] || $item.id }}
6
+ ui-select-choices repeat="childEntry.id as childEntry in {{ field.liquor_name }}"
7
+ div ng-bind-html="childEntry.values[childEntry.model.label_field] | highlight: $select.search"
@@ -0,0 +1,3 @@
1
+ label for="{{ field.liquor_name }}"
2
+ | {{ field.name }}
3
+ input.form-control type="text" ng-model="entry.values[field.liquor_name]" ng-attr-id="{{field.liquor_name}}"
@@ -0,0 +1,3 @@
1
+ label for="{{ field.liquor_name }}"
2
+ | {{ field.name }}
3
+ textarea.form-control ng-model="entry.values[field.liquor_name]" rows="15" ckeditor='editorOptions' ng-attr-id="{{field.liquor_name}}"
@@ -0,0 +1,10 @@
1
+ h4 = I18n.t("liquor_help.variables_title")
2
+ p
3
+ ul
4
+ li
5
+ var models
6
+ p
7
+ span = I18n.t('liquor_help.variables.models.main_description')
8
+ p
9
+ code
10
+ | {% for service in: models.services do: %}
@@ -0,0 +1,6 @@
1
+ .row
2
+ .col-lg-12
3
+ form role="form" ng-submit="update()" novalidate=""
4
+ ng-include src="'models/form.html'"
5
+ ng-include src="'models/fields.html'"
6
+ button.btn.btn-default type="submit" = I18n.t(:update_model)
@@ -0,0 +1,36 @@
1
+ .form-group ng-controller="FieldsController"
2
+ table.table
3
+ thead
4
+ tr
5
+ th colspan="4" = Kms::Model.human_attribute_name(:fields)
6
+ tbody
7
+ tr ng-repeat="field in model.fields" ng-hide="field._destroy"
8
+ td
9
+ | {{ field.name }}
10
+ td
11
+ | {{ field.liquor_name }}
12
+ td
13
+ | {{ formatType(field) }}
14
+ td
15
+ | {{ field.required }}
16
+ td
17
+ .btn-group.pull-right
18
+ a.btn.btn-sm.btn-danger ng-click="removeField(field)"
19
+ i.fa.fa-times
20
+ tr ng-hide="model.fields.length > 0"
21
+ td
22
+ i = I18n.t(:no_fields_yet)
23
+ .row
24
+ .col-lg-3
25
+ input.form-control type="text" required="" placeholder=Kms::Field.human_attribute_name(:name) ng-model="field.name"
26
+ .col-lg-3
27
+ input.form-control type="text" required="" placeholder=Kms::Field.human_attribute_name(:liquor_name) ng-model="field.liquor_name"
28
+ .col-lg-2
29
+ select#field_type.form-control ng-model="field.type" ng-options="type.id as type.name for type in types" required="" placeholder=Kms::Field.human_attribute_name(:type)
30
+ option value="" disabled="" selected="" = I18n.t(:select_field_type)
31
+ .col-lg-2 ng-show="isAssociationField(field)"
32
+ select#field_class_name.form-control ng-model="field.class_name" ng-options="templatable_type.type as templatable_type.title for templatable_type in templatable_types" required="" placeholder=Kms::Field.human_attribute_name(:class_name)
33
+ option value="" disabled="" selected="" = I18n.t(:select_model)
34
+ .col-lg-2
35
+ a.btn.btn-small.btn-primary ng-click="addField()"
36
+ i.fa.fa-plus
@@ -0,0 +1,10 @@
1
+ .form-group
2
+ label for="kms_model_name" = Kms::Model.human_attribute_name(:kms_model_name)
3
+ input#kms_model_name.form-control type="text" ng-model="model.kms_model_name"
4
+ .form-group
5
+ label for="collection_name" = Kms::Model.human_attribute_name(:collection_name)
6
+ input#collection_name.form-control type="text" ng-model="model.collection_name"
7
+ small.help-block = I18n.t(:collection_name_field_hint)
8
+ .form-group
9
+ label for="label_field" = Kms::Model.human_attribute_name(:label_field)
10
+ select#label_field.form-control ng-model="model.label_field" ng-options="field.liquor_name as field.name for field in model.fields"
@@ -0,0 +1,20 @@
1
+ .row
2
+ .col-lg-12
3
+ .widget
4
+ .widget-header
5
+ i.fa.fa-list
6
+ = Kms::Model.model_name.human(count: 1.1)
7
+ a.btn.btn-sm.btn-primary.pull-right ui-sref="models.new"
8
+ = I18n.t("add_model")
9
+ .widget-body.no-padding
10
+ .table-responsive
11
+ table.table
12
+ tbody
13
+ tr ng-repeat="model in models"
14
+ td style="width: 80%"
15
+ a ui-sref="models.edit({id: model.id})"
16
+ | {{ model.kms_model_name }}
17
+ td
18
+ .btn-group.pull-right
19
+ a.btn.btn-sm.btn-danger ng-click="destroy(model)" ng-show="currentUser.admin"
20
+ i.fa.fa-times
@@ -0,0 +1,6 @@
1
+ .row
2
+ .col-lg-12
3
+ form role="form" ng-submit="create()" novalidate=""
4
+ ng-include src="'models/form.html'"
5
+ ng-include src="'models/fields.html'"
6
+ button.btn.btn-default type="submit" = I18n.t(:add_model)
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,49 @@
1
+ module Kms
2
+ module Models
3
+ class EntriesController < ApplicationController
4
+ def index
5
+ model = Model.find(params[:model_id])
6
+ @entries = model.entries.order('position')
7
+ render json: @entries, root: false
8
+ end
9
+
10
+ def show
11
+ model = Model.find(params[:model_id])
12
+ @entry = model.entries.find(params[:id])
13
+ render json: @entry, root: false
14
+ end
15
+
16
+ def create
17
+ model = Model.find(params[:model_id])
18
+ @entry = model.entries.new(entry_params)
19
+ if @entry.save
20
+ render json: @entry, root: false
21
+ else
22
+ render json: @entry.to_json(methods: :errors), status: :unprocessable_entity
23
+ end
24
+ end
25
+
26
+ def update
27
+ model = Model.find(params[:model_id])
28
+ @entry = model.entries.find(params[:id])
29
+ if @entry.update_attributes(entry_params)
30
+ render json: @entry, root: false
31
+ else
32
+ render json: @entry.to_json(methods: :errors), status: :unprocessable_entity
33
+ end
34
+ end
35
+
36
+ def destroy
37
+ @entry = Entry.find(params[:id])
38
+ @entry.destroy
39
+ render json: @entry, root: false
40
+ end
41
+
42
+ protected
43
+
44
+ def entry_params
45
+ params.require(:entry).permit!
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,51 @@
1
+ module Kms
2
+ module Models
3
+ class ModelsController < ApplicationController
4
+
5
+ def index
6
+ render json: Model.all.to_json
7
+ end
8
+
9
+ def show
10
+ @model = Model.find(params[:id])
11
+ render json: @model.to_json(include: {:fields => {methods: :type}})
12
+ end
13
+
14
+ def create
15
+ params[:model].merge!(fields_attributes: params[:fields])
16
+ @model = Model.new(model_params)
17
+ if @model.save
18
+ Kms::ResourceService.register(:models, @model, "fa-tasks")
19
+ Kms::ModelsWrapperDrop.register_model @model.collection_name
20
+ render json: @model.to_json
21
+ else
22
+ render json: @model.to_json(methods: :errors), status: :unprocessable_entity
23
+ end
24
+ end
25
+
26
+ def update
27
+ params[:model].merge!(fields_attributes: params[:fields])
28
+ @model = Model.find(params[:id])
29
+ if @model.update_attributes(model_params)
30
+ render json: @model.to_json
31
+ else
32
+ render json: @model.to_json(methods: :errors), status: :unprocessable_entity
33
+ end
34
+ end
35
+
36
+ def destroy
37
+ @model = Model.find(params[:id])
38
+ @model.destroy
39
+ Kms::ResourceService.unregister(:models, @model)
40
+ render json: @model.to_json
41
+ end
42
+
43
+ protected
44
+
45
+ def model_params
46
+ params.require(:model).permit!
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,4 @@
1
+ module KmsModels
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,9 @@
1
+ module Kms
2
+ class BelongsToField < Field
3
+ def get_value(entry)
4
+ entry_id = entry.values[liquor_name]
5
+ association_record = Kms::Entry.find_by(id: entry_id)
6
+ Liquor::DropDelegation.wrap_element(association_record)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ module Kms
2
+ class CheckboxField < Field
3
+ end
4
+ end