Added admin page to update script caches.

This commit is contained in:
Oleg Sh 2023-11-11 16:01:55 +02:00
parent 3f9586951e
commit af68690055
15 changed files with 142 additions and 21 deletions

View File

@ -93,5 +93,5 @@
$g_config['vote'] = "./tmp/vote/vote.txt";
$g_config['voteTopics'] = "./tmp/vote/voteTopics.txt_";
$g_config['use_js_cache'] = true;
$g_config['engine_version'] = 1;
$g_config['engine_version'] = 76;
?>

View File

@ -46,7 +46,8 @@
array('link' => SiteRoot('admin/page_saved_graph'), 'name' => 'Статистика', 'label' => 'Статистика сохранений'),
array('link' => SiteRoot('admin/page_example_graph'), 'name' => 'Примеры', 'label' => 'Примеры графов'),
array('link' => SiteRoot('admin/page_vote'), 'name' => 'Голосование', 'label' => 'Результаты голосования'),
array('link' => SiteRoot('admin/page_test_graphcgi'), 'name' => 'Тестирование CGI', 'label' => 'Тестирования GraphCGI')
array('link' => SiteRoot('admin/page_test_graphcgi'), 'name' => 'Тестирование CGI', 'label' => 'Тестирования GraphCGI'),
array('link' => SiteRoot('admin/page_update_script_cache'), 'name' => 'Обновить кэш скрипта', 'label' => 'Обновить кэш скрипта')
)
);

View File

@ -1,6 +1,3 @@
// Global version needs to force reload scripts from server.
globalVersion = 75;
{
let modulDir = "pages/create_graph_by_edge_list/";

View File

@ -1,4 +1,4 @@
moduleLoader.beginCacheLoading(["/script/entities/graph/api/index.js?v=75","/script/shared/point.js?v=75","/script/entities/edge/api/index.js?v=75","/script/entities/edge/model/BaseEdge.js?v=75","/script/entities/edge/model/EdgeModel.js?v=75","/script/entities/vertex/api/index.js?v=75","/script/entities/vertex/model/BaseVertex.js?v=75","/script/entities/vertex/model/VertexModel.js?v=75","/script/entities/graph/model/Graph.js?v=75",]);globalVersion=75;{let modulDir="pages/create_graph_by_edge_list/";doInclude([include("entities/graph/api/index.js")]);}
moduleLoader.beginCacheLoading(["/script/entities/graph/api/index.js?v=75","/script/shared/point.js?v=75","/script/entities/edge/api/index.js?v=75","/script/entities/edge/model/BaseEdge.js?v=75","/script/entities/edge/model/EdgeModel.js?v=75","/script/entities/vertex/api/index.js?v=75","/script/entities/vertex/model/BaseVertex.js?v=75","/script/entities/vertex/model/VertexModel.js?v=75","/script/entities/graph/model/Graph.js?v=75",]);{let modulDir="pages/create_graph_by_edge_list/";doInclude([include("entities/graph/api/index.js")]);}
{let modulDir="entities/graph/";doInclude([include("shared/point.js"),include("entities/edge/api/index.js"),include("entities/vertex/api/index.js"),include("model/Graph.js",modulDir)])}function Point(x,y){this.x=x||0;this.y=y||0;};Point.prototype.x=null;Point.prototype.y=null;Point.prototype.add=function(v){return new Point(this.x+v.x,this.y+v.y);};Point.prototype.addValue=function(v){return new Point(this.x+v,this.y+v);};Point.prototype.clone=function(){return new Point(this.x,this.y);};Point.prototype.degreesTo=function(v){var dx=this.x-v.x;var dy=this.y-v.y;var angle=Math.atan2(dy,dx);return angle*(180/Math.PI);};Point.prototype.distance=function(v){return Math.sqrt(this.distanceSqr(v));};Point.prototype.distanceSqr=function(v){var x=this.x-v.x;var y=this.y-v.y;return x*x+y*y;};Point.prototype.equals=function(toCompare){return this.x==toCompare.x&&this.y==toCompare.y;};Point.prototype.interpolate=function(v,f){return new Point((this.x+v.x)*f,(this.y+v.y)*f);};Point.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y);};Point.prototype.normalize=function(thickness){var l=this.length();this.x=this.x/l*thickness;this.y=this.y/l*thickness;return new Point(this.x,this.y);};Point.prototype.normalizeCopy=function(thickness){var l=this.length();return new Point(this.x/l*thickness,this.y/l*thickness);};Point.prototype.orbit=function(origin,arcWidth,arcHeight,degrees){var radians=degrees*(Math.PI/180);this.x=origin.x+arcWidth*Math.cos(radians);this.y=origin.y+arcHeight*Math.sin(radians);};Point.prototype.rotate=function(center,degrees){var radians=degrees*(Math.PI/180);offset=this.subtract(center);this.x=offset.x*Math.cos(radians)-offset.y*Math.sin(radians);this.y=offset.x*Math.sin(radians)+offset.y*Math.cos(radians);this.x=this.x+center.x;this.y=this.y+center.y;return this;};Point.prototype.offset=function(dx,dy){this.x+=dx;this.y+=dy;};Point.prototype.subtract=function(v){return new Point(this.x-v.x,this.y-v.y);};Point.prototype.subtractValue=function(value){return new Point(this.x-value,this.y-value);};Point.prototype.multiply=function(value){return new Point(this.x*value,this.y*value);};Point.prototype.toString=function(){return"(x="+this.x+", y="+this.y+")";};Point.prototype.normal=function(){return new Point(-this.y,this.x);};Point.prototype.min=function(point)
{return new Point(Math.min(this.x,point.x),Math.min(this.y,point.y));};Point.prototype.max=function(point)
{return new Point(Math.max(this.x,point.x),Math.max(this.y,point.y));};Point.prototype.inverse=function()

