class AccessPointsController < ApplicationController
  before_action :authenticate_user!
  before_action :dashboard_topbar
  skip_load_resource :only => [:change_network]

  def access_point
    @filter = params[:filter]
    unless @current_network.blank?
      routers
    end
  end

  def routers
    @routers = @current_network.router_inventories.includes(:location_network, :associated_radio_profile => [:radio_settings])
    @inventory_up_list = RouterInventory.find_up_list(@routers.pluck(:mac_id), RouterInventory.get_hb_intreval(@current_network.hb_freq))
    @clients_up_list = RouterInventory.find_up_clients(@routers.pluck(:mac_id), @current_network.hb_freq*2)
    @hardware_parts = HardwarePart.all.inject({}) {|h, v| h[v.id] = v.name; h }
  end

  def change_network
    network = current_user.location_networks.find_by_id(params[:id])
    unless network.present?
    network = current_user.location_networks.first
    flash[:notice] = "Your network has been changed to #{network.network_name}"
    end
    current_user.current_network = network.id
    @current_network = current_user.current_network
    logger.info("Current Network in show <<<<<<#{@current_network.id}") unless @current_network.blank?
    routers
    render :action => :access_point
  end
end
