mirror of
https://github.com/Karaka-Management/oms-Attribute.git
synced 2026-02-14 00:18:41 +00:00
update
This commit is contained in:
parent
e696bc37a4
commit
b763ef96c6
|
|
@ -37,29 +37,42 @@ trait ApiAttributeTraitController
|
||||||
* Method to create item attribute from request.
|
* Method to create item attribute from request.
|
||||||
*
|
*
|
||||||
* @param RequestAbstract $request Request
|
* @param RequestAbstract $request Request
|
||||||
|
* @param AttributeType $type Attribute type
|
||||||
*
|
*
|
||||||
* @return Attribute
|
* @return Attribute
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private function createAttributeFromRequest(RequestAbstract $request) : Attribute
|
private function createAttributeFromRequest(RequestAbstract $request, AttributeType $type) : Attribute
|
||||||
{
|
{
|
||||||
$attribute = new Attribute();
|
$new = new Attribute();
|
||||||
$attribute->ref = (int) $request->getData('ref');
|
$new->ref = (int) $request->getData('ref');
|
||||||
$attribute->type = new NullAttributeType((int) $request->getData('type'));
|
$new->type = $type;
|
||||||
|
|
||||||
if ($request->hasData('value')) {
|
if ($new->type->custom) {
|
||||||
$attribute->value = new NullAttributeValue((int) $request->getData('value'));
|
if ($request->hasData('value_id')) {
|
||||||
|
$new->value = new NullAttributeValue((int) $request->getData('value_id'));
|
||||||
|
} else {
|
||||||
|
// @todo: consider to check if custom value already exist and just reference the id? Problematic if content of id gets changed.
|
||||||
|
$new->value = new AttributeValue();
|
||||||
|
$new->value->setValue($request->getData('value'), $new->type->datatype);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$newRequest = clone $request;
|
// @todo: fix by only accepting the value id to be used
|
||||||
$newRequest->setData('value', $request->getData('custom'), true);
|
// this is a workaround for now because the front end doesn't allow to dynamically show default values.
|
||||||
|
$value = new NullAttributeValue((int) $request->getData('value_id'));
|
||||||
|
|
||||||
$value = $this->createAttributeValueFromRequest($newRequest, $attribute->type);
|
// Couldn't find matching default value
|
||||||
|
/*
|
||||||
|
if ($value->id === 0) {
|
||||||
|
return $new;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
$attribute->value = $value;
|
$new->value = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $attribute;
|
return $new;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -75,7 +88,7 @@ trait ApiAttributeTraitController
|
||||||
{
|
{
|
||||||
$val = [];
|
$val = [];
|
||||||
if (($val['type'] = !$request->hasData('type'))
|
if (($val['type'] = !$request->hasData('type'))
|
||||||
|| ($val['value'] = (!$request->hasData('value') && !$request->hasData('custom')))
|
|| ($val['value'] = (!$request->hasData('value') && !$request->hasData('value_id')))
|
||||||
) {
|
) {
|
||||||
return $val;
|
return $val;
|
||||||
}
|
}
|
||||||
|
|
@ -267,21 +280,24 @@ trait ApiAttributeTraitController
|
||||||
public function updateAttributeFromRequest(RequestAbstract $request, Attribute $new) : Attribute
|
public function updateAttributeFromRequest(RequestAbstract $request, Attribute $new) : Attribute
|
||||||
{
|
{
|
||||||
if ($new->type->custom) {
|
if ($new->type->custom) {
|
||||||
if ($request->hasData('value')) {
|
if ($request->hasData('value_id')) {
|
||||||
$new->value = new NullAttributeValue((int) $request->getData('value'));
|
$new->value = new NullAttributeValue((int) $request->getData('value_id'));
|
||||||
} else {
|
} else {
|
||||||
// @todo: consider to check if custom value already exist and just reference the id? Problematic if content of id gets changed.
|
// @todo: consider to check if custom value already exist and just reference the id? Problematic if content of id gets changed.
|
||||||
$new->value = new AttributeValue();
|
$new->value = new AttributeValue();
|
||||||
$new->value->setValue($request->getData('custom'), $new->type->datatype);
|
$new->value->setValue($request->getData('value'), $new->type->datatype);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// @todo: fix by only accepting the value id to be used
|
if ($request->hasData('value_id')) {
|
||||||
// this is a workaround for now because the front end doesn't allow to dynamically show default values.
|
// @todo: check if value_id part of default values
|
||||||
$value = $new->type->getDefaultByValue($request->getData('value'));
|
$value = new NullAttributeValue((int) $request->getData('value_id'));
|
||||||
|
} else {
|
||||||
|
$value = $new->type->getDefaultByValue($request->getData('value'));
|
||||||
|
|
||||||
// Couldn't find matching default value
|
// Couldn't find matching default value
|
||||||
if ($value->id === 0) {
|
if ($value->id === 0) {
|
||||||
return $new;
|
return $new;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$new->value = $value;
|
$new->value = $value;
|
||||||
|
|
@ -303,7 +319,7 @@ trait ApiAttributeTraitController
|
||||||
{
|
{
|
||||||
$val = [];
|
$val = [];
|
||||||
if (($val['id'] = !$request->hasData('id'))
|
if (($val['id'] = !$request->hasData('id'))
|
||||||
|| ($val['value'] = (!$request->hasData('value') && !$request->hasData('custom')))
|
|| ($val['value'] = (!$request->hasData('value') && !$request->hasData('value_id')))
|
||||||
) {
|
) {
|
||||||
return $val;
|
return $val;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ final class ApiController extends Controller
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$attribute = $this->createAttributeFromRequest($request);
|
$attribute = $this->createAttributeFromRequest($request, new NullAttributeType((int) $request->getData('type')));
|
||||||
$this->createModel($request->header->account, $attribute, AttributeMapper::class, 'attribute', $request->getOrigin());
|
$this->createModel($request->header->account, $attribute, AttributeMapper::class, 'attribute', $request->getOrigin());
|
||||||
|
|
||||||
$response->header->status = RequestStatusCode::R_400;
|
$response->header->status = RequestStatusCode::R_400;
|
||||||
|
|
@ -73,29 +73,43 @@ final class ApiController extends Controller
|
||||||
* Method to create item attribute from request.
|
* Method to create item attribute from request.
|
||||||
*
|
*
|
||||||
* @param RequestAbstract $request Request
|
* @param RequestAbstract $request Request
|
||||||
|
* @param AttributeType $type Attribute type
|
||||||
*
|
*
|
||||||
* @return Attribute
|
* @return Attribute
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private function createAttributeFromRequest(RequestAbstract $request) : Attribute
|
private function createAttributeFromRequest(RequestAbstract $request, AttributeType $type) : Attribute
|
||||||
{
|
{
|
||||||
$attribute = new Attribute();
|
$new = new Attribute();
|
||||||
$attribute->ref = (int) $request->getData('ref');
|
$new->ref = (int) $request->getData('ref');
|
||||||
$attribute->type = new NullAttributeType((int) $request->getData('type'));
|
$new->type = $type;
|
||||||
|
|
||||||
if ($request->hasData('value')) {
|
if ($new->type->custom) {
|
||||||
$attribute->value = new NullAttributeValue((int) $request->getData('value'));
|
if ($request->hasData('value_id')) {
|
||||||
|
$new->value = new NullAttributeValue((int) $request->getData('value_id'));
|
||||||
|
} else {
|
||||||
|
// @todo: consider to check if custom value already exist and just reference the id? Problematic if content of id gets changed.
|
||||||
|
$new->value = new AttributeValue();
|
||||||
|
$new->value->setValue($request->getData('value'), $new->type->datatype);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$newRequest = clone $request;
|
if ($request->hasData('value_id')) {
|
||||||
$newRequest->setData('value', $request->getData('custom'), true);
|
// @todo: check if value_id part of default values
|
||||||
|
$value = new NullAttributeValue((int) $request->getData('value_id'));
|
||||||
|
} else {
|
||||||
|
$value = $new->type->getDefaultByValue($request->getData('value'));
|
||||||
|
|
||||||
$value = $this->createAttributeValueFromRequest($newRequest);
|
// Couldn't find matching default value
|
||||||
|
if ($value->id === 0) {
|
||||||
|
return $new;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$attribute->value = $value;
|
$new->value = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $attribute;
|
return $new;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,14 @@ class AttributeView extends View
|
||||||
*/
|
*/
|
||||||
public string $apiUri = '';
|
public string $apiUri = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference id
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public int $refId = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
@ -81,6 +89,7 @@ class AttributeView extends View
|
||||||
$this->attributeTypes = $data[1];
|
$this->attributeTypes = $data[1];
|
||||||
$this->units = $data[2];
|
$this->units = $data[2];
|
||||||
$this->apiUri = $data[3];
|
$this->apiUri = $data[3];
|
||||||
|
$this->refId = $data[4];
|
||||||
|
|
||||||
return parent::render();
|
return parent::render();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,8 @@ $l11n = $this->data['defaultlocalization'] ?? new NullLocalization();
|
||||||
data-add-tpl="#attributeTable tbody .oms-add-tpl-attribute">
|
data-add-tpl="#attributeTable tbody .oms-add-tpl-attribute">
|
||||||
<div class="portlet-head"><?= $this->getHtml('Attribute', 'Attribute', 'Backend'); ?></div>
|
<div class="portlet-head"><?= $this->getHtml('Attribute', 'Attribute', 'Backend'); ?></div>
|
||||||
<div class="portlet-body">
|
<div class="portlet-body">
|
||||||
|
<input type="hidden" id="iAttributeRef" name="ref" value="<?= $this->refId ?>" disabled>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="iAttributeId"><?= $this->getHtml('ID', '0', '0'); ?></label>
|
<label for="iAttributeId"><?= $this->getHtml('ID', '0', '0'); ?></label>
|
||||||
<input type="text" id="iAttributeId" name="id" data-tpl-text="/id" data-tpl-value="/id" disabled>
|
<input type="text" id="iAttributeId" name="id" data-tpl-text="/id" data-tpl-value="/id" disabled>
|
||||||
|
|
@ -48,6 +50,7 @@ $l11n = $this->data['defaultlocalization'] ?? new NullLocalization();
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- @todo: implement
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="iAttributesUnit"><?= $this->getHtml('Unit', 'Attribute', 'Backend'); ?></label>
|
<label for="iAttributesUnit"><?= $this->getHtml('Unit', 'Attribute', 'Backend'); ?></label>
|
||||||
<select id="iAttributesUnit" name="unit" data-tpl-text="/unit" data-tpl-value="/unit">
|
<select id="iAttributesUnit" name="unit" data-tpl-text="/unit" data-tpl-value="/unit">
|
||||||
|
|
@ -58,6 +61,7 @@ $l11n = $this->data['defaultlocalization'] ?? new NullLocalization();
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
-->
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="iAttributeValue"><?= $this->getHtml('Value', 'Attribute', 'Backend'); ?></label>
|
<label for="iAttributeValue"><?= $this->getHtml('Value', 'Attribute', 'Backend'); ?></label>
|
||||||
|
|
@ -67,7 +71,7 @@ $l11n = $this->data['defaultlocalization'] ?? new NullLocalization();
|
||||||
<div class="portlet-foot">
|
<div class="portlet-foot">
|
||||||
<input id="bAttributeAdd" formmethod="put" type="submit" class="add-form" value="<?= $this->getHtml('Add', '0', '0'); ?>">
|
<input id="bAttributeAdd" formmethod="put" type="submit" class="add-form" value="<?= $this->getHtml('Add', '0', '0'); ?>">
|
||||||
<input id="bAttributeSave" formmethod="post" type="submit" class="save-form hidden button save" value="<?= $this->getHtml('Update', '0', '0'); ?>">
|
<input id="bAttributeSave" formmethod="post" type="submit" class="save-form hidden button save" value="<?= $this->getHtml('Update', '0', '0'); ?>">
|
||||||
<input type="submit" class="cancel-form hidden button close" value="<?= $this->getHtml('Cancel', '0', '0'); ?>">
|
<input id="bAttributeCancel" type="submit" class="cancel-form hidden button close" value="<?= $this->getHtml('Cancel', '0', '0'); ?>">
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
|
|
@ -91,7 +95,7 @@ $l11n = $this->data['defaultlocalization'] ?? new NullLocalization();
|
||||||
<td><?= $this->getHtml('Unit', 'Attribute', 'Backend'); ?><i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
|
<td><?= $this->getHtml('Unit', 'Attribute', 'Backend'); ?><i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
|
||||||
<tbody>
|
<tbody>
|
||||||
<template class="oms-add-tpl-attribute">
|
<template class="oms-add-tpl-attribute">
|
||||||
<tr data-id="" draggable="false">
|
<tr class="animated medium-duration greenCircleFade" data-id="" draggable="false">
|
||||||
<td>
|
<td>
|
||||||
<i class="fa fa-cogs btn update-form"></i>
|
<i class="fa fa-cogs btn update-form"></i>
|
||||||
<input id="attributeTable-remove-0" type="checkbox" class="hidden">
|
<input id="attributeTable-remove-0" type="checkbox" class="hidden">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user