Skip to content

Commit

Permalink
Merge pull request #1177 from themeum/harun-v3
Browse files Browse the repository at this point in the history
Settings sub-menu support added added 🎉
  • Loading branch information
shewa12 authored Oct 2, 2024
2 parents 4d1012b + 7bea712 commit fdb8418
Show file tree
Hide file tree
Showing 5 changed files with 240 additions and 153 deletions.
32 changes: 31 additions & 1 deletion assets/react/admin-dashboard/segments/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,16 +616,46 @@ document.addEventListener('DOMContentLoaded', function () {

const invoice_field = document.querySelector("[name='tutor_option[tutor_woocommerce_invoice]']");
const invoice_field_wrapper = document.getElementById('field_tutor_woocommerce_invoice');
const ecommerce_pages = document.querySelector('.ecommerce_pages');
const ecommerce_currency = document.querySelector('.ecommerce_currency');
const revenue_sharing_checkbox = document.querySelector('[data-toggle-fields="sharing_percentage"]')
const revenue_sharing_field = document.querySelector("[name='tutor_option[enable_revenue_sharing]']");
const revenue_sharing_section = document.querySelector('.revenue_sharing');
const fees_section = document.querySelector('.fees');
const withdraw_section = document.querySelector('.withdraw');

if (invoice_field) {
showHideOption(invoice_field_wrapper, monetization_field.value, 'wc')
}

if (monetization_field) {
showHideOption(order_autocomplete_wrapper, monetization_field.value, 'wc');
const monetized_by = monetization_field?.value;
/**
* Show/Hide on saved value.
*/
showHideOption(order_autocomplete_wrapper, monetized_by, 'wc');
showHideOption(ecommerce_pages, monetized_by, 'tutor');
showHideOption(ecommerce_currency, monetized_by, 'tutor');

/**
* Show/Hide on-change value change.
*/
monetization_field.onchange = (e) => {
showHideOption(order_autocomplete_wrapper, e.target.value, 'wc');
showHideOption(invoice_field_wrapper, e.target.value, 'wc');

showHideOption(ecommerce_pages, e.target.value, 'tutor');
showHideOption(ecommerce_currency, e.target.value, 'tutor');
}
}

if (revenue_sharing_field) {
showHideOption(fees_section, revenue_sharing_field.value, 'on');
showHideOption(withdraw_section, revenue_sharing_field.value, 'on');

revenue_sharing_checkbox.onchange = (e) => {
showHideOption(fees_section, e.target.checked, true);
showHideOption(withdraw_section, e.target.checked, true);
}
}

Expand Down
4 changes: 4 additions & 0 deletions assets/scss/admin-dashboard/v2/components/_nav-tab.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
border-color: #e8e8e8;
}
}

