-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexistdb-package-install-action.html
148 lines (125 loc) · 5 KB
/
existdb-package-install-action.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
<!--
`existdb-package-action`
implements an interaction with the package repository
@demo demo/index.html
-->
<dom-module id="existdb-package-install-action">
<template>
<style>
:host {
display: block;
--paper-icon-button: {
color: var(--paper-blue-700);
}
}
</style>
<iron-ajax handle-as="text"
id="installPackage" method="post"
on-error="_handleError" on-response="_handleResponse"
url="../packageservice/packages/action"
verbose
with-credentials></iron-ajax>
<paper-icon-button class="install" icon="file-download" id="install" on-click="submit"
title="download and install latest version"></paper-icon-button>
<form action="" id="installform" is="iron-form" method="post">
<input name="package-url" type="hidden" value="{{url}}"/>
<input name="abbrev" type="hidden" value="{{abbrev}}"/>
<input name="version" type="hidden" value="{{version}}"/>
<input name="action" type="hidden" value="install"/>
<input name="type" type="hidden" value="{{type}}"/>
</form>
</template>
<script>
class ExistdbPackageInstallAction extends Polymer.Element {
static get is() {
return 'existdb-package-install-action';
}
static get properties() {
return {
url: {
type: String,
reflectToAttribute: true
},
abbrev: {
type: String,
reflectToAttribute: true
},
action: {
type: String,
reflectToAttribute: true
},
version: {
type: String,
reflectToAttribute: true
},
type: {
type: String,
reflectToAttribute: true
}
};
}
constructor() {
// console.log('constructor')
super();
}
connectedCallback() {
super.connectedCallback();
// this.$.install.addEventListener('tap', e => this.submit);
this.addEventListener('iron-form-response', e => this.handleResponse);
this.addEventListener('iron-form-error', e => this.handleError);
}
submit(e) {
// console.log("install action submit ",e);
e.stopPropagation();
e.preventDefault();
this.dispatchEvent(new CustomEvent('package-install-started', {
bubbles: true,
composed: true,
detail: {}
}));
}
install() {
/*
console.log('install action install');
console.log('install action install url ', this.url);
console.log('install action install version ', this.version);
*/
this.$.installPackage.params = {
"package-url": this.url,
"action": "install",
"abbrev": this.abbrev,
"version": this.version,
};
this.$.installPackage.generateRequest();
}
_handleResponse(data) {
// console.log("response: ", data);
// console.log("install response: ", JSON.parse(this.$.installPackage.lastResponse).err);
var error = JSON.parse(this.$.installPackage.lastResponse).error;
if (error != undefined) {
this.dispatchEvent(new CustomEvent('package-install-error', {
bubbles: true,
composed: true,
detail: {error: error}
}));
} else {
this.dispatchEvent(new CustomEvent('package-installed', {
bubbles: true,
composed: true,
detail: {abbrev: this.abbrev}
}));
}
}
// this is likely never fired as server responds with a 200 status code always
_handleError(e) {
// console.log("error: ", e)
this.dispatchEvent(new CustomEvent('package-install-error', {
bubbles: true,
composed: true,
detail: {error: e.detail}
}));
}
}
window.customElements.define(ExistdbPackageInstallAction.is, ExistdbPackageInstallAction);
</script>
</dom-module>