From cb46b99bf2b54d16a1bad99217b419373fec99a5 Mon Sep 17 00:00:00 2001 From: sokmean-mptc Date: Wed, 27 Jan 2021 11:03:14 +0700 Subject: [PATCH 1/9] # --- src/services/editor.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/src/services/editor.scss b/src/services/editor.scss index f23e2c2..db9c0ed 100644 --- a/src/services/editor.scss +++ b/src/services/editor.scss @@ -13,3 +13,4 @@ max-width: 740px; padding: 2rem; } + From 2e8926d3de704ab325b130e6d67874ab570603ca Mon Sep 17 00:00:00 2001 From: sokmean-mptc Date: Wed, 27 Jan 2021 17:10:50 +0700 Subject: [PATCH 2/9] # --- inc/Blocks/SCDetail.php | 74 ++++++++++++++ inc/Blocks/SCLists.php | 77 +++++++++++++++ inc/Init.php | 2 + src/blocks.js | 2 + src/common.scss | 2 +- src/components/MarkText.jsx | 16 +++ src/sc-detail/block.js | 72 ++++++++++++++ src/sc-detail/editor.scss | 16 +++ src/sc-detail/style.scss | 14 +++ src/sc-lists/block.js | 72 ++++++++++++++ src/sc-lists/editor.scss | 16 +++ src/sc-lists/style.scss | 14 +++ src/services/block.js | 2 + yarn.lock | 188 +++++++++++++++++------------------- 14 files changed, 465 insertions(+), 102 deletions(-) create mode 100644 inc/Blocks/SCDetail.php create mode 100644 inc/Blocks/SCLists.php create mode 100644 src/components/MarkText.jsx create mode 100644 src/sc-detail/block.js create mode 100644 src/sc-detail/editor.scss create mode 100644 src/sc-detail/style.scss create mode 100644 src/sc-lists/block.js create mode 100644 src/sc-lists/editor.scss create mode 100644 src/sc-lists/style.scss diff --git a/inc/Blocks/SCDetail.php b/inc/Blocks/SCDetail.php new file mode 100644 index 0000000..ac2c78b --- /dev/null +++ b/inc/Blocks/SCDetail.php @@ -0,0 +1,74 @@ +plugin_name . '/sc-detail', array( + 'style' => $this->plugin_name . '-style', + 'editor_script' => $this->plugin_name . '-js', + 'editor_style' => $this->plugin_name . '-editor-css', + 'render_callback' => array( $this, 'renderPostsBlock' ), + 'attributes' => array( + 'api' => array( + 'type' => 'string', + 'default' => '' + ), + 'item_to_show' => array( + 'type' => 'number', + 'default' => 8 + ) + ) + ) + ); + } + public function renderPostsBlock( $attributes ) { + ob_start(); + + echo '
'; + echo $this->getDistantTerms()->content->rendered; + echo '
'; + return ob_get_clean(); + } + public function getDistantTerms() { + if ( ! isset( $_GET['service_id'] ) ) { + return []; + } + $id = $_GET['service_id']; + $response = wp_remote_get('https://demo.cambodia.gov.kh/wp-json/wp/v2/service/'.$id); + if(is_wp_error($response)) { + return array(); + } + return json_decode(wp_remote_retrieve_body($response)); + } +} + diff --git a/inc/Blocks/SCLists.php b/inc/Blocks/SCLists.php new file mode 100644 index 0000000..d2bba0c --- /dev/null +++ b/inc/Blocks/SCLists.php @@ -0,0 +1,77 @@ +plugin_name . '/sc-lists', array( + 'style' => $this->plugin_name . '-style', + 'editor_script' => $this->plugin_name . '-js', + 'editor_style' => $this->plugin_name . '-editor-css', + 'render_callback' => array( $this, 'renderPostsBlock' ), + 'attributes' => array( + 'api' => array( + 'type' => 'string', + 'default' => '' + ), + 'item_to_show' => array( + 'type' => 'number', + 'default' => 8 + ) + ) + ) + ); + } + public function renderPostsBlock( $attributes ) { + ob_start(); + echo '
';
+        // print_r( $this->getDistantTerms() );
+        // foreach( $this->getDistantTerms() as $item ) {
+        //     print_r( $item->content->rendered );
+        // }
+        echo '
'; + echo '
'; + foreach( $this->getDistantTerms() as $item ) { + echo '

'.$item->title->rendered.'