.tutor-option-submenu-nav{
margin-left: 28px;
}
}
&.tutor-is-sticky {
position: sticky;
Expand Down
83 changes: 63 additions & 20 deletions classes/Options_V2.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,25 @@ public static function get_only( $only = array() ) {
return array_intersect_key( $settings, array_flip( $only ) );
}

/**
* Prepare settings search item.
*
* @since 3.0.0
*
* @param array $section section item.
* @param array $block block item.
* @param array $field field item.
*
* @return array prepared searchable field item.
*/
private function prepare_search_item( $section, $block, $field ) {
$field['section_label'] = isset( $section['label'] ) ? $section['label'] : '';
$field['section_slug'] = isset( $section['slug'] ) ? $section['slug'] : '';
$field['block_label'] = isset( $block['label'] ) ? $block['label'] : '';

return $field;
}

/**
* Function to get all fields for search tutor_option_search
*
Expand All @@ -150,14 +169,28 @@ public function tutor_option_search() {
$data_array = array();
foreach ( $this->get_setting_fields() as $sections ) {
if ( is_array( $sections ) && ! empty( $sections ) ) {
foreach ( tutils()->sanitize_recursively( $sections ) as $section ) {
foreach ( tutor_utils()->sanitize_recursively( $sections ) as $section ) {
foreach ( $section['blocks'] as $blocks ) {
if ( isset( $blocks['fields'] ) && ! empty( $blocks['fields'] ) ) {
foreach ( $blocks['fields'] as $fields ) {
$fields['section_label'] = isset( $section['label'] ) ? $section['label'] : '';
$fields['section_slug'] = isset( $section['slug'] ) ? $section['slug'] : '';
$fields['block_label'] = isset( $blocks['label'] ) ? $blocks['label'] : '';
$data_array['fields'][] = $fields;
$data_array['fields'][] = $this->prepare_search_item( $section, $blocks, $fields );
}
}
}

/**
* Submenu item search.
*
* @since 3.0.0
*/
if ( isset( $section['submenu'] ) && is_array( $section['submenu'] ) ) {
foreach ( tutor_utils()->sanitize_recursively( $section['submenu'] ) as $submenu_section ) {
foreach ( $submenu_section['blocks'] as $block ) {
if ( isset( $block['fields'] ) && ! empty( $block['fields'] ) ) {
foreach ( $block['fields'] as $fields ) {
$data_array['fields'][] = $this->prepare_search_item( $submenu_section, $block, $fields );
}
}
}
}
}
Expand Down Expand Up @@ -918,11 +951,11 @@ public function get_setting_fields() {
'monetization' => array(
'label' => __( 'Monetization', 'tutor' ),
'slug' => 'monetization',
'desc' => __( 'Monitization Settings', 'tutor' ),
'desc' => __( 'Monetization Settings', 'tutor' ),
'template' => 'basic',
'icon' => 'tutor-icon-badge-discount',
'blocks' => array(
'block_options' => array(
'block_options' => array(
'label' => __( 'Options', 'tutor' ),
'slug' => 'options',
'block_type' => 'uniform',
Expand All @@ -949,6 +982,22 @@ public function get_setting_fields() {
'default' => 'off',
'desc' => __( 'If enabled, in the case of Courses, WooCommerce Orders will get the "Completed" status .', 'tutor' ),
),
array(
'key' => 'statement_show_per_page',
'type' => 'number',
'number_type' => 'integer',
'label' => __( 'Show Statement Per Page', 'tutor' ),
'default' => '20',

'desc' => __( 'Define the number of statements to show.', 'tutor' ),
),
),
),
'block_revenue_sharing' => array(
'label' => __( 'Revenue Sharing', 'tutor' ),
'slug' => 'revenue_sharing',
'block_type' => 'uniform',
'fields' => array(
array(
'key' => 'enable_revenue_sharing',
'type' => 'toggle_switch',
Expand Down Expand Up @@ -980,18 +1029,9 @@ public function get_setting_fields() {
),
'desc' => __( 'Set how the sales revenue will be shared among admins and instructors.', 'tutor' ),
),
array(
'key' => 'statement_show_per_page',
'type' => 'number',
'number_type' => 'integer',
'label' => __( 'Show Statement Per Page', 'tutor' ),
'default' => '20',

'desc' => __( 'Define the number of statements to show.', 'tutor' ),
),
),
),
array(
'block_fees' => array(
'label' => __( 'Fees', 'tutor' ),
'slug' => 'fees',
'block_type' => 'uniform',
Expand Down Expand Up @@ -1037,7 +1077,7 @@ public function get_setting_fields() {
),
),
),
array(
'block_withdraw' => array(
'label' => __( 'Withdraw', 'tutor' ),
'slug' => 'withdraw',
'block_type' => 'uniform',
Expand Down Expand Up @@ -1652,8 +1692,11 @@ public function get_setting_fields() {
'type' => 'text',
'label' => __( 'YouTube API Key', 'tutor' ),
'default' => '',
'desc' => __( 'To host live videos on your platform using YouTube, enter your YouTube API key.
Text inside the box: Insert API key here.', 'tutor' ),
'desc' => __(
'To host live videos on your platform using YouTube, enter your YouTube API key.
Text inside the box: Insert API key here.',
'tutor'
),
),
),
),
Expand Down
Loading

0 comments on commit fdb8418

Please sign in to comment.