Skip to content

Commit

Permalink
[dashboards] Squashed commits to delete history
Browse files Browse the repository at this point in the history
  • Loading branch information
enbashi committed Feb 1, 2019
1 parent 6f80d64 commit 62fa31e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
10 changes: 4 additions & 6 deletions lib/dogapi/facade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,13 @@ def delete_dashboard(dash_id)
#

# Create a dashboard.
def create_board(title, widgets, description = nil, is_read_only = false, notify_list = nil, template_variables = nil)
@dashboard_service.create_board(title, widgets, description, is_read_only, notify_list, template_variables)
def create_board(title, widgets, layout_type, options= {})
@dashboard_service.create_board(title, widgets, layout_type, options)
end

# Update a dashboard.
def update_board(dashboard_id, title, widgets, description = nil, is_read_only = false, notify_list = nil,
template_variables = nil)
@dashboard_service.update_board(dashboard_id, title, widgets, description, is_read_only, notify_list,
template_variables)
def update_board(dashboard_id, title, widgets, layout_type, options= {})
@dashboard_service.update_board(dashboard_id, title, widgets, layout_type, options)
end

# Fetch the given dashboard.
Expand Down
36 changes: 22 additions & 14 deletions lib/dogapi/v1/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,63 @@ class DashboardService < Dogapi::APIService

# Create new dashboard
#
# Required arguments:
# :title => String: Title of the dashboard
# :widgets => JSON: List of widgets to display on the dashboard
# :layout_type => String: Layout type of the dashboard
# (for now, only "ordered" layout - current timeboard layout - is supported)
# Optional arguments:
# :description => String: Description of the dashboard
# :is_read_only => Boolean: Whether this dashboard is read-only.
# If True, only the author and admins can make changes to it.
# :notify_list => JSON: List of handles of users to notify when changes are made to this dashboard
# e.g. '["[email protected]", "[email protected]"]'
# :template_variables => JSON: List of template variables for this dashboard.
# e.g. [{"name": "host", "prefix": "host", "default": "my-host"}]'
def create_board(title, widgets, description, is_read_only, notify_list, template_variables)
# e.g. [{"name": "host", "prefix": "host", "default": "my-host"}]
def create_board(title, widgets, layout_type, options)
# Required arguments
body = {
title: title,
widgets: widgets,
layout_type: 'ordered'
layout_type: layout_type
}
# Optional arguments
body[:description] = description if description
body[:is_read_only] = is_read_only if is_read_only
body[:notify_list] = notify_list if notify_list
body[:template_variables] = template_variables if template_variables
body[:description] = options[:description] if options[:description]
body[:is_read_only] = options[:is_read_only] if options[:is_read_only]
body[:notify_list] = options[:notify_list] if options[:notify_list]
body[:template_variables] = options[:template_variables] if options[:template_variables]

request(Net::HTTP::Post, "/api/#{API_VERSION}/#{RESOURCE_NAME}", nil, body, true)
end

# Update a dashboard
#
# Required arguments:
# :dashboard_id => String: ID of the dashboard
# :title => String: Title of the dashboard
# :widgets => JSON: List of widgets to display on the dashboard
# :layout_type => String: Layout type of the dashboard
# (for now, only "ordered" layout - current timeboard layout - is supported)
# Optional arguments:
# :description => String: Description of the dashboard
# :is_read_only => Boolean: Whether this dashboard is read-only.
# If True, only the author and admins can make changes to it.
# :notify_list => JSON: List of handles of users to notify when changes are made to this dashboard
# e.g. '["[email protected]", "[email protected]"]'
# :template_variables => JSON: List of template variables for this dashboard.
# e.g. [{"name": "host", "prefix": "host", "default": "my-host"}]'
def update_board(dashboard_id, title, widgets, description, is_read_only, notify_list, template_variables)
# e.g. [{"name": "host", "prefix": "host", "default": "my-host"}]
def update_board(dashboard_id, title, widgets, layout_type, options)
# Required arguments
body = {
title: title,
widgets: widgets,
layout_type: 'ordered'
layout_type: layout_type
}
# Optional arguments
body[:description] = description if description
body[:is_read_only] = is_read_only if is_read_only
body[:notify_list] = notify_list if notify_list
body[:template_variables] = template_variables if template_variables
body[:description] = options[:description] if options[:description]
body[:is_read_only] = options[:is_read_only] if options[:is_read_only]
body[:notify_list] = options[:notify_list] if options[:notify_list]
body[:template_variables] = options[:template_variables] if options[:template_variables]

request(Net::HTTP::Put, "/api/#{API_VERSION}/#{RESOURCE_NAME}/#{dashboard_id}", nil, body, true)
end
Expand Down
12 changes: 8 additions & 4 deletions spec/integration/dashboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@
'default' => 'my-host'
}].freeze

DASHBOARD_PAYLOAD = {
REQUIRED_ARGS = {
title: TITLE,
widgets: WIDGETS,
layout_type: LAYOUT_TYPE,
layout_type: LAYOUT_TYPE
}.freeze

OPTIONS = {
description: DESCRIPTION,
is_read_only: IS_READ_ONLY,
notify_list: NOTIFY_LIST,
template_variables: TEMPLATE_VARIABLES
}.freeze
DASHBOARD_ARGS = DASHBOARD_PAYLOAD.values - [LAYOUT_TYPE]
}
DASHBOARD_ARGS = REQUIRED_ARGS.values + [OPTIONS]
DASHBOARD_PAYLOAD = REQUIRED_ARGS.merge(OPTIONS)

describe '#create_board' do
it_behaves_like 'an api method',
Expand Down

0 comments on commit 62fa31e

Please sign in to comment.