瀏覽代碼

Intégration de l'app product

develop
Fab 3 年之前
父節點
當前提交
97f693943f
共有 9 個文件被更改,包括 211 次插入92 次删除
  1. +2
    -3
      Controller/AbstractAdminController.php
  2. +5
    -1
      Doctrine/EntityManager.php
  3. +32
    -0
      Doctrine/QueryBuilder.php
  4. +3
    -0
      Form/Common/CrudFormType.php
  5. +5
    -0
      Resources/assets/app/adminlte/plugins/app.plugins.js
  6. +34
    -0
      Resources/assets/functions/prices.js
  7. +28
    -0
      Resources/assets/functions/tools.js
  8. +1
    -0
      Resources/config/services.yaml
  9. +101
    -88
      Resources/views/adminlte/crud/form_theme.html.twig

+ 2
- 3
Controller/AbstractAdminController.php 查看文件

@@ -311,10 +311,9 @@ abstract class AbstractAdminController extends EaAbstractCrudController
if ($this->isInstanceOf(TreeInterface::class)) {
$entityId = $searchDto->getRequest()->get('entityId');
if ($entityId !== null) {
$queryBuilder->andWhere('entity.parent = :entityId');
$queryBuilder->setParameter('entityId', $searchDto->getRequest()->get('entityId'));
$queryBuilder->andWhereParent('entity', $entityId);
} else {
$queryBuilder->andWhere('entity.parent IS NULL');
$queryBuilder->andWhereParentIsNull('entity');
}
}


+ 5
- 1
Doctrine/EntityManager.php 查看文件

@@ -6,7 +6,6 @@ use Doctrine\ORM\Decorator\EntityManagerDecorator;
use Doctrine\ORM\EntityManager as DoctrineEntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
use Lc\SovBundle\Doctrine\EntityInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
@@ -27,6 +26,11 @@ class EntityManager extends EntityManagerDecorator
parent::__construct($wrapped);
}

public function createQueryBuilder()
{
return new QueryBuilder($this);
}

