@webbio/strapi-plugin-page-builder 0.0.31 → 0.1.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/README.md +35 -4
- package/admin/src/components/EditView/CollectionTypeSearch/index.tsx +6 -0
- package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +5 -3
- package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +14 -3
- package/admin/src/components/EditView/PageSettings/index.tsx +13 -6
- package/admin/src/components/EditView/Template/TemplateSelect/index.tsx +6 -1
- package/admin/src/components/EditView/Template/TemplateSelect/use-template-modules.ts +1 -1
- package/admin/src/components/EditView/page-type-select.tsx +3 -1
- package/admin/src/constants.ts +2 -0
- package/admin/src/index.tsx +1 -1
- package/dist/package.json +1 -1
- package/dist/server/bootstrap.js +86 -17
- package/dist/server/controllers/collection-types.js +0 -2
- package/dist/server/controllers/page-type.js +0 -1
- package/dist/server/controllers/page.js +0 -8
- package/dist/server/controllers/platform.js +20 -0
- package/dist/server/controllers/template.js +0 -2
- package/dist/server/graphql/index.js +2 -0
- package/dist/server/graphql/page-by-slug.js +4 -4
- package/dist/server/graphql/pages-by-uid.js +105 -0
- package/dist/server/register.js +2 -0
- package/dist/server/schema/platform-start.json +31 -0
- package/dist/server/services/builder.js +2 -2
- package/dist/server/services/page-type.js +7 -4
- package/dist/server/services/platform.js +36 -0
- package/dist/server/utils/paginationValidation.js +31 -0
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/server/bootstrap.ts +94 -17
- package/server/controllers/collection-types.ts +4 -4
- package/server/controllers/page-type.ts +3 -2
- package/server/controllers/page.ts +0 -11
- package/server/controllers/template.ts +4 -4
- package/server/graphql/index.ts +2 -0
- package/server/graphql/page-by-slug.ts +1 -1
- package/server/graphql/page-type.ts +8 -4
- package/server/graphql/pages-by-uid.ts +127 -0
- package/server/register.ts +2 -0
- package/server/services/builder.ts +9 -11
- package/server/services/collection-types.ts +5 -6
- package/server/services/page-type.ts +7 -3
- package/server/utils/paginationValidation.ts +39 -0
- package/server/utils/strapi.ts +3 -1
- package/tsconfig.tsbuildinfo +1 -1
package/README.md
CHANGED
|
@@ -26,8 +26,9 @@ De collectiontypes `Page`, `Template` en `PageType` worden aangemaakt of bijgewe
|
|
|
26
26
|
## Page Types
|
|
27
27
|
|
|
28
28
|
Maak voor elke pagina type een Page Type aan. Deze kan, maar hoeft niet, gekoppeld worden aan een collection type. Je moet altijd een UID invoeren, als je wenst geen koppeling te maken met een collection type, vul hier alsnog iets in. Het kan zijn dat dit deel van de plugin nog niet werkt, hier is nog niet mee getest.
|
|
29
|
+
hasPage moet toegevoegd worden aan de collectiontype. Dit komt doordat er gefilterd moet kunnen worden middels graphql. Er is een custom manier gebouwd om ervoor te zorgen dat pages gefilterd kan worden.
|
|
29
30
|
|
|
30
|
-
Voor elk collection type die een page type is, moet deze
|
|
31
|
+
Voor elk collection type die een page type is, moet deze properties toegevoegd worden:
|
|
31
32
|
|
|
32
33
|
```
|
|
33
34
|
"page": {
|
|
@@ -35,7 +36,11 @@ Voor elk collection type die een page type is, moet deze property toegevoegd wor
|
|
|
35
36
|
"relation": "morphMany",
|
|
36
37
|
"target": "api::page.page",
|
|
37
38
|
"morphBy": "collectionTypeData"
|
|
38
|
-
}
|
|
39
|
+
},
|
|
40
|
+
"hasPage": {
|
|
41
|
+
"type": "boolean",
|
|
42
|
+
"default": false
|
|
43
|
+
}
|
|
39
44
|
```
|
|
40
45
|
|
|
41
46
|
Zodra dit goed is ingesteld, kan je via deze collectie types direct een pagina aanmaken.
|
|
@@ -48,10 +53,36 @@ Op een page kan je in de Edit View een page type selecteren. Op basis daarvan wo
|
|
|
48
53
|
|
|
49
54
|
Een template is niets anders dan een sjabloon die je eenmalig kan toevoegen op een pagina. Dit kan via een page type gaan maar kan ook zonder de page type. Een modal zal eerst nog vragen of je zeker bent van je keuze, alle modules zullen vervangen worden.
|
|
50
55
|
|
|
56
|
+
## Platform
|
|
57
|
+
|
|
58
|
+
Om wijzigignen aan te brengen in een platform, moeten deze in de schema aangepast worden van de api. `/src/api/platform/content-types/platform/schema.json`
|
|
59
|
+
|
|
60
|
+
Voor elk collectiontype die je wil toevoegen aan het platform, moet deze relatie toegevoegd worden:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
"collectiontype": {
|
|
64
|
+
"type": "relation",
|
|
65
|
+
"relation": "oneToMany",
|
|
66
|
+
"target": "UID van collection type",
|
|
67
|
+
"mappedBy": "platform"
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
bijvoorbeeld :
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
"faqs": {
|
|
75
|
+
"type": "relation",
|
|
76
|
+
"relation": "oneToMany",
|
|
77
|
+
"target": "api::faq.faq",
|
|
78
|
+
"mappedBy": "platform"
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Een platform zit altijd aan een pagina gekoppeld. Deze moet handmatig in de pagina toegevoegd worden.
|
|
83
|
+
|
|
51
84
|
# Known bugs
|
|
52
85
|
|
|
53
|
-
- Bij het dupliceren van een collectiontype met een gekoppelde pagina, wordt ook de nieuwe collectiontype gekoppeld aan die pagina. Dit moet niet gebeuren.
|
|
54
|
-
- Bij het inladen van een template worden diepere waarden niet meegenomen.
|
|
55
86
|
- Bij het opslaan van een collectietype wil de gekoppelde pagina of type in het ui wel eens verdwijnen.
|
|
56
87
|
- Na het ontkoppelen en opslaan van een collectie item op een pagina, staat deze nog als "Geselecteerd" in de dropdown.
|
|
57
88
|
|
|
@@ -32,6 +32,12 @@ export const CollectionTypeSearch = ({ uid }: Props) => {
|
|
|
32
32
|
const isPagePageType = !uid;
|
|
33
33
|
const searchEntitiesIsEnabled = !isPagePageType;
|
|
34
34
|
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (form.isCreatingEntry) {
|
|
37
|
+
setSelected(null);
|
|
38
|
+
}
|
|
39
|
+
}, []);
|
|
40
|
+
|
|
35
41
|
const getItems = async (inputValue?: string): Promise<IReactSelectValue[]> => {
|
|
36
42
|
const searchEntities = await getSearchEntities({
|
|
37
43
|
fetchClient,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
2
|
import { useHistory } from 'react-router-dom';
|
|
3
3
|
|
|
4
4
|
import { Plus } from '@strapi/icons';
|
|
@@ -15,7 +15,7 @@ export const CreatePageButton = () => {
|
|
|
15
15
|
const history = useHistory();
|
|
16
16
|
const { layout, initialData } = useCMEditViewDataManager();
|
|
17
17
|
|
|
18
|
-
const { post, get } = useFetchClient();
|
|
18
|
+
const { post, get, put } = useFetchClient();
|
|
19
19
|
const url = `/content-manager/collectionType/${PAGE_UID}/create`;
|
|
20
20
|
|
|
21
21
|
const handleCreatePage = async (e: React.MouseEvent<HTMLAnchorElement>) => {
|
|
@@ -41,8 +41,10 @@ export const CreatePageButton = () => {
|
|
|
41
41
|
layoutUid: layout.uid,
|
|
42
42
|
relatedEntityId: createLocalizedPage ? linkedPages.data?.[0]?.id : undefined
|
|
43
43
|
});
|
|
44
|
-
|
|
45
44
|
if (newPage?.id) {
|
|
45
|
+
await put(`/content-manager/collection-types/${layout.uid}/${initialData.id}`, {
|
|
46
|
+
hasPage: true
|
|
47
|
+
});
|
|
46
48
|
history.push(`/content-manager/collectionType/${PAGE_UID}/${newPage.id}?plugins[i18n][locale]=${locale}`);
|
|
47
49
|
}
|
|
48
50
|
} catch (error) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
2
|
|
|
3
3
|
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
|
4
4
|
import { Flex } from '@strapi/design-system';
|
|
@@ -10,7 +10,7 @@ import { PAGE_TYPE_PAGE, PAGE_UID } from '../../../../../shared/utils/constants'
|
|
|
10
10
|
import S from '../Details/styles';
|
|
11
11
|
|
|
12
12
|
export const CollectionTypeSettings = () => {
|
|
13
|
-
const { layout, isCreatingEntry, initialData } = useCMEditViewDataManager();
|
|
13
|
+
const { layout, isCreatingEntry, initialData, onChange } = useCMEditViewDataManager();
|
|
14
14
|
|
|
15
15
|
const isUserCreatedContentType = layout.uid.startsWith('api::');
|
|
16
16
|
const linkedPage = initialData.page?.[0];
|
|
@@ -18,12 +18,23 @@ export const CollectionTypeSettings = () => {
|
|
|
18
18
|
const showCreatePageButton = isUserCreatedContentType && !isCreatingEntry && !linkedPage;
|
|
19
19
|
const url = generateLink(linkedPage?.id, initialData?.locale);
|
|
20
20
|
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (isCreatingEntry) {
|
|
23
|
+
onChange({
|
|
24
|
+
target: {
|
|
25
|
+
name: 'page',
|
|
26
|
+
value: null
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}, []);
|
|
31
|
+
|
|
21
32
|
if (isCreatingEntry) {
|
|
22
33
|
return null;
|
|
23
34
|
}
|
|
24
35
|
|
|
25
36
|
return (
|
|
26
|
-
<Wrapper title="
|
|
37
|
+
<Wrapper title="Gekoppelde pagina">
|
|
27
38
|
<Flex direction="column" gap={4} width="100%" alignItems="start">
|
|
28
39
|
{showCreatePageButton && <CreatePageButton />}
|
|
29
40
|
|
|
@@ -3,7 +3,6 @@ import React, { useEffect, useMemo, useState } from 'react';
|
|
|
3
3
|
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
|
4
4
|
import { Stack, Flex } from '@strapi/design-system';
|
|
5
5
|
import { Cog, Cross } from '@strapi/icons';
|
|
6
|
-
|
|
7
6
|
import { TemplateSelect } from '../Template/TemplateSelect';
|
|
8
7
|
import { PageTypeSelect } from '../page-type-select';
|
|
9
8
|
import { CollectionTypeSearch } from '../CollectionTypeSearch';
|
|
@@ -14,9 +13,10 @@ import S from '../Details/styles';
|
|
|
14
13
|
|
|
15
14
|
export const PageSettings = () => {
|
|
16
15
|
const { isCreatingEntry, initialData, onChange, modifiedData } = useCMEditViewDataManager();
|
|
17
|
-
const { data:
|
|
18
|
-
|
|
16
|
+
const { data: pageTypesData } = useGetPageTypes({});
|
|
17
|
+
const [pageTypes, setPageTypes] = useState(pageTypesData);
|
|
19
18
|
const [selectedPageType, setSelectedPageType] = useState<PageType | undefined | null>(initialData?.initialPageType);
|
|
19
|
+
const [hasSelectedPlatform, setHasSelectedPlatform] = useState<boolean>(true);
|
|
20
20
|
const [isEditting, setIsEditting] = useState(false);
|
|
21
21
|
const showEditFields = useMemo(
|
|
22
22
|
() => isCreatingEntry || !selectedPageType?.id || !initialData.collectionTypeTitle || isEditting,
|
|
@@ -35,6 +35,7 @@ export const PageSettings = () => {
|
|
|
35
35
|
|
|
36
36
|
useEffect(() => {
|
|
37
37
|
setSelectedPageType(initialData?.initialPageType);
|
|
38
|
+
|
|
38
39
|
setIsEditting(false);
|
|
39
40
|
}, [initialData]);
|
|
40
41
|
|
|
@@ -65,18 +66,24 @@ export const PageSettings = () => {
|
|
|
65
66
|
value: pageType.id
|
|
66
67
|
};
|
|
67
68
|
setFormValue('pageType', [formPageType]);
|
|
69
|
+
setHasSelectedPlatform(false);
|
|
68
70
|
} else {
|
|
69
71
|
removePageType();
|
|
70
72
|
}
|
|
71
73
|
};
|
|
72
74
|
|
|
73
75
|
return (
|
|
74
|
-
<Wrapper title="
|
|
76
|
+
<Wrapper title="Gekoppelde type">
|
|
75
77
|
<Flex direction="column" gap={4} width="100%">
|
|
76
78
|
{showEditFields ? (
|
|
77
79
|
<Stack spacing={4} width="100%">
|
|
78
|
-
<PageTypeSelect
|
|
79
|
-
|
|
80
|
+
<PageTypeSelect
|
|
81
|
+
pageTypes={pageTypes}
|
|
82
|
+
selectedPageType={selectedPageType}
|
|
83
|
+
onChange={handleSelectPageType}
|
|
84
|
+
disabled={hasSelectedPlatform}
|
|
85
|
+
/>
|
|
86
|
+
<TemplateSelect disabled={hasSelectedPlatform} />
|
|
80
87
|
{selectedPageType?.uid && <CollectionTypeSearch uid={selectedPageType.uid} />}
|
|
81
88
|
</Stack>
|
|
82
89
|
) : (
|
|
@@ -5,7 +5,11 @@ import { Template } from '../../../../api/template';
|
|
|
5
5
|
import TemplateConfirmModal from '../TemplateConfirmModal';
|
|
6
6
|
import { useTemplateModules } from './use-template-modules';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
interface Props {
|
|
9
|
+
disabled: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const TemplateSelect = ({ disabled }: Props) => {
|
|
9
13
|
const { onChange, modifiedData } = useCMEditViewDataManager();
|
|
10
14
|
const [selectedTemplate, setSelectedTemplate] = useState<Template | null>(null);
|
|
11
15
|
const { templates, replaceContentTypeModules } = useTemplateModules(onChange);
|
|
@@ -44,6 +48,7 @@ export const TemplateSelect = () => {
|
|
|
44
48
|
placeholder="Choose a template"
|
|
45
49
|
value={selectedTemplate?.id || 0}
|
|
46
50
|
onChange={handleSelectChange}
|
|
51
|
+
disabled={disabled}
|
|
47
52
|
>
|
|
48
53
|
<SingleSelectOption value={0}>None</SingleSelectOption>
|
|
49
54
|
{templates?.map((template) => (
|
|
@@ -31,7 +31,7 @@ const sanatizeContentTypeModules = (onChange: OnChangeFormType, modules: Record<
|
|
|
31
31
|
});
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
const replaceContentTypeModules = async (id: number,
|
|
34
|
+
const replaceContentTypeModules = async (id: number, fetchClient: any, onChange: OnChangeFormType) => {
|
|
35
35
|
const { get } = fetchClient;
|
|
36
36
|
const result = await get(getRequestUrl(`/template/${id}`));
|
|
37
37
|
return sanatizeContentTypeModules(onChange, result.data.modules);
|
|
@@ -9,15 +9,17 @@ interface Props {
|
|
|
9
9
|
onChange: (pageTypeId: string) => void;
|
|
10
10
|
selectedPageType?: PageType | null;
|
|
11
11
|
pageTypes?: PageType[];
|
|
12
|
+
disabled: boolean;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
export const PageTypeSelect = ({ onChange, pageTypes, selectedPageType }: Props) => {
|
|
15
|
+
export const PageTypeSelect = ({ onChange, pageTypes, selectedPageType, disabled }: Props) => {
|
|
15
16
|
return (
|
|
16
17
|
<SingleSelect
|
|
17
18
|
label="Page type"
|
|
18
19
|
placeholder="Choose a page type"
|
|
19
20
|
value={selectedPageType?.id || PAGE_TYPE_PAGE}
|
|
20
21
|
onChange={onChange}
|
|
22
|
+
disabled={disabled}
|
|
21
23
|
>
|
|
22
24
|
<SingleSelectOption value={PAGE_TYPE_PAGE}>Page</SingleSelectOption>
|
|
23
25
|
{pageTypes?.map((pageType: PageType) => (
|
package/admin/src/constants.ts
CHANGED
package/admin/src/index.tsx
CHANGED
package/dist/package.json
CHANGED
package/dist/server/bootstrap.js
CHANGED
|
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const utils_1 = require("@strapi/utils");
|
|
4
4
|
const constants_1 = require("../shared/utils/constants");
|
|
5
5
|
exports.default = async ({ strapi }) => {
|
|
6
|
+
var _a, _b;
|
|
6
7
|
// TODO: refactor to own function
|
|
7
8
|
try {
|
|
8
|
-
const pageTypes = await strapi.entityService.findMany(
|
|
9
|
+
const pageTypes = (await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findMany(constants_1.PAGE_TYPE_UID, {
|
|
9
10
|
limit: -1
|
|
10
|
-
});
|
|
11
|
+
})));
|
|
11
12
|
const pagePermissions = pageTypes.map((pageType) => {
|
|
12
13
|
const name = `page-type-is-${pageType.uid}`;
|
|
13
14
|
const displayName = pageType.title;
|
|
@@ -50,27 +51,28 @@ exports.default = async ({ strapi }) => {
|
|
|
50
51
|
};
|
|
51
52
|
return data;
|
|
52
53
|
};
|
|
53
|
-
strapi.db.lifecycles.subscribe({
|
|
54
|
+
(_b = strapi.db) === null || _b === void 0 ? void 0 : _b.lifecycles.subscribe({
|
|
54
55
|
// @ts-ignore
|
|
55
56
|
models: [constants_1.PAGE_UID],
|
|
56
57
|
async beforeCreate(event) {
|
|
57
|
-
var _a, _b;
|
|
58
|
+
var _a, _b, _c, _d;
|
|
58
59
|
let { data } = event.params;
|
|
59
60
|
const collectionTypeId = data === null || data === void 0 ? void 0 : data.collectionTypeId;
|
|
60
61
|
const pageTypeId = ((_b = (_a = data === null || data === void 0 ? void 0 : data.pageType.connect) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.id) || data.initialPageType;
|
|
61
62
|
if (collectionTypeId && pageTypeId) {
|
|
62
|
-
const
|
|
63
|
-
const collectionToConnect = await strapi.entityService.findOne(uid, collectionTypeId, {
|
|
63
|
+
const pageType = await ((_c = strapi.entityService) === null || _c === void 0 ? void 0 : _c.findOne(constants_1.PAGE_TYPE_UID, pageTypeId));
|
|
64
|
+
const collectionToConnect = await ((_d = strapi.entityService) === null || _d === void 0 ? void 0 : _d.findOne(pageType === null || pageType === void 0 ? void 0 : pageType.uid, collectionTypeId, {
|
|
64
65
|
populate: { page: true }
|
|
65
|
-
});
|
|
66
|
-
|
|
66
|
+
}));
|
|
67
|
+
const page = collectionToConnect === null || collectionToConnect === void 0 ? void 0 : collectionToConnect.page;
|
|
68
|
+
if (page && page.length > 0) {
|
|
67
69
|
throw new utils_1.errors.ValidationError('You can only link one CollectionType to one page');
|
|
68
70
|
}
|
|
69
|
-
data = updateCollectionTypeData(data, collectionTypeId, uid);
|
|
71
|
+
data = updateCollectionTypeData(data, collectionTypeId, pageType === null || pageType === void 0 ? void 0 : pageType.uid);
|
|
70
72
|
}
|
|
71
73
|
},
|
|
72
74
|
async beforeUpdate(event) {
|
|
73
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
75
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
74
76
|
let data = (_a = event === null || event === void 0 ? void 0 : event.params) === null || _a === void 0 ? void 0 : _a.data;
|
|
75
77
|
const collectionTypeId = data === null || data === void 0 ? void 0 : data.collectionTypeId;
|
|
76
78
|
const pageTypeId = ((_d = (_c = (_b = data === null || data === void 0 ? void 0 : data.pageType) === null || _b === void 0 ? void 0 : _b.connect) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.id) || (data === null || data === void 0 ? void 0 : data.initialPageType);
|
|
@@ -79,16 +81,83 @@ exports.default = async ({ strapi }) => {
|
|
|
79
81
|
data.collectionTypeData = undefined;
|
|
80
82
|
}
|
|
81
83
|
if (collectionTypeId && pageTypeId && !removedPageType) {
|
|
82
|
-
const
|
|
83
|
-
const collectionToConnect = await strapi.entityService.findOne(uid, collectionTypeId, {
|
|
84
|
+
const pageType = await ((_h = strapi.entityService) === null || _h === void 0 ? void 0 : _h.findOne(constants_1.PAGE_TYPE_UID, pageTypeId));
|
|
85
|
+
const collectionToConnect = await ((_j = strapi.entityService) === null || _j === void 0 ? void 0 : _j.findOne(pageType === null || pageType === void 0 ? void 0 : pageType.uid, collectionTypeId, {
|
|
84
86
|
populate: { page: true }
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
!(collectionToConnect === null || collectionToConnect === void 0 ? void 0 : collectionToConnect.page.some((p) => p.id === data.id))) {
|
|
87
|
+
}));
|
|
88
|
+
const page = collectionToConnect === null || collectionToConnect === void 0 ? void 0 : collectionToConnect.page;
|
|
89
|
+
if (page && (page === null || page === void 0 ? void 0 : page.length) > 0 && !page.some((p) => p.id === data.id)) {
|
|
89
90
|
throw new utils_1.errors.ValidationError('You can only link one CollectionType to one page');
|
|
90
91
|
}
|
|
91
|
-
data = updateCollectionTypeData(data, collectionTypeId, uid);
|
|
92
|
+
data = updateCollectionTypeData(data, collectionTypeId, pageType === null || pageType === void 0 ? void 0 : pageType.uid);
|
|
93
|
+
}
|
|
94
|
+
// needs to check if the collectionTypeData is already connected to another page
|
|
95
|
+
// if so, remove the hasPage for filtering
|
|
96
|
+
// const foundPage = await strapi.entityService?.findOne(PAGE_UID, data.id, { populate: '*' });
|
|
97
|
+
// if (
|
|
98
|
+
// data.collectionTypeData &&
|
|
99
|
+
// foundPage &&
|
|
100
|
+
// foundPage.collectionTypeData &&
|
|
101
|
+
// +data.collectionTypeData.id !== foundPage.collectionTypeData[0].id
|
|
102
|
+
// ) {
|
|
103
|
+
// await strapi.entityService?.update(foundPage.collectionTypeData[0].__type, foundPage.collectionTypeData[0].id, {
|
|
104
|
+
// data: {
|
|
105
|
+
// id: foundPage.collectionTypeData[0].id,
|
|
106
|
+
// hasPage: false
|
|
107
|
+
// }
|
|
108
|
+
// });
|
|
109
|
+
// }
|
|
110
|
+
},
|
|
111
|
+
async afterUpdate(event) {
|
|
112
|
+
var _a, _b;
|
|
113
|
+
const data = (_a = event === null || event === void 0 ? void 0 : event.params) === null || _a === void 0 ? void 0 : _a.data;
|
|
114
|
+
console.log(data);
|
|
115
|
+
if (data.collectionTypeData) {
|
|
116
|
+
await ((_b = strapi.entityService) === null || _b === void 0 ? void 0 : _b.update(data.collectionTypeData.__type, data.collectionTypeData.id, {
|
|
117
|
+
data: {
|
|
118
|
+
id: data.collectionTypeData.id,
|
|
119
|
+
hasPage: true
|
|
120
|
+
}
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
async afterCreate(event) {
|
|
125
|
+
var _a, _b;
|
|
126
|
+
const data = (_a = event === null || event === void 0 ? void 0 : event.params) === null || _a === void 0 ? void 0 : _a.data;
|
|
127
|
+
if (data.collectionTypeData) {
|
|
128
|
+
await ((_b = strapi.entityService) === null || _b === void 0 ? void 0 : _b.update(data.collectionTypeData.__type, data.collectionTypeData.id, {
|
|
129
|
+
data: {
|
|
130
|
+
id: data.collectionTypeData.id,
|
|
131
|
+
hasPage: true
|
|
132
|
+
}
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
async beforeDelete(event) {
|
|
137
|
+
var _a, _b;
|
|
138
|
+
const foundPage = await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findOne(constants_1.PAGE_UID, event.params.where.id, { populate: '*' }));
|
|
139
|
+
if (foundPage && foundPage.collectionTypeData) {
|
|
140
|
+
await ((_b = strapi.entityService) === null || _b === void 0 ? void 0 : _b.update(foundPage.collectionTypeData[0].__type, foundPage.collectionTypeData[0].id, {
|
|
141
|
+
data: {
|
|
142
|
+
id: foundPage.collectionTypeData[0].id,
|
|
143
|
+
hasPage: false
|
|
144
|
+
}
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
async beforeDeleteMany(event) {
|
|
149
|
+
var _a, _b;
|
|
150
|
+
const pagesToUnConnect = event.params.where['$and'][0].id['$in'];
|
|
151
|
+
for (const pageId of pagesToUnConnect) {
|
|
152
|
+
const foundPage = await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findOne(constants_1.PAGE_UID, pageId, { populate: '*' }));
|
|
153
|
+
if (foundPage && foundPage.collectionTypeData) {
|
|
154
|
+
await ((_b = strapi.entityService) === null || _b === void 0 ? void 0 : _b.update(foundPage.collectionTypeData[0].__type, foundPage.collectionTypeData[0].id, {
|
|
155
|
+
data: {
|
|
156
|
+
id: foundPage.collectionTypeData[0].id,
|
|
157
|
+
hasPage: false
|
|
158
|
+
}
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
92
161
|
}
|
|
93
162
|
}
|
|
94
163
|
});
|
|
@@ -4,7 +4,6 @@ exports.default = {
|
|
|
4
4
|
async hasPageRelation(ctx) {
|
|
5
5
|
var _a;
|
|
6
6
|
const uid = (_a = ctx.params) === null || _a === void 0 ? void 0 : _a.uid;
|
|
7
|
-
// @ts-ignore
|
|
8
7
|
return strapi.service('plugin::page-builder.collection-types').hasPageRelation(uid);
|
|
9
8
|
},
|
|
10
9
|
async getTranslationPageLinks(ctx) {
|
|
@@ -13,7 +12,6 @@ exports.default = {
|
|
|
13
12
|
if (!uid || (idsArr === null || idsArr === void 0 ? void 0 : idsArr.length) === 0) {
|
|
14
13
|
return undefined;
|
|
15
14
|
}
|
|
16
|
-
// @ts-ignore
|
|
17
15
|
return strapi.service('plugin::page-builder.collection-types').getTranslationPageLinks(uid, idsArr);
|
|
18
16
|
}
|
|
19
17
|
};
|
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const constants_1 = require("../../shared/utils/constants");
|
|
4
3
|
exports.default = {
|
|
5
4
|
async getPage(ctx) {
|
|
6
5
|
var _a, _b;
|
|
7
6
|
const id = (_a = ctx.params) === null || _a === void 0 ? void 0 : _a.id;
|
|
8
7
|
return (_b = strapi.service('plugin::page-builder.page')) === null || _b === void 0 ? void 0 : _b.getPage(id);
|
|
9
|
-
},
|
|
10
|
-
async findOneBySlug(ctx) {
|
|
11
|
-
var _a;
|
|
12
|
-
const { slug = '' } = ctx.params;
|
|
13
|
-
const entity = await ((_a = strapi.service(constants_1.PAGE_UID)) === null || _a === void 0 ? void 0 : _a.find({ filters: { slug } }));
|
|
14
|
-
const sanitizedEntity = await this.sanitizeOutput(entity, ctx);
|
|
15
|
-
return this.transformResponse(sanitizedEntity);
|
|
16
8
|
}
|
|
17
9
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = {
|
|
4
|
+
async findAll() {
|
|
5
|
+
return await strapi.service('plugin::page-builder.platform').findAll();
|
|
6
|
+
},
|
|
7
|
+
async findOneByUid(ctx) {
|
|
8
|
+
var _a;
|
|
9
|
+
const uid = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.params) === null || _a === void 0 ? void 0 : _a.uid;
|
|
10
|
+
if (!uid) {
|
|
11
|
+
return ctx.badRequest('uid is missing.');
|
|
12
|
+
}
|
|
13
|
+
return await strapi.service('plugin::page-builder.platform').findOneByUid(uid);
|
|
14
|
+
},
|
|
15
|
+
async findPageTypesByPlatform(ctx) {
|
|
16
|
+
var _a;
|
|
17
|
+
const platform = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.params) === null || _a === void 0 ? void 0 : _a.platform;
|
|
18
|
+
return await strapi.services['plugin::page-builder.platform'].findPageTypesByPlatform(platform);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
@@ -7,11 +7,9 @@ exports.default = {
|
|
|
7
7
|
if (!id) {
|
|
8
8
|
return ctx.badRequest('id is missing.');
|
|
9
9
|
}
|
|
10
|
-
// @ts-ignore strapi typings
|
|
11
10
|
return await strapi.service('plugin::page-builder.template').findOne(id);
|
|
12
11
|
},
|
|
13
12
|
async findAll() {
|
|
14
|
-
// @ts-ignore strapi typings
|
|
15
13
|
return await strapi.service('plugin::page-builder.template').findAll();
|
|
16
14
|
}
|
|
17
15
|
};
|
|
@@ -5,7 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const page_type_1 = __importDefault(require("./page-type"));
|
|
7
7
|
const page_by_slug_1 = __importDefault(require("./page-by-slug"));
|
|
8
|
+
const pages_by_uid_1 = __importDefault(require("./pages-by-uid"));
|
|
8
9
|
exports.default = {
|
|
10
|
+
getPageInfoFromUID: pages_by_uid_1.default,
|
|
9
11
|
pageType: page_type_1.default,
|
|
10
12
|
pageBySlug: page_by_slug_1.default
|
|
11
13
|
};
|
|
@@ -27,17 +27,17 @@ const getPageBySlug = (strapi) => {
|
|
|
27
27
|
};
|
|
28
28
|
const { toEntityResponse } = strapi.plugin('graphql').service('format').returnTypes;
|
|
29
29
|
const getPage = async () => {
|
|
30
|
-
var _a, _b;
|
|
30
|
+
var _a, _b, _c;
|
|
31
31
|
const transformedArgs = transformArgs(filteredArgs, {
|
|
32
32
|
contentType: strapi.contentTypes[constants_1.PAGE_UID],
|
|
33
33
|
usePagination: false
|
|
34
34
|
});
|
|
35
|
-
const results = await strapi.entityService.findMany(constants_1.PAGE_UID, {
|
|
35
|
+
const results = await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findMany(constants_1.PAGE_UID, {
|
|
36
36
|
filters: transformedArgs,
|
|
37
37
|
locale: args._locale,
|
|
38
38
|
publicationState: args._publicationState,
|
|
39
39
|
populate: '*'
|
|
40
|
-
});
|
|
40
|
+
}));
|
|
41
41
|
const entityResponse = toEntityResponse((results === null || results === void 0 ? void 0 : results[0]) || {}, {
|
|
42
42
|
args: transformedArgs,
|
|
43
43
|
resourceUID: constants_1.PAGE_UID
|
|
@@ -45,7 +45,7 @@ const getPageBySlug = (strapi) => {
|
|
|
45
45
|
if (!(entityResponse === null || entityResponse === void 0 ? void 0 : entityResponse.value) || Object.keys(entityResponse.value).length === 0) {
|
|
46
46
|
throw new Error(ctx.koaContext.response.message);
|
|
47
47
|
}
|
|
48
|
-
const collectionTypeDataFilter = (
|
|
48
|
+
const collectionTypeDataFilter = (_c = (_b = entityResponse === null || entityResponse === void 0 ? void 0 : entityResponse.value) === null || _b === void 0 ? void 0 : _b.collectionTypeData) === null || _c === void 0 ? void 0 : _c.filter(Boolean);
|
|
49
49
|
const collectionType = collectionTypeDataFilter.length === 1 ? collectionTypeDataFilter === null || collectionTypeDataFilter === void 0 ? void 0 : collectionTypeDataFilter[0] : null;
|
|
50
50
|
const addedAttributes = {
|
|
51
51
|
collectionType: collectionType
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const filter_underscore_arguments_1 = require("../utils/filter-underscore-arguments");
|
|
4
|
+
const constants_1 = require("../../shared/utils/constants");
|
|
5
|
+
const paginationValidation_1 = require("../utils/paginationValidation");
|
|
6
|
+
const getPageInfoFromUID = (strapi) => {
|
|
7
|
+
// @ts-ignore service does exist
|
|
8
|
+
const collectionTypes = strapi.service('plugin::page-builder.collection-types').withPageMorph();
|
|
9
|
+
const typeDefs = () => {
|
|
10
|
+
const metaInfo = `type MetaInfo {
|
|
11
|
+
total: Int
|
|
12
|
+
page: Int
|
|
13
|
+
pageCount: Int
|
|
14
|
+
pageSize: Int
|
|
15
|
+
}`;
|
|
16
|
+
const entityInfo = collectionTypes.map((collectionType) => {
|
|
17
|
+
return `
|
|
18
|
+
extend type ${collectionType.type}EntityResponseCollection {
|
|
19
|
+
metaInfo: MetaInfo
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type Query {
|
|
23
|
+
get${collectionType.type}Pages(filters: ${collectionType.type}FiltersInput,pagination: PaginationArg, sort:[String], pageFilters: PageFiltersInput): ${collectionType.type}EntityResponseCollection
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
`;
|
|
27
|
+
});
|
|
28
|
+
return `${metaInfo} ${entityInfo}`;
|
|
29
|
+
};
|
|
30
|
+
const resolvers = (strapi) => {
|
|
31
|
+
const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
|
|
32
|
+
const pageQuery = collectionTypes.map((collectionType) => {
|
|
33
|
+
return {
|
|
34
|
+
[`get${collectionType.type}Pages`]: {
|
|
35
|
+
resolve: async (_parent, args, ctx) => {
|
|
36
|
+
var _a;
|
|
37
|
+
if (!args.pagination || !args.pagination.page || !args.pagination.pageSize) {
|
|
38
|
+
throw new Error('page and pageSize is required');
|
|
39
|
+
}
|
|
40
|
+
const { start, limit } = paginationValidation_1.Pagination.checkPagination(args.pagination.page, args.pagination.pageSize);
|
|
41
|
+
const filteredArgs = {
|
|
42
|
+
...(0, filter_underscore_arguments_1.filterUnderscoreArguments)(args)
|
|
43
|
+
};
|
|
44
|
+
const pageFilters = { filters: args.pageFilters };
|
|
45
|
+
const { toEntityResponseCollection } = strapi.plugin('graphql').service('format').returnTypes;
|
|
46
|
+
const getPage = async () => {
|
|
47
|
+
var _a;
|
|
48
|
+
const transformedArgs = transformArgs(filteredArgs, {
|
|
49
|
+
contentType: strapi.contentTypes[collectionType.uid],
|
|
50
|
+
usePagination: true
|
|
51
|
+
});
|
|
52
|
+
const transformedpageArgs = transformArgs(pageFilters, {
|
|
53
|
+
contentType: strapi.contentTypes[constants_1.PAGE_UID],
|
|
54
|
+
usePagination: true
|
|
55
|
+
});
|
|
56
|
+
const results = await ((_a = strapi === null || strapi === void 0 ? void 0 : strapi.entityService) === null || _a === void 0 ? void 0 : _a.findMany(collectionType.uid, {
|
|
57
|
+
populate: '*',
|
|
58
|
+
filters: {
|
|
59
|
+
...transformedArgs.filters,
|
|
60
|
+
hasPage: { $eq: true },
|
|
61
|
+
page: { ...transformedpageArgs.filters }
|
|
62
|
+
},
|
|
63
|
+
sort: transformedArgs.sort,
|
|
64
|
+
start: start,
|
|
65
|
+
limit: limit
|
|
66
|
+
}));
|
|
67
|
+
const entityResponse = toEntityResponseCollection(results || [], {
|
|
68
|
+
args: transformedArgs,
|
|
69
|
+
resourceUID: collectionType.uid
|
|
70
|
+
});
|
|
71
|
+
const entityResponsePaginated = paginationValidation_1.Pagination.getPaginationInfo(transformedpageArgs, transformedArgs, start, args.pagination.pageSize, entityResponse, collectionType.uid);
|
|
72
|
+
return entityResponsePaginated;
|
|
73
|
+
};
|
|
74
|
+
const results = await getPage();
|
|
75
|
+
if (((_a = Object.values(results)) === null || _a === void 0 ? void 0 : _a.filter(Boolean).length) > 0) {
|
|
76
|
+
return results;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
throw new Error(ctx.koaContext.response.message);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
Query: Object.assign({}, ...pageQuery)
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
const resolversConfig = () => {
|
|
90
|
+
const configQuery = collectionTypes.map((collectionType) => {
|
|
91
|
+
return {
|
|
92
|
+
[`Query.get${collectionType.type}Pages`]: {
|
|
93
|
+
auth: false
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
return Object.assign({}, ...configQuery);
|
|
98
|
+
};
|
|
99
|
+
return {
|
|
100
|
+
typeDefs: typeDefs(),
|
|
101
|
+
resolvers: resolvers(strapi),
|
|
102
|
+
resolversConfig: resolversConfig()
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
exports.default = getPageInfoFromUID;
|