View File

@ -1,7 +1,3 @@
// Global version needs to force reload scripts from server.
globalVersion = 75;
{
let modulDir = "pages/create_graph_by_matrix/";

View File

@ -1,4 +1,4 @@
moduleLoader.beginCacheLoading(["/script/entities/graph/api/index.js?v=75","/script/shared/point.js?v=75","/script/entities/edge/api/index.js?v=75","/script/entities/edge/model/BaseEdge.js?v=75","/script/entities/edge/model/EdgeModel.js?v=75","/script/entities/vertex/api/index.js?v=75","/script/entities/vertex/model/BaseVertex.js?v=75","/script/entities/vertex/model/VertexModel.js?v=75","/script/entities/graph/model/Graph.js?v=75",]);globalVersion=75;{let modulDir="pages/create_graph_by_matrix/";doInclude([include("entities/graph/api/index.js")]);}
moduleLoader.beginCacheLoading(["/script/entities/graph/api/index.js?v=75","/script/shared/point.js?v=75","/script/entities/edge/api/index.js?v=75","/script/entities/edge/model/BaseEdge.js?v=75","/script/entities/edge/model/EdgeModel.js?v=75","/script/entities/vertex/api/index.js?v=75","/script/entities/vertex/model/BaseVertex.js?v=75","/script/entities/vertex/model/VertexModel.js?v=75","/script/entities/graph/model/Graph.js?v=75",]);{let modulDir="pages/create_graph_by_matrix/";doInclude([include("entities/graph/api/index.js")]);}
{let modulDir="entities/graph/";doInclude([include("shared/point.js"),include("entities/edge/api/index.js"),include("entities/vertex/api/index.js"),include("model/Graph.js",modulDir)])}function Point(x,y){this.x=x||0;this.y=y||0;};Point.prototype.x=null;Point.prototype.y=null;Point.prototype.add=function(v){return new Point(this.x+v.x,this.y+v.y);};Point.prototype.addValue=function(v){return new Point(this.x+v,this.y+v);};Point.prototype.clone=function(){return new Point(this.x,this.y);};Point.prototype.degreesTo=function(v){var dx=this.x-v.x;var dy=this.y-v.y;var angle=Math.atan2(dy,dx);return angle*(180/Math.PI);};Point.prototype.distance=function(v){return Math.sqrt(this.distanceSqr(v));};Point.prototype.distanceSqr=function(v){var x=this.x-v.x;var y=this.y-v.y;return x*x+y*y;};Point.prototype.equals=function(toCompare){return this.x==toCompare.x&&this.y==toCompare.y;};Point.prototype.interpolate=function(v,f){return new Point((this.x+v.x)*f,(this.y+v.y)*f);};Point.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y);};Point.prototype.normalize=function(thickness){var l=this.length();this.x=this.x/l*thickness;this.y=this.y/l*thickness;return new Point(this.x,this.y);};Point.prototype.normalizeCopy=function(thickness){var l=this.length();return new Point(this.x/l*thickness,this.y/l*thickness);};Point.prototype.orbit=function(origin,arcWidth,arcHeight,degrees){var radians=degrees*(Math.PI/180);this.x=origin.x+arcWidth*Math.cos(radians);this.y=origin.y+arcHeight*Math.sin(radians);};Point.prototype.rotate=function(center,degrees){var radians=degrees*(Math.PI/180);offset=this.subtract(center);this.x=offset.x*Math.cos(radians)-offset.y*Math.sin(radians);this.y=offset.x*Math.sin(radians)+offset.y*Math.cos(radians);this.x=this.x+center.x;this.y=this.y+center.y;return this;};Point.prototype.offset=function(dx,dy){this.x+=dx;this.y+=dy;};Point.prototype.subtract=function(v){return new Point(this.x-v.x,this.y-v.y);};Point.prototype.subtractValue=function(value){return new Point(this.x-value,this.y-value);};Point.prototype.multiply=function(value){return new Point(this.x*value,this.y*value);};Point.prototype.toString=function(){return"(x="+this.x+", y="+this.y+")";};Point.prototype.normal=function(){return new Point(-this.y,this.x);};Point.prototype.min=function(point)
{return new Point(Math.min(this.x,point.x),Math.min(this.y,point.y));};Point.prototype.max=function(point)
{return new Point(Math.max(this.x,point.x),Math.max(this.y,point.y));};Point.prototype.inverse=function()

