Skip to content

Commit 59abecf

Browse files
committed
UI performance improvements
* Support of including Smarty files (.tpl) from html templates * Objects tree UI improvement
1 parent a875969 commit 59abecf

File tree

6 files changed

+225
-26
lines changed

6 files changed

+225
-26
lines changed

admin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484

8585
startMeasure('accelerationProcess');
8686
if ((!defined('DISABLE_PANEL_ACCELERATION') || DISABLE_PANEL_ACCELERATION!=1)) {
87-
$result = preg_replace('/href="(\/admin\.php.+?)">/is','href="\1" onclick="return partLoad(this.href);">',$result);
87+
//$result = preg_replace('/href="(\/admin\.php.+?)">/is','href="\1" onclick="return partLoad(this.href);">',$result);
88+
$result = str_replace(' href="/admin.php',' onclick="return partLoad(this.href);" href="/admin.php',$result);
8889
}
8990
endMeasure('accelerationProcess');
9091

lib/jTemplate.class.php

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ public function __construct($template, &$data, &$owner = '')
9999

100100
if (strpos($res, '{#')) {
101101
//second pass
102+
startMeasure('secondpass');
102103
$res = str_replace('{#', '[#', $res);
103104
$res = str_replace('#}', '#]', $res);
104105
$res = $this->parse($res, $this->data, $root);
106+
endMeasure('secondpass');
105107
}
106108

107109
if (isset($this->ajax) && $this->ajax) {
@@ -158,30 +160,40 @@ public function parse($res, &$hash, $dir)
158160

159161
// ARRAYS
160162
if (is_integer(strpos($res, '[#begin '))) {
163+
//startMeasure('parsingArrays'.$this->template);
161164
$this->parseArrays($res, $hash, $dir);
165+
//endMeasure('parsingArrays'.$this->template);
162166
}
163167

164168
// HASHES
165169
$this->parseHashes($res, $hash);
166170

167171
// CONDITIONS
168172
if (is_integer(strpos($res, '[#if '))) {
173+
//startMeasure('parsingIfs'.$this->template);
169174
$this->parseIf($res, $hash);
175+
//endMeasure('parsingIfs'.$this->template);
170176
}
171177

172178
// MODULES
173179
if (is_integer(strpos($res, '[#module '))) {
180+
//startMeasure('parsingModules'.$this->template);
174181
$this->parseModules($res, $hash, $dir);
182+
//endMeasure('parsingModules'.$this->template);
175183
}
176184

177185
// INCLUDE FILES
178186
if (is_integer(strpos($res, '[#inc '))) {
187+
//startMeasure('parsingIncludes'.$this->template);
179188
$this->parseIncludes($res, $hash, $dir);
189+
//endMeasure('parsingIncludes'.$this->template);
180190
}
181191

182192
// VARIABLES
183193
if (is_integer(strpos($res, '[#'))) {
194+
//startMeasure('parsingVariables'.$this->template);
184195
$this->parseVariables($res, $hash);
196+
//endMeasure('parsingVariables'.$this->template);
185197
}
186198

187199
return $res;
@@ -332,7 +344,7 @@ public function parseGlobals(&$res, &$hash)
332344
if (defined($matches[1][$i])) {
333345
$res = str_replace($matches[0][$i], constant($matches[1][$i]), $res);
334346
} else {
335-
if (!isset($hash[$matches[1][$i]])) $hash[$matches[1][$i]]=null;
347+
if (!isset($hash[$matches[1][$i]])) $hash[$matches[1][$i]] = null;
336348
$res = str_replace($matches[0][$i], $hash[$matches[1][$i]], $res);
337349
}
338350
}
@@ -355,7 +367,7 @@ public function parseArrays(&$res, &$hash, $dir)
355367
$count_matches_0 = count($matches[0]);
356368

