IMPR: Move elements to another page

This commit is contained in:
Tony Air 2021-03-29 14:55:04 +07:00
parent b87adfa1cc
commit b2691a7112
6 changed files with 200 additions and 153 deletions

View File

@ -34,6 +34,6 @@ $config->setOption(
FulltextSearchable::enable();
// replace embed parser
$parser = ShortcodeParser::get('default');
/*$parser = ShortcodeParser::get('default');
$parser->unregister('embed');
$parser->register('embed', [EmbedShortcodeProvider::class, 'handle_shortcode']);
$parser->register('embed', [EmbedShortcodeProvider::class, 'handle_shortcode']);*/

View File

@ -41,6 +41,7 @@ DNADesign\Elemental\Models\BaseElement:
default_global_elements: true
extensions:
#- DNADesign\Elemental\TopPage\DataExtension
- App\Elements\Extensions\BaseElementEx
- App\Elements\Extensions\ElementRows
SilverStripe\CMS\Model\SiteTree:

View File

@ -0,0 +1,68 @@
<?php
/**
* Created by PhpStorm.
* User: tony
* Date: 6/23/18
* Time: 1:23 PM
*/
namespace App\Elements\Extensions;
use DNADesign\Elemental\Models\BaseElement;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Forms\TreeDropdownField;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\LiteralField;
class BaseElementEx extends DataExtension
{
public function updateCMSFields(FieldList $fields)
{
$obj = $this->owner;
parent::updateCMSFields($fields);
$tab = $fields->findOrMakeTab('Root.Settings');
$tab->push(LiteralField::create(
'ClassName',
'<div class="form-group field text">'
.'<div class="form__field-label">Class</div>'
.'<div class="form__field-holder">'.$obj->getField('ClassName').'</div>'
.'</div>'
));
if($this->owner->ID) {
$tab->push(TreeDropdownField::create(
'MoveElementIDToPage',
'Move an element to page',
SiteTree::class
)->setEmptyString('(select an element to move)'));
}
}
public static function MoveElementToPage($ID, $moveToID)
{
$el = BaseElement::get()->byID($ID);
$page = SiteTree::get()->byID($moveToID);
if (!$page || !$el) {
return false;
}
$el->setField('ParentID', $page->ElementalArea()->ID);
$el->write();
return true;
}
public function onBeforeWrite()
{
parent::onBeforeWrite();
$moveID = $this->owner->getField('MoveElementIDToPage');
if($this->owner->ID && $moveID) {
self::MoveElementToPage($this->owner->ID, $moveID);
}
}
}

View File

@ -15,7 +15,6 @@ use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\LiteralField;
use App\Elements\AccordionElement;
class ElementRows extends DataExtension
@ -127,16 +126,6 @@ class ElementRows extends DataExtension
)->setEmptyString('(select an element to move)'));
}
}
$fields->findOrMakeTab('Root.Settings')
->push(LiteralField::create(
'ClassName',
'<div class="form-group field text">'
.'<div class="form__field-label">Class</div>'
.'<div class="form__field-holder">'.$obj->getField('ClassName').'</div>'
.'</div>'
));
}
public function getWidthPercetage()

View File

@ -28,8 +28,8 @@
font-size: 14px;
margin: 0;
padding: 0;
background: #1c2947;
color: #fff;
background: #fff;
color: #212529;
overflow-x: hidden;
}
@media (min-width: 2000px) {
@ -52,8 +52,8 @@
justify-content: center;
z-index: 2000;
will-change: opacity;
background: #1c2947;
color: #fff;
background: #fff;
color: #212529;
}
#PageLoading .logo {
width:100px;

View File

