lib/gooddata/models/metadata/report_definition.rb in gooddata-0.6.11 vs lib/gooddata/models/metadata/report_definition.rb in gooddata-0.6.12

- old
+ new

@@ -42,10 +42,16 @@ 'uri' => attrib.uri } } end + def create_filters_part(filters) + filters.select { |f| f.class == GoodData::Variable }.map do |v| + { expression: "[#{v.uri}]" } + end + end + def create_part(stuff) stuff = Array(stuff) parts = stuff.reduce([]) do |memo, item| if item.respond_to?(:metric?) && item.metric? memo @@ -144,11 +150,10 @@ projectMetadata: project.links['metadata'] } } } uri = "/gdc/app/projects/#{project.pid}/execute" - client.post(uri, data) end # TODO: refactor the method. It should be instance method # Method used for getting a data_result from a wire representation of @@ -168,10 +173,17 @@ else client.create(ReportDataResult, result) end end + # Return true if the report definition is a chart + # + # @return [Boolean] Return true if report definition is a chart + def chart? + !table? + end + def create(options = { :client => GoodData.connection, :project => GoodData.project }) client = options[:client] fail ArgumentError, 'No :client specified' if client.nil? p = options[:project] @@ -180,10 +192,11 @@ project = GoodData::Project[p, options] fail ArgumentError, 'Wrong :project specified' if project.nil? left = Array(options[:left]) top = Array(options[:top]) + filters = options[:filters] || [] left = ReportDefinition.find(left, options) top = ReportDefinition.find(top, options) # TODO: Put somewhere for i18n @@ -202,11 +215,11 @@ 'columns' => ReportDefinition.create_part(top), 'metrics' => ReportDefinition.create_metrics_part(left, top), 'rows' => ReportDefinition.create_part(left) }, 'format' => 'grid', - 'filters' => [] + 'filters' => ReportDefinition.create_filters_part(filters) }, 'meta' => { 'tags' => '', 'summary' => '', 'title' => 'Untitled report definition' @@ -370,8 +383,15 @@ end content['filters'] = filters.map { |filter_expression| { 'expression' => filter_expression.gsub(uri_what, uri_for_what) } } end self + end + + # Return true if the report definition is a table + # + # @return [Boolean] Return true if report definition is a table + def table? + content['format'] == 'grid' end end end