diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5d2ca8f..b44bfca 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -11,6 +11,13 @@ class ApplicationController < Sinatra::Base set :port, 4567 end + before do + local_network = LocalNetwork.first + @dark_hex = local_network.primary_dark_hex || "140029" + @light_hex = local_network.primary_light_hex || "8000FF" + @accent_hex = local_network.accent_hex || "2FD400" + end + get '/' do client_ip = request.ip.to_s puts client_ip @@ -37,13 +44,13 @@ class ApplicationController < Sinatra::Base get '/admin/local_network' do @local_network = LocalNetwork.first || LocalNetwork.new - @is_readonly = true + @editing = true erb :'admin/local_network/index' end get '/admin/local_network/edit' do @local_network = LocalNetwork.first || LocalNetwork.create - @is_readonly = false + @editing = false erb :'admin/local_network/index' end @@ -58,13 +65,13 @@ class ApplicationController < Sinatra::Base get '/admin/machines' do @machines = Machine.all - @is_readonly = true + @editing = true erb :'admin/machines/index' end get '/admin/machines/edit' do @machines = Machine.all - @is_readonly = false + @editing = false erb :'admin/machines/index' end @@ -83,37 +90,44 @@ class ApplicationController < Sinatra::Base get '/admin/service_types' do @service_types = ServiceType.all - @is_readonly = true + @editing = true erb :'admin/service_types/index' end get '/admin/service_types/edit' do @service_types = ServiceType.all - @is_readonly = false + @editing = false erb :'admin/service_types/index' end - get '/admin/service_types/media' do - @service_type = ServiceType.media + get '/admin/service_types/:name' do + type_name = params[:name] + @service_type = ServiceType.public_send(type_name) + # @service_type = ServiceType.media erb :'admin/service_types/position' end - get '/admin/service_types/admin' do - @service_type = ServiceType.admin - erb :'admin/service_types/position' - end + # get '/admin/service_types/media' do + # @service_type = ServiceType.media + # erb :'admin/service_types/position' + # end - get '/admin/service_types/support' do - @service_type = ServiceType.support - erb :'admin/service_types/position' - end + # get '/admin/service_types/admin' do + # @service_type = ServiceType.admin + # erb :'admin/service_types/position' + # end + + # get '/admin/service_types/support' do + # @service_type = ServiceType.support + # erb :'admin/service_types/position' + # end post '/admin/service_types' do puts params params[:service_types].each do |service_type_data| if service_type_data[:id].empty? && service_type_data[:name].present? ServiceType.create(service_type_data) - elsif service_type_data[:id].present? + elsif service_type_data[:id].present? && service_type_data[:name].present? @service_type = ServiceType.find(service_type_data[:id]) @service_type.update(service_type_data) end @@ -125,7 +139,7 @@ class ApplicationController < Sinatra::Base @services = Service.all @service_types = ServiceType.all @machines = Machine.all - @is_readonly = true + @editing = true erb :'admin/services/index' end @@ -133,7 +147,7 @@ class ApplicationController < Sinatra::Base @services = Service.all @service_types = ServiceType.all @machines = Machine.all - @is_readonly = false + @editing = false erb :'admin/services/index' end diff --git a/app/views/admin/index.erb b/app/views/admin/index.erb index c9b8881..a7bfa67 100644 --- a/app/views/admin/index.erb +++ b/app/views/admin/index.erb @@ -1,23 +1,28 @@ +