Fixes 3594 - Allow position to determine an attributes position entirely.
This commit is contained in:
parent
41a04193da
commit
d61932de6e
6 changed files with 165 additions and 10 deletions
|
@ -247,8 +247,6 @@ class Edit extends App.ControllerGenericEdit
|
||||||
#if attribute.name is 'data_type'
|
#if attribute.name is 'data_type'
|
||||||
# attribute.disabled = true
|
# attribute.disabled = true
|
||||||
|
|
||||||
console.log('configure_attributes', configure_attributes)
|
|
||||||
|
|
||||||
@controller = new App.ControllerForm(
|
@controller = new App.ControllerForm(
|
||||||
model:
|
model:
|
||||||
configure_attributes: configure_attributes
|
configure_attributes: configure_attributes
|
||||||
|
|
|
@ -916,20 +916,25 @@ set new attributes of model (remove already available attributes)
|
||||||
|
|
||||||
# use jquery instead of ._clone() because we need a deep copy of the obj
|
# use jquery instead of ._clone() because we need a deep copy of the obj
|
||||||
@org_configure_attributes = $.extend(true, [], @configure_attributes)
|
@org_configure_attributes = $.extend(true, [], @configure_attributes)
|
||||||
|
configure_attributes = $.extend(true, [], @configure_attributes)
|
||||||
|
allAttributes = []
|
||||||
for attribute in attributes
|
for attribute in attributes
|
||||||
@attributes.push attribute.name
|
@attributes.push attribute.name
|
||||||
|
|
||||||
found = false
|
found = false
|
||||||
for attribute_model, index in @configure_attributes
|
for attribute_model, index in configure_attributes
|
||||||
continue if attribute_model.name != attribute.name
|
continue if attribute_model.name != attribute.name
|
||||||
|
|
||||||
@configure_attributes[index] = _.extend(attribute_model, attribute)
|
allAttributes.push $.extend(true, attribute_model, attribute)
|
||||||
|
configure_attributes.splice(index, 1) # remove found attribute
|
||||||
|
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
|
|
||||||
if !found
|
if !found
|
||||||
@configure_attributes.push attribute
|
allAttributes.push $.extend(true, {}, attribute)
|
||||||
|
|
||||||
|
@configure_attributes = $.extend(true, [], allAttributes.concat(configure_attributes))
|
||||||
|
|
||||||
@resetAttributes: ->
|
@resetAttributes: ->
|
||||||
return if _.isEmpty(@org_configure_attributes)
|
return if _.isEmpty(@org_configure_attributes)
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
|
class ObjectManagerTicketObjectUpdate < ActiveRecord::Migration[4.2]
|
||||||
|
def up
|
||||||
|
|
||||||
|
# return if it's a new setup
|
||||||
|
return if !Setting.exists?(name: 'system_init_done')
|
||||||
|
|
||||||
|
UserInfo.current_user_id = 1
|
||||||
|
ObjectManager::Attribute.add(
|
||||||
|
force: true,
|
||||||
|
object: 'Ticket',
|
||||||
|
name: 'number',
|
||||||
|
display: '#',
|
||||||
|
data_type: 'input',
|
||||||
|
data_option: {
|
||||||
|
type: 'text',
|
||||||
|
readonly: 1,
|
||||||
|
null: true,
|
||||||
|
maxlength: 60,
|
||||||
|
width: '68px',
|
||||||
|
},
|
||||||
|
editable: false,
|
||||||
|
active: true,
|
||||||
|
screens: {
|
||||||
|
create_top: {},
|
||||||
|
edit: {},
|
||||||
|
},
|
||||||
|
to_create: false,
|
||||||
|
to_migrate: false,
|
||||||
|
to_delete: false,
|
||||||
|
position: 5,
|
||||||
|
)
|
||||||
|
|
||||||
|
ObjectManager::Attribute.add(
|
||||||
|
force: true,
|
||||||
|
object: 'Ticket',
|
||||||
|
name: 'title',
|
||||||
|
display: 'Title',
|
||||||
|
data_type: 'input',
|
||||||
|
data_option: {
|
||||||
|
type: 'text',
|
||||||
|
maxlength: 200,
|
||||||
|
null: false,
|
||||||
|
translate: false,
|
||||||
|
},
|
||||||
|
editable: false,
|
||||||
|
active: true,
|
||||||
|
screens: {
|
||||||
|
create_top: {
|
||||||
|
'-all-' => {
|
||||||
|
null: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
edit: {},
|
||||||
|
},
|
||||||
|
to_create: false,
|
||||||
|
to_migrate: false,
|
||||||
|
to_delete: false,
|
||||||
|
position: 8,
|
||||||
|
)
|
||||||
|
|
||||||
|
ObjectManager::Attribute.add(
|
||||||
|
force: true,
|
||||||
|
object: 'Ticket',
|
||||||
|
name: 'organization_id',
|
||||||
|
display: 'Organization',
|
||||||
|
data_type: 'autocompletion_ajax',
|
||||||
|
data_option: {
|
||||||
|
relation: 'Organization',
|
||||||
|
autocapitalize: false,
|
||||||
|
multiple: false,
|
||||||
|
null: true,
|
||||||
|
translate: false,
|
||||||
|
permission: ['ticket.agent'],
|
||||||
|
readonly: 1,
|
||||||
|
},
|
||||||
|
editable: false,
|
||||||
|
active: true,
|
||||||
|
screens: {
|
||||||
|
create_top: {
|
||||||
|
'-all-' => {
|
||||||
|
null: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
edit: {},
|
||||||
|
},
|
||||||
|
to_create: false,
|
||||||
|
to_migrate: false,
|
||||||
|
to_delete: false,
|
||||||
|
position: 12,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,5 +1,30 @@
|
||||||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
|
ObjectManager::Attribute.add(
|
||||||
|
force: true,
|
||||||
|
object: 'Ticket',
|
||||||
|
name: 'number',
|
||||||
|
display: '#',
|
||||||
|
data_type: 'input',
|
||||||
|
data_option: {
|
||||||
|
type: 'text',
|
||||||
|
readonly: 1,
|
||||||
|
null: true,
|
||||||
|
maxlength: 60,
|
||||||
|
width: '68px',
|
||||||
|
},
|
||||||
|
editable: false,
|
||||||
|
active: true,
|
||||||
|
screens: {
|
||||||
|
create_top: {},
|
||||||
|
edit: {},
|
||||||
|
},
|
||||||
|
to_create: false,
|
||||||
|
to_migrate: false,
|
||||||
|
to_delete: false,
|
||||||
|
position: 5,
|
||||||
|
)
|
||||||
|
|
||||||
ObjectManager::Attribute.add(
|
ObjectManager::Attribute.add(
|
||||||
force: true,
|
force: true,
|
||||||
object: 'Ticket',
|
object: 'Ticket',
|
||||||
|
@ -25,7 +50,7 @@ ObjectManager::Attribute.add(
|
||||||
to_create: false,
|
to_create: false,
|
||||||
to_migrate: false,
|
to_migrate: false,
|
||||||
to_delete: false,
|
to_delete: false,
|
||||||
position: 15,
|
position: 8,
|
||||||
)
|
)
|
||||||
|
|
||||||
ObjectManager::Attribute.add(
|
ObjectManager::Attribute.add(
|
||||||
|
@ -61,6 +86,38 @@ ObjectManager::Attribute.add(
|
||||||
to_delete: false,
|
to_delete: false,
|
||||||
position: 10,
|
position: 10,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ObjectManager::Attribute.add(
|
||||||
|
force: true,
|
||||||
|
object: 'Ticket',
|
||||||
|
name: 'organization_id',
|
||||||
|
display: 'Organization',
|
||||||
|
data_type: 'autocompletion_ajax',
|
||||||
|
data_option: {
|
||||||
|
relation: 'Organization',
|
||||||
|
autocapitalize: false,
|
||||||
|
multiple: false,
|
||||||
|
null: true,
|
||||||
|
translate: false,
|
||||||
|
permission: ['ticket.agent'],
|
||||||
|
readonly: 1,
|
||||||
|
},
|
||||||
|
editable: false,
|
||||||
|
active: true,
|
||||||
|
screens: {
|
||||||
|
create_top: {
|
||||||
|
'-all-' => {
|
||||||
|
null: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
edit: {},
|
||||||
|
},
|
||||||
|
to_create: false,
|
||||||
|
to_migrate: false,
|
||||||
|
to_delete: false,
|
||||||
|
position: 12,
|
||||||
|
)
|
||||||
|
|
||||||
ObjectManager::Attribute.add(
|
ObjectManager::Attribute.add(
|
||||||
force: true,
|
force: true,
|
||||||
object: 'Ticket',
|
object: 'Ticket',
|
||||||
|
|
|
@ -227,8 +227,9 @@ QUnit.test("updateAttributes will change existing attributes and add new ones",
|
||||||
var attributesAfterUpdate = _.clone(App.Ticket.configure_attributes);
|
var attributesAfterUpdate = _.clone(App.Ticket.configure_attributes);
|
||||||
|
|
||||||
assert.equal(attributesAfterUpdate.length, attributesBefore.length + 1, 'new attributes list contains 1 more elements')
|
assert.equal(attributesAfterUpdate.length, attributesBefore.length + 1, 'new attributes list contains 1 more elements')
|
||||||
assert.equal(attributesAfterUpdate[attributesAfterUpdate.length - 1]['name'], 'new_attribute_1010101', 'new attributes list contains the new element')
|
assert.equal(attributesAfterUpdate[0]['new_option_1239393'], 1, 'first element of the new attributes is number')
|
||||||
assert.equal(attributesAfterUpdate[0]['new_option_1239393'], 1, 'first element of the new attributes got updated with the new option')
|
assert.equal(attributesAfterUpdate[0]['name'], 'number', 'first element of the new attributes got updated with the new option')
|
||||||
|
assert.equal(attributesAfterUpdate[1]['name'], 'new_attribute_1010101', 'new attributes list contains the new element')
|
||||||
|
|
||||||
App.Ticket.resetAttributes();
|
App.Ticket.resetAttributes();
|
||||||
var attributesAfterReset = _.clone(App.Ticket.configure_attributes);
|
var attributesAfterReset = _.clone(App.Ticket.configure_attributes);
|
||||||
|
|
|
@ -76,7 +76,7 @@ RSpec.describe ObjectManager::Attribute, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
%w[title tags].each do |not_editable_attribute|
|
%w[title tags number].each do |not_editable_attribute|
|
||||||
it "rejects '#{not_editable_attribute}' which is used" do
|
it "rejects '#{not_editable_attribute}' which is used" do
|
||||||
expect do
|
expect do
|
||||||
described_class.add attributes_for :object_manager_attribute_text, name: not_editable_attribute
|
described_class.add attributes_for :object_manager_attribute_text, name: not_editable_attribute
|
||||||
|
@ -84,7 +84,7 @@ RSpec.describe ObjectManager::Attribute, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
%w[priority state note number].each do |existing_attribute|
|
%w[priority state note].each do |existing_attribute|
|
||||||
it "rejects '#{existing_attribute}' which is used" do
|
it "rejects '#{existing_attribute}' which is used" do
|
||||||
expect do
|
expect do
|
||||||
described_class.add attributes_for :object_manager_attribute_text, name: existing_attribute
|
described_class.add attributes_for :object_manager_attribute_text, name: existing_attribute
|
||||||
|
|
Loading…
Reference in a new issue