Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "packages/core/apps/workbench"]
path = packages/core/apps/workbench/sources
url = https://github.com/f7ed0/equal-workbench.git
branch = dev
6 changes: 3 additions & 3 deletions packages/core/actions/config/create-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
throw new Exception("view_id_invalid",QN_ERROR_INVALID_PARAM);
}

if(strcmp($type, "form")!==0 && strcmp($type, "list")!==0) {
if(strcmp($type, "form")!==0 && strcmp($type, "list")!==0 && strcmp($type, "search")!==0 && strcmp($type, "app")!==0 && strcmp($type, $package)!==0 ) {
$test = strcmp($type, "list");
throw new Exception("view_type_invalid",QN_ERROR_INVALID_PARAM);
}
Expand Down Expand Up @@ -85,10 +85,10 @@
throw new Exception('file_access_denied', QN_ERROR_UNKNOWN);
}

if($type == "form") {
if($type == "form" || $type == "search") {
fputs($f,"{\"layout\" : {\"groups\" : []}}");
}
elseif($type == "list") {
else {
fputs($f,"{\"layout\" : {\"items\" : []}}");
}

Expand Down
16 changes: 11 additions & 5 deletions packages/core/actions/config/update-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'controller' => [
'description' => 'Name of the controller.',
'type' => 'string',
'usage' => 'orm/entity'
// 'required' => true
],
'operation' => [
Expand Down Expand Up @@ -55,8 +56,8 @@
$prettyPrinter = new PhpParser\PrettyPrinter\Standard;

// Get the parts of the entity string, separated by backslashes
$params['entity'] = str_replace('_', '\\', $params['entity']);
$parts = explode('\\', $params['entity']);
$params['controller'] = str_replace('_', '\\', $params['controller']);
$parts = explode('\\', $params['controller']);

// Get the package name from the first part of the string
$package = array_shift($parts);
Expand All @@ -65,9 +66,12 @@
// Get the class path from the remaining part
$class_path = implode('/', $parts);

/*if(!($decoded = json_decode($params['payload'],true))) {
throw new Exception('Malformed Json', QN_ERROR_INVALID_PARAM);
}*/

// Get a string representation from the code_php variable, with backslashes escaped
$code_string = str_replace("\\\\", "\\", var_export($params['payload'], true));
$code_string = str_replace("\\\\", "\\", var_export( $params['payload'], true));

// #test #toremove
// $code_string = "[
Expand Down Expand Up @@ -137,9 +141,10 @@ public function leaveNode(Node $node) {
);

// Get the full path of the file
$dir = ['do' => 'actions', 'get' => 'date', 'show' => 'apps'][$params['operation']];
$dir = ['do' => 'actions', 'get' => 'data', 'show' => 'apps'][$params['operation']];
$file = QN_BASEDIR."/packages/{$package}/{$dir}/{$class_path}/{$filename}.php";

$file = str_replace("//","/",$file);
// Get the code from the original file ...
$code = file_get_contents($file);
// ... and parse it to create an AST
Expand Down Expand Up @@ -174,7 +179,8 @@ public function leaveNode(Node $node) {
}
}
catch(Exception $e) {
trigger_error("PHP::unable to beautify rendered file ($file): ".$e->getMessage(), QN_REPORT_INFO);
throw new Exception('unable to beautfy the file', QN_ERROR_UNKNOWN);
//trigger_error("PHP::unable to beautify rendered file ($file): ".$e->getMessage(), QN_REPORT_INFO);
}

$result = file_get_contents($file);
Expand Down
1 change: 0 additions & 1 deletion packages/core/apps/workbench/.gitignore

This file was deleted.

8 changes: 2 additions & 6 deletions packages/core/apps/workbench/manifest.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{
"name": "Workbench",
"description": "App for customizing models, views and controllers from the user interface without code.",
"version": "1.0",
"authors": ["Cedric Francoys", "Sylvain Sausse", "Quentin Leveque"],
"license": "LGPL-3",
"repository": "https://github.com/equalframework/apps-core-settings.git",
"description": "This is the workbench application.",
"url": "/workbench",
"icon": "edit_note",
"color": "#0f1397",
"color": "#d2252c",
"access": {
"groups": [
"users", "admin"
Expand Down
1 change: 1 addition & 0 deletions packages/core/apps/workbench/sources
Submodule sources added at 2efc9f
Binary file modified packages/core/apps/workbench/web.app
Binary file not shown.
98 changes: 98 additions & 0 deletions packages/core/data/config/menus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php
/*
This file is part of the eQual framework <http://www.github.com/cedricfrancoys/equal>
Some Rights Reserved, Cedric Francoys, 2010-2021
Licensed under GNU LGPL 3 license <http://www.gnu.org/licenses/>
*/
list($params, $providers) = eQual::announce([
'description' => 'Returns the list of menus defined in a given package, or applicable to a given entity.',
'response' => [
'content-type' => 'application/json',
'charset' => 'UTF-8',
'accept-origin' => '*'
],
'params' => [
'package' => [
'description' => 'Name of the package for which the list is requested.',
'type' => 'string',
'required' => true
],
],
'providers' => ['context', 'orm']
]);

/**
* @var \equal\php\Context $context
* @var \equal\orm\ObjectManager $orm
*/
list($context, $orm) = [$providers['context'], $providers['orm']];

$result = [];

if(!file_exists("packages/{$params['package']}")) {
throw new Exception('missing_package_dir', QN_ERROR_INVALID_CONFIG);
}
if(!file_exists("packages/{$params['package']}/views")) {
throw new Exception('missing_views_dir', QN_ERROR_INVALID_CONFIG);
}
// recurse through all sub-folders of `views` directory
$result = recurse_dir("packages/{$params['package']}/views", 'json', $params['package']);


$context->httpResponse()
->body($result)
->send();

function has_sub_items($directory, $extension) {
$files = glob($directory.'/*.'.$extension);
if(count($files)) {
return true;
}
foreach(glob($directory.'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $node) {
if(has_sub_items($node, $extension)) {
return true;
}
}
return false;
}

/**
* #memo - this method slightly differs from the one in controllers.php and translations.php
*/
function recurse_dir($directory, $extension, $parent_name='') {
$result = array();
if( is_dir($directory) ) {
$dir_name = basename($directory);
$list = glob($directory.'/*');
foreach($list as $node) {
$filename = basename($node, '.'.$extension);
list($entity_name, $view_id) = explode('.', $filename, 2);
if(!($entity_name == 'menu')) continue;
if(is_dir($node)) {
if(!has_sub_items($node, $extension)) {
continue;
}
$result = array_merge($result, recurse_dir($node, $extension, (strlen($parent_name)?$parent_name.'\\'.$filename:$filename)));
}
elseif(pathinfo($node, PATHINFO_EXTENSION) == $extension) {
$entity = (strlen($parent_name)?$parent_name.'\\':'').$entity_name;
try {
// #memo - ! can be controller or class
// $entity::getType();
$result[] = $view_id;
}
catch(Exception $e) {
if($entity_name == 'menu') {
// ignore
}
else {
// entity should be a controller
// #todo - check that the controller actually exists
$result[] = str_replace('\\', '_', $entity).':'.$view_id;
}
}
}
}
}
return $result;
}
5 changes: 4 additions & 1 deletion packages/core/data/config/types.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@
'computed' => [
'type' => ['type' => 'string'],
//'default' => ['type' => 'string'],
'function', 'result_type', 'onupdate', 'store', 'instant', 'multilang', 'selection'
'function', 'result_type', 'onupdate', 'store', 'instant', 'multilang'
],
'array' => [
'default','type' => ['type' => 'string'],'dependencies','onupdate', 'selection','usage'
]
];

Expand Down
1 change: 1 addition & 0 deletions packages/core/data/config/views.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ function recurse_dir($directory, $extension, $parent_name='') {
foreach($list as $node) {
$filename = basename($node, '.'.$extension);
list($entity_name, $view_id) = explode('.', $filename, 2);
if($entity_name == 'menu') continue;
if(is_dir($node)) {
if(!has_sub_items($node, $extension)) {
continue;
Expand Down
Loading