From b2691a7112cee4f02fe808872ec29efc42a0f912 Mon Sep 17 00:00:00 2001 From: Tony Air Date: Mon, 29 Mar 2021 14:55:04 +0700 Subject: [PATCH] IMPR: Move elements to another page --- app/_config.php | 4 +- app/_config/options-elements.yml | 1 + app/src/Elements/Extensions/BaseElementEx.php | 68 +++++ app/src/Elements/Extensions/ElementRows.php | 11 - app/templates/Includes/LoadingSpinner.ss | 8 +- webpack.config.serve.js | 261 +++++++++--------- 6 files changed, 200 insertions(+), 153 deletions(-) create mode 100644 app/src/Elements/Extensions/BaseElementEx.php diff --git a/app/_config.php b/app/_config.php index 75a2a34..897cc06 100644 --- a/app/_config.php +++ b/app/_config.php @@ -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']);*/ diff --git a/app/_config/options-elements.yml b/app/_config/options-elements.yml index 3e9fdc1..da2cde6 100644 --- a/app/_config/options-elements.yml +++ b/app/_config/options-elements.yml @@ -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: diff --git a/app/src/Elements/Extensions/BaseElementEx.php b/app/src/Elements/Extensions/BaseElementEx.php new file mode 100644 index 0000000..d9f6f73 --- /dev/null +++ b/app/src/Elements/Extensions/BaseElementEx.php @@ -0,0 +1,68 @@ +owner; + parent::updateCMSFields($fields); + $tab = $fields->findOrMakeTab('Root.Settings'); + + $tab->push(LiteralField::create( + 'ClassName', + '
' + .'
Class
' + .'
'.$obj->getField('ClassName').'
' + .'
' + )); + + 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); + } + } +} diff --git a/app/src/Elements/Extensions/ElementRows.php b/app/src/Elements/Extensions/ElementRows.php index e074b65..93d8047 100644 --- a/app/src/Elements/Extensions/ElementRows.php +++ b/app/src/Elements/Extensions/ElementRows.php @@ -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', - '
' - .'
Class
' - .'
'.$obj->getField('ClassName').'
' - .'
' - )); } public function getWidthPercetage() diff --git a/app/templates/Includes/LoadingSpinner.ss b/app/templates/Includes/LoadingSpinner.ss index 834122a..5eefa57 100644 --- a/app/templates/Includes/LoadingSpinner.ss +++ b/app/templates/Includes/LoadingSpinner.ss @@ -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; diff --git a/webpack.config.serve.js b/webpack.config.serve.js index 7aaaac1..0d2854c 100644 --- a/webpack.config.serve.js +++ b/webpack.config.serve.js @@ -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' - ? '' - : '', - }, - }), - ); + 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' ? + '' : + '', + }, + }), + ); } 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;