Change layout data

This commit is contained in:
soupette 2019-07-12 14:15:56 +02:00
parent 8508b0c310
commit 02493109f5
11 changed files with 406 additions and 148 deletions

View File

@ -20,9 +20,6 @@
"content": {
"type": "text"
},
"json": {
"type": "string"
},
"number": {
"type": "integer"
},
@ -47,6 +44,9 @@
"tags": {
"collection": "tag",
"via": "articles"
},
"json": {
"type": "json"
}
}
}

View File

@ -0,0 +1,52 @@
{
"routes": [
{
"method": "GET",
"path": "/recipes",
"handler": "Recipe.find",
"config": {
"policies": []
}
},
{
"method": "GET",
"path": "/recipes/count",
"handler": "Recipe.count",
"config": {
"policies": []
}
},
{
"method": "GET",
"path": "/recipes/:id",
"handler": "Recipe.findOne",
"config": {
"policies": []
}
},
{
"method": "POST",
"path": "/recipes",
"handler": "Recipe.create",
"config": {
"policies": []
}
},
{
"method": "PUT",
"path": "/recipes/:id",
"handler": "Recipe.update",
"config": {
"policies": []
}
},
{
"method": "DELETE",
"path": "/recipes/:id",
"handler": "Recipe.delete",
"config": {
"policies": []
}
}
]
}

View File

@ -0,0 +1,8 @@
'use strict';
/**
* Read the documentation (https://strapi.io/documentation/3.0.0-beta.x/guides/controllers.html#core-controllers)
* to customize this controller
*/
module.exports = {};

View File

@ -0,0 +1,55 @@
'use strict';
/**
* Lifecycle callbacks for the `Recipe` model.
*/
module.exports = {
// Before saving a value.
// Fired before an `insert` or `update` query.
// beforeSave: async (model, attrs, options) => {},
// After saving a value.
// Fired after an `insert` or `update` query.
// afterSave: async (model, response, options) => {},
// Before fetching a value.
// Fired before a `fetch` operation.
// beforeFetch: async (model, columns, options) => {},
// After fetching a value.
// Fired after a `fetch` operation.
// afterFetch: async (model, response, options) => {},
// Before fetching all values.
// Fired before a `fetchAll` operation.
// beforeFetchAll: async (model, columns, options) => {},
// After fetching all values.
// Fired after a `fetchAll` operation.
// afterFetchAll: async (model, response, options) => {},
// Before creating a value.
// Fired before an `insert` query.
// beforeCreate: async (model, attrs, options) => {},
// After creating a value.
// Fired after an `insert` query.
// afterCreate: async (model, attrs, options) => {},
// Before updating a value.
// Fired before an `update` query.
// beforeUpdate: async (model, attrs, options) => {},
// After updating a value.
// Fired after an `update` query.
// afterUpdate: async (model, attrs, options) => {},
// Before destroying a value.
// Fired before a `delete` query.
// beforeDestroy: async (model, attrs, options) => {},
// After destroying a value.
// Fired after a `delete` query.
// afterDestroy: async (model, attrs, options) => {}
};

View File

@ -0,0 +1,18 @@
{
"connection": "default",
"collectionName": "recipes",
"info": {
"name": "recipe",
"description": ""
},
"options": {
"increments": true,
"timestamps": true,
"comment": ""
},
"attributes": {
"title": {
"type": "string"
}
}
}

View File

@ -0,0 +1,8 @@
'use strict';
/**
* Read the documentation (https://strapi.io/documentation/3.0.0-beta.x/guides/services.html#core-services)
* to customize this service
*/
module.exports = {};

View File

@ -16,8 +16,8 @@
},
"articles": {
"collection": "article",
"via": "tags",
"dominant": true
"dominant": true,
"via": "tags"
}
}
}

View File

