Skip to content

Commit

Permalink
Merge branch 'master' into 43305-backend-performance
Browse files Browse the repository at this point in the history
  • Loading branch information
yeneastgate authored Feb 20, 2024
2 parents c8a8382 + 32802bb commit ab504e7
Show file tree
Hide file tree
Showing 30 changed files with 579 additions and 18 deletions.
25 changes: 25 additions & 0 deletions css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,16 @@ body #post-body-content p.wp-clearfix:nth-child(1){
min-height: 30px;
}

.oo-poststuff .custom-input-field input[name=oopluginlistviews-countryactive]:checked::before,
.oo-poststuff .custom-input-field input[name=oopluginlistviews-radiusactive]:checked::before {
filter: brightness(0) saturate(100%) invert(35%) sepia(4%) saturate(967%) hue-rotate(170deg) brightness(91%) contrast(94%);
}

.oo-poststuff .custom-input-field input[name=oopluginlistviews-countryactive],
.oo-poststuff .custom-input-field input[name=oopluginlistviews-radiusactive] {
pointer-events: none;
}

#listSettings .custom-input-field,
#viewpicturetypes .custom-input-field {
display: block;
Expand All @@ -568,4 +578,19 @@ body #post-body-content p.wp-clearfix:nth-child(1){

.oo-poststuff .key-of-field-block {
display: flex;
}

.oo-poststuff .custom-input-field .onoffice-input-radio {
border-radius: 4px;
width: 50%;
display: grid;
float: left;
justify-content: initial;
border: 1px solid #8c8f94;
}

.oo-poststuff .custom-input-field .onoffice-input-radio label {
display: flex;
justify-content: space-between;
margin: 10px;
}
2 changes: 1 addition & 1 deletion dist/onoffice-default-form-values.min.js

Large diffs are not rendered by default.

