Continued BMO optimisations

Tidy up ajaxHelper
Set correct return values from ajaxHandler
Use BMO __get to minimise construct calls
Implement Module.xml depends
This commit is contained in:
stevenA 2022-01-12 12:22:14 +01:00
parent a3eb87610c
commit 7e50dbf2d2
7 changed files with 50 additions and 75 deletions

View file

@ -142,7 +142,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
// The __Get override then determines that the class does not exist and so creates a new class Which
// in turn calls this __construct. This test can be removed when the bug is fixed in FreePBX.
dbug('__construct called', debug_backtrace(2));
//dbug('__construct called', debug_backtrace(2));
$this->sccpvalues = $this->dbinterface->get_db_SccpSetting(); //Initialise core settings
$this->initializeSccpPath(); //Set required Paths
@ -208,11 +208,6 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
}
}
public function showPage() {
dbug('showPage called', $_REQUEST);
return;
}
/*
* Show form information - General
*/
@ -311,8 +306,6 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
}
public function phoneShowPage() {
dbug($_REQUEST);
dbug(debug_backtrace(0));
$request = $_REQUEST;
$action = !empty($request['action']) ? $request['action'] : '';
$inputform = !empty($request['tech_hardware']) ? $request['tech_hardware'] : '';
@ -573,7 +566,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
}
$this->dbinterface->write('sccpuser', $save_settings, 'replace', 'name');
$this->dbinterface->write('sccpbuttons', $save_buttons, 'delete', '', $name_dev); //standardise to delete
return $save_buttons;
return array('status' => true, 'search' => '?display=sccp_phone', 'hash' => 'general');
}
public function getCodecs($type, $showDefaults = false) {

View file

@ -1,7 +1,7 @@
<module>
<rawname>sccp_manager</rawname>
<name>SCCP Manager</name>
<version>14.4.0.6</version>
<version>16.0.0.1</version>
<type>setup</type>
<category>SCCP Connectivity</category>
<publisher>Steve Lad, Alex GP</publisher>
@ -41,6 +41,7 @@
* Version 14.4.0.2 * - Revert error in Installer db calls - IF EXISTS is not valid in MariaDb v5 (package DB)
* Version 14.4.0.3 * - Change method of selecting phonecodepage depending on if is java phone.
* Version 14.4.0.5 * - Fix issue #59.
* Version 16.0.0.1 * - Improve compliance and use of BMO to optimise performance
</changelog>
<location>https://github.com/chan-sccp/sccp_manager</location>
<depends>

View file

@ -14,12 +14,6 @@ if (!defined('FREEPBX_IS_AUTH')) {
// function is called. This is where you do any changes. The page.foo.php
// is only for DISPLAYING things. MVC is a cool idea, ya know?
//
dbug(debug_backtrace());
if (isset(\FreePBX::create()->Sccp_manager)) {
dbug('is set');
} else {
dbug('is not set');
}
$spage = FreePBX::create()->Sccp_manager;
if (empty($spage->class_error)) {
$display_page = $spage->phoneShowPage();

View file

@ -45,24 +45,17 @@ trait ajaxHelper {
$request = $_REQUEST;
$msg = array();
$cmd_id = $request['command'];
dbug('ajax', $cmd_id);
switch ($cmd_id) {
case 'savesettings':
// Consolidate this into a separate method to improve legibility
$this->handleSubmit($request);
// TODO: Need to be more specific on reload and only reload if critical settings changed.
$res = $this->aminterface->core_sccp_reload();
return array('status' => true, 'message' => 'Data saved', 'reload' => true, 'toastFlag' => 'success', 'search' => '?display=sccpsettings', 'hash' => '');
return $this->saveSccpSettings($request);
break;
case 'save_sip_device':
case 'save_device':
return $this->saveSccpDevice($request);
break;
case 'save_ruser':
//$res = $request;
$res = $this->handleRoamingUsers($request);
return array('status' => true, 'search' => '?display=sccp_phone', 'hash' => 'general');
return $this->handleRoamingUsers($request);
break;
case 'save_dialplan_template':
/* !TODO!: -TODO-: dialplan templates should be removed (only required for very old devices (like ATA) */
@ -79,7 +72,7 @@ trait ajaxHelper {
if (!empty($request['dialplan'])) {
$get_file = $request['dialplan'];
$res = $this->deleteDialPlan($get_file);
return array('status' => true, 'message' => 'Dial Template has been deleted ! ', 'table_reload' => true);
return array('status' => true, 'message' => 'Dial Template has been deleted !', 'table_reload' => true);
} else {
return array('status' => false, 'message' => print_r($res));
}
@ -95,7 +88,7 @@ trait ajaxHelper {
$this->aminterface->sccpDeviceReset($idv, 'reset');
}
}
return array('status' => true, 'table_reload' => true, 'message' => 'Hardware device has been deleted! ');
return array('status' => true, 'table_reload' => true, 'message' => 'Hardware device has been deleted!');
}
break;
case 'create_hw_tftp':
@ -116,7 +109,7 @@ trait ajaxHelper {
foreach ($models as $data) {
$ver_id = $this->createSccpDeviceXML($data['name']);
if ($ver_id == -1) {
return array('status' => false, 'message' => 'Error Create Configuration Divice :' . $data['name']);
return array('status' => false, 'message' => 'Error Creating Device Configuration: ' . $data['name']);
}
};
@ -285,7 +278,7 @@ trait ajaxHelper {
}
}
function handleSubmit($request, $validateonly = false) {
function saveSccpSettings($request, $validateonly = false) {
$hdr_prefix = 'sccp_';
$hdr_arprefix = 'sccp-ar_';
$save_settings = array();
@ -404,32 +397,9 @@ trait ajaxHelper {
// rewrite sccp.conf
$this->createDefaultSccpConfig($this->sccpvalues, $this->sccppath["asterisk"]);
$this->createDefaultSccpXml();
}
public function getMyConfig($var = null, $id = "noid") {
// TODO: this function has little purpose - need to integrate into AjaxHelper
switch ($var) {
case "softkeyset":
$final = array();
$i = 0;
if ($id == "noid") {
foreach ($this->sccp_conf_init as $key => $value) {
if ($this->sccp_conf_init[$key]['type'] == 'softkeyset') {
$final[$i] = $value;
$i++;
}
}
} else {
if (!empty($this->sccp_conf_init[$id])) {
if ($this->sccp_conf_init[$id]['type'] == 'softkeyset') {
$final = $this->sccp_conf_init[$id];
}
}
}
break;
}
return $final;
// TODO: Need to be more specific on reload and only reload if critical settings changed.
$res = $this->aminterface->core_sccp_reload();
return array('status' => true, 'message' => 'Data saved', 'reload' => true, 'toastFlag' => 'success', 'search' => '?display=sccpsettings', 'hash' => '');
}
public function getFilesFromProvisioner($request) {

View file

@ -13,25 +13,16 @@ trait bmoFunctions {
public function doConfigPageInit($page) {
switch ($page) {
case 'sccpsettings':
dbug('doConfigPageInit called for', $page);
break;
case 'sccp_phone':
dbug('doConfigPageInit called for', $page);
//dbug('doConfigPageInit called from', debug_backtrace());
//"ajax.php?module=sccp_manager&command=getExtensionGrid&type=extGrid"
//header('Content-type: application/json');
$this->extensionData = json_encode($this->getExtensionGrid('extGrid'));
//$this->extensionData = $this->getExtensionGrid('extGrid');
//"ajax.php?module=sccp_manager&command=getPhoneGrid&type=sccp
$this->sccpPhoneData = json_encode($this->getPhoneGrid('sccp'));
$this->sipPhoneData = json_encode($this->getPhoneGrid('cisco-sip'));
break;
case 'sccp_adv':
dbug('doConfigPageInit called for', $page);
$this->dialTemplateData = json_encode($this->getDialTemplate());
$this->softKeyData = json_encode($this->getSoftKey());
$this->deviceModelData = json_encode($this->ajaxHandler($_REQUEST = array('command'=>'getDeviceModel', 'type'=>'enabled')));
//dbug($this->deviceModelData);
break;
default:
break;
@ -141,11 +132,30 @@ trait bmoFunctions {
$result[$i][$key] = str_replace(',', '<br>', $value);
}
}
$i++;
}
return $result;
}
public function getMyConfig(string $var, $id = "noid") {
$final = array();
$i = 0;
if ($id == "noid") {
foreach ($this->sccp_conf_init as $key => $value) {
if ($this->sccp_conf_init[$key]['type'] == 'softkeyset') {
$final[$i] = $value;
$i++;
}
}
} else {
if (!empty($this->sccp_conf_init[$id])) {
if ($this->sccp_conf_init[$id]['type'] == 'softkeyset') {
$final = $this->sccp_conf_init[$id];
}
}
}
return $final;
}
/* unused but FPBX API requires it */
public function install() {

View file

@ -165,7 +165,12 @@ foreach ($keysetarray as $key => $value) {
</div>
<script>
function DispayActionsKeyFormatter(value, row, index) {
$(function() {
$('#softkey-all').bootstrapTable({data: <?php echo $this->softKeyData ?>});
})
function DisplayActionsKeyFormatter(value, row, index) {
var exp_model = '';
if (row['softkeys'] !== 'default') {
exp_model += '<a href="#edit_softkeys" onclick="load_oncliсk(this, &quot;'+row['softkeys']+'&quot;)" data-toggle="modal" data-target=".edit_new_keyset"><i class="fa fa-pencil"></i></a>&nbsp;';

View file

@ -48,6 +48,8 @@ if ($h_show==1) {
<?php
}
// Use BMO - this will return an Sccp_manager object if it already exists in BMO, or create one if not
$sccpManager = FreePBX::create()->Sccp_manager;
foreach ($items as $child) {
$disabledButtons = array();
if (empty($child->help)) {
@ -57,10 +59,10 @@ foreach ($items as $child) {
echo "<!-- Begin {$child->label} -->";
switch ($child['type']) {
case 'IE':
\FreePbx::sccp_manager()->formcreate->addElementIE($child, $fvalues, $sccp_defaults,$npref);
$sccpManager->formcreate->addElementIE($child, $fvalues, $sccp_defaults,$npref);
break;
case 'IED':
\FreePbx::sccp_manager()->formcreate->addElementIED($child, $fvalues, $sccp_defaults,$npref, $napref);
$sccpManager->formcreate->addElementIED($child, $fvalues, $sccp_defaults,$npref, $napref);
break;
case 'ISC':
// This is a special case for Provision mode. Set some parameters here and fall through to IS.
@ -69,7 +71,7 @@ foreach ($items as $child) {
$disabledButtons = array('off' => 'Off');
}
case 'IS':
\FreePbx::sccp_manager()->formcreate->addElementIS($child, $fvalues, $sccp_defaults,$npref, $disabledButtons);
$sccpManager->formcreate->addElementIS($child, $fvalues, $sccp_defaults,$npref, $disabledButtons);
break;
case 'SLD':
case 'SLM':
@ -81,11 +83,11 @@ foreach ($items as $child) {
case 'SLA':
case 'SLZ':
case 'SL':
\FreePbx::sccp_manager()->formcreate->addElementSL($child, $fvalues, $sccp_defaults,$npref, $installedLangs);
$sccpManager->formcreate->addElementSL($child, $fvalues, $sccp_defaults,$npref, $installedLangs);
break;
case 'SLDA':
case 'SLNA':
\FreePbx::sccp_manager()->formcreate->addElementSLNA($child, $fvalues, $sccp_defaults,$npref, $installedLangs);
$sccpManager->formcreate->addElementSLNA($child, $fvalues, $sccp_defaults,$npref, $installedLangs);
break;
case 'SDM':
case 'SDMS':
@ -93,16 +95,16 @@ foreach ($items as $child) {
case 'SDMF':
case 'SDE':
case 'SDD':
\FreePbx::sccp_manager()->formcreate->addElementSD($child, $fvalues, $sccp_defaults,$npref);
$sccpManager->formcreate->addElementSD($child, $fvalues, $sccp_defaults,$npref);
break;
case 'ITED':
\FreePbx::sccp_manager()->formcreate->addElementITED($child, $fvalues, $sccp_defaults, $npref, $napref);
$sccpManager->formcreate->addElementITED($child, $fvalues, $sccp_defaults, $npref, $napref);
break;
case 'HLP':
\FreePbx::sccp_manager()->formcreate->addElementHLP($child, $fvalues, $sccp_defaults,$npref);
$sccpManager->formcreate->addElementHLP($child, $fvalues, $sccp_defaults,$npref);
break;
case 'SLTZN':
\FreePbx::sccp_manager()->formcreate->addElementSLTZN($child, $fvalues, $sccp_defaults,$npref);
$sccpManager->formcreate->addElementSLTZN($child, $fvalues, $sccp_defaults,$npref);
break;
}
echo "<!-- END {$child->label} -->";