Skip to content

Commit 2224604

Browse files
authored
Merge pull request #4168 from 3scale/THREESCALE-9908_usage_rules
♻️🦋 refactor, improve, PF4 and make equal both usage rules pages
2 parents b6884c4 + 24aad23 commit 2224604

18 files changed

Lines changed: 190 additions & 252 deletions

File tree

app/assets/stylesheets/provider/_forms.scss

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ input[type='text']:not(.pf-c-form-control, .pf-c-text-input-group__text-input),
55
input[type='search']:not(.pf-c-form-control),
66
input[type='number'],
77
textarea,
8-
select,
8+
select:not(.pf-c-form-control),
99
form.button-to button:not(.pf-c-button),
1010
form.formtastic:not(.pf-c-form) button:not(.pf-c-button, .btn-add, .btn-danger,
1111
.pf-c-data-list__item-draggable-button, .pf-c-dropdown__toggle-button, .pf-c-dropdown__menu-item),
@@ -208,10 +208,6 @@ form.formtastic:not(.pf-c-form) ol > li {
208208
max-width: line-height-times(32);
209209
position: relative;
210210

211-
&.full-width {
212-
max-width: 100%;
213-
}
214-
215211
&.hidden {
216212
margin: 0;
217213
}
@@ -376,7 +372,7 @@ form.formtastic:not(.pf-c-form) fieldset.inputs label.disabled {
376372
color: $disabled-color;
377373
}
378374

379-
select:disabled,
375+
select:disabled:not(.pf-c-form-control),
380376
form.formtastic:not(.pf-c-form) fieldset.inputs input:disabled,
381377
form.formtastic:not(.pf-c-form) fieldset.inputs input[readonly="readonly"] {
382378
outline: none !important;
@@ -594,7 +590,7 @@ form.formtastic#new_metric {
594590

595591
// HACK: first pf-c-section in a form don't have margin-top. However, formtastic adds hidden fields
596592
// before and therefore the section is not a first element and margin-top is maintained.
597-
.pf-c-form.formtastic > input[type="hidden"] + .pf-c-form__section {
593+
.pf-c-form > input[type="hidden"] + .pf-c-form__section {
598594
margin-top: 0;
599595
}
600596

app/assets/stylesheets/provider/_theme.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
@import 'provider/admin/apiconfig/services/promote_form';
5858
@import 'provider/admin/apiconfig/services/promote_button';
5959
@import 'provider/admin/apiconfig/services/configuration_version';
60-
@import 'provider/sites/usage_rules';
6160
@import 'provider/colorbox';
6261
@import 'provider/pagination';
6362
@import 'provider/print';

app/assets/stylesheets/provider/sites/usage_rules.scss

Lines changed: 0 additions & 20 deletions
This file was deleted.

app/inputs/patternfly_checkbox_input.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
class PatternflyCheckboxInput < Formtastic::Inputs::BooleanInput
44
delegate :tag, to: :template
55

6+
def self.block_compatible?
7+
true
8+
end
9+
610
def to_html
711
tag.div(class: 'pf-c-form__group') do
812
tag.div(class: 'pf-c-form__group-control') do
913
tag.div(class: 'pf-c-check') do
10-
hidden_field_html + input + label + description
14+
content = hidden_field_html + input + label + description
15+
content += template.capture(&options[:block]) if options[:block]
16+
content
1117
end
1218
end
1319
end

app/javascript/packs/provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ document.addEventListener('DOMContentLoaded', () => {
2121
.forEach(form => {
2222
form.addEventListener('change', () => {
2323
if (form.dataset.remote) {
24-
void window.Rails.handleRemote(jQuery1(form))
24+
void window.Rails.handleRemote.call(form, jQuery1(form))
2525
} else {
2626
form.submit()
2727
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
11
@import '~@patternfly/patternfly/components/Table/table.css';
2+
@import '~@patternfly/patternfly/utilities/Spacing/spacing.css';
3+
4+
.use-service-plans,
5+
.use-account-plans {
6+
grid-column: 2;
7+
display: none;
8+
}
9+
10+
#settings_account_plans_ui_visible:checked ~ .use-account-plans,
11+
#settings_service_plans_ui_visible:checked ~ .use-service-plans {
12+
display: block;
13+
}
14+
15+
.pf-c-form + .pf-c-form {
16+
margin-top: var(--pf-global--spacer--xl) !important;
17+
}

app/lib/fields/patternfly_form_builder.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,19 @@ def inputs(*args, &block)
4848
title + template.capture { yield block } # FIXME: Is this making the first render super slow?
4949
end
5050
end
51+
52+
def input(method, options = {}, &block)
53+
if block_given?
54+
input_class = namespaced_input_class(options[:as])
55+
56+
supports_blocks = input_class.respond_to?(:block_compatible?) &&
57+
input_class.block_compatible?
58+
59+
raise ArgumentError, "Input type :#{input_type} does not support blocks" unless supports_blocks
60+
61+
options[:block] = block
62+
end
63+
64+
super(method, options)
65+
end
5166
end

app/lib/logic/plan_changes.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@
2020
module Logic
2121
module PlanChanges
2222

23-
PERMISSIONS = [[ "Request a plan change", :request ],
24-
[ "Change the plan directly", :direct ],
25-
[ "Only request a plan change", :credit_card],
26-
[ "Request Credit Card entry for paid plans", :request_credit_card],
27-
[ "Don't allow plan changes", :none ]]
28-
23+
PERMISSIONS = %i[request direct credit_card request_credit_card none].freeze
2924

3025
module Contract
3126
# Returns true, if +Buyer+ is able to ask for some kind of

app/views/api/services/forms/_usage_rules.html.slim

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 85 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,87 @@
1-
- # TODO: When APIAP is default, adjust the old settings cukes to usage rules
1+
- content_for :title, 'Usage Rules'
22
- content_for :page_header_title, 'Usage Rules'
33

4-
/ TODO: is this ever used? If so, replace with a DefaultPlanSelect (React) and forget about autosubmit
5-
- if (can? :manage, :service_plans) && !current_account.settings.service_plans_ui_visible?
6-
= form_tag polymorphic_path([:masterize, :admin, @service, ServicePlan]), :method => :post, :class => 'service autosubmit formtastic', :remote => true do
7-
fieldset.inputs
8-
legend Default Service Plan
9-
ol
10-
li.string.optional
11-
label for="default_plan" Default plan
12-
- service_plans_exists = @service.service_plans.exists?
13-
= select_tag :id, options_from_collection_for_select(@service.service_plans.not_custom, "id", "name", lambda { |p| p.master? }),
14-
:include_blank => true, :id => "default_plan", disabled: !service_plans_exists
15-
- if service_plans_exists
16-
p.inline-hints= @service.service_plans.first.class.human_attribute_name 'default_plan_hint'
17-
- else
18-
p.inline-hints Please create a service plan first.
19-
20-
= semantic_form_for @service, :url => admin_service_path(@service) do |form|
21-
= render :partial => 'api/services/forms/usage_rules', :locals => { :form => form }
22-
= form.actions do
23-
= form.commit_button 'Update Product'
4+
- content_for :javascripts do
5+
= stylesheet_packs_chunks_tag 'pf_form', 'usage_rules'
6+
7+
div class="pf-c-card"
8+
div class="pf-c-card__body"
9+
/ TODO: THREESCALE-12093: remove autosubmit
10+
- if (can? :manage, :service_plans) && !current_account.settings.service_plans_ui_visible? || true
11+
= form_tag polymorphic_path([:masterize, :admin, @service, ServicePlan]), method: :post,
12+
class: 'autosubmit pf-c-form pf-m-limit-width',
13+
remote: true
14+
section class="pf-c-form__section" role="group" aria-labelledby="settings-section-users"
15+
div class="pf-c-form__section-title" id="settings-section-users" aria-hidden="true" Default service plan
16+
div class="pf-c-form__group"
17+
div class="pf-c-form__group-control"
18+
- service_plans_exists = @service.service_plans.exists?
19+
= select_tag :id, options_from_collection_for_select(@service.service_plans.not_custom, "id", "name", lambda { |p| p.master? }),
20+
prompt: '',
21+
class: "pf-c-form-control #{'pf-m-warning' unless service_plans_exists}",
22+
id: 'default_plan',
23+
disabled: !service_plans_exists
24+
- if service_plans_exists
25+
p class="pf-c-form__helper-text"
26+
= @service.service_plans.first.class.human_attribute_name('default_plan_hint')
27+
- else
28+
p class="pf-c-form__helper-text pf-m-warning"
29+
| Please create a service plan first
30+
31+
= semantic_form_for @service, url: admin_service_path(@service),
32+
builder: Fields::PatternflyFormBuilder,
33+
html: { class: "pf-c-form pf-m-limit-width" } do |form|
34+
- multiple_applications = current_account.multiple_applications_allowed? && false
35+
= form.inputs multiple_applications ? 'Application Requirements' : 'Signup & Use' do
36+
/ very old TODO: remove intentions_required and make it an extra_field? Or how about just remove it?
37+
- unless multiple_applications
38+
= form.input :intentions_required, as: :patternfly_checkbox
39+
40+
= form.input :buyers_manage_apps, as: :patternfly_checkbox
41+
42+
- if @service.backend_version.v2?
43+
= form.input :buyers_manage_keys, as: :patternfly_checkbox
44+
= form.input :mandatory_app_key, as: :patternfly_checkbox
45+
46+
- if @service.oauth?
47+
= form.input :buyer_key_regenerate_enabled, as: :patternfly_checkbox
48+
49+
= form.input :referrer_filters_required, as: :patternfly_checkbox
50+
= form.input :custom_keys_enabled, as: :patternfly_checkbox
51+
52+
= form.inputs "Application Plans" do
53+
= form.input :buyer_can_select_plan, as: :patternfly_checkbox
54+
55+
= form.inputs "Application Plan Changing" do
56+
p = t('sites.usage_rules.edit.plans_info')
57+
div class="pf-c-form__group" role="radiogroup" aria-labelledby="change-plan-radio-group"
58+
div class="pf-c-form__group-label" id="change-plan-radio-group"
59+
label class="pf-c-form__label"
60+
span class="pf-c-form__label-text"
61+
= t('sites.usage_rules.edit.plans_label')
62+
= render 'shared/plan_change_settings', setting: :buyer_plan_change_permission,
63+
current: @service.buyer_plan_change_permission.to_sym
64+
65+
= form.inputs 'Alerts' do
66+
div class="pf-c-content"
67+
p
68+
' Here you can set at which utilization levels you want to trigger alerts, whom you want to send these alerts to (admins and/or developers) and by which means (web and/or email).
69+
em In order for an application to trigger usage alerts, usage limit(s) need to be set up in the Application Plan to which the application is subscribed.
70+
71+
table class="pf-c-table pf-m-grid-lg" role="grid"
72+
thead
73+
tr role="row"
74+
th
75+
- alert_limits.each do |level|
76+
th role="columnheader" scope="col"
77+
= level
78+
| %
79+
80+
tbody
81+
= row_for_alert_levels 'Show Web Alerts to Admins of this Account', :web_provider
82+
= row_for_alert_levels 'Send Email Alerts to Admins of this Account', :email_provider
83+
= row_for_alert_levels 'Show Web Alerts to Admins of the Developer Account', :web_buyer
84+
= row_for_alert_levels 'Send Email Alerts to Admins of the Developer Account', :email_buyer
85+
86+
= form.actions do
87+
= form.commit_button 'Update product'

0 commit comments

Comments
 (0)