@quandis/qbo4.ui 4.0.1-CI-20241021-180407 → 4.0.1-CI-20241022-165449

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "Quandis, Inc.",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
- "version": "4.0.1-CI-20241021-180407",
6
+ "version": "4.0.1-CI-20241022-165449",
7
7
  "workspaces": [
8
8
  "code"
9
9
  ],
package/scss/qboui.scss CHANGED
@@ -78,6 +78,20 @@
78
78
  @extend .active;
79
79
  }
80
80
 
81
+ li.pageSize {
82
+ @extend .input-group;
83
+ @extend .w-auto;
84
+
85
+ input {
86
+ @extend .form-control;
87
+ width: 5em;
88
+ }
89
+
90
+ span {
91
+ @extend .input-group-text;
92
+ }
93
+ }
94
+
81
95
  &.center {
82
96
  @extend .justify-content-center;
83
97
  }
@@ -19,8 +19,15 @@ export class RestApiService {
19
19
  headers: headers,
20
20
  body: (method === 'POST' && payload) ? JSON.stringify(payload) : null
21
21
  });
22
- if (response.ok)
23
- return response.json();
22
+ const accept = headers.get("Accept") ?? '';
23
+ if (response.ok) {
24
+ switch (accept) {
25
+ case "application/json":
26
+ return await response.json();
27
+ default:
28
+ return await response.text();
29
+ }
30
+ }
24
31
  console.error(`API request failed with status ${response.status}`);
25
32
  return null;
26
33
  }
@@ -28,9 +28,15 @@ export class RestApiService implements IApiService {
28
28
  headers: headers,
29
29
  body: (method === 'POST' && payload) ? JSON.stringify(payload) : null
30
30
  });
31
-
32
- if (response.ok)
33
- return response.json();
31
+ const accept = headers.get("Accept") ?? '';
32
+ if (response.ok) {
33
+ switch (accept) {
34
+ case "application/json":
35
+ return await response.json();
36
+ default:
37
+ return await response.text();
38
+ }
39
+ }
34
40
  console.error(`API request failed with status ${response.status}`);
35
41
  return null;
36
42
  }
@@ -9,6 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  };
10
10
  import { LitElement } from 'lit';
11
11
  import { property } from 'lit/decorators.js';
