Renamed class name to get app model name.

This commit is contained in:
Martin Edenhofer 2013-09-22 00:50:23 +02:00
parent b26cdf6d59
commit 438baa1231
15 changed files with 105 additions and 105 deletions

View file

@ -257,7 +257,7 @@ class ApplicationController < ActionController::Base
begin begin
# create object # create object
generic_object = object.new( object.param_cleanup( params[object.to_app_model] ) ) generic_object = object.new( object.param_cleanup( params[object.to_app_model_url] ) )
# save object # save object
generic_object.save! generic_object.save!
@ -281,7 +281,7 @@ class ApplicationController < ActionController::Base
generic_object = object.find( params[:id] ) generic_object = object.find( params[:id] )
# save object # save object
generic_object.update_attributes!( object.param_cleanup( params[object.to_app_model] ) ) generic_object.update_attributes!( object.param_cleanup( params[object.to_app_model_url] ) )
model_update_render_item(generic_object) model_update_render_item(generic_object)
rescue Exception => e rescue Exception => e
logger.error e.message logger.error e.message

View file

@ -4,29 +4,29 @@ module ExtraCollection
def session( collections, user ) def session( collections, user )
# all base stuff # all base stuff
collections[ Taskbar.to_online_model ] = Taskbar.where( :user_id => user.id ) collections[ Taskbar.to_app_model ] = Taskbar.where( :user_id => user.id )
collections[ Role.to_online_model ] = Role.all collections[ Role.to_app_model ] = Role.all
collections[ Group.to_online_model ] = Group.all collections[ Group.to_app_model ] = Group.all
if !user.is_role('Customer') if !user.is_role('Customer')
collections[ Organization.to_online_model ] = Organization.all collections[ Organization.to_app_model ] = Organization.all
else else
if user.organization_id if user.organization_id
collections[ Organization.to_online_model ] = Organization.where( :id => user.organization_id ) collections[ Organization.to_app_model ] = Organization.where( :id => user.organization_id )
end end
end end
end end
def push( collections, user ) def push( collections, user )
# all base stuff # all base stuff
collections[ Role.to_online_model ] = Role.all collections[ Role.to_app_model ] = Role.all
collections[ Group.to_online_model ] = Group.all collections[ Group.to_app_model ] = Group.all
if !user.is_role('Customer') if !user.is_role('Customer')
collections[ Organization.to_online_model ] = Organization.all collections[ Organization.to_app_model ] = Organization.all
else else
if user.organization_id if user.organization_id
collections[ Organization.to_online_model ] = Organization.where( :id => user.organization_id ) collections[ Organization.to_app_model ] = Organization.where( :id => user.organization_id )
end end
end end
end end

View file

@ -3,18 +3,18 @@
module ExtraCollection module ExtraCollection
def session( collections, user ) def session( collections, user )
collections[ Network.to_online_model ] = Network.all collections[ Network.to_app_model ] = Network.all
collections[ Network::Category.to_online_model ] = Network::Category.all collections[ Network::Category.to_app_model ] = Network::Category.all
collections[ Network::Category::Type.to_online_model ] = Network::Category::Type.all collections[ Network::Category::Type.to_app_model ] = Network::Category::Type.all
collections[ Network::Privacy.to_online_model ] = Network::Privacy.all collections[ Network::Privacy.to_app_model ] = Network::Privacy.all
end end
def push( collections, user ) def push( collections, user )
collections[ Network.to_online_model ] = Network.all collections[ Network.to_app_model ] = Network.all
collections[ Network::Category.to_online_model ] = Network::Category.all collections[ Network::Category.to_app_model ] = Network::Category.all
collections[ Network::Category::Type.to_online_model ] = Network::Category::Type.all collections[ Network::Category::Type.to_app_model ] = Network::Category::Type.all
collections[ Network::Privacy.to_online_model ] = Network::Privacy.all collections[ Network::Privacy.to_app_model ] = Network::Privacy.all
end end
module_function :session, :push module_function :session, :push

View file