@ -4,25 +4,25 @@ type Article {
updated_at: DateTime!
title: String
content: String
json: String
number: Int
date: DateTime
enum: ENUM_ARTICLE_ENUM
pic: UploadFile
bool: Boolean
json: JSON
tags(sort: String, limit: Int, start: Int, where: JSON): [Tag]
}
input ArticleInput {
title: String
content: String
json: String
number: Int
date: DateTime
enum: ENUM_ARTICLE_ENUM
pic: ID
bool: Boolean
tags: [ID]
json: JSON
}
input createArticleInput {
@ -33,6 +33,14 @@ type createArticlePayload {
article: Article
}
input createRecipeInput {
data: RecipeInput
}
type createRecipePayload {
recipe: Recipe
}
input createRoleInput {
data: RoleInput
}
@ -70,6 +78,14 @@ type deleteArticlePayload {
article: Article
}
input deleteRecipeInput {
where: InputID
}
type deleteRecipePayload {
recipe: Recipe
}
input deleteRoleInput {
where: InputID
}
@ -97,13 +113,13 @@ type deleteUserPayload {
input editArticleInput {
title: String
content: String
json: String
number: Int
date: DateTime
enum: ENUM_ARTICLE_ENUM
pic: ID
bool: Boolean
tags: [ID]
json: JSON
}
input editFileInput {
@ -119,6 +135,10 @@ input editFileInput {
related: [ID]
}
input editRecipeInput {
title: String
}
input editRoleInput {
name: String
description: String
@ -174,12 +194,15 @@ scalar JSON
"""The `Long` scalar type represents 52-bit integers"""
scalar Long
union Morph = UsersPermissionsMe | UsersPermissionsMeRole | Article | createArticlePayload | updateArticlePayload | deleteArticlePayload | Tag | createTagPayload | updateTagPayload | deleteTagPayload | UploadFile | UsersPermissionsPermission | UsersPermissionsRole | createRolePayload | updateRolePayload | deleteRolePayload | UsersPermissionsUser | createUserPayload | updateUserPayload | deleteUserPayload | MypluginTest
union Morph = UsersPermissionsMe | UsersPermissionsMeRole | Article | createArticlePayload | updateArticlePayload | deleteArticlePayload | Recipe | createRecipePayload | updateRecipePayload | deleteRecipePayload | Tag | createTagPayload | updateTagPayload | deleteTagPayload | UploadFile | UsersPermissionsPermission | UsersPermissionsRole | createRolePayload | updateRolePayload | deleteRolePayload | UsersPermissionsUser | createUserPayload | updateUserPayload | deleteUserPayload | MypluginTest
type Mutation {
createArticle(input: createArticleInput): createArticlePayload
updateArticle(input: updateArticleInput): updateArticlePayload
deleteArticle(input: deleteArticleInput): deleteArticlePayload
createRecipe(input: createRecipeInput): createRecipePayload
updateRecipe(input: updateRecipeInput): updateRecipePayload
deleteRecipe(input: deleteRecipeInput): deleteRecipePayload
createTag(input: createTagInput): createTagPayload
updateTag(input: updateTagInput): updateTagPayload
deleteTag(input: deleteTagInput): deleteTagPayload
@ -212,6 +235,8 @@ type MypluginTest {
type Query {
article(id: ID!): Article
articles(sort: String, limit: Int, start: Int, where: JSON): [Article]
recipe(id: ID!): Recipe
recipes(sort: String, limit: Int, start: Int, where: JSON): [Recipe]
tag(id: ID!): Tag
tags(sort: String, limit: Int, start: Int, where: JSON): [Tag]
files(sort: String, limit: Int, start: Int, where: JSON): [UploadFile]
@ -229,6 +254,17 @@ type Query {
userCustomRoute: String
}
type Recipe {
id: ID!
created_at: DateTime!
updated_at: DateTime!
title: String
}
input RecipeInput {
title: String
}
input RoleInput {
name: String!
description: String
@ -263,6 +299,15 @@ type updateArticlePayload {
article: Article
}
input updateRecipeInput {
where: InputID
data: editRecipeInput
}
type updateRecipePayload {
recipe: Recipe
}
input updateRoleInput {
where: InputID
data: editRoleInput

View File

@ -1,6 +1,16 @@
import styled from 'styled-components';
const LinkWrapper = styled.div`
const SubWrapper = styled.div`
background: #ffffff;
border-radius: 2px;
box-shadow: 0 2px 4px #e3e9f3;
`;
const MainWrapper = styled(SubWrapper)`
padding: 22px 10px;
`;
const LinkWrapper = styled(SubWrapper)`
background: #ffffff;
border-radius: 2px;
box-shadow: 0 2px 4px #e3e9f3;
@ -17,4 +27,4 @@ const LinkWrapper = styled.div`
}
`;
export { LinkWrapper };
export { LinkWrapper, MainWrapper, SubWrapper };

View File

@ -1,6 +1,7 @@
import React, { memo, useEffect, useState, useReducer } from 'react';
import PropTypes from 'prop-types';
import { get } from 'lodash';
import {
BackHeader,
getQueryParameters,
@ -14,7 +15,8 @@ import {
import pluginId from '../../pluginId';
import Container from '../../components/Container';
import { LinkWrapper } from './components';
import { LinkWrapper, MainWrapper, SubWrapper } from './components';
import init from './init';
import reducer, { initialState } from './reducer';
@ -108,7 +110,9 @@ function EditView({
? { id: `${pluginId}.containers.Edit.pluginHeader.title.new` }
: templateObject({ mainField: displayedFieldNameInHeader }, initialData)
.mainField;
const hasRelations = get(layout, ['layouts', 'editRelations'], []).length > 0;
const fields = get(layout, ['layouts', 'edit'], []);
console.log({ fields });
/**
* Retrieve external links from injected components
* @type {Array} List of external links to display
@ -155,6 +159,7 @@ function EditView({
return (
<>
<BackHeader onClick={() => redirectToPreviousPage()} />
<Container className="container-fluid">
<form onSubmit={handleSubmit}>
<PluginHeader
@ -197,8 +202,34 @@ function EditView({
title={pluginHeaderTitle}
/>
<div className="row">
<div className="col-9"></div>
<div className="col-3">
<div className="col-md-12 col-lg-9">
<MainWrapper>
{fields.map((fieldsRow, key) => {
//
return (
<div key={key} className="row">
{fieldsRow.map(field => {
// cons
return (
<div key={field.name} className={`col-${field.size}`}>
{field.name}
</div>
);
})}
</div>
);
})}
</MainWrapper>
</div>
<div className="col-md-12 col-lg-3">
{hasRelations && (
<SubWrapper
style={{ padding: '0 20px 1px', marginBottom: '28px' }}
>
<div style={{ paddingTop: '19px' }}>Relations</div>
</SubWrapper>
)}
<LinkWrapper>
<ul>
<LiLink

View File

@ -24,48 +24,156 @@ module.exports = {
getLayout: ctx => {
const layouts = {
tag: {
uid: 'article',
ingredient: {
uid: 'ingredient',
schema: {
// good old schema
connection: 'default',
collectionName: 'articles',
options: {},
infos: {
name: 'article',
collectionName: 'ingredients',
info: {
name: 'ingredient',
description: '',
},
options: {
increments: true,
timestamps: true,
comment: '',
},
attributes: {
name: {
type: 'string',
},
},
},
settings: {
mainField: 'id',
defaultSortBy: 'id',
defaultSortOrder: 'ASC',
searchable: true,
filterable: false,
bulkable: true,
pageSize: 10,
},
metadata: {
name: {
list: {},
edit: {
label: 'name',
description: '....',
editable: true,
visible: true,
},
},
},
layouts: {
list: [],
editRelations: [],
edit: [
[
{
name: 'name',
size: 6,
},
],
],
},
},
recipe: {
uid: 'recipe',
schema: {
connection: 'default',
collectionName: 'recipes',
info: {
name: 'recipe',
description: '',
},
options: {
increments: true,
timestamps: true,
comment: '',
},
attributes: {
title: {
type: 'string',
},
content: {
type: 'text',
ingredients: {
type: 'group',
group: 'ingredient',
required: true,
repeatable: true,
min: 1,
max: 20,
},
json: {
},
},
settings: {
mainField: 'id',
defaultSortBy: 'id',
defaultSortOrder: 'ASC',
searchable: true,
filterable: false,
bulkable: true,
pageSize: 10,
},
metadata: {
title: {
list: {
label: 'Title',
searchable: true,
sortable: true,
},
edit: {
label: 'Title',
description: '....',
editable: true,
visible: true,
},
},
ingredients: {
list: {},
edit: {
label: 'ingredients',
description: '....',
editable: true,
visible: true,
},
},
},
layouts: {
list: ['title'],
editRelations: [],
edit: [
{
name: 'title',
size: 6,
},
[
{
name: 'ingredients',
size: 12,
},
],
],
},
},
tag: {
uid: 'tag',
schema: {
// good old schema
connection: 'default',
collectionName: 'tags',
options: {},
infos: {
name: 'tag',
description: '',
},
attributes: {
name: {
type: 'string',
},
number: {
type: 'integer',
},
date: {
type: 'date',
},
enum: {
enum: ['morning,', 'noon'],
type: 'enumeration',
},
pic: {
model: 'file',
via: 'related',
plugin: 'upload',
},
bool: {
type: 'boolean',
},
tags: {
collection: 'tag',
via: 'articles',
articles: {
type: 'relation',
relationType: 'manyToMany',
},
},
},
@ -87,123 +195,37 @@ module.exports = {
sortable: true,
},
},
title: {
name: {
edit: {
label: 'title',
label: 'name',
description: '....',
editable: true,
visible: true,
},
list: {
label: 'title',
label: 'Name',
searchable: true,
sortable: true,
},
},
content: {
articles: {
edit: {
label: 'content',
description: '....',
editable: true,
visible: true,
},
list: {
label: 'content',
searchable: true,
sortable: true,
},
},
json: {
edit: {
label: 'json',
label: 'articles',
description: '....',
editable: true,
visible: true,
mainField: 'id',
},
list: {},
},
number: {
edit: {
label: 'number',
description: '....',
editable: true,
visible: true,
},
list: {
label: 'number',
searchable: true,
sortable: true,
},
},
date: {
edit: {
label: 'date',
description: '....',
editable: true,
visible: true,
},
list: {
label: 'date',
searchable: true,
sortable: true,
},
},
enum: {
edit: {
label: 'enum',
description: '....',
editable: true,
visible: true,
},
list: {
label: 'enum',
searchable: true,
sortable: true,
},
},
pic: {
edit: {
label: 'pic',
description: '....',
editable: true,
visible: true,
},
list: {},
},
tags: {
edit: {
label: 'tags',
description: '....',
editable: true,
visible: true,
},
list: {},
},
bool: {
edit: {
label: 'bool',
description: '....',
editable: true,
visible: true,
},
list: {
label: 'bool',
searchable: true,
sortable: true,
},
},
},
layouts: {
list: ['id', 'title', 'content'],
editRelations: [],
list: ['id', 'name'],
editRelations: ['articles'],
edit: [
[
{
name: 'title',
size: 6,
},
{
name: 'content',
name: 'name',
size: 6,
},
],
@ -250,8 +272,8 @@ module.exports = {
type: 'boolean',
},
tags: {
collection: 'tag',
via: 'articles',
type: 'relation',
relationType: 'manyToMany',
},
},
},
@ -362,6 +384,7 @@ module.exports = {
description: '....',
editable: true,
visible: true,
mainField: 'name',
},
list: {},
},
@ -381,7 +404,7 @@ module.exports = {
},
layouts: {
list: ['id', 'title', 'content'],
editRelations: [],
editRelations: ['tags'],
edit: [
[
{
@ -393,6 +416,10 @@ module.exports = {
size: 6,
},
],
[{ name: 'json', size: 12 }],
[{ name: 'number', size: 6 }, { name: 'date', size: 4 }],
[{ name: 'enum', size: 6 }, { name: 'pic', size: 6 }],
[{ name: 'bool', size: 4 }],
],
},
},
@ -446,10 +473,8 @@ module.exports = {
configurable: false,
},
role: {
model: 'role',
via: 'users',
plugin: 'users-permissions',
configurable: false,
type: 'relation',
relationType: 'manyToOne',
},
},
},
@ -541,6 +566,7 @@ module.exports = {
description: '....',
editable: true,
visible: true,
mainField: 'name',
},
list: {},
},
@ -591,6 +617,11 @@ module.exports = {
label: 'Article',
destination: 'article',
},
{
name: 'recipe',
label: 'Recipe',
destination: 'recipe',
},
{
name: 'tag',
label: 'Tag',