Migration from users.street, users.zip, users.city to user.address.

This commit is contained in:
Martin Edenhofer 2015-02-08 09:16:01 +01:00
parent 519028f491
commit 13685030d1
3 changed files with 103 additions and 11 deletions

View file

@ -83,8 +83,9 @@ class App extends Spine.Controller
isHtmlEscape = false
if attribute_config.tag is 'textarea'
isHtmlEscape = true
result = App.Utils.text2html( result )
result = App.Utils.text2html( result )
# remember, html snippets are already escaped
else if attribute_config.tag is 'richtext'
isHtmlEscape = true
@ -94,22 +95,20 @@ class App extends Spine.Controller
result = attribute_config.options[result]
# translate content
isTranslated = false
if attribute_config.translate || ( isObject && item.translate && item.translate() )
isTranslated = true
isHtmlEscape = true
result = App.i18n.translateContent( result )
result = App.i18n.translateContent( result )
# transform date
if attribute_config.tag is 'date'
isHtmlEscape = true
result = App.i18n.translateDate(result)
result = App.i18n.translateDate(result)
# use pretty time for datetime
else if attribute_config.tag is 'datetime'
isHtmlEscape = true
result = "<span class=\"humanTimeFromNow #{attribute_config.class}\" data-time=\"#{result}\">?</span>"
#result = App.i18n.translateTimestamp(result)
result = "<span class=\"humanTimeFromNow #{attribute_config.class}\" data-time=\"#{result}\">?</span>"
#result = App.i18n.translateTimestamp(result)
if !isHtmlEscape && typeof result is 'string'
result = App.Utils.htmlEscape(result)

View file

@ -65,7 +65,7 @@ list of all attributes
=begin
add a new activity entry for an object
add a new attribute entry for an object
ObjectManager::Attribute.add(
:object => 'Ticket',
@ -101,7 +101,6 @@ add a new activity entry for an object
:updated_at => '2014-06-04 10:00:00',
)
=end
def self.add(data)
@ -114,8 +113,8 @@ add a new activity entry for an object
# check newest entry - is needed
result = ObjectManager::Attribute.where(
:object_lookup_id => data[:object_lookup_id],
:name => data[:name],
:object_lookup_id => data[:object_lookup_id],
:name => data[:name],
).first
if result
# raise "ERROR: attribute #{data[:name]} for #{data[:object]} already exists"
@ -129,6 +128,30 @@ add a new activity entry for an object
=begin
get the attribute model based on object and name
attribute = ObjectManager::Attribute.get(
:object => 'Ticket',
:name => 'group_id',
)
=end
def self.get(data)
# lookups
if data[:object]
data[:object_lookup_id] = ObjectLookup.by_name( data[:object] )
end
ObjectManager::Attribute.where(
:object_lookup_id => data[:object_lookup_id],
:name => data[:name],
).first
end
=begin
get user based list of object attributes
attribute_list = ObjectManager::Attribute.by_object('Ticket', user)

View file

@ -0,0 +1,70 @@
class CreateAddress < ActiveRecord::Migration
def up
add_column :users, :address, :string, :limit => 500, :null => true
User.all.each {|user|
address = ''
if user.street && !user.street.empty?
address += "#{user.street}\n"
end
if user.zip && !user.zip.empty?
address += "#{user.zip} "
end
if user.city && !user.city.empty?
address += "#{user.city}"
end
if !address.empty?
user.address = address
user.save
end
}
['street', 'zip', 'city', 'department'].each {|attribute_name|
attribute = ObjectManager::Attribute.get(
:object => 'User',
:name => attribute_name,
)
if attribute
attribute.active = false
attribute.save
end
}
ObjectManager::Attribute.add(
:object => 'User',
:name => 'address',
:display => 'Address',
:data_type => 'textarea',
:data_option => {
:type => 'text',
:maxlength => 500,
:null => true,
:item_class => 'formGroup--halfSize',
},
:editable => false,
:active => true,
:screens => {
:signup => {},
:invite_agent => {},
:edit => {
'-all-' => {
:null => true,
},
},
:view => {
'-all-' => {
:shown => true,
},
},
},
:pending_migration => false,
:position => 1350,
:created_by_id => 1,
:updated_by_id => 1,
)
end
def down
end
end