@ -4,37 +4,37 @@ module ExtraCollection
def session( collections, user ) def session( collections, user )
# all ticket stuff # all ticket stuff
collections[ Ticket::StateType.to_online_model ] = Ticket::StateType.all collections[ Ticket::StateType.to_app_model ] = Ticket::StateType.all
collections[ Ticket::State.to_online_model ] = Ticket::State.all collections[ Ticket::State.to_app_model ] = Ticket::State.all
collections[ Ticket::Priority.to_online_model ] = Ticket::Priority.all collections[ Ticket::Priority.to_app_model ] = Ticket::Priority.all
collections[ Ticket::Article::Type.to_online_model ] = Ticket::Article::Type.all collections[ Ticket::Article::Type.to_app_model ] = Ticket::Article::Type.all
collections[ Ticket::Article::Sender.to_online_model ] = Ticket::Article::Sender.all collections[ Ticket::Article::Sender.to_app_model ] = Ticket::Article::Sender.all
if !user.is_role('Customer') if !user.is_role('Customer')
# all signatures # all signatures
collections[ Signature.to_online_model ] = Signature.all collections[ Signature.to_app_model ] = Signature.all
# all email addresses # all email addresses
collections[ EmailAddress.to_online_model ] = EmailAddress.all collections[ EmailAddress.to_app_model ] = EmailAddress.all
end end
end end
def push( collections, user ) def push( collections, user )
# all ticket stuff # all ticket stuff
collections[ Ticket::StateType.to_online_model ] = Ticket::StateType.all collections[ Ticket::StateType.to_app_model ] = Ticket::StateType.all
collections[ Ticket::State.to_online_model ] = Ticket::State.all collections[ Ticket::State.to_app_model ] = Ticket::State.all
collections[ Ticket::Priority.to_online_model ] = Ticket::Priority.all collections[ Ticket::Priority.to_app_model ] = Ticket::Priority.all
collections[ Ticket::Article::Type.to_online_model ] = Ticket::Article::Type.all collections[ Ticket::Article::Type.to_app_model ] = Ticket::Article::Type.all
collections[ Ticket::Article::Sender.to_online_model ] = Ticket::Article::Sender.all collections[ Ticket::Article::Sender.to_app_model ] = Ticket::Article::Sender.all
if !user.is_role('Customer') if !user.is_role('Customer')
# all signatures # all signatures
collections[ Signature.to_online_model ] = Signature.all collections[ Signature.to_app_model ] = Signature.all
# all email addresses # all email addresses
collections[ EmailAddress.to_online_model ] = EmailAddress.all collections[ EmailAddress.to_app_model ] = EmailAddress.all
end end
end end

View file

@ -161,7 +161,7 @@ class SessionsController < ApplicationController
} }
render :json => { render :json => {
:sessions => sessions_clean, :sessions => sessions_clean,
User.to_online_model.to_sym => users, User.to_app_model => users,
} }
end end

View file

@ -49,7 +49,7 @@ class TicketOverviewsController < ApplicationController
end end
# get related users # get related users
assets = { User.to_online_model.to_sym => {} } assets = { User.to_app_model => {} }
overview[:ticket_ids].each {|ticket_id| overview[:ticket_ids].each {|ticket_id|
ticket = Ticket.lookup( :id => ticket_id ) ticket = Ticket.lookup( :id => ticket_id )
assets = ticket.assets(assets) assets = ticket.assets(assets)
@ -70,8 +70,8 @@ class TicketOverviewsController < ApplicationController
Group.find(group_id).users.each {|user| Group.find(group_id).users.each {|user|
next if !agents[ user.id ] next if !agents[ user.id ]
groups_users[ group_id ].push user.id groups_users[ group_id ].push user.id
if !assets[ User.to_online_model.to_sym ][user.id] if !assets[ User.to_app_model ][user.id]
assets[ User.to_online_model.to_sym ][user.id] = User.user_data_full(user.id) assets[ User.to_app_model ][user.id] = User.user_data_full(user.id)
end end
} }
} }

View file