12
+ import { getApiService } from './RestApiService.js';
12
13
  export const QboFetchMixin = (superClass) => {
13
14
  class QboFetchClass extends superClass {
14
15
  constructor(...args) {
@@ -21,13 +22,15 @@ export const QboFetchMixin = (superClass) => {
21
22
  this.headerTag = 'script[name="headers"]';
22
23
  this.html = null;
23
24
  this.fetchOnLoad = true;
25
+ this.headers = null;
26
+ this.payload = null;
24
27
  }
25
28
  async connectedCallback() {
26
29
  super.connectedCallback();
27
30
  if (this.fetchOnLoad) {
28
- const headers = this.getHeaders();
29
- const payload = this.getPayload(headers);
30
- await this.fetchData(headers, payload);
31
+ this.headers = this.headers ?? this.getHeaders();
32
+ this.payload = this.payload ?? this.getPayload(this.headers);
33
+ await this.fetchData(this.headers, this.payload);
31
34
  }
32
35
  }
33
36
  getHeaders() {
@@ -65,18 +68,20 @@ export const QboFetchMixin = (superClass) => {
65
68
  if (payload !== null)
66
69
  this.method = 'POST';
67
70
  try {
68
- const response = await fetch(this.apiEndpoint, {
69
- method: this.method,
70
- headers: headers,
71
- body: payload ? JSON.stringify(payload) : null
72
- });
71
+ const api = getApiService(this.apiEndpoint);
72
+ const response = await api.fetch(null, payload);
73
+ //const response = await fetch(this.apiEndpoint, {
74
+ // method: this.method,
75
+ // headers: headers,
76
+ // body: payload ? JSON.stringify(payload) : null
77
+ //});
73
78
  switch (this.accept) {
74
79
  case "application/json":
75
- this.jsonData = await response.json();
80
+ this.jsonData = response;
76
81
  this.html = null;
77
82
  break;
78
83
  default:
79
- this.html = await response.text();
84
+ this.html = response;
80
85
  this.jsonData = null;
81
86
  break;
82
87
  }
@@ -120,6 +125,14 @@ export const QboFetchMixin = (superClass) => {
120
125
  property({ type: Boolean }),
121
126
  __metadata("design:type", Object)
122
127
  ], QboFetchClass.prototype, "fetchOnLoad", void 0);
128
+ __decorate([
129
+ property({ attribute: false }),
130
+ __metadata("design:type", Object)
131
+ ], QboFetchClass.prototype, "headers", void 0);
132
+ __decorate([
133
+ property({ attribute: false }),
134
+ __metadata("design:type", Object)
135
+ ], QboFetchClass.prototype, "payload", void 0);
123
136
  ;
124
137
  return QboFetchClass;
125
138
  };
@@ -1,5 +1,6 @@
1
1
  import { LitElement } from 'lit';
2
2
  import { property } from 'lit/decorators.js';
3
+ import { getApiService } from './RestApiService.js';
3
4
 
4
5
  // Define the interface for the mixin
5
6
  export declare class IFetch {
@@ -11,7 +12,6 @@ export declare class IFetch {
11
12
  protected fetchData(headers: { [key: string]: string; }, payload: Object | null): Promise<void>;
12
13
  protected getPayload(headers: { [key: string]: string; });
13
14
  protected getHeaders(): { [key: string]: string };
14
- // protected createRenderRoot(): unknown;
15
15
  }
16
16
 
17
17
  type Constructor<T = {}> = new (...args: any[]) => T;
@@ -42,6 +42,12 @@ export const QboFetchMixin = <T extends Constructor<LitElement>>(superClass: T)
42
42
  @property({ type: Boolean })
43
43
  fetchOnLoad = true;
44
44
 
45
+ @property({ attribute: false })
46
+ headers: { [key: string]: string } | null = null;
47
+
48
+ @property({ attribute: false })
49
+ payload: Record<string, string> | null = null;
50
+
45
51
  constructor(...args: any[]) {
46
52
  super(...args);
47
53
  }
@@ -50,9 +56,9 @@ export const QboFetchMixin = <T extends Constructor<LitElement>>(superClass: T)
50
56
  super.connectedCallback();
51
57
 
52
58
  if (this.fetchOnLoad) {
53
- const headers = this.getHeaders();
54
- const payload = this.getPayload(headers);
55
- await this.fetchData(headers, payload);
59
+ this.headers = this.headers ?? this.getHeaders();
60
+ this.payload = this.payload ?? this.getPayload(this.headers);
61
+ await this.fetchData(this.headers, this.payload);
56
62
  }
57
63
  }
58
64
 
@@ -71,7 +77,7 @@ export const QboFetchMixin = <T extends Constructor<LitElement>>(superClass: T)
71
77
 
72
78
  getPayload(headers: { [key: string]: string; }) {
73
79
  const payloadTag = this.querySelector('script[name="payload"]');
74
- let payload: Object | null = null;
80
+ let payload: Record<string, string> | null = null;
75
81
  if (payloadTag && payloadTag.textContent !== null) {
76
82
  try {
77
83
  payload = JSON.parse(payloadTag.textContent);
@@ -85,23 +91,26 @@ export const QboFetchMixin = <T extends Constructor<LitElement>>(superClass: T)
85
91
  }
86
92
 
87
93
  /* @description Fetch data from an api, and set @see {@link html} or @see {@link jsonData} with the result. */
88
- async fetchData(headers: { [key: string]: string; }, payload: Object | null) {
94
+ async fetchData(headers: { [key: string]: string; }, payload: Record<string, string> | null) {
89
95
  if (this.apiEndpoint === null) return;
90
96
  if (payload !== null)
91
97
  this.method = 'POST';
92
98
  try {
93
- const response = await fetch(this.apiEndpoint, {
94
- method: this.method,
95
- headers: headers,
96
- body: payload ? JSON.stringify(payload) : null
97
- });
99
+
100
+ const api = getApiService(this.apiEndpoint);
101
+ const response = await api.fetch(null, payload);
102
+ //const response = await fetch(this.apiEndpoint, {
103
+ // method: this.method,
104
+ // headers: headers,
105
+ // body: payload ? JSON.stringify(payload) : null
106
+ //});
98
107
  switch (this.accept) {
99
108
  case "application/json":
100
- this.jsonData = await response.json();
109
+ this.jsonData = response;
101
110
  this.html = null;
102
111
  break;
103
112
  default:
104
- this.html = await response.text();
113
+ this.html = response;
105
114
  this.jsonData = null;
106
115
  break;
107
116
  }
@@ -6,11 +6,14 @@ export declare class QboPaginate extends LitElement {
6
6
  pageLimit: number;
7
7
  currentPage: number;
8
8
  rollingView: boolean;
9
+ editSize: boolean;
9
10
  private get maxPage();
10
11
  static styles: import("lit").CSSResult[];
11
12
  goToPage(page: any): void;
12
13
  renderPage(i: number): TemplateResult<1>;
13
14
  renderSpacer(): TemplateResult<1>;
14
15
  renderPageNumbers(): TemplateResult[];
16
+ setDisplaySize(e: Event): void;
17
+ renderPageSize(): TemplateResult<1>;
15
18
  render(): TemplateResult<1>;
16
19
  }
@@ -19,6 +19,7 @@ let QboPaginate = class QboPaginate extends LitElement {
19
19
  this.pageLimit = 10;
20
20
  this.currentPage = 1;
21
21
  this.rollingView = true;
22
+ this.editSize = true;
22
23
  }
23
24
  get maxPage() {
24
25
  return Math.floor(this.count / this.display) + (this.count % this.display === 0 ? 0 : 1);
@@ -37,8 +38,8 @@ let QboPaginate = class QboPaginate extends LitElement {
37
38
  }));
38
39
  }
39
40
  renderPage(i) {
40
- return html `<li class="page-item ${this.currentPage === i ? 'active' : ''}">
41
- <a class="page-link" @click="${() => this.goToPage(i)}">${i}</a>
41
+ return html `<li class="${this.currentPage === i ? 'active' : ''}">
42
+ <a @click="${(e) => this.goToPage(i)}">${i}</a>
42
43
  </li>`;
43
44
  }
44
45
  renderSpacer() {
@@ -69,21 +70,37 @@ let QboPaginate = class QboPaginate extends LitElement {
69
70
  }
70
71
  return pages;
71
72
  }
73
+ setDisplaySize(e) {
74
+ const target = e.target;
75
+ const display = parseInt(target.value);
76
+ if (!isNaN(display)) {
77
+ this.display = display;
78
+ this.start = 0;
79
+ this.goToPage(1);
80
+ }
81
+ }
82
+ renderPageSize() {
83
+ return html `<li class="pageSize">
84
+ <input type="number" min="5" value="${this.display}" title="Display Size" @change=${(e) => this.setDisplaySize(e)}>
85
+ <span>records per page</span>
86
+ </li>`;
87
+ }
72
88
  render() {
73
89
  return html `
74
90
  <nav aria-label="Page navigation">
75
- <ul class="qbo-paginate paginate">
76
- <li class="page-item ${this.currentPage === 1 ? 'disabled' : ''}">
77
- <a class="page-link" aria-label="Previous" @click="${this.goToPage(this.currentPage--)}">
91
+ <ul class="qbo-paginate">
92
+ <li class="${this.currentPage === 1 ? 'disabled' : ''}">
93
+ <a aria-label="Previous" @click="${(e) => this.goToPage(this.currentPage--)}">
78
94
  <span aria-hidden="true">&laquo;</span>
79
95
  </a>
80
96
  </li>
81
97
  ${this.renderPageNumbers()}
82
- <li class="page-item ${this.currentPage === this.maxPage ? 'disabled' : ''}">
83
- <a class="page-link" aria-label="Next" @click="${this.goToPage(this.currentPage++)}">
98
+ <li class="${this.currentPage === this.maxPage ? 'disabled' : ''}">
99
+ <a aria-label="Next" @click="${(e) => this.goToPage(this.currentPage++)}">
84
100
  <span aria-hidden="true">&raquo;</span>
85
101
  </a>
86
102
  </li>
103
+ ${this.editSize ? this.renderPageSize() : html ``}
87
104
  </ul>
88
105
  </nav>`;
89
106
  }
@@ -112,6 +129,10 @@ __decorate([
112
129
  property({ type: Boolean }),
113
130
  __metadata("design:type", Object)
114
131
  ], QboPaginate.prototype, "rollingView", void 0);
132
+ __decorate([
133
+ property({ type: Boolean }),
134
+ __metadata("design:type", Object)
135
+ ], QboPaginate.prototype, "editSize", void 0);
115
136
  QboPaginate = __decorate([
116
137
  customElement('qbo-paginate')
117
138
  ], QboPaginate);
@@ -22,6 +22,9 @@ export class QboPaginate extends LitElement {
22
22
  @property({ type: Boolean })
23
23
  rollingView = true;
24
24
 
25
+ @property({ type: Boolean })
26
+ editSize = true;
27
+
25
28
  private get maxPage(): number {
26
29
  return Math.floor(this.count / this.display) + (this.count % this.display === 0 ? 0 : 1);
27
30
  }
@@ -45,8 +48,8 @@ export class QboPaginate extends LitElement {
45
48
 
46
49
 
47
50
  renderPage(i: number) {
48
- return html`<li class="page-item ${this.currentPage === i ? 'active' : ''}">
49
- <a class="page-link" @click="${() => this.goToPage(i)}">${i}</a>
51
+ return html`<li class="${this.currentPage === i ? 'active' : ''}">
52
+ <a @click="${(e) => this.goToPage(i)}">${i}</a>
50
53
  </li>`;
51
54
  }
52
55
 
@@ -79,21 +82,39 @@ export class QboPaginate extends LitElement {
79
82
  return pages;
80
83
  }
81
84
 
85
+ setDisplaySize(e: Event) {
86
+ const target = e.target as HTMLInputElement;
87
+ const display = parseInt(target.value);
88
+ if (!isNaN(display)) {
89
+ this.display = display;
90
+ this.start = 0;
91
+ this.goToPage(1);
92
+ }
93
+ }
94
+
95
+ renderPageSize() {
96
+ return html`<li class="pageSize">
97
+ <input type="number" min="5" value="${this.display}" title="Display Size" @change=${(e) => this.setDisplaySize(e)}>
98
+ <span>records per page</span>
99
+ </li>`
100
+ }
101
+
82
102
  render() {
83
103
  return html`
84
104
  <nav aria-label="Page navigation">
85
- <ul class="qbo-paginate paginate">
86
- <li class="page-item ${this.currentPage === 1 ? 'disabled' : ''}">
87
- <a class="page-link" aria-label="Previous" @click="${this.goToPage(this.currentPage--) }">
105
+ <ul class="qbo-paginate">
106
+ <li class="${this.currentPage === 1 ? 'disabled' : ''}">
107
+ <a aria-label="Previous" @click="${(e) => this.goToPage(this.currentPage--) }">
88
108
  <span aria-hidden="true">&laquo;</span>
89
109
  </a>
90
110
  </li>
91
111
  ${this.renderPageNumbers()}
92
- <li class="page-item ${this.currentPage === this.maxPage ? 'disabled' : ''}">
93
- <a class="page-link" aria-label="Next" @click="${this.goToPage(this.currentPage++)}">
112
+ <li class="${this.currentPage === this.maxPage ? 'disabled' : ''}">
113
+ <a aria-label="Next" @click="${(e) => this.goToPage(this.currentPage++)}">
94
114
  <span aria-hidden="true">&raquo;</span>
95
115
  </a>
96
116
  </li>
117
+ ${this.editSize ? this.renderPageSize() : html``}
97
118
  </ul>
98
119
  </nav>`;
99
120
  }