RichEditor Snippets and Nested Relations Rendering - nested

OctoberCMS Build: 469
PHP Version: 7.3
Database Engine: MySQL
Plugins Installed: Rainlab.Builder, Rainlab.Translate, Inetis.RichEditorSnippets, Rainlab.Pages
Description:
I have followed the tutorial to make List and Form with nested Relations (https://octobercms.com/support/article/ob-21).
I open a model, and inside this model, i have a relation that have many relations like below :
-- Residence
--- Pages
---- Sections
In the "Section" popup, i display a richeditor, with snippets. But when i click on the snippet to open and edit properties, it can't focus the input.
I have search a long time in the source code of all OctoberCms, but i did not find anything.
After many tries, i have found that if in the browser inspector, i delete formPopups, the focus enables.
Here is an example of what i have actually.
Here is an example where i delete the second popup in the browser inspector
Does someone already had this issue ? Is there any fix for ?
EDIT :
Steps to reproduce
To help you to reproduce this,
you need to make 3 models with those fields :
1. Residence - fields.yaml
fields:
name:
label: Residence
span: left
required: 1
type: text
pages:
type: partial
path: pages
home_content:
label: 'Residence Content'
size: large
span: full
type: richeditor
2. Page - fields.yaml
fields:
title:
label: Titre
span: left
required: 1
type: text
sections:
span: full
path: pages_sections
type: partial
3. Section - fields.yaml
fields:
title:
label: Title
span: left
required: 1
type: text
content:
label: Content
size: ''
span: full
required: 1
type: richeditor
And you need to create relations in your models :
Residence.php
public $hasMany = [
'pages' => [
'Author\Plugin\Models\Page'
]
];
Page.php
public $hasMany = [
'sections' => [
'Author\Plugin\Models\Section'
]
];
Then you need to follow the tutorial on Making form with nested relations (https://octobercms.com/support/article/ob-21) to be able to open the relation between Page and Section inside the Residence Form.
Do not hesitate to ask me for more informations,
Best,

Related

How to use the text editor type for a translated type with EasyAdmin 2 and A2lix TranslationFormBundle

In the example below, the SetTranslation entity has a field introduction (type="text") which is displayed in forms using a simple textarea.
How to configure a text field to use the text_editor (only known by EasyAdmin) with a translated field ?
Here is the EasyAdmin 2 config for the Set entiy:
easy_admin:
entities:
Set:
form:
fields:
-
property: translations
type: 'A2lix\TranslationFormBundle\Form\Type\TranslationsType'
The solution is to specify the type with the full path using the type_options and field_type properties:
easy_admin:
entities:
Set:
form:
fields:
-
property: translations
label: ''
type: 'A2lix\TranslationFormBundle\Form\Type\TranslationsType'
type_options:
fields:
introduction:
field_type: 'EasyCorp\Bundle\EasyAdminBundle\Form\Type\TextEditorType'

Rest Api for search by products, brands and more using single search input

I'm new to Node and Mongodb.
I want to implement Search Rest api, with single param passing to api resulting to search in mongo collections checking the category, subCategory values and returning the related keyword matching object. just like flipkart search bar, with suggestion keywords, what should i follow to achieve this. i'm just having knowledge with basic CRUD operations that's all. Any suggestions or ref practices are helpful to me. Thank you
You can follow two approaches for the above implementation.
1) Basic approach. We can create a search collection which would have the following field like
Search
_id, name, description, type (brand, products, etc), type_id (brand_id, product_id), logo (It can be a brand logo, or product logo and etc).
On every product, brand, etc add we would create an entry in the search table.
Similarly, on deletion, we would remove that product or brand from the search table
We would have an end called http:///search/:string
Which would in response give result as
{
data: [
{
_id: 507f1f77bcf86cd799439011,
name: 'Clothing',
description: "Sample description about clothing",
type: 'brand',
type_id: 675f1f77bcf86cd799439124, // brand id reference,
logo: "http://<domain_name>/logo/675f1f77bcf86cd799439124"
},
{
_id: 5d3f1f77bcf86cd799439234,
name: 'Monitor',
description: "Sample description about Monitor",
type: 'product',
type_id: 5j5f1f77bcf86cd799439987, // product id reference
logo: "http://<domain_name>/logo/5j5f1f77bcf86cd799439987"
}, {
_id: 507f1f77bcf86cd799439333,
name: "Mobile",
description: "Sample description about Mobile",
type: 'brand',
type_id: 876f1f77bcf86cd799439444, // brand id reference
logo: "http://<domain_name>/logo/876f1f77bcf86cd799439444"
}
]
}
2) Sophisticated approach: Instead of using a search table you can go with the elastic search for a faster and robust approach
you can use mongodb text search feature
or you can go with elasatic search as per your requirement.

OpenAPI: Mandatory properties of an Optional Property

