Class: MapBackground

Inherits:
Ekylibre::Record::Base show all
Defined in:
app/models/map_background.rb

Overview

Informations

License

Ekylibre - Simple agricultural ERP Copyright (C) 2008-2009 Brice Texier, Thibaud Merigon Copyright (C) 2010-2012 Brice Texier Copyright (C) 2012-2016 Brice Texier, David Joulin

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see www.gnu.org/licenses.

Table: map_backgrounds

attribution    :string
by_default     :boolean          default(FALSE), not null
created_at     :datetime         not null
creator_id     :integer
enabled        :boolean          default(FALSE), not null
id             :integer          not null, primary key
lock_version   :integer          default(0), not null
managed        :boolean          default(FALSE), not null
max_zoom       :integer
min_zoom       :integer
name           :string           not null
reference_name :string
subdomains     :string
tms            :boolean          default(FALSE), not null
updated_at     :datetime         not null
updater_id     :integer
url            :string           not null

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Ekylibre::Record::Base

#already_updated?, attr_readonly_with_conditions, #check_if_destroyable?, #check_if_updateable?, columns_definition, complex_scopes, customizable?, #customizable?, #customized?, #destroyable?, #editable?, has_picture, #human_attribute_name, human_attribute_name_with_id, nomenclature_reflections, #old_record, #others, refers_to, scope_with_registration, simple_scopes, #updateable?

Class Method Details

.load_defaultsObject


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/models/map_background.rb', line 56

def self.load_defaults
  if MapBackgrounds::Layer.items.empty? && Rails.env.development?
    raise 'MapBackground: Layers array is empty.'
  end
  MapBackgrounds::Layer.items.each do |item|
    attrs = {
      name: item.label,
      reference_name: item.reference_name,
      enabled: item.enabled,
      by_default: item.by_default,
      url: item.url,
      attribution: item.options.try(:[], :attribution),
      subdomains: item.options.try(:[], :subdomains),
      min_zoom: item.options.try(:[], :min_zoom),
      max_zoom: item.options.try(:[], :max_zoom),
      managed: true
    }
    where(reference_name: item.reference_name).first_or_create(attrs)
  end

  default = MapBackgrounds::Layer.items.select(&:by_default)

  if default.size >= 1 && default.first.reference_name
    where(reference_name: default.first.reference_name).first.update!(by_default: true)
  end
end

Instance Method Details

#to_json_objectObject


83
84
85
# File 'app/models/map_background.rb', line 83

def to_json_object
  JSON.parse(to_json).compact.select { |_, value| value != '' }.deep_transform_keys { |key| key.to_s.camelize(:lower) }
end