kms_models 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 424033f3b06425377a0f0219d397dd0a60d0389f
4
- data.tar.gz: fc7d53423262bfcb12f0934a19904b356e3b7600
3
+ metadata.gz: c7d0df8ff5a3477c6d524949f0e152cb74fbc066
4
+ data.tar.gz: bbc91ff5304078d8551b9fb2b687e13ec16b42ce
5
5
  SHA512:
6
- metadata.gz: f4a851a816ccd513a2d16336d02525c218a22d3535689b31b6c43f8c038d159039b78fd8b325a507879c221cee9912fde05b191f2355702f77ae44fa6a68ab36
7
- data.tar.gz: e88abe7c4d3198264d7d5f197c57d805333775700da3134a6ec668ec87ef2e825e148a95f8ade82f6a530e9225f7a1324acd3f265ac6ecdfaca51c586b7d1b4b
6
+ metadata.gz: ee61d66f62c0b91ed9a69660d429b11149a7f64faa55bf8e90661fd799585d35988df9ae4332fc61fa58528ae8e322456bf1c0998914740c376435df3d6aec13
7
+ data.tar.gz: 4ebc68f98c34e1a86da3fe86caac321c128a8236958189a5ec56afc2552bb8597c8a1322cfb167c4d32fba22ad67345eb85c72ddae8cc0b06a93b11164d89151
@@ -3,6 +3,7 @@ EntriesController = ($scope, $state, Restangular, $stateParams, Alertify, Errors
3
3
  $scope.store = Restangular.one("models", $stateParams.modelId).all("entries")
4
4
  $scope.editorOptions =
5
5
  filebrowserUploadUrl: '/kms/assets/ckeditor'
6
+ language: '<%= I18n.locale.to_s %>'
6
7
 
7
8
  #Restangular.all('users').customGET('kms_user').then (current_user) ->
8
9
  #$scope.currentUser = current_user
@@ -1,11 +1,12 @@
1
1
  FieldsController = ($scope, $state, Restangular, $stateParams, TransliterationService) ->
2
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") %>"},
3
+ { id: 'Kms::StringField', name: "<%= I18n.t("field_types.string") %>", icon: 'fa-font'},
4
+ { id: 'Kms::TextField', name: "<%= I18n.t("field_types.text") %>", icon: 'fa-file-text-o'},
5
+ { id: 'Kms::CheckboxField', name: "<%= I18n.t("field_types.checkbox") %>", icon: 'fa-check-square-o'},
6
+ { id: 'Kms::DateField', name: "<%= I18n.t("field_types.date") %>", icon: 'fa-calendar'},
7
+ { id: 'Kms::FileField', name: "<%= I18n.t("field_types.file") %>", icon: 'fa-image'},
8
+ { id: 'Kms::HasManyField', name: "<%= I18n.t("field_types.has_many") %>", icon: 'fa-sitemap'},
9
+ { id: 'Kms::BelongsToField', name: "<%= I18n.t("field_types.belongs_to") %>", icon: 'fa-leaf'},
9
10
  ]
10
11
 
11
12
  $scope.fieldsSortableOptions =