public function getRepository($className)
{
return $this->wrapped->getRepository($this->getEntityName($className));

+ 32
- 0
Doctrine/QueryBuilder.php 查看文件

@@ -0,0 +1,32 @@
<?php

namespace Lc\SovBundle\Doctrine;

use Doctrine\ORM\QueryBuilder as DoctrineQueryBuilder;

/**
* class QueryBuilder.
*
* @author La clic !!!!
*/
class QueryBuilder extends DoctrineQueryBuilder
{

public function andWhereParent($dqlId, $entityId):self
{
$this->andWhere($dqlId.'.parent = :entityId');
$this->setParameter('entityId', $entityId);
return $this;
}

public function andWhereParentIsNull($dqlId):self
{
$this->andWhere($dqlId.'.parent IS NULL');
return $this;
}

/*public function andIsOnline(){

}*/

}

+ 3
- 0
Form/Common/CrudFormType.php 查看文件

@@ -27,17 +27,20 @@ class CrudFormType extends AbstractType
DoctrineOrmTypeGuesser $doctrineOrmTypeGuesser,
\EasyCorp\Bundle\EasyAdminBundle\Form\Type\CrudFormType $crudFormType
) {

$this->parent = $crudFormType;
$this->doctrineOrmTypeGuesser = $doctrineOrmTypeGuesser;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{

$this->parent->buildForm($builder, $options);
$entityDto = $options['entityDto'];
$formPanels = [];
$currentFormPanel = 0;
foreach ($entityDto->getFields() as $fieldDto) {

if (null === $formFieldType = $fieldDto->getFormType()) {
$guessType = $this->doctrineOrmTypeGuesser->guessType($entityDto->getFqcn(), $fieldDto->getProperty());
$formFieldType = $guessType->getType();

+ 5
- 0
Resources/assets/app/adminlte/plugins/app.plugins.js 查看文件

@@ -32,6 +32,11 @@ import 'daterangepicker/daterangepicker.css' ;
import { SovTools } from '../../../functions/tools.js';
global.SovTools = SovTools;


// Prices
import { SovPrices } from '../../../functions/prices.js';
global.SovPrices = SovPrices;

// Widgets
import { SovWidgets } from '../../../functions/widgets.js';
global.SovWidgets = SovWidgets;

+ 34
- 0
Resources/assets/functions/prices.js 查看文件

@@ -0,0 +1,34 @@

export class SovPrices {

static getPrice(priceWithTax, taxRate) {
return parseFloat(parseFloat(priceWithTax) / ((taxRate/100) + 1)).toFixed(4);
}

static getPriceWithTax(priceWithoutTax, taxRate) {
return parseFloat(parseFloat(priceWithoutTax) * ((taxRate/100) + 1)).toFixed(2);
}

static getMargin(price, buyingPrice){
return parseFloat(price - buyingPrice).toFixed(2);
}

static getMarginPercent(price, buyingPrice){
return parseFloat(((price - buyingPrice) / price) * 100).toFixed(2);
}

static applyReductionPercent(price, percentage)
{
return applyPercent(price, -percentage);
}

static applyReductionAmount(price, amount)
{
return parseFloat(price - amount).toFixed(2);
}

static applyPercent(price, percentage)
{
return parseFloat(price * (percentage / 100 + 1)).toFixed(2);
}
}

+ 28
- 0
Resources/assets/functions/tools.js 查看文件

@@ -59,4 +59,32 @@ export class SovTools {
for (; input[i] < '0' || input[i] > '9'; i--) ;
return i == input.length ? -1 : i;
}

static formatNumber(number, toFixed){
if(number)return Number(number.replace(',', '.')).toFixed(toFixed);
else return null;
}

static formatNumberWithoutFixed(number){
if(typeof number == 'string')number = number.replace(',', '.');
if(number)return Number(number);
else return null;
}

static getUrlParameter(sParam) {
var sPageURL = window.location.search.substring(1),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;

for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');

if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
}
}
};


}

+ 1
- 0
Resources/config/services.yaml 查看文件

@@ -8,6 +8,7 @@ services:
exclude:
- '../../DependencyInjection/'
- '../../Entity/'
- '../../Doctrine/QueryBuilder'
- '../../Kernel.php'
- '../../Tests/'


+ 101
- 88
Resources/views/adminlte/crud/form_theme.html.twig 查看文件

@@ -13,112 +13,116 @@
{%- else -%}
{% set form_method = "POST" %}
{%- endif -%}
<form{% if name != '' %} name="{{ name }}"{% endif %} method="{{ form_method|lower }}"{% if action != '' %} action="{{ action }}"{% endif %}{{ block('attributes') }}{% if multipart %} enctype="multipart/form-data"{% endif %}>
<form{% if name != '' %} name="{{ name }}"{% endif %}
method="{{ form_method|lower }}"{% if action != '' %} action="{{ action }}"{% endif %}{{ block('attributes') }}{% if multipart %} enctype="multipart/form-data"{% endif %}>
{%- if form_method != method -%}
<input type="hidden" name="_method" value="{{ method }}" />
<input type="hidden" name="_method" value="{{ method }}"/>
{%- endif -%}

<input type="hidden" name="referrer" value="{% if ea is defined %}{{ ea.request.query.get('referrer') }}{% endif %}">
{% endblock form_start %}
<input type="hidden" name="referrer"
value="{% if ea is defined %}{{ ea.request.query.get('referrer') }}{% endif %}">
{% endblock form_start %}

{% block form_row %}
{% set row_attr = row_attr|merge({
class: row_attr.class|default('') ~ ' form-group'
}) %}
{% block form_row %}
{% set row_attr = row_attr|merge({
class: row_attr.class|default('') ~ ' form-group'
}) %}

<div {% with { attr: row_attr } %}{{ block('attributes') }}{% endwith %}>
{{- form_label(form) -}}
<div class="form-widget">
<div {% with { attr: row_attr } %}{{ block('attributes') }}{% endwith %}>
{{- form_label(form) -}}
<div class="form-widget">

{#
{#
{% set has_prepend_html = ea.field.prepend_html|default(null) is not null %}
{% set has_append_html = ea.field.append_html|default(null) is not null %}
{% set has_input_groups = has_prepend_html or has_append_html %}
#}
#}

{% set has_prepend_html = false %}
{% set has_append_html = false %}
{% set has_input_groups = false %}

{% if ea_crud_form.ea_field is defined and ea_crud_form.ea_field is not null %}
{% set prepend_html = ea_crud_form.ea_field.customOptions.get('prependHtml') %}
{% set append_html = ea_crud_form.ea_field.customOptions.get('appendHtml') %}
{% set has_prepend_html = prepend_html is not null %}
{% set has_append_html = append_html is not null %}
{% set has_input_groups = has_prepend_html or has_append_html %}
{% endif %}

{% set has_prepend_html = false %}
{% set has_append_html = false %}
{% set has_input_groups = false %}
{% if has_input_groups %}
<div class="input-group">{% endif %}
{% if has_prepend_html %}
<div class="input-group-prepend">
<span class="input-group-text">{{ prepend_html|raw }}</span>
</div>
{% endif %}

{% if ea_crud_form.ea_field is defined and ea_crud_form.ea_field is not null %}
{% set prepend_html = ea_crud_form.ea_field.customOptions.get('prependHtml') %}
{% set append_html = ea_crud_form.ea_field.customOptions.get('appendHtml') %}
{% set has_prepend_html = prepend_html is not null %}
{% set has_append_html = append_html is not null %}
{% set has_input_groups = has_prepend_html or has_append_html %}
{% endif %}
{{ form_widget(form) }}

{% if has_input_groups %}
<div class="input-group">{% endif %}
{% if has_prepend_html %}
<div class="input-group-prepend">
<span class="input-group-text">{{ prepend_html|raw }}</span>
{% if has_append_html %}
<div class="input-group-append">
<span class="input-group-text">{{ append_html|raw }}</span>
</div>
{% endif %}
{% if has_input_groups %}</div>{% endif %}

{% set nullable_fields_fqcn = [
'EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField',
'EasyCorp\Bundle\EasyAdminBundle\Field\DateField',
'EasyCorp\Bundle\EasyAdminBundle\Field\TimeField',
] %}
{% if form.vars.ea_crud_form.ea_field.fieldFqcn|default(false) in nullable_fields_fqcn and ea.field.nullable|default(false) %}
<div class="nullable-control">
<label>
<input type="checkbox" {% if data is null %}checked="checked"{% endif %}>
{{ 'label.nullable_field'|trans({}, 'EasyAdminBundle') }}
</label>
</div>
{% endif %}

{{ form_widget(form) }}

{% if has_append_html %}
<div class="input-group-append">
<span class="input-group-text">{{ append_html|raw }}</span>
</div>
{% set help_message = name|sov_trans_admin_help(form.parent.vars.data) %}
{% if help_message != '' %}
<small class="form-help">{{ help_message }}</small>
{% endif %}
{% if has_input_groups %}</div>{% endif %}

{% set nullable_fields_fqcn = [
'EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField',
'EasyCorp\Bundle\EasyAdminBundle\Field\DateField',
'EasyCorp\Bundle\EasyAdminBundle\Field\TimeField',
] %}
{% if form.vars.ea_crud_form.ea_field.fieldFqcn|default(false) in nullable_fields_fqcn and ea.field.nullable|default(false) %}
<div class="nullable-control">
<label>
<input type="checkbox" {% if data is null %}checked="checked"{% endif %}>
{{ 'label.nullable_field'|trans({}, 'EasyAdminBundle') }}
</label>
</div>
{% endif %}

{% set help_message = name|sov_trans_admin_help(form.parent.vars.data) %}
{% if help_message != '' %}
<small class="form-help">{{ help_message }}</small>
{% endif %}

{{- form_errors(form) -}}
{{- form_errors(form) -}}
</div>
</div>
</div>
{% endblock form_row %}
{% endblock form_row %}

{% block form_label -%}
{% block form_label -%}
{% if label is same as(false) -%}
<label>{# the empty <label> is needed to not break the form design #}</label>
<label>{# the empty <label> is needed to not break the form design #}</label>
{%- else -%}
{%- if compound is defined and compound -%}
{%- set element = 'legend' -%}
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' col-form-label')|trim}) -%}
{%- if compound is defined and compound -%}
{%- set element = 'legend' -%}
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' col-form-label')|trim}) -%}
{%- else -%}
{%- set label_attr = label_attr|merge({for: id, class: (label_attr.class|default('') ~ ' form-control-label')|trim}) -%}
{%- endif -%}
{% if required -%}
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) %}
{%- endif -%}
{% if label is empty -%}
{%- if label_format is not empty -%}
{% set label = label_format|replace({
'%name%': name,
'%id%': id,
}) %}
{%- else -%}
{%- set label_attr = label_attr|merge({for: id, class: (label_attr.class|default('') ~ ' form-control-label')|trim}) -%}
{%- endif -%}
{% if required -%}
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) %}
{%- endif -%}
{% if label is empty -%}
{%- if label_format is not empty -%}
{% set label = label_format|replace({
'%name%': name,
'%id%': id,
}) %}
{%- else -%}
{# {% set label = name|humanize %} #}
{%- endif -%}
{# {% set label = name|humanize %} #}
{%- endif -%}
{%- endif -%}

{% set entityNameOrObject = form.parent.vars.data %}
{% if not entityNameOrObject and form.parent.vars.errors.form.config.dataClass is defined %}
{% set entityNameOrObject = form.parent.vars.errors.form.config.dataClass %}
{% endif %}
{% set entityNameOrObject = form.parent.vars.data %}
{% if not entityNameOrObject and form.parent.vars.errors.form.config.dataClass is defined %}
{% set entityNameOrObject = form.parent.vars.errors.form.config.dataClass %}
{% endif %}

<{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ (label is not empty and '.' in label) ? label|trans({}, 'admin') : name|sov_trans_admin_field(entityNameOrObject) }}</{{ element|default('label') }}>
<{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}
>{{ (label is not empty and '.' in label) ? label|trans({}, 'admin') : name|sov_trans_admin_field(entityNameOrObject) }}
</{{ element|default('label') }}>

{%- endif -%}
{%- endblock form_label %}
@@ -216,8 +220,8 @@
{% endif %}

<div class="col-12">
{# {{ dump(form.vars) }}#}
{# {{ dump(form.vars.ea_crud_form.ea_field) }}#}
{# {{ dump(form.vars) }} #}
{# {{ dump(form.vars.ea_crud_form.ea_field) }} #}
<div class="input-group">
<div class="input-group-prepend">
{% if form.parent.vars['row_attr']['data-sortable'] is defined %}
@@ -226,7 +230,8 @@
<i class="fa fa-arrows-alt"></i>
</button>
{% endif %}
<button type="button" class="btn btn-primary lc-filemanager-open" data-id="{{ form.path.vars.id }}"
<button type="button" class="btn btn-primary lc-filemanager-open"
data-id="{{ form.path.vars.id }}"
data-toggle="tooltip" title="Sélectionner un fichier"
data-target="{{ path('file_manager', {module:1, conf: managerDir})|raw }}">
<i class="fa fa-folder-open"></i>
@@ -249,7 +254,7 @@
{% endblock file_manager_widget %}

{% block checkbox_radio_label -%}
{#- Do not display the label if widget is not defined in order to prevent double label rendering -#}
{#- Do not display the label if widget is not defined in order to prevent double label rendering -#}
{%- if widget is defined -%}
{% set is_parent_custom = parent_label_class is defined and ('checkbox-custom' in parent_label_class or 'radio-custom' in parent_label_class or 'switch-custom' in parent_label_class) %}
{% set is_custom = label_attr.class is defined and ('checkbox-custom' in label_attr.class or 'radio-custom' in label_attr.class or 'switch-custom' in label_attr.class) %}
@@ -279,19 +284,27 @@
{%- endif -%}
{%- endif -%}

{% if attr.disabled is defined and attr.disabled %}
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' disabled')|trim}) -%}
{% endif %}

<label{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}>
{{ widget|raw }}
<span class="checkmark"></span>

{# {{- label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans(label_translation_parameters, translation_domain))|raw -}} #}
{# {{- label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans(label_translation_parameters, translation_domain))|raw -}} #}

{% set entityNameOrObject = form.parent.vars.data %}
{% if not entityNameOrObject and form.parent.vars.errors.form.config.dataClass is defined %}
{% set entityNameOrObject = form.parent.vars.errors.form.config.dataClass %}
{% endif %}

{{- (label is not empty and '.' in label) ? label|trans({}, 'admin') : name|sov_trans_admin_field(entityNameOrObject) -}}

<!-- lorsque que le name est un entier "case radio"-->
{% if name matches '/^\\d+$/' %}
{{- label|trans({}, 'admin') -}}
{% else %}
{{- (label is not empty and '.' in label) ? label|trans({}, 'admin') : name|sov_trans_admin_field(entityNameOrObject) -}}
{% endif %}
{{- form_errors(form) -}}
</label>
{%- endif -%}

Loading…
取消
儲存