@opengis/cms 0.0.57 → 0.0.58
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 +131 -131
- package/dist/AddNewItemInTree-05PSSEFi.js +76 -0
- package/dist/ArticlesPage-CFjE_cw_.js +298 -0
- package/dist/CollectionsBreadcrumb-BCxeRikP.js +4 -0
- package/dist/CollectionsBreadcrumb.vue_vue_type_script_setup_true_lang-umRzB5mY.js +53 -0
- package/dist/CollectionsPage-DHfPNql6.js +124 -0
- package/dist/{CreateForm-BMOBeP4G.js → CreateForm-5FvT45vH.js} +1 -1
- package/dist/Dashboard-C1eGscNd.js +358 -0
- package/dist/EditCollectionPage-DIr1tdtn.js +187 -0
- package/dist/{EmptyData-DaZt_nAm.js → EmptyData-DxPrSXhV.js} +1 -1
- package/dist/{MenuAddPage-Bf48Z-ah.js → MenuAddPage-D-p3gFgm.js} +40 -35
- package/dist/MenuBody-rN5j4YBu.js +125 -0
- package/dist/MenuItemPage-BoJw885D.js +1027 -0
- package/dist/MenuList-DFEBS0NB.js +172 -0
- package/dist/MenuPage-BCZB_S8j.js +107 -0
- package/dist/MenuWrapper-AZ_8s-zd.js +12 -0
- package/dist/MonacoEditor-Db-3Jc3E.js +4 -0
- package/dist/{UniversalTable.vue_vue_type_script_setup_true_lang-CJGTsd1V.js → UniversalTable-CzqPG-tY.js} +12 -12
- package/dist/{UniversalTablePagination.vue_vue_type_script_setup_true_lang-GYZd_gkA.js → UniversalTablePagination-4gL47A7I.js} +1 -1
- package/dist/VsFormTags-CMjiu9sY.js +114 -0
- package/dist/VsPreview-DwETkOpb.js +63 -0
- package/dist/contentForm-CtMhQTG0.js +489 -0
- package/dist/getField-CpwVE28P.js +179 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.html +29 -29
- package/dist/index.js +72 -71
- package/dist/style.css +1 -1
- package/dist/vs-builder-edit-D-q1o8tF.js +604 -0
- package/dist/vs-builder-monaco-B3Jj0V31.js +33 -0
- package/dist/vs-builder-preview-BH4VAM3a.js +44 -0
- package/dist/vs-form-custom-datatable-BDZo48w3.js +317 -0
- package/dist/vs-form-integer-BZ855R3g.js +61 -0
- package/dist/vs-form-media-select-NY27EaG1.js +837 -0
- package/dist/vs-form-reference-list-Dtv8fJJU.js +1536 -0
- package/dist/vs-form-reletion-link-BhzNQszm.js +34 -0
- package/dist/vs-form-tiptap-DDFQjRjY.js +4 -0
- package/dist/vs-form-tiptap.vue_vue_type_script_setup_true_lang-DGgsqXwg.js +11 -0
- package/dist/vs-richtext-md-C098v_6Q.js +4 -0
- package/dist/vs-richtext-md.vue_vue_type_script_setup_true_lang-Ct8uTV-J.js +14 -0
- package/input-types.json +9 -9
- package/locales/en.json +815 -814
- package/locales/uk.json +813 -812
- package/module/cms/cls/content.status.json +17 -17
- package/module/cms/cls/user_type.json +9 -9
- package/module/cms/form/admin.users.form.json +77 -77
- package/module/cms/select/cms.page_type.sql +1 -1
- package/module/cms/select/news_tag_id.sql +11 -11
- package/module/cms/table/admin.users.table.json +53 -53
- package/module/cms/table/collection.default.table.json +96 -96
- package/module/cms/table/single.default.table.json +116 -116
- package/package.json +68 -68
- package/plugin.js +43 -43
- package/server/app.js +35 -35
- package/server/config.js +4 -4
- package/server/functions/getContent.js +45 -45
- package/server/functions/getDraftKey.js +22 -22
- package/server/functions/getSearchData.js +31 -31
- package/server/functions/getTags.js +30 -30
- package/server/functions/getUser.js +27 -27
- package/server/functions/utils/mock.reply.js +55 -55
- package/server/index.js +22 -22
- package/server/migrations/fixes.sql +129 -129
- package/server/migrations/site.sql +595 -595
- package/server/plugins/adminHook.js +78 -78
- package/server/plugins/hook.js +59 -59
- package/server/plugins/vite.js +75 -75
- package/server/routes/category/controllers/cms.category.delete.js +21 -21
- package/server/routes/category/controllers/cms.category.get.js +17 -17
- package/server/routes/category/controllers/cms.category.list.js +16 -16
- package/server/routes/category/controllers/cms.category.post.js +21 -21
- package/server/routes/category/controllers/cms.category.put.js +23 -23
- package/server/routes/category/index.mjs +22 -22
- package/server/routes/cms/controllers/cmsStat.js +55 -55
- package/server/routes/cms/controllers/cmsSuggest.js +57 -57
- package/server/routes/cms/controllers/deleteContent.js +113 -113
- package/server/routes/cms/controllers/deleteMedia.js +76 -76
- package/server/routes/cms/controllers/downloadMedia.js +84 -84
- package/server/routes/cms/controllers/getContent.js +113 -113
- package/server/routes/cms/controllers/getContentBySlug.js +93 -93
- package/server/routes/cms/controllers/insertContent.js +217 -217
- package/server/routes/cms/controllers/listMedia.js +155 -155
- package/server/routes/cms/controllers/metadataMedia.js +39 -39
- package/server/routes/cms/controllers/properties.get.js +18 -18
- package/server/routes/cms/controllers/properties.post.js +99 -99
- package/server/routes/cms/controllers/searchContent.js +214 -214
- package/server/routes/cms/controllers/translate.js +89 -89
- package/server/routes/cms/controllers/updateContent.js +266 -266
- package/server/routes/cms/controllers/uploadMedia.js +79 -79
- package/server/routes/cms/functions/getSettings.js +48 -48
- package/server/routes/cms/index.mjs +112 -112
- package/server/routes/cms/utils/additionalData.js +35 -35
- package/server/routes/cms/utils/getCollection.js +89 -89
- package/server/routes/cms/utils/getSingle.js +188 -188
- package/server/routes/cms/utils/inputTypes.js +5 -5
- package/server/routes/cms/utils/insertContentLocalization.js +104 -104
- package/server/routes/cms/utils/requestTranslation.js +85 -85
- package/server/routes/cms/utils/updateLocalization.js +47 -47
- package/server/routes/cmsSpace/controllers/deleteSpace.js +25 -25
- package/server/routes/cmsSpace/controllers/getSpaces.js +27 -27
- package/server/routes/cmsSpace/controllers/insertSpace.js +21 -21
- package/server/routes/cmsSpace/controllers/updateSpace.js +23 -23
- package/server/routes/cmsSpace/index.mjs +20 -20
- package/server/routes/contentType/controllers/addContentType.js +160 -160
- package/server/routes/contentType/controllers/contentTypeList.js +54 -54
- package/server/routes/contentType/controllers/delContentType.js +75 -75
- package/server/routes/contentType/controllers/editContentType.js +88 -88
- package/server/routes/contentType/controllers/getContentType.js +65 -65
- package/server/routes/contentType/index.mjs +35 -35
- package/server/routes/contentType/utils/updateContents.js +44 -44
- package/server/routes/contentType/utils/updateCustomContentTable.js +53 -53
- package/server/routes/feedback/controllers/email.list.js +24 -24
- package/server/routes/feedback/controllers/feedback.js +48 -48
- package/server/routes/feedback/controllers/feedback.list.js +37 -37
- package/server/routes/feedback/controllers/news.subscriptions.js +44 -44
- package/server/routes/feedback/index.mjs +71 -71
- package/server/routes/logs/controllers/export.user.logs.js +77 -77
- package/server/routes/logs/controllers/user.logs.js +44 -44
- package/server/routes/logs/index.mjs +9 -9
- package/server/routes/menu/controllers/addMenu.js +37 -37
- package/server/routes/menu/controllers/delMenu.js +31 -31
- package/server/routes/menu/controllers/editMenu.js +41 -41
- package/server/routes/menu/controllers/getMenu.js +24 -24
- package/server/routes/menu/functions/getMenu.js +50 -50
- package/server/routes/menu/index.mjs +13 -13
- package/server/routes/migration/controllers/collectionToCustom.js +137 -137
- package/server/routes/migration/index.mjs +8 -8
- package/server/routes/root.mjs +8 -8
- package/server/routes/tags/controllers/add.tags.js +24 -24
- package/server/routes/tags/controllers/del.tags.js +19 -19
- package/server/routes/tags/controllers/edit.tags.js +25 -25
- package/server/routes/tags/controllers/get.tags.js +15 -15
- package/server/routes/tags/index.mjs +14 -14
- package/server/templates/cls/cms.category_type.json +9 -9
- package/server/templates/cls/cms.content_review_status.json +9 -9
- package/server/templates/cls/cms.content_status.json +9 -9
- package/server/templates/cls/cms.content_type.json +9 -9
- package/server/templates/cls/cms.lang.json +9 -9
- package/server/templates/page/login.html +126 -126
- package/utils.d.ts +52 -52
- package/utils.js +8 -8
- package/dist/ArticlesPage-BcR1hbds.js +0 -286
- package/dist/BuilderPage-CK_osM89.js +0 -386
- package/dist/CollectionsBreadcrumb.vue_vue_type_script_setup_true_lang-CnOe9ORD.js +0 -45
- package/dist/CollectionsPage-JfmrHNR_.js +0 -110
- package/dist/EditCollectionPage-Cw3GQYRe.js +0 -809
- package/dist/MenuItemPage-CXn5HC8j.js +0 -1366
- package/dist/MenuPage-tJZtK46W.js +0 -106
- package/dist/contentForm-B6gHgGkz.js +0 -586
- package/dist/getField-Y5WXnRR0.js +0 -2948
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
import { dataUpdate, dataDelete, pgClients } from '@opengis/fastify-table/utils.js';
|
|
2
|
-
|
|
3
|
-
export default async function builderDelete({ pg = pgClients.client, user = {}, params = {} }, reply) {
|
|
4
|
-
if (!params.id) {
|
|
5
|
-
return reply.status(400).send('not enough params: id');
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (!pg?.pk?.['site.content_types']) {
|
|
9
|
-
return reply.status(404).send('table not found');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const { cid, table, title, type } = await pg.query(
|
|
13
|
-
`select content_type_id as cid, table_name as table, title, type from site.content_types where $1 in (content_type_id, name)`,
|
|
14
|
-
[params.id],
|
|
15
|
-
).then(el => el.rows?.[0] || {});
|
|
16
|
-
|
|
17
|
-
if (!cid) {
|
|
18
|
-
return reply.status(404).send('content type not found');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (cid === 'pages') {
|
|
22
|
-
return reply.status(403).send('access restricted: pages content type cannot be deleted');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// await pg.query('delete from site.content_data where content_id in (select content_id from site.contents where content_type_id=$1)', [cid]);
|
|
26
|
-
// await pg.query('delete from site.contents where content_type_id=$1', [cid]);
|
|
27
|
-
|
|
28
|
-
if (table) {
|
|
29
|
-
// await pg.query(`drop table if exists data."${table}"`);
|
|
30
|
-
if (pg?.pk && false) {
|
|
31
|
-
delete pg.pk[`data."${table}"`];
|
|
32
|
-
pg.tlist = pg.tlist.filter(el => el !== `data."${table}"`);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// await pg.query('delete from site.content_data where content_id in (select content_id from site.contents where content_type_id=$1)', [cid])
|
|
36
|
-
|
|
37
|
-
// await pg.query('delete from site.contents where content_type_id=$1', [cid]);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// cascade
|
|
41
|
-
const contentIds = await pg.query('select array_agg(content_id) from site.contents where content_type_id=$1 and title<>$2', [cid, title])
|
|
42
|
-
.then(el => el.rows?.[0]?.array_agg || []);
|
|
43
|
-
|
|
44
|
-
if (contentIds.length) {
|
|
45
|
-
// await pg.query('delete from site.content_data where content_id=any($1)', [contentIds]);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (type === 'collection' && table) {
|
|
49
|
-
const count = await pg.query(`select count(*)::int from data."${table}"`).then(el => el.rows?.[0]?.count || 0);
|
|
50
|
-
if (count === 0) {
|
|
51
|
-
await pg.query('delete from site.contents where content_type_id=$1', [cid]);
|
|
52
|
-
const res = await dataDelete({
|
|
53
|
-
pg,
|
|
54
|
-
table: 'site.content_types',
|
|
55
|
-
id: cid,
|
|
56
|
-
uid: user?.uid
|
|
57
|
-
});
|
|
58
|
-
// await pg.query(`drop table if exists data."${table}"`);
|
|
59
|
-
return { id: cid, rows: [res].filter(Boolean) };
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// console.log('archived', cid, contentIds);
|
|
64
|
-
const res = await dataUpdate({
|
|
65
|
-
pg,
|
|
66
|
-
table: 'site.content_types',
|
|
67
|
-
id: cid,
|
|
68
|
-
data: {
|
|
69
|
-
status: 'archived',
|
|
70
|
-
},
|
|
71
|
-
uid: user?.uid
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
return { id: cid, rows: [res].filter(Boolean) };
|
|
75
|
-
}
|
|
1
|
+
import { dataUpdate, dataDelete, pgClients } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
export default async function builderDelete({ pg = pgClients.client, user = {}, params = {} }, reply) {
|
|
4
|
+
if (!params.id) {
|
|
5
|
+
return reply.status(400).send('not enough params: id');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (!pg?.pk?.['site.content_types']) {
|
|
9
|
+
return reply.status(404).send('table not found');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const { cid, table, title, type } = await pg.query(
|
|
13
|
+
`select content_type_id as cid, table_name as table, title, type from site.content_types where $1 in (content_type_id, name)`,
|
|
14
|
+
[params.id],
|
|
15
|
+
).then(el => el.rows?.[0] || {});
|
|
16
|
+
|
|
17
|
+
if (!cid) {
|
|
18
|
+
return reply.status(404).send('content type not found');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (cid === 'pages') {
|
|
22
|
+
return reply.status(403).send('access restricted: pages content type cannot be deleted');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// await pg.query('delete from site.content_data where content_id in (select content_id from site.contents where content_type_id=$1)', [cid]);
|
|
26
|
+
// await pg.query('delete from site.contents where content_type_id=$1', [cid]);
|
|
27
|
+
|
|
28
|
+
if (table) {
|
|
29
|
+
// await pg.query(`drop table if exists data."${table}"`);
|
|
30
|
+
if (pg?.pk && false) {
|
|
31
|
+
delete pg.pk[`data."${table}"`];
|
|
32
|
+
pg.tlist = pg.tlist.filter(el => el !== `data."${table}"`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// await pg.query('delete from site.content_data where content_id in (select content_id from site.contents where content_type_id=$1)', [cid])
|
|
36
|
+
|
|
37
|
+
// await pg.query('delete from site.contents where content_type_id=$1', [cid]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// cascade
|
|
41
|
+
const contentIds = await pg.query('select array_agg(content_id) from site.contents where content_type_id=$1 and title<>$2', [cid, title])
|
|
42
|
+
.then(el => el.rows?.[0]?.array_agg || []);
|
|
43
|
+
|
|
44
|
+
if (contentIds.length) {
|
|
45
|
+
// await pg.query('delete from site.content_data where content_id=any($1)', [contentIds]);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (type === 'collection' && table) {
|
|
49
|
+
const count = await pg.query(`select count(*)::int from data."${table}"`).then(el => el.rows?.[0]?.count || 0);
|
|
50
|
+
if (count === 0) {
|
|
51
|
+
await pg.query('delete from site.contents where content_type_id=$1', [cid]);
|
|
52
|
+
const res = await dataDelete({
|
|
53
|
+
pg,
|
|
54
|
+
table: 'site.content_types',
|
|
55
|
+
id: cid,
|
|
56
|
+
uid: user?.uid
|
|
57
|
+
});
|
|
58
|
+
// await pg.query(`drop table if exists data."${table}"`);
|
|
59
|
+
return { id: cid, rows: [res].filter(Boolean) };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// console.log('archived', cid, contentIds);
|
|
64
|
+
const res = await dataUpdate({
|
|
65
|
+
pg,
|
|
66
|
+
table: 'site.content_types',
|
|
67
|
+
id: cid,
|
|
68
|
+
data: {
|
|
69
|
+
status: 'archived',
|
|
70
|
+
},
|
|
71
|
+
uid: user?.uid
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return { id: cid, rows: [res].filter(Boolean) };
|
|
75
|
+
}
|
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import { dataInsert, dataUpdate, pgClients, getTemplate } from '@opengis/fastify-table/utils.js';
|
|
2
|
-
|
|
3
|
-
import updateCustomContentTable from '../utils/updateCustomContentTable.js';
|
|
4
|
-
import updateContents from '../utils/updateContents.js';
|
|
5
|
-
|
|
6
|
-
export default async function builderPut(req, reply) {
|
|
7
|
-
const { pg = pgClients.client, body = {}, params = {}, user = {} } = req;
|
|
8
|
-
if (!params.id) {
|
|
9
|
-
return reply.status(400).send('not enough params: id');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (!pg?.pk?.['site.content_types']) {
|
|
13
|
-
return reply.status(404).send('table not found');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const single = await pg.query(
|
|
17
|
-
`select content_id as id, content_type_id, slug FROM site.contents
|
|
18
|
-
where $1 in (content_id, content_type_id, slug)`, [params.id]
|
|
19
|
-
).then(el => el.rows?.[0]);
|
|
20
|
-
|
|
21
|
-
const customCtExists = await pg.query(
|
|
22
|
-
`select 1 FROM site.content_types
|
|
23
|
-
where content_type_id=$1`, [params.id]
|
|
24
|
-
).then(el => el.rowCount || 0);
|
|
25
|
-
|
|
26
|
-
const { cid, table } = await pg.query(
|
|
27
|
-
`select content_type_id as cid, table_name as table, type from site.content_types where $1 in (content_type_id, name)`,
|
|
28
|
-
[params.id],
|
|
29
|
-
).then(el => el.rows?.[0] || {});
|
|
30
|
-
|
|
31
|
-
if (!cid && !single) {
|
|
32
|
-
return reply.status(404).send('content type not found');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const columns = (body.fields || body.columns)?.filter?.(el => el.name)?.map?.(el => Object.assign(el, { name: el.name.toLowerCase() })); // for rest crud
|
|
36
|
-
|
|
37
|
-
const client = await pg.connect();
|
|
38
|
-
|
|
39
|
-
client.options = pg.options;
|
|
40
|
-
client.tlist = pg.tlist;
|
|
41
|
-
client.pgType = pg.pgType;
|
|
42
|
-
client.relkinds = pg.relkinds;
|
|
43
|
-
client.pk = pg.pk;
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
await client.query('begin');
|
|
47
|
-
|
|
48
|
-
const cid1 = cid || single?.content_type_id;
|
|
49
|
-
|
|
50
|
-
if (table) {
|
|
51
|
-
await updateCustomContentTable({ pg: client, id: cid1, columns });
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const name = body.name === 'pages' ? (single?.slug || params.id) : (body.name || body.slug);
|
|
55
|
-
|
|
56
|
-
// insert new,
|
|
57
|
-
if (single && !customCtExists && (single?.content_type_id === 'pages' || single?.content_type_id === params.id)) {
|
|
58
|
-
// const loadTable = await getTemplate('table', 'single.default.table');
|
|
59
|
-
// const { columns: defaultColumns } = loadTable || {};
|
|
60
|
-
await dataInsert({
|
|
61
|
-
pg,
|
|
62
|
-
table: 'site.content_types',
|
|
63
|
-
id: params.id,
|
|
64
|
-
data: { ...body, type: 'single', name /*, columns: defaultColumns */ },
|
|
65
|
-
uid: user?.uid,
|
|
66
|
-
});
|
|
67
|
-
} else {
|
|
68
|
-
await dataUpdate({
|
|
69
|
-
pg: client,
|
|
70
|
-
table: 'site.content_types',
|
|
71
|
-
id: cid1,
|
|
72
|
-
data: { ...body, content_type_id: cid1, name },
|
|
73
|
-
uid: user?.uid,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const row = await updateContents(client, cid1, { ...body, slug: name }, user?.uid);
|
|
78
|
-
|
|
79
|
-
await client.query('commit');
|
|
80
|
-
|
|
81
|
-
return { id: row?.content_type_id, rows: [row].filter(Boolean) };
|
|
82
|
-
} catch (err) {
|
|
83
|
-
await client.query('rollback');
|
|
84
|
-
throw err;
|
|
85
|
-
} finally {
|
|
86
|
-
client.release();
|
|
87
|
-
}
|
|
88
|
-
}
|
|
1
|
+
import { dataInsert, dataUpdate, pgClients, getTemplate } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
import updateCustomContentTable from '../utils/updateCustomContentTable.js';
|
|
4
|
+
import updateContents from '../utils/updateContents.js';
|
|
5
|
+
|
|
6
|
+
export default async function builderPut(req, reply) {
|
|
7
|
+
const { pg = pgClients.client, body = {}, params = {}, user = {} } = req;
|
|
8
|
+
if (!params.id) {
|
|
9
|
+
return reply.status(400).send('not enough params: id');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (!pg?.pk?.['site.content_types']) {
|
|
13
|
+
return reply.status(404).send('table not found');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const single = await pg.query(
|
|
17
|
+
`select content_id as id, content_type_id, slug FROM site.contents
|
|
18
|
+
where $1 in (content_id, content_type_id, slug)`, [params.id]
|
|
19
|
+
).then(el => el.rows?.[0]);
|
|
20
|
+
|
|
21
|
+
const customCtExists = await pg.query(
|
|
22
|
+
`select 1 FROM site.content_types
|
|
23
|
+
where content_type_id=$1`, [params.id]
|
|
24
|
+
).then(el => el.rowCount || 0);
|
|
25
|
+
|
|
26
|
+
const { cid, table } = await pg.query(
|
|
27
|
+
`select content_type_id as cid, table_name as table, type from site.content_types where $1 in (content_type_id, name)`,
|
|
28
|
+
[params.id],
|
|
29
|
+
).then(el => el.rows?.[0] || {});
|
|
30
|
+
|
|
31
|
+
if (!cid && !single) {
|
|
32
|
+
return reply.status(404).send('content type not found');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const columns = (body.fields || body.columns)?.filter?.(el => el.name)?.map?.(el => Object.assign(el, { name: el.name.toLowerCase() })); // for rest crud
|
|
36
|
+
|
|
37
|
+
const client = await pg.connect();
|
|
38
|
+
|
|
39
|
+
client.options = pg.options;
|
|
40
|
+
client.tlist = pg.tlist;
|
|
41
|
+
client.pgType = pg.pgType;
|
|
42
|
+
client.relkinds = pg.relkinds;
|
|
43
|
+
client.pk = pg.pk;
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
await client.query('begin');
|
|
47
|
+
|
|
48
|
+
const cid1 = cid || single?.content_type_id;
|
|
49
|
+
|
|
50
|
+
if (table) {
|
|
51
|
+
await updateCustomContentTable({ pg: client, id: cid1, columns });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const name = body.name === 'pages' ? (single?.slug || params.id) : (body.name || body.slug);
|
|
55
|
+
|
|
56
|
+
// insert new,
|
|
57
|
+
if (single && !customCtExists && (single?.content_type_id === 'pages' || single?.content_type_id === params.id)) {
|
|
58
|
+
// const loadTable = await getTemplate('table', 'single.default.table');
|
|
59
|
+
// const { columns: defaultColumns } = loadTable || {};
|
|
60
|
+
await dataInsert({
|
|
61
|
+
pg,
|
|
62
|
+
table: 'site.content_types',
|
|
63
|
+
id: params.id,
|
|
64
|
+
data: { ...body, type: 'single', name /*, columns: defaultColumns */ },
|
|
65
|
+
uid: user?.uid,
|
|
66
|
+
});
|
|
67
|
+
} else {
|
|
68
|
+
await dataUpdate({
|
|
69
|
+
pg: client,
|
|
70
|
+
table: 'site.content_types',
|
|
71
|
+
id: cid1,
|
|
72
|
+
data: { ...body, content_type_id: cid1, name },
|
|
73
|
+
uid: user?.uid,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const row = await updateContents(client, cid1, { ...body, slug: name }, user?.uid);
|
|
78
|
+
|
|
79
|
+
await client.query('commit');
|
|
80
|
+
|
|
81
|
+
return { id: row?.content_type_id, rows: [row].filter(Boolean) };
|
|
82
|
+
} catch (err) {
|
|
83
|
+
await client.query('rollback');
|
|
84
|
+
throw err;
|
|
85
|
+
} finally {
|
|
86
|
+
client.release();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import { pgClients, getTemplate } from '@opengis/fastify-table/utils.js';
|
|
2
|
-
|
|
3
|
-
export default async function builderGet({ pg = pgClients.client, params = {} }, reply) {
|
|
4
|
-
if (!params.id) {
|
|
5
|
-
return reply.status(400).send('not enough params: id');
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (!pg?.pk?.['site.content_types']) {
|
|
9
|
-
return reply.status(404).send('table not found');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const single = await pg.query(
|
|
13
|
-
`select content_id as id, * FROM site.contents
|
|
14
|
-
where $1 in (content_id, content_type_id, slug)`, [params.id]
|
|
15
|
-
).then(el => el.rows?.[0]);
|
|
16
|
-
|
|
17
|
-
// new ? 1 : 2
|
|
18
|
-
const isNew = single && single.content_type_id === params.id;
|
|
19
|
-
const row = isNew
|
|
20
|
-
? await pg.query(
|
|
21
|
-
`select content_type_id as id, * FROM site.content_types
|
|
22
|
-
where $1 in (content_type_id, name)`, [params.id]
|
|
23
|
-
).then(el => el.rows?.[0])
|
|
24
|
-
: await pg.query(`SELECT content_type_id as id, * FROM site.content_types WHERE content_type_id in (select content_type_id from site.contents where content_id=$1) limit 1`, [params.id]).then(el => el.rows?.[0]);
|
|
25
|
-
|
|
26
|
-
if (!isNew && single.content_type_id === 'pages') {
|
|
27
|
-
Object.assign(row, { id: params.id, type: 'single', title: single.title || params.id, content_type_id: params.id, name: single.slug || params.id });
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (single && !row) {
|
|
31
|
-
const loadTable = await getTemplate('table', 'single.default.table');
|
|
32
|
-
const { columns: defaultColumns } = loadTable || {};
|
|
33
|
-
(defaultColumns || []).forEach(col => Object.assign(col, { default: true }));
|
|
34
|
-
const columns = (defaultColumns || []).filter(col => !col.hidden);
|
|
35
|
-
return reply.status(200).send({ default: true, id: single.id, name: single.slug, type: 'single', ...single, columns });
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (!row) {
|
|
39
|
-
return reply.status(404).send('content type not found');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const space = await pg.query(
|
|
43
|
-
'select name, default_locale, locales from site.spaces where space_id = $1', ['default'],
|
|
44
|
-
).then(el => el.rows?.[0] || {});
|
|
45
|
-
Object.assign(row, { space });
|
|
46
|
-
|
|
47
|
-
// const loadTable = params.id === 'pages' ? await getTemplate('table', 'single.default.table') : {};
|
|
48
|
-
// const columns = params.id === 'pages' ? loadTable?.columns : row.columns;
|
|
49
|
-
|
|
50
|
-
const loadTable = params.id === 'pages'
|
|
51
|
-
? await getTemplate('table', 'single.default.table')
|
|
52
|
-
: await getTemplate('table', 'collection.default.table');
|
|
53
|
-
const { columns: defaultColumns = [] } = loadTable || {};
|
|
54
|
-
defaultColumns.forEach(col => Object.assign(col, { default: true }));
|
|
55
|
-
const columns = (defaultColumns || []).concat((row.columns || []).filter(col => !defaultColumns.map(el => el.name).includes(col.name)));
|
|
56
|
-
|
|
57
|
-
Object.assign(row, { columns });
|
|
58
|
-
|
|
59
|
-
// filter system / hidden
|
|
60
|
-
if (Array.isArray(row.columns)) {
|
|
61
|
-
row.columns.filter(col => !col.hidden);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return reply.status(200).send(row);
|
|
65
|
-
}
|
|
1
|
+
import { pgClients, getTemplate } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
export default async function builderGet({ pg = pgClients.client, params = {} }, reply) {
|
|
4
|
+
if (!params.id) {
|
|
5
|
+
return reply.status(400).send('not enough params: id');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (!pg?.pk?.['site.content_types']) {
|
|
9
|
+
return reply.status(404).send('table not found');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const single = await pg.query(
|
|
13
|
+
`select content_id as id, * FROM site.contents
|
|
14
|
+
where $1 in (content_id, content_type_id, slug)`, [params.id]
|
|
15
|
+
).then(el => el.rows?.[0]);
|
|
16
|
+
|
|
17
|
+
// new ? 1 : 2
|
|
18
|
+
const isNew = single && single.content_type_id === params.id;
|
|
19
|
+
const row = isNew
|
|
20
|
+
? await pg.query(
|
|
21
|
+
`select content_type_id as id, * FROM site.content_types
|
|
22
|
+
where $1 in (content_type_id, name)`, [params.id]
|
|
23
|
+
).then(el => el.rows?.[0])
|
|
24
|
+
: await pg.query(`SELECT content_type_id as id, * FROM site.content_types WHERE content_type_id in (select content_type_id from site.contents where content_id=$1) limit 1`, [params.id]).then(el => el.rows?.[0]);
|
|
25
|
+
|
|
26
|
+
if (!isNew && single.content_type_id === 'pages') {
|
|
27
|
+
Object.assign(row, { id: params.id, type: 'single', title: single.title || params.id, content_type_id: params.id, name: single.slug || params.id });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (single && !row) {
|
|
31
|
+
const loadTable = await getTemplate('table', 'single.default.table');
|
|
32
|
+
const { columns: defaultColumns } = loadTable || {};
|
|
33
|
+
(defaultColumns || []).forEach(col => Object.assign(col, { default: true }));
|
|
34
|
+
const columns = (defaultColumns || []).filter(col => !col.hidden);
|
|
35
|
+
return reply.status(200).send({ default: true, id: single.id, name: single.slug, type: 'single', ...single, columns });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!row) {
|
|
39
|
+
return reply.status(404).send('content type not found');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const space = await pg.query(
|
|
43
|
+
'select name, default_locale, locales from site.spaces where space_id = $1', ['default'],
|
|
44
|
+
).then(el => el.rows?.[0] || {});
|
|
45
|
+
Object.assign(row, { space });
|
|
46
|
+
|
|
47
|
+
// const loadTable = params.id === 'pages' ? await getTemplate('table', 'single.default.table') : {};
|
|
48
|
+
// const columns = params.id === 'pages' ? loadTable?.columns : row.columns;
|
|
49
|
+
|
|
50
|
+
const loadTable = params.id === 'pages'
|
|
51
|
+
? await getTemplate('table', 'single.default.table')
|
|
52
|
+
: await getTemplate('table', 'collection.default.table');
|
|
53
|
+
const { columns: defaultColumns = [] } = loadTable || {};
|
|
54
|
+
defaultColumns.forEach(col => Object.assign(col, { default: true }));
|
|
55
|
+
const columns = (defaultColumns || []).concat((row.columns || []).filter(col => !defaultColumns.map(el => el.name).includes(col.name)));
|
|
56
|
+
|
|
57
|
+
Object.assign(row, { columns });
|
|
58
|
+
|
|
59
|
+
// filter system / hidden
|
|
60
|
+
if (Array.isArray(row.columns)) {
|
|
61
|
+
row.columns.filter(col => !col.hidden);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return reply.status(200).send(row);
|
|
65
|
+
}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import getContentType from './controllers/getContentType.js';
|
|
2
|
-
import contentTypeList from './controllers/contentTypeList.js';
|
|
3
|
-
import editContentType from './controllers/editContentType.js';
|
|
4
|
-
import addContentType from './controllers/addContentType.js';
|
|
5
|
-
import delContentType from './controllers/delContentType.js';
|
|
6
|
-
|
|
7
|
-
const params = { config: { policy: ['public'] } };
|
|
8
|
-
|
|
9
|
-
export default async function route(app) {
|
|
10
|
-
const schema = {
|
|
11
|
-
params: {
|
|
12
|
-
type: 'object',
|
|
13
|
-
properties: {
|
|
14
|
-
id: {
|
|
15
|
-
type: 'string'
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
body: {
|
|
20
|
-
type: 'object',
|
|
21
|
-
required: ['name'],
|
|
22
|
-
properties: {
|
|
23
|
-
name: { type: 'string' }
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
app.get('/cms', params, contentTypeList);
|
|
29
|
-
app.get('/cms-type', params, contentTypeList);
|
|
30
|
-
|
|
31
|
-
app.post('/cms-type', { ...params, schema }, addContentType);
|
|
32
|
-
app.put('/cms-type/:id', { ...params, schema }, editContentType);
|
|
33
|
-
app.get('/cms-type/:id', params, getContentType);
|
|
34
|
-
app.delete('/cms-type/:id', params, delContentType);
|
|
35
|
-
}
|
|
1
|
+
import getContentType from './controllers/getContentType.js';
|
|
2
|
+
import contentTypeList from './controllers/contentTypeList.js';
|
|
3
|
+
import editContentType from './controllers/editContentType.js';
|
|
4
|
+
import addContentType from './controllers/addContentType.js';
|
|
5
|
+
import delContentType from './controllers/delContentType.js';
|
|
6
|
+
|
|
7
|
+
const params = { config: { policy: ['public'] } };
|
|
8
|
+
|
|
9
|
+
export default async function route(app) {
|
|
10
|
+
const schema = {
|
|
11
|
+
params: {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
id: {
|
|
15
|
+
type: 'string'
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
body: {
|
|
20
|
+
type: 'object',
|
|
21
|
+
required: ['name'],
|
|
22
|
+
properties: {
|
|
23
|
+
name: { type: 'string' }
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
app.get('/cms', params, contentTypeList);
|
|
29
|
+
app.get('/cms-type', params, contentTypeList);
|
|
30
|
+
|
|
31
|
+
app.post('/cms-type', { ...params, schema }, addContentType);
|
|
32
|
+
app.put('/cms-type/:id', { ...params, schema }, editContentType);
|
|
33
|
+
app.get('/cms-type/:id', params, getContentType);
|
|
34
|
+
app.delete('/cms-type/:id', params, delContentType);
|
|
35
|
+
}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { dataInsert, dataUpdate } from "@opengis/fastify-table/utils.js";
|
|
2
|
-
|
|
3
|
-
export default async function updateContents(pg, id, data, uid) {
|
|
4
|
-
if (!pg?.pk || !id) return null;
|
|
5
|
-
|
|
6
|
-
const single = await pg.query(
|
|
7
|
-
`select 1 from site.contents where content_id=$1`,
|
|
8
|
-
[id],
|
|
9
|
-
).then(el => el.rowCount || 0);
|
|
10
|
-
|
|
11
|
-
if (single) {
|
|
12
|
-
const result = await dataUpdate({
|
|
13
|
-
pg,
|
|
14
|
-
table: 'site.contents',
|
|
15
|
-
id,
|
|
16
|
-
data,
|
|
17
|
-
uid,
|
|
18
|
-
});
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const contentId = await pg.query(
|
|
23
|
-
`select content_id from site.contents where content_type_id = $1 order by content_id=content_type_id desc limit 1`, // update pages collection, avoid singles
|
|
24
|
-
[id],
|
|
25
|
-
).then(el => el.rows?.[0]?.content_id);
|
|
26
|
-
|
|
27
|
-
if (contentId) {
|
|
28
|
-
const result = await dataUpdate({
|
|
29
|
-
pg,
|
|
30
|
-
id: data?.type === 'single' ? id : contentId,
|
|
31
|
-
table: 'site.contents',
|
|
32
|
-
data,
|
|
33
|
-
uid,
|
|
34
|
-
});
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const result = await dataInsert({
|
|
39
|
-
pg,
|
|
40
|
-
table: 'site.contents',
|
|
41
|
-
data: { ...data || {}, content_type_id: id },
|
|
42
|
-
uid,
|
|
43
|
-
}).then(el => el.rows?.[0]);
|
|
44
|
-
return result;
|
|
1
|
+
import { dataInsert, dataUpdate } from "@opengis/fastify-table/utils.js";
|
|
2
|
+
|
|
3
|
+
export default async function updateContents(pg, id, data, uid) {
|
|
4
|
+
if (!pg?.pk || !id) return null;
|
|
5
|
+
|
|
6
|
+
const single = await pg.query(
|
|
7
|
+
`select 1 from site.contents where content_id=$1`,
|
|
8
|
+
[id],
|
|
9
|
+
).then(el => el.rowCount || 0);
|
|
10
|
+
|
|
11
|
+
if (single) {
|
|
12
|
+
const result = await dataUpdate({
|
|
13
|
+
pg,
|
|
14
|
+
table: 'site.contents',
|
|
15
|
+
id,
|
|
16
|
+
data,
|
|
17
|
+
uid,
|
|
18
|
+
});
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const contentId = await pg.query(
|
|
23
|
+
`select content_id from site.contents where content_type_id = $1 order by content_id=content_type_id desc limit 1`, // update pages collection, avoid singles
|
|
24
|
+
[id],
|
|
25
|
+
).then(el => el.rows?.[0]?.content_id);
|
|
26
|
+
|
|
27
|
+
if (contentId) {
|
|
28
|
+
const result = await dataUpdate({
|
|
29
|
+
pg,
|
|
30
|
+
id: data?.type === 'single' ? id : contentId,
|
|
31
|
+
table: 'site.contents',
|
|
32
|
+
data,
|
|
33
|
+
uid,
|
|
34
|
+
});
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const result = await dataInsert({
|
|
39
|
+
pg,
|
|
40
|
+
table: 'site.contents',
|
|
41
|
+
data: { ...data || {}, content_type_id: id },
|
|
42
|
+
uid,
|
|
43
|
+
}).then(el => el.rows?.[0]);
|
|
44
|
+
return result;
|
|
45
45
|
}
|