@ -304,22 +304,22 @@ class TicketsController < ApplicationController
# get related users # get related users
assets = {} assets = {}
assets[ User.to_online_model.to_sym ] = {} assets[ User.to_app_model ] = {}
assets = ticket.assets(assets) assets = ticket.assets(assets)
# get attributes to update # get attributes to update
attributes_to_change = Ticket::ScreenOptions.attributes_to_change( :user => current_user, :ticket => ticket ) attributes_to_change = Ticket::ScreenOptions.attributes_to_change( :user => current_user, :ticket => ticket )
attributes_to_change[:owner_id].each { |user_id| attributes_to_change[:owner_id].each { |user_id|
if !assets[ User.to_online_model.to_sym ][user_id] if !assets[ User.to_app_model ][user_id]
assets[ User.to_online_model.to_sym ][user_id] = User.user_data_full( user_id ) assets[ User.to_app_model ][user_id] = User.user_data_full( user_id )
end end
} }
attributes_to_change[:group_id__owner_id].each {|group_id, user_ids| attributes_to_change[:group_id__owner_id].each {|group_id, user_ids|
user_ids.each {|user_id| user_ids.each {|user_id|
if !assets[ User.to_online_model.to_sym ][user_id] if !assets[ User.to_app_model ][user_id]
assets[ User.to_online_model.to_sym ][user_id] = User.user_data_full( user_id ) assets[ User.to_app_model ][user_id] = User.user_data_full( user_id )
end end
} }
} }
@ -362,17 +362,17 @@ class TicketsController < ApplicationController
) )
assets = {} assets = {}
assets[ User.to_online_model.to_sym ] = {} assets[ User.to_app_model ] = {}
attributes_to_change[:owner_id].each { |user_id| attributes_to_change[:owner_id].each { |user_id|
if !assets[ User.to_online_model.to_sym ][user_id] if !assets[ User.to_app_model ][user_id]
assets[ User.to_online_model.to_sym ][user_id] = User.user_data_full( user_id ) assets[ User.to_app_model ][user_id] = User.user_data_full( user_id )
end end
} }
attributes_to_change[:group_id__owner_id].each {|group_id, user_ids| attributes_to_change[:group_id__owner_id].each {|group_id, user_ids|
user_ids.each {|user_id| user_ids.each {|user_id|
if !assets[ User.to_online_model.to_sym ][user_id] if !assets[ User.to_app_model ][user_id]
assets[ User.to_online_model.to_sym ][user_id] = User.user_data_full( user_id ) assets[ User.to_app_model ][user_id] = User.user_data_full( user_id )
end end
} }
} }
@ -387,8 +387,8 @@ class TicketsController < ApplicationController
owner_ids = [] owner_ids = []
ticket.agent_of_group.each { |user| ticket.agent_of_group.each { |user|
owner_ids.push user.id owner_ids.push user.id
if !assets[ User.to_online_model.to_sym ][user.id] if !assets[ User.to_app_model ][user.id]
assets[ User.to_online_model.to_sym ][user.id] = User.user_data_full( user.id ) assets[ User.to_app_model ][user.id] = User.user_data_full( user.id )
end end
} }

View file

@ -22,22 +22,22 @@ returns
def assets (data) def assets (data)
if !data[ User.to_online_model.to_sym ] if !data[ User.to_app_model ]
data[ User.to_online_model.to_sym ] = {} data[ User.to_app_model ] = {}
end end
if !data[ User.to_online_model.to_sym ][ self['created_by_id'] ] if !data[ User.to_app_model ][ self['created_by_id'] ]
data[ User.to_online_model.to_sym ][ self['created_by_id'] ] = User.user_data_full( self['created_by_id'] ) data[ User.to_app_model ][ self['created_by_id'] ] = User.user_data_full( self['created_by_id'] )
end end
# fetch meta relations # fetch meta relations
if !data[ History::Object.to_online_model.to_sym ] if !data[ History::Object.to_app_model ]
data[ History::Object.to_online_model.to_sym ] = History::Object.all() data[ History::Object.to_app_model ] = History::Object.all()
end end
if !data[ History::Type.to_online_model.to_sym ] if !data[ History::Type.to_app_model ]
data[ History::Type.to_online_model.to_sym ] = History::Type.all() data[ History::Type.to_app_model ] = History::Type.all()
end end
if !data[ History::Attribute.to_online_model.to_sym ] if !data[ History::Attribute.to_app_model ]
data[ History::Attribute.to_online_model.to_sym ] = History::Attribute.all() data[ History::Attribute.to_app_model ] = History::Attribute.all()
end end
data data