62 changes: 59 additions & 3 deletions js/onoffice-default-form-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,49 @@ onOffice.default_values_input_converter = function () {
onOffice.default_values_inputs_converted.push(fieldName);
var fieldDefinition = getFieldDefinition(fieldName);

if (fieldDefinition.type === "urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:tinyint") {
const parent = mainInput;
const element = document.createElement('fieldset');
const keys = Object.keys(fieldDefinition.permittedvalues).sort();
parent.name = 'oopluginfieldconfigformdefaultsvalues-value[' + fieldName + ']';

element.className = 'onoffice-input-radio';
keys.forEach(k => {
const mainInputClone = parent.cloneNode(true);
const label = document.createElement('label');
onOffice.js_field_count += 1;
mainInputClone.id = 'input_radio_js_' + onOffice.js_field_count;
mainInputClone.value = k;
label.textContent = fieldDefinition.permittedvalues[k];
if (k == onOffice_loc_settings.defaultvalues[fieldName]) {
mainInputClone.checked = true;
}
label.appendChild(mainInputClone);
element.appendChild(label);
parent.parentElement.appendChild(element);
});
const labels = parent.parentElement.getElementsByTagName('label')[1];
parent.parentElement.removeChild(labels);
mainInput.remove();
return;
}

if (!fieldDefinition.rangefield &&
[
'integer', 'float', 'date', 'datetime',
'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:float',
'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:int',
'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:integer',
'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:decimal'
'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:decimal',
'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:date',
'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:tinyint'
].indexOf(fieldDefinition.type) >= 0) {
if (fieldDefinition.type === 'date' || fieldDefinition.type === 'datetime') {
mainInput.setAttribute('type', 'text');
if (fieldDefinition.type === 'date' || fieldDefinition.type === 'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:date') {
mainInput.setAttribute('type', 'date');
}
if (fieldDefinition.type === 'datetime') {
mainInput.setAttribute('type', 'datetime-local');
mainInput.setAttribute('step', 1);
}
mainInput.name = 'oopluginfieldconfigformdefaultsvalues-value[' + fieldName + ']';
mainInput.value = predefinedValues[fieldName][0] || '';
Expand Down Expand Up @@ -286,6 +319,29 @@ document.addEventListener("addFieldItem", function(e) {
onOffice.js_field_count += 1;
select.options.selectedIndex = 0;
element.parentNode.replaceChild(select, element);
} else if (['urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:tinyint'].indexOf(fieldDefinition.type) >= 0) {
const element = e.detail.item.querySelector('input[name^=oopluginfieldconfigformdefaultsvalues-value]');
const fieldset = document.createElement('fieldset');
const keys = Object.keys(fieldDefinition.permittedvalues).sort();
fieldset.className = 'onoffice-input-radio';
keys.forEach(function (k) {
const label = document.createElement('label');
const input = document.createElement('input');
input.name = 'oopluginfieldconfigformdefaultsvalues-value[' + fieldName + ']';
input.type = 'radio';
input.value = k;
input.className = 'onoffice-input';
onOffice.js_field_count += 1;
label.htmlFor = 'input_radio_js_' + onOffice.js_field_count;
label.textContent = fieldDefinition.permittedvalues[k];
if(k == onOffice_loc_settings.defaultvalues[fieldName]){
input.checked = true;
}
label.appendChild(input);
fieldset.appendChild(label);
});

element.parentNode.replaceChild(fieldset, element);
}

var paragraph = e.detail.item.querySelectorAll('.menu-item-settings p')[2];
Expand Down
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
Author: onOffice GmbH
Author URI: https://en.onoffice.com/
Description: Your connection to onOffice: This plugin enables you to have quick access to estates and forms – no additional sync with the software is needed. Consult support@onoffice.de for source code.
Version: 4.16
Version: 4.17
License: AGPL 3+
License URI: https://www.gnu.org/licenses/agpl-3.0
Text Domain: onoffice-for-wp-websites
Expand Down
1 change: 1 addition & 0 deletions plugin/Controller/GeoPositionFieldHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ private function getDefaultConfiguration(): array
$defaultActive = [
GeoPosition::ESTATE_LIST_SEARCH_ZIP,
GeoPosition::ESTATE_LIST_SEARCH_RADIUS,
GeoPosition::ESTATE_LIST_SEARCH_COUNTRY
];
$intersection = array_intersect_key($this->_booleanFields, array_flip($defaultActive));
return array_combine($intersection, array_fill(0, count($intersection), '1'));
Expand Down
24 changes: 24 additions & 0 deletions plugin/DataView/DataDetailView.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,21 @@ class DataDetailView
/** @var bool */
private $_showPriceOnRequest = false;

/** @var string[] */
private $_priceFields = [
'kaufpreis',
'erbpacht',
'nettokaltmiete',
'warmmiete',
'pacht',
'kaltmiete',
'miete_pauschal',
'saisonmiete',
'wochmietbto',
'kaufpreis_pro_qm',
'mietpreis_pro_qm',
];

/**
*
*/
Expand Down Expand Up @@ -353,4 +368,13 @@ public function getShowPriceOnRequest(): bool
/** @param bool $priceOnRequest */
public function setShowPriceOnRequest(bool $priceOnRequest)
{ $this->_showPriceOnRequest = $priceOnRequest; }


/**
* @return array
*/
public function getListFieldsShowPriceOnRequest(): array
{
return $this->_priceFields;
}
}
117 changes: 117 additions & 0 deletions plugin/Field/Collection/FieldLoaderSupervisorValues.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php

namespace onOffice\WPlugin\Field\Collection;

use Generator;
use onOffice\SDK\onOfficeSDK;
use onOffice\WPlugin\API\APIClientActionGeneric;
use onOffice\WPlugin\API\ApiClientException;
use onOffice\WPlugin\Language;
use onOffice\WPlugin\SDKWrapper;
use onOffice\WPlugin\Types\FieldTypes;

class FieldLoaderSupervisorValues implements FieldLoader
{
/** @var SDKWrapper */
private $_pSDKWrapper;

public function __construct(SDKWrapper $_pSDKWrapper)
{
$this->_pSDKWrapper = $_pSDKWrapper;
}

/**
* @throws ApiClientException
*/
public function load(): Generator
{
$fullNameSupervisor = $this->getFullNameSupervisor();
$supervisorElementsRecord = $this->getSupervisorField();

if (empty($supervisorElementsRecord)) {
return;
}

foreach ($supervisorElementsRecord as $fieldName => $fieldProperties) {
if ($fieldName === 'benutzer') {
$fieldProperties['type'] = FieldTypes::FIELD_TYPE_SINGLESELECT;
$fieldProperties['module'] = onOfficeSDK::MODULE_SEARCHCRITERIA;
$fieldProperties['permittedvalues'] = $fullNameSupervisor;
$fieldProperties['content'] = __('Search Criteria', 'onoffice-for-wp-websites');
yield $fieldName => $fieldProperties;
}
}
}


/**
* @return array
* @throws ApiClientException
*/
private function getSupervisorField(): array
{
$parametersGetFieldList = [
'labels' => true,
'showContent' => true,
'showTable' => true,
'fieldList' => ['benutzer'],
'language' => Language::getDefault(),
'modules' => [onOfficeSDK::MODULE_ESTATE],
'realDataTypes' => true
];

$pApiClientActionFields = new APIClientActionGeneric
($this->_pSDKWrapper, onOfficeSDK::ACTION_ID_GET, 'fields');
$pApiClientActionFields->setParameters($parametersGetFieldList);
$pApiClientActionFields->addRequestToQueue()->sendRequests();
$result = $pApiClientActionFields->getResultRecords();

if (empty($result[0]['elements'])) {
return [];
}

return $result[0]['elements'];
}

/**
* @return array
* @throws ApiClientException
*/
private function getFullNameSupervisor(): array
{
$pApiClientAction = new APIClientActionGeneric
($this->_pSDKWrapper, onOfficeSDK::ACTION_ID_GET, 'users');

$pApiClientAction->addRequestToQueue();
$this->_pSDKWrapper->sendRequests();
$result = $pApiClientAction->getResultRecords();
$fullNameSupervisor = [];

if (empty($result)) {
return [];
}

foreach ($result as $value) {
$fullName = '';
$firstName = $value['elements']['firstname'];
$lastName = $value['elements']['lastname'];
$userName = $value['elements']['username'];

if (!empty($firstName) && !empty($lastName)) {
$fullName = $lastName . ', ' . $firstName;
} else {
if (!empty($firstName) && empty($lastName)) {
$fullName = $firstName;
} elseif (empty($firstName) && !empty($lastName)) {
$fullName = $lastName;
} else {
$fullName = '(' .$userName . ')';
}
}

$fullNameSupervisor[$value['elements']['id']] = $fullName;
}

return $fullNameSupervisor;
}
}
18 changes: 18 additions & 0 deletions plugin/Field/Collection/FieldsCollectionBuilderShort.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,22 @@ public function addFieldsEstateGeoPositionFrontend(FieldsCollection $pFieldsColl
$pFieldsCollection->merge($pFieldsCollectionTmp);
return $this;
}

/**
* @param FieldsCollection $pFieldsCollection
* @return $this
* @throws DependencyException
* @throws NotFoundException
*/
public function addFieldSupervisorForSearchCriteria(FieldsCollection $pFieldsCollection): self
{
if (!$pFieldsCollection->containsFieldByModule(onOfficeSDK::MODULE_SEARCHCRITERIA, 'benutzer')) {
return $this;
};
$pFieldLoader = $this->_pContainer->get(FieldLoaderSupervisorValues::class);
$pFieldCollectionSupervisor = $this->_pContainer->get(FieldsCollectionBuilder::class)
->buildFieldsCollection($pFieldLoader);
$pFieldsCollection->merge($pFieldCollectionSupervisor);
return $this;
}
}
2 changes: 1 addition & 1 deletion plugin/Field/CustomLabel/CustomLabelRead.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private function createCustomsLabelsByFormIdQuery(int $formId, string $field, $c
. "INNER JOIN {$prefix}$pTranslateLabelConfigurationField\n"
. "ON {$prefix}$pCustomsLabelConfigurationField.customs_labels_id = "
. " {$prefix}$pTranslateLabelConfigurationField.input_id\n"
. "WHERE {$prefix}$pCustomsLabelConfigurationField.fieldname = '" . esc_sql($field) . "' AND\n"
. "WHERE BINARY {$prefix}$pCustomsLabelConfigurationField.fieldname = '" . esc_sql($field) . "' AND\n"
. "{$prefix}$pTranslateLabelConfigurationField.locale = '" . esc_sql($current_lang) . "' AND\n"
. " {$prefix}$pCustomsLabelConfigurationField.form_id = " . esc_sql($formId);
return $queryByFormId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public function getConvertedMultiFields(int $formId, array $pFields): array
case FieldTypes::isDateOrDateTime($pField->getType()):
case FieldTypes::isNumericType($pField->getType()):
case $pField->getType() === FieldTypes::FIELD_TYPE_SINGLESELECT:
case $pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_TINYINT:
case $pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_DATE:
$pDataModel = $this->convertGeneric($formId, $pField, $rowData);
$pDataModels[ $pField->getName() ] = $pDataModel[0] ?? '';
break;
Expand Down Expand Up @@ -139,6 +141,8 @@ public function getConvertedMultiFieldsForAdmin(int $formId, array $pFields): ar
case FieldTypes::isDateOrDateTime($pField->getType()):
case FieldTypes::isNumericType($pField->getType()):
case $pField->getType() === FieldTypes::FIELD_TYPE_SINGLESELECT:
case $pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_TINYINT:
case $pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_DATE:
$pDataModel = $this->convertGeneric($formId, $pField, $rowData);
break;
case $pField->getType() === FieldTypes::FIELD_TYPE_MULTISELECT;
Expand Down Expand Up @@ -194,7 +198,16 @@ private function convertGeneric(int $formId, Field $pField, array $rows): array
{
$pDataModel = new DefaultValueModelSingleselect($formId, $pField);
$pDataModel->setDefaultsId(isset($rows[0]->defaults_id) ? (int) $rows[0]->defaults_id : 0);
$pDataModel->setValue($rows[0]->value ?? '');

if ($pField->getType() === FieldTypes::FIELD_TYPE_DATE || $pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_DATE) {
$formattedDate = date_i18n('Y-m-d', strtotime($rows[0]->value ?? ''));
$pDataModel->setValue($formattedDate);
} elseif ($pField->getType() === FieldTypes::FIELD_TYPE_DATETIME) {
$formattedDate = date_i18n('Y-m-d H:i:s', strtotime($rows[0]->value ?? ''));
$pDataModel->setValue($formattedDate);
} else {
$pDataModel->setValue($rows[0]->value ?? '');
}

$pConverter = $this->_pOutputConverterFactory->createForSingleSelect();
return $pConverter->convertToRow($pDataModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ private function saveForFoundType(int $formId, Field $pField, $values)
{
$isSingleValue = FieldTypes::isDateOrDateTime($pField->getType()) ||
FieldTypes::isNumericType($pField->getType()) ||
$pField->getType() === FieldTypes::FIELD_TYPE_SINGLESELECT;
$pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_TINYINT ||
$pField->getType() === FieldTypes::FIELD_TYPE_SINGLESELECT ||
$pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_DATE;
$isMultiSelect = $pField->getType() === FieldTypes::FIELD_TYPE_MULTISELECT;
$isBoolean = $pField->getType() === FieldTypes::FIELD_TYPE_BOOLEAN;
$isStringType = FieldTypes::isStringType($pField->getType());
Expand Down
6 changes: 5 additions & 1 deletion plugin/Field/OutputFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ public function getVisibleFilterableFields(

$allFields = array_merge($fieldsArray, array_keys($geoFields));
$valuesDefault = array_map(function($field) use ($geoFields, $pInputVariableReader) {
return $pInputVariableReader->getFieldValueFormatted($field) ?: $geoFields[$field] ?? null;
$fieldValue = $pInputVariableReader->getFieldValueFormatted($field);
if ($fieldValue === false) {
return false;
}
return $fieldValue ?: $geoFields[$field] ?? null;
}, $allFields);

$resultDefault = array_combine($allFields, $valuesDefault);
Expand Down
Loading

0 comments on commit ab504e7

Please sign in to comment.