Skip to content

Commit

Permalink
generated first lists from wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
otrok7 committed Nov 27, 2024
1 parent e5c9206 commit 8c2dcb3
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 91 deletions.
55 changes: 53 additions & 2 deletions admin/class-bread-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,38 @@ public function enqueue_scripts($hook)
*/
$str = file_get_contents(plugin_dir_path(__FILE__) . 'templates/meeting_data_templates.json');
wp_add_inline_script('common', "meetingDataTemplates = $str", 'before');
$str = $this->get_meeting_list_templates_json(plugin_dir_path(__FILE__) . 'templates');
wp_add_inline_script('breadWizard', "breadLayouts = $str", 'before');
}
/**
* This allows us to simply add a file to the appropriate directory
* to make the configuration available for selection in the wizard.
*
* @param string $root the directory where we will search for configurations. The configurations must be in
* a directory with a numeric name, where the numeric value is the maximum number of meetings for the configurations stored there.
* The filenames of the configurations must have a specific format, which is used to describe the configurations in the UI.
* @return string
*/
function get_meeting_list_templates_json(string $root): string
{
$sizes = [];
foreach(scandir($root) as $dir) {
if (!(is_numeric($dir))) {
continue;
}
$files = [];
foreach(scandir($root.'/'.$dir) as $file) {
if (substr($file,0,1) !== '.') {
$files[] = $file;
}
}
$sizes[] = array(
'maxSize' => $dir,
'configurations' => $files,
);
}
return json_encode($sizes);
}

