-
Notifications
You must be signed in to change notification settings - Fork 1
/
qos-backend-information.html
123 lines (113 loc) · 3.94 KB
/
qos-backend-information.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
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="./../util-precondition/preconditionjs-import.html">
<link rel="import" href="./../util-majax-requests/majax-requests.html">
<script>
'use strict';
/**
* `qos-backend-information`
*
*
* @customElement
* @polymer
* @demo demo/index.html
*/
class QosBackendInformation extends Polymer.Element
{
static get is()
{
return 'qos-backend-information';
}
static get properties()
{
return {
auth: {
type: String,
value: 'Basic YW5vbnltb3VzOm5vcGFzc3dvcmQ='
},
/**
* value: file or directory
* default to file
*/
fileType: {
type: Array,
value: 'file'
},
response: {
type: Array,
notify: true
},
apiEndPoint: {
type: String
}
}
}
ready()
{
super.ready();
this._ensureAttribute('hidden', true);
}
_getSiteBackendCapabilities(urls, headers)
{
precondition.checkArgument(urls !== undefined || urls !== null,
'Property \'urls\' cannot be unspecified.');
precondition.checkArgument(urls.length !== 0,
'Cannot set property \'urls\' to empty array.');
let requestQosInfo = new MultipleAjaxRequests(urls, this, headers);
this.addEventListener('allResolved', e => {
this.response = e.detail.response;
/**
* @event {qos-backend-response}
*/
this.dispatchEvent(new CustomEvent('qos-backend-response', {
bubbles: true,
composed: true,
detail: {response: this.response}
}));
});
requestQosInfo.send();
}
trigger()
{
try {
precondition.checkArgument(this.apiEndPoint !== undefined || this.apiEndPoint !== null,
'Property \'apiEndPoint\' cannot be unspecified.');
let headers = this._computeHeaders(this.auth);
const url = this.apiEndPoint + "qos-management/qos/"+this.fileType;
const xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onload = ()=> {
if (xhr.status >= 200 || xhr.status < 500) {
let urls = [];
const x = JSON.parse(xhr.responseText);
const response = x.name;
for (let i = 0; i < response.length ; i++) {
urls.push(this.apiEndPoint + "qos-management/qos/"+this.fileType+"/" + response[i]);
}
this._getSiteBackendCapabilities(urls, headers);
} else {
new Error("Server Side Error");
}
};
xhr.onerror = function() {
new Error("Network Error");
};
for (let key in headers) {
xhr.setRequestHeader(key, headers[key]);
}
xhr.send();
} catch (e) {
throw new Error(e.message);
}
}
_computeHeaders(auth)
{
return {
"Content-type":"application/json",
"Accept": "application/json",
"Suppress-WWW-Authenticate": "Suppress",
"Authorization": `${auth}`
}
}
}
window.customElements.define(QosBackendInformation.is, QosBackendInformation);
</script>