-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigurator.html
267 lines (234 loc) · 10.6 KB
/
configurator.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<style>
html,
body {
height: 100%;
width: 100%;
}
</style>
<title>DV360 configurator</title>
</head>
<body>
<div data-bind="template: 'master'" class="container vh-100">
Loading...
</div>
<script type="text/html" id="partner">
</script>
<script type="text/html" id="master">
<header>
<h1>DV360 proxy configurator</h1>
<div class="alert alert-dark" role="alert">
<p>This page allow to generate configuration object for DV360 proxy. This page <strong>is not
synchronized</strong> with
function's configuration. You can paste current configuration to the right field. Once you done with editing,
you need to function's env variables manually using gloud CLI <a
href="https://github.com/audienceproject/dv360proxy-gcc#configuration">the guide</a>
</p>
<p>List of available metrics for blacklist can be found at <a
href="https://developers.google.com/bid-manager/v1.1/filters-metrics">https://developers.google.com/bid-manager/v1.1/filters-metrics</a>
</p>
</div>
</header>
<section style="width: 48%; float: left;" data-bind="with: config">
<div data-bind="foreach: partners">
<div class="card mb-3">
<div class="card-header">
<label class="label">Partner ID <input type="number" data-bind="textInput: id"
class="form-control" /></label>
<button type="button" class="btn btn-danger float-right btn-sm"
data-bind="click: $parent.deletePartner">x</button>
</div>
<div class="card-body">
<table class="table table-sm">
<thead>
<tr>
<th>Advertiser ID</th>
<th><abbr data-toggle="tooltip" title="Denies access to the cost data">Deny
cost</abbr></th>
<th><abbr data-toggle="tooltip" title="Additional blacklisted metrics">Additional
blacklist</abbr>
</th>
<th></th>
</tr>
</thead>
<tbody data-bind="foreach: advertisers">
<tr>
<td>
<input type="number" data-bind="textInput: id"
class="form-control form-control-sm" size="8" />
</td>
<td>
<div class="form-check">
<input type="checkbox" data-bind="checked: costsMetricsDenied" />
</div>
</td>
<td style="text-align: center">
<input type="text" class="form-control form-control-sm"
data-bind="textInput: blacklistCSV" />
</td>
<td>
<button type="button" class="btn btn-danger btn-sm"
data-bind="click: $parent.removeAdvertiser">x</button>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4">
<button type="button" class="btn btn-success btn-sm"
data-bind="click: addNewAdvertiser">Add advertiser</button>
</td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
<button type="button" class="btn btn-success" data-bind="click: addNewPartner">Add partner</button>
</section>
<section style="width: 48%; float: right;">
<textarea class="form-control mb-3" style="width: 100%; min-height: 600px; font-family: monospace;"
data-bind="textInput: json"></textarea>
<a class="btn btn-success" download="env.yaml" data-bind="attr: { href: 'data:text/yaml;charset=utf-8,' + encodeURIComponent(yaml()) }">Download</a>
</section>
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.5.0/knockout-min.js">
</script>
<script>
function AdvertiserViewModel(advertiser) {
var self = this;
if (!advertiser) {
advertiser = {
id: null,
blacklistMetrics: ["_FEE_", "_COST_"]
}
}
self.id = ko.observable(advertiser.id);
self.blacklistMetrics = ko.observableArray(advertiser.blacklistMetrics);
self.costsMetricsDenied = ko.computed({
read: function () {
return self.blacklistMetrics.indexOf("_FEE_") > -1 && self.blacklistMetrics.indexOf(
"_COST_") > -1;
},
write: function (value) {
if (value) {
if (self.blacklistMetrics.indexOf("_FEE_") === -1) {
self.blacklistMetrics.push("_FEE_");
}
if (self.blacklistMetrics.indexOf("_COST_") === -1) {
self.blacklistMetrics.push("_COST_");
}
} else {
self.blacklistMetrics.removeAll(["_FEE_", "_COST_"]);
}
}
});
self.blacklistCSV = ko.computed({
read: function () {
var blacklist = self.blacklistMetrics();
// If cost metrics are denied, not need to show them in additional blacklist fields
if (self.costsMetricsDenied()) {
blacklist = blacklist.filter(function (f) {
return f !== "_FEE_" && f !== "_COST_";
})
}
return blacklist.join(', ');
},
write: function (value) {
if (!value) {
value = "";
}
var blacklist = value.split('/').map(function (f) {
return f.trim();
});
if (self.costsMetricsDenied()) {
blacklist.push("_FEE_");
blacklist.push("_COST_");
}
self.blacklistMetrics(blacklist);
}
})
}
AdvertiserViewModel.prototype.toJSON = function () {
var copy = ko.toJS(this);
delete copy.costsMetricsDenied;
delete copy.blacklistCSV;
return copy;
};
function PartnerViewModel(partner) {
var self = this;
if (!partner) {
partner = {
id: null,
advertisers: [null]
}
}
self.id = ko.observable(partner.id);
self.advertisers = ko.observableArray(partner.advertisers.map(function (advertiser) {
return new AdvertiserViewModel(advertiser)
}));
self.addNewAdvertiser = function () {
self.advertisers.push(new AdvertiserViewModel())
}
self.removeAdvertiser = function (advertiser) {
self.advertisers.remove(advertiser);
}
}
function ConfigViewModel(config) {
var self = this;
self.partners = ko.observableArray(config.partners.map(function (partner) {
return new PartnerViewModel(partner)
}));
self.addNewPartner = function () {
self.partners.push(new PartnerViewModel());
}
self.deletePartner = function (partner) {
self.partners.remove(partner);
}
}
var RootViewModel = function (initialConfiguration) {
initialConfiguration = initialConfiguration || {
partners: [null]
};
var self = this;
self.config = ko.observable(new ConfigViewModel(initialConfiguration));
self.json = ko.computed({
read: function () {
return ko.toJSON(self.config, null, 2);
},
write: function (value) {
try {
var config = JSON.parse(value);
console.log("Processed input", config);
self.config(new ConfigViewModel(config));
} catch (err) {
console.log("Malformed JSON", value, err)
}
}
});
self.yaml = ko.computed(function() {
return "DV360_PROXY_CONFIG: |\n " + ko.toJSON(self.config);
})
self.json.subscribe(function (json) {
localStorage.setItem("dv360proxy.config", json);
});
};
var config = null;
var lastConig = localStorage.getItem("dv360proxy.config");
if (lastConig) {
try {
var config = JSON.parse(lastConig);
} catch (err) {
}
}
ko.applyBindings(new RootViewModel(config));
</script>
</body>
</html>