Clean up test script

This commit is contained in:
Daniel Lautzenheiser 2022-10-26 11:46:06 -04:00
parent 41c2b32665
commit 03815ec2f0

View File

@ -1,66 +1,66 @@
// Register all the things // Register all the things
window.CMS.init(); CMS.init();
const PostPreview = window.createClass({ const PostPreview = createClass({
render: function () { render: function () {
var entry = this.props.entry; var entry = this.props.entry;
return window.h( return h(
'div', 'div',
{}, {},
window.h( h(
'div', 'div',
{ className: 'cover' }, { className: 'cover' },
window.h('h1', {}, entry.data.title), h('h1', {}, entry.data.title),
this.props.widgetFor('image'), this.props.widgetFor('image'),
), ),
window.h('p', {}, window.h('small', {}, 'Written ' + entry.data.date)), h('p', {}, h('small', {}, 'Written ' + entry.data.date)),
window.h('div', { className: 'text' }, this.props.widgetFor('body')), h('div', { className: 'text' }, this.props.widgetFor('body')),
); );
}, },
}); });
const GeneralPreview = window.createClass({ const GeneralPreview = createClass({
render: function () { render: function () {
const entry = this.props.entry; const entry = this.props.entry;
const title = entry.data.site_title; const title = entry.data.site_title;
const posts = entry.data.posts; const posts = entry.data.posts;
const thumb = posts && posts.thumb; const thumb = posts && posts.thumb;
return window.h( return h(
'div', 'div',
{}, {},
window.h('h1', {}, title), h('h1', {}, title),
window.h( h(
'dl', 'dl',
{}, {},
window.h('dt', {}, 'Posts on Frontpage'), h('dt', {}, 'Posts on Frontpage'),
window.h('dd', {}, this.props.widgetsFor('posts').widgets.front_limit || 0), h('dd', {}, this.props.widgetsFor('posts').widgets.front_limit || 0),
window.h('dt', {}, 'Default Author'), h('dt', {}, 'Default Author'),
window.h('dd', {}, this.props.widgetsFor('posts').data.author || 'None'), h('dd', {}, this.props.widgetsFor('posts').data.author || 'None'),
window.h('dt', {}, 'Default Thumbnail'), h('dt', {}, 'Default Thumbnail'),
window.h( h(
'dd', 'dd',
{}, {},
thumb && window.h('img', { src: this.props.getAsset(thumb).toString() }), thumb && h('img', { src: this.props.getAsset(thumb).toString() }),
), ),
), ),
); );
}, },
}); });
const AuthorsPreview = window.createClass({ const AuthorsPreview = createClass({
render: function () { render: function () {
return window.h( return h(
'div', 'div',
{}, {},
window.h('h1', {}, 'Authors'), h('h1', {}, 'Authors'),
this.props.widgetsFor('authors').map(function (author, index) { this.props.widgetsFor('authors').map(function (author, index) {
return window.h( return h(
'div', 'div',
{ key: index }, { key: index },
window.h('hr', {}), h('hr', {}),
window.h('strong', {}, author.data.name), h('strong', {}, author.data.name),
author.widgets.description, author.widgets.description,
); );
}), }),
@ -68,7 +68,7 @@ const AuthorsPreview = window.createClass({
}, },
}); });
const RelationKitchenSinkPostPreview = window.createClass({ const RelationKitchenSinkPostPreview = createClass({
render: function () { render: function () {
// When a post is selected from the relation field, all of it's data // When a post is selected from the relation field, all of it's data
// will be available in the field's metadata nested under the collection // will be available in the field's metadata nested under the collection
@ -80,24 +80,24 @@ const RelationKitchenSinkPostPreview = window.createClass({
const post = fieldsMetaData && fieldsMetaData.posts.value; const post = fieldsMetaData && fieldsMetaData.posts.value;
const style = { border: '2px solid #ccc', borderRadius: '8px', padding: '20px' }; const style = { border: '2px solid #ccc', borderRadius: '8px', padding: '20px' };
return post return post
? window.h( ? h(
'div', 'div',
{ style: style }, { style: style },
window.h('h2', {}, 'Related Post'), h('h2', {}, 'Related Post'),
window.h('h3', {}, post.title), h('h3', {}, post.title),
window.h('img', { src: post.image }), h('img', { src: post.image }),
window.h('p', {}, (post.body ?? '').slice(0, 100) + '...'), h('p', {}, (post.body ?? '').slice(0, 100) + '...'),
) )
: null; : null;
}, },
}); });
window.CMS.registerPreviewTemplate('posts', PostPreview); CMS.registerPreviewTemplate('posts', PostPreview);
window.CMS.registerPreviewTemplate('general', GeneralPreview); CMS.registerPreviewTemplate('general', GeneralPreview);
window.CMS.registerPreviewTemplate('authors', AuthorsPreview); CMS.registerPreviewTemplate('authors', AuthorsPreview);
// Pass the name of a registered control to reuse with a new widget preview. // Pass the name of a registered control to reuse with a new widget preview.
window.CMS.registerWidget('relationKitchenSinkPost', 'relation', RelationKitchenSinkPostPreview); CMS.registerWidget('relationKitchenSinkPost', 'relation', RelationKitchenSinkPostPreview);
window.CMS.registerAdditionalLink({ CMS.registerAdditionalLink({
id: 'example', id: 'example',
title: 'Example.com', title: 'Example.com',
data: 'https://example.com', data: 'https://example.com',