@kohanajs/mod-cms
Advanced tools
Comparing version 7.0.2 to 7.1.0
@@ -5,2 +5,9 @@ # Changelog | ||
## [7.1.0](https://gitlab.com/kohana-js/proposals/level0/mod-cms/compare/v7.0.2...v7.1.0) (2022-03-24) | ||
### Features | ||
* original tags ([2c99ee0](https://gitlab.com/kohana-js/proposals/level0/mod-cms/commit/2c99ee084d2c2a24eaf78879cbfd49ad80e3dea6)) | ||
### [7.0.2](https://gitlab.com/kohana-js/proposals/level0/mod-cms/compare/v7.0.1...v7.0.2) (2022-03-24) | ||
@@ -7,0 +14,0 @@ |
@@ -9,2 +9,3 @@ const { ControllerAdmin } = require('@kohanajs/mod-admin'); | ||
const Tag = ORM.require('Tag'); | ||
const TagType = ORM.require('TagType'); | ||
@@ -19,3 +20,2 @@ class ControllerAdminPage extends ControllerAdmin { | ||
['tag', `${KohanaJS.config.cms.databasePath}/www/tag.sqlite`], | ||
['language', `${KohanaJS.config.cms.databasePath}/www/language.sqlite`] | ||
]), | ||
@@ -41,2 +41,13 @@ database: 'draft', | ||
//collect tags and write to original | ||
const database = this.state.get(ControllerMixinDatabase.DATABASES).get('content'); | ||
await instance.eagerLoad({with:['PageTag']}, {database}); | ||
const databaseTag = this.state.get(ControllerMixinDatabase.DATABASES).get('tag'); | ||
const tagTypes = await ORM.readAll(TagType, {database:databaseTag, asArray:true}); | ||
const tagTypeMap = new Map(tagTypes.map(it => [it.id, it.name])); | ||
const tags = await ORM.readBy(Tag, 'id', instance.page_tags.map(it => it.tag_id), {database: databaseTag, asArray:true }); | ||
original.tags = tags.map(tag => HelperPageText.getOriginal(tag, {_id: tag.id, _type_id: tag.tag_type_id, _type:tagTypeMap.get(tag.tag_type_id)})); | ||
instance.original = JSON.stringify(original); | ||
@@ -293,2 +304,2 @@ await instance.write(); | ||
module.exports = ControllerAdminPage; | ||
module.exports = ControllerAdminPage; |
class HelperPageText{ | ||
static getOriginal(page){ | ||
return JSON.parse(page.original || `{"attributes":{}, "values":{}, "items":{}}`); | ||
static getOriginal(page, attributes={}){ | ||
if(!page.original){ | ||
return {"attributes":{}, "values":{}, "items":{}} | ||
} | ||
const original = JSON.parse(page.original); | ||
Object.assign(original.attributes, attributes); | ||
return original; | ||
} | ||
@@ -108,5 +115,13 @@ | ||
tokens : this.flattenTokens(original, languageCode, masterLanguageCode), | ||
blocks:[] | ||
} | ||
blocks:[], | ||
tags: {} | ||
}; | ||
(original.tags || []).forEach(tag => { | ||
const tagToken = this.flattenTokens(tag, languageCode, masterLanguageCode); | ||
result.tags[tagToken._type] ||= []; | ||
result.tags[tagToken._type].push(tagToken); | ||
}) | ||
if(!original.blocks)return result; | ||
@@ -113,0 +128,0 @@ |
{ | ||
"name": "@kohanajs/mod-cms", | ||
"version": "7.0.2", | ||
"version": "7.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
94013
1245