Sha256: 7beb8b5ba346b60ecc17833f0fd7f135fa11f69cbd5779e975f0a1bfba2ed1e2

Contents?: true

Size: 1.8 KB

Versions: 73

Compression:

Stored size: 1.8 KB

Contents

# encoding: UTF-8
#
# Copyright (c) 2010-2017 GoodData Corporation. All rights reserved.
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

require_relative '../rest/resource'

module GoodData
  class StyleSetting < Rest::Resource
    STYLE_SETTING_PATH = '/gdc/projects/%s/styleSettings'

    EMPTY_OBJECT = {
      'styleSettings' => {
        'chartPalette' => []
      }
    }

    attr_reader :colors

    class << self
      def current(opts = { client: GoodData.connection, project: GoodData.project })
        client, project = GoodData.get_client_and_project(opts)
        uri = STYLE_SETTING_PATH % project.pid
        data = client.get(uri)
        client.create(StyleSetting, data)
      end

      def create(colors, opts = { client: GoodData.connection, project: GoodData.project })
        client, project = GoodData.get_client_and_project(opts)
        if colors.is_a?(StyleSetting)
          colors = colors.colors
        else
          colors = colors.uniq
        end
        uri = STYLE_SETTING_PATH % project.pid
        data_to_send = GoodData::Helpers.deep_dup(EMPTY_OBJECT).tap do |d|
          d['styleSettings']['chartPalette'] = colors.map { |color| GoodData::Helpers.stringify_keys(color) }
        end
        style = client.create(StyleSetting, data_to_send)
        client.put(uri, data_to_send)
        style
      end

      def reset(opts = { client: GoodData.connection, project: GoodData.project })
        client, project = GoodData.get_client_and_project(opts)
        uri = STYLE_SETTING_PATH % project.pid
        client.delete(uri)
      end
    end

    def initialize(json)
      super
      @json = json
      @colors = json ? data['chartPalette'] : []
    end

    def empty?
      colors.empty?
    end
  end
end

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
gooddata-2.1.10-java lib/gooddata/models/style_setting.rb
gooddata-2.1.10 lib/gooddata/models/style_setting.rb
gooddata-2.1.9-java lib/gooddata/models/style_setting.rb
gooddata-2.1.9 lib/gooddata/models/style_setting.rb
gooddata-2.1.8-java lib/gooddata/models/style_setting.rb
gooddata-2.1.8 lib/gooddata/models/style_setting.rb
gooddata-2.1.7-java lib/gooddata/models/style_setting.rb
gooddata-2.1.7 lib/gooddata/models/style_setting.rb
gooddata-2.1.6-java lib/gooddata/models/style_setting.rb
gooddata-2.1.6 lib/gooddata/models/style_setting.rb
gooddata-2.1.5-java lib/gooddata/models/style_setting.rb
gooddata-2.1.5 lib/gooddata/models/style_setting.rb
gooddata-2.1.4-java lib/gooddata/models/style_setting.rb
gooddata-2.1.4 lib/gooddata/models/style_setting.rb
gooddata-2.1.3-java lib/gooddata/models/style_setting.rb
gooddata-2.1.3 lib/gooddata/models/style_setting.rb
gooddata-2.1.2-java lib/gooddata/models/style_setting.rb
gooddata-2.1.2 lib/gooddata/models/style_setting.rb
gooddata-2.1.1-java lib/gooddata/models/style_setting.rb
gooddata-2.1.1 lib/gooddata/models/style_setting.rb