cartodb-4.42/app/models/carto/layer_node_style.rb

24 lines
764 B
Ruby
Raw Normal View History

2024-04-06 13:25:13 +08:00
require_dependency 'carto/carto_json_serializer'
module Carto
class LayerNodeStyle < ActiveRecord::Base
belongs_to :layer
serialize :options, CartoJsonSymbolizerSerializer
serialize :infowindow, CartoJsonSymbolizerSerializer
serialize :tooltip, CartoJsonSymbolizerSerializer
OPTIONS_TO_COPY = [:sql_wrap, :style_properties, :tile_style].freeze
def self.from_visualization_and_source(visualization, source_id)
Carto::LayerNodeStyle.where(layer_id: visualization.data_layers.map(&:id), source_id: source_id)
end
def update_from_layer(layer)
self.infowindow = layer.infowindow || {}
self.tooltip = layer.tooltip || {}
self.options = layer.options.symbolize_keys.slice(*OPTIONS_TO_COPY)
end
end
end