-
Notifications
You must be signed in to change notification settings - Fork 655
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8131 from CartoDB/revert-8045-7657-duplicate_maps…
…_with_analyses Revert "Copy visualizations using export/import"
- Loading branch information
Showing
12 changed files
with
287 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# encoding: utf-8 | ||
require 'ostruct' | ||
require_relative './name_generator' | ||
require_relative '../map/copier' | ||
|
||
module CartoDB | ||
module Visualization | ||
# Creates a new visualization using another as source. | ||
# Do NOT use this to create derived visualizations as creates a new map. | ||
class Copier | ||
def initialize(user, visualization, name = nil) | ||
@user = user | ||
@visualization = visualization | ||
@name = name | ||
end | ||
|
||
def copy(overlays = true, layers = true, additional_fields = {}) | ||
member = Member.new( | ||
name: new_name, | ||
tags: visualization.tags, | ||
description: visualization.description, | ||
type: type_from(additional_fields), | ||
parent_id: additional_fields.fetch(:parent_id, nil), | ||
map_id: map_copy(layers).id, | ||
privacy: visualization.privacy, | ||
user_id: @user.id | ||
) | ||
if overlays | ||
overlays_copy(member) | ||
end | ||
member | ||
end | ||
|
||
private | ||
|
||
attr_reader :visualization, :user, :name | ||
|
||
def type_from(fields) | ||
fields.fetch(:type, Member::TYPE_DERIVED) | ||
end | ||
|
||
def overlays_copy(new_visualization) | ||
visualization.overlays.each.map do |overlay| | ||
new_overlay = overlay.dup | ||
new_overlay.visualization_id = new_visualization.id | ||
new_overlay.save | ||
end | ||
end | ||
|
||
def map_copy(layers) | ||
@map_copy ||= CartoDB::Map::Copier.new.copy(visualization.map, layers) | ||
end | ||
|
||
def new_name | ||
@new_name ||= NameGenerator.new(user).name(name || visualization.name) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.