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
# 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
generic_object.save!
@ -281,7 +281,7 @@ class ApplicationController < ActionController::Base
generic_object = object.find( params[:id] )
# 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)
rescue Exception => e
logger.error e.message

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -23,24 +23,24 @@ returns
def assets (data)
if !data[ Ticket::Article.to_online_model.to_sym ]
data[ Ticket::Article.to_online_model.to_sym ] = {}
if !data[ Ticket::Article.to_app_model ]
data[ Ticket::Article.to_app_model ] = {}
end
if !data[ Ticket::Article.to_online_model.to_sym ][ self.id ]
data[ Ticket::Article.to_online_model.to_sym ][ self.id ] = self.attributes
if !data[ Ticket::Article.to_app_model ][ self.id ]
data[ Ticket::Article.to_app_model ][ self.id ] = self.attributes
# 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
if !data[ User.to_online_model.to_sym ]
data[ User.to_online_model.to_sym ] = {}
if !data[ User.to_app_model ]
data[ User.to_app_model ] = {}
end
if !data[ User.to_online_model.to_sym ][ self['created_by_id'] ]
data[ User.to_online_model.to_sym ][ self['created_by_id'] ] = User.user_data_full( self['created_by_id'] )
if !data[ User.to_app_model ][ self['created_by_id'] ]
data[ User.to_app_model ][ self['created_by_id'] ] = User.user_data_full( self['created_by_id'] )
end
if !data[ User.to_online_model.to_sym ][ self['updated_by_id'] ]
data[ User.to_online_model.to_sym ][ self['updated_by_id'] ] = User.user_data_full( self['updated_by_id'] )
if !data[ User.to_app_model ][ self['updated_by_id'] ]
data[ User.to_app_model ][ self['updated_by_id'] ] = User.user_data_full( self['updated_by_id'] )
end
data
end

View file

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

View file

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

View file

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

View file

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

View file

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