inviton-powerduck 0.0.184 → 0.0.186
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.
- package/common/ajax-xhr.ts +4 -1
- package/common/api-http.ts +8 -0
- package/components/photos/photo-manager.tsx +58 -21
- package/package.json +1 -1
package/common/ajax-xhr.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { AjaxRequestProvider, AjaxRequestProviderRequestArgs, AjaxRequestPr
|
|
|
2
2
|
import { globalState } from '../app/global-state';
|
|
3
3
|
|
|
4
4
|
export class AjaxProviderXhr implements AjaxRequestProvider {
|
|
5
|
-
sendRequest<T>(args: AjaxRequestProviderRequestArgs): Promise<AjaxRequestProviderRequestResponse> {
|
|
5
|
+
sendRequest<T> (args: AjaxRequestProviderRequestArgs): Promise<AjaxRequestProviderRequestResponse> {
|
|
6
6
|
return new Promise((resolve) => {
|
|
7
7
|
const x = new XMLHttpRequest();
|
|
8
8
|
|
|
@@ -11,6 +11,9 @@ export class AjaxProviderXhr implements AjaxRequestProvider {
|
|
|
11
11
|
args.url,
|
|
12
12
|
true,
|
|
13
13
|
);
|
|
14
|
+
|
|
15
|
+
x.withCredentials = args.withCredentials === true;
|
|
16
|
+
|
|
14
17
|
x.onreadystatechange = function () {
|
|
15
18
|
if (x.readyState == 4) {
|
|
16
19
|
let status = x.status;
|
package/common/api-http.ts
CHANGED
|
@@ -47,6 +47,11 @@ export interface AjaxDefinition<T> {
|
|
|
47
47
|
* The type of request to make ("POST" or "GET"), default is "GET". Note: Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers.
|
|
48
48
|
*/
|
|
49
49
|
type?: string;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Determines whether cross-site Access-Control requests should be made using credentials such as cookies.
|
|
53
|
+
*/
|
|
54
|
+
withCredentials?: boolean;
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
export interface AjaxDefinitionWithUrl<T> extends AjaxDefinition<T> {
|
|
@@ -179,6 +184,7 @@ export interface AjaxRequestProviderRequestArgs {
|
|
|
179
184
|
headers: AjaxHeader[];
|
|
180
185
|
timeout: number;
|
|
181
186
|
url: string;
|
|
187
|
+
withCredentials?: boolean;
|
|
182
188
|
}
|
|
183
189
|
|
|
184
190
|
export interface AjaxRequestProviderRequestResponse {
|
|
@@ -223,6 +229,7 @@ export class AppHttpProvider {
|
|
|
223
229
|
blockArgument: null,
|
|
224
230
|
}),
|
|
225
231
|
headers: <Array<AjaxHeader>>[],
|
|
232
|
+
withCredentials: false,
|
|
226
233
|
};
|
|
227
234
|
|
|
228
235
|
static getRequestProvider(): AjaxRequestProvider {
|
|
@@ -414,6 +421,7 @@ export class AppHttpProvider {
|
|
|
414
421
|
query,
|
|
415
422
|
timeout: args.timeout,
|
|
416
423
|
url,
|
|
424
|
+
withCredentials: args.withCredentials ?? this.ajaxDefaults?.withCredentials,
|
|
417
425
|
})
|
|
418
426
|
.then(async (resp) => {
|
|
419
427
|
if (blockUiEnabled) {
|
|
@@ -14,12 +14,52 @@ import FormItemWrapper from '../form/form-item-wrapper';
|
|
|
14
14
|
import NotificationProvider from '../ui/notification';
|
|
15
15
|
|
|
16
16
|
interface PhotoManagerArgs {
|
|
17
|
+
/**
|
|
18
|
+
* The photos to manage
|
|
19
|
+
*/
|
|
17
20
|
photos: Photo[];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Whether to show the upload button
|
|
24
|
+
*/
|
|
18
25
|
showUploadButton?: boolean;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The URL to upload photos to
|
|
29
|
+
*/
|
|
19
30
|
uploadUrl?: string;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The URL where photos are stored
|
|
34
|
+
*/
|
|
20
35
|
photosUrl?: string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Whether at least one photo is mandatory
|
|
39
|
+
*/
|
|
21
40
|
mandatory?: boolean;
|
|
22
|
-
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Key in server response where file data is located after upload
|
|
44
|
+
*/
|
|
45
|
+
responseFileKey?: string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Called when the photo collection has changed
|
|
49
|
+
*/
|
|
50
|
+
changed: (args: PhotoManagerChangedArgs) => void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface PhotoManagerChangedArgs {
|
|
54
|
+
/**
|
|
55
|
+
* The action that occurred
|
|
56
|
+
*/
|
|
57
|
+
action: 'addition' | 'removal';
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The current photos
|
|
61
|
+
*/
|
|
62
|
+
photos: Photo[];
|
|
23
63
|
}
|
|
24
64
|
|
|
25
65
|
class PhotoManagerUberModel extends Photo {
|
|
@@ -28,10 +68,6 @@ class PhotoManagerUberModel extends Photo {
|
|
|
28
68
|
SortOrder: number = null;
|
|
29
69
|
}
|
|
30
70
|
|
|
31
|
-
class TsxComponentExtended<P> extends TsxComponentExtendedBase<P> {
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
71
|
const rootValidations: ValidationRuleset<PhotoManagerComponent> = {
|
|
36
72
|
photos: new ValidationBuilder().customRule('atLeastOnePhoto', function (this: PhotoManagerComponent) {
|
|
37
73
|
if (this.mandatory == true) {
|
|
@@ -43,13 +79,14 @@ const rootValidations: ValidationRuleset<PhotoManagerComponent> = {
|
|
|
43
79
|
};
|
|
44
80
|
|
|
45
81
|
@Component({ validations: rootValidations })
|
|
46
|
-
class PhotoManagerComponent extends
|
|
82
|
+
class PhotoManagerComponent extends TsxComponentExtendedBase<PhotoManagerArgs> implements PhotoManagerArgs {
|
|
47
83
|
@Prop() photos!: Photo[];
|
|
48
84
|
@Prop() mandatory?: boolean;
|
|
49
85
|
@Prop() uploadUrl!: string;
|
|
50
86
|
@Prop() photosUrl!: string;
|
|
51
87
|
@Prop() showUploadButton!: boolean;
|
|
52
|
-
@Prop()
|
|
88
|
+
@Prop() responseFileKey?: string;
|
|
89
|
+
@Prop() changed!: (args: PhotoManagerChangedArgs) => void;
|
|
53
90
|
|
|
54
91
|
translateItems(): DropzoneGalleryItem[] {
|
|
55
92
|
if (isNullOrEmpty(this.photos)) {
|
|
@@ -68,22 +105,16 @@ class PhotoManagerComponent extends TsxComponentExtended<PhotoManagerArgs> imple
|
|
|
68
105
|
}
|
|
69
106
|
|
|
70
107
|
parseServerResponse(resp): DropzoneGalleryItem {
|
|
71
|
-
|
|
72
|
-
|
|
108
|
+
const key = this.responseFileKey || 'fileData';
|
|
109
|
+
if (resp[key] == null) {
|
|
110
|
+
throw new Error(`Invalid server response, missing key ${key}`);
|
|
73
111
|
}
|
|
74
112
|
|
|
75
|
-
const retVal: PhotoManagerUberModel = resp
|
|
76
|
-
retVal.Id =
|
|
77
|
-
retVal.ImageUrl = this.getFullPath(
|
|
113
|
+
const retVal: PhotoManagerUberModel = resp[key];
|
|
114
|
+
retVal.Id = retVal.id;
|
|
115
|
+
retVal.ImageUrl = this.getFullPath(retVal);
|
|
78
116
|
retVal.SortOrder = this.photos.length + 1;
|
|
79
117
|
return retVal;
|
|
80
|
-
// console.log(resp.fileData);
|
|
81
|
-
|
|
82
|
-
// return {
|
|
83
|
-
// Id: resp.fileData.id,
|
|
84
|
-
// ImageUrl: this.getFullPath(resp.fileData),
|
|
85
|
-
// SortOrder: this.photos.length + 1,
|
|
86
|
-
// };
|
|
87
118
|
}
|
|
88
119
|
|
|
89
120
|
render(h) {
|
|
@@ -124,7 +155,10 @@ class PhotoManagerComponent extends TsxComponentExtended<PhotoManagerArgs> imple
|
|
|
124
155
|
}}
|
|
125
156
|
removedFile={(item) => {
|
|
126
157
|
if (this.changed != null) {
|
|
127
|
-
this.changed({
|
|
158
|
+
this.changed({
|
|
159
|
+
action: 'removal',
|
|
160
|
+
photos: this.photos,
|
|
161
|
+
});
|
|
128
162
|
}
|
|
129
163
|
}}
|
|
130
164
|
changed={(items) => {
|
|
@@ -141,7 +175,10 @@ class PhotoManagerComponent extends TsxComponentExtended<PhotoManagerArgs> imple
|
|
|
141
175
|
}
|
|
142
176
|
|
|
143
177
|
if (this.changed != null) {
|
|
144
|
-
this.changed({
|
|
178
|
+
this.changed({
|
|
179
|
+
action: 'addition',
|
|
180
|
+
photos: this.photos,
|
|
181
|
+
});
|
|
145
182
|
}
|
|
146
183
|
}}
|
|
147
184
|
/>
|