357369
for ($i = 0; $i < $count_matches_0; $i++) {
358-
if (!isset($hash[$matches[1][$i]])) $hash[$matches[1][$i]]=null;
370+
if (!isset($hash[$matches[1][$i]])) $hash[$matches[1][$i]] = null;
359371
$var = $hash[$matches[1][$i]];
360372
$line1 = $matches[2][$i];
361373
$res1 = "";
@@ -456,7 +468,7 @@ public function parseHashes(&$res, &$hash)
456468
if (preg_match_all('/<#(\w+?)\.(\w+?)#>/', $res, $matches, PREG_PATTERN_ORDER)) {
457469
$count_matches_1 = count($matches[1]);
458470
for ($i = 0; $i < $count_matches_1; $i++) {
459-
if (!isset($hash[$matches[1][$i]][$matches[2][$i]])) $hash[$matches[1][$i]][$matches[2][$i]]=null;
471+
if (!isset($hash[$matches[1][$i]][$matches[2][$i]])) $hash[$matches[1][$i]][$matches[2][$i]] = null;
460472
$res = str_replace($matches[0][$i], $this->templateSafe($hash[$matches[1][$i]][$matches[2][$i]]), $res);
461473
}
462474
}
@@ -724,19 +736,43 @@ public function parseIncludes(&$res, &$hash, $dir)
724736
if (!file_exists($file_name)) {
725737
$res = str_replace($matches[0][$i], "<!-- Cannot find file $file_name -->", $res);
726738
} else {
739+
startMeasure('including '.$file_name);
740+
$old_template = $this->template;
741+
$this->template = $file_name;
742+
727743
if ((defined("DEBUG_MODE")) && !is_integer(strpos($file_name, ".js"))) {
728744
$id = "block" . (int)rand(0, 100000);
729-
730745
/*
731746
$replaceStr = "<!-- begin of file $file_name -->";
732747
$replaceStr .= $this->parse($this->loadfile($file_name) . "<!-- end of file $file_name -->", $new_hash, $new_root);
733748
$res = str_replace($matches[0][$i], $replaceStr, $res);
734749
*/
735-
736-
$res = str_replace($matches[0][$i], "" . $this->parse($this->loadfile($file_name) . "", $new_hash, $new_root), $res);
750+
if (preg_match('/\.tpl$/', $file_name)) {
751+
require_once ROOT . 'lib/smarty/Smarty.class.php';
752+
$smarty = new Smarty;
753+
$smarty->setCacheDir(ROOT . 'cms/cached/template_c');
754+
$smarty->setTemplateDir(ROOT . './templates')
755+
->setCompileDir(ROOT . './cms/cached/templates_c')
756+
->setCacheDir(ROOT . './cms/cached');
757+
$smarty->debugging = false;
758+
$smarty->caching = true;
759+
$smarty->setCaching(120);
760+
foreach ($new_hash as $k => $v) {
761+
$smarty->assign($k, $v);
762+
}
763+
$res = str_replace($matches[0][$i], "" . $smarty->fetch($file_name), $res);
764+
} else {
765+
$res = str_replace($matches[0][$i], "" . $this->parse($this->loadfile($file_name) . "", $new_hash, $new_root), $res);
766+
}
737767
} else {
738-
$res = str_replace($matches[0][$i], $this->parse($this->loadfile($file_name), $new_hash, $new_root), $res);
768+
if (preg_match('/\.tpl$/', $file_name)) {
769+
dprint($new_hash);
770+
} else {
771+
$res = str_replace($matches[0][$i], $this->parse($this->loadfile($file_name), $new_hash, $new_root), $res);
772+
}
739773
}
774+
$this->template = $old_template;
775+
endMeasure('including '.$file_name);
740776
}
741777
}
742778
}
@@ -756,7 +792,7 @@ public function parseVariables(&$res, &$hash)
756792
if (preg_match_all('/\[#(\w+?)#\]/', $res, $matches, PREG_PATTERN_ORDER)) {
757793
$count_matches_1 = count($matches[1]);
758794
for ($i = 0; $i < $count_matches_1; $i++) {
759-
if (!isset($hash[$matches[1][$i]])) $hash[$matches[1][$i]]='';
795+
if (!isset($hash[$matches[1][$i]])) $hash[$matches[1][$i]] = '';
760796
$res = str_replace($matches[0][$i], $this->templateSafe($hash[$matches[1][$i]]), $res);
761797
}
762798
}
@@ -765,7 +801,7 @@ public function parseVariables(&$res, &$hash)
765801
if (preg_match_all('/\[#(\w+?)\.(\w+?)#\]/', $res, $matches, PREG_PATTERN_ORDER)) {
766802
$count_matches_1 = count($matches[1]);
767803
for ($i = 0; $i < $count_matches_1; $i++) {
768-
if (!isset($hash[$matches[1][$i]][$matches[2][$i]])) $hash[$matches[1][$i]][$matches[2][$i]]='';
804+
if (!isset($hash[$matches[1][$i]][$matches[2][$i]])) $hash[$matches[1][$i]][$matches[2][$i]] = '';
769805
$res = str_replace($matches[0][$i], $this->templateSafe($hash[$matches[1][$i]][$matches[2][$i]]), $res);
770806
}
771807
}
@@ -788,7 +824,6 @@ public function templateSafe($val)
788824
$res = str_replace('#}', '#&#125', $res);
789825
$res = str_replace('<#', '&#060#', $res);
790826
$res = str_replace('#>', '#&#062', $res);
791-
792827
return $res;
793828
}
794829

