diff --git a/src/module-magespices-core/etc/adminhtml/system.xml b/src/module-magespices-core/etc/adminhtml/system.xml index b5187a7..ea96b55 100644 --- a/src/module-magespices-core/etc/adminhtml/system.xml +++ b/src/module-magespices-core/etc/adminhtml/system.xml @@ -16,7 +16,7 @@
separator-top - + magespices MageSpices_Core::config element; + } + + /** + * Set an element + * + * @param AbstractElement $element + * @return $this + */ + public function setElement(AbstractElement $element) + { + $this->element = $element; + + return $this; + } + + /** + * Render element + * + * @param AbstractElement $element + * @return string + */ + public function render(AbstractElement $element) + { + $this->element = $element; + + return $this->toHtml(); + } + + /** + * @return string + */ + public function getHtmlId() + { + return $this->_htmlId; + } + + /** + * @return string + */ + public function getNameFrom() + { + return str_replace("/", "_", self::BASE_CONFIG_PATH).self::TIME_NAME_FROM; + } + + /** + * @return string + */ + public function getNameTo() + { + return str_replace("/", "_", self::BASE_CONFIG_PATH).self::TIME_NAME_TO; + } + + public function getTimeFrom() + { + return $this->_scopeConfig->getValue(self::BASE_CONFIG_PATH.self::TIME_NAME_FROM); + } + + public function getTimeTo() + { + return $this->_scopeConfig->getValue(self::BASE_CONFIG_PATH.self::TIME_NAME_TO); + } + + /** + * @param int $minutes + * @return string + */ + public function minutesToTime($minutes) + { + $hours = floor($minutes / 60); + $minutes = $minutes % 60; + $part = $hours >= 12 ? 'PM' : 'AM'; + + return sprintf('%02d:%02d %s', $hours, $minutes, $part); + } + + /** + * @return string + * @throws ValidatorException + */ + protected function _toHtml() + { + if (!$this->getTemplate()) { + return ''; + } + + return $this->fetchView($this->getTemplateFile()); + } +} \ No newline at end of file diff --git a/src/module-magespices-mage2dark/Model/Config/FrontendModel/TimeSlider.php b/src/module-magespices-mage2dark/Model/Config/FrontendModel/TimeSlider.php new file mode 100644 index 0000000..49dadff --- /dev/null +++ b/src/module-magespices-mage2dark/Model/Config/FrontendModel/TimeSlider.php @@ -0,0 +1,27 @@ +getLayout()->createBlock( + \MageSpices\Mage2Dark\Block\Adminhtml\Config\TimeSlider::class + ); + $renderer->setElement($element); + + return $renderer->toHtml(); + } +} \ No newline at end of file diff --git a/src/module-magespices-mage2dark/Model/Config/Source/Selection.php b/src/module-magespices-mage2dark/Model/Config/Source/Selection.php new file mode 100644 index 0000000..ec75129 --- /dev/null +++ b/src/module-magespices-mage2dark/Model/Config/Source/Selection.php @@ -0,0 +1,25 @@ + "auto", + "label" => __("Auto") + ], + [ + "value" => "dark", + "label" => __("Dark") + ], + [ + "value" => "light", + "label" => __("Light") + ] + ]; + } +} \ No newline at end of file diff --git a/src/module-magespices-mage2dark/Plugin/Model/View/Design.php b/src/module-magespices-mage2dark/Plugin/Model/View/Design.php new file mode 100644 index 0000000..76d9c2b --- /dev/null +++ b/src/module-magespices-mage2dark/Plugin/Model/View/Design.php @@ -0,0 +1,69 @@ +scopeConfig = $scopeConfig; + $this->timeZone = $timezone; + } + + /** + * @param \Magento\Theme\Model\View\Design $subject + * @param string|null $area + * @param $result + * @return string + */ + public function afterGetConfigurationDesignTheme( + \Magento\Theme\Model\View\Design $subject, + $result, + $area = null + ) { + if (!$area) { + $area = $subject->getArea(); + } + if ($area == Area::AREA_ADMINHTML && $this->getThemeSelectionConfig() == "dark") { + return "MageSpices/Mage2Dark"; + } + return $result; + } + + protected function getThemeSelectionConfig() + { + if (!$this->themeSelectionConfig) { + $this->themeSelectionConfig = $this->getConfig('theme_selection'); + if ($this->themeSelectionConfig == "auto") { + $currentDate = $this->timeZone->date(); + $currentTime = ($currentDate->format("H")*60)+$currentDate->format("i"); + $lightThemeStartTime = $this->getConfig("light_theme_time_from"); + $lightThemeEndTime = $this->getConfig("light_theme_time_to"); + if ($currentTime >= $lightThemeStartTime && $currentTime <= $lightThemeEndTime) { + $this->themeSelectionConfig = "light"; + } else { + $this->themeSelectionConfig = "dark"; + } + } + } + return $this->themeSelectionConfig; + } + + protected function getConfig($path) + { + return $this->scopeConfig->getValue(self::BASE_CONFIG_PATH.$path); + } +} \ No newline at end of file diff --git a/src/module-magespices-mage2dark/etc/adminhtml/di.xml b/src/module-magespices-mage2dark/etc/adminhtml/di.xml new file mode 100644 index 0000000..41e00d8 --- /dev/null +++ b/src/module-magespices-mage2dark/etc/adminhtml/di.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/module-magespices-mage2dark/etc/adminhtml/system.xml b/src/module-magespices-mage2dark/etc/adminhtml/system.xml new file mode 100644 index 0000000..7da9636 --- /dev/null +++ b/src/module-magespices-mage2dark/etc/adminhtml/system.xml @@ -0,0 +1,43 @@ + + + + +
+ + + + MageSpices\Mage2Dark\Model\Config\Source\Selection + If "Auto" is selected, then please select time slot for light theme from next setting and outside of that time slot Dark theme will be in use. + + + + MageSpices\Mage2Dark\Model\Config\FrontendModel\TimeSlider + + auto + + + + + + auto + + + + + + auto + + + +
+
+
diff --git a/src/module-magespices-mage2dark/etc/config.xml b/src/module-magespices-mage2dark/etc/config.xml new file mode 100644 index 0000000..d73134c --- /dev/null +++ b/src/module-magespices-mage2dark/etc/config.xml @@ -0,0 +1,12 @@ + + + + + + auto + 420 + 1140 + + + + diff --git a/src/module-magespices-mage2dark/etc/di.xml b/src/module-magespices-mage2dark/etc/di.xml deleted file mode 100644 index f6f20a1..0000000 --- a/src/module-magespices-mage2dark/etc/di.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - MageSpices/Mage2Dark - - - - diff --git a/src/module-magespices-mage2dark/view/adminhtml/layout/adminhtml_system_config_edit.xml b/src/module-magespices-mage2dark/view/adminhtml/layout/adminhtml_system_config_edit.xml new file mode 100644 index 0000000..9cc24f5 --- /dev/null +++ b/src/module-magespices-mage2dark/view/adminhtml/layout/adminhtml_system_config_edit.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/module-magespices-mage2dark/view/adminhtml/templates/config/renderer/time_slider.phtml b/src/module-magespices-mage2dark/view/adminhtml/templates/config/renderer/time_slider.phtml new file mode 100644 index 0000000..a825acd --- /dev/null +++ b/src/module-magespices-mage2dark/view/adminhtml/templates/config/renderer/time_slider.phtml @@ -0,0 +1,78 @@ +getTimeFrom(); +$timeTo = $block->getTimeTo(); +?> +
+ +
+
+
+
+ \ No newline at end of file diff --git a/src/module-magespices-mage2dark/view/adminhtml/web/css/config.css b/src/module-magespices-mage2dark/view/adminhtml/web/css/config.css new file mode 100644 index 0000000..9b5c5d1 --- /dev/null +++ b/src/module-magespices-mage2dark/view/adminhtml/web/css/config.css @@ -0,0 +1,7 @@ +#row_mage2dark_settings_light_theme_time_from, +#row_mage2dark_settings_light_theme_time_to { + display: none; +} +.light-theme-slot .ui-slider-handle { + background: #ec5102; +} \ No newline at end of file