View file

@ -22,19 +22,19 @@ returns
def assets (data) def assets (data)
if !data[ Organization.to_online_model.to_sym ] if !data[ Organization.to_app_model ]
data[ Organization.to_online_model.to_sym ] = {} data[ Organization.to_app_model ] = {}
end end
if !data[ User.to_online_model.to_sym ] if !data[ User.to_app_model ]
data[ User.to_online_model.to_sym ] = {} data[ User.to_app_model ] = {}
end end
if !data[ Organization.to_online_model.to_sym ][ self.id ] if !data[ Organization.to_app_model ][ self.id ]
data[ Organization.to_online_model.to_sym ][ self.id ] = self.attributes data[ Organization.to_app_model ][ self.id ] = self.attributes
data[ Organization.to_online_model.to_sym ][ self.id ][:user_ids] = [] data[ Organization.to_app_model ][ self.id ][:user_ids] = []
users = User.where( :organization_id => self.id ).limit(10) users = User.where( :organization_id => self.id ).limit(10)
users.each {|user| users.each {|user|
data[ User.to_online_model.to_sym ][ user.id ] = User.user_data_full( user.id ) data[ User.to_app_model ][ user.id ] = User.user_data_full( user.id )
data[ Organization.to_online_model.to_sym ][ self.id ][:user_ids].push user.id data[ Organization.to_app_model ][ self.id ][:user_ids].push user.id
} }
end end
data data

View file

@ -23,24 +23,24 @@ returns
def assets (data) def assets (data)
if !data[ Ticket::Article.to_online_model.to_sym ] if !data[ Ticket::Article.to_app_model ]
data[ Ticket::Article.to_online_model.to_sym ] = {} data[ Ticket::Article.to_app_model ] = {}
end end
if !data[ Ticket::Article.to_online_model.to_sym ][ self.id ] if !data[ Ticket::Article.to_app_model ][ self.id ]
data[ Ticket::Article.to_online_model.to_sym ][ self.id ] = self.attributes data[ Ticket::Article.to_app_model ][ self.id ] = self.attributes
# add attachment list to article # add attachment list to article
data[ Ticket::Article.to_online_model.to_sym ][ self.id ]['attachments'] = Store.list( :object => 'Ticket::Article', :o_id => self.id ) data[ Ticket::Article.to_app_model ][ self.id ]['attachments'] = Store.list( :object => 'Ticket::Article', :o_id => self.id )
end end
if !data[ User.to_online_model.to_sym ] if !data[ User.to_app_model ]
data[ User.to_online_model.to_sym ] = {} data[ User.to_app_model ] = {}
end end
if !data[ User.to_online_model.to_sym ][ self['created_by_id'] ] if !data[ User.to_app_model ][ self['created_by_id'] ]
data[ User.to_online_model.to_sym ][ self['created_by_id'] ] = User.user_data_full( self['created_by_id'] ) data[ User.to_app_model ][ self['created_by_id'] ] = User.user_data_full( self['created_by_id'] )
end end
if !data[ User.to_online_model.to_sym ][ self['updated_by_id'] ] if !data[ User.to_app_model ][ self['updated_by_id'] ]
data[ User.to_online_model.to_sym ][ self['updated_by_id'] ] = User.user_data_full( self['updated_by_id'] ) data[ User.to_app_model ][ self['updated_by_id'] ] = User.user_data_full( self['updated_by_id'] )
end end
data data
end end

View file