modules/classes/classes_search.inc.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,9 @@
6969
if ($methods[0]['ID']) {
7070
$total_m=count($methods);
7171
for($im=0;$im<$total_m;$im++) {
72-
73-
if ($methods[$im]['ID']==272) {
74-
//print_r($parent_methods);exit;
75-
}
76-
7772
if ($parent_methods_titles[$methods[$im]['TITLE']]) {
7873
$methods[$im]['ID']=$parent_methods_titles[$methods[$im]['TITLE']];
7974
}
80-
81-
/*
82-
$parent_method=SQLSelectOne("SELECT ID FROM methods WHERE OBJECT_ID=0 AND CLASS_ID='".$objects[$o]['CLASS_ID']."' AND TITLE='".DBSafe($methods[$im]['TITLE'])."'");
83-
if ($parent_method['ID']) {
84-
$methods[$im]['ID']=$parent_method['ID'];
85-
}
86-
*/
8775
}
8876
$objects[$o]['METHODS']=$methods;
8977
}
@@ -100,4 +88,3 @@
10088
endMeasure('classesBuildTree');
10189
$out['RESULT']=$res;
10290
}
103-
?>

templates/classes/classes_search_admin.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
#-->
44

55

6-
[#inc view_tree.html#]
6+
[#inc view_tree.tpl#]

templates/classes/view_tree.tpl

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
<div class="row" style="margin-right: -15px;margin-left: -15px;">
2+
<div class="col-lg-6 col-md-5 col-sm-12 col-xs-12">
3+
<script>
4+
function filterProp() {
5+
term = $('#filterProp').val().toLowerCase();
6+
if(term.length <= 2) {
7+
$('ul.classSearch>li').attr('style', 'padding: 5px;display: block;border: 0px;border-radius: 0px;border-bottom: 1px solid #ddd;');
8+
$('ul.classSearch>li').removeAttr('id');
9+
return;
10+
}
11+
$('ul.classSearch>li').each(function(index) {
12+
textForSearch = $(this).children().children().text().trim();
13+
searchResult = textForSearch.toLowerCase().indexOf(term);
14+
15+
if(searchResult >= 0) {
16+
$(this).attr('style', 'padding: 5px;display: block;border: 0px;border-radius: 0px;border-bottom: 1px solid #ddd;color: red;background: #fff2f2;');
17+
$($(this).prev()).attr('id', 'foundSearch');
18+
} else {
19+
$(this).attr('style', 'padding: 5px;display: block;border: 0px;border-radius: 0px;border-bottom: 1px solid #ddd;');
20+
$(this).removeAttr('id');
21+
}
22+
});
23+
24+
if($('#foundSearch').length == 1) {
25+
$('html, body').stop().animate({
26+
scrollTop: $('#foundSearch').offset().top
27+
}, 1000);
28+
}
29+
}
30+
31+
function toggleClass(sub_id) {
32+
splitSub = sub_id.split(',');
33+
splitSubLength = splitSub.length-1;
34+
35+
$('#sub_'+splitSub[0]).collapse('toggle');
36+
37+
if($('#sub_'+splitSub[0]).attr('style') == 'height: 0px;') {
38+
console.log('vis');
39+
$.cookie("sub_classes_"+splitSub[0], '0');
40+
} else {
41+
console.log('hid');
42+
$.cookie("sub_classes_"+splitSub[0], '1');
43+
}
44+
45+
if(splitSubLength != 1) {
46+
$.each(splitSub,function(index,value){
47+
if($('#sub_'+splitSub[0]).is(':hidden')) {
48+
$('#sub_'+value).collapse('hide');
49+
}
50+
});
51+
}
52+
}
53+
</script>
54+
<input type="text" class="form-control" id="filterProp" oninput="filterProp();" placeholder="{$smarty.const.LANG_NEWMARKET_SEARCH_INPUT_PLACEHOLDER}">
55+
</div>
56+
<div class="col-lg-6 col-md-7 col-sm-12 col-xs-12 text-right" style="margin-bottom: 15px;">
57+
<div class="visible-sm visible-xs" style="margin-top: 5px;"></div>
58+
<a href="?view_mode=edit_classes" class="btn btn-success"><i class="glyphicon glyphicon-plus"></i> {$smarty.const.LANG_ADD_NEW_CLASS}</a>
59+
<div class="visible-sm visible-xs" style="margin-top: 5px;"></div>
60+
<a href="{$smarty.const.ROOTHTML}panel/class/0/object/0.html?md=objects&view_mode=edit_objects&id=" class="btn btn-success" title="{$smarty.const.LANG_EDIT}"><i class="glyphicon glyphicon-plus"></i> {$smarty.const.LANG_ADD_NEW_OBJECT}</a>
61+
</div>
62+
</div>
63+
64+
<div class="row" style="margin-right: -15px;margin-left: -15px;">
65+
<div class="col-md-12" style="margin-bottom: 15px;">
66+
<form action="?" method="post" name="frmList_classes" style="padding:0px">
67+
{function name=classes}
68+
{foreach $items as $item}
69+
<script language="javascript">
70+
$(function() {
71+
if ($.cookie("sub_classes_{$item.ID}") == '1') {
72+
$('#sub_{$item.ID}').collapse('show');
73+
}
74+
});
75+
</script>
76+
<div class="panel panel-{if $item.TITLE == 'SDevices'}primary{else}{if $item.TITLE == 'Computer' OR $item.TITLE == 'systemStates' OR $item.TITLE == 'OperationalModes' OR $item.TITLE == 'Timer'}danger{else}default{/if}{/if}" style="margin-bottom: 5px;{if $item.LEVEL_PAD!=0}margin:10px;{/if}">
77+
<div class="panel-heading">
78+
<div class="row">
79+
<div class="col-lg-8 col-md-8 col-sm-7 col-xs-9" onclick="toggleClass('{if $item.SUB_LIST!=$item.ID}{$item.ID},{/if}{$item.SUB_LIST}');" style="cursor: pointer;{if $item.CAN_DELETE=="1"}opacity: 0.3;{/if}">
80+
<h3 class="panel-title">
81+
<i class="glyphicon glyphicon-search" style="margin-right: 10px;vertical-align: text-top;cursor: pointer;" onclick="$('#filter_modules').val('{$item.TITLE}');filterSearch();$('#mdmGlobalSearchModal').modal('show');"></i> {$item.TITLE}
82+
</h3>
83+
{if $item.DESCRIPTION!=''}<div style="font-size: 1rem;padding-left: 30px;">{$item.DESCRIPTION}</div>{/if}
84+
</div>
85+
<div class="col-lg-4 col-md-4 col-sm-5 col-xs-3 text-right">
86+
<div class="btn-group btn-group-xs">
87+
<a href="?view_mode=edit_classes&id={$item.ID}" class="btn btn-success btn-sm" title="{$smarty.const.LANG_EDIT}"><i class="glyphicon glyphicon-pencil"></i></a>
88+
<a href="?view_mode=edit_classes&id={$item.ID}&tab=properties" class="btn btn-default btn-sm" title="{$smarty.const.LANG_PROPERTIES}"><i class="glyphicon glyphicon-th"></i></a>
89+
<a href="?view_mode=edit_classes&id={$item.ID}&tab=methods" class="btn btn-default btn-sm hidden-xs" title="{$smarty.const.LANG_METHODS}"><i class="glyphicon glyphicon-th-list"></i></a>
90+
<a href="?view_mode=edit_classes&id={$item.ID}&tab=objects" class="btn btn-default btn-sm hidden-xs" title="{$smarty.const.LANG_OBJECTS}"><i class="glyphicon glyphicon-th-large"></i></a>
91+
<a href="?view_mode=edit_classes&parent_id={$item.ID}" class="btn btn-default btn-sm hidden-xs" title="{$smarty.const.LANG_EXPAND}"><i class=""></i>{$smarty.const.LANG_EXPAND}</a>
92+
{if $item.CAN_DELETE=="1"}
93+
<a href="?view_mode=delete_classes&id={$item.ID}" onClick="return confirm('{$smarty.const.LANG_ARE_YOU_SURE}')" class="btn btn-danger btn-sm" title="{$smarty.const.LANG_DELETE}"><i class="glyphicon glyphicon-remove"></i></a>
94+
{/if}
95+
</div>
96+
</div>
97+
</div>
98+
</div>
99+
<div class="panel-collapse collapse out" id="sub_{$item.ID}">
100+
{if $item.OBJECTS}
101+
<ul class="list-group classSearch">
102+
{foreach $item.OBJECTS as $object}
103+
<li style="padding: 5px;display: block;border: 0px;border-radius: 0px;border-bottom: 1px solid #ddd;">
104+
<div class="row">
105+
<div class="col-md-12">
106+
<a href="{$smarty.const.ROOTHTML}panel/class/{$item.ID}/object/{$object.ID}.html">{$object.TITLE}</a> {if $object.DESCRIPTION != ''}<span style="font-size: 1rem;color: gray;vertical-align: middle;">→ {$object.DESCRIPTION}</span>{/if}
107+
{if $object.KEY_DATA!=""} → <i>{$object.KEY_DATA}</i>{/if}
108+
{if $object.METHODS}
109+
<div style="padding-left: 10px">
110+
{foreach $object.METHODS as $method}
111+
<p style="color: gray;font-size: 1.2rem;margin: 0px;">↳
112+
<span class="label label-primary" style="margin-bottom: 5px;">{$smarty.const.LANG_METHOD}:
113+
<a style="color: white;text-decoration: none;"
114+
href="{$smarty.const.ROOTHTML}panel/class/{$item.ID}/object/{$object.ID}.html?tab=methods&overwrite=1&method_id={$method.ID}">{$method.TITLE}</a></span></p>
115+
{/foreach}
116+
</div>
117+
{/if}
118+
</div>
119+
</div>
120+
</li>
121+
{/foreach}
122+
</ul>
123+
{/if}
124+
125+
{if $item.RESULT}
126+
{classes items=$item.RESULT}
127+
{/if}
128+
129+
</div>
130+
</div>
131+
{/foreach}
132+
{/function}
133+
{classes items=$RESULT}
134+
<input type="hidden" name="data_source" value="<#DATA_SOURCE#>">
135+
<input type="hidden" name="view_mode" value="multiple_classes">
136+
</form>
137+
</div>
138+
</div>
139+
140+
141+
142+
143+
144+
&nbsp;
145+
<a href="#" onClick="$('#tools').toggle();return false;" class="btn btn-default">{$smarty.const.LANG_TOOLS}</a>
146+
<br>&nbsp;
147+
<div id='tools' style="display:none">
148+
<form action="?" enctype="multipart/form-data" method="post">
149+
<table border="0">
150+
<tr>
151+
<td valign="top">
152+
{$smarty.const.LANG_IMPORT_CLASS_FROM_FILE}:
153+
</td>
154+
<td valign="top"><input type="file" name="file" enctype="multipart/form-data"></td>
155+
</tr>
156+
<tr>
157+
<td valign="top">&nbsp;</td>
158+
<td valign="top"><label><input type="checkbox" name="overwrite" value="1">
159+
{$smarty.const.LANG_OVERWRITE}
160+
</label></td>
161+
</tr>
162+
<tr>
163+
<td valign="top">&nbsp;</td>
164+
<td valign="top"><label><input type="checkbox" name="only_classes" value="1">
165+
{$smarty.const.LANG_ONLY_CLASSES}
166+
</label></td>
167+
</tr>
168+
<tr>
169+
<td valign="top">&nbsp;</td>
170+
<td valign="top"><input type="submit" name="submit" value="{$smarty.const.LANG_IMPORT}" class="btn btn-default">
171+
</td>
172+
</tr>
173+
</table>
174+
<input type="hidden" name="view_mode" value="import_classes">
175+
</form>
176+
</div>

templates/panel.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
</ul>
102102
</li>
103103
[#if HIDE_LEFT_PANEL="1"#]
104-
[#inc panel_nav_top.html#]
104+
[#inc panel_nav_top.tpl#]
105105
[#else#]
106106
<li class="dropdown">
107107
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="glyphicon glyphicon-dashboard" style="vertical-align: top;font-size: 11pt;"></i> <#LANG_SECTION_SYSTEM#> <b class="caret"></b></a>

0 commit comments

Comments
 (0)