- WIP on some pushMessage and createdAt/updatedAt handling
This commit is contained in:
parent
993c556d30
commit
382a4459d7
@ -58,7 +58,9 @@ class EntityGenerate
|
|||||||
$webPath = $this->pathFromNamespace($this->webNamespace, $this->application->routes);
|
$webPath = $this->pathFromNamespace($this->webNamespace, $this->application->routes);
|
||||||
|
|
||||||
if (empty($webPath)) {
|
if (empty($webPath)) {
|
||||||
throw new \InvalidArgumentException("Could not find web path routes from given namespaces.");
|
throw new \InvalidArgumentException(
|
||||||
|
sprintf("Could not find web path routes from given namespaces. Given info : %s, %s", $this->webNamespace, json_encode($this->application->routes))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +68,9 @@ class EntityGenerate
|
|||||||
$apiPath = $this->pathFromNamespace($this->apiNamespace, $this->application->routes);
|
$apiPath = $this->pathFromNamespace($this->apiNamespace, $this->application->routes);
|
||||||
|
|
||||||
if (empty($apiPath)) {
|
if (empty($apiPath)) {
|
||||||
throw new \InvalidArgumentException("Could not find web path routes from given namespaces.");
|
throw new \InvalidArgumentException(
|
||||||
|
sprintf("Could not find web path routes from given namespaces. Given info : %s, %s", $this->apiNamespace, json_encode($this->application->routes))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->includeDocs) {
|
if ($this->includeDocs) {
|
||||||
@ -101,12 +105,12 @@ class EntityGenerate
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isset($formPath)) {
|
if (isset($formPath)) {
|
||||||
if ($this->saveForm) {
|
if ($this->saveForm ?? false) {
|
||||||
$this->writeToFile($formPath, $this->saveForm, $this->compiledSaveForm,);
|
$this->writeToFile($formPath, $this->saveForm, $this->compiledSaveForm,);
|
||||||
$this->writeToFile($formPath, $this->saveContext, $this->compiledSaveFormContext,);
|
$this->writeToFile($formPath, $this->saveContext, $this->compiledSaveFormContext,);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->deleteForm) {
|
if ($this->deleteForm ?? false) {
|
||||||
$this->writeToFile($formPath, $this->deleteForm, $this->compiledDeleteForm,);
|
$this->writeToFile($formPath, $this->deleteForm, $this->compiledDeleteForm,);
|
||||||
$this->writeToFile($formPath, $this->deleteContext, $this->compiledDeleteFormContext,);
|
$this->writeToFile($formPath, $this->deleteContext, $this->compiledDeleteFormContext,);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,11 @@ abstract class Save extends Form implements \Picea\Ui\Method\FormInterface {
|
|||||||
|
|
||||||
protected string $messageWarningSave = 'lean.api.form.save.warning.entity';
|
protected string $messageWarningSave = 'lean.api.form.save.warning.entity';
|
||||||
|
|
||||||
|
protected array $fields = [
|
||||||
|
'updatedAt' => 'updatedAt',
|
||||||
|
'createdAt' => 'createdAt'
|
||||||
|
];
|
||||||
|
|
||||||
protected array $reflectedProperties;
|
protected array $reflectedProperties;
|
||||||
|
|
||||||
protected string $contextClass = FormContext::class;
|
protected string $contextClass = FormContext::class;
|
||||||
@ -72,6 +77,8 @@ abstract class Save extends Form implements \Picea\Ui\Method\FormInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->handleTimestamp($entity);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->assignContextToEntity($context);
|
$this->assignContextToEntity($context);
|
||||||
|
|
||||||
@ -112,38 +119,38 @@ abstract class Save extends Form implements \Picea\Ui\Method\FormInterface {
|
|||||||
{
|
{
|
||||||
$entity = $this->getEntity();
|
$entity = $this->getEntity();
|
||||||
|
|
||||||
foreach($entity::resolveEntity()->fieldList() as $key => $property) {
|
foreach($entity::resolveEntity()->getPropertyHavingAttribute(EntityField::class) as $key => $entityField) {
|
||||||
$field = $property->getAttribute(Field::class)->object;
|
$property = $entity::resolveEntity()->reflectedClass->getProperties(true)[$key];
|
||||||
|
|
||||||
if (! $field->readonly || ! $entity->isLoaded()) {
|
if ($property) {
|
||||||
|
if (($property->getAttribute(Field::class)->object->readonly ?? false) && $entity->isLoaded()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$apiField = $property->getAttribute(EntityField::class)->object ?? null;
|
$apiField = $entityField[0]->object ;
|
||||||
|
$var = $apiField->field ?: $key;
|
||||||
|
|
||||||
if ($apiField) {
|
if ( property_exists($context, $var) && ( new \ReflectionProperty($context, $var) )->isInitialized($context) ) {
|
||||||
$var = $apiField->field ?: $key;
|
if ($apiField->setterMethod) {
|
||||||
|
# Use a setter method
|
||||||
if ( property_exists($context, $var) && ( new \ReflectionProperty($context, $var) )->isInitialized($context) ) {
|
call_user_func([ $entity, $apiField->setterMethod ], $context->{$var});
|
||||||
if ($apiField->setterMethod) {
|
|
||||||
# Use a setter method
|
|
||||||
call_user_func([ $entity, $apiField->setterMethod ], $context->{$var});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
# Direct property set
|
|
||||||
$entity->$key = $context->{$var};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
elseif (! $entity->isLoaded()) {
|
else {
|
||||||
# Applies 'default' value assigned to ContextField property
|
# Direct property set
|
||||||
$attr = $this->reflectedProperties($context)[$var] ?? null;
|
$entity->$key = $context->{$var};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif (! $entity->isLoaded()) {
|
||||||
|
# Applies 'default' value assigned to ContextField property
|
||||||
|
$attr = $this->reflectedProperties($context)[$var] ?? null;
|
||||||
|
|
||||||
if ($attr) {
|
if ($attr) {
|
||||||
$contextField = $attr->getAttribute(ContextField::class);
|
$contextField = $attr->getAttribute(ContextField::class);
|
||||||
|
|
||||||
if ($contextField) {
|
if ($contextField) {
|
||||||
if (isset($contextField->object->default)) {
|
if (isset($contextField->object->default)) {
|
||||||
|
|
||||||
$entity->$key = $contextField->object->default;
|
$entity->$key = $contextField->object->default;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,6 +159,25 @@ abstract class Save extends Form implements \Picea\Ui\Method\FormInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function handleTimestamp(EntityInterface $entity) : void
|
||||||
|
{
|
||||||
|
if ($entity->isLoaded()) {
|
||||||
|
if (property_exists($entity, $this->fields['updatedAt']) && $entity->repository()->generateDatasetDiff($entity) ) {
|
||||||
|
$field = $this->fields['updatedAt'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (property_exists($entity, $this->fields['createdAt']) && empty($entity->{$this->fields['createdAt']})) {
|
||||||
|
$field = $this->fields['createdAt'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($field ?? false) {
|
||||||
|
$cls = $entity::resolveEntity()->field($field)->type->type;
|
||||||
|
$entity->{$field} = new $cls();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function reflectedProperties(FormContextInterface $context) : array
|
private function reflectedProperties(FormContextInterface $context) : array
|
||||||
{
|
{
|
||||||
$this->reflectedProperties ??= ObjectReflection::fromClass($context::class)->reflectProperties(\ReflectionProperty::IS_PUBLIC);
|
$this->reflectedProperties ??= ObjectReflection::fromClass($context::class)->reflectProperties(\ReflectionProperty::IS_PUBLIC);
|
||||||
|
|||||||
@ -26,25 +26,25 @@ class FormContext extends \Picea\Ui\Method\FormContext {
|
|||||||
return $this->languageHandler->languageFromKey($key, $variables);
|
return $this->languageHandler->languageFromKey($key, $variables);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pushSuccessMessage($key, $variables = []) {
|
public function pushSuccessMessage($key, $variables = []) : void {
|
||||||
$this->pushMessage($this->message::generateSuccess(
|
$this->pushMessage($this->message::generateSuccess(
|
||||||
$this->lang($key, $variables)
|
$this->lang($key, $variables)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pushWarningMessage($key, $variables = []) {
|
public function pushWarningMessage($key, $variables = []) : void {
|
||||||
$this->pushMessage($this->message::generateWarning(
|
$this->pushMessage($this->message::generateWarning(
|
||||||
$this->lang($key, $variables)
|
$this->lang($key, $variables)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pushErrorMessage($key, $variables = []) {
|
public function pushErrorMessage($key, $variables = []) : void {
|
||||||
$this->pushMessage($this->message::generateError(
|
$this->pushMessage($this->message::generateError(
|
||||||
$a = $this->lang($key, $variables)
|
$a = $this->lang($key, $variables)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pushInfoMessage($key, $variables = []) {
|
public function pushInfoMessage($key, $variables = []) : void {
|
||||||
$this->pushMessage($this->message::generateInfo(
|
$this->pushMessage($this->message::generateInfo(
|
||||||
$this->lang($key, $variables)
|
$this->lang($key, $variables)
|
||||||
));
|
));
|
||||||
|
|||||||
@ -15,8 +15,6 @@ class CORS implements MiddlewareInterface {
|
|||||||
|
|
||||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
var_dump($request->getMethod() );
|
|
||||||
if ($request->getMethod() === "option") {
|
if ($request->getMethod() === "option") {
|
||||||
die("an option :)");
|
die("an option :)");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
h4{background:#e0f7ed;padding:6px 12px; font-weight: bold!important;font-size:100%;margin-top:0}
|
h4{background:#e0f7ed;padding:6px 12px; font-weight: bold!important;font-size:100%;margin-top:0}
|
||||||
h5{text-decoration: underline}
|
h5{text-decoration: underline}
|
||||||
h3 {display: flex;align-items: center;padding: 0 15px 0 15px;font-variant: small-caps;border-bottom: 5px solid #ccc;line-height: 60px;}
|
h3 {display: flex;align-items: center;padding: 0 15px 0 15px;font-variant: small-caps;border-bottom: 5px solid #ccc;line-height: 60px;}
|
||||||
li.odd-even{border-top:1px solid #ccc;margin:10px 0;padding:15px 15px 10px 5px}
|
li.odd-even{border-top:1px solid #ccc;margin:10px 0;padding:15px 10px 10px 10px}
|
||||||
li.odd-even:first-child{border:0}
|
li.odd-even:first-child{border:0}
|
||||||
input, button {padding:5px; font-size:1em;margin:0}
|
input, button {padding:5px; font-size:1em;margin:0}
|
||||||
|
|
||||||
@ -84,13 +84,15 @@
|
|||||||
|
|
||||||
.forms{background: #e8f7ff;padding: 5px;}
|
.forms{background: #e8f7ff;padding: 5px;}
|
||||||
|
|
||||||
|
.forms ol {padding-left:0;list-style-type: none;}
|
||||||
|
|
||||||
.entities {background: #f0e0e0;padding:5px;}
|
.entities {background: #f0e0e0;padding:5px;}
|
||||||
.entity-wrapper .entity-name {background:#eaa1af;color: #682828;font-size:110%}
|
.entity-wrapper .entity-name {background:#eaa1af;color: #682828;font-size:110%}
|
||||||
.entity-wrapper .fields-wrapper {border-color: #c14141}
|
.entity-wrapper .fields-wrapper {border-color: #c14141}
|
||||||
.entity-wrapper .header-fields {background:#c14141}
|
.entity-wrapper .header-fields {background:#c14141}
|
||||||
.entity-wrapper .field-desc {margin-top:10px;;background:#fff;padding:5px;font-size:0.9em}
|
.entity-wrapper .field-desc {margin-top:10px;;background:#fff;padding:5px;font-size:0.9em}
|
||||||
.entity-wrapper .field-desc .array-of {font-weight:bold;padding-left:15px;color:#955252}
|
.entity-wrapper .field-desc .array-of {font-weight:bold;padding-left:15px;color:#955252}
|
||||||
.entity-wrapper ol {background: #e3d0d0;}
|
.entity-wrapper ol {background: #e3d0d0;padding-left:0;list-style-type: none;}
|
||||||
.entity-wrapper li {border-color: #ae8585;}
|
.entity-wrapper li {border-color: #ae8585;}
|
||||||
.entity-wrapper li .default {color:#bf7d4d;}
|
.entity-wrapper li .default {color:#bf7d4d;}
|
||||||
|
|
||||||
@ -98,7 +100,7 @@
|
|||||||
.search-request-wrapper {padding: 15px;margin-top:5px;border-left: 3px solid #72886a;background: #eeffe6;}
|
.search-request-wrapper {padding: 15px;margin-top:5px;border-left: 3px solid #72886a;background: #eeffe6;}
|
||||||
.search-request-wrapper .header-fields {background:#395332}
|
.search-request-wrapper .header-fields {background:#395332}
|
||||||
.search-request-wrapper .fields-wrapper{border-color:#395332}
|
.search-request-wrapper .fields-wrapper{border-color:#395332}
|
||||||
.search-request-wrapper ol {background: #d8f0cd;}
|
.search-request-wrapper ol {background: #d8f0cd;padding-left:0;list-style-type: none;}
|
||||||
.search-request-wrapper li {border-color: #72886a;}
|
.search-request-wrapper li {border-color: #72886a;}
|
||||||
.search-request-wrapper .default {color:#72886a;}
|
.search-request-wrapper .default {color:#72886a;}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user