@akemona-org/strapi-plugin-content-type-builder 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +19 -0
- package/admin/src/InjectedComponents/ContentManager/EditSettingViewButton.js +76 -0
- package/admin/src/InjectedComponents/ContentManager/EditViewLink.js +44 -0
- package/admin/src/assets/images/logo.svg +1 -0
- package/admin/src/components/AllowedTypesSelect/MenuList.js +115 -0
- package/admin/src/components/AllowedTypesSelect/Text.js +26 -0
- package/admin/src/components/AllowedTypesSelect/index.js +55 -0
- package/admin/src/components/AttributeOption/Button.js +50 -0
- package/admin/src/components/AttributeOption/Card.js +26 -0
- package/admin/src/components/AttributeOption/index.js +127 -0
- package/admin/src/components/BooleanBox/CT.js +21 -0
- package/admin/src/components/BooleanBox/Enumeration.js +10 -0
- package/admin/src/components/BooleanBox/EnumerationWrapper.js +14 -0
- package/admin/src/components/BooleanBox/Label.js +9 -0
- package/admin/src/components/BooleanBox/ST.js +21 -0
- package/admin/src/components/BooleanBox/Wrapper.js +75 -0
- package/admin/src/components/BooleanBox/icons/CTSelected.js +136 -0
- package/admin/src/components/BooleanBox/icons/CTUnselected.js +136 -0
- package/admin/src/components/BooleanBox/icons/STSelected.js +80 -0
- package/admin/src/components/BooleanBox/icons/STUnselected.js +76 -0
- package/admin/src/components/BooleanBox/index.js +103 -0
- package/admin/src/components/CheckboxWithDescription/Wrapper.js +12 -0
- package/admin/src/components/CheckboxWithDescription/index.js +40 -0
- package/admin/src/components/ComponentCard/Close.js +12 -0
- package/admin/src/components/ComponentCard/Wrapper.js +84 -0
- package/admin/src/components/ComponentCard/index.js +62 -0
- package/admin/src/components/ComponentIconPicker/Cell.js +40 -0
- package/admin/src/components/ComponentIconPicker/CellRenderer.js +36 -0
- package/admin/src/components/ComponentIconPicker/Search.js +12 -0
- package/admin/src/components/ComponentIconPicker/SearchWrapper.js +34 -0
- package/admin/src/components/ComponentIconPicker/Wrapper.js +60 -0
- package/admin/src/components/ComponentIconPicker/index.js +143 -0
- package/admin/src/components/ComponentList/index.js +78 -0
- package/admin/src/components/ComponentSelect/Category.js +20 -0
- package/admin/src/components/ComponentSelect/CategoryName.js +11 -0
- package/admin/src/components/ComponentSelect/MenuList.js +110 -0
- package/admin/src/components/ComponentSelect/MultipleMenuList.js +271 -0
- package/admin/src/components/ComponentSelect/Value.js +83 -0
- package/admin/src/components/ComponentSelect/index.js +83 -0
- package/admin/src/components/ComponentSelect/utils/HasSomeSubArray.js +5 -0
- package/admin/src/components/ComponentSelect/utils/hasSubArray.js +5 -0
- package/admin/src/components/CreatableSelect/index.js +58 -0
- package/admin/src/components/CustomCheckbox/StyledCustomCheckbox.js +25 -0
- package/admin/src/components/CustomCheckbox/index.js +71 -0
- package/admin/src/components/CustomLink/P.js +17 -0
- package/admin/src/components/CustomLink/StyledCustomLink.js +20 -0
- package/admin/src/components/CustomLink/index.js +31 -0
- package/admin/src/components/DynamicZoneList/ComponentButton.js +39 -0
- package/admin/src/components/DynamicZoneList/index.js +124 -0
- package/admin/src/components/HeaderModalNavContainer/index.js +25 -0
- package/admin/src/components/HeaderNavLink/Wrapper.js +21 -0
- package/admin/src/components/HeaderNavLink/index.js +50 -0
- package/admin/src/components/List/List.js +131 -0
- package/admin/src/components/List/index.js +295 -0
- package/admin/src/components/ListButton/index.js +9 -0
- package/admin/src/components/ListHeader/Title.js +19 -0
- package/admin/src/components/ListHeader/Wrapper.js +24 -0
- package/admin/src/components/ListHeader/index.js +37 -0
- package/admin/src/components/ListRow/Wrapper.js +76 -0
- package/admin/src/components/ListRow/index.js +334 -0
- package/admin/src/components/ModalHeader/ComponentIcon.js +21 -0
- package/admin/src/components/ModalHeader/ComponentInfos.js +22 -0
- package/admin/src/components/ModalHeader/ComponentInfosWrapper.js +9 -0
- package/admin/src/components/ModalHeader/DropdownInfos.js +50 -0
- package/admin/src/components/ModalHeader/Icon.js +26 -0
- package/admin/src/components/ModalHeader/IconWrapper.js +11 -0
- package/admin/src/components/ModalHeader/Item.js +19 -0
- package/admin/src/components/ModalHeader/Menu.js +8 -0
- package/admin/src/components/ModalHeader/Toggle.js +14 -0
- package/admin/src/components/ModalHeader/Wrapper.js +12 -0
- package/admin/src/components/ModalHeader/index.js +105 -0
- package/admin/src/components/RelationForm/Wrapper.js +9 -0
- package/admin/src/components/RelationForm/index.js +66 -0
- package/admin/src/components/RelationFormBox/Wrapper.js +34 -0
- package/admin/src/components/RelationFormBox/index.js +85 -0
- package/admin/src/components/RelationFormNaturePicker/Wrapper.js +53 -0
- package/admin/src/components/RelationFormNaturePicker/index.js +112 -0
- package/admin/src/components/RelationTargetPicker/Item.js +62 -0
- package/admin/src/components/RelationTargetPicker/Wrapper.js +89 -0
- package/admin/src/components/RelationTargetPicker/index.js +88 -0
- package/admin/src/components/SelectCheckbox/index.js +8 -0
- package/admin/src/components/SelectMenuSubUl/ToggleUl.js +23 -0
- package/admin/src/components/SelectMenuSubUl/index.js +23 -0
- package/admin/src/components/SelectMenuUl/index.js +66 -0
- package/admin/src/components/Td/index.js +37 -0
- package/admin/src/components/UpperFirst/index.js +14 -0
- package/admin/src/components/WrapperSelect/index.js +89 -0
- package/admin/src/containers/App/Wrapper.js +14 -0
- package/admin/src/containers/App/index.js +39 -0
- package/admin/src/containers/App/utils/icons.json +962 -0
- package/admin/src/containers/DataManagerProvider/constants.js +15 -0
- package/admin/src/containers/DataManagerProvider/index.js +610 -0
- package/admin/src/containers/DataManagerProvider/reducer.js +461 -0
- package/admin/src/containers/DataManagerProvider/selectors.js +25 -0
- package/admin/src/containers/DataManagerProvider/utils/cleanData.js +167 -0
- package/admin/src/containers/DataManagerProvider/utils/createDataObject.js +8 -0
- package/admin/src/containers/DataManagerProvider/utils/createModifiedDataSchema.js +91 -0
- package/admin/src/containers/DataManagerProvider/utils/retrieveComponentsFromSchema.js +55 -0
- package/admin/src/containers/DataManagerProvider/utils/retrieveComponentsThatHaveComponents.js +35 -0
- package/admin/src/containers/DataManagerProvider/utils/retrieveNestedComponents.js +34 -0
- package/admin/src/containers/DataManagerProvider/utils/retrieveSpecificInfoFromComponents.js +12 -0
- package/admin/src/containers/FormModal/CustomButton.js +12 -0
- package/admin/src/containers/FormModal/attributes/advancedForm.js +269 -0
- package/admin/src/containers/FormModal/attributes/attributeOptions.js +99 -0
- package/admin/src/containers/FormModal/attributes/baseForm.js +322 -0
- package/admin/src/containers/FormModal/attributes/commonBaseForm.js +7 -0
- package/admin/src/containers/FormModal/attributes/form.js +9 -0
- package/admin/src/containers/FormModal/attributes/index.js +4 -0
- package/admin/src/containers/FormModal/attributes/nameField.js +19 -0
- package/admin/src/containers/FormModal/attributes/types.js +309 -0
- package/admin/src/containers/FormModal/attributes/uiHelpers.js +11 -0
- package/admin/src/containers/FormModal/attributes/validation/common.js +151 -0
- package/admin/src/containers/FormModal/category/createCategorySchema.js +28 -0
- package/admin/src/containers/FormModal/category/form.js +27 -0
- package/admin/src/containers/FormModal/category/index.js +3 -0
- package/admin/src/containers/FormModal/category/regex.js +3 -0
- package/admin/src/containers/FormModal/component/componentField.js +25 -0
- package/admin/src/containers/FormModal/component/createComponentSchema.js +49 -0
- package/admin/src/containers/FormModal/component/form.js +67 -0
- package/admin/src/containers/FormModal/component/index.js +4 -0
- package/admin/src/containers/FormModal/constants.js +11 -0
- package/admin/src/containers/FormModal/contentType/createContentTypeSchema.js +44 -0
- package/admin/src/containers/FormModal/contentType/form.js +116 -0
- package/admin/src/containers/FormModal/contentType/index.js +2 -0
- package/admin/src/containers/FormModal/dynamicZone/form.js +45 -0
- package/admin/src/containers/FormModal/dynamicZone/index.js +2 -0
- package/admin/src/containers/FormModal/forms/index.js +164 -0
- package/admin/src/containers/FormModal/index.js +1552 -0
- package/admin/src/containers/FormModal/reducer.js +293 -0
- package/admin/src/containers/FormModal/selectors.js +24 -0
- package/admin/src/containers/FormModal/utils/canEditContentType.js +19 -0
- package/admin/src/containers/FormModal/utils/createHeadersArray.js +37 -0
- package/admin/src/containers/FormModal/utils/createHeadersObjectFromArray.js +27 -0
- package/admin/src/containers/FormModal/utils/createUid.js +17 -0
- package/admin/src/containers/FormModal/utils/getAttributesToDisplay.js +35 -0
- package/admin/src/containers/FormModal/utils/getModalTitleSubHeader.js +25 -0
- package/admin/src/containers/FormModal/utils/getNextSearch.js +17 -0
- package/admin/src/containers/FormModal/utils/index.js +6 -0
- package/admin/src/containers/FormModal/utils/relations.js +9 -0
- package/admin/src/containers/FormModal/utils/staticData.js +43 -0
- package/admin/src/containers/Initializer/index.js +26 -0
- package/admin/src/containers/LeftMenu/Wrapper.js +14 -0
- package/admin/src/containers/LeftMenu/index.js +220 -0
- package/admin/src/containers/ListView/Wrapper.js +16 -0
- package/admin/src/containers/ListView/index.js +322 -0
- package/admin/src/containers/NotFoundPage/index.js +20 -0
- package/admin/src/containers/RecursivePath/index.js +22 -0
- package/admin/src/contexts/DataManagerContext.js +5 -0
- package/admin/src/contexts/ListViewContext.js +5 -0
- package/admin/src/hooks/useDataManager.js +6 -0
- package/admin/src/hooks/useListView.js +6 -0
- package/admin/src/icons/Curve.js +26 -0
- package/admin/src/icons/ManyToMany.js +98 -0
- package/admin/src/icons/ManyToOne.js +64 -0
- package/admin/src/icons/ManyWay.js +36 -0
- package/admin/src/icons/OneToMany.js +65 -0
- package/admin/src/icons/OneToOne.js +47 -0
- package/admin/src/icons/OneWay.js +38 -0
- package/admin/src/index.js +83 -0
- package/admin/src/lifecycles.js +13 -0
- package/admin/src/permissions.js +9 -0
- package/admin/src/pluginId.js +5 -0
- package/admin/src/reducers.js +10 -0
- package/admin/src/translations/ar.json +48 -0
- package/admin/src/translations/cs.json +151 -0
- package/admin/src/translations/de.json +187 -0
- package/admin/src/translations/dk.json +181 -0
- package/admin/src/translations/en.json +188 -0
- package/admin/src/translations/es.json +188 -0
- package/admin/src/translations/fr.json +87 -0
- package/admin/src/translations/id.json +187 -0
- package/admin/src/translations/index.js +51 -0
- package/admin/src/translations/it.json +187 -0
- package/admin/src/translations/ja.json +50 -0
- package/admin/src/translations/ko.json +57 -0
- package/admin/src/translations/ms.json +179 -0
- package/admin/src/translations/nl.json +171 -0
- package/admin/src/translations/pl.json +152 -0
- package/admin/src/translations/pt-BR.json +51 -0
- package/admin/src/translations/pt.json +51 -0
- package/admin/src/translations/ru.json +188 -0
- package/admin/src/translations/sk.json +186 -0
- package/admin/src/translations/th.json +181 -0
- package/admin/src/translations/tr.json +51 -0
- package/admin/src/translations/uk.json +180 -0
- package/admin/src/translations/zh-Hans.json +188 -0
- package/admin/src/translations/zh.json +178 -0
- package/admin/src/utils/convertAttrObjToArray.js +7 -0
- package/admin/src/utils/formAPI.js +112 -0
- package/admin/src/utils/getAttributeDisplayedType.js +31 -0
- package/admin/src/utils/getComponents.js +31 -0
- package/admin/src/utils/getTrad.js +5 -0
- package/admin/src/utils/makeSearch.js +15 -0
- package/admin/src/utils/makeUnique.js +3 -0
- package/config/functions/bootstrap.js +14 -0
- package/config/routes.json +144 -0
- package/controllers/Builder.js +7 -0
- package/controllers/ComponentCategories.js +43 -0
- package/controllers/Components.js +152 -0
- package/controllers/Connections.js +9 -0
- package/controllers/ContentTypes.js +143 -0
- package/controllers/validation/common.js +118 -0
- package/controllers/validation/component-category.js +21 -0
- package/controllers/validation/component.js +89 -0
- package/controllers/validation/content-type.js +161 -0
- package/controllers/validation/data-transform.js +32 -0
- package/controllers/validation/model-schema.js +91 -0
- package/controllers/validation/relations.js +56 -0
- package/controllers/validation/types.js +277 -0
- package/package.json +63 -0
- package/services/Builder.js +7 -0
- package/services/ComponentCategories.js +88 -0
- package/services/Components.js +103 -0
- package/services/ContentTypes.js +263 -0
- package/services/api-handler.js +158 -0
- package/services/constants.js +59 -0
- package/services/schema-builder/component-builder.js +137 -0
- package/services/schema-builder/content-type-builder.js +256 -0
- package/services/schema-builder/index.js +196 -0
- package/services/schema-builder/schema-handler.js +297 -0
- package/utils/attributes.js +154 -0
- package/utils/helpers.js +31 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { cloneDeep, get } from 'lodash';
|
|
2
|
+
import * as yup from 'yup';
|
|
3
|
+
|
|
4
|
+
const formsAPI = {
|
|
5
|
+
components: {
|
|
6
|
+
inputs: {},
|
|
7
|
+
add({ id, component }) {
|
|
8
|
+
if (!this.inputs[id]) {
|
|
9
|
+
this.inputs[id] = component;
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
types: {
|
|
14
|
+
attribute: {
|
|
15
|
+
// test: {
|
|
16
|
+
// validators: [],
|
|
17
|
+
// form: {
|
|
18
|
+
// advanced: [
|
|
19
|
+
// /* cb */
|
|
20
|
+
// ],
|
|
21
|
+
// base: [
|
|
22
|
+
// /* cb */
|
|
23
|
+
// ],
|
|
24
|
+
// },
|
|
25
|
+
// },
|
|
26
|
+
},
|
|
27
|
+
contentType: {
|
|
28
|
+
validators: [],
|
|
29
|
+
form: {
|
|
30
|
+
advanced: [],
|
|
31
|
+
base: [],
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
component: {
|
|
35
|
+
validators: [],
|
|
36
|
+
form: {
|
|
37
|
+
advanced: [],
|
|
38
|
+
base: [],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
contentTypeSchemaMutations: [],
|
|
43
|
+
addContentTypeSchemaMutation(cb) {
|
|
44
|
+
this.contentTypeSchemaMutations.push(cb);
|
|
45
|
+
},
|
|
46
|
+
extendContentType({ validator, form: { advanced, base } }) {
|
|
47
|
+
const { contentType } = this.types;
|
|
48
|
+
|
|
49
|
+
contentType.validators.push(validator);
|
|
50
|
+
contentType.form.advanced.push(advanced);
|
|
51
|
+
contentType.form.base.push(base);
|
|
52
|
+
},
|
|
53
|
+
extendFields(fields, { validator, form: { advanced, base } }) {
|
|
54
|
+
const formType = this.types.attribute;
|
|
55
|
+
|
|
56
|
+
fields.forEach(field => {
|
|
57
|
+
if (!formType[field]) {
|
|
58
|
+
formType[field] = {
|
|
59
|
+
validators: [],
|
|
60
|
+
form: {
|
|
61
|
+
advanced: [
|
|
62
|
+
/* cb */
|
|
63
|
+
],
|
|
64
|
+
base: [
|
|
65
|
+
/* cb */
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
formType[field].validators.push(validator);
|
|
71
|
+
formType[field].form.advanced.push(advanced);
|
|
72
|
+
formType[field].form.base.push(base);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
makeAdvancedForm(target, initSections, props) {
|
|
77
|
+
const sectionsToAdd = get(this.types, [...target, 'form', 'advanced'], []).reduce(
|
|
78
|
+
(acc, current) => {
|
|
79
|
+
const sections = current(props);
|
|
80
|
+
|
|
81
|
+
return [...acc, ...sections];
|
|
82
|
+
},
|
|
83
|
+
[]
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
return { items: [...initSections, ...sectionsToAdd] };
|
|
87
|
+
},
|
|
88
|
+
makeValidator(target, initShape, ...args) {
|
|
89
|
+
const validators = get(this.types, [...target, 'validators'], []);
|
|
90
|
+
|
|
91
|
+
const pluginOptionsShape = validators.reduce((acc, current) => {
|
|
92
|
+
const pluginOptionShape = current(args);
|
|
93
|
+
|
|
94
|
+
return { ...acc, ...pluginOptionShape };
|
|
95
|
+
}, {});
|
|
96
|
+
|
|
97
|
+
return initShape.shape({ pluginOptions: yup.object().shape(pluginOptionsShape) });
|
|
98
|
+
},
|
|
99
|
+
mutateContentTypeSchema(data, initialData) {
|
|
100
|
+
let enhancedData = cloneDeep(data);
|
|
101
|
+
|
|
102
|
+
const refData = cloneDeep(initialData);
|
|
103
|
+
|
|
104
|
+
this.contentTypeSchemaMutations.forEach(cb => {
|
|
105
|
+
enhancedData = cb(enhancedData, refData);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return enhancedData;
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export default formsAPI;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const getAttributeDisplayedType = type => {
|
|
2
|
+
let displayedType;
|
|
3
|
+
|
|
4
|
+
switch (type) {
|
|
5
|
+
case 'date':
|
|
6
|
+
case 'datetime':
|
|
7
|
+
case 'time':
|
|
8
|
+
case 'timestamp':
|
|
9
|
+
displayedType = 'date';
|
|
10
|
+
break;
|
|
11
|
+
case 'integer':
|
|
12
|
+
case 'biginteger':
|
|
13
|
+
case 'decimal':
|
|
14
|
+
case 'float':
|
|
15
|
+
displayedType = 'number';
|
|
16
|
+
break;
|
|
17
|
+
case 'string':
|
|
18
|
+
case 'text':
|
|
19
|
+
displayedType = 'text';
|
|
20
|
+
break;
|
|
21
|
+
case '':
|
|
22
|
+
displayedType = 'relation';
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
displayedType = type;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return displayedType;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default getAttributeDisplayedType;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { get } from 'lodash';
|
|
3
|
+
import pluginId from '../pluginId';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Retrieve external links from injected components
|
|
7
|
+
* @type {Array} List of external links to display
|
|
8
|
+
*/
|
|
9
|
+
const getInjectedComponents = (container, area, plugins, rest) => {
|
|
10
|
+
const componentsToInject = Object.keys(plugins).reduce((acc, current) => {
|
|
11
|
+
// Retrieve injected compos from plugin
|
|
12
|
+
const currentPlugin = plugins[current];
|
|
13
|
+
const injectedComponents = get(currentPlugin, 'injectedComponents', []);
|
|
14
|
+
|
|
15
|
+
const compos = injectedComponents
|
|
16
|
+
.filter(compo => {
|
|
17
|
+
return compo.plugin === `${pluginId}.${container}` && compo.area === area;
|
|
18
|
+
})
|
|
19
|
+
.map(compo => {
|
|
20
|
+
const Component = compo.component;
|
|
21
|
+
|
|
22
|
+
return <Component {...compo} {...rest} key={compo.key} />;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return [...acc, ...compos];
|
|
26
|
+
}, []);
|
|
27
|
+
|
|
28
|
+
return componentsToInject;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default getInjectedComponents;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const makeSearch = (searchObj, shouldContinue = true) => {
|
|
2
|
+
if (!shouldContinue) {
|
|
3
|
+
return '';
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
return Object.keys(searchObj).reduce((acc, current, index) => {
|
|
7
|
+
if (searchObj[current] !== null) {
|
|
8
|
+
acc = `${acc}${index === 0 ? '' : '&'}${current}=${searchObj[current]}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return acc;
|
|
12
|
+
}, '');
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default makeSearch;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = async () => {
|
|
4
|
+
const actions = [
|
|
5
|
+
{
|
|
6
|
+
section: 'plugins',
|
|
7
|
+
displayName: 'Read',
|
|
8
|
+
uid: 'read',
|
|
9
|
+
pluginName: 'content-type-builder',
|
|
10
|
+
},
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
await strapi.admin.services.permission.actionProvider.registerMany(actions);
|
|
14
|
+
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
{
|
|
2
|
+
"routes": [
|
|
3
|
+
{
|
|
4
|
+
"method": "GET",
|
|
5
|
+
"path": "/reserved-names",
|
|
6
|
+
"handler": "Builder.getReservedNames",
|
|
7
|
+
"config": {
|
|
8
|
+
"policies": [
|
|
9
|
+
["admin::hasPermissions", ["plugins::content-type-builder.read"]]
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"method": "GET",
|
|
15
|
+
"path": "/connections",
|
|
16
|
+
"handler": "Connections.getConnections",
|
|
17
|
+
"config": {
|
|
18
|
+
"policies": [
|
|
19
|
+
["admin::hasPermissions", ["plugins::content-type-builder.read"]]
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"method": "GET",
|
|
25
|
+
"path": "/content-types",
|
|
26
|
+
"handler": "ContentTypes.getContentTypes",
|
|
27
|
+
"config": {
|
|
28
|
+
"policies": [
|
|
29
|
+
["admin::hasPermissions", ["plugins::content-type-builder.read"]]
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"method": "GET",
|
|
35
|
+
"path": "/content-types/:uid",
|
|
36
|
+
"handler": "ContentTypes.getContentType",
|
|
37
|
+
"config": {
|
|
38
|
+
"policies": [
|
|
39
|
+
["admin::hasPermissions", ["plugins::content-type-builder.read"]]
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"method": "POST",
|
|
45
|
+
"path": "/content-types",
|
|
46
|
+
"handler": "ContentTypes.createContentType",
|
|
47
|
+
"config": {
|
|
48
|
+
"policies": [
|
|
49
|
+
["admin::hasPermissions", ["plugins::content-type-builder.read"]]
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"method": "PUT",
|
|
55
|
+
"path": "/content-types/:uid",
|
|
56
|
+
"handler": "ContentTypes.updateContentType",
|
|
57
|
+
"config": {
|
|
58
|
+
"policies": [
|
|
59
|
+
["admin::hasPermissions", ["plugins::content-type-builder.read"]]
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"method": "DELETE",
|
|
65
|
+
"path": "/content-types/:uid",
|
|
66
|
+
"handler": "ContentTypes.deleteContentType",
|
|
67
|
+
"config": {
|
|
68
|
+
"policies": [
|
|
69
|
+
["admin::hasPermissions", ["plugins::content-type-builder.read"]]
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"method": "GET",
|
|
75
|
+
"path": "/components",
|
|
76
|
+
"handler": "Components.getComponents",
|
|
77
|
+
"config": {
|
|
78
|
+
"policies": [
|
|
79
|
+
["admin::hasPermissions", ["plugins::content-type-builder.read"]]
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"method": "GET",
|
|
85
|
+
"path": "/components/:uid",
|
|
86
|
+
"handler": "Components.getComponent",
|
|
87
|
+
"config": {
|
|
88
|
+
"policies": [
|
|
89
|
+
["admin::hasPermissions", ["plugins::content-type-builder.read"]]
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"method": "POST",
|
|
95
|
+
"path": "/components",
|
|
96
|
+
"handler": "Components.createComponent",
|
|
97
|
+
"config": {
|
|
98
|
+
"policies": [
|
|
99
|
+
["admin::hasPermissions", ["plugins::content-type-builder.read"]]
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"method": "PUT",
|
|
105
|
+
"path": "/components/:uid",
|
|
106
|
+
"handler": "Components.updateComponent",
|
|
107
|
+
"config": {
|
|
108
|
+
"policies": [
|
|
109
|
+
["admin::hasPermissions", ["plugins::content-type-builder.read"]]
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"method": "DELETE",
|
|
115
|
+
"path": "/components/:uid",
|
|
116
|
+
"handler": "Components.deleteComponent",
|
|
117
|
+
"config": {
|
|
118
|
+
"policies": [
|
|
119
|
+
["admin::hasPermissions", ["plugins::content-type-builder.read"]]
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"method": "PUT",
|
|
125
|
+
"path": "/component-categories/:name",
|
|
126
|
+
"handler": "ComponentCategories.editCategory",
|
|
127
|
+
"config": {
|
|
128
|
+
"policies": [
|
|
129
|
+
["admin::hasPermissions", ["plugins::content-type-builder.read"]]
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"method": "DELETE",
|
|
135
|
+
"path": "/component-categories/:name",
|
|
136
|
+
"handler": "ComponentCategories.deleteCategory",
|
|
137
|
+
"config": {
|
|
138
|
+
"policies": [
|
|
139
|
+
["admin::hasPermissions", ["plugins::content-type-builder.read"]]
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const validateComponentCategory = require('./validation/component-category');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
async editCategory(ctx) {
|
|
7
|
+
const { body } = ctx.request;
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
await validateComponentCategory(body);
|
|
11
|
+
} catch (error) {
|
|
12
|
+
return ctx.send({ error }, 400);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const { name } = ctx.params;
|
|
16
|
+
|
|
17
|
+
strapi.reload.isWatching = false;
|
|
18
|
+
|
|
19
|
+
const componentCategoryService =
|
|
20
|
+
strapi.plugins['content-type-builder'].services.componentcategories;
|
|
21
|
+
|
|
22
|
+
const newName = await componentCategoryService.editCategory(name, body);
|
|
23
|
+
|
|
24
|
+
setImmediate(() => strapi.reload());
|
|
25
|
+
|
|
26
|
+
ctx.send({ name: newName });
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
async deleteCategory(ctx) {
|
|
30
|
+
const { name } = ctx.params;
|
|
31
|
+
|
|
32
|
+
strapi.reload.isWatching = false;
|
|
33
|
+
|
|
34
|
+
const componentCategoryService =
|
|
35
|
+
strapi.plugins['content-type-builder'].services.componentcategories;
|
|
36
|
+
|
|
37
|
+
await componentCategoryService.deleteCategory(name);
|
|
38
|
+
|
|
39
|
+
setImmediate(() => strapi.reload());
|
|
40
|
+
|
|
41
|
+
ctx.send({ name });
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
validateComponentInput,
|
|
7
|
+
validateUpdateComponentInput,
|
|
8
|
+
} = require('./validation/component');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Components controller
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
/**
|
|
16
|
+
* GET /components handler
|
|
17
|
+
* Returns a list of available components
|
|
18
|
+
* @param {Object} ctx - koa context
|
|
19
|
+
*/
|
|
20
|
+
async getComponents(ctx) {
|
|
21
|
+
const componentService =
|
|
22
|
+
strapi.plugins['content-type-builder'].services.components;
|
|
23
|
+
|
|
24
|
+
const data = Object.keys(strapi.components).map(uid => {
|
|
25
|
+
return componentService.formatComponent(strapi.components[uid]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
ctx.send({ data });
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* GET /components/:uid
|
|
33
|
+
* Returns a specific component
|
|
34
|
+
* @param {Object} ctx - koa context
|
|
35
|
+
*/
|
|
36
|
+
async getComponent(ctx) {
|
|
37
|
+
const { uid } = ctx.params;
|
|
38
|
+
|
|
39
|
+
const component = strapi.components[uid];
|
|
40
|
+
|
|
41
|
+
if (!component) {
|
|
42
|
+
return ctx.send({ error: 'component.notFound' }, 404);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const componentService =
|
|
46
|
+
strapi.plugins['content-type-builder'].services.components;
|
|
47
|
+
|
|
48
|
+
ctx.send({ data: componentService.formatComponent(component) });
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* POST /components
|
|
53
|
+
* Creates a component and returns its infos
|
|
54
|
+
* @param {Object} ctx - koa context
|
|
55
|
+
*/
|
|
56
|
+
async createComponent(ctx) {
|
|
57
|
+
const { body } = ctx.request;
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
await validateComponentInput(body);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return ctx.send({ error }, 400);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
strapi.reload.isWatching = false;
|
|
67
|
+
|
|
68
|
+
const componentService =
|
|
69
|
+
strapi.plugins['content-type-builder'].services.components;
|
|
70
|
+
|
|
71
|
+
const component = await componentService.createComponent({
|
|
72
|
+
component: body.component,
|
|
73
|
+
components: body.components,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
setImmediate(() => strapi.reload());
|
|
77
|
+
|
|
78
|
+
ctx.send({ data: { uid: component.uid } }, 201);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
strapi.log.error(error);
|
|
81
|
+
ctx.send({ error: error.message }, 400);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* PUT /components/:uid
|
|
87
|
+
* Updates a component and return its infos
|
|
88
|
+
* @param {Object} ctx - koa context - enhanced koa context
|
|
89
|
+
*/
|
|
90
|
+
async updateComponent(ctx) {
|
|
91
|
+
const { uid } = ctx.params;
|
|
92
|
+
const { body } = ctx.request;
|
|
93
|
+
|
|
94
|
+
if (!_.has(strapi.components, uid)) {
|
|
95
|
+
return ctx.send({ error: 'component.notFound' }, 404);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
await validateUpdateComponentInput(body);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
return ctx.send({ error }, 400);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
try {
|
|
105
|
+
strapi.reload.isWatching = false;
|
|
106
|
+
|
|
107
|
+
const componentService =
|
|
108
|
+
strapi.plugins['content-type-builder'].services.components;
|
|
109
|
+
|
|
110
|
+
const component = await componentService.editComponent(uid, {
|
|
111
|
+
component: body.component,
|
|
112
|
+
components: body.components,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
setImmediate(() => strapi.reload());
|
|
116
|
+
|
|
117
|
+
ctx.send({ data: { uid: component.uid } });
|
|
118
|
+
} catch (error) {
|
|
119
|
+
strapi.log.error(error);
|
|
120
|
+
ctx.send({ error: error.message }, 400);
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* DELETE /components/:uid
|
|
126
|
+
* Deletes a components and returns its old infos
|
|
127
|
+
* @param {Object} ctx - koa context
|
|
128
|
+
*/
|
|
129
|
+
async deleteComponent(ctx) {
|
|
130
|
+
const { uid } = ctx.params;
|
|
131
|
+
|
|
132
|
+
if (!_.has(strapi.components, uid)) {
|
|
133
|
+
return ctx.send({ error: 'component.notFound' }, 404);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
strapi.reload.isWatching = false;
|
|
138
|
+
|
|
139
|
+
const componentService =
|
|
140
|
+
strapi.plugins['content-type-builder'].services.components;
|
|
141
|
+
|
|
142
|
+
const component = await componentService.deleteComponent(uid);
|
|
143
|
+
|
|
144
|
+
setImmediate(() => strapi.reload());
|
|
145
|
+
|
|
146
|
+
ctx.send({ data: { uid: component.uid } });
|
|
147
|
+
} catch (error) {
|
|
148
|
+
strapi.log.error(error);
|
|
149
|
+
ctx.send({ error: error.message }, 400);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
};
|