zuora_connect_ui 0.10.2 → 0.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b8a9c79d0859807d72b8c481bcd4e60dd45bc51385919cfa26ffb0c15663fe1f
|
|
4
|
+
data.tar.gz: 26ca79e92d1f25230c09266a626d1e19b8f6093924b99932ed88fca7e3ad75a4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 749dc08d67f909d8a573f6120f2eeb09b783909730053896bda3c4288e61b849b0151fbbc4ba0f606726331d5662a008f8fc9c45f4109b01209ed40faab08474
|
|
7
|
+
data.tar.gz: e5ef2639f583a652a2b253c002c0bba7d433db02fbdbb6e81fbfeb88513d370a9fa0b9256632212d04938938a6bf867d4f34944f98a29dacd07c1a13e880eaa2
|
|
@@ -14,6 +14,8 @@ module ZuoraConnectUi
|
|
|
14
14
|
def zuo_include_tag
|
|
15
15
|
script_tag(type: 'module', src: anjuna(ANJUNA_VERSION, true)) +
|
|
16
16
|
script_tag(nomodule: '', src: anjuna(ANJUNA_VERSION, false)) +
|
|
17
|
+
script_tag(type: 'module', src: charts(ANJUNA_VERSION, true)) +
|
|
18
|
+
script_tag(nomodule: '', src: charts(ANJUNA_VERSION, false)) +
|
|
17
19
|
link_tag(href: theme(THEME_VERSION, 'application'), rel: 'stylesheet') +
|
|
18
20
|
link_tag(href: theme(THEME_VERSION, 'theme'), rel: 'stylesheet') +
|
|
19
21
|
link_tag(href: theme(THEME_VERSION, 'icons'), rel: 'stylesheet')
|
|
@@ -30,6 +32,11 @@ module ZuoraConnectUi
|
|
|
30
32
|
"/anjuna-core/anjuna-core#{'.esm' if esm}.js"
|
|
31
33
|
end
|
|
32
34
|
|
|
35
|
+
def charts(version, esm)
|
|
36
|
+
"https://cdn.zuora.com/@anjuna/charts@#{version}" \
|
|
37
|
+
"/anjuna-charts/anjuna-charts#{'.esm' if esm}.js"
|
|
38
|
+
end
|
|
39
|
+
|
|
33
40
|
def link_tag(attrs)
|
|
34
41
|
attr_map = attrs.map { |key, value| " #{key}=\"#{value}\"" }
|
|
35
42
|
|
|
@@ -40,7 +47,7 @@ module ZuoraConnectUi
|
|
|
40
47
|
"https://cdn.zuora.com/@anjuna/theme@#{version}/css/#{file}.css"
|
|
41
48
|
end
|
|
42
49
|
|
|
43
|
-
ANJUNA_VERSION = '1.
|
|
44
|
-
THEME_VERSION = '1.
|
|
50
|
+
ANJUNA_VERSION = '1.2.3'
|
|
51
|
+
THEME_VERSION = '1.2.3'
|
|
45
52
|
end
|
|
46
53
|
end
|
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'active_support/core_ext/string'
|
|
4
|
+
require 'zuora_connect_ui/serializer/relationship'
|
|
5
|
+
|
|
3
6
|
module ZuoraConnectUi
|
|
4
7
|
# Take a resource and dump it to Google Style JSON, really fast
|
|
5
8
|
class Serializer
|
|
6
9
|
def initialize(resource, options = {})
|
|
7
10
|
@resource = resource
|
|
8
11
|
@kind = options[:kind]
|
|
9
|
-
@fields = options[:fields]
|
|
10
12
|
@is_collection = options[:is_collection]
|
|
11
13
|
|
|
14
|
+
@record_type = parse_record_type(@kind, @resource)
|
|
15
|
+
|
|
16
|
+
@associations = parse_associations(
|
|
17
|
+
options[:has_many], options[:belongs_to], options[:has_one]
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
@fields = parse_fields(options[:fields])
|
|
21
|
+
|
|
12
22
|
# TODO: if an attribute given is reserved, throw an error
|
|
13
23
|
end
|
|
14
24
|
|
|
@@ -16,10 +26,10 @@ module ZuoraConnectUi
|
|
|
16
26
|
require 'oj'
|
|
17
27
|
# Enable to show Oj working in console
|
|
18
28
|
# Oj.default_options = { trace: true }
|
|
19
|
-
Oj.dump(
|
|
29
|
+
Oj.dump(serializable_hash, mode: :compat, time_format: :ruby)
|
|
20
30
|
end
|
|
21
31
|
|
|
22
|
-
def
|
|
32
|
+
def serializable_hash
|
|
23
33
|
return hash_for_collection if collection?(@resource)
|
|
24
34
|
|
|
25
35
|
hash_for_one
|
|
@@ -30,27 +40,37 @@ module ZuoraConnectUi
|
|
|
30
40
|
|
|
31
41
|
return hash unless @resource
|
|
32
42
|
|
|
33
|
-
hash[:data] = record_hash(@resource)
|
|
43
|
+
hash[:data] = record_hash(@resource, @record_type)
|
|
44
|
+
|
|
45
|
+
return hash if @associations.empty?
|
|
46
|
+
|
|
47
|
+
hash[:data][:relationships] = @associations.each_with_object({}) do |a, h|
|
|
48
|
+
h[a.plural_type] = a.serialize([@resource], @fields[a.record_type])
|
|
49
|
+
end
|
|
50
|
+
|
|
34
51
|
hash
|
|
35
52
|
end
|
|
36
53
|
|
|
37
54
|
def hash_for_collection
|
|
38
55
|
hash = { data: {} }
|
|
39
56
|
|
|
40
|
-
items = []
|
|
57
|
+
hash[:data][:items] = @resource.each_with_object([]) do |resource, items|
|
|
58
|
+
items << record_hash(resource, @record_type)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
return hash if @associations.empty?
|
|
41
62
|
|
|
42
|
-
@
|
|
43
|
-
|
|
63
|
+
hash[:data][:relationships] = @associations.each_with_object({}) do |a, h|
|
|
64
|
+
h[a.plural_type] = a.serialize(@resource, @fields[a.record_type])
|
|
44
65
|
end
|
|
45
66
|
|
|
46
|
-
hash[:data][:items] = items
|
|
47
67
|
hash
|
|
48
68
|
end
|
|
49
69
|
|
|
50
70
|
private
|
|
51
71
|
|
|
52
72
|
def key_transform(input)
|
|
53
|
-
input.to_s.camelize(:lower)
|
|
73
|
+
input.to_s.camelize(:lower).to_sym
|
|
54
74
|
end
|
|
55
75
|
|
|
56
76
|
def collection?(resource)
|
|
@@ -59,14 +79,55 @@ module ZuoraConnectUi
|
|
|
59
79
|
resource.respond_to?(:size) && !resource.respond_to?(:each_pair)
|
|
60
80
|
end
|
|
61
81
|
|
|
62
|
-
def record_hash(resource)
|
|
63
|
-
hash = {
|
|
64
|
-
|
|
82
|
+
def record_hash(resource, record_type)
|
|
83
|
+
hash = @kind.nil? ? {} : { kind: record_type }
|
|
84
|
+
hash[:id] = resource.id
|
|
85
|
+
@fields[record_type].each do |field|
|
|
86
|
+
hash[key_transform(field)] = resource.public_send(field)
|
|
87
|
+
end
|
|
88
|
+
@associations.each do |association|
|
|
89
|
+
field = association.id_method_name
|
|
65
90
|
hash[key_transform(field)] = resource.public_send(field)
|
|
66
91
|
end
|
|
67
92
|
hash
|
|
68
93
|
end
|
|
69
94
|
|
|
95
|
+
def parse_fields(fields)
|
|
96
|
+
if fields.is_a? Array
|
|
97
|
+
Hash[@record_type, filter_associations(fields)]
|
|
98
|
+
elsif fields.is_a? Hash
|
|
99
|
+
fields[@record_type] = filter_associations(fields[@record_type])
|
|
100
|
+
fields
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def filter_associations(fields)
|
|
105
|
+
fields.select { |field| @associations.none? { |a| a.key == field } }
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def parse_associations(has_many, belongs_to, has_one)
|
|
109
|
+
[
|
|
110
|
+
*(has_many || []).map { |k| create_association(k, :has_many) },
|
|
111
|
+
*(belongs_to || []).map { |k| create_association(k, :belongs_to) },
|
|
112
|
+
*(has_one || []).map { |k| create_association(k, :has_one) }
|
|
113
|
+
]
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def create_association(key, relationship_type)
|
|
117
|
+
Relationship.new(
|
|
118
|
+
key: key_transform(key),
|
|
119
|
+
relationship_type: relationship_type
|
|
120
|
+
)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def parse_record_type(kind, resource)
|
|
124
|
+
return key_transform(kind) if kind
|
|
125
|
+
|
|
126
|
+
return key_transform(resource.class.name) unless collection?(resource)
|
|
127
|
+
|
|
128
|
+
key_transform(resource.first.class.name)
|
|
129
|
+
end
|
|
130
|
+
|
|
70
131
|
# TODO: hold reserved words
|
|
71
132
|
|
|
72
133
|
# see https://google.github.io/styleguide/jsoncstyleguide.xml
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ZuoraConnectUi
|
|
4
|
+
class Serializer
|
|
5
|
+
# The configuration for a relationship between models
|
|
6
|
+
class Relationship
|
|
7
|
+
# key may be plural, record_type will always be singular
|
|
8
|
+
attr_reader :key, :relationship_type, :id_method_name,
|
|
9
|
+
:record_type, :plural_type
|
|
10
|
+
|
|
11
|
+
def initialize(key:, relationship_type:)
|
|
12
|
+
@key = key
|
|
13
|
+
@relationship_type = relationship_type
|
|
14
|
+
|
|
15
|
+
set_id_method_name
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def serialize(resources, fields)
|
|
19
|
+
resources.each_with_object({}) do |resource, hash|
|
|
20
|
+
relations = resource.public_send(key)
|
|
21
|
+
relations = [relations] unless @relationship_type == :has_many
|
|
22
|
+
|
|
23
|
+
relations.each do |relation|
|
|
24
|
+
next if hash.key? relation.id.to_s.to_sym
|
|
25
|
+
|
|
26
|
+
hash[relation.id.to_s.to_sym] = record_hash(relation, fields)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def record_hash(resource, fields)
|
|
34
|
+
hash = { id: resource.id }
|
|
35
|
+
|
|
36
|
+
fields.each do |field|
|
|
37
|
+
hash[key_transform(field)] = resource.public_send(field)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
hash
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def set_id_method_name
|
|
44
|
+
if @relationship_type == :has_many
|
|
45
|
+
singular_key = @key.to_s.singularize
|
|
46
|
+
id_postfix = '_ids'
|
|
47
|
+
else
|
|
48
|
+
singular_key = @key
|
|
49
|
+
id_postfix = '_id'
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
@record_type = singular_key.to_sym
|
|
53
|
+
@plural_type = singular_key.pluralize.to_sym
|
|
54
|
+
@id_method_name = "#{singular_key}#{id_postfix}".to_sym
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def key_transform(input)
|
|
58
|
+
input.to_s.camelize(:lower).to_sym
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zuora_connect_ui
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.10.
|
|
4
|
+
version: 0.10.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Connect Team
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-03-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bootstrap-sass
|
|
@@ -81,33 +81,33 @@ dependencies:
|
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '3.8'
|
|
83
83
|
- !ruby/object:Gem::Dependency
|
|
84
|
-
name:
|
|
84
|
+
name: activesupport
|
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
|
86
86
|
requirements:
|
|
87
|
-
- - "
|
|
87
|
+
- - ">="
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: '
|
|
90
|
-
type: :
|
|
89
|
+
version: '4.2'
|
|
90
|
+
type: :runtime
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
|
-
- - "
|
|
94
|
+
- - ">="
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: '
|
|
96
|
+
version: '4.2'
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
98
|
-
name:
|
|
98
|
+
name: bundler
|
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
|
100
100
|
requirements:
|
|
101
|
-
- - "
|
|
101
|
+
- - ">"
|
|
102
102
|
- !ruby/object:Gem::Version
|
|
103
|
-
version: '
|
|
103
|
+
version: '1.16'
|
|
104
104
|
type: :development
|
|
105
105
|
prerelease: false
|
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
|
107
107
|
requirements:
|
|
108
|
-
- - "
|
|
108
|
+
- - ">"
|
|
109
109
|
- !ruby/object:Gem::Version
|
|
110
|
-
version: '
|
|
110
|
+
version: '1.16'
|
|
111
111
|
- !ruby/object:Gem::Dependency
|
|
112
112
|
name: rspec
|
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -194,6 +194,7 @@ files:
|
|
|
194
194
|
- lib/peek/views/connect.rb
|
|
195
195
|
- lib/zuora_connect_ui.rb
|
|
196
196
|
- lib/zuora_connect_ui/serializer.rb
|
|
197
|
+
- lib/zuora_connect_ui/serializer/relationship.rb
|
|
197
198
|
- lib/zuora_connect_ui/version.rb
|
|
198
199
|
- vendor/assets/anjuna/css/anjuna-icons.css
|
|
199
200
|
- vendor/assets/awesome-bootstrap-checkbox/css/awesome-bootstrap-checkbox.scss
|