Skip to content

Commit 2ca5e7c

Browse files
committed
add description to Models - closes #6
1 parent 4ce971f commit 2ca5e7c

File tree

8 files changed

+18
-5
lines changed

8 files changed

+18
-5
lines changed

app/assets/javascripts/templates/entries/index.html.slim

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.widget
44
.widget-header
55
i.fa.fa-list
6-
= Kms::Entry.model_name.human(count: 1.1)
6+
| {{ model.description }}
77
a.btn.btn-sm.btn-primary.pull-right ui-sref="models.entries.new({modelId: model.id})"
88
= I18n.t("add_entry")
99
.widget-body.no-padding

app/assets/javascripts/templates/models/form.html.slim

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
label for="collection_name" = Kms::Model.human_attribute_name(:collection_name)
66
input#collection_name.form-control type="text" ng-model="model.collection_name"
77
small.help-block = I18n.t(:collection_name_field_hint)
8+
.form-group
9+
label for="description" = Kms::Model.human_attribute_name(:description)
10+
textarea#description.form-control ng-model="model.description"
11+
small.help-block = I18n.t(:description_field_hint)
812
.form-group
913
label for="label_field" = Kms::Model.human_attribute_name(:label_field)
1014
select#label_field.form-control ng-model="model.label_field" ng-options="field.liquor_name as field.name for field in model.fields_attributes"

app/controllers/kms/models/models_controller.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Kms
22
module Models
33
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]
55

66
def index
77
render json: Model.all, root: false
@@ -38,7 +38,7 @@ def destroy
3838
protected
3939

4040
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])
4242
end
4343

4444
end

app/serializers/kms/model_serializer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Kms
22
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
44

55
has_many :fields_attributes, serializer: Kms::FieldSerializer
66

config/locales/en.yml

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ en:
1212
select_field_type: "Select field type"
1313
select_model: "Select Model"
1414
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"
1516
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"
1617
allow_creation_using_form_field_hint: "On website you can place a form allowing to create model entries"
1718
has_many_field_placeholder: "Select related objects..."
@@ -55,6 +56,7 @@ en:
5556
kms/model:
5657
kms_model_name: "Name"
5758
collection_name: "Collection name (for Liquor)"
59+
description: "Description"
5860
fields: "Fields"
5961
label_field: "Label field (used for URL/slug generating)"
6062
allow_creation_using_form: "Allow creation using form"

config/locales/ru.yml

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ru:
1212
select_field_type: "Выберите тип свойства"
1313
select_model: "Выберите модель"
1414
collection_name_field_hint: "К коллекции можно будет обратиться так: models.your_collection_name (напр., models.services)"
15+
description_field_hint: "Необязательное поле. Напишите небольшое описание, чтобы было понятно назначение данной Модели"
1516
label_field_hint: "Добавьте хотя бы одно Свойство ниже. И затем вы можете выбрать свойство для генерации ссылки на элемент, а так же для отображения элементов в списке"
1617
allow_creation_using_form_field_hint: "На сайте можно будет разместить форму для создания элементов модели"
1718
has_many_field_placeholder: "Выберите связанные объекты..."
@@ -54,6 +55,7 @@ ru:
5455
kms/model:
5556
kms_model_name: "Название"
5657
collection_name: "Название коллекции (для Liquor)"
58+
description: "Описание"
5759
fields: "Свойства"
5860
label_field: "Поле, используемое для генерации ссылок на объекты"
5961
allow_creation_using_form: "Разрешить создание элементов с помощью форм"
Original file line numberDiff line numberDiff line change
@@ -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

spec/controllers/kms/models/models_controller_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module Models
3434
end
3535
context 'when valid' do
3636
it "returns no content" do
37-
attributes = { kms_model_name: 'Posts', collection_name: 'posts', allow_creation_using_form: true }
37+
attributes = { kms_model_name: 'Posts', collection_name: 'posts', description: 'Posts', allow_creation_using_form: true }
3838
post :create, params: { model: attributes }, format: :json
3939
expect(response).to have_http_status(204)
4040
expect(Kms::Model.last.attributes.symbolize_keys).to include attributes

0 commit comments

Comments
 (0)