'; + } + echo '
'; + return ob_get_clean(); + } + public function getDistantTerms() { + $response = wp_remote_get('https://demo.cambodia.gov.kh/wp-json/wp/v2/service?service-topic=316'); + if(is_wp_error($response)) { + return array(); + } + return json_decode(wp_remote_retrieve_body($response)); + } +} + diff --git a/inc/Init.php b/inc/Init.php index 7af18ad..ef08f16 100644 --- a/inc/Init.php +++ b/inc/Init.php @@ -22,6 +22,8 @@ public static function getServices() { LoadSettings::class, RegisterAsset::class, Blocks\Services::class, + Blocks\SCLists::class, + Blocks\SCDetail::class ); } diff --git a/src/blocks.js b/src/blocks.js index 214b0f2..7c0e41e 100644 --- a/src/blocks.js +++ b/src/blocks.js @@ -10,4 +10,6 @@ */ import './services/block'; +import './sc-lists/block' +import './sc-detail/block' // import './block-service-content/block.js'; diff --git a/src/common.scss b/src/common.scss index 4b3ba98..8fe7629 100644 --- a/src/common.scss +++ b/src/common.scss @@ -10,4 +10,4 @@ $black: rgb(41, 41, 41); $white: #f4f4f4; $gray: #dedede; $green: #bada55; -$red: orangered; +$red: orangered; diff --git a/src/components/MarkText.jsx b/src/components/MarkText.jsx new file mode 100644 index 0000000..f01c853 --- /dev/null +++ b/src/components/MarkText.jsx @@ -0,0 +1,16 @@ +const { __ } = wp.i18n +const { TextControl } = wp.components + +const MarkText = ( { attributes, setAttributes } ) => { + const { mark_text } = attributes + + return ( + setAttributes( { mark_text: value } ) } + /> + ) +} + +export default MarkText \ No newline at end of file diff --git a/src/sc-detail/block.js b/src/sc-detail/block.js new file mode 100644 index 0000000..8349fa2 --- /dev/null +++ b/src/sc-detail/block.js @@ -0,0 +1,72 @@ +import './style.scss' +import './editor.scss' +const { __ } = wp.i18n +import MarkText from '../components/MarkText.jsx' +const { registerBlockType } = wp.blocks +const { InspectorControls } = wp.blockEditor +const { PanelBody, __experimentalNumberControl : NumberControl, __experimentalInputControl : InputControl } = wp.components +const { Fragment } = wp.element +registerBlockType( 'digital-blocks/sc-detail', { + title: __( 'Serivce Cambodia Detail', 'CEGOV' ), + icon: 'admin-page', + category: 'digital-blocks', + keywords: [ + __( 'service', 'CEGOV' ), + __( 'cambodia', 'CEGOV' ), + __( 'egov block', 'CEGOV' ) + ], + attributes: { + mark_text: { + type: 'string', + default: 'Service Cambodia Detail' + }, + toggle_panel: { + type: 'boolean', + default: false + }, + api: { + type: 'string', + default: '' + } + }, + edit: ( { attributes, setAttributes } ) => { + const { + mark_text, + toggle_panel, + api + } = attributes + + return ( + + + + + + { + setAttributes( { toggle_panel: ! toggle_panel } ) + } } + > + setAttributes( { api: value } ) } + /> + + +
+ { mark_text } +
+
+ ) + }, + + save: ( { attributes } ) => { + return null + } +} ) \ No newline at end of file diff --git a/src/sc-detail/editor.scss b/src/sc-detail/editor.scss new file mode 100644 index 0000000..db9c0ed --- /dev/null +++ b/src/sc-detail/editor.scss @@ -0,0 +1,16 @@ +/** + * #.# Editor Styles + * + * CSS for just Backend enqueued after style.scss + * which makes it higher in priority. + */ + +.wp-block-cgb-block-digital-blocks { + background: $green; + border: 0.2rem solid $black; + color: $black; + margin: 0 auto; + max-width: 740px; + padding: 2rem; +} + diff --git a/src/sc-detail/style.scss b/src/sc-detail/style.scss new file mode 100644 index 0000000..385d010 --- /dev/null +++ b/src/sc-detail/style.scss @@ -0,0 +1,14 @@ +/** + * #.# Styles + * + * CSS for both Frontend+Backend. + */ + +.wp-block-cgb-block-digital-blocks { + background: $red; + border: 0.2rem solid $black; + color: $black; + margin: 0 auto; + max-width: 740px; + padding: 2rem; +} diff --git a/src/sc-lists/block.js b/src/sc-lists/block.js new file mode 100644 index 0000000..04b8f6a --- /dev/null +++ b/src/sc-lists/block.js @@ -0,0 +1,72 @@ +import './style.scss' +import './editor.scss' +const { __ } = wp.i18n +import MarkText from '../components/MarkText.jsx' +const { registerBlockType } = wp.blocks +const { InspectorControls } = wp.blockEditor +const { PanelBody, __experimentalNumberControl : NumberControl, __experimentalInputControl : InputControl } = wp.components +const { Fragment } = wp.element +registerBlockType( 'digital-blocks/sc-lists', { + title: __( 'Serivce Cambodia Lists', 'CEGOV' ), + icon: 'admin-page', + category: 'digital-blocks', + keywords: [ + __( 'service', 'CEGOV' ), + __( 'cambodia', 'CEGOV' ), + __( 'egov block', 'CEGOV' ) + ], + attributes: { + mark_text: { + type: 'string', + default: 'Service Cambodia Lists' + }, + toggle_panel: { + type: 'boolean', + default: false + }, + api: { + type: 'string', + default: '' + } + }, + edit: ( { attributes, setAttributes } ) => { + const { + mark_text, + toggle_panel, + api + } = attributes + + return ( + + + + + + { + setAttributes( { toggle_panel: ! toggle_panel } ) + } } + > + setAttributes( { api: value } ) } + /> + + +
+ { mark_text } +
+
+ ) + }, + + save: ( { attributes } ) => { + return null + } +} ) \ No newline at end of file diff --git a/src/sc-lists/editor.scss b/src/sc-lists/editor.scss new file mode 100644 index 0000000..db9c0ed --- /dev/null +++ b/src/sc-lists/editor.scss @@ -0,0 +1,16 @@ +/** + * #.# Editor Styles + * + * CSS for just Backend enqueued after style.scss + * which makes it higher in priority. + */ + +.wp-block-cgb-block-digital-blocks { + background: $green; + border: 0.2rem solid $black; + color: $black; + margin: 0 auto; + max-width: 740px; + padding: 2rem; +} + diff --git a/src/sc-lists/style.scss b/src/sc-lists/style.scss new file mode 100644 index 0000000..385d010 --- /dev/null +++ b/src/sc-lists/style.scss @@ -0,0 +1,14 @@ +/** + * #.# Styles + * + * CSS for both Frontend+Backend. + */ + +.wp-block-cgb-block-digital-blocks { + background: $red; + border: 0.2rem solid $black; + color: $black; + margin: 0 auto; + max-width: 740px; + padding: 2rem; +} diff --git a/src/services/block.js b/src/services/block.js index 9582187..6e49f46 100644 --- a/src/services/block.js +++ b/src/services/block.js @@ -1,3 +1,5 @@ +import './style.scss' +import './editor.scss' const { __ } = wp.i18n const { registerBlockType } = wp.blocks const { InspectorControls } = wp.blockEditor diff --git a/yarn.lock b/yarn.lock index 6085789..bf3db08 100644 --- a/yarn.lock +++ b/yarn.lock @@ -293,7 +293,7 @@ array-find-index@^1.0.1: resolved "https://registry.yarnpkg.com/array-find-index/-/array-find-index-1.0.2.tgz#df010aa1287e164bbda6f9723b0a96a1ec4187a1" integrity sha1-3wEKoSh+Fku9pvlyOwqWoexBh6E= -array-includes@^3.1.1: +array-includes@^3.1.1, array-includes@^3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/array-includes/-/array-includes-3.1.2.tgz#a8db03e0b88c8c6aeddc49cb132f9bcab4ebf9c8" integrity sha512-w2GspexNQpx+PutG3QpT437/BenZBj0M/MZGn5mzv/MofYqo0xmRHzn4lFsoDlWJ+THYsGJmFlW68WlDFx7VRw== @@ -1068,9 +1068,9 @@ binary-extensions@^1.0.0: integrity sha512-Un7MIEDdUC5gNpcGDV97op1Ywk748MpHcFTHoYs6qnj1Z3j7I53VG3nwZhKzoBZmbdRNnb6WRdFlwl7tSDuZGw== binary-extensions@^2.0.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.1.0.tgz#30fa40c9e7fe07dbc895678cd287024dea241dd9" - integrity sha512-1Yj8h9Q+QDF5FzhMs/c9+6UntbD5MkRfRwac8DoEm9ZfUBZ7tZ55YcGVAzEe4bXsdQHEk+s9S5wsOKVdZrw0tQ== + version "2.2.0" + resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" + integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== bindings@^1.5.0: version "1.5.0" @@ -1266,13 +1266,13 @@ cache-base@^1.0.1: union-value "^1.0.0" unset-value "^1.0.0" -call-bind@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.0.tgz#24127054bb3f9bdcb4b1fb82418186072f77b8ce" - integrity sha512-AEXsYIyyDY3MCzbwdhzG3Jx1R0J2wetQyUynn6dYHAO+bg8l1k7jwZtRv4ryryFs7EP+NDlikJlVe59jr0cM2w== +call-bind@^1.0.0, call-bind@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.2.tgz#b1d4e89e688119c3c9a903ad30abb2f6a919be3c" + integrity sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA== dependencies: function-bind "^1.1.1" - get-intrinsic "^1.0.0" + get-intrinsic "^1.0.2" caller-callsite@^2.0.0: version "2.0.0" @@ -1334,9 +1334,9 @@ camelcase@^5.0.0: integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg== caniuse-lite@^1.0.30000792, caniuse-lite@^1.0.30000805, caniuse-lite@^1.0.30000844: - version "1.0.30001168" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001168.tgz#6fcd098c139d003b9bd484cbb9ca26cb89907f9a" - integrity sha512-P2zmX7swIXKu+GMMR01TWa4csIKELTNnZKc+f1CjebmZJQtTAEXmpQSoKVJVVcvPGAA0TEYTOUp3VehavZSFPQ== + version "1.0.30001179" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001179.tgz#b0803883b4471a6c62066fb1752756f8afc699c8" + integrity sha512-blMmO0QQujuUWZKyVrD1msR4WNDAqb/UPO1Sw2WWsQ7deoM5bJiicKnWJ1Y0NS/aGINSnKPIWBMw5luX+NDUCA== capture-stack-trace@^1.0.0: version "1.0.1" @@ -1457,9 +1457,9 @@ chokidar@^2.1.8: fsevents "^1.2.7" chokidar@^3.4.1: - version "3.4.3" - resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.4.3.tgz#c1df38231448e45ca4ac588e6c79573ba6a57d5b" - integrity sha512-DtM3g7juCXQxFVSNPNByEC2+NImtBuxQQvWlHunpJIS5Ocr0lG306cC7FCi7cEA0fzmybPUIl4txBIobk1gGOQ== + version "3.5.1" + resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.1.tgz#ee9ce7bbebd2b79f49f304799d5468e31e14e68a" + integrity sha512-9+s+Od+W0VJJzawDma/gvBNQqkTiqYTWLuZoyAsivsI4AaWTCzHG06/TMjsf1cYe9Cb97UCEhjz7HvnPk2p/tw== dependencies: anymatch "~3.1.1" braces "~3.0.2" @@ -1469,7 +1469,7 @@ chokidar@^3.4.1: normalize-path "~3.0.0" readdirp "~3.5.0" optionalDependencies: - fsevents "~2.1.2" + fsevents "~2.3.1" ci-info@^1.5.0: version "1.6.0" @@ -1660,9 +1660,9 @@ copy-descriptor@^0.1.0: integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40= core-js-pure@^3.0.0: - version "3.8.1" - resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.8.1.tgz#23f84048f366fdfcf52d3fd1c68fec349177d119" - integrity sha512-Se+LaxqXlVXGvmexKGPvnUIYC1jwXu1H6Pkyb3uBM5d8/NELMYCHs/4/roD7721NxrTLyv7e5nXd5/QLBO+10g== + version "3.8.3" + resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.8.3.tgz#10e9e3b2592ecaede4283e8f3ad7020811587c02" + integrity sha512-V5qQZVAr9K0xu7jXg1M7qTEwuxUgqr7dUOezGaNa7i+Xn9oXAU/d1fzqD9ObuwpVQOaorO5s70ckyi1woP9lVA== core-js@^2.4.0, core-js@^2.5.0: version "2.6.12" @@ -1941,9 +1941,9 @@ ecc-jsbn@~0.1.1: safer-buffer "^2.1.0" electron-to-chromium@^1.3.30, electron-to-chromium@^1.3.47: - version "1.3.627" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.627.tgz#4acdbbbbe31eb605fba8380063fd9c8a7e5ca4a0" - integrity sha512-O5IVRS4sCxP2+vECAp7uHkaI8V+dKYpuCyBcLn+hqVAOy/RONd8zx+6eH7TuWSTBYs/oUrzBXkNMZuVsQd58kQ== + version "1.3.645" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.645.tgz#c0b269ae2ecece5aedc02dd4586397d8096affb1" + integrity sha512-T7mYop3aDpRHIQaUYcmzmh6j9MAe560n6ukqjJMbVC6bVTau7dSpvB18bcsBPPtOSe10cKxhJFtlbEzLa0LL1g== elliptic@^6.5.3: version "6.5.3" @@ -1984,9 +1984,9 @@ enhanced-resolve@^3.4.0: tapable "^0.2.7" errno@^0.1.3: - version "0.1.7" - resolved "https://registry.yarnpkg.com/errno/-/errno-0.1.7.tgz#4684d71779ad39af177e3f007996f7c67c852618" - integrity sha512-MfrRBDWzIWifgq6tJj60gkAwtLNb6sQPlcFrSOflcP1aFmmruKQ2wRnze/8V6kgyz7H3FF8Npzv78mZ7XLLflg== + version "0.1.8" + resolved "https://registry.yarnpkg.com/errno/-/errno-0.1.8.tgz#8bb3e9c7d463be4976ff888f76b4809ebc2e811f" + integrity sha512-dJ6oBr5SQ1VSd9qkk7ByRgb/1SH4JZjCHSW/mr63/QcXO9zLVxvJ6Oy13nio03rxpSnVDDjFor75SjVeZWPW/A== dependencies: prr "~1.0.1" @@ -1997,40 +1997,25 @@ error-ex@^1.2.0, error-ex@^1.3.1: dependencies: is-arrayish "^0.2.1" -es-abstract@^1.17.0-next.1: - version "1.17.7" - resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.17.7.tgz#a4de61b2f66989fc7421676c1cb9787573ace54c" - integrity sha512-VBl/gnfcJ7OercKA9MVaegWsBHFjV492syMudcnQZvt/Dw8ezpcOHYZXa/J96O8vx+g4x65YKhxOwDUh63aS5g== - dependencies: - es-to-primitive "^1.2.1" - function-bind "^1.1.1" - has "^1.0.3" - has-symbols "^1.0.1" - is-callable "^1.2.2" - is-regex "^1.1.1" - object-inspect "^1.8.0" - object-keys "^1.1.1" - object.assign "^4.1.1" - string.prototype.trimend "^1.0.1" - string.prototype.trimstart "^1.0.1" - -es-abstract@^1.18.0-next.0, es-abstract@^1.18.0-next.1: - version "1.18.0-next.1" - resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.18.0-next.1.tgz#6e3a0a4bda717e5023ab3b8e90bec36108d22c68" - integrity sha512-I4UGspA0wpZXWENrdA0uHbnhte683t3qT/1VFH9aX2dA5PPSf6QW5HHXf5HImaqPmjXaVeVk4RGWnaylmV7uAA== +es-abstract@^1.18.0-next.1: + version "1.18.0-next.2" + resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.18.0-next.2.tgz#088101a55f0541f595e7e057199e27ddc8f3a5c2" + integrity sha512-Ih4ZMFHEtZupnUh6497zEL4y2+w8+1ljnCyaTa+adcoafI1GOvMwFlDjBLfWR7y9VLfrjRJe9ocuHY1PSR9jjw== dependencies: + call-bind "^1.0.2" es-to-primitive "^1.2.1" function-bind "^1.1.1" + get-intrinsic "^1.0.2" has "^1.0.3" has-symbols "^1.0.1" is-callable "^1.2.2" - is-negative-zero "^2.0.0" + is-negative-zero "^2.0.1" is-regex "^1.1.1" - object-inspect "^1.8.0" + object-inspect "^1.9.0" object-keys "^1.1.1" - object.assign "^4.1.1" - string.prototype.trimend "^1.0.1" - string.prototype.trimstart "^1.0.1" + object.assign "^4.1.2" + string.prototype.trimend "^1.0.3" + string.prototype.trimstart "^1.0.3" es-to-primitive@^1.2.1: version "1.2.1" @@ -2151,9 +2136,9 @@ eslint-plugin-jsx-a11y@^6.0.3: language-tags "^1.0.5" eslint-plugin-react@^7.5.1: - version "7.21.5" - resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.21.5.tgz#50b21a412b9574bfe05b21db176e8b7b3b15bff3" - integrity sha512-8MaEggC2et0wSF6bUeywF7qQ46ER81irOdWS4QWxnnlAEsnzeBevk1sWh7fhpCghPpXb+8Ks7hvaft6L/xsR6g== + version "7.22.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.22.0.tgz#3d1c542d1d3169c45421c1215d9470e341707269" + integrity sha512-p30tuX3VS+NWv9nQot9xIGAHBXR0+xJVaZriEsHoJrASGCJZDJ8JLNM0YqKqI0AKm6Uxaa1VUHoNEibxRCMQHA== dependencies: array-includes "^3.1.1" array.prototype.flatmap "^1.2.3" @@ -2561,10 +2546,10 @@ fsevents@^1.2.7: bindings "^1.5.0" nan "^2.12.1" -fsevents@~2.1.2: - version "2.1.3" - resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.1.3.tgz#fb738703ae8d2f9fe900c33836ddebee8b97f23e" - integrity sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ== +fsevents@~2.3.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.1.tgz#b209ab14c61012636c8863507edf7fb68cc54e9f" + integrity sha512-YR47Eg4hChJGAB1O3yEAOkGO+rlzutoICGqGo9EZ4lKWokzZRSyIW1QmTzqjtw8MJdj9srP869CuWw/hyzSiBw== fstream@^1.0.0, fstream@^1.0.12: version "1.0.12" @@ -2617,10 +2602,10 @@ get-caller-file@^2.0.1: resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== -get-intrinsic@^1.0.0, get-intrinsic@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.0.1.tgz#94a9768fcbdd0595a1c9273aacf4c89d075631be" - integrity sha512-ZnWP+AmS1VUaLgTRy47+zKtjTxz+0xMpx3I52i+aalBK1QP19ggLF3Db89KJX7kjfOfP2eoa01qc++GwPgufPg== +get-intrinsic@^1.0.1, get-intrinsic@^1.0.2, get-intrinsic@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.1.0.tgz#892e62931e6938c8a23ea5aaebcfb67bd97da97e" + integrity sha512-M11rgtQp5GZMZzDL7jLTNxbDfurpzuau5uqRWDPvlHjfvg3TdScAZo96GLvhMjImrmR8uAt0FS2RLoMrfWGKlg== dependencies: function-bind "^1.1.1" has "^1.0.3" @@ -2991,13 +2976,13 @@ inquirer@^5.0.0: through "^2.3.6" internal-slot@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/internal-slot/-/internal-slot-1.0.2.tgz#9c2e9fb3cd8e5e4256c6f45fe310067fcfa378a3" - integrity sha512-2cQNfwhAfJIkU4KZPkDI+Gj5yNNnbqi40W9Gge6dfnk4TocEVm00B3bdiL+JINrbGJil2TeHvM4rETGzk/f/0g== + version "1.0.3" + resolved "https://registry.yarnpkg.com/internal-slot/-/internal-slot-1.0.3.tgz#7347e307deeea2faac2ac6205d4bc7d34967f59c" + integrity sha512-O0DB1JC/sPyZl7cIo78n5dR7eUSwwpYPiXRhTzNxZVAMUuB8vlnRFyLxdrVToks6XPLVnFfbzaVd5WLjhgg+vA== dependencies: - es-abstract "^1.17.0-next.1" + get-intrinsic "^1.1.0" has "^1.0.3" - side-channel "^1.0.2" + side-channel "^1.0.4" interpret@^1.0.0: version "1.4.0" @@ -3171,7 +3156,7 @@ is-installed-globally@^0.1.0: global-dirs "^0.1.0" is-path-inside "^1.0.0" -is-negative-zero@^2.0.0: +is-negative-zero@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/is-negative-zero/-/is-negative-zero-2.0.1.tgz#3de746c18dda2319241a53675908d8f766f11c24" integrity sha512-2z6JzQvZRa9A2Y7xC6dQQm4FSTSTNWjKIYYTt4246eMTJmIo0Q+ZyOsU66X8lxK1AbB92dFeglPLrhwpeRKO6w== @@ -3401,12 +3386,12 @@ jsprim@^1.2.2: verror "1.10.0" "jsx-ast-utils@^2.4.1 || ^3.0.0", jsx-ast-utils@^3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-3.1.0.tgz#642f1d7b88aa6d7eb9d8f2210e166478444fa891" - integrity sha512-d4/UOjg+mxAWxCiF0c5UTSwyqbchkbqCvK87aBovhnh8GtysTjWmgC63tY0cJx/HzGgm9qnA147jVBdpOiQ2RA== + version "3.2.0" + resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-3.2.0.tgz#41108d2cec408c3453c1bbe8a4aae9e1e2bd8f82" + integrity sha512-EIsmt3O3ljsU6sot/J4E1zDRxfBNrhjyf/OKjlydwgEimQuznlM4Wv7U+ueONJMyEn1WRE0K8dhi3dVAXYT24Q== dependencies: - array-includes "^3.1.1" - object.assign "^4.1.1" + array-includes "^3.1.2" + object.assign "^4.1.2" kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.2.0: version "3.2.2" @@ -3663,17 +3648,17 @@ miller-rabin@^4.0.0: bn.js "^4.0.0" brorand "^1.0.1" -mime-db@1.44.0: - version "1.44.0" - resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.44.0.tgz#fa11c5eb0aca1334b4233cb4d52f10c5a6272f92" - integrity sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg== +mime-db@1.45.0: + version "1.45.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.45.0.tgz#cceeda21ccd7c3a745eba2decd55d4b73e7879ea" + integrity sha512-CkqLUxUk15hofLoLyljJSrukZi8mAtgd+yE5uO4tqRZsdsAJKv0O+rFMhVDRJgozy+yG6md5KwuXhD4ocIoP+w== mime-types@^2.1.12, mime-types@~2.1.19: - version "2.1.27" - resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.27.tgz#47949f98e279ea53119f5722e0f34e529bec009f" - integrity sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w== + version "2.1.28" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.28.tgz#1160c4757eab2c5363888e005273ecf79d2a0ecd" + integrity sha512-0TO2yJ5YHYr7M2zzT7gDU1tbwHxEUWBCLt0lscSNpcdAfFyJOVEpRYNS7EXVcTLNj/25QO8gulHC5JtTzSE2UQ== dependencies: - mime-db "1.44.0" + mime-db "1.45.0" mimic-fn@^1.0.0: version "1.2.0" @@ -3932,7 +3917,7 @@ object-copy@^0.1.0: define-property "^0.2.5" kind-of "^3.0.3" -object-inspect@^1.8.0: +object-inspect@^1.9.0: version "1.9.0" resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.9.0.tgz#c90521d74e1127b67266ded3394ad6116986533a" integrity sha512-i3Bp9iTqwhaLZBxGkRfo5ZbE07BQRT7MGu8+nNgwW9ItGp1TzCTw2DLEoWwjClxBjOFI/hWljTAmYGCEwmtnOw== @@ -3949,7 +3934,7 @@ object-visit@^1.0.0: dependencies: isobject "^3.0.0" -object.assign@^4.1.1: +object.assign@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.1.2.tgz#0ed54a342eceb37b38ff76eb831a0e788cb63940" integrity sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ== @@ -4554,12 +4539,12 @@ regex-not@^1.0.0, regex-not@^1.0.2: safe-regex "^1.1.0" regexp.prototype.flags@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.3.0.tgz#7aba89b3c13a64509dabcf3ca8d9fbb9bdf5cb75" - integrity sha512-2+Q0C5g951OlYlJz6yu5/M33IcsESLlLfsyIaLJaG4FA2r4yP8MvVMJUUP/fVBkSpbbbZlS5gynbEWLipiiXiQ== + version "1.3.1" + resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.3.1.tgz#7ef352ae8d159e758c0eadca6f8fcb4eef07be26" + integrity sha512-JiBdRBq91WlY7uRJ0ds7R+dU02i6LKi8r3BuQhNXn+kmeLN+EfHhfjqMRis1zJxnlu88hq/4dx0P2OP3APRTOA== dependencies: + call-bind "^1.0.2" define-properties "^1.1.3" - es-abstract "^1.17.0-next.1" regexpp@^1.0.1: version "1.1.0" @@ -4929,13 +4914,14 @@ shelljs@^0.8.0: interpret "^1.0.0" rechoir "^0.6.2" -side-channel@^1.0.2, side-channel@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.3.tgz#cdc46b057550bbab63706210838df5d4c19519c3" - integrity sha512-A6+ByhlLkksFoUepsGxfj5x1gTSrs+OydsRptUxeNCabQpCFUvcwIczgOigI8vhY/OJCnPnyE9rGiwgvr9cS1g== +side-channel@^1.0.3, side-channel@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf" + integrity sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw== dependencies: - es-abstract "^1.18.0-next.0" - object-inspect "^1.8.0" + call-bind "^1.0.0" + get-intrinsic "^1.0.2" + object-inspect "^1.9.0" signal-exit@^3.0.0, signal-exit@^3.0.2: version "3.0.3" @@ -5155,7 +5141,7 @@ string.prototype.matchall@^4.0.2: regexp.prototype.flags "^1.3.0" side-channel "^1.0.3" -string.prototype.trimend@^1.0.1: +string.prototype.trimend@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.3.tgz#a22bd53cca5c7cf44d7c9d5c732118873d6cd18b" integrity sha512-ayH0pB+uf0U28CtjlLvL7NaohvR1amUvVZk+y3DYb0Ey2PUV5zPkkKy9+U1ndVEIXO8hNg18eIv9Jntbii+dKw== @@ -5163,7 +5149,7 @@ string.prototype.trimend@^1.0.1: call-bind "^1.0.0" define-properties "^1.1.3" -string.prototype.trimstart@^1.0.1: +string.prototype.trimstart@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/string.prototype.trimstart/-/string.prototype.trimstart-1.0.3.tgz#9b4cb590e123bb36564401d59824298de50fd5aa" integrity sha512-oBIBUy5lea5tt0ovtOFiEQaBkoBBkyJhZXzJYrSmDo5IUUqbOPvVezuRs/agBIdZ2p2Eo1FD6bD9USyBLfl3xg== @@ -5521,9 +5507,9 @@ update-notifier@^2.3.0: xdg-basedir "^3.0.0" uri-js@^4.2.2: - version "4.4.0" - resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.0.tgz#aa714261de793e8a82347a7bcc9ce74e86f28602" - integrity sha512-B0yRTzYdUCCn9n+F4+Gh4yIDtMQcaJsmYBDsTSG8g/OejKBodLQ2IHfN3bM7jUsRXndopT7OIXWdYqc1fjmV6g== + version "4.4.1" + resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e" + integrity sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg== dependencies: punycode "^2.1.0" @@ -5742,9 +5728,9 @@ xtend@^4.0.0: integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ== y18n@^3.2.1: - version "3.2.1" - resolved "https://registry.yarnpkg.com/y18n/-/y18n-3.2.1.tgz#6d15fba884c08679c0d77e88e7759e811e07fa41" - integrity sha1-bRX7qITAhnnA136I53WegR4H+kE= + version "3.2.2" + resolved "https://registry.yarnpkg.com/y18n/-/y18n-3.2.2.tgz#85c901bd6470ce71fc4bb723ad209b70f7f28696" + integrity sha512-uGZHXkHnhF0XeeAPgnKfPv1bgKAYyVvmNL1xlKsPYZPaIHxGti2hHqvOCQv71XMsLxu1QjergkqogUnms5D3YQ== y18n@^4.0.0: version "4.0.1" From 6981eee25bc8df850e3c75c7ff31dbc4d7d2f969 Mon Sep 17 00:00:00 2001 From: sokmean-mptc Date: Sun, 31 Jan 2021 17:44:44 +0700 Subject: [PATCH 3/9] # --- inc/Blocks/SCFor.php | 117 +++++++++++++++++++++++++++++++++++++++ inc/Blocks/SCUnion.php | 75 +++++++++++++++++++++++++ inc/Init.php | 4 +- src/blocks.js | 4 +- src/sc-for/block.js | 93 +++++++++++++++++++++++++++++++ src/sc-for/editor.scss | 16 ++++++ src/sc-for/style.scss | 14 +++++ src/sc-union/block.js | 93 +++++++++++++++++++++++++++++++ src/sc-union/editor.scss | 16 ++++++ src/sc-union/style.scss | 14 +++++ 10 files changed, 444 insertions(+), 2 deletions(-) create mode 100644 inc/Blocks/SCFor.php create mode 100644 inc/Blocks/SCUnion.php create mode 100644 src/sc-for/block.js create mode 100644 src/sc-for/editor.scss create mode 100644 src/sc-for/style.scss create mode 100644 src/sc-union/block.js create mode 100644 src/sc-union/editor.scss create mode 100644 src/sc-union/style.scss diff --git a/inc/Blocks/SCFor.php b/inc/Blocks/SCFor.php new file mode 100644 index 0000000..d9ded50 --- /dev/null +++ b/inc/Blocks/SCFor.php @@ -0,0 +1,117 @@ +plugin_name . '/sc-for', array( + 'style' => $this->plugin_name . '-style', + 'editor_script' => $this->plugin_name . '-js', + 'editor_style' => $this->plugin_name . '-editor-css', + 'render_callback' => array( $this, 'renderPostsBlock' ), + 'attributes' => array( + 'api' => array( + 'type' => 'string', + 'default' => '' + ), + 'union' => array( + 'type' => 'string', + 'default' => '' + ), + 'page' => array( + 'type' => 'string', + 'default' => '' + ) + ) + ) + ); + } + public function renderPostsBlock( $attributes ) { + ob_start(); + + $column = 3; + $api = $attributes['api']; + echo ( + ' +
+
+ + + + ' + ); + + foreach ( $this->getDistantTerms( $api ) as $key => $term ) { + printf( + ' + + ', + $term->icon, + $attributes['page'], + $term->id, + $attributes['union'], + $term->name, + $term->description + ); + if ( ( ( $key + 1 ) % $column ) === 0 ) { + echo ''; + } + + } + + echo ( '
+ +
' ); + + return ob_get_clean(); + } + public function getDistantTerms( $api = '' ) { + $response = wp_remote_get( $api ); + if(is_wp_error($response)) { + return array(); + } + return json_decode(wp_remote_retrieve_body($response)); + } +} + diff --git a/inc/Blocks/SCUnion.php b/inc/Blocks/SCUnion.php new file mode 100644 index 0000000..6c96c17 --- /dev/null +++ b/inc/Blocks/SCUnion.php @@ -0,0 +1,75 @@ +plugin_name . '/sc-union', array( + 'style' => $this->plugin_name . '-style', + 'editor_script' => $this->plugin_name . '-js', + 'editor_style' => $this->plugin_name . '-editor-css', + 'render_callback' => array( $this, 'renderPostsBlock' ), + 'attributes' => array( + 'api' => array( + 'type' => 'string', + 'default' => '' + ), + 'union' => array( + 'type' => 'string', + 'default' => '' + ), + 'page' => array( + 'type' => 'string', + 'default' => '' + ) + ) + ) + ); + } + public function renderPostsBlock( $attributes ) { + ob_start(); + + echo '
'; + echo ( $this->getDistantTerms( $attributes['api'] )); + echo '
'; + + return ob_get_clean(); + } + public function getDistantTerms( $api = '' ) { + $response = wp_remote_get( $api ); + if(is_wp_error($response)) { + return array(); + } + return json_decode(wp_remote_retrieve_body($response)); + } +} + diff --git a/inc/Init.php b/inc/Init.php index ef08f16..10e4113 100644 --- a/inc/Init.php +++ b/inc/Init.php @@ -23,7 +23,9 @@ public static function getServices() { RegisterAsset::class, Blocks\Services::class, Blocks\SCLists::class, - Blocks\SCDetail::class + Blocks\SCDetail::class, + Blocks\SCFor::class, + Blocks\SCUnion::class ); } diff --git a/src/blocks.js b/src/blocks.js index 7c0e41e..c715251 100644 --- a/src/blocks.js +++ b/src/blocks.js @@ -9,7 +9,9 @@ * Webpack is compiling as the input file. */ -import './services/block'; +import './services/block' import './sc-lists/block' import './sc-detail/block' +import './sc-for/block' +import './sc-union/block' // import './block-service-content/block.js'; diff --git a/src/sc-for/block.js b/src/sc-for/block.js new file mode 100644 index 0000000..74cb6b8 --- /dev/null +++ b/src/sc-for/block.js @@ -0,0 +1,93 @@ +import './style.scss' +import './editor.scss' +const { __ } = wp.i18n +import MarkText from '../components/MarkText.jsx' +const { registerBlockType } = wp.blocks +const { InspectorControls } = wp.blockEditor +const { PanelBody, __experimentalNumberControl : NumberControl, __experimentalInputControl : InputControl } = wp.components +const { Fragment } = wp.element +registerBlockType( 'digital-blocks/sc-for', { + title: __( 'Serivce Cambodia For', 'CEGOV' ), + icon: 'admin-page', + category: 'digital-blocks', + keywords: [ + __( 'service', 'CEGOV' ), + __( 'cambodia', 'CEGOV' ), + __( 'for', 'CEGOV' ), + __( 'egov block', 'CEGOV' ) + ], + attributes: { + mark_text: { + type: 'string', + default: 'Service Cambodia For' + }, + toggle_panel: { + type: 'boolean', + default: false + }, + api: { + type: 'string', + default: '' + }, + union: { + type: 'string', + default: '' + }, + page: { + type: 'string', + default: '' + } + }, + edit: ( { attributes, setAttributes } ) => { + const { + mark_text, + toggle_panel, + api, + union, + page + } = attributes + + return ( + + + + + + { + setAttributes( { toggle_panel: ! toggle_panel } ) + } } + > + setAttributes( { api: value } ) } + /> + setAttributes( { union: value } ) } + /> + setAttributes( { page: value } ) } + /> + + +
+ { mark_text } +
+
+ ) + }, + + save: ( { attributes } ) => { + return null + } +} ) \ No newline at end of file diff --git a/src/sc-for/editor.scss b/src/sc-for/editor.scss new file mode 100644 index 0000000..db9c0ed --- /dev/null +++ b/src/sc-for/editor.scss @@ -0,0 +1,16 @@ +/** + * #.# Editor Styles + * + * CSS for just Backend enqueued after style.scss + * which makes it higher in priority. + */ + +.wp-block-cgb-block-digital-blocks { + background: $green; + border: 0.2rem solid $black; + color: $black; + margin: 0 auto; + max-width: 740px; + padding: 2rem; +} + diff --git a/src/sc-for/style.scss b/src/sc-for/style.scss new file mode 100644 index 0000000..385d010 --- /dev/null +++ b/src/sc-for/style.scss @@ -0,0 +1,14 @@ +/** + * #.# Styles + * + * CSS for both Frontend+Backend. + */ + +.wp-block-cgb-block-digital-blocks { + background: $red; + border: 0.2rem solid $black; + color: $black; + margin: 0 auto; + max-width: 740px; + padding: 2rem; +} diff --git a/src/sc-union/block.js b/src/sc-union/block.js new file mode 100644 index 0000000..8a20412 --- /dev/null +++ b/src/sc-union/block.js @@ -0,0 +1,93 @@ +import './style.scss' +import './editor.scss' +const { __ } = wp.i18n +import MarkText from '../components/MarkText.jsx' +const { registerBlockType } = wp.blocks +const { InspectorControls } = wp.blockEditor +const { PanelBody, __experimentalNumberControl : NumberControl, __experimentalInputControl : InputControl } = wp.components +const { Fragment } = wp.element +registerBlockType( 'digital-blocks/sc-union', { + title: __( 'Serivce Cambodia Union', 'CEGOV' ), + icon: 'admin-page', + category: 'digital-blocks', + keywords: [ + __( 'service', 'CEGOV' ), + __( 'cambodia', 'CEGOV' ), + __( 'union', 'CEGOV' ), + __( 'egov block', 'CEGOV' ) + ], + attributes: { + mark_text: { + type: 'string', + default: 'Service Cambodia Union' + }, + toggle_panel: { + type: 'boolean', + default: false + }, + api: { + type: 'string', + default: '' + }, + union: { + type: 'string', + default: '' + }, + page: { + type: 'string', + default: '' + } + }, + edit: ( { attributes, setAttributes } ) => { + const { + mark_text, + toggle_panel, + api, + union, + page + } = attributes + + return ( + + + + + + { + setAttributes( { toggle_panel: ! toggle_panel } ) + } } + > + setAttributes( { api: value } ) } + /> + setAttributes( { union: value } ) } + /> + setAttributes( { page: value } ) } + /> + + +
+ { mark_text } +
+
+ ) + }, + + save: ( { attributes } ) => { + return null + } +} ) \ No newline at end of file diff --git a/src/sc-union/editor.scss b/src/sc-union/editor.scss new file mode 100644 index 0000000..db9c0ed --- /dev/null +++ b/src/sc-union/editor.scss @@ -0,0 +1,16 @@ +/** + * #.# Editor Styles + * + * CSS for just Backend enqueued after style.scss + * which makes it higher in priority. + */ + +.wp-block-cgb-block-digital-blocks { + background: $green; + border: 0.2rem solid $black; + color: $black; + margin: 0 auto; + max-width: 740px; + padding: 2rem; +} + diff --git a/src/sc-union/style.scss b/src/sc-union/style.scss new file mode 100644 index 0000000..385d010 --- /dev/null +++ b/src/sc-union/style.scss @@ -0,0 +1,14 @@ +/** + * #.# Styles + * + * CSS for both Frontend+Backend. + */ + +.wp-block-cgb-block-digital-blocks { + background: $red; + border: 0.2rem solid $black; + color: $black; + margin: 0 auto; + max-width: 740px; + padding: 2rem; +} From 46be5514afbf267b03812a5f6d760c5c381fcd11 Mon Sep 17 00:00:00 2001 From: sokmean-mptc Date: Mon, 1 Feb 2021 11:26:17 +0700 Subject: [PATCH 4/9] # --- inc/Base/BaseController.php | 10 ++++++++++ inc/Blocks/SCDetail.php | 33 +++++++++++++++------------------ inc/Blocks/SCFor.php | 15 +++++---------- inc/Blocks/SCLists.php | 9 +-------- inc/Blocks/SCUnion.php | 21 ++++++--------------- src/sc-for/block.js | 6 +++--- src/sc-union/block.js | 14 ++------------ 7 files changed, 42 insertions(+), 66 deletions(-) diff --git a/inc/Base/BaseController.php b/inc/Base/BaseController.php index 580249f..b93f500 100644 --- a/inc/Base/BaseController.php +++ b/inc/Base/BaseController.php @@ -24,4 +24,14 @@ public function __construct() { $this->plugin_url = plugin_dir_url( dirname( __FILE__, 2 ) ); $this->plugin = plugin_basename( dirname( __FILE__, 3 ) ); } + public function getDistantTerms( $api = '' ) { + $response = wp_remote_get( $api ); + if(is_wp_error($response)) { + return array(); + } + return json_decode(wp_remote_retrieve_body($response)); + } + public function baseUrlWithoutHttp(){ + return preg_replace('#^https?://#', '', get_home_url()); + } } \ No newline at end of file diff --git a/inc/Blocks/SCDetail.php b/inc/Blocks/SCDetail.php index ac2c78b..07a6836 100644 --- a/inc/Blocks/SCDetail.php +++ b/inc/Blocks/SCDetail.php @@ -42,33 +42,30 @@ public function registerBlock() { 'api' => array( 'type' => 'string', 'default' => '' - ), - 'item_to_show' => array( - 'type' => 'number', - 'default' => 8 ) ) ) ); } public function renderPostsBlock( $attributes ) { - ob_start(); - - echo '
'; - echo $this->getDistantTerms()->content->rendered; - echo '
'; - return ob_get_clean(); - } - public function getDistantTerms() { if ( ! isset( $_GET['service_id'] ) ) { - return []; + return; } $id = $_GET['service_id']; - $response = wp_remote_get('https://demo.cambodia.gov.kh/wp-json/wp/v2/service/'.$id); - if(is_wp_error($response)) { - return array(); - } - return json_decode(wp_remote_retrieve_body($response)); + $data = $this->getDistantTerms( 'https://demo.cambodia.gov.kh/wp-json/wp/v2/service/'.$id ); + ob_start(); + echo ' +
+
+