@ -33,161 +33,150 @@ console.log('GRAPHQL_API_KEY: ' + conf['GRAPHQL_API_KEY']);
console.log('HTTPS: ' + conf['HTTPS']);
const plugins = [
new webpack.ProvidePlugin({
react: 'React',
'react-dom': 'ReactDOM',
/*$: 'jquery',
new webpack.ProvidePlugin({
react: 'React',
'react-dom': 'ReactDOM',
/*$: 'jquery',
jQuery: 'jquery',*/
}),
new webpack.DefinePlugin({
UINAME: JSON.stringify(UIInfo.name),
UIVERSION: UIVERSION,
UIAUTHOR: JSON.stringify(UIInfo.author),
UIMetaNAME: JSON.stringify(UIMetaInfo.name),
UIMetaVersion: JSON.stringify(UIMetaInfo.version),
GRAPHQL_API_KEY: JSON.stringify(conf['GRAPHQL_API_KEY']),
SWVERSION: JSON.stringify(`sw-${new Date().getTime()}`),
BASE_HREF: JSON.stringify(
`http${conf['HTTPS'] ? 's' : ''}://${IP}:${PORT}`,
),
}),
//new webpack.HotModuleReplacementPlugin(),
new MiniCssExtractPlugin(),
}),
new webpack.DefinePlugin({
UINAME: JSON.stringify(UIInfo.name),
UIVERSION: UIVERSION,
UIAUTHOR: JSON.stringify(UIInfo.author),
UIMetaNAME: JSON.stringify(UIMetaInfo.name),
UIMetaVersion: JSON.stringify(UIMetaInfo.version),
GRAPHQL_API_KEY: JSON.stringify(conf['GRAPHQL_API_KEY']),
SWVERSION: JSON.stringify(`sw-${new Date().getTime()}`),
BASE_HREF: JSON.stringify(
`http${conf['HTTPS'] ? 's' : ''}://${IP}:${PORT}`,
),
}),
//new webpack.HotModuleReplacementPlugin(),
new MiniCssExtractPlugin(),
];
const indexPath = path.join(__dirname, conf.APPDIR, conf.SRC, 'index.html');
if (filesystem.existsSync(indexPath)) {
plugins.push(
new HtmlWebpackPlugin({
publicPath: '',
template: path.join(conf.APPDIR, conf.SRC, 'index.html'),
templateParameters: {
NODE_ENV: NODE_ENV,
GRAPHQL_URL: conf['GRAPHQL_URL'],
STATIC_URL: conf['STATIC_URL'],
REACT_SCRIPTS:
NODE_ENV === 'production'
? '<script crossorigin src="https://unpkg.com/react@17/umd/react.production.min.js"></script><script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>'
: '<script crossorigin src="https://unpkg.com/react@17/umd/react.development.js"></script><script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>',
},
}),
);
plugins.push(
new HtmlWebpackPlugin({
publicPath: '',
template: path.join(conf.APPDIR, conf.SRC, 'index.html'),
templateParameters: {
NODE_ENV: NODE_ENV,
GRAPHQL_URL: conf['GRAPHQL_URL'],
STATIC_URL: conf['STATIC_URL'],
REACT_SCRIPTS: NODE_ENV === 'production' ?
'<script crossorigin src="https://unpkg.com/react@17/umd/react.production.min.js"></script><script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>' :
'<script crossorigin src="https://unpkg.com/react@17/umd/react.development.js"></script><script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>',
},
}),
);
}
const config = merge(common, {
mode: 'development',
mode: 'development',
entry: {
/*hot: [
entry: {
/*hot: [
'react-hot-loader/patch',
'webpack-dev-server/?https://' + conf.HOSTNAME + ':' + conf.PORT,
'webpack/hot/only-dev-server',
],*/
},
},
output: {
path: path.join(__dirname),
filename: '[name].js',
// necessary for HMR to know where to load the hot update chunks
publicPath: `http${conf['HTTPS'] ? 's' : ''}://${conf['HOSTNAME']}:${
output: {
path: path.join(__dirname),
filename: '[name].js',
// necessary for HMR to know where to load the hot update chunks
publicPath: `http${conf['HTTPS'] ? 's' : ''}://${conf['HOSTNAME']}:${
conf.PORT
}/`,
},
},
module: {
rules: [
{
test: /\.jsx?$/,
//exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env',
'@babel/react',
{
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-syntax-top-level-await',
],
},
], //Preset used for env setup
plugins: [
['@babel/transform-react-jsx'],
['@babel/plugin-syntax-top-level-await'],
],
cacheDirectory: true,
cacheCompression: true,
},
},
},
{
test: /\.s?css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
options: {
sourceMap: !COMPRESS,
},
},
{
loader: 'resolve-url-loader',
},
{
loader: 'sass-loader',
options: {
sourceMap: false,
},
},
],
},
{
test: /fontawesome([^.]+).(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
use: [
{
loader: 'url-loader',
},
],
},
{
test: /\.(gif|png|jpg|jpeg|ttf|otf|eot|svg|webp|woff(2)?)$/,
use: [
{
loader: 'file-loader',
options: {
name(file) {
return 'public/[path][name].[ext]';
},
},
},
],
},
],
},
plugins: plugins,
module: {
rules: [{
test: /\.jsx?$/,
//exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env',
'@babel/react',
{
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-syntax-top-level-await',
],
},
], //Preset used for env setup
plugins: [
['@babel/transform-react-jsx'],
['@babel/plugin-syntax-top-level-await'],
],
cacheDirectory: true,
cacheCompression: true,
},
},
},
{
test: /\.s?css$/,
use: [{
loader: MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
options: {
sourceMap: !COMPRESS,
},
},
{
loader: 'resolve-url-loader',
},
{
loader: 'sass-loader',
options: {
sourceMap: false,
},
},
],
},
{
test: /fontawesome([^.]+).(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
use: [{
loader: 'url-loader',
}, ],
},
{
test: /\.(gif|png|jpg|jpeg|ttf|otf|eot|svg|webp|woff(2)?)$/,
use: [{
loader: 'file-loader',
options: {
name(file) {
return 'public/[path][name].[ext]';
},
},
}, ],
},
],
},
plugins: plugins,
devServer: {
host: IP,
port: PORT,
historyApiFallback: false,
static: path.resolve(__dirname, conf['APPDIR'], conf['SRC']),
https: conf['HTTPS'],
hot: false,
injectClient: conf['injectClient'],
devServer: {
host: IP,
port: PORT,
historyApiFallback: false,
static: path.resolve(__dirname, conf['APPDIR'], conf['SRC']),
https: conf['HTTPS'],
hot: false,
injectClient: conf['injectClient'],
overlay: {
warnings: true,
errors: true,
},
headers: {
'Access-Control-Allow-Origin': '*',
'Referrer-Policy': 'unsafe-url',
'service-worker-allowed': '/',
},
},
headers: {
'Access-Control-Allow-Origin': '*',
'Referrer-Policy': 'unsafe-url',
'service-worker-allowed': '/',
},
},
});
module.exports = config;