@kohanajs/mod-cms
Advanced tools
Comparing version 5.1.0 to 5.2.0
@@ -5,2 +5,15 @@ # Changelog | ||
## [5.2.0](https://gitlab.com/kohana-js/proposals/level0/mod-cms/compare/v5.1.0...v5.2.0) (2022-02-17) | ||
### Features | ||
* draft database and simplify live database ([0a46686](https://gitlab.com/kohana-js/proposals/level0/mod-cms/commit/0a46686183db4253c63d59d3b8bc03fbdac23555)) | ||
* simple live page data ([c2adeb4](https://gitlab.com/kohana-js/proposals/level0/mod-cms/commit/c2adeb454a72ea9126b8a8f44591b885af1b32b0)) | ||
### Bug Fixes | ||
* language database live access, route loading ([230194c](https://gitlab.com/kohana-js/proposals/level0/mod-cms/commit/230194c900236de375eaa5dfeebc252e9e3a678e)) | ||
## [5.1.0](https://gitlab.com/kohana-js/proposals/level0/mod-cms/compare/v5.0.0...v5.1.0) (2022-02-16) | ||
@@ -7,0 +20,0 @@ |
@@ -10,2 +10,3 @@ const { ControllerMixin } = require('@kohanajs/core-mvc'); | ||
static DATABASE_NAME = 'languageDatabaseName'; | ||
static DATABASE = 'languageDatabase'; | ||
@@ -24,3 +25,3 @@ static init(state){ | ||
if(!databaseMap.get(databaseName)){ | ||
databaseMap.set(databaseName, KohanaJS.config.cms.databasePath + '/' + databaseName + '.sqlite') | ||
databaseMap.set(databaseName, KohanaJS.config.cms.databasePath + '/www/' + databaseName + '.sqlite') | ||
} | ||
@@ -32,4 +33,4 @@ } | ||
const database = state.get(ControllerMixinDatabase.DATABASES).get(state.get(this.DATABASE_NAME)); | ||
state.set(this.DATABASE, database); | ||
console.log(state.get(ControllerMixinDatabase.DATABASES)); | ||
const language = await ORM.readBy(Language, 'code', [ client.language ], {database, limit:1 }); | ||
@@ -36,0 +37,0 @@ state.set(this.LANGUAGE_ID, language.id); |
const {SQL} = require('@kohanajs/constants'); | ||
const {ControllerMixinDatabase, KohanaJS, ORM} = require("kohanajs"); | ||
const {ControllerAdmin} = require("@kohanajs/mod-admin"); | ||
const ControllerMixinPageLanguage = require('../../controller-mixin/PageLanguage'); | ||
@@ -10,2 +9,3 @@ const Page = ORM.require('Page'); | ||
const ControllerMixinPageLanguage = require('../../controller-mixin/PageLanguage'); | ||
const Base = ControllerAdmin.mixin([ControllerMixinPageLanguage], ControllerAdmin); | ||
@@ -18,3 +18,3 @@ | ||
databases: new Map([ | ||
['draft', `${KohanaJS.config.cms.databasePath}/content.sqlite`], | ||
['draft', `${KohanaJS.config.cms.databasePath}/content-draft.sqlite`], | ||
]), | ||
@@ -21,0 +21,0 @@ database: 'draft', |
@@ -17,3 +17,3 @@ const path = require('path'); | ||
databases: new Map([ | ||
['draft', `${KohanaJS.EXE_PATH}/../database/content.sqlite`], | ||
['draft', `${KohanaJS.config.cms.databasePath}/content-draft.sqlite`], | ||
]), | ||
@@ -20,0 +20,0 @@ orderBy: new Map([['weight', 'ASC'], ['created_at', 'DESC']]), |
@@ -12,2 +12,4 @@ const {SQL} = require("@kohanajs/constants"); | ||
const Page = ORM.require('Page'); | ||
const PageAttribute = ORM.require('PageAttribute'); | ||
const PageValue = ORM.require('PageValue'); | ||
@@ -21,2 +23,5 @@ const PageItem = ORM.require('PageItem'); | ||
const PageBlockItemValue = ORM.require('PageBlockItemValue'); | ||
const PageText = ORM.require('PageText'); | ||
const PageKeyword = ORM.require('PageKeyword'); | ||
const Language = ORM.require('Language'); | ||
@@ -31,3 +36,3 @@ const ControllerMixinPageLanguage = require('../../controller-mixin/PageLanguage'); | ||
databases: new Map([ | ||
['draft', `${KohanaJS.config.cms.databasePath}/content.sqlite`], | ||
['draft', `${KohanaJS.config.cms.databasePath}/content-draft.sqlite`], | ||
['live', `${KohanaJS.config.cms.databasePath}/www/content.sqlite`], | ||
@@ -105,5 +110,82 @@ ]), | ||
async createVersion(pageId){ | ||
//create version | ||
const version = { | ||
attributes:{}, | ||
values:{}, | ||
items:{}, | ||
blocks:[] | ||
} | ||
const keywords = []; | ||
const database = this.state.get(ControllerMixinDatabase.DATABASES).get('draft'); | ||
const languages = await ORM.readAll(Language, {database: this.state.get(ControllerMixinPageLanguage.DATABASE)}); | ||
const languageIdMap = new Map(); | ||
const i18nValue = {} | ||
languages.forEach(it=> { | ||
i18nValue[it.code] = {}; | ||
languageIdMap.set(it.id, it.code); | ||
}); | ||
const i18nValueJSON = JSON.stringify(i18nValue); | ||
Object.assign(version.values, JSON.parse(i18nValueJSON)); | ||
const assignValue = (obj, it) => { | ||
if(!it.value)return; | ||
obj[(!!it.attribute_name) ? `${it.name}@${it.attribute_name}` : it.name] = it.value; | ||
} | ||
const assignItem = (obj, its, prop) => { | ||
its.forEach(it => { | ||
obj.items[it.name] = obj.items[it.name] || []; | ||
const item = JSON.parse(i18nValueJSON); | ||
obj.items[it.name].push(item); | ||
it[prop].forEach(x => assignValue(item[languageIdMap.get(x.language_id)], x)) | ||
}) | ||
} | ||
//add attribute to version | ||
const attributes = await ORM.readBy(PageAttribute, 'page_id', [pageId], {database, asArray:true}); | ||
attributes.forEach(it => assignValue(version.attributes, it)); | ||
//add values to version | ||
const values = await ORM.readBy(PageValue, 'page_id', [pageId], {database, asArray:true}); | ||
values.forEach(it => assignValue(version.values[languageIdMap.get(it.language_id)], it)) | ||
//add items to version | ||
const items = await ORM.readBy(PageItem, 'page_id', [pageId], {database, asArray: true}); | ||
await ORM.eagerLoad(items, {with:["PageItemValue"]}, {database}); | ||
assignItem(version, items, 'page_item_values'); | ||
//add blocks to version | ||
const blocks = await ORM.readBy(PageBlock, 'page_id', [pageId], {database, asArray: true}); | ||
await ORM.eagerLoad(blocks, { | ||
with:["PageBlockAttribute", "PageBlockValue", "PageBlockItem"], | ||
page_block_items: {with: ['PageBlockItemValue']} | ||
}, {database}); | ||
blocks.forEach(it=>{ | ||
const block = { | ||
name: it.name, | ||
attributes:{}, | ||
values:JSON.parse(i18nValueJSON), | ||
items: {} | ||
} | ||
//block attribute | ||
it.page_block_attributes.forEach(x => assignValue(block.attributes, x)); | ||
//block values | ||
it.page_block_values.forEach(x => assignValue(block.values[languageIdMap.get(x.language_id)], x)); | ||
//block items | ||
assignItem(block, it.page_block_items, 'page_block_item_values'); | ||
version.blocks.push(block); | ||
}); | ||
return { | ||
version, | ||
keywords | ||
}; | ||
} | ||
async publish(page){ | ||
//create version. | ||
//ORM.create(PageVersion, ) | ||
const database = this.state.get(ControllerMixinDatabase.DATABASES).get('live'); | ||
@@ -115,39 +197,25 @@ | ||
//create live page with page.id | ||
const livePage = ORM.create(Page, {database, insertID: page.id}); | ||
const pageFields = {...page}; | ||
//remove page field id | ||
delete pageFields.id; | ||
Object.assign(livePage, pageFields); | ||
await livePage.write(); | ||
await page.eagerLoad( | ||
{ | ||
with:["PageAttribute", "PageValue", "PageItem", "PageBlock"], | ||
page_items: {with:["PageItemValue"]}, | ||
page_blocks: {with: ["PageBlockAttribute", "PageBlockValue"]} | ||
} | ||
) | ||
//copy from tables | ||
await this.copyToLive(ORM.require('PageAttribute'), page.page_attributes, database); | ||
await this.copyToLive(ORM.require('PageValue'), page.page_values, database); | ||
//create version. | ||
const {version, keywords} = await this.createVersion(page.id); | ||
console.log(JSON.stringify(version, null, 2)); | ||
if(page.page_items){ | ||
await this.copyToLive(ORM.require('PageItem'), page.page_items, database); | ||
await Promise.all( | ||
page.page_items.map(async item =>{ | ||
await this.copyToLive(ORM.require('PageItemValue'), item.page_item_values, database); | ||
}) | ||
) | ||
} | ||
const livePageBody = ORM.create(PageText, {database}); | ||
livePageBody.text = version; | ||
livePageBody.page_id = page.id; | ||
await livePageBody.write(); | ||
if(page.page_blocks){ | ||
await this.copyToLive(ORM.require('PageBlock'), page.page_blocks, database); | ||
await Promise.all( | ||
page.page_blocks.map(async block =>{ | ||
await this.copyToLive(ORM.require('PageBlockAttribute'), block.page_block_attributes, database); | ||
await this.copyToLive(ORM.require('PageBlockValue'), block.page_block_values, database); | ||
}) | ||
) | ||
} | ||
await Promise.all(keywords.map(async it => { | ||
const keyword = ORM.create(PageKeyword, {database}); | ||
keyword.page_id = page.id; | ||
Object.assign(keyword, it); | ||
await keyword.write(); | ||
})); | ||
} | ||
@@ -154,0 +222,0 @@ |
@@ -14,3 +14,3 @@ const {ControllerMixinDatabase, ControllerMixinView, KohanaJS, ORM} = require("kohanajs"); | ||
databases: new Map([ | ||
['draft', `${KohanaJS.config.cms.databasePath}/content.sqlite`], | ||
['draft', `${KohanaJS.config.cms.databasePath}/content-draft.sqlite`], | ||
['tag', `${KohanaJS.config.cms.databasePath}/www/tag.sqlite`], | ||
@@ -17,0 +17,0 @@ ]), |
@@ -5,3 +5,3 @@ const { KohanaJS } = require('kohanajs'); | ||
databasePath: `${KohanaJS.EXE_PATH}/../database`, | ||
databasePath: `${KohanaJS.APP_PATH}/../database`, | ||
defaultLanguage: 'en', | ||
@@ -8,0 +8,0 @@ blueprint: { |
32
index.js
require('kohanajs').addNodeModule(__dirname); | ||
const { RouteList } = require('@kohanajs/mod-route'); | ||
const { HelperCRUD: RouteCRUD } = require('@kohanajs/mod-admin'); | ||
const ControllerAdminPage = require('./classes/controller/admin/Page'); | ||
const ControllerAdminContent = require('./classes/controller/admin/Content'); | ||
const ControllerAdminTag = require('./classes/controller/admin/Tag'); | ||
const ControllerMixinPageLanguage = require('./classes/controller-mixin/PageLanguage'); | ||
const HelperPage = require('./classes/helper/Page'); | ||
@@ -8,2 +14,28 @@ module.exports = { | ||
ControllerAdminContent, | ||
ControllerAdminTag, | ||
ControllerMixinPageLanguage, | ||
HelperPage, | ||
routes : { | ||
apply: ()=>{ | ||
RouteList.add('/admin/pages/add-block/:page_id/:block_name', 'controller/admin/Page', 'add_block'); | ||
RouteList.add('/admin/pages/delete-block/:block_id', 'controller/admin/Page', 'delete_block'); | ||
RouteList.add('/admin/pages/add-block-item/:block_id/:item_name', 'controller/admin/Page', 'add_block_item'); | ||
RouteList.add('/admin/pages/delete-block-item/:item_id', 'controller/admin/Page', 'delete_block_item'); | ||
RouteList.add('/admin/pages/add-item/:page_id/:item_name', 'controller/admin/Page', 'add_item'); | ||
RouteList.add('/admin/pages/delete-item/:item_id', 'controller/admin/Page', 'delete_item'); | ||
RouteList.add('/admin/pages/un-publish/:id', 'controller/admin/Page', 'unpublish'); | ||
RouteList.add('/admin/contents/list/:page_type', 'controller/admin/Content'); | ||
RouteList.add('/admin/contents/create/:page_type', 'controller/admin/Content', 'create_by_type'); | ||
RouteList.add('/admin/api/page-items/:page_type/:item', 'controller/admin/API', 'page_items'); | ||
RouteList.add('/admin/api/pages/:page_type', 'controller/admin/API', 'pages'); | ||
RouteList.add('/admin/api', 'controller/admin/API'); | ||
RouteCRUD.add('pages', 'controller/admin/Page'); | ||
RouteCRUD.add('tag_types', 'controller/admin/TagType'); | ||
RouteCRUD.add('tags', 'controller/admin/Tag'); | ||
} | ||
} | ||
}; |
24
init.js
@@ -5,25 +5,1 @@ const {KohanaJS} = require('kohanajs') | ||
])); | ||
const { RouteList } = require('@kohanajs/mod-route'); | ||
const { HelperCRUD: RouteCRUD } = require('@kohanajs/mod-admin'); | ||
RouteList.add('/admin/pages/add-block/:page_id/:block_name', 'controller/admin/Page', 'add_block'); | ||
RouteList.add('/admin/pages/delete-block/:block_id', 'controller/admin/Page', 'delete_block'); | ||
RouteList.add('/admin/pages/add-block-item/:block_id/:item_name', 'controller/admin/Page', 'add_block_item'); | ||
RouteList.add('/admin/pages/delete-block-item/:item_id', 'controller/admin/Page', 'delete_block_item'); | ||
RouteList.add('/admin/pages/add-item/:page_id/:item_name', 'controller/admin/Page', 'add_item'); | ||
RouteList.add('/admin/pages/delete-item/:item_id', 'controller/admin/Page', 'delete_item'); | ||
RouteList.add('/admin/pages/un-publish/:id', 'controller/admin/Page', 'unpublish'); | ||
RouteList.add('/admin/contents/list/:page_type', 'controller/admin/Content'); | ||
RouteList.add('/admin/contents/create/:page_type', 'controller/admin/Content', 'create_by_type'); | ||
RouteList.add('/admin/api/page-items/:page_type/:item', 'controller/admin/API', 'page_items'); | ||
RouteList.add('/admin/api/pages/:page_type', 'controller/admin/API', 'pages'); | ||
RouteList.add('/admin/api', 'controller/admin/API'); | ||
RouteCRUD.add('pages', 'controller/admin/Page'); | ||
RouteCRUD.add('tag_types', 'controller/admin/TagType'); | ||
RouteCRUD.add('tags', 'controller/admin/Tag'); |
{ | ||
"name": "@kohanajs/mod-cms", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "The CMS module for KohanaJS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55351
33
1277