@raketa-cloud/admin 0.0.13 → 0.0.15
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/package.json +1 -1
- package/src/HonoAdapter.js +3 -0
- package/src/cloud/ArticleChanges.js +15 -0
- package/src/cloud/ArticleRevisions.js +152 -0
- package/src/cloud/Articles.js +133 -0
- package/src/cloud/documents/articlesDocuments.js +109 -469
- package/src/cloud/documents/common.js +10 -0
- package/src/handlers/article_revisions/ArticleRevisionsHandler.js +49 -0
- package/src/handlers/article_revisions/CodeHandler.js +90 -0
- package/src/handlers/article_revisions/GeneralHandler.js +95 -0
- package/src/handlers/article_revisions/LocksHandler.js +54 -0
- package/src/handlers/article_revisions/MetaHandler.js +90 -0
- package/src/handlers/article_revisions/PublishesHandler.js +90 -0
- package/src/handlers/article_revisions/RevertsHandler.js +28 -0
- package/src/handlers/article_revisions/TagHandler.js +89 -0
- package/src/handlers/article_revisions/UnlocksHandler.js +22 -0
- package/src/handlers/article_revisions/VisualHandler.js +84 -0
- package/src/handlers/article_revisions/WidgetHandler.js +47 -0
- package/src/handlers/articles/ArticlesHandler.js +119 -0
- package/src/handlers/articles/ClonesHandler.js +17 -0
- package/src/handlers/articles/DeletesHandler.js +68 -0
- package/src/handlers/articles/TranslationsHandler.js +103 -0
- package/src/handlers/articles/URLsHandler.js +71 -0
- package/src/handlers/pages/PagesHandler.js +4 -2
- package/src/handlers/pages/TranslationsHandler.js +7 -5
- package/src/index.js +22 -0
- package/src/routeArticles.js +65 -0
- package/src/routeStandard.js +2 -0
- package/src/setupCloud.js +12 -0
- package/src/tests/handlers/articles/ArticlesHandler.test/create.test.js +144 -0
- package/src/tests/handlers/articles/ArticlesHandler.test/create_form.test.js +41 -0
- package/src/tests/handlers/articles/ArticlesHandler.test/index.test.js +49 -0
- package/src/tests/handlers/articles/ArticlesHandler.test/show.test.js +105 -0
- package/src/tests/handlers/articles/ConesHandler.test/create.test.js +54 -0
- package/src/tests/handlers/articles/DeletesHandler.test/create.test.js +110 -0
- package/src/tests/handlers/articles/DeletesHandler.test/create_form.test.js +54 -0
- package/src/tests/handlers/articles/URLsHandler.test/create.test.js +155 -0
- package/src/tests/handlers/articles/URLsHandler.test/create_form.test.js +51 -0
- package/src/tests/handlers/pages/PagesHandler.test/create.test.js +3 -3
- package/src/utils.js +46 -0
- package/src/views/article_revisions/_nav.ejs +40 -0
- package/src/views/article_revisions/codes/edit_form.ejs +39 -0
- package/src/views/article_revisions/general/edit_form.ejs +70 -0
- package/src/views/article_revisions/locks/create_form.ejs +35 -0
- package/src/views/article_revisions/meta/edit_form.ejs +41 -0
- package/src/views/article_revisions/publishes/_form.ejs +57 -0
- package/src/views/article_revisions/publishes/create_form.ejs +10 -0
- package/src/views/article_revisions/tags/edit_form.ejs +64 -0
- package/src/views/article_revisions/visuals/edit_form.ejs +42 -0
- package/src/views/articles/_form.ejs +86 -0
- package/src/views/articles/create_form.ejs +9 -0
- package/src/views/articles/deletes/create_form.ejs +55 -0
- package/src/views/articles/edit_form.ejs +3 -0
- package/src/views/articles/index.ejs +161 -0
- package/src/views/articles/show.ejs +281 -0
- package/src/views/articles/translations/_form.ejs +77 -0
- package/src/views/articles/translations/create_form.ejs +11 -0
- package/src/views/articles/urls/create_form.ejs +31 -0
- package/src/views/layouts/application.ejs +41 -78
- package/src/views/page_revisions/locks/create_form.ejs +1 -1
- package/test/factory.js +37 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const create = async (ctx) => {
|
|
2
|
+
const { parent_id } = ctx.params;
|
|
3
|
+
|
|
4
|
+
const { errors, articleErrors } = await ctx.client.articleRevisions.create(
|
|
5
|
+
parent_id,
|
|
6
|
+
ctx.locale
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
if (errors) {
|
|
10
|
+
throw new Error(`Failed to start revision: ${JSON.stringify(errors)}`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (articleErrors) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
`Failed to start revision: ${JSON.stringify(articleErrors)}`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
redirect: `/${ctx.locale}/articles/${parent_id}`,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const destroy = async (ctx) => {
|
|
25
|
+
const { id } = ctx.params;
|
|
26
|
+
|
|
27
|
+
const { errors, revision } = await ctx.client.articleRevisions.delete(
|
|
28
|
+
id,
|
|
29
|
+
ctx.locale
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
if (errors) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`Failed to delete revision#${id}: ${JSON.stringify(errors)}`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
headers: {
|
|
40
|
+
"HX-Redirect": `/${ctx.locale}/articles/${revision.originalId}`,
|
|
41
|
+
},
|
|
42
|
+
json: {},
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export default {
|
|
47
|
+
destroy,
|
|
48
|
+
create,
|
|
49
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const edit_form = async (ctx) => {
|
|
2
|
+
const { parent_id } = ctx.params;
|
|
3
|
+
|
|
4
|
+
const revision = await ctx.client.articleRevisions.find(
|
|
5
|
+
parent_id,
|
|
6
|
+
ctx.locale
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
if (!revision) {
|
|
10
|
+
throw new Error(`Missing revision #${parent_id}`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const code_settings = {
|
|
14
|
+
id: revision.id,
|
|
15
|
+
originalId: revision.originalId,
|
|
16
|
+
scripts: JSON.stringify(revision.settings.codes?.scripts || []),
|
|
17
|
+
structured_data: JSON.stringify(
|
|
18
|
+
revision.settings.codes?.structured_data || {}
|
|
19
|
+
),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
assigns: {
|
|
24
|
+
code_settings,
|
|
25
|
+
errors: {},
|
|
26
|
+
_translations: [],
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const update = async (ctx) => {
|
|
32
|
+
const { parent_id } = ctx.params;
|
|
33
|
+
|
|
34
|
+
const revision = await ctx.client.articleRevisions.find(
|
|
35
|
+
parent_id,
|
|
36
|
+
ctx.locale
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
if (!revision) {
|
|
40
|
+
throw new Error(`Missing revision #${parent_id}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const params = ctx.resourceParams.code_settings;
|
|
44
|
+
|
|
45
|
+
const { errors } = await ctx.client.articleRevisions.update(
|
|
46
|
+
revision.id,
|
|
47
|
+
ctx.locale,
|
|
48
|
+
{
|
|
49
|
+
slug: revision.slug,
|
|
50
|
+
title: revision.title,
|
|
51
|
+
visibility: revision.visibility,
|
|
52
|
+
publishAt: revision.publishAt,
|
|
53
|
+
widgets: JSON.stringify(revision.widgets),
|
|
54
|
+
tags: revision.tags.map((t) => t.id),
|
|
55
|
+
categories: revision.categories.map((c) => c.id),
|
|
56
|
+
settings: JSON.stringify({
|
|
57
|
+
...revision.settings,
|
|
58
|
+
codes: {
|
|
59
|
+
scripts: JSON.parse(params.scripts),
|
|
60
|
+
structured_data: JSON.parse(params.structured_data),
|
|
61
|
+
},
|
|
62
|
+
}),
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
if (errors) {
|
|
67
|
+
return {
|
|
68
|
+
assigns: {
|
|
69
|
+
code_settings: {
|
|
70
|
+
...params,
|
|
71
|
+
id: revision.id,
|
|
72
|
+
originalId: revision.originalId,
|
|
73
|
+
},
|
|
74
|
+
errors: {
|
|
75
|
+
code_settings: ctx.client.articleRevisions.formatErrors(errors),
|
|
76
|
+
},
|
|
77
|
+
_translations: [],
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
redirect: `/${ctx.locale}/article_revisions/${revision.id}/codes/edit`,
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export default {
|
|
88
|
+
edit_form,
|
|
89
|
+
update,
|
|
90
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { toDateTimeInput, toUTCISO8601String } from "../../utils";
|
|
2
|
+
const edit_form = async (ctx) => {
|
|
3
|
+
const { parent_id } = ctx.params;
|
|
4
|
+
|
|
5
|
+
const revision = await ctx.client.articleRevisions.find(
|
|
6
|
+
parent_id,
|
|
7
|
+
ctx.locale
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
if (!revision) {
|
|
11
|
+
throw new Error(`Missing revision #${parent_id}`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const general_settings = {
|
|
15
|
+
id: revision.id,
|
|
16
|
+
originalId: revision.originalId,
|
|
17
|
+
title: revision.title,
|
|
18
|
+
slug: revision.slug,
|
|
19
|
+
publish_at: toDateTimeInput(revision.publishAt),
|
|
20
|
+
visibility: revision.visibility,
|
|
21
|
+
username: revision.settings?.credentials?.user || "",
|
|
22
|
+
password: revision.settings?.credentials?.password || "",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
assigns: {
|
|
27
|
+
general_settings,
|
|
28
|
+
errors: {},
|
|
29
|
+
visibilityOptions: ctx.client.articles.visibilityOptions(),
|
|
30
|
+
_translations: [],
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const update = async (ctx) => {
|
|
36
|
+
const { parent_id } = ctx.params;
|
|
37
|
+
|
|
38
|
+
const revision = await ctx.client.articleRevisions.find(
|
|
39
|
+
parent_id,
|
|
40
|
+
ctx.locale
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
if (!revision) {
|
|
44
|
+
throw new Error(`Missing revision #${parent_id}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const params = ctx.resourceParams.general_settings;
|
|
48
|
+
|
|
49
|
+
const { errors } = await ctx.client.articleRevisions.update(
|
|
50
|
+
revision.id,
|
|
51
|
+
ctx.locale,
|
|
52
|
+
{
|
|
53
|
+
slug: params.slug,
|
|
54
|
+
title: params.title,
|
|
55
|
+
visibility: params.visibility,
|
|
56
|
+
publishAt: toUTCISO8601String(params.publish_at),
|
|
57
|
+
widgets: JSON.stringify(revision.widgets),
|
|
58
|
+
tags: revision.tags.map((t) => t.id),
|
|
59
|
+
categories: revision.categories.map((c) => c.id),
|
|
60
|
+
settings: JSON.stringify({
|
|
61
|
+
...revision.settings,
|
|
62
|
+
credentials: {
|
|
63
|
+
user: params.username,
|
|
64
|
+
password: params.password,
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
if (errors) {
|
|
71
|
+
return {
|
|
72
|
+
assigns: {
|
|
73
|
+
general_settings: {
|
|
74
|
+
...params,
|
|
75
|
+
id: revision.id,
|
|
76
|
+
originalId: revision.originalId,
|
|
77
|
+
},
|
|
78
|
+
errors: {
|
|
79
|
+
general_settings: ctx.client.articleRevisions.formatErrors(errors),
|
|
80
|
+
},
|
|
81
|
+
visibilityOptions: ctx.client.articles.visibilityOptions(),
|
|
82
|
+
_translations: [],
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
redirect: `/${ctx.locale}/article_revisions/${revision.id}/general/edit`,
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export default {
|
|
93
|
+
edit_form,
|
|
94
|
+
update,
|
|
95
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const create_form = async (ctx) => {
|
|
2
|
+
const { parent_id } = ctx.params;
|
|
3
|
+
|
|
4
|
+
const revision = await ctx.client.articleRevisions.find(
|
|
5
|
+
parent_id,
|
|
6
|
+
ctx.locale
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
const lock_settings = {
|
|
10
|
+
revision,
|
|
11
|
+
message: "",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
assigns: {
|
|
16
|
+
lock_settings,
|
|
17
|
+
errors: {},
|
|
18
|
+
_translations: [],
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const create = async (ctx) => {
|
|
24
|
+
const { parent_id } = ctx.params;
|
|
25
|
+
const { message } = ctx.resourceParams.lock_settings;
|
|
26
|
+
|
|
27
|
+
const { revision, errors, articleErrors } =
|
|
28
|
+
await ctx.client.articleRevisions.lock(parent_id, ctx.locale, message);
|
|
29
|
+
|
|
30
|
+
if (errors) {
|
|
31
|
+
return {
|
|
32
|
+
assigns: {
|
|
33
|
+
lock_settings: { revision, message },
|
|
34
|
+
errors: {
|
|
35
|
+
lock_settings: ctx.client.articles.formatErrors(errors, "message"),
|
|
36
|
+
},
|
|
37
|
+
_translations: [],
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (articleErrors) {
|
|
43
|
+
throw `Failed to lock revisions: ${JSON.stringify(articleErrors)}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
redirect: `/${ctx.locale}/articles/${revision.originalId}`,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export default {
|
|
52
|
+
create_form,
|
|
53
|
+
create,
|
|
54
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const edit_form = async (ctx) => {
|
|
2
|
+
const { parent_id } = ctx.params;
|
|
3
|
+
|
|
4
|
+
const revision = await ctx.client.articleRevisions.find(
|
|
5
|
+
parent_id,
|
|
6
|
+
ctx.locale
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
if (!revision) {
|
|
10
|
+
throw new Error(`Missing revision #${parent_id}`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const meta_settings = {
|
|
14
|
+
id: revision.id,
|
|
15
|
+
originalId: revision.originalId,
|
|
16
|
+
title: revision.settings.meta?.title || "",
|
|
17
|
+
description: revision.settings.meta?.description || "",
|
|
18
|
+
image: revision.settings.meta?.image || {},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
assigns: {
|
|
23
|
+
meta_settings,
|
|
24
|
+
errors: {},
|
|
25
|
+
_translations: [],
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const update = async (ctx) => {
|
|
31
|
+
const { parent_id } = ctx.params;
|
|
32
|
+
|
|
33
|
+
const revision = await ctx.client.articleRevisions.find(
|
|
34
|
+
parent_id,
|
|
35
|
+
ctx.locale
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
if (!revision) {
|
|
39
|
+
throw new Error(`Missing revision #${parent_id}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const params = ctx.resourceParams.meta_settings;
|
|
43
|
+
|
|
44
|
+
const { errors } = await ctx.client.articleRevisions.update(
|
|
45
|
+
revision.id,
|
|
46
|
+
ctx.locale,
|
|
47
|
+
{
|
|
48
|
+
slug: revision.slug,
|
|
49
|
+
title: revision.title,
|
|
50
|
+
visibility: revision.visibility,
|
|
51
|
+
publishAt: revision.publishAt,
|
|
52
|
+
widgets: JSON.stringify(revision.widgets),
|
|
53
|
+
tags: revision.tags.map((t) => t.id),
|
|
54
|
+
categories: revision.categories.map((c) => c.id),
|
|
55
|
+
settings: JSON.stringify({
|
|
56
|
+
...revision.settings,
|
|
57
|
+
meta: {
|
|
58
|
+
title: params.title,
|
|
59
|
+
description: params.description,
|
|
60
|
+
image: JSON.parse(params.image),
|
|
61
|
+
},
|
|
62
|
+
}),
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
if (errors) {
|
|
67
|
+
return {
|
|
68
|
+
assigns: {
|
|
69
|
+
meta_settings: {
|
|
70
|
+
...params,
|
|
71
|
+
id: revision.id,
|
|
72
|
+
originalId: revision.originalId,
|
|
73
|
+
},
|
|
74
|
+
errors: {
|
|
75
|
+
meta_settings: ctx.client.articleRevisions.formatErrors(errors),
|
|
76
|
+
},
|
|
77
|
+
_translations: [],
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
redirect: `/${ctx.locale}/article_revisions/${revision.id}/meta/edit`,
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export default {
|
|
88
|
+
edit_form,
|
|
89
|
+
update,
|
|
90
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const create_form = async (ctx) => {
|
|
2
|
+
const { parent_id } = ctx.params;
|
|
3
|
+
|
|
4
|
+
const revision = await ctx.client.articleRevisions.find(
|
|
5
|
+
parent_id,
|
|
6
|
+
ctx.locale
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
return {
|
|
10
|
+
assigns: {
|
|
11
|
+
publishing: {
|
|
12
|
+
id: revision.id,
|
|
13
|
+
originalId: revision.originalId,
|
|
14
|
+
title: revision.meta.title,
|
|
15
|
+
description: revision.meta.description,
|
|
16
|
+
visibility: revision.visibility,
|
|
17
|
+
username: revision.settings?.credentials?.user,
|
|
18
|
+
password: revision.settings?.credentials?.password,
|
|
19
|
+
},
|
|
20
|
+
visibilityOptions: ctx.client.articles.visibilityOptions(),
|
|
21
|
+
errors: {},
|
|
22
|
+
_translations: [],
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function publishArticleParams(
|
|
28
|
+
{ visibility, username, password },
|
|
29
|
+
currentSettings
|
|
30
|
+
) {
|
|
31
|
+
if (visibility === "protected") {
|
|
32
|
+
const credentials = {
|
|
33
|
+
user: username,
|
|
34
|
+
password: password,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
visibility,
|
|
39
|
+
settings: JSON.stringify({
|
|
40
|
+
...currentSettings,
|
|
41
|
+
credentials,
|
|
42
|
+
}),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return { visibility };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const create = async (ctx) => {
|
|
50
|
+
const { parent_id } = ctx.params;
|
|
51
|
+
const publishing = ctx.resourceParams.publishing;
|
|
52
|
+
|
|
53
|
+
const revision = await ctx.client.articleRevisions.find(
|
|
54
|
+
parent_id,
|
|
55
|
+
ctx.locale
|
|
56
|
+
);
|
|
57
|
+
const { errors } = await ctx.client.articleRevisions.publish(
|
|
58
|
+
revision.id,
|
|
59
|
+
ctx.locale,
|
|
60
|
+
{
|
|
61
|
+
title: publishing.title || "",
|
|
62
|
+
description: publishing.description || "",
|
|
63
|
+
},
|
|
64
|
+
publishArticleParams(publishing, revision.settings)
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
if (errors) {
|
|
68
|
+
return {
|
|
69
|
+
assigns: {
|
|
70
|
+
publishing: {
|
|
71
|
+
...publishing,
|
|
72
|
+
id: revision.id,
|
|
73
|
+
originalId: revision.originalId,
|
|
74
|
+
},
|
|
75
|
+
visibilityOptions: ctx.client.articles.visibilityOptions(),
|
|
76
|
+
errors: ctx.client.articleRevisions.formatErrors(errors),
|
|
77
|
+
_translations: [],
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
redirect: `/${ctx.locale}/articles/${revision.originalId}`,
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export default {
|
|
88
|
+
create,
|
|
89
|
+
create_form,
|
|
90
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const create = async (ctx) => {
|
|
2
|
+
const { parent_id } = ctx.params;
|
|
3
|
+
const { version } = ctx.resourceParams;
|
|
4
|
+
|
|
5
|
+
const { errors, articleErrors } = await ctx.client.articleRevisions.revert(
|
|
6
|
+
parent_id,
|
|
7
|
+
Number.parseInt(version, 10),
|
|
8
|
+
ctx.locale
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
if (errors) {
|
|
12
|
+
throw new Error(`Failed to start revision: ${JSON.stringify(errors)}`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (articleErrors) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
`Failed to start revision: ${JSON.stringify(articleErrors)}`
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
redirect: `/${ctx.locale}/articles/${parent_id}`,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default {
|
|
27
|
+
create,
|
|
28
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const edit_form = async (ctx) => {
|
|
2
|
+
const { parent_id } = ctx.params;
|
|
3
|
+
|
|
4
|
+
const revision = await ctx.client.articleRevisions.find(
|
|
5
|
+
parent_id,
|
|
6
|
+
ctx.locale
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
if (!revision) {
|
|
10
|
+
throw new Error(`Missing revision #${parent_id}`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const tags = await ctx.client.tags.all(ctx.locale);
|
|
14
|
+
|
|
15
|
+
const tag_settings = {
|
|
16
|
+
id: revision.id,
|
|
17
|
+
originalId: revision.originalId,
|
|
18
|
+
tags: revision.tags.map((t) => t.id),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
assigns: {
|
|
23
|
+
tag_settings,
|
|
24
|
+
errors: {},
|
|
25
|
+
tags: tags.list,
|
|
26
|
+
_translations: [],
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const update = async (ctx) => {
|
|
32
|
+
const { parent_id } = ctx.params;
|
|
33
|
+
|
|
34
|
+
const revision = await ctx.client.articleRevisions.find(
|
|
35
|
+
parent_id,
|
|
36
|
+
ctx.locale
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
if (!revision) {
|
|
40
|
+
throw new Error(`Missing revision #${parent_id}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const params = ctx.resourceParams.tag_settings;
|
|
44
|
+
|
|
45
|
+
const { errors } = await ctx.client.articleRevisions.update(
|
|
46
|
+
revision.id,
|
|
47
|
+
ctx.locale,
|
|
48
|
+
{
|
|
49
|
+
slug: revision.slug,
|
|
50
|
+
title: revision.title,
|
|
51
|
+
visibility: revision.visibility,
|
|
52
|
+
publishAt: revision.publishAt,
|
|
53
|
+
widgets: JSON.stringify(revision.widgets),
|
|
54
|
+
tags: params.tags,
|
|
55
|
+
categories: revision.categories.map((c) => c.id),
|
|
56
|
+
settings: JSON.stringify({
|
|
57
|
+
...revision.settings,
|
|
58
|
+
}),
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
if (errors) {
|
|
63
|
+
const tags = await ctx.client.tags.all(ctx.locale);
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
assigns: {
|
|
67
|
+
tag_settings: {
|
|
68
|
+
...params,
|
|
69
|
+
id: revision.id,
|
|
70
|
+
originalId: revision.originalId,
|
|
71
|
+
},
|
|
72
|
+
errors: {
|
|
73
|
+
tag_settings: ctx.client.articleRevisions.formatErrors(errors),
|
|
74
|
+
},
|
|
75
|
+
tags: tags.list,
|
|
76
|
+
_translations: [],
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
redirect: `/${ctx.locale}/article_revisions/${revision.id}/tags/edit`,
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export default {
|
|
87
|
+
edit_form,
|
|
88
|
+
update,
|
|
89
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const create = async (ctx) => {
|
|
2
|
+
const { parent_id } = ctx.params;
|
|
3
|
+
|
|
4
|
+
const { revision, errors, articleErrors } =
|
|
5
|
+
await ctx.client.articleRevisions.unlock(parent_id, ctx.locale);
|
|
6
|
+
|
|
7
|
+
if (errors) {
|
|
8
|
+
throw new Error(`Failed to unlock revision: ${JSON.stringify(errors)}`);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (articleErrors) {
|
|
12
|
+
throw `Failed to start revision: ${JSON.stringify(articleErrors)}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
redirect: `/${ctx.locale}/articles/${revision.originalId}`,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default {
|
|
21
|
+
create,
|
|
22
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const edit_form = async (ctx) => {
|
|
2
|
+
const { parent_id } = ctx.params;
|
|
3
|
+
|
|
4
|
+
const revision = await ctx.client.articleRevisions.find(
|
|
5
|
+
parent_id,
|
|
6
|
+
ctx.locale
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
if (!revision) {
|
|
10
|
+
throw new Error(`Missing revision #${parent_id}`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const visual_settings = {
|
|
14
|
+
id: revision.id,
|
|
15
|
+
originalId: revision.originalId,
|
|
16
|
+
layout: revision.settings.layout,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
assigns: {
|
|
21
|
+
visual_settings,
|
|
22
|
+
errors: {},
|
|
23
|
+
_translations: [],
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const update = async (ctx) => {
|
|
29
|
+
const { parent_id } = ctx.params;
|
|
30
|
+
|
|
31
|
+
const revision = await ctx.client.articleRevisions.find(
|
|
32
|
+
parent_id,
|
|
33
|
+
ctx.locale
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
if (!revision) {
|
|
37
|
+
throw new Error(`Missing revision #${parent_id}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const params = ctx.resourceParams.visual_settings;
|
|
41
|
+
|
|
42
|
+
const { errors } = await ctx.client.articleRevisions.update(
|
|
43
|
+
revision.id,
|
|
44
|
+
ctx.locale,
|
|
45
|
+
{
|
|
46
|
+
slug: revision.slug,
|
|
47
|
+
title: revision.title,
|
|
48
|
+
visibility: revision.visibility,
|
|
49
|
+
publishAt: revision.publishAt,
|
|
50
|
+
widgets: JSON.stringify(revision.widgets),
|
|
51
|
+
tags: revision.tags.map((t) => t.id),
|
|
52
|
+
categories: revision.categories.map((c) => c.id),
|
|
53
|
+
settings: JSON.stringify({
|
|
54
|
+
...revision.settings,
|
|
55
|
+
layout: params.layout,
|
|
56
|
+
}),
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
if (errors) {
|
|
61
|
+
return {
|
|
62
|
+
assigns: {
|
|
63
|
+
visual_settings: {
|
|
64
|
+
...params,
|
|
65
|
+
id: revision.id,
|
|
66
|
+
originalId: revision.originalId,
|
|
67
|
+
},
|
|
68
|
+
errors: {
|
|
69
|
+
visual_settings: ctx.client.articleRevisions.formatErrors(errors),
|
|
70
|
+
},
|
|
71
|
+
_translations: [],
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
redirect: `/${ctx.locale}/article_revisions/${revision.id}/visuals/edit`,
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export default {
|
|
82
|
+
edit_form,
|
|
83
|
+
update,
|
|
84
|
+
};
|