@@ -29,8 +30,11 @@ FieldsController = ($scope, $state, Restangular, $stateParams, TransliterationSe
29
30
  if newValue? and !$scope.field.id
30
31
  $scope.field.liquor_name = _.snakeCase TransliterationService.translit(newValue, 5).replace(/`/g, '')
31
32
 
32
- $scope.formatType = (field)->
33
- fieldType = _.find $scope.types, (type) -> type.id == field.type
33
+ $scope.findTypeByField = (field) ->
34
+ _.find $scope.types, (type) -> type.id == field.type
35
+
36
+ $scope.formatType = (field) ->
37
+ fieldType = $scope.findTypeByField(field)
34
38
  if $scope.isAssociationField(field) then "#{fieldType.name} (#{$scope.getDisplayableTemplatableType(field)})" else fieldType.name
35
39
 
36
40
  $scope.getDisplayableTemplatableType = (field)->
@@ -40,8 +44,11 @@ FieldsController = ($scope, $state, Restangular, $stateParams, TransliterationSe
40
44
  $scope.isAssociationField = (field)->
41
45
  field.type == 'Kms::HasManyField' or field.type == 'Kms::BelongsToField'
42
46
 
47
+ $scope.isValidField = ->
48
+ $scope.field.name and $scope.field.liquor_name and $scope.field.type
49
+
43
50
  $scope.addField = ->
44
- if $scope.field.name and $scope.field.type
51
+ if $scope.isValidField()
45
52
  $scope.model.fields_attributes.push($scope.field)
46
53
  $scope.field = {}
47
54
 
@@ -3,7 +3,7 @@
3
3
  .widget
4
4
  .widget-header
5
5
  i.fa.fa-list
6
- = Kms::Entry.model_name.human(count: 1.1)
6
+ | {{ model.description || model.kms_model_name }}
7
7
  a.btn.btn-sm.btn-primary.pull-right ui-sref="models.entries.new({modelId: model.id})"
8
8
  = I18n.t("add_entry")
9
9
  .widget-body.no-padding
@@ -0,0 +1,3 @@
1
+ label for="{{ field.liquor_name }}"
2
+ | {{ field.name }}
3
+ input.form-control datepicker-popup="" is-open="field.datepickerOpened" show-button-bar="false" ng-click="field.datepickerOpened = true" type="text" ng-model="entry.values[field.liquor_name]" ng-attr-id="{{field.liquor_name}}"
@@ -2,7 +2,8 @@
2
2
  table.table
3
3
  thead
4
4
  tr
5
- th colspan="4" = Kms::Model.human_attribute_name(:fields)
5
+ th colspan="4"
6
+ h4 = Kms::Model.human_attribute_name(:fields)
6
7
  tbody as-sortable="fieldsSortableOptions" ng-model="model.fields_attributes"
7
8
  tr ng-repeat="field in model.fields_attributes" ng-hide="field._destroy" as-sortable-item=""
8
9
  td
@@ -11,7 +12,8 @@
11
12
  td
12
13
  | {{ field.liquor_name }}
13
14
  td
14
- | {{ formatType(field) }}
15
+ i.fa ng-class="findTypeByField(field).icon"
16
+ | {{ formatType(field) }}
15
17
  td
16
18
  | {{ field.required }}
17
19
  td
@@ -27,8 +29,13 @@
27
29
  .col-lg-3
28
30
  input.form-control type="text" required="" placeholder=Kms::Field.human_attribute_name(:liquor_name) ng-model="field.liquor_name"
29
31
  .col-lg-2
30
- 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)
31
- option value="" disabled="" selected="" = I18n.t(:select_field_type)
32
+ ui-select ng-model="field.type" theme="bootstrap"
33
+ ui-select-match placeholder=I18n.t(:select_field_type)
34
+ i.fa ng-class="$select.selected.icon"
35
+ | {{ $select.selected.name }}
36
+ ui-select-choices repeat="type.id as type in types"
37
+ i.fa ng-class="type.icon"
38
+ | {{ type.name | highlight: $select.search }}
32
39
  .col-lg-2 ng-show="isAssociationField(field)"
33
40
  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)
34
41
  option value="" disabled="" selected="" = I18n.t(:select_model)
@@ -1,15 +1,41 @@
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_attributes"
11
- .form-group
12
- label for="allow_creation_using_form" style="margin-right:10px;"
13
- = Kms::Model.human_attribute_name(:allow_creation_using_form)
14
- toggle-switch ng-model="model.allow_creation_using_form" on-label=I18n.t(:yes_word) off-label=I18n.t(:no_word)
15
- small.help-block = I18n.t(:allow_creation_using_form_field_hint)
1
+ .row
2
+ .col-md-6.col-sm-12
3
+ .form-group
4
+ label for="kms_model_name" = Kms::Model.human_attribute_name(:kms_model_name)
5
+ input#kms_model_name.form-control type="text" ng-model="model.kms_model_name"
6
+ .form-group
7
+ label for="collection_name" = Kms::Model.human_attribute_name(:collection_name)
8
+ input#collection_name.form-control type="text" ng-model="model.collection_name"
9
+ small.help-block = I18n.t(:collection_name_field_hint)
10
+ .form-group
11
+ label for="description" = Kms::Model.human_attribute_name(:description)
12
+ textarea#description.form-control ng-model="model.description"
13
+ small.help-block = I18n.t(:description_field_hint)
14
+ .form-group
15
+ label for="label_field" = Kms::Model.human_attribute_name(:label_field)
16
+ select#label_field.form-control ng-model="model.label_field" ng-options="field.liquor_name as field.name for field in model.fields_attributes"
17
+ small.help-block = I18n.t(:label_field_hint)
18
+ .form-group
19
+ label for="allow_creation_using_form" style="margin-right:10px;"
20
+ = Kms::Model.human_attribute_name(:allow_creation_using_form)
21
+ toggle-switch ng-model="model.allow_creation_using_form" on-label=I18n.t(:yes_word) off-label=I18n.t(:no_word)
22
+ small.help-block = I18n.t(:allow_creation_using_form_field_hint)
23
+ .col-md-6.col-sm-12
24
+ .widget.model-iteration-code-snippet
25
+ .widget-body
26
+ .widget-content
27
+ .widget-icon.pull-left
28
+ i class="fa fa-clipboard"
29
+ .title Model iteration hint
30
+ .comment Use sample code below for iterating your model entries in Template, Page or Snippet:
31
+ br
32
+ pre
33
+ | {% for element in: models.{{ model.collection_name }} do: %}
34
+ br
35
+ code ng-non-bindable=""
36
+ | &lt;p&gt;{{
37
+ | element.{{ model.label_field }}
38
+ code ng-non-bindable=""
39
+ | }}&lt;/p&gt;
40
+ br
41
+ | {% end for %}
@@ -16,3 +16,9 @@
16
16
  .as-sortable-dragging td {
17
17
  padding: 0 10px;
18
18
  }
19
+ .widget.model-iteration-code-snippet {
20
+ margin-top: 23px;
21
+ }
22
+ .widget.model-iteration-code-snippet .widget-icon {
23
+ background: #ff5274;
24
+ }
@@ -19,7 +19,7 @@ module Kms
19
19
  if @entry.save
20
20
  render json: @entry, root: false
21
21
  else
22
- render json: @entry.to_json(methods: :errors), status: :unprocessable_entity
22
+ render json: { errors: @entry.errors.full_messages }.to_json, status: :unprocessable_entity
23
23
  end
24
24
  end
25
25
 
@@ -29,7 +29,7 @@ module Kms
29
29
  if @entry.update_attributes(entry_params)
30
30
  render json: @entry, root: false
31
31
  else
32
- render json: @entry.to_json(methods: :errors), status: :unprocessable_entity
32
+ render json: { errors: @entry.errors.full_messages }.to_json, status: :unprocessable_entity
33
33
  end
34
34
  end
35
35
 
@@ -1,7 +1,7 @@
1
1
  module Kms
2
2
  module Models
3
3
  class ModelsController < ApplicationController
4
- wrap_parameters :model, include: [:kms_model_name, :collection_name, :label_field, :fields_attributes, :allow_creation_using_form]
4
+ wrap_parameters :model, include: [:kms_model_name, :collection_name, :description, :label_field, :fields_attributes, :allow_creation_using_form]
5
5
 
6
6
  def index
7
7
  render json: Model.all, root: false
@@ -18,14 +18,14 @@ module Kms
18
18
  Kms::ResourceService.register(:models, @model, "fa-tasks")
19
19
  Kms::ModelsWrapperDrop.register_model @model.collection_name
20
20
  else
21
- render json: {errors: @model.errors}.to_json, status: :unprocessable_entity
21
+ render json: { errors: @model.errors.full_messages }.to_json, status: :unprocessable_entity
22
22
  end
23
23
  end
24
24
 
25
25
  def update
26
26
  @model = Model.find(params[:id])
27
27
  unless @model.update_attributes(model_params)
28
- render json: {errors: @model.errors}.to_json, status: :unprocessable_entity
28
+ render json: { errors: @model.errors.full_messages }.to_json, status: :unprocessable_entity
29
29
  end
30
30
  end
31
31
 
@@ -38,7 +38,7 @@ module Kms
38
38
  protected
39
39
 
40
40
  def model_params
41
- params.require(:model).permit(:kms_model_name, :collection_name, :label_field, :allow_creation_using_form, fields_attributes: [:id, :name, :liquor_name, :type, :class_name, :_destroy])
41
+ params.require(:model).permit(:kms_model_name, :collection_name, :description, :label_field, :allow_creation_using_form, fields_attributes: [:id, :name, :liquor_name, :type, :class_name, :_destroy])
42
42
  end
43
43
 
44
44
  end
@@ -1,4 +1,7 @@
1
1
  module Kms
2
2
  class CheckboxField < Field
3
+ def get_value(entry)
4
+ entry.values[liquor_name] == 'true'
5
+ end
3
6
  end
4
7
  end
@@ -0,0 +1,4 @@
1
+ module Kms
2
+ class DateField < Field
3
+ end
4
+ end
@@ -3,6 +3,7 @@ module Kms
3
3
  belongs_to :model
4
4
  scope :file_fields, -> { where(type: Kms::FileField.name) }
5
5
  scope :checkbox_fields, -> { where(type: Kms::CheckboxField.name) }
6
+ scope :date_fields, -> { where(type: Kms::DateField.name) }
6
7
 
7
8
  def get_value(entry)
8
9
  # OVERRIDE in subclasses if needed
@@ -17,6 +17,10 @@ module Kms
17
17
  object.model.fields.checkbox_fields.each do |checkbox_field|
18
18
  values_with_urls[checkbox_field.liquor_name] = values_with_urls[checkbox_field.liquor_name] == 'true'
19
19
  end
20
+ # prepare checkbox fields - cause PostgreSQL json stored as strings
21
+ object.model.fields.date_fields.each do |date_field|
22
+ values_with_urls[date_field.liquor_name] = Date.parse(values_with_urls[date_field.liquor_name])
23
+ end
20
24
  values_with_urls
21
25
  end
22
26
  end
@@ -1,6 +1,6 @@
1
1
  module Kms
2
2
  class ModelSerializer < ActiveModel::Serializer
3
- attributes :id, :kms_model_name, :collection_name, :label_field, :allow_creation_using_form, :fields_attributes
3
+ attributes :id, :kms_model_name, :collection_name, :description, :label_field, :allow_creation_using_form, :fields_attributes
4
4
 
5
5
  has_many :fields_attributes, serializer: Kms::FieldSerializer
6
6
 
@@ -12,6 +12,8 @@ en:
12
12
  select_field_type: "Select field type"
13
13
  select_model: "Select Model"
14
14
  collection_name_field_hint: "You can access model collection like this: models.your_collection_name (ex., models.services)"
15
+ description_field_hint: "Optional field. Just write some description so everyone would be aware what's the purpose of this Model"
16
+ label_field_hint: "Add at least one Field below. And then you could choose one that would be used for item permalink generation and entries list displaying"
15
17
  allow_creation_using_form_field_hint: "On website you can place a form allowing to create model entries"
16
18
  has_many_field_placeholder: "Select related objects..."
17
19
  belongs_to_field_placeholder: "Select related object..."
@@ -23,6 +25,7 @@ en:
23
25
  string: "String"
24
26
  text: "Text"
25
27
  checkbox: "Checkbox"
28
+ date: "Date"
26
29
  file: "File"
27
30
  has_many: "Has many"
28
31
  belongs_to: "Belongs to"
@@ -53,6 +56,7 @@ en:
53
56
  kms/model:
54
57
  kms_model_name: "Name"
55
58
  collection_name: "Collection name (for Liquor)"
59
+ description: "Description"
56
60
  fields: "Fields"
57
61
  label_field: "Label field (used for URL/slug generating)"
58
62
  allow_creation_using_form: "Allow creation using form"
@@ -12,6 +12,8 @@ ru:
12
12
  select_field_type: "Выберите тип свойства"
13
13
  select_model: "Выберите модель"
14
14
  collection_name_field_hint: "К коллекции можно будет обратиться так: models.your_collection_name (напр., models.services)"
15
+ description_field_hint: "Необязательное поле. Напишите небольшое описание, чтобы было понятно назначение данной Модели"
16
+ label_field_hint: "Добавьте хотя бы одно Свойство ниже. И затем вы можете выбрать свойство для генерации ссылки на элемент, а так же для отображения элементов в списке"
15
17
  allow_creation_using_form_field_hint: "На сайте можно будет разместить форму для создания элементов модели"
16
18
  has_many_field_placeholder: "Выберите связанные объекты..."
17
19
  belongs_to_field_placeholder: "Выберите связанный объект..."
@@ -23,6 +25,7 @@ ru:
23
25
  string: "Строка"
24
26
  text: "Текст"
25
27
  checkbox: "Чекбокс"
28
+ date: "Дата"
26
29
  file: "Файл"
27
30
  has_many: "Имеет много"
28
31
  belongs_to: "Связано с"
@@ -52,6 +55,7 @@ ru:
52
55
  kms/model:
53
56
  kms_model_name: "Название"
54
57
  collection_name: "Название коллекции (для Liquor)"
58
+ description: "Описание"
55
59
  fields: "Свойства"
56
60
  label_field: "Поле, используемое для генерации ссылок на объекты"
57
61
  allow_creation_using_form: "Разрешить создание элементов с помощью форм"
@@ -0,0 +1,5 @@
1
+ class AddDescriptionToKmsModels < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :kms_models, :description, :text
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module Kms
2
2
  module Models
3
- VERSION = '1.0.1'
3
+ VERSION = '1.1.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kms_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Petrov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-09 00:00:00.000000000 Z
11
+ date: 2018-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: friendly_id
@@ -120,6 +120,7 @@ files:
120
120
  - app/assets/javascripts/templates/entries/new.html.slim
121
121
  - app/assets/javascripts/templates/fields/belongs_to_field.html.slim
122
122
  - app/assets/javascripts/templates/fields/checkbox_field.html.slim
123
+ - app/assets/javascripts/templates/fields/date_field.html.slim
123
124
  - app/assets/javascripts/templates/fields/file_field.html.slim
124
125
  - app/assets/javascripts/templates/fields/has_many_field.html.slim
125
126
  - app/assets/javascripts/templates/fields/string_field.html.slim
@@ -139,6 +140,7 @@ files:
139
140
  - app/helpers/kms_models/application_helper.rb
140
141
  - app/models/kms/belongs_to_field.rb
141
142
  - app/models/kms/checkbox_field.rb
143
+ - app/models/kms/date_field.rb
142
144
  - app/models/kms/entry.rb
143
145
  - app/models/kms/field.rb
144
146
  - app/models/kms/file_field.rb
@@ -172,6 +174,7 @@ files:
172
174
  - db/migrate/20170209125819_add_allow_creation_using_form_to_models.rb
173
175
  - db/migrate/20170802063046_change_values_column_to_jsonb.rb
174
176
  - db/migrate/20170802085121_add_position_to_kms_fields.rb
177
+ - db/migrate/20180122135245_add_description_to_kms_models.rb
175
178
  - lib/drops/kms/entry_drop.rb
176
179
  - lib/drops/kms/models_wrapper_drop.rb
177
180
  - lib/generators/kms_models/install/install_generator.rb
@@ -199,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
202
  version: '0'
200
203
  requirements: []
201
204
  rubyforge_project:
202
- rubygems_version: 2.6.11
205
+ rubygems_version: 2.4.5
203
206
  signing_key:
204
207
  specification_version: 4
205
208
  summary: Extension for KMS