fixed
This commit is contained in:
1 parent
4194cef934
commit
363127fe9e
3350 files changed
+1284220
-1
No files matched your search
@@ -0,0 +1,231 @@
|
||||
/**
|
||||
* Declarative schemas for every admin CRUD resource.
|
||||
*
|
||||
* Column types: id | lang | text | image | date | bool | number
|
||||
* Field types: lang | lang-textarea | lang-richtext | text | textarea | image | date | select
|
||||
*
|
||||
* Endpoints follow the backend envelope { status, message, code, data }
|
||||
* where list payloads are { <listKey>: [...], count: N }.
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
window.Resources = {
|
||||
categories: {
|
||||
title: "Categories",
|
||||
endpoint: "/v1/admin/categories",
|
||||
listKey: "categories",
|
||||
searchable: true,
|
||||
statusToggle: true,
|
||||
columns: [
|
||||
{ key: "Id", label: "ID", type: "id", sortKey: "id" },
|
||||
{ key: "name", label: "Name", type: "lang" },
|
||||
{ key: "status", label: "Status", type: "bool", sortKey: "status" },
|
||||
{ key: "createdAt", label: "Created", type: "date", sortKey: "createdAt" },
|
||||
],
|
||||
fields: [
|
||||
{ name: "name", label: "Name", type: "lang", required: true },
|
||||
],
|
||||
buildPayload: (values, mode, record) => {
|
||||
if (mode === "edit") {
|
||||
return { name: values.name, status: record ? !!record.status : true };
|
||||
}
|
||||
return { name: values.name };
|
||||
},
|
||||
},
|
||||
|
||||
"sub-categories": {
|
||||
title: "Sub-categories",
|
||||
endpoint: "/v1/admin/sub-categories",
|
||||
listKey: "subCategory",
|
||||
searchable: true,
|
||||
statusToggle: true,
|
||||
// The list endpoint is scoped by category: GET /v1/admin/sub-categories/:categoryId
|
||||
parentFilter: {
|
||||
label: "Category",
|
||||
endpoint: "/v1/admin/categories",
|
||||
listKey: "categories",
|
||||
labelField: "name",
|
||||
},
|
||||
listUrl: (state) => "/v1/admin/sub-categories/" + state.parentId,
|
||||
getOneUrl: (id) => "/v1/admin/sub-categories/" + id + "/edit",
|
||||
columns: [
|
||||
{ key: "Id", label: "ID", type: "id", sortKey: "id" },
|
||||
{ key: "name", label: "Name", type: "lang" },
|
||||
{ key: "status", label: "Status", type: "bool", sortKey: "status" },
|
||||
{ key: "createdAt", label: "Created", type: "date", sortKey: "createdAt" },
|
||||
],
|
||||
fields: [
|
||||
{
|
||||
name: "categoryId",
|
||||
label: "Category",
|
||||
type: "select",
|
||||
required: true,
|
||||
options: {
|
||||
endpoint: "/v1/admin/categories",
|
||||
listKey: "categories",
|
||||
valueField: "Id",
|
||||
labelField: "name",
|
||||
},
|
||||
},
|
||||
{ name: "name", label: "Name", type: "lang", required: true },
|
||||
{ name: "content", label: "Content", type: "lang-richtext", required: true },
|
||||
],
|
||||
buildPayload: (values) => ({
|
||||
categoryId: Number(values.categoryId),
|
||||
name: values.name,
|
||||
content: values.content,
|
||||
}),
|
||||
},
|
||||
|
||||
banners: {
|
||||
title: "Banners",
|
||||
endpoint: "/v1/admin/banner",
|
||||
listKey: "banners",
|
||||
searchable: true,
|
||||
columns: [
|
||||
{ key: "Id", label: "ID", type: "id", sortKey: "id" },
|
||||
{ key: "imagePath", label: "Image", type: "image" },
|
||||
{ key: "title", label: "Title", type: "lang" },
|
||||
{ key: "createdAt", label: "Created", type: "date", sortKey: "createdAt" },
|
||||
],
|
||||
fields: [
|
||||
{ name: "title", label: "Title", type: "lang", required: true },
|
||||
{
|
||||
name: "content",
|
||||
label: "Content",
|
||||
type: "lang-richtext",
|
||||
flat: true, // stored as contentTm / contentRu / contentEn
|
||||
},
|
||||
{ name: "imagePath", label: "Image", type: "image", required: true },
|
||||
],
|
||||
buildPayload: (values) => ({
|
||||
title: values.title,
|
||||
contentTm: (values.content && values.content.tm) || "",
|
||||
contentRu: (values.content && values.content.ru) || "",
|
||||
contentEn: (values.content && values.content.en) || "",
|
||||
imagePath: values.imagePath,
|
||||
}),
|
||||
recordToValues: (record) => ({
|
||||
title: record.title,
|
||||
content: {
|
||||
tm: record.contentTm || "",
|
||||
ru: record.contentRu || "",
|
||||
en: record.contentEn || "",
|
||||
},
|
||||
imagePath: record.imagePath,
|
||||
}),
|
||||
},
|
||||
|
||||
news: {
|
||||
title: "News",
|
||||
endpoint: "/v1/admin/news",
|
||||
listKey: "news",
|
||||
searchable: true,
|
||||
columns: [
|
||||
{ key: "Id", label: "ID", type: "id", sortKey: "id" },
|
||||
{ key: "imagePath", label: "Image", type: "image" },
|
||||
{ key: "title", label: "Title", type: "lang" },
|
||||
{ key: "dateRelease", label: "Release date", type: "date", sortKey: "dateRelease" },
|
||||
],
|
||||
fields: [
|
||||
{ name: "title", label: "Title", type: "lang", required: true },
|
||||
{ name: "content", label: "Content", type: "lang-richtext", required: true },
|
||||
{ name: "imagePath", label: "Image", type: "image", required: true },
|
||||
{ name: "dateRelease", label: "Release date", type: "date", required: true },
|
||||
],
|
||||
buildPayload: (values) => ({
|
||||
title: values.title,
|
||||
content: values.content,
|
||||
imagePath: values.imagePath,
|
||||
dateRelease: values.dateRelease,
|
||||
}),
|
||||
},
|
||||
|
||||
static: {
|
||||
title: "Static pages",
|
||||
endpoint: "/v1/admin/static",
|
||||
listKey: "statics",
|
||||
searchable: true,
|
||||
columns: [
|
||||
{ key: "Id", label: "ID", type: "id", sortKey: "id" },
|
||||
{ key: "logo", label: "Logo", type: "image" },
|
||||
{ key: "title", label: "Title", type: "lang" },
|
||||
{ key: "createdAt", label: "Created", type: "date", sortKey: "createdAt" },
|
||||
],
|
||||
fields: [
|
||||
{ name: "logo", label: "Logo", type: "image", required: true },
|
||||
{ name: "title", label: "Title", type: "lang", required: true },
|
||||
{
|
||||
name: "content",
|
||||
label: "Content",
|
||||
type: "lang-richtext",
|
||||
flat: true, // stored as contentTm / contentRu / contentEn
|
||||
},
|
||||
],
|
||||
buildPayload: (values) => ({
|
||||
logo: values.logo,
|
||||
title: values.title,
|
||||
contentTm: (values.content && values.content.tm) || "",
|
||||
contentRu: (values.content && values.content.ru) || "",
|
||||
contentEn: (values.content && values.content.en) || "",
|
||||
}),
|
||||
/** Map a fetched record into form values. */
|
||||
recordToValues: (record) => ({
|
||||
logo: record.logo,
|
||||
title: record.title,
|
||||
content: {
|
||||
tm: record.contentTm || "",
|
||||
ru: record.contentRu || "",
|
||||
en: record.contentEn || "",
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
||||
currency: {
|
||||
title: "Currency",
|
||||
endpoint: "/v1/admin/currency",
|
||||
listKey: "currencies",
|
||||
searchable: true,
|
||||
columns: [
|
||||
{ key: "Id", label: "ID", type: "id", sortKey: "id" },
|
||||
{ key: "path", label: "Image", type: "image" },
|
||||
{ key: "title", label: "Title", type: "lang" },
|
||||
{ key: "createdAt", label: "Created", type: "date", sortKey: "createdAt" },
|
||||
],
|
||||
fields: [
|
||||
{ name: "path", label: "Image", type: "image", required: true },
|
||||
{ name: "title", label: "Title", type: "lang", required: true },
|
||||
{
|
||||
name: "content",
|
||||
label: "Content",
|
||||
type: "lang-richtext",
|
||||
flat: true, // stored as contentTm / contentRu / contentEn
|
||||
},
|
||||
],
|
||||
buildPayload: (values) => ({
|
||||
path: values.path,
|
||||
title: values.title,
|
||||
contentTm: (values.content && values.content.tm) || "",
|
||||
contentRu: (values.content && values.content.ru) || "",
|
||||
contentEn: (values.content && values.content.en) || "",
|
||||
}),
|
||||
recordToValues: (record) => ({
|
||||
path: record.path,
|
||||
title: record.title,
|
||||
content: {
|
||||
tm: record.contentTm || "",
|
||||
ru: record.contentRu || "",
|
||||
en: record.contentEn || "",
|
||||
},
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
/** Preferred display order for a multilingual value. */
|
||||
window.langText = function (value) {
|
||||
if (!value) return "";
|
||||
if (typeof value === "string") return value;
|
||||
return value.tm || value.ru || value.en || "";
|
||||
};
|
||||
})();
|
||||
Reference in new issue
Block a user