entity manager: order
This commit is contained in:
@@ -62,6 +62,12 @@ class EntityManager extends \Espo\Core\Controllers\Base
|
||||
if (!empty($data['stream'])) {
|
||||
$params['stream'] = $data['stream'];
|
||||
}
|
||||
if (!empty($data['sortBy'])) {
|
||||
$params['sortBy'] = $data['sortBy'];
|
||||
}
|
||||
if (!empty($data['sortDirection'])) {
|
||||
$params['asc'] = $data['sortDirection'] === 'asc';
|
||||
}
|
||||
|
||||
$result = $this->getContainer()->get('entityManagerUtil')->create($name, $type, $params);
|
||||
|
||||
@@ -90,6 +96,10 @@ class EntityManager extends \Espo\Core\Controllers\Base
|
||||
$name = $data['name'];
|
||||
$name = filter_var($name, \FILTER_SANITIZE_STRING);
|
||||
|
||||
if (!empty($data['sortDirection'])) {
|
||||
$data['asc'] = $data['sortDirection'] === 'asc';
|
||||
}
|
||||
|
||||
$result = $this->getContainer()->get('entityManagerUtil')->update($name, $data);
|
||||
|
||||
if ($result) {
|
||||
|
||||
@@ -193,6 +193,16 @@ class EntityManager
|
||||
$this->getLanguage()->set('Global', 'scopeNamesPlural', $name, $labelPlural);
|
||||
}
|
||||
|
||||
if (isset($data['sortBy'])) {
|
||||
$entityDefsData = array(
|
||||
'collection' => array(
|
||||
'sortBy' => $data['sortBy'],
|
||||
'asc' => !empty($data['asc'])
|
||||
)
|
||||
);
|
||||
$this->getMetadata()->set('entityDefs', $name, $entityDefsData);
|
||||
}
|
||||
|
||||
$this->getMetadata()->save();
|
||||
$this->getLanguage()->save();
|
||||
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
"entityForeign": "Foreign Entity",
|
||||
"linkForeign": "Foreign Link",
|
||||
"link": "Link",
|
||||
"labelForeign": "Foreign Label"
|
||||
"labelForeign": "Foreign Label",
|
||||
"sortBy": "Default Order (field)",
|
||||
"sortDirection": "Default Order (direction)"
|
||||
},
|
||||
"options": {
|
||||
"type": {
|
||||
@@ -29,6 +31,10 @@
|
||||
"manyToOne": "Many-to-One",
|
||||
"parentToChildren": "Parent-to-Children",
|
||||
"childrenToParent": "Children-to-Parent"
|
||||
},
|
||||
"sortDirection": {
|
||||
"asc": "Ascending",
|
||||
"desc": "Descending"
|
||||
}
|
||||
},
|
||||
"messages": {
|
||||
|
||||
@@ -26,13 +26,29 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{#if stream}}
|
||||
<div class="row">
|
||||
{{#if stream}}
|
||||
<div class="cell cell-stream form-group col-md-6">
|
||||
<label class="field-label-stream control-label">{{translate 'stream' category='fields' scope='EntityManager'}}</label>
|
||||
<div class="field field-stream">
|
||||
{{{stream}}}
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{/if}}
|
||||
{{#if sortBy}}
|
||||
<div class="row">
|
||||
<div class="cell cell-sortBy form-group col-md-6">
|
||||
<label class="field-label-sortBy control-label">{{translate 'sortBy' category='fields' scope='EntityManager'}}</label>
|
||||
<div class="field field-sortBy">
|
||||
{{{sortBy}}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="cell cell-sortDirection form-group col-md-6">
|
||||
<label class="field-label-sortDirection control-label">{{translate 'sortDirection' category='fields' scope='EntityManager'}}</label>
|
||||
<div class="field field-sortDirection">
|
||||
{{{sortDirection}}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
@@ -70,6 +70,9 @@ Espo.define('Views.Admin.EntityManager.Modals.EditEntity', 'Views.Modal', functi
|
||||
this.model.set('labelPlural', this.translate(scope, 'scopeNamesPlural'));
|
||||
this.model.set('type', this.getMetadata().get('scopes.' + scope + '.type') || '');
|
||||
this.model.set('stream', this.getMetadata().get('scopes.' + scope + '.stream') || false);
|
||||
|
||||
this.model.set('sortBy', this.getMetadata().get('entityDefs.' + scope + '.collection.sortBy'));
|
||||
this.model.set('sortDirection', this.getMetadata().get('entityDefs.' + scope + '.collection.asc') ? 'asc' : 'desc');
|
||||
}
|
||||
|
||||
this.createView('type', 'Fields.Enum', {
|
||||
@@ -131,6 +134,46 @@ Espo.define('Views.Admin.EntityManager.Modals.EditEntity', 'Views.Modal', functi
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (scope) {
|
||||
var fieldDefs = this.getMetadata().get('entityDefs.' + scope + '.fields') || {}
|
||||
var orderableFieldList = Object.keys(fieldDefs).filter(function (item) {
|
||||
if (fieldDefs[item].notStorable) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}, this);
|
||||
|
||||
var translatedOptions = {};
|
||||
orderableFieldList.forEach(function (item) {
|
||||
translatedOptions[item] = this.translate(item, 'fields', scope);
|
||||
}, this);
|
||||
|
||||
this.createView('sortBy', 'Fields.Enum', {
|
||||
model: model,
|
||||
mode: 'edit',
|
||||
el: this.options.el + ' .field-sortBy',
|
||||
defs: {
|
||||
name: 'sortBy',
|
||||
params: {
|
||||
options: orderableFieldList,
|
||||
translatedOptions: translatedOptions
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.createView('sortDirection', 'Fields.Enum', {
|
||||
model: model,
|
||||
mode: 'edit',
|
||||
el: this.options.el + ' .field-sortDirection',
|
||||
defs: {
|
||||
name: 'sortDirection',
|
||||
params: {
|
||||
options: ['asc', 'desc']
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
afterRender: function () {
|
||||
@@ -162,6 +205,11 @@ Espo.define('Views.Admin.EntityManager.Modals.EditEntity', 'Views.Modal', functi
|
||||
'stream'
|
||||
];
|
||||
|
||||
if (this.scope) {
|
||||
arr.push('sortBy');
|
||||
arr.push('sortDirection');
|
||||
}
|
||||
|
||||
var notValid = false;
|
||||
|
||||
arr.forEach(function (item) {
|
||||
@@ -189,16 +237,23 @@ Espo.define('Views.Admin.EntityManager.Modals.EditEntity', 'Views.Modal', functi
|
||||
|
||||
var name = this.model.get('name');
|
||||
|
||||
var data = {
|
||||
name: name,
|
||||
labelSingular: this.model.get('labelSingular'),
|
||||
labelPlural: this.model.get('labelPlural'),
|
||||
type: this.model.get('type'),
|
||||
stream: this.model.get('stream')
|
||||
};
|
||||
|
||||
if (this.scope) {
|
||||
data.sortBy = this.model.get('sortBy');
|
||||
data.sortDirection = this.model.get('sortDirection');
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'POST',
|
||||
data: JSON.stringify({
|
||||
name: name,
|
||||
labelSingular: this.model.get('labelSingular'),
|
||||
labelPlural: this.model.get('labelPlural'),
|
||||
type: this.model.get('type'),
|
||||
stream: this.model.get('stream')
|
||||
}),
|
||||
data: JSON.stringify(data),
|
||||
error: function () {
|
||||
this.$el.find('button[data-name="save"]').removeClass('disabled');
|
||||
}.bind(this)
|
||||
|
||||
@@ -49,6 +49,10 @@ Espo.define('Views.Fields.Enum', ['Views.Fields.Base'], function (Dep) {
|
||||
}
|
||||
}
|
||||
|
||||
if ('translatedOptions' in this.params) {
|
||||
this.translatedOptions = this.params.translatedOptions;
|
||||
}
|
||||
|
||||
if (this.params.translation) {
|
||||
var data = this.getLanguage().data;
|
||||
var arr = this.params.translation.split('.');
|
||||
|
||||
Reference in New Issue
Block a user