function ml_default_editor()
{
global $my_admin_page;
Expand Down Expand Up @@ -396,7 +426,7 @@ function admin_options_page()
case 'import_settings':
$this->pwsix_process_settings_import();
break;
case 'import_settings':
case 'wizard':
$this->pwsix_process_wizard();
break;
default:
Expand All @@ -411,6 +441,27 @@ function pwsix_process_wizard()
if (! wp_verify_nonce($_POST['pwsix_wizard_nonce'], 'pwsix_wizard_nonce')) {
return;
}
if (!$this->current_user_can_create()) {
return;
}
$encode_options = file_get_contents(plugin_dir_path(__FILE__) . 'templates/'.$_POST['wizard_layout']);
while (0 === strpos(bin2hex($encode_options), 'efbbbf')) {
$encode_options = substr($encode_options, 3);
}
$settings = json_decode($encode_options, true);
$id = $this->maxSetting + 1;
$optionsName = $this->bread->generateOptionName($id);
$settings['authors'] = array();
$settings['root_server'] = sanitize_url($_POST['wizard_root_server']);
for ($i=0; $i<count($_POST['wizard_service_bodies']); $i++) {
$j = $i+1;
$settings['service_body_'.$j] = sanitize_text_field($_POST['wizard_service_bodies'][$i]);
}
$settings['used_format_1'] = intval('wizard_format');
update_option($optionsName, $settings);
$this->bread->renameSetting($id, 'Setting '.$id);
setcookie('current-meeting-list', $id, time()+10);
wp_safe_redirect(admin_url('?page=class-bread-admin.php'));
}
function pwsix_process_settings_admin()
{
Expand Down
4 changes: 2 additions & 2 deletions admin/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,8 @@ width: 4em !important;
.mce-menu-item-normal.mce-active:focus .mce-text, .mce-menu-item-normal.mce-active:focus .mce-ico {
color: #FFF !important;
}
h3.help-accordian { background-color: #F5F5F5 !important; color: #000 !important; font-weight: 400 !important; border: 1px solid #E5E5E5 !important;}
.help-accordian .ui-icon { background-color: #0A8ADD; }
h3.help-accordion { background-color: #F5F5F5 !important; color: #000 !important; font-weight: 400 !important; border: 1px solid #E5E5E5 !important;}
.help-accordion .ui-icon { background-color: #0A8ADD; }
.videocontent {
width:100%;
max-width: 100%;
Expand Down
137 changes: 69 additions & 68 deletions admin/js/bmlt_meeting_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ jQuery(document).ready(
function($ml) {
$ml(".connecting").hide();
$ml(".saving").hide();
$ml(".bmlt-accrodian").accordion(
$ml(".bmlt-accordion").accordion(
{
heightStyle: "content",
active: false,
collapsible: true
}
);
$ml(".bmlt_color").spectrum({preferredFormat: 'hex', showInput: true, showPalette: false});
$ml("#col_color").on("click", ()=>$ml("#triggerSet").spectrum("set", this.val()));
$ml("#col_color").on("click", () => $ml("#triggerSet").spectrum("set", this.val()));
$ml("#bmlt_meeting_list_options").on(
"keypress", function(event) {
if(event.which == 13 && !event.shiftKey) {
Expand Down Expand Up @@ -137,14 +137,15 @@ jQuery(document).ready(
}
}
);
$ml('.my-tooltip').each(function(i,e) {
$ml(e).tooltipster(
{
contentAsHTML: true,
theme: 'tooltipster-noir',
trigger: 'click'
}
)});
$ml('.my-tooltip').each(function(i, e) {
$ml(e).tooltipster(
{
contentAsHTML: true,
theme: 'tooltipster-noir',
trigger: 'click'
}
)
});
$ml("#meeting-list-tabs").tabs(
{
active: 0
Expand Down Expand Up @@ -254,30 +255,30 @@ jQuery(document).ready(
let removeSpaces = $ml('input[name=remove_space]:checked').val()
let startTime = '8:00 PM';
let endTime = '9:00 PM';
if (clock == '24') {
if(clock == '24') {
startTime = '20:00';
endTime = '21:00';
} else if (clock == '24fr') {
} else if(clock == '24fr') {
startTime = '20h00';
endTime = '21h00';
}
if (hasEndTime==2) {
startTime += ' - '+endTime;
if(hasEndTime == 2) {
startTime += ' - ' + endTime;
}
if (hasEndTime==3) {
startTime = clock=='12' ? '8 - 9' : '';
if(hasEndTime == 3) {
startTime = clock == '12' ? '8 - 9' : '';
}
if (removeSpaces!="0") {
startTime = startTime.replaceAll(' ','');
if(removeSpaces != "0") {
startTime = startTime.replaceAll(' ', '');
}
return startTime;
}
function setTimeOptionText() {
$ml('label[for=option1]').html(calcTimeDisplay(1));
$ml('label[for=option2]').html(calcTimeDisplay(2));
$ml('label[for=option3]').html(calcTimeDisplay(3));
if ($ml('input[name=time_clock]:checked').val()!='12') {
if ($ml('input[name=time_clock]:checked').val()==3)
if($ml('input[name=time_clock]:checked').val() != '12') {
if($ml('input[name=time_clock]:checked').val() == 3)
$ml('#option2').prop('checked', true);
$ml('#option3').hide();
} else $ml('#option3').show();
Expand All @@ -297,8 +298,8 @@ jQuery(document).ready(
$ml('.booklet').hide();
$ml('.single-page').show();
}
$ml('.single-page-check').on('click',singlePageControlsShowHide);
$ml('.booklet-check').on('click',bookletControlsShowHide);
$ml('.single-page-check').on('click', singlePageControlsShowHide);
$ml('.booklet-check').on('click', bookletControlsShowHide);
$ml('input[name=page_fold]:checked').hasClass('booklet-check') && bookletControlsShowHide();
$ml('input[name=page_fold]:checked').hasClass('single-page-check') && singlePageControlsShowHide();
$ml(".service_body_select").chosen(
Expand Down Expand Up @@ -404,49 +405,49 @@ jQuery(document).ready(
*/
function getTabKey(href) {
return href.replace('#', '');
}
/**
* Hide all tabs
*/
function hideAllTabs() {
tabs.each(function(){
var href = getTabKey(jQuery(this).attr('href'));
jQuery('#' + href).hide();
});
}
/**
* Activate Tab
*/
function activateTab(tab) {
var href = getTabKey(tab.attr('href'));
tabs.removeClass('nav-tab-active');
tab.addClass('nav-tab-active');
jQuery('#' + href).show();
}
jQuery(document).ready(function($){
var activeTab, firstTab;
// First load, activate first tab or tab with nav-tab-active class
firstTab = false;
activeTab = false;
tabs = $('a.nav-tab');
hideAllTabs();
tabs.each(function(){
var href = $(this).attr('href').replace('#', '');
if (!firstTab) {
firstTab = $(this);
}
if ($(this).hasClass('nav-tab-active')) {
activeTab = $(this);
}
});
if (!activeTab) {
activeTab = firstTab;
}
activateTab(activeTab);
//Click tab
tabs.click(function(e) {
e.preventDefault();
hideAllTabs();
activateTab($(this));
});
});
}
/**
* Hide all tabs
*/
function hideAllTabs() {
tabs.each(function() {
var href = getTabKey(jQuery(this).attr('href'));
jQuery('#' + href).hide();
});
}
/**
* Activate Tab
*/
function activateTab(tab) {
var href = getTabKey(tab.attr('href'));
tabs.removeClass('nav-tab-active');
tab.addClass('nav-tab-active');
jQuery('#' + href).show();
}
jQuery(document).ready(function($) {
var activeTab, firstTab;
// First load, activate first tab or tab with nav-tab-active class
firstTab = false;
activeTab = false;
tabs = $('a.nav-tab');
hideAllTabs();
tabs.each(function() {
var href = $(this).attr('href').replace('#', '');
if(!firstTab) {
firstTab = $(this);
}
if($(this).hasClass('nav-tab-active')) {
activeTab = $(this);
}
});
if(!activeTab) {
activeTab = firstTab;
}
activateTab(activeTab);
//Click tab
tabs.click(function(e) {
e.preventDefault();
hideAllTabs();
activateTab($(this));
});
});
48 changes: 41 additions & 7 deletions admin/js/bread-wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ jQuery(document).ready(function($){
$('#wizard_root_server_result').removeClass('invalid-feedback').removeClass('valid-feedback')
.html('Verify that this is valid root server URL before continuing');
}
write_service_body_with_childern = function(options, sb, parents, level) {
write_service_body_with_childern = function(options, sb, parents, my_parent, level) {
let prefix = '';
for (i=0; i<level; i++) prefix += '-';
options.push('<option value="'+sb.id+'">'+prefix+sb.name+'</option>');
const sbVal = [sb.name,sb.id,sb.parent_id, my_parent].join(',');
options.push('<option value="'+sbVal+'">'+prefix+sb.name+'</option>');
found = parents.find((p) => p.id == sb.id);
if (typeof found !== 'undefined')
found.children.forEach((child) =>
options = write_service_body_with_childern(options, child, parents, level+1));
options = write_service_body_with_childern(options, child, parents, sb.name, level+1));
return options;
}
fill_service_bodies = function(service_bodies) {
Expand All @@ -60,18 +61,47 @@ jQuery(document).ready(function($){
}, []);
let options = [];
roots.forEach((sb) => {
options = write_service_body_with_childern(options, sb, parents, 0);
options = write_service_body_with_childern(options, sb, parents, 'ROOT', 0);
});
$('#wizard_service_bodies').html(options.join(''));
$('#wizard_service_bodies').trigger("chosen:updated");
}
service_body_error = function(error) {
fill_formats = function(formats) {
const options = formats.reduce((carry,item) => {
carry.push('<option value="'+item.id+'">Only '+item.name_string+'</option>');
return carry;
}, ['<option value="0" selected>All Meetings</option>']);
$('#wizard_format_filter').html(options.join(''));
}
layout_options = function(meetings) {
const meeting_count = meetings.length;
$('#wizard_meeting_count').html(meeting_count);
const layouts = breadLayouts.find((layouts) => meeting_count <= Number(layouts.maxSize));
const options = layouts.configurations.reduce((carry,item) => {
const selected = (carry.length === 0) ? ' selected' : '';
carry.push('<option value="'+layouts.maxSize+'/'+item+'"'+selected+'>'+item+'</option>');
return carry;
}, []);
$('#wizard_layout').html(options.join(''));
}
handle_error = function(error) {
console.log(error);
$('#bread-wizard').smartWizard("goToStep", 0);
}
BreadWizard.prototype.getContent = function(idx, stepDirection, stepPosition, selStep, callback) {
switch(idx) {
case 1:
ask_bmlt('switcher=GetServiceBodies', fill_service_bodies, service_body_error);
ask_bmlt('switcher=GetServiceBodies', fill_service_bodies, handle_error);
ask_bmlt('switcher=GetFormats', fill_formats, handle_error);
break;
case 2:
const services = $('#wizard_service_bodies').val().reduce((carry,item) => {
carry += '&services[]='+item.split(',')[1];
return carry;
}, '');
const formats = (Number($('#wizard_format_filter').val()) > 0) ? '&formats='+$('#wizard_format_filter').val() : '';

ask_bmlt('switcher=GetSearchResults'+services+formats, layout_options, handle_error);
break;
default:
break;
Expand Down Expand Up @@ -102,7 +132,11 @@ jQuery(document).ready(function($){
const ret = $('#wizard_root_server_result').hasClass('valid-feedback');
if (!ret) $('#wizard_root_server_result').html('Verify that this is valid root server URL before continuing');
return ret;

case 1:
if ($('#wizard_service_bodies').val().length == 0 && stepDirection=='forward') {
$('#wizard_service_body_result').html('You must select a service body before continuing');
return false;
}
default:
break;
}
Expand Down
11 changes: 10 additions & 1 deletion admin/partials/_bread_wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,22 @@
<option value=8>The is placeholder 1 Hello</option>
<option value=9>The is placeholder 1 Hello</option>
</select>
<div id="wizard_service_body_result">
</div>
<p>If you want to limit the meeting list to a particular format, for instance, to create a language-specific meeting list, you can enter it here.
<br/><select style="width: 400px;" id="wizard_format_filter" name="wizard_format_filte">
</select></p>
</div>
</div>
<div id="step-3" class="tab-pane" role="tabpanel" aria-labelledby="step-3">
<h3>Step 3: Page Layout</h3>
<p>Number of meetings on list: <span id="wizard_meeting_count"></span></p>
<p>Select one of the layouts appropriate to the number of meetings</p>
<select id="wizard_layout" name="wizard_layout">
</select>
</div>
<div id="step-4" class="tab-pane" role="tabpanel" aria-labelledby="step-4">
//<?php submit_button(__('Create Meeting List'), 'button-primary', 'create_meeting_list', false); ?>
<?php submit_button(__('Create Meeting List'), 'button-primary', 'create_meeting_list', false); ?>
</div>
</div>
<!-- Include optional progressbar HTML -->
Expand Down
Loading

0 comments on commit 8c2dcb3

Please sign in to comment.