View File

@ -1,7 +1,3 @@
// Global version needs to force reload scripts from server.
globalVersion = 75;
{
let modulDir = "pages/create_graph_by_matrix/";

View File

@ -1,4 +1,4 @@
moduleLoader.beginCacheLoading(["/script/entities/graph/api/index.js?v=75","/script/shared/point.js?v=75","/script/entities/edge/api/index.js?v=75","/script/entities/edge/model/BaseEdge.js?v=75","/script/entities/edge/model/EdgeModel.js?v=75","/script/entities/vertex/api/index.js?v=75","/script/entities/vertex/model/BaseVertex.js?v=75","/script/entities/vertex/model/VertexModel.js?v=75","/script/entities/graph/model/Graph.js?v=75","/script/pages/create_graph_by_matrix/model/createByMatrixMain.js?v=75","/script/pages/create_graph_by_matrix/model/main.js?v=75",]);globalVersion=75;{let modulDir="pages/create_graph_by_matrix/";doInclude([include("entities/graph/api/index.js"),include("model/createByMatrixMain.js",modulDir),include("model/main.js",modulDir)]);}
moduleLoader.beginCacheLoading(["/script/entities/graph/api/index.js?v=75","/script/shared/point.js?v=75","/script/entities/edge/api/index.js?v=75","/script/entities/edge/model/BaseEdge.js?v=75","/script/entities/edge/model/EdgeModel.js?v=75","/script/entities/vertex/api/index.js?v=75","/script/entities/vertex/model/BaseVertex.js?v=75","/script/entities/vertex/model/VertexModel.js?v=75","/script/entities/graph/model/Graph.js?v=75","/script/pages/create_graph_by_matrix/model/createByMatrixMain.js?v=75","/script/pages/create_graph_by_matrix/model/main.js?v=75",]);{let modulDir="pages/create_graph_by_matrix/";doInclude([include("entities/graph/api/index.js"),include("model/createByMatrixMain.js",modulDir),include("model/main.js",modulDir)]);}
{let modulDir="entities/graph/";doInclude([include("shared/point.js"),include("entities/edge/api/index.js"),include("entities/vertex/api/index.js"),include("model/Graph.js",modulDir)])}function Point(x,y){this.x=x||0;this.y=y||0;};Point.prototype.x=null;Point.prototype.y=null;Point.prototype.add=function(v){return new Point(this.x+v.x,this.y+v.y);};Point.prototype.addValue=function(v){return new Point(this.x+v,this.y+v);};Point.prototype.clone=function(){return new Point(this.x,this.y);};Point.prototype.degreesTo=function(v){var dx=this.x-v.x;var dy=this.y-v.y;var angle=Math.atan2(dy,dx);return angle*(180/Math.PI);};Point.prototype.distance=function(v){return Math.sqrt(this.distanceSqr(v));};Point.prototype.distanceSqr=function(v){var x=this.x-v.x;var y=this.y-v.y;return x*x+y*y;};Point.prototype.equals=function(toCompare){return this.x==toCompare.x&&this.y==toCompare.y;};Point.prototype.interpolate=function(v,f){return new Point((this.x+v.x)*f,(this.y+v.y)*f);};Point.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y);};Point.prototype.normalize=function(thickness){var l=this.length();this.x=this.x/l*thickness;this.y=this.y/l*thickness;return new Point(this.x,this.y);};Point.prototype.normalizeCopy=function(thickness){var l=this.length();return new Point(this.x/l*thickness,this.y/l*thickness);};Point.prototype.orbit=function(origin,arcWidth,arcHeight,degrees){var radians=degrees*(Math.PI/180);this.x=origin.x+arcWidth*Math.cos(radians);this.y=origin.y+arcHeight*Math.sin(radians);};Point.prototype.rotate=function(center,degrees){var radians=degrees*(Math.PI/180);offset=this.subtract(center);this.x=offset.x*Math.cos(radians)-offset.y*Math.sin(radians);this.y=offset.x*Math.sin(radians)+offset.y*Math.cos(radians);this.x=this.x+center.x;this.y=this.y+center.y;return this;};Point.prototype.offset=function(dx,dy){this.x+=dx;this.y+=dy;};Point.prototype.subtract=function(v){return new Point(this.x-v.x,this.y-v.y);};Point.prototype.subtractValue=function(value){return new Point(this.x-value,this.y-value);};Point.prototype.multiply=function(value){return new Point(this.x*value,this.y*value);};Point.prototype.toString=function(){return"(x="+this.x+", y="+this.y+")";};Point.prototype.normal=function(){return new Point(-this.y,this.x);};Point.prototype.min=function(point)
{return new Point(Math.min(this.x,point.x),Math.min(this.y,point.y));};Point.prototype.max=function(point)
{return new Point(Math.max(this.x,point.x),Math.max(this.y,point.y));};Point.prototype.inverse=function()

