123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- class SlasController < ApplicationController
- before_action :authentication_check
- def index
- return if deny_if_not_role(Z_ROLENAME_ADMIN)
- assets = {}
-
- calendar_ids = []
- Calendar.all.order(:name).each {|calendar|
- calendar_ids.push calendar.id
- assets = calendar.assets(assets)
- }
-
- sla_ids = []
- models = Models.all
- Sla.all.order(:name).each {|sla|
- sla_ids.push sla.id
- assets = sla.assets(assets)
-
- sla.condition.each {|item, content|
- attribute = item.split(/\./)
- next if !attribute[1]
- attribute_class = attribute[0].to_classname.constantize
- reflection = attribute[1].sub(/_id$/, '')
- reflection = reflection.to_sym
- next if !models[attribute_class]
- next if !models[attribute_class][:reflections]
- next if !models[attribute_class][:reflections][reflection]
- next if !models[attribute_class][:reflections][reflection].klass
- attribute_ref_class = models[attribute_class][:reflections][reflection].klass
- if content['value'].class == Array
- content['value'].each {|item_id|
- attribute_object = attribute_ref_class.find_by(id: item_id)
- assets = attribute_object.assets(assets)
- }
- else
- attribute_object = attribute_ref_class.find_by(id: content['value'])
- assets = attribute_object.assets(assets)
- end
- }
- }
- render json: {
- calendar_ids: calendar_ids,
- sla_ids: sla_ids,
- assets: assets,
- }, status: :ok
- end
- def show
- return if deny_if_not_role(Z_ROLENAME_ADMIN)
- model_show_render(Sla, params)
- end
- def create
- return if deny_if_not_role(Z_ROLENAME_ADMIN)
- model_create_render(Sla, params)
- end
- def update
- return if deny_if_not_role(Z_ROLENAME_ADMIN)
- model_update_render(Sla, params)
- end
- def destroy
- return if deny_if_not_role(Z_ROLENAME_ADMIN)
- model_destory_render(Sla, params)
- end
- end
|