@kohanajs/mod-cms
Advanced tools
Comparing version 3.0.0 to 3.1.0
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. | ||
## [Unreleased] | ||
### accept tags: Added, Changed, Removed, Deprecated, Removed, Fixed, Security | ||
## 3.1.0 (2021-10-29) | ||
### Features | ||
* publish ([a38c6d4](https://gitlab.com/kohana-js/proposals/level0/mod-cms/commit/a38c6d473bc4fcb80a1b85b4e88ffddae238cd71)) | ||
* unpublish ([3c5ed30](https://gitlab.com/kohana-js/proposals/level0/mod-cms/commit/3c5ed30051da3fd9ea120cb5cc261a32f220e243)) | ||
## [3.0.0] - 2021-09-08 | ||
@@ -11,0 +14,0 @@ ### Change |
const {SQL} = require("@kohanajs/constants"); | ||
const {ControllerMixinDatabase, ControllerMixinView, ORMAdapter, KohanaJS, ORM} = require("kohanajs"); | ||
const { ControllerMixinMultipartForm } = require('@kohanajs/mod-form'); | ||
const {ControllerAdmin} = require("@kohanajs/mod-admin"); | ||
@@ -12,3 +11,2 @@ const Page = ORM.require('Page'); | ||
const PageItemValue = ORM.require('PageItemValue'); | ||
const Language = ORM.require('Language'); | ||
const pluralize = require('pluralize'); | ||
@@ -286,17 +284,2 @@ | ||
/* | ||
* { | ||
* job_description: [{ | ||
* body : object, | ||
* link: { | ||
* attributes: { | ||
* label : object, | ||
* url: object | ||
* } | ||
* } | ||
* }], | ||
* | ||
* } | ||
* */ | ||
await Promise.all( | ||
@@ -303,0 +286,0 @@ Object.keys(content.items).map(async item_name => { |
@@ -45,2 +45,9 @@ const { ControllerAdmin } = require('@kohanajs/mod-admin'); | ||
const $_POST = this.state.get(ControllerMixinMultipartForm.POST_DATA); | ||
switch ($_POST['action']) { | ||
case "publish": | ||
await this.publish(instance); | ||
break; | ||
default: | ||
} | ||
const destination = $_POST.destination || `/admin/pages/${instance.id}?language=${this.language}`; | ||
@@ -50,2 +57,78 @@ await this.redirect(destination); | ||
async copyToLive(Model, sources, database){ | ||
if(!sources) return; | ||
return Promise.all( | ||
sources.map(async (item) =>{ | ||
if(item.value === null || item.value === "")return; | ||
const live = ORM.create(Model, {database, insertID: item.id}); | ||
const draft = {...item}; | ||
delete draft.id; | ||
Object.assign(live, draft); | ||
await live.write(); | ||
}) | ||
) | ||
} | ||
async publish(page){ | ||
//create version. | ||
//ORM.create(PageVersion, ) | ||
const database = this.state.get(ControllerMixinDatabase.DATABASES).get('live'); | ||
//live database always keep minimal content | ||
//check page exist, remove it. | ||
const exist = await ORM.readBy(Page, 'id', [page.id],{database, limit:1, asArray:false}); | ||
if(exist)await exist.delete(); | ||
const livePage = ORM.create(Page, {database, insertID: page.id}); | ||
const pageFields = {...page}; | ||
delete pageFields.id; | ||
Object.assign(livePage, pageFields); | ||
await livePage.write(); | ||
//copy from tables | ||
await this.copyToLive(ORM.require('PageAttribute'), page.page_attributes, database); | ||
await this.copyToLive(ORM.require('PageValue'), page.page_values, database); | ||
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('PageItemValues'), item.page_item_values, database); | ||
}) | ||
) | ||
} | ||
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); | ||
}) | ||
) | ||
} | ||
page.publish = true; | ||
await page.write(); | ||
} | ||
async action_unpublish(){ | ||
const id = this.request.params['id']; | ||
const database = this.state.get(ControllerMixinDatabase.DATABASES).get('live'); | ||
const exist = await ORM.factory(Page, id,{database}); | ||
if(!exist)throw new Error(`Page not published`); | ||
await exist.delete(); | ||
const draftDB = this.state.get(ControllerMixinDatabase.DATABASES).get('draft'); | ||
const page = await ORM.factory(Page, id, {database: draftDB}); | ||
page.publish = false; | ||
await page.write(); | ||
await this.redirect(`/admin/pages/${id}?language=${this.language}`); | ||
} | ||
async setEditTemplate(){ | ||
@@ -112,7 +195,7 @@ const templateData = this.state.get(ControllerMixinView.TEMPLATE).data; | ||
if(pageObject.values[key])return; | ||
if(masterPageObject.values[key].id){ | ||
if( masterPageObject.values[key].id ){ | ||
//create current language value | ||
newValuePromises.push(ControllerAdminContent.createEmptyValue(key, null, page, this.languageId, database)); | ||
}else{ | ||
Object.key(pageObject.values[key]).forEach(subValue => { | ||
Object.keys(pageObject.values[key] || {}).forEach(subValue => { | ||
newValuePromises.push(ControllerAdminContent.createEmptyValue(key, subValue, page, this.languageId, database)); | ||
@@ -119,0 +202,0 @@ }); |
@@ -21,2 +21,3 @@ const {KohanaJS} = require('kohanajs') | ||
RouteList.add('/admin/pages/un-publish/:id', 'controller/admin/Page', 'unpublish'); | ||
RouteCRUD.add('pages', 'controller/admin/Page'); | ||
@@ -27,2 +28,3 @@ | ||
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'); | ||
RouteList.add('/admin/contents/page-delete-item/:item_id', 'controller/admin/Content', 'page_delete_item'); | ||
{ | ||
"name": "@kohanajs/mod-cms", | ||
"version": "3.0.0", | ||
"version": "3.1.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
47080
45
1217