Pretty much what the title says. I have an optional object in the request body. However, if that object is given, it should mandatorily contain a few child properties.
My OpenAPI component config looks like this:
UserDetails:
type: object
properties:
surname:
type: string
givenName:
type: string
dob:
type: string
format: date
gender:
type: string
enum:
- male
- female
- others
partner:
type: object
properties:
name:
type: string
phone:
type: string
maxLength: 10
minLength: 10
pattern: ^[1-9]+[0-9]{9}$
required: [name, phone]
required:
- surname
- givenName
- dob
I am using express-openapi-validator to validate this. Now, I don't understand if this is the problem of the express-openapi-validator package or not, but the required fields (name, phone) of the optional field (partner) is never validated. I can just provide partner: {} and it slips in right through, or even, partner: { name: 'some name', phone: '123' }. Phone number should be validated for the length and the regex.
Am I missing anything in the definition?
There does not seem to be a solution to this, but I am closing this just for peace to my mind.
like what #Helen has replied, this seems to be an issue with the library itself.
In the process of developing my application, I discovered more problems, which make the the library express-openapi-validator and another library swagger-express-middleware I used, even lesser reliable for validating requests.
The other problem that I discovered was that a value is validated with a provided enum only if it is provided as an array:
eg. The following is validated correctly:
UserLiabilities:
type: object
properties:
liabilities:
type: object
properties:
creditCards:
type: array
items:
allOf:
- $ref: '#/components/schemas/Provider'
- type: object
properties:
limit:
type: number
minimum: 0
Here Provider is:
Provider:
type: object
properties:
provider:
type: string
enum: ['ABC', 'DEF', 'GHI', 'Others']
However, if I need provider as a plain string in an object (not in an array like above), it is not validated. And, it allows any arbitrary string:
homeLoan:
allOf:
- $ref: '#/components/schemas/Provider'
- type: object
properties:
amount:
type: number
minimum: 0
This behavior is consistent with atleast two libraries that I have tried and mentioned above. I am not sure I am doing something wrong here, but I have lost enough time trying to debug this and had to finally resolve this in my server itself.

Apostrophecms: Allow to upload PDF file only

I am having one field with relation. I want to upload only PDF files. Whereas I don't want to change the default setting for the dgad-attachments from app.js/default.js that allows all office type of files as those are needed in other places in project.
{
name: '_file',
type: 'joinByOne',
withType: 'apostrophe-file',
label: 'File',
required: true,
idField: 'fileId',
filters: {
projection: {
slug: 1,
title: 1,
attachment: 1
}
},
extensions: ['pdf'],
extensionMaps: {},
image: false
}
Can anyone help me on this please?
It sounds like you'll want to create a new file group in Apostrophe-attachments. You can use a file group to specify what types of files and/or extensions should be available when you add an apostrophe-attachments field to an object's schema. In order to add a file group that only contains PDFs, you will want to add this to the modules object in your app.js file:
'apostrophe-attachments': {
fileGroups: [
{
name: 'pdf',
label: 'Pdf',
extensions: ['pdf'],
image: false
}
]
}
This will create a new file group that will only allow files with the extension 'pdf'. Apostrophe-files isn't a regular schema type (it can't be added to an object's schema like other objects can). Instead of using apostrophe-files, it would be better to use apostrophe-attachments, which can be given a file group to restrict what types of files are allowed. In order to specify that group in your attachment, your new field will end up looking like this:
{
name: 'file',
type: 'attachment',
label: 'File',
group: 'pdf',
required: true
}
If you do decide you need to use a join directly to apostrophe-files, you will probably need to add some custom code in order to restrict the file type. If that is the case, you can find more information about apostrophe-files here:
https://apostrophecms.org/docs/modules/apostrophe-files/
You will probably be able to look at the way apostrophe-attachments handles file groups and replicate the behavior if necessary:
https://apostrophecms.org/docs/modules/apostrophe-attachments/

Array of Multiple items in Swagger

So I'm creating a user endpoint with nodejs to add a user to the database , and for the api documentation I'm using swagger editor and I'm completely new to it.
what I want to do is add a user with login , password , avatar but that user has multiple roles I want to add to the database
what I have done in the yaml document in the swagger editor is this
/users/add:
post:
description: ''
operationId: AddUser
parameters:
- description: The user login
in: formData
name: user
required: true
type: string
- description: The user password
in: formData
name: password
required: true
type: string
- description: The user name
in: formData
name: username
required: true
type: string
- description: The user avatar
in: formData
name: avatar
required: true
type: file
- in: formData
name: roles
description: roles
required: false
type: array
items:
type: string
collectionFormat: multi
and it's kind of displaying what I want in the swagger editor
but what i'm getting in the UI is just an input field
In conclusion what I want to get is an inputted array which contains the user roles and input them in the database.
Thank you
What version of Swagger UI are you using? I am on version 2.1.1 and when I put the same definition as you I get the following input box for an array field.
Try upgrading to the newest version of Swagger UI.
Also, if you update the "in" field to be "query" the resulting URL will look like this:
http://localhost:8080/accounts?roles=admin%2Cguest%2Cuser
You can then access the array values in the URL parameters rather than in "formData".

Resources