Weekly sync 2022-07-15

This commit is contained in:
Pavel Dmitriev 2022-07-15 15:48:50 +03:00
parent 6cbf608b94
commit 872da83978
8 changed files with 134 additions and 18744 deletions

View File

@ -13,6 +13,7 @@ use Exception;
* @license GPLv3
* @property-read mixed $changelog
* @property-read string $sqlSelectTemplate
* @property-read string $sqlCountSelectTemplate
*
**/
@ -35,6 +36,9 @@ class baseClass extends dbStoredBase implements \JsonSerializable, jsonImportabl
# if null - generated automatically
public static $baseSqlSelectTemplate = null;
# if null - generated automatically
public static $baseSqlCountSelectTemplate = null;
# primary index field. Default is id
public static $sqlIdx = "id";
@ -45,12 +49,14 @@ class baseClass extends dbStoredBase implements \JsonSerializable, jsonImportabl
public static $deletedFieldName = null;
protected $__sqlSelectTemplate = null;
protected $__sqlCountSelectTemplate = null;
# basic exclude props
protected static $excludePropsBase = [
'sql',
'changelog',
'__sqlSelectTemplate',
'__sqlCountSelectTemplate',
'fillPrefix'
];
@ -152,6 +158,12 @@ class baseClass extends dbStoredBase implements \JsonSerializable, jsonImportabl
$this->__sqlSelectTemplate = $this::$baseSqlSelectTemplate;
}
if (empty($this::$baseSqlCountSelectTemplate) && ! empty($this::$sqlTable)) {
$this->__sqlCountSelectTemplate = "select count(".static::$sqlIdx.") as `count` from `" . $this::$sqlTable . "` as `i`";
} else {
$this->__sqlCountSelectTemplate = $this::$baseSqlCountSelectTemplate;
}
if (isset($sql)) {
$this->sql = &$sql;
}
@ -430,6 +442,9 @@ class baseClass extends dbStoredBase implements \JsonSerializable, jsonImportabl
case "sqlSelectTemplate":
return $this->__sqlSelectTemplate;
break;
case "sqlCountSelectTemplate":
return $this->__sqlCountSelectTemplate;
break;
case "sql":
$this->checkSql();
return $this->sql;
@ -545,6 +560,15 @@ class baseClass extends dbStoredBase implements \JsonSerializable, jsonImportabl
if (static::$sqlTable == null) {
throw new \Exception("Search not implemented for ".static::class);
}
if ($pattern instanceof request) {
@$page=$pattern->requestBody->page;
@$pageSize=$pattern->requestBody->pageSize;
$options=(array)$pattern->requestBody;
@$pattern=$pattern->requestBody->pattern;
}
$ref=new static();
$sql = $ref->getSql();
@ -581,8 +605,34 @@ class baseClass extends dbStoredBase implements \JsonSerializable, jsonImportabl
$where = (empty($where)?"":"(".$where.") AND ")."`".static::$deletedFieldName."` = 0";
}
$xRes=static::xSearch($where, $pattern, $options, $sql);
$where = array_key_exists("where",$xRes)?$xRes["where"]:"";
$join=array_key_exists("join",$xRes)?$xRes["join"]:"";
$groupBy=array_key_exists("group",$xRes)?$xRes["group"]:"";
$orderBy=array_key_exists("order",$xRes)?$xRes["order"]:"";
if (empty($orderBy) && array_key_exists("orderBy", $options)) {
@$orderDesc=strtoupper($options["orderDir"])=="DESC"?"DESC":"ASC";
$orderBy=common::clearInput($options["orderBy"])." ".$orderDesc;
}
$sqlQueryStringCount=$ref->sqlCountSelectTemplate.(empty($join)?"":" ".$join).(empty($where)?"":" WHERE ".$where).(empty($groupBy)?"":" GROUP BY ".$groupBy);
$rv=new searchResult();
$pageSize=is_numeric($pageSize)?((int)$pageSize):null;
$page=is_numeric($page)?((int)$page):null;
$page=is_numeric($page)?((int)$page):1;
if ($pageSize) {
$rc=$sql->quickExec1Line($sqlQueryStringCount);
$rv->pages=ceil($rc["count"]/$pageSize);
} else {
$page=1;
$rv->pages=1;
}
if ($rv->pages < $page) { $page=$rv->pages; }
$rv->page=$page;
if ($pageSize!==null) {
if ($page<1) { $page=1;}
@ -591,15 +641,9 @@ class baseClass extends dbStoredBase implements \JsonSerializable, jsonImportabl
$limit="";
}
$xRes=static::xSearch($where, $pattern, $options, $sql);
$where = array_key_exists("where",$xRes)?$xRes["where"]:"";
$join=array_key_exists("join",$xRes)?$xRes["join"]:"";
$groupBy=array_key_exists("group",$xRes)?$xRes["group"]:"";
$sqlQueryString=$ref->sqlSelectTemplate.(empty($join)?"":" ".$join).(empty($where)?"":" WHERE ".$where).(empty($groupBy)?"":" GROUP BY ".$groupBy).(empty($limit)?"":" ".$limit);
$sqlQueryString=$ref->sqlSelectTemplate.(empty($join)?"":" ".$join).(empty($where)?"":" WHERE ".$where).(empty($orderBy)?"":" ORDER BY ".$orderBy).(empty($groupBy)?"":" GROUP BY ".$groupBy).(empty($limit)?"":" ".$limit);
$res=$sql->quickExec($sqlQueryString);
$rv=new searchResult();
$rv->setIndexByPage($page, $pageSize);
while ($row=mysqli_fetch_assoc($res)) {
$rv->push(new static($row));

View File

@ -57,6 +57,7 @@ class request extends baseClass implements noSqlMigration
function parce()
{
global $__foxRequestInstance;
$this->method = (empty($_SERVER["REQUEST_METHOD"]) ? "GET" : $_SERVER["REQUEST_METHOD"]);
if (array_key_exists("FOX_REWRITE", $_SERVER) && $_SERVER["FOX_REWRITE"] != "yes") {
$prefix = ($_SERVER["CONTEXT_PREFIX"] . "index.php/");
@ -89,6 +90,7 @@ class request extends baseClass implements noSqlMigration
$this->module = ((count($req) > 0) ? $req[0] : NULL);
$this->instance=$this->module;
$__foxRequestInstance=$this->instance;
$this->function = ((count($req) > 1) ? $req[1] : NULL);
if (count($req) > 2) {
@ -146,8 +148,10 @@ class request extends baseClass implements noSqlMigration
function shift()
{
global $__foxRequestInstance;
$this->instance=$this->module;
$this->module = $this->function;
$__foxRequestInstance=$this->instance;
$this->function = array_shift($this->parameters);
return $this;
}

View File

@ -1,7 +1,7 @@
<?php
namespace fox;
class searchResult {
public $page=0;
public $page=1;
public $pages=0;
public $result=[];
public $count=0;

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -117,8 +117,18 @@ export function empty() {
*/
export function createLeftPanel(panels) {
let ref=($(".t_main #mainframe div.widget_panel_left"));
export function createLeftPanel(panels, config) {
if (config==undefined) { config={};}
let ref;
if (config.ref) {
ref=config.ref;
} else {
if (!ref) { ref =$(".t_main #mainframe div.widget_panel_left"); }
}
if (ref.length==0) {
ref=$("<div>", { class: "widget_panel_left" }).appendTo(".t_main #mainframe");
} else {
@ -131,18 +141,37 @@ export function createLeftPanel(panels) {
}).appendTo(ref);
$.each(panels,function (index,panel) {
let px = $("<h3>",{text: panel.title, id: panel.id+"_title", append: panel.buttons, style: panel.disabled?"display: none":"" })
.add($("<div>", { class: "widget lock c_contacts", id: panel.id, text: langPack.core.iface.dataLoading, style: panel.disabled?"display: none":""}));
$.each(panels,function (_index,panel) {
let xpdiv=$("<div>", { class: "widget lock c_contacts", id: panel.id, text: langPack.core.iface.dataLoading, style: panel.disabled?"display: none":""});
if (panel.attrs) {
$.each(panel.attrs, function (key, val) {
xpdiv.attr(key,val);
});
}
let px = $("<h3>",{text: panel.title, id: panel.id+"_title", append: panel.buttons, style: panel.disabled?"display: none":"" })
.add(xpdiv);
px.appendTo(divAccord);
});
$( "#accordion" ).accordion({
heightStyle: "content",
activate: function( event, ui) {
}
});
let accConfig={
heightStyle: "content",
};
if (typeof(config.beforeActivate)=="function") {
accConfig.beforeActivate=config.beforeActivate;
}
if (typeof(config.activate)=="function") {
accConfig.activate=config.activate;
}
if (typeof(config.create)=="function") {
accConfig.create=config.create;
}
$("#accordion" ).accordion(accConfig);
}
function panelBeforeActivate(panel, callback) {
@ -518,9 +547,23 @@ export function date2stamp(dateString) {
return (new Date(dateString).getTime()/1000);
}
export function stamp2isodateq(stamp) {
var xdate = new Date(stamp*1000);
var rv=xdate.getFullYear().pad(4)+"-"+String((xdate.getMonth()+1).pad(2))+"-"+String(xdate.getDate().pad(2));
return rv;
}
export function stamp2isodatens(stamp) {
var xdate = new Date(stamp*1000);
var rv=stamp2isodateq(stamp)+" "+xdate.getHours().pad(2)+":"+xdate.getMinutes().pad(2);
return rv;
}
export function stamp2isodate(stamp) {
var xdate = new Date(stamp*1000);
var rv=xdate.getFullYear().pad(4)+"-"+String((xdate.getMonth()+1).pad(2))+"-"+String(xdate.getDate().pad(2))+" "+xdate.getHours().pad(2)+":"+xdate.getMinutes().pad(2)+":"+xdate.getSeconds().pad(2);
var rv=stamp2isodatens(stamp)+":"+xdate.getSeconds().pad(2);
return rv;
}
@ -1108,6 +1151,7 @@ Number.prototype.pad = function(size) {
$(ref).empty();
$(ref).prop('foxPager_prefix', options.prefix);
$(ref).addClass('foxPager_'+options.prefix);
$(ref).addClass('foxPagerMain');
$("<i>",{class: "fas fa-angle-double-left", css: { padding: "0 10 0 10", cursor: 'hand' }}).click(function() {
options.page = parseInt($(ref).prop('foxPager_page'));
@ -1118,7 +1162,7 @@ Number.prototype.pad = function(size) {
sessionStorage.setItem(options.prefix+"pager", options.page);
$(".foxPager_"+options.prefix).find(".foxPager_label").text("Стр: "+options.page+" из "+options.pages);
$(".foxPager_"+options.prefix).prop('foxPager_page', options.page);
options.callback();
options.callback({prefix: options.prefix, page: options.page});
}
})
.appendTo(ref);
@ -1132,7 +1176,7 @@ Number.prototype.pad = function(size) {
sessionStorage.setItem(options.prefix+"pager", options.page);
$(".foxPager_"+options.prefix).find(".foxPager_label").text("Стр: "+options.page+" из "+options.pages);
$(".foxPager_"+options.prefix).prop('foxPager_page', options.page);
options.callback();
options.callback({prefix: options.prefix, page: options.page});
}
}).appendTo(ref);
@ -1148,7 +1192,7 @@ Number.prototype.pad = function(size) {
sessionStorage.setItem(options.prefix+"pager", options.page);
$(".foxPager_"+options.prefix).find(".foxPager_label").text("Стр: "+options.page+" из "+options.pages);
$(".foxPager_"+options.prefix).prop('foxPager_page', options.page);
options.callback();
options.callback({prefix: options.prefix, page: options.page});
}
}).appendTo(ref);
$("<i>",{class: "fas fa-angle-double-right", css: { padding: "0 10 0 10", cursor: 'hand' } }).click(function() {
@ -1161,7 +1205,7 @@ Number.prototype.pad = function(size) {
sessionStorage.setItem(options.prefix+"pager", options.page);
$(".foxPager_"+options.prefix).find(".foxPager_label").text("Стр: "+options.page+" из "+options.pages);
$(".foxPager_"+options.prefix).prop('foxPager_page', options.page);
options.callback();
options.callback({prefix: options.prefix, page: options.page});
}
}).appendTo(ref);

View File

@ -164,6 +164,16 @@ table.datatable th.icon
}
div.foxPagerMain i {
margin-left: 4px;
margin-right: 4px;
}
div.foxPagerMain span.foxPager_label {
margin-left: 10px;
margin-right: 10px;
}
div.header
{
margin: 0px;
@ -1718,7 +1728,8 @@ td.hideablealt, th.hideablealt
display: none;
}
div.widget_panel_left div.accordion div.widget {
/* div.widget_panel_left */
div.accordion div.widget {
padding: 10px 0 10px 0;
height: auto;
margin-top: 5px;