View File

@ -1,7 +1,3 @@
// Global version needs to force reload scripts from server.
globalVersion = 75;
{
function onloadEditor() {
console.log("onload() call");

View File

@ -1,4 +1,4 @@
moduleLoader.beginCacheLoading(["/script/shared/utils.js?v=75","/script/entities/graph/api/index.js?v=75","/script/shared/point.js?v=75","/script/entities/edge/api/index.js?v=75","/script/entities/edge/model/BaseEdge.js?v=75","/script/entities/edge/model/EdgeModel.js?v=75","/script/entities/vertex/api/index.js?v=75","/script/entities/vertex/model/BaseVertex.js?v=75","/script/entities/vertex/model/VertexModel.js?v=75","/script/entities/graph/model/Graph.js?v=75","/script/features/draw_graph/api/index.js?v=75","/script/features/draw_graph/model/BaseBackgroundDrawer.js?v=75","/script/features/draw_graph/model/BaseEdgeDrawer.js?v=75","/script/features/draw_graph/model/BaseVertexDrawer.js?v=75","/script/features/algorithms/api/index.js?v=75","/script/features/algorithms/model/Algorithms.js?v=75","/script/features/algorithms/model/BaseTraversal.js?v=75","/script/features/base_handler/index.js?v=75","/script/features/default_handler/index.js?v=75","/script/features/add_vertices_handler/index.js?v=75","/script/features/connect_vertices_handler/index.js?v=75","/script/features/delete_objects_handler/index.js?v=75","/script/features/algorithm_handler/index.js?v=75","/script/features/serialization/api/index.js?v=75","/script/features/serialization/model/GraphMLCreator.js?v=75","/script/features/enum_vertices/EnumVertices.js?v=75","/script/pages/editor/model/texts.js?v=75","/script/pages/editor/model/Application.js?v=75","/script/pages/editor/ui/main.js?v=75",]);globalVersion=75;{function onloadEditor(){console.log("onload() call");doIncludeAsync([include("shared/canvas2svg.js"),include("features/group_rename_handler/index.js"),include("features/saved_graph_handler/index.js"),include("features/saved_graph_image_handler/index.js"),include("features/show_adjacency_matrix/index.js"),include("features/show_distance_matrix/index.js"),include("features/show_incidence_matrix/index.js"),include("features/setup_background_style/index.js"),include("features/setup_edge_style/index.js"),include("features/setup_vertex_style/index.js"),]);preLoadPage();postLoadPage();}
moduleLoader.beginCacheLoading(["/script/shared/utils.js?v=75","/script/entities/graph/api/index.js?v=75","/script/shared/point.js?v=75","/script/entities/edge/api/index.js?v=75","/script/entities/edge/model/BaseEdge.js?v=75","/script/entities/edge/model/EdgeModel.js?v=75","/script/entities/vertex/api/index.js?v=75","/script/entities/vertex/model/BaseVertex.js?v=75","/script/entities/vertex/model/VertexModel.js?v=75","/script/entities/graph/model/Graph.js?v=75","/script/features/draw_graph/api/index.js?v=75","/script/features/draw_graph/model/BaseBackgroundDrawer.js?v=75","/script/features/draw_graph/model/BaseEdgeDrawer.js?v=75","/script/features/draw_graph/model/BaseVertexDrawer.js?v=75","/script/features/algorithms/api/index.js?v=75","/script/features/algorithms/model/Algorithms.js?v=75","/script/features/algorithms/model/BaseTraversal.js?v=75","/script/features/base_handler/index.js?v=75","/script/features/default_handler/index.js?v=75","/script/features/add_vertices_handler/index.js?v=75","/script/features/connect_vertices_handler/index.js?v=75","/script/features/delete_objects_handler/index.js?v=75","/script/features/algorithm_handler/index.js?v=75","/script/features/serialization/api/index.js?v=75","/script/features/serialization/model/GraphMLCreator.js?v=75","/script/features/enum_vertices/EnumVertices.js?v=75","/script/pages/editor/model/texts.js?v=75","/script/pages/editor/model/Application.js?v=75","/script/pages/editor/ui/main.js?v=75",]);{function onloadEditor(){console.log("onload() call");doIncludeAsync([include("shared/canvas2svg.js"),include("features/group_rename_handler/index.js"),include("features/saved_graph_handler/index.js"),include("features/saved_graph_image_handler/index.js"),include("features/show_adjacency_matrix/index.js"),include("features/show_distance_matrix/index.js"),include("features/show_incidence_matrix/index.js"),include("features/setup_background_style/index.js"),include("features/setup_edge_style/index.js"),include("features/setup_vertex_style/index.js"),]);preLoadPage();postLoadPage();}
let modulDir="pages/editor/";doInclude([include("shared/utils.js"),include("entities/graph/api/index.js"),include("features/draw_graph/api/index.js"),include("features/algorithms/api/index.js"),include("features/base_handler/index.js"),include("features/default_handler/index.js"),include("features/add_vertices_handler/index.js"),include("features/connect_vertices_handler/index.js"),include("features/delete_objects_handler/index.js"),include("features/algorithm_handler/index.js"),include("features/serialization/api/index.js"),include("features/enum_vertices/EnumVertices.js"),include("model/texts.js",modulDir),include("model/Application.js",modulDir),include("ui/main.js",modulDir)],onloadEditor);}
function gEncodeToHTML(str)
{if(typeof str!=='string')

View File

@ -1,3 +1,6 @@
// Global version needs to force reload scripts from server.
let globalVersion = 75;
var include = function(filename, localDir) {
return {filename: filename, localDir: localDir};
};

68
src/admin/pack.php Normal file
View File

@ -0,0 +1,68 @@
<?php
/**
* Return relative path between two sources
* @param $from
* @param $to
* @param string $separator
* @return string
*/
function relativePath($from, $to, $separator = DIRECTORY_SEPARATOR)
{
$from = str_replace(array('/', '\\'), $separator, $from);
$to = str_replace(array('/', '\\'), $separator, $to);
$arFrom = explode($separator, rtrim($from, $separator));
$arTo = explode($separator, rtrim($to, $separator));
while(count($arFrom) && count($arTo) && ($arFrom[0] == $arTo[0]))
{
array_shift($arFrom);
array_shift($arTo);
}
return str_pad("", count($arFrom) * 3, '..'.$separator).implode($separator, $arTo);
}
include (relativePath(dirname($_SERVER['PHP_SELF']), "/") . "lib/ExtraPacker/Lib/JSMin.php");
if (isset($_GET["cacheFiles"])) {
$cacheFilenameList = $_GET["cacheFiles"];
$files = explode(",", $cacheFilenameList);
//print_r($files);
$indexFilename = "./" . $_GET["target"];
$outputFilename = $indexFilename . '.cache';
unlink($outputFilename);
// Put files already loaded.
$cacheContent = "";
$cacheContent = $cacheContent . "\nmoduleLoader.beginCacheLoading([";
foreach ($files as &$file) {
$cacheContent = $cacheContent . "\"" . $file . "\"" . ",";
}
$cacheContent = $cacheContent . "]);\n";
// Put index file.
$processedFilesCount = 1;
$cacheContent = $cacheContent . file_get_contents($indexFilename);
// Put files
foreach ($files as &$file) {
$relativePath = strtok($file, '?');
$relativePath = relativePath(dirname($_SERVER['PHP_SELF']), $relativePath);
$cacheContent = $cacheContent . file_get_contents($relativePath);
$processedFilesCount ++;
}
// Put event about cache loaded.
$cacheContent = $cacheContent . "\nmoduleLoader.endCacheLoading();";
$minifiedCacheContent = JSMin::minify($cacheContent);
file_put_contents($outputFilename, $minifiedCacheContent, FILE_APPEND);
echo("<p>Processed files: " . $processedFilesCount . "</p>");
echo("<p>File updated: " . $outputFilename . "</p>");
echo("<p>You may close this page</p>");
}
?>

View File

@ -0,0 +1,10 @@
<?php
$cacheList = array(
"/script/pages/editor/api/index.js",
"/script/pages/create_graph_by_edge_list/api/index.js",
"/script/pages/create_graph_by_incidence_matrix/api/index.js",
"/script/pages/create_graph_by_matrix/api/index.js"
);
?>

41
tpl/admin/pack.php Normal file
View File

@ -0,0 +1,41 @@
<?php if (!isset($_GET["cacheFiles"]) && isset($_GET["target"])): ?>
<head>
<script src="/script/shared/config.js" ></script>
<script src="/script/shared/loader.js" ></script>
<script src="<?= $_GET["target"] ?>" ></script>
<script>
setTimeout(
() => {
document.getElementById("state").innerHTML = "Saving files";
const xhr = new XMLHttpRequest();
xhr.open("GET", "pack?cacheFiles=" + moduleLoader.syncLoaded.toString() + "&target=" + "<?= $_GET["target"] ?>");
xhr.send();
xhr.onload = () => {
if (xhr.readyState == 4 && xhr.status == 200) {
document.getElementById("state").innerHTML = "Finished <br>";
document.getElementById("other_page").innerHTML = xhr.response;
} else {
document.getElementById("state").innerHTML = "Error happends";
}
};
}, 3000);
</script>
</head>
<body>
<div>
<h1>Update script cache</h1>
<h2>State: <span id="state">Loading</span></h2>
<p id="other_page"></p>
</div>
</doby>
<?php endif; ?>
<?php
if (!isset($_GET["target"])) {
echo ("Error target is not set");
return;
}
?>

View File

@ -0,0 +1,13 @@
<?php IncludeCom('dev/bootstrap3')?>
<h1>Update script cache</h1>
<p>Click to each link to update cache. Don't forget change $g_config['engine_version'] version in file /core/config/main.php</p>
<ul>
<?php
foreach ($cacheList as &$page) {
$date = date('d.m.Y H:i:s', filemtime("./$page.cache"));
echo ("<li><a href='pack?target=$page' target='_blank'>$page</a> $date</li>");
}
?>
</ul>