class InternetClassUsers

Allows to edit and add users with regard to InternetClass, so they only can use a certain amount of bytes per day.

TODO: make a working add-button

Public Instance Methods

layout() click to toggle source
# File Views/Internet/ClassUsers.rb, line 9
def layout
  @order = 300
  @update = true

  gui_hbox do
    gui_vbox :nogroup do
      show_str :search_str
      show_entity_person :persons, :single, :login_name, callback: true
      show_button :search #, :add
    end
    gui_vbox :nogroup do
      show_entity_internetClass_empty_all :iclass, :drop, :name
      show_date :start
      show_int :duration
      show_button :save
    end

    gui_window :add_win do
      show_str :add_full_name
      show_str :add_login_name
      show_entity_internetClass_empty_all :add_iclass, :drop, :name
      show_date :add_date
      show_int :add_duration
      show_button :add_user
    end
  end
end
rpc_button_add(session, data) click to toggle source
# File Views/Internet/ClassUsers.rb, line 37
def rpc_button_add(session, data)
  reply(:window_show)
end
rpc_button_save(session, data) click to toggle source
# File Views/Internet/ClassUsers.rb, line 72
def rpc_button_save(session, data)
  ip = InternetPersons.match_by_person(data._persons.person_id) ||
      InternetPersons.create(person: data._persons)
  ip.data_set_hash(data)
  if data._start.to_s == ''
    ip.start = nil
  end
end
rpc_list_choice_persons(session, data) click to toggle source
# File Views/Internet/ClassUsers.rb, line 64
def rpc_list_choice_persons(session, data)
  ret = reply(:empty, %w(start duration)) +
      reply(:update, iclass: [0])
  ip = InternetPersons.match_by_person(data._persons)
  return ret unless ip
  ret + reply(:update, ip.to_hash)
end
rpc_update(session) click to toggle source
# File Views/Internet/ClassUsers.rb, line 41
def rpc_update(session)
  return unless t = Network::Captive.traffic
  list = t.traffic.collect { |h, _k|
    [h, t.get_day(h, 1).inject(:+)]
  }.sort_by { |t| t[1] }.reverse[0..10].
      select{|t| Persons.match_by_login_name(t[0])}.collect { |t|
    p = Persons.match_by_login_name t[0]
    p.to_list_id(session.owner)
  }
  reply(:empty_update, persons: list)
end