@kohanajs/mod-cms
Advanced tools
Comparing version 2.1.0 to 2.3.0
const { ControllerAdmin } = require('@kohanajs/mod-admin'); | ||
const { KohanaJS, ORM } = require('kohanajs'); | ||
const { ControllerMixinDatabase, ControllerMixinView, KohanaJS, ORM } = require('kohanajs'); | ||
const ControllerAdminContent = KohanaJS.require('controller/admin/Content'); | ||
const Page = ORM.require('Page'); | ||
const PageType = ORM.require('PageType'); | ||
@@ -11,7 +13,7 @@ class ControllerAdminPage extends ControllerAdmin { | ||
databases: new Map([ | ||
['pagetype', `${KohanaJS.config.auth.databasePath}/pagetype.sqlite`], | ||
['draft', `${KohanaJS.config.auth.databasePath}/content.sqlite`], | ||
['live', `${KohanaJS.config.auth.databasePath}/www/content.sqlite`] | ||
['pagetype', `${KohanaJS.config.cms.databasePath}/pagetype.sqlite`], | ||
['draft', `${KohanaJS.config.cms.databasePath}/content.sqlite`], | ||
['live', `${KohanaJS.config.cms.databasePath}/www/content.sqlite`], | ||
]), | ||
database: 'pagetype', | ||
database: 'draft', | ||
}); | ||
@@ -21,19 +23,50 @@ } | ||
async action_update() { | ||
//if publish state change from 0 to 1, | ||
//a live version of | ||
// 1. page attributes, | ||
// 2. page values, | ||
// 3. page Items + Page Item values, | ||
// 4. page Blocks, block attribute, block values | ||
// will be cloned to live database | ||
//if no param id, create page proxy | ||
const database = this.state.get(ControllerMixinDatabase.DATABASES).get('draft'); | ||
const pageTypeDB = this.state.get(ControllerMixinDatabase.DATABASES).get('pagetype'); | ||
const instance = this.state.get('instance'); | ||
if(!instance)return; | ||
const pageType = await ORM.factory(PageType, instance.page_type_id, {database: pageTypeDB}) | ||
await ControllerAdminContent.defaultValue(instance, pageType.name.toLowerCase(), database); | ||
} | ||
async action_index() { | ||
async setEditTemplate(){ | ||
const templateData = this.state.get(ControllerMixinView.TEMPLATE).data; | ||
const database = this.state.get(ControllerMixinDatabase.DATABASES).get('pagetype'); | ||
const draftDB = this.state.get(ControllerMixinDatabase.DATABASES).get('draft'); | ||
const page = this.state.get('instance'); | ||
const pagetypes = await ORM.readAll(PageType, {database, asArray:true}); | ||
templateData.pagetypes = pagetypes; | ||
pagetypes.forEach(it => { | ||
if(it.id === page.page_type_id)page.page_type = it; | ||
}); | ||
await page.eagerLoad({ | ||
with:["PageValue", "PageAttribute", "PageItem"], | ||
page_items: {with:['PageItemValue']} | ||
}); | ||
templateData.values = ControllerAdminContent.arrayToObject(page.page_values); | ||
templateData.attributes = ControllerAdminContent.arrayToObject(page.page_attributes); | ||
templateData.items = ControllerAdminContent.itemsToObject(page.page_items); | ||
templateData.blocks = ControllerAdminContent.blocksToObject(page.blocks); | ||
const editTemplateFolder = page.page_type?.name ?? 'default'; | ||
this.setTemplate(`templates/admin/page/page_types/${editTemplateFolder.toLowerCase()}/edit`, templateData); | ||
} | ||
async action_create(){ | ||
await this.setEditTemplate(); | ||
} | ||
async action_read() { | ||
await this.setEditTemplate(); | ||
} | ||
async action_edit(){ | ||
await this.setEditTemplate(); | ||
} | ||
} | ||
module.exports = ControllerAdminPage; |
11
init.js
@@ -0,1 +1,7 @@ | ||
const {KohanaJS} = require('kohanajs') | ||
KohanaJS.initConfig(new Map([ | ||
['cms', require('./config/cms')], | ||
])); | ||
const { RouteList } = require('@kohanajs/mod-route'); | ||
const { HelperCRUD: RouteCRUD } = require('@kohanajs/mod-admin'); | ||
@@ -16,1 +22,6 @@ | ||
RouteCRUD.add('pages', 'controller/admin/Page'); | ||
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/contents/page-add-item/:page_id/:item_name', 'controller/admin/Content', 'page_add_item'); | ||
RouteList.add('/admin/contents/page-delete-item/:item_id', 'controller/admin/Content', 'page_delete_item'); |
{ | ||
"name": "@kohanajs/mod-cms", | ||
"version": "2.1.0", | ||
"version": "2.3.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
55470
46
1434