@ -23,27 +23,27 @@ returns
def assets (data) def assets (data)
if !data[ Ticket.to_online_model.to_sym ] if !data[ Ticket.to_app_model ]
data[ Ticket.to_online_model.to_sym ] = {} data[ Ticket.to_app_model ] = {}
end end
if !data[ Ticket.to_online_model.to_sym ][ self.id ] if !data[ Ticket.to_app_model ][ self.id ]
data[ Ticket.to_online_model.to_sym ][ self.id ] = self.attributes data[ Ticket.to_app_model ][ self.id ] = self.attributes
end end
if !data[ User.to_online_model.to_sym ] if !data[ User.to_app_model ]
data[ User.to_online_model.to_sym ] = {} data[ User.to_app_model ] = {}
end end
if !data[ User.to_online_model.to_sym ][ self['owner_id'] ] if !data[ User.to_app_model ][ self['owner_id'] ]
data[ User.to_online_model.to_sym ][ self['owner_id'] ] = User.user_data_full( self['owner_id'] ) data[ User.to_app_model ][ self['owner_id'] ] = User.user_data_full( self['owner_id'] )
end end
if !data[ User.to_online_model.to_sym ][ self['customer_id'] ] if !data[ User.to_app_model ][ self['customer_id'] ]
data[ User.to_online_model.to_sym ][ self['customer_id'] ] = User.user_data_full( self['customer_id'] ) data[ User.to_app_model ][ self['customer_id'] ] = User.user_data_full( self['customer_id'] )
end end
if !data[ User.to_online_model.to_sym ][ self['created_by_id'] ] if !data[ User.to_app_model ][ self['created_by_id'] ]
data[ User.to_online_model.to_sym ][ self['created_by_id'] ] = User.user_data_full( self['created_by_id'] ) data[ User.to_app_model ][ self['created_by_id'] ] = User.user_data_full( self['created_by_id'] )
end end
if !data[ User.to_online_model.to_sym ][ self['updated_by_id'] ] if !data[ User.to_app_model ][ self['updated_by_id'] ]
data[ User.to_online_model.to_sym ][ self['updated_by_id'] ] = User.user_data_full( self['updated_by_id'] ) data[ User.to_app_model ][ self['updated_by_id'] ] = User.user_data_full( self['updated_by_id'] )
end end
data data
end end

View file

@ -22,11 +22,11 @@ returns
def assets (data) def assets (data)
if !data[ User.to_online_model.to_sym ] if !data[ User.to_app_model ]
data[ User.to_online_model.to_sym ] = {} data[ User.to_app_model ] = {}
end end
if !data[ User.to_online_model.to_sym ][ self.id ] if !data[ User.to_app_model ][ self.id ]
data[ User.to_online_model.to_sym ][ self.id ] = User.user_data_full( self.id ) data[ User.to_app_model ][ self.id ] = User.user_data_full( self.id )
end end
data data
end end

View file

@ -1,5 +1,5 @@
class Class class Class
def to_app_model def to_app_model_url
camel_cased_word = self.to_s camel_cased_word = self.to_s
camel_cased_word.gsub(/::/, '_'). camel_cased_word.gsub(/::/, '_').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
@ -7,8 +7,8 @@ class Class
tr("-", "_"). tr("-", "_").
downcase downcase
end end
def to_online_model def to_app_model
camel_cased_word = self.to_s camel_cased_word = self.to_s
camel_cased_word.gsub(/::/, '') camel_cased_word.gsub(/::/, '').to_sym
end end
end end

View file

@ -70,8 +70,8 @@ module Sessions::Backend::TicketOverviewList
# send update to browser # send update to browser
client.send({ client.send({
:data => { :data => {
User.to_online_model.to_sym => users, User.to_app_model => users,
Ticket.to_online_model.to_sym => tickets, Ticket.to_app_model => tickets,
}, },
:event => [ 'loadAssets' ] :event => [ 'loadAssets' ]
}) })

View file

@ -47,7 +47,7 @@ class Sessions::Client
self.send({ self.send({
:data => { :data => {
:collections => { :collections => {
User.to_online_model.to_sym => users, User.to_app_model => users,
}, },
}, },
:event => [ 'loadCollection', 'ticket_overview_rebuild' ], :event => [ 'loadCollection', 'ticket_overview_rebuild' ],
@ -73,8 +73,8 @@ class Sessions::Client
self.send({ self.send({
:data => { :data => {
:collections => { :collections => {
Ticket.to_online_model.to_sym => tickets, Ticket.to_app_model => tickets,
User.to_online_model.to_sym => users, User.to_app_model => users,
}, },
}, },
:event => [ 'loadCollection', 'ticket_overview_rebuild' ], :event => [ 'loadCollection', 'ticket_overview_rebuild' ],