quasar-ui-danx 0.3.47 → 0.3.48

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.
@@ -1,50 +1,56 @@
1
1
  import { ref, Ref } from "vue";
2
2
 
3
3
  interface RequestOptions {
4
- baseUrl: string;
4
+ baseUrl: string;
5
5
  }
6
6
 
7
7
  const requestOptions: Ref<RequestOptions> = ref({
8
- baseUrl: ""
8
+ baseUrl: ""
9
9
  });
10
10
  /**
11
11
  * A simple request helper that wraps the fetch API
12
12
  * to make GET and POST requests easier w/ JSON payloads
13
13
  */
14
14
  export const request = {
15
- configure(options: RequestOptions) {
16
- requestOptions.value = options;
17
- },
15
+ configure(options: RequestOptions) {
16
+ requestOptions.value = options;
17
+ },
18
18
 
19
- url(url: string) {
20
- if (url.startsWith("http")) {
21
- return url;
22
- }
23
- return requestOptions.value.baseUrl + url;
24
- },
19
+ url(url: string) {
20
+ if (url.startsWith("http")) {
21
+ return url;
22
+ }
23
+ return requestOptions.value.baseUrl + url;
24
+ },
25
25
 
26
- async get(url: string, options = {}): Promise<object> {
27
- return fetch(request.url(url), {
28
- method: "get",
29
- headers: {
30
- Accept: "application/json",
31
- "Content-Type": "application/json"
32
- },
33
- ...options
34
- }).then((r) => r.json());
35
- },
26
+ async get(url: string, options = {}): Promise<object> {
27
+ return fetch(request.url(url), {
28
+ method: "get",
29
+ headers: {
30
+ Accept: "application/json",
31
+ "Content-Type": "application/json"
32
+ },
33
+ ...options
34
+ }).then((r) => r.json());
35
+ },
36
36
 
37
- async post(url: string, data = {}, options = {}) {
38
- return fetch(request.url(url), {
39
- method: "post",
40
- body: JSON.stringify(data),
41
- headers: {
42
- Accept: "application/json",
43
- "Content-Type": "application/json"
44
- },
45
- ...options
46
- }).then((r) => r.json());
47
- }
37
+ async post(url: string, data = {}, options = {}) {
38
+ let body = "";
39
+ try {
40
+ body = JSON.stringify(data);
41
+ } catch (e) {
42
+ // fail silently
43
+ }
44
+ return fetch(request.url(url), {
45
+ method: "post",
46
+ body,
47
+ headers: {
48
+ Accept: "application/json",
49
+ "Content-Type": "application/json"
50
+ },
51
+ ...options
52
+ }).then((r) => r.json());
53
+ }
48
54
  };
49
55
 
50
56
  /**
@@ -55,25 +61,25 @@ export const request = {
55
61
  *
56
62
  */
57
63
  export async function fetchResourceListWithSelected(fetchFn: (filter: object) => Promise<any[]>, list: Ref, id: string, filter: object): Promise<void> {
58
- // First make sure we have the selected record, so we can always add it to the list
59
- let selectedResource;
60
- if (id) {
61
- selectedResource = list.value.find((c: { id: string }) => c.id === id) || (await fetchFn({ id }))[0];
62
- }
64
+ // First make sure we have the selected record, so we can always add it to the list
65
+ let selectedResource;
66
+ if (id) {
67
+ selectedResource = list.value.find((c: { id: string }) => c.id === id) || (await fetchFn({ id }))[0];
68
+ }
63
69
 
64
- // Get the filtered campaign list
65
- list.value = await fetchFn(filter);
70
+ // Get the filtered campaign list
71
+ list.value = await fetchFn(filter);
66
72
 
67
- // If our selected campaign is not in the filtered list, add it
68
- if (selectedResource && !list.value.find((c: { id: string }) => c.id === id)) {
69
- list.value.push(selectedResource);
70
- }
73
+ // If our selected campaign is not in the filtered list, add it
74
+ if (selectedResource && !list.value.find((c: { id: string }) => c.id === id)) {
75
+ list.value.push(selectedResource);
76
+ }
71
77
  }
72
78
 
73
79
  /**
74
80
  * Returns the value of the URL parameter (if it is set)
75
81
  */
76
82
  export function getUrlParam(key: string, url?: string) {
77
- const params = new URLSearchParams(url?.replace(/.*\?/, "") || window.location.search);
78
- return params.get(key);
83
+ const params = new URLSearchParams(url?.replace(/.*\?/, "") || window.location.search);
84
+ return params.get(key);
79
85
  }