+ '.$data->title->rendered.' +

+
+
+ '; + echo $data->content->rendered; + return ob_get_clean(); } + } diff --git a/inc/Blocks/SCFor.php b/inc/Blocks/SCFor.php index d9ded50..249baa7 100644 --- a/inc/Blocks/SCFor.php +++ b/inc/Blocks/SCFor.php @@ -59,10 +59,11 @@ public function renderPostsBlock( $attributes ) { ob_start(); $column = 3; + $term_id = $attributes['union']; $api = $attributes['api']; echo ( ' -
+
@@ -70,7 +71,7 @@ public function renderPostsBlock( $attributes ) { ' ); - foreach ( $this->getDistantTerms( $api ) as $key => $term ) { + foreach ( $this->getDistantTerms( $api.'/'.$term_id ) as $key => $term ) { printf( '
@@ -92,7 +93,7 @@ public function renderPostsBlock( $attributes ) { $term->icon, $attributes['page'], $term->id, - $attributes['union'], + $term_id, $term->name, $term->description ); @@ -106,12 +107,6 @@ public function renderPostsBlock( $attributes ) { return ob_get_clean(); } - public function getDistantTerms( $api = '' ) { - $response = wp_remote_get( $api ); - if(is_wp_error($response)) { - return array(); - } - return json_decode(wp_remote_retrieve_body($response)); - } + } diff --git a/inc/Blocks/SCLists.php b/inc/Blocks/SCLists.php index d2bba0c..c788f24 100644 --- a/inc/Blocks/SCLists.php +++ b/inc/Blocks/SCLists.php @@ -60,18 +60,11 @@ public function renderPostsBlock( $attributes ) { // } echo ''; echo '
'; - foreach( $this->getDistantTerms() as $item ) { + foreach( $this->getDistantTerms( 'https://demo.cambodia.gov.kh/wp-json/wp/v2/service?service-topic=316' ) as $item ) { echo '

'.$item->title->rendered.'

'; } echo '
'; return ob_get_clean(); } - public function getDistantTerms() { - $response = wp_remote_get('https://demo.cambodia.gov.kh/wp-json/wp/v2/service?service-topic=316'); - if(is_wp_error($response)) { - return array(); - } - return json_decode(wp_remote_retrieve_body($response)); - } } diff --git a/inc/Blocks/SCUnion.php b/inc/Blocks/SCUnion.php index 6c96c17..7b96c81 100644 --- a/inc/Blocks/SCUnion.php +++ b/inc/Blocks/SCUnion.php @@ -43,10 +43,6 @@ public function registerBlock() { 'type' => 'string', 'default' => '' ), - 'union' => array( - 'type' => 'string', - 'default' => '' - ), 'page' => array( 'type' => 'string', 'default' => '' @@ -56,20 +52,15 @@ public function registerBlock() { ); } public function renderPostsBlock( $attributes ) { + $api = $attributes['api']; + $service_topic = $_GET['topic']; + $service_for = $_GET['for']; + $des_page_slug = $attributes['page']; ob_start(); - - echo '
'; - echo ( $this->getDistantTerms( $attributes['api'] )); - echo '
'; + + echo ( $this->getDistantTerms( $api.'/topic='.$service_topic.'/for='.$service_for.'/base='.$this->baseUrlWithoutHttp().'/page='.$des_page_slug )); return ob_get_clean(); } - public function getDistantTerms( $api = '' ) { - $response = wp_remote_get( $api ); - if(is_wp_error($response)) { - return array(); - } - return json_decode(wp_remote_retrieve_body($response)); - } } diff --git a/src/sc-for/block.js b/src/sc-for/block.js index 74cb6b8..06dc199 100644 --- a/src/sc-for/block.js +++ b/src/sc-for/block.js @@ -64,17 +64,17 @@ registerBlockType( 'digital-blocks/sc-for', { } } > setAttributes( { api: value } ) } /> setAttributes( { union: value } ) } /> setAttributes( { page: value } ) } /> diff --git a/src/sc-union/block.js b/src/sc-union/block.js index 8a20412..8734f89 100644 --- a/src/sc-union/block.js +++ b/src/sc-union/block.js @@ -29,10 +29,6 @@ registerBlockType( 'digital-blocks/sc-union', { type: 'string', default: '' }, - union: { - type: 'string', - default: '' - }, page: { type: 'string', default: '' @@ -43,7 +39,6 @@ registerBlockType( 'digital-blocks/sc-union', { mark_text, toggle_panel, api, - union, page } = attributes @@ -64,17 +59,12 @@ registerBlockType( 'digital-blocks/sc-union', { } } > setAttributes( { api: value } ) } /> setAttributes( { union: value } ) } - /> - setAttributes( { page: value } ) } /> From 3aa0382ff7d9d6afe7b940fb76081499e3863375 Mon Sep 17 00:00:00 2001 From: sokmean-mptc Date: Mon, 1 Feb 2021 11:30:28 +0700 Subject: [PATCH 5/9] # --- inc/Blocks/SCLists.php | 70 -------------------------------------- inc/Init.php | 1 - src/blocks.js | 1 - src/sc-lists/block.js | 72 ---------------------------------------- src/sc-lists/editor.scss | 16 --------- src/sc-lists/style.scss | 14 -------- 6 files changed, 174 deletions(-) delete mode 100644 inc/Blocks/SCLists.php delete mode 100644 src/sc-lists/block.js delete mode 100644 src/sc-lists/editor.scss delete mode 100644 src/sc-lists/style.scss diff --git a/inc/Blocks/SCLists.php b/inc/Blocks/SCLists.php deleted file mode 100644 index c788f24..0000000 --- a/inc/Blocks/SCLists.php +++ /dev/null @@ -1,70 +0,0 @@ -plugin_name . '/sc-lists', array( - 'style' => $this->plugin_name . '-style', - 'editor_script' => $this->plugin_name . '-js', - 'editor_style' => $this->plugin_name . '-editor-css', - 'render_callback' => array( $this, 'renderPostsBlock' ), - 'attributes' => array( - 'api' => array( - 'type' => 'string', - 'default' => '' - ), - 'item_to_show' => array( - 'type' => 'number', - 'default' => 8 - ) - ) - ) - ); - } - public function renderPostsBlock( $attributes ) { - ob_start(); - echo '
';
-        // print_r( $this->getDistantTerms() );
-        // foreach( $this->getDistantTerms() as $item ) {
-        //     print_r( $item->content->rendered );
-        // }
-        echo '
'; - echo '
'; - foreach( $this->getDistantTerms( 'https://demo.cambodia.gov.kh/wp-json/wp/v2/service?service-topic=316' ) as $item ) { - echo '

'.$item->title->rendered.'

'; - } - echo '
'; - return ob_get_clean(); - } -} - diff --git a/inc/Init.php b/inc/Init.php index 10e4113..db08c87 100644 --- a/inc/Init.php +++ b/inc/Init.php @@ -22,7 +22,6 @@ public static function getServices() { LoadSettings::class, RegisterAsset::class, Blocks\Services::class, - Blocks\SCLists::class, Blocks\SCDetail::class, Blocks\SCFor::class, Blocks\SCUnion::class diff --git a/src/blocks.js b/src/blocks.js index c715251..c765b20 100644 --- a/src/blocks.js +++ b/src/blocks.js @@ -10,7 +10,6 @@ */ import './services/block' -import './sc-lists/block' import './sc-detail/block' import './sc-for/block' import './sc-union/block' diff --git a/src/sc-lists/block.js b/src/sc-lists/block.js deleted file mode 100644 index 04b8f6a..0000000 --- a/src/sc-lists/block.js +++ /dev/null @@ -1,72 +0,0 @@ -import './style.scss' -import './editor.scss' -const { __ } = wp.i18n -import MarkText from '../components/MarkText.jsx' -const { registerBlockType } = wp.blocks -const { InspectorControls } = wp.blockEditor -const { PanelBody, __experimentalNumberControl : NumberControl, __experimentalInputControl : InputControl } = wp.components -const { Fragment } = wp.element -registerBlockType( 'digital-blocks/sc-lists', { - title: __( 'Serivce Cambodia Lists', 'CEGOV' ), - icon: 'admin-page', - category: 'digital-blocks', - keywords: [ - __( 'service', 'CEGOV' ), - __( 'cambodia', 'CEGOV' ), - __( 'egov block', 'CEGOV' ) - ], - attributes: { - mark_text: { - type: 'string', - default: 'Service Cambodia Lists' - }, - toggle_panel: { - type: 'boolean', - default: false - }, - api: { - type: 'string', - default: '' - } - }, - edit: ( { attributes, setAttributes } ) => { - const { - mark_text, - toggle_panel, - api - } = attributes - - return ( - - - - - - { - setAttributes( { toggle_panel: ! toggle_panel } ) - } } - > - setAttributes( { api: value } ) } - /> - - -
- { mark_text } -
-
- ) - }, - - save: ( { attributes } ) => { - return null - } -} ) \ No newline at end of file diff --git a/src/sc-lists/editor.scss b/src/sc-lists/editor.scss deleted file mode 100644 index db9c0ed..0000000 --- a/src/sc-lists/editor.scss +++ /dev/null @@ -1,16 +0,0 @@ -/** - * #.# Editor Styles - * - * CSS for just Backend enqueued after style.scss - * which makes it higher in priority. - */ - -.wp-block-cgb-block-digital-blocks { - background: $green; - border: 0.2rem solid $black; - color: $black; - margin: 0 auto; - max-width: 740px; - padding: 2rem; -} - diff --git a/src/sc-lists/style.scss b/src/sc-lists/style.scss deleted file mode 100644 index 385d010..0000000 --- a/src/sc-lists/style.scss +++ /dev/null @@ -1,14 +0,0 @@ -/** - * #.# Styles - * - * CSS for both Frontend+Backend. - */ - -.wp-block-cgb-block-digital-blocks { - background: $red; - border: 0.2rem solid $black; - color: $black; - margin: 0 auto; - max-width: 740px; - padding: 2rem; -} From 736648accdf62bd4e947cbba9581b8c79708bc25 Mon Sep 17 00:00:00 2001 From: sokmean-mptc Date: Tue, 2 Feb 2021 13:47:16 +0700 Subject: [PATCH 6/9] # --- inc/Blocks/SCDetail.php | 2 +- src/blocks.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/inc/Blocks/SCDetail.php b/inc/Blocks/SCDetail.php index 07a6836..fb141e0 100644 --- a/inc/Blocks/SCDetail.php +++ b/inc/Blocks/SCDetail.php @@ -55,7 +55,7 @@ public function renderPostsBlock( $attributes ) { $data = $this->getDistantTerms( 'https://demo.cambodia.gov.kh/wp-json/wp/v2/service/'.$id ); ob_start(); echo ' -
+

'.$data->title->rendered.' diff --git a/src/blocks.js b/src/blocks.js index c765b20..e201a63 100644 --- a/src/blocks.js +++ b/src/blocks.js @@ -13,4 +13,3 @@ import './services/block' import './sc-detail/block' import './sc-for/block' import './sc-union/block' -// import './block-service-content/block.js'; From 0dc0553764b39832d20c4f3a1c8d999667a93681 Mon Sep 17 00:00:00 2001 From: sokmean-mptc Date: Tue, 2 Feb 2021 14:52:50 +0700 Subject: [PATCH 7/9] # --- inc/Blocks/SCUnion.php | 3 +++ src/sc-detail/block.js | 21 +-------------------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/inc/Blocks/SCUnion.php b/inc/Blocks/SCUnion.php index 7b96c81..63f78cf 100644 --- a/inc/Blocks/SCUnion.php +++ b/inc/Blocks/SCUnion.php @@ -56,6 +56,9 @@ public function renderPostsBlock( $attributes ) { $service_topic = $_GET['topic']; $service_for = $_GET['for']; $des_page_slug = $attributes['page']; + if ( !$api || !$service_for || !$service_topic || !$des_page_slug ) { + return; + } ob_start(); echo ( $this->getDistantTerms( $api.'/topic='.$service_topic.'/for='.$service_for.'/base='.$this->baseUrlWithoutHttp().'/page='.$des_page_slug )); diff --git a/src/sc-detail/block.js b/src/sc-detail/block.js index 8349fa2..2a4bd00 100644 --- a/src/sc-detail/block.js +++ b/src/sc-detail/block.js @@ -23,17 +23,11 @@ registerBlockType( 'digital-blocks/sc-detail', { toggle_panel: { type: 'boolean', default: false - }, - api: { - type: 'string', - default: '' } }, edit: ( { attributes, setAttributes } ) => { const { - mark_text, - toggle_panel, - api + mark_text } = attributes return ( @@ -45,19 +39,6 @@ registerBlockType( 'digital-blocks/sc-detail', { setAttributes={setAttributes} /> - { - setAttributes( { toggle_panel: ! toggle_panel } ) - } } - > - setAttributes( { api: value } ) } - /> -
{ mark_text } From 4ba5b9365eb20243d4290cc7c236e7431e61bdee Mon Sep 17 00:00:00 2001 From: sokmean-mptc Date: Thu, 4 Feb 2021 17:49:34 +0700 Subject: [PATCH 8/9] # --- inc/Blocks/SCFor.php | 17 ++++++++++++----- inc/Blocks/SCUnion.php | 3 ++- src/sc-for/block.js | 20 +++++++++++++++----- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/inc/Blocks/SCFor.php b/inc/Blocks/SCFor.php index 249baa7..8275d99 100644 --- a/inc/Blocks/SCFor.php +++ b/inc/Blocks/SCFor.php @@ -43,7 +43,11 @@ public function registerBlock() { 'type' => 'string', 'default' => '' ), - 'union' => array( + 'service_for' => array( + 'type' => 'string', + 'default' => '' + ), + 'service_level' => array( 'type' => 'string', 'default' => '' ), @@ -59,8 +63,10 @@ public function renderPostsBlock( $attributes ) { ob_start(); $column = 3; - $term_id = $attributes['union']; + $service_for = $attributes['service_for']; + $service_level = $attributes['service_level']; $api = $attributes['api']; + $get_fetch = $this->getDistantTerms( $api.'/for='.$service_for.'/level='.$service_level ); echo ( '
@@ -71,7 +77,7 @@ public function renderPostsBlock( $attributes ) { ' ); - foreach ( $this->getDistantTerms( $api.'/'.$term_id ) as $key => $term ) { + foreach ( $get_fetch as $key => $term ) { printf( '

@@ -81,7 +87,7 @@ public function renderPostsBlock( $attributes ) {
- +
%s

%s

@@ -93,7 +99,8 @@ public function renderPostsBlock( $attributes ) { $term->icon, $attributes['page'], $term->id, - $term_id, + $service_for, + $service_level, $term->name, $term->description ); diff --git a/inc/Blocks/SCUnion.php b/inc/Blocks/SCUnion.php index 63f78cf..3fa9cca 100644 --- a/inc/Blocks/SCUnion.php +++ b/inc/Blocks/SCUnion.php @@ -55,13 +55,14 @@ public function renderPostsBlock( $attributes ) { $api = $attributes['api']; $service_topic = $_GET['topic']; $service_for = $_GET['for']; + $service_level = $_GET['level']; $des_page_slug = $attributes['page']; if ( !$api || !$service_for || !$service_topic || !$des_page_slug ) { return; } ob_start(); - echo ( $this->getDistantTerms( $api.'/topic='.$service_topic.'/for='.$service_for.'/base='.$this->baseUrlWithoutHttp().'/page='.$des_page_slug )); + echo ( $this->getDistantTerms( $api.'/topic='.$service_topic.'/for='.$service_for.'/level='.$service_level.'/base='.$this->baseUrlWithoutHttp().'/page='.$des_page_slug )); return ob_get_clean(); } diff --git a/src/sc-for/block.js b/src/sc-for/block.js index 06dc199..4f314dc 100644 --- a/src/sc-for/block.js +++ b/src/sc-for/block.js @@ -29,7 +29,11 @@ registerBlockType( 'digital-blocks/sc-for', { type: 'string', default: '' }, - union: { + service_for: { + type: 'string', + default: '' + }, + service_level: { type: 'string', default: '' }, @@ -43,7 +47,8 @@ registerBlockType( 'digital-blocks/sc-for', { mark_text, toggle_panel, api, - union, + service_for, + service_level, page } = attributes @@ -69,9 +74,14 @@ registerBlockType( 'digital-blocks/sc-for', { onChange={ ( value ) => setAttributes( { api: value } ) } /> setAttributes( { union: value } ) } + label={ __( 'Service For (ID)', 'CEGOV' ) } + value={ service_for } + onChange={ ( value ) => setAttributes( { service_for: value } ) } + /> + setAttributes( { service_level: value } ) } /> Date: Fri, 16 Apr 2021 17:29:29 +0700 Subject: [PATCH 9/9] # --- inc/Blocks/SCUnion.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inc/Blocks/SCUnion.php b/inc/Blocks/SCUnion.php index 3fa9cca..6557986 100644 --- a/inc/Blocks/SCUnion.php +++ b/inc/Blocks/SCUnion.php @@ -53,12 +53,12 @@ public function registerBlock() { } public function renderPostsBlock( $attributes ) { $api = $attributes['api']; - $service_topic = $_GET['topic']; - $service_for = $_GET['for']; - $service_level = $_GET['level']; + $service_topic = isset( $_GET['topic'] ) ? $_GET['topic'] : ''; + $service_for = isset( $_GET['for'] ) ? $_GET['for'] : ''; + $service_level = isset( $_GET['level'] ) ? $_GET['level'] : ''; $des_page_slug = $attributes['page']; if ( !$api || !$service_for || !$service_topic || !$des_page_slug ) { - return; + return ob_get_clean(); } ob_start();