Skip to content

Commit b8b5e66

Browse files
committed
merge
2 parents c5ace85 + b7f0aa7 commit b8b5e66

File tree

10 files changed

+27
-10
lines changed

10 files changed

+27
-10
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 || model.kms_model_name }}
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/fields.html.slim

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
table.table
33
thead
44
tr
5-
th colspan="4" = Kms::Model.human_attribute_name(:fields)
5+
th colspan="4"
6+
h4 = Kms::Model.human_attribute_name(:fields)
67
tbody as-sortable="fieldsSortableOptions" ng-model="model.fields_attributes"
78
tr ng-repeat="field in model.fields_attributes" ng-hide="field._destroy" as-sortable-item=""
89
td

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

+5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
label for="collection_name" = Kms::Model.human_attribute_name(:collection_name)
88
input#collection_name.form-control type="text" ng-model="model.collection_name"
99
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)
1014
.form-group
1115
label for="label_field" = Kms::Model.human_attribute_name(:label_field)
1216
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)
1318
.form-group
1419
label for="allow_creation_using_form" style="margin-right:10px;"
1520
= Kms::Model.human_attribute_name(:allow_creation_using_form)

app/controllers/kms/models/entries_controller.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def create
1919
if @entry.save
2020
render json: @entry, root: false
2121
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
2323
end
2424
end
2525

@@ -29,7 +29,7 @@ def update
2929
if @entry.update_attributes(entry_params)
3030
render json: @entry, root: false
3131
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
3333
end
3434
end
3535

app/controllers/kms/models/models_controller.rb

+4-4
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
@@ -18,14 +18,14 @@ def create
1818
Kms::ResourceService.register(:models, @model, "fa-tasks")
1919
Kms::ModelsWrapperDrop.register_model @model.collection_name
2020
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
2222
end
2323
end
2424

2525
def update
2626
@model = Model.find(params[:id])
2727
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
2929
end
3030
end
3131

@@ -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

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ 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"
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"
1517
allow_creation_using_form_field_hint: "On website you can place a form allowing to create model entries"
1618
has_many_field_placeholder: "Select related objects..."
1719
belongs_to_field_placeholder: "Select related object..."
@@ -54,6 +56,7 @@ en:
5456
kms/model:
5557
kms_model_name: "Name"
5658
collection_name: "Collection name (for Liquor)"
59+
description: "Description"
5760
fields: "Fields"
5861
label_field: "Label field (used for URL/slug generating)"
5962
allow_creation_using_form: "Allow creation using form"

config/locales/ru.yml

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ ru:
1212
select_field_type: "Выберите тип свойства"
1313
select_model: "Выберите модель"
1414
collection_name_field_hint: "К коллекции можно будет обратиться так: models.your_collection_name (напр., models.services)"
15+
description_field_hint: "Необязательное поле. Напишите небольшое описание, чтобы было понятно назначение данной Модели"
16+
label_field_hint: "Добавьте хотя бы одно Свойство ниже. И затем вы можете выбрать свойство для генерации ссылки на элемент, а так же для отображения элементов в списке"
1517
allow_creation_using_form_field_hint: "На сайте можно будет разместить форму для создания элементов модели"
1618
has_many_field_placeholder: "Выберите связанные объекты..."
1719
belongs_to_field_placeholder: "Выберите связанный объект..."
@@ -53,6 +55,7 @@ ru:
5355
kms/model:
5456
kms_model_name: "Название"
5557
collection_name: "Название коллекции (для Liquor)"
58+
description: "Описание"
5659
fields: "Свойства"
5760
label_field: "Поле, используемое для генерации ссылок на объекты"
5861
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)