@things-factory/biz-base 10.1.265 → 10.1.269
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/client/counterparty-register-form.ts +219 -0
- package/client/counterparty-register.ts +52 -0
- package/client/counterparty-select.ts +221 -0
- package/client/index.ts +9 -0
- package/dist-client/counterparty-register-form.d.ts +40 -0
- package/dist-client/counterparty-register-form.js +230 -0
- package/dist-client/counterparty-register-form.js.map +1 -0
- package/dist-client/counterparty-register.d.ts +31 -0
- package/dist-client/counterparty-register.js +42 -0
- package/dist-client/counterparty-register.js.map +1 -0
- package/dist-client/counterparty-select.d.ts +41 -0
- package/dist-client/counterparty-select.js +238 -0
- package/dist-client/counterparty-select.js.map +1 -0
- package/dist-client/index.d.ts +3 -0
- package/dist-client/index.js +4 -0
- package/dist-client/index.js.map +1 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -0
- package/dist-server/service/counterparty/counterparty-names.d.ts +6 -0
- package/dist-server/service/counterparty/counterparty-names.js +12 -0
- package/dist-server/service/counterparty/counterparty-names.js.map +1 -1
- package/dist-server/service/counterparty/counterparty-query.d.ts +2 -1
- package/dist-server/service/counterparty/counterparty-query.js +19 -0
- package/dist-server/service/counterparty/counterparty-query.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -9
- package/tests/counterparty-names.test.mjs +17 -0
- package/tests/counterparty-register.test.mjs +40 -0
- package/translations/en.json +21 -1
- package/translations/es.json +21 -1
- package/translations/ja.json +28 -1
- package/translations/ko.json +21 -1
- package/translations/ms.json +28 -1
- package/translations/zh.json +28 -1
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import '@material/web/button/filled-button.js';
|
|
3
|
+
import '@material/web/button/text-button.js';
|
|
4
|
+
import '@operato/input/ox-input-select-buttons.js';
|
|
5
|
+
import '@operato/popup/ox-popup-actions.js';
|
|
6
|
+
import gql from 'graphql-tag';
|
|
7
|
+
import { css, html, LitElement, nothing } from 'lit';
|
|
8
|
+
import { customElement, property, state } from 'lit/decorators.js';
|
|
9
|
+
import { gqlContext, MutationController, QueryController } from '@operato/graphql';
|
|
10
|
+
import { i18next, localize } from '@operato/i18n';
|
|
11
|
+
import { CommonPopupStyles, FormFieldStyles, PopupBodyStyles, PopupFieldStyles } from '@operato/styles';
|
|
12
|
+
/** The kinds a counterparty registered here may be - our own company is one per domain and kept on its own screen. */
|
|
13
|
+
const KINDS = ['COMPANY', 'INSTITUTION', 'PERSON'];
|
|
14
|
+
const SAME_NAMED = gql `
|
|
15
|
+
query ($name: String!) {
|
|
16
|
+
counterpartiesNamed(name: $name) {
|
|
17
|
+
id
|
|
18
|
+
name
|
|
19
|
+
kind
|
|
20
|
+
businessNumber
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
const REGISTER = gql `
|
|
25
|
+
mutation ($counterparty: NewCounterparty!) {
|
|
26
|
+
createCounterparty(counterparty: $counterparty) {
|
|
27
|
+
id
|
|
28
|
+
name
|
|
29
|
+
kind
|
|
30
|
+
businessNumber
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
/**
|
|
35
|
+
* 새 거래처 등록 - the short form a picker opens for a name it did not find (ADR-0195 decision 3): the name, the kind,
|
|
36
|
+
* and the business number and representative when known. Saved through `createCounterparty`, the counterparty screen's
|
|
37
|
+
* own checks. Fires `counterparty` with the one to take, `close` when given up.
|
|
38
|
+
*
|
|
39
|
+
* A name already a counterparty - its name or an alias, spaces and (주) aside - is not registered again: the form shows
|
|
40
|
+
* that one and offers only to take it (decision 4). A business of the same name is registered on the counterparty
|
|
41
|
+
* screen.
|
|
42
|
+
*
|
|
43
|
+
* The business number field is where a check with the public registries will sit (decision 7).
|
|
44
|
+
*/
|
|
45
|
+
let CounterpartyRegisterForm = class CounterpartyRegisterForm extends localize(i18next)(LitElement) {
|
|
46
|
+
constructor() {
|
|
47
|
+
super(...arguments);
|
|
48
|
+
/** The name the picker was searched by - the form starts from it. */
|
|
49
|
+
this.name = '';
|
|
50
|
+
this.kind = 'COMPANY';
|
|
51
|
+
this.businessNumber = '';
|
|
52
|
+
this.representative = '';
|
|
53
|
+
/** The name asked about - set once the person stops typing. */
|
|
54
|
+
this.asked = '';
|
|
55
|
+
this.sameNamed = new QueryController(this, SAME_NAMED, {
|
|
56
|
+
variables: () => (this.asked ? { name: this.asked } : undefined),
|
|
57
|
+
fetchPolicy: 'no-cache',
|
|
58
|
+
context: gqlContext()
|
|
59
|
+
});
|
|
60
|
+
this.save = new MutationController(this, REGISTER, { context: gqlContext(), showsError: true });
|
|
61
|
+
}
|
|
62
|
+
/* The house shape of a popup (page-standard sections 7, 8): only the body scrolls, labels above native inputs. */
|
|
63
|
+
static { this.styles = [
|
|
64
|
+
CommonPopupStyles,
|
|
65
|
+
PopupBodyStyles,
|
|
66
|
+
FormFieldStyles,
|
|
67
|
+
PopupFieldStyles,
|
|
68
|
+
css `
|
|
69
|
+
ox-input-select-buttons {
|
|
70
|
+
align-self: flex-start;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
[guide] {
|
|
74
|
+
margin: 0;
|
|
75
|
+
color: var(--ui-muted);
|
|
76
|
+
line-height: var(--popup-line-height);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
[invalid] {
|
|
80
|
+
color: var(--ui-crit, var(--md-sys-color-error));
|
|
81
|
+
font-size: var(--ui-t-small, 11.5px);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
[invalid]:empty {
|
|
85
|
+
display: none;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
ul[same] {
|
|
89
|
+
list-style: none;
|
|
90
|
+
margin: 0;
|
|
91
|
+
padding: 0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
ul[same] li {
|
|
95
|
+
display: flex;
|
|
96
|
+
align-items: center;
|
|
97
|
+
justify-content: space-between;
|
|
98
|
+
gap: var(--spacing-medium, 8px);
|
|
99
|
+
padding: 3px 0;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
ul[same] small {
|
|
103
|
+
color: var(--ui-muted);
|
|
104
|
+
}
|
|
105
|
+
`
|
|
106
|
+
]; }
|
|
107
|
+
connectedCallback() {
|
|
108
|
+
super.connectedCallback();
|
|
109
|
+
this.asked = this.name.trim();
|
|
110
|
+
}
|
|
111
|
+
/** What the name check says for the name now in the field. */
|
|
112
|
+
get check() {
|
|
113
|
+
const name = this.name.trim();
|
|
114
|
+
if (!name || this.asked !== name)
|
|
115
|
+
return 'idle';
|
|
116
|
+
if (this.sameNamed.loading)
|
|
117
|
+
return 'checking';
|
|
118
|
+
const found = this.sameNamed.error ? undefined : this.sameNamed.data?.counterpartiesNamed;
|
|
119
|
+
if (!Array.isArray(found))
|
|
120
|
+
return 'failed';
|
|
121
|
+
return found.length ? 'taken' : 'free';
|
|
122
|
+
}
|
|
123
|
+
get registrable() {
|
|
124
|
+
return this.check === 'free' && !this.save.pending;
|
|
125
|
+
}
|
|
126
|
+
render() {
|
|
127
|
+
const check = this.check;
|
|
128
|
+
return html `
|
|
129
|
+
<div class="body">
|
|
130
|
+
<p guide>${i18next.t('text.counterparty-register-guide')}</p>
|
|
131
|
+
|
|
132
|
+
<label class="field">
|
|
133
|
+
<span>${i18next.t('field.counterparty-name')}</span>
|
|
134
|
+
<input name="name" .value=${this.name} @input=${(e) => this.onName(e.target.value)} />
|
|
135
|
+
<span invalid
|
|
136
|
+
>${check === 'failed' ? i18next.t('text.counterparty-name-check-failed') : check === 'checking' ? i18next.t('text.counterparty-checking-name') : ''}</span
|
|
137
|
+
>
|
|
138
|
+
</label>
|
|
139
|
+
|
|
140
|
+
${check === 'taken' ? this.renderSameNamed() : nothing}
|
|
141
|
+
|
|
142
|
+
<div class="field">
|
|
143
|
+
<span>${i18next.t('field.counterparty-kind')}</span>
|
|
144
|
+
<ox-input-select-buttons
|
|
145
|
+
.value=${this.kind}
|
|
146
|
+
.options=${KINDS.map(kind => ({ display: i18next.t(`text.counterparty-kind-${kind.toLowerCase()}`), value: kind }))}
|
|
147
|
+
@change=${(e) => e.detail && (this.kind = e.detail)}
|
|
148
|
+
></ox-input-select-buttons>
|
|
149
|
+
</div>
|
|
150
|
+
|
|
151
|
+
<label class="field">
|
|
152
|
+
<span>${i18next.t('field.business-number')}</span>
|
|
153
|
+
<input name="businessNumber" .value=${this.businessNumber} inputmode="numeric" @input=${(e) => (this.businessNumber = e.target.value)} />
|
|
154
|
+
<span>${i18next.t('text.business-number-hint')}</span>
|
|
155
|
+
</label>
|
|
156
|
+
|
|
157
|
+
<label class="field">
|
|
158
|
+
<span>${i18next.t('field.representative')}</span>
|
|
159
|
+
<input name="representative" .value=${this.representative} @input=${(e) => (this.representative = e.target.value)} />
|
|
160
|
+
</label>
|
|
161
|
+
</div>
|
|
162
|
+
|
|
163
|
+
<ox-popup-actions>
|
|
164
|
+
<md-text-button slot="cancel" @click=${() => this.dispatchEvent(new CustomEvent('close'))}>${i18next.t('button.cancel')}</md-text-button>
|
|
165
|
+
<md-filled-button slot="confirm" ?disabled=${!this.registrable} @click=${() => this.register()}>${i18next.t('button.counterparty-register')}</md-filled-button>
|
|
166
|
+
</ox-popup-actions>
|
|
167
|
+
`;
|
|
168
|
+
}
|
|
169
|
+
renderSameNamed() {
|
|
170
|
+
const found = this.sameNamed.data?.counterpartiesNamed ?? [];
|
|
171
|
+
return html `
|
|
172
|
+
<div class="field">
|
|
173
|
+
<span invalid>${i18next.t('text.counterparty-same-named')}</span>
|
|
174
|
+
<ul same>
|
|
175
|
+
${found.map(one => html `<li>
|
|
176
|
+
<span>${one.name} ${one.businessNumber ? html `<small>${one.businessNumber}</small>` : nothing}</span>
|
|
177
|
+
<md-text-button @click=${() => this.take(one)}>${i18next.t('button.counterparty-choose-this')}</md-text-button>
|
|
178
|
+
</li>`)}
|
|
179
|
+
</ul>
|
|
180
|
+
</div>
|
|
181
|
+
`;
|
|
182
|
+
}
|
|
183
|
+
onName(value) {
|
|
184
|
+
this.name = value;
|
|
185
|
+
clearTimeout(this.timer);
|
|
186
|
+
this.timer = setTimeout(() => (this.asked = this.name.trim()), 300);
|
|
187
|
+
}
|
|
188
|
+
async register() {
|
|
189
|
+
if (!this.registrable)
|
|
190
|
+
return;
|
|
191
|
+
const counterparty = {
|
|
192
|
+
name: this.name.trim(),
|
|
193
|
+
kind: this.kind,
|
|
194
|
+
...(this.businessNumber.trim() ? { businessNumber: this.businessNumber.trim() } : {}),
|
|
195
|
+
...(this.representative.trim() ? { representative: this.representative.trim() } : {})
|
|
196
|
+
};
|
|
197
|
+
const data = await this.save.run({ counterparty });
|
|
198
|
+
const saved = data?.createCounterparty;
|
|
199
|
+
if (saved)
|
|
200
|
+
this.take(saved);
|
|
201
|
+
}
|
|
202
|
+
take(one) {
|
|
203
|
+
this.dispatchEvent(new CustomEvent('counterparty', { detail: { id: one.id, name: one.name, businessNumber: one.businessNumber ?? null, kind: one.kind ?? null } }));
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
__decorate([
|
|
207
|
+
property({ type: String }),
|
|
208
|
+
__metadata("design:type", Object)
|
|
209
|
+
], CounterpartyRegisterForm.prototype, "name", void 0);
|
|
210
|
+
__decorate([
|
|
211
|
+
state(),
|
|
212
|
+
__metadata("design:type", Object)
|
|
213
|
+
], CounterpartyRegisterForm.prototype, "kind", void 0);
|
|
214
|
+
__decorate([
|
|
215
|
+
state(),
|
|
216
|
+
__metadata("design:type", Object)
|
|
217
|
+
], CounterpartyRegisterForm.prototype, "businessNumber", void 0);
|
|
218
|
+
__decorate([
|
|
219
|
+
state(),
|
|
220
|
+
__metadata("design:type", Object)
|
|
221
|
+
], CounterpartyRegisterForm.prototype, "representative", void 0);
|
|
222
|
+
__decorate([
|
|
223
|
+
state(),
|
|
224
|
+
__metadata("design:type", Object)
|
|
225
|
+
], CounterpartyRegisterForm.prototype, "asked", void 0);
|
|
226
|
+
CounterpartyRegisterForm = __decorate([
|
|
227
|
+
customElement('counterparty-register-form')
|
|
228
|
+
], CounterpartyRegisterForm);
|
|
229
|
+
export { CounterpartyRegisterForm };
|
|
230
|
+
//# sourceMappingURL=counterparty-register-form.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"counterparty-register-form.js","sourceRoot":"","sources":["../client/counterparty-register-form.ts"],"names":[],"mappings":";AAAA,OAAO,uCAAuC,CAAA;AAC9C,OAAO,qCAAqC,CAAA;AAC5C,OAAO,2CAA2C,CAAA;AAClD,OAAO,oCAAoC,CAAA;AAE3C,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAElE,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClF,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAEvG,sHAAsH;AACtH,MAAM,KAAK,GAAG,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAA;AAElD,MAAM,UAAU,GAAG,GAAG,CAAA;;;;;;;;;CASrB,CAAA;AAED,MAAM,QAAQ,GAAG,GAAG,CAAA;;;;;;;;;CASnB,CAAA;AAED;;;;;;;;;;GAUG;AAEI,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC;IAApE;;QA+CL,qEAAqE;QACzC,SAAI,GAAG,EAAE,CAAA;QAEpB,SAAI,GAAG,SAAS,CAAA;QAChB,mBAAc,GAAG,EAAE,CAAA;QACnB,mBAAc,GAAG,EA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I,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC,CAAA;IACrK,CAAC;;AAvH2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;sDAAU;AAEpB;IAAhB,KAAK,EAAE;;sDAAyB;AAChB;IAAhB,KAAK,EAAE;;gEAA4B;AACnB;IAAhB,KAAK,EAAE;;gEAA4B;AAEnB;IAAhB,KAAK,EAAE;;uDAAmB;AAtDhB,wBAAwB;IADpC,aAAa,CAAC,4BAA4B,CAAC;GAC/B,wBAAwB,CAwKpC","sourcesContent":["import '@material/web/button/filled-button.js'\nimport '@material/web/button/text-button.js'\nimport '@operato/input/ox-input-select-buttons.js'\nimport '@operato/popup/ox-popup-actions.js'\n\nimport gql from 'graphql-tag'\nimport { css, html, LitElement, nothing } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\n\nimport { gqlContext, MutationController, QueryController } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { CommonPopupStyles, FormFieldStyles, PopupBodyStyles, PopupFieldStyles } from '@operato/styles'\n\n/** The kinds a counterparty registered here may be - our own company is one per domain and kept on its own screen. */\nconst KINDS = ['COMPANY', 'INSTITUTION', 'PERSON']\n\nconst SAME_NAMED = gql`\n query ($name: String!) {\n counterpartiesNamed(name: $name) {\n id\n name\n kind\n businessNumber\n }\n }\n`\n\nconst REGISTER = gql`\n mutation ($counterparty: NewCounterparty!) {\n createCounterparty(counterparty: $counterparty) {\n id\n name\n kind\n businessNumber\n }\n }\n`\n\n/**\n * 새 거래처 등록 - the short form a picker opens for a name it did not find (ADR-0195 decision 3): the name, the kind,\n * and the business number and representative when known. Saved through `createCounterparty`, the counterparty screen's\n * own checks. Fires `counterparty` with the one to take, `close` when given up.\n *\n * A name already a counterparty - its name or an alias, spaces and (주) aside - is not registered again: the form shows\n * that one and offers only to take it (decision 4). A business of the same name is registered on the counterparty\n * screen.\n *\n * The business number field is where a check with the public registries will sit (decision 7).\n */\n@customElement('counterparty-register-form')\nexport class CounterpartyRegisterForm extends localize(i18next)(LitElement) {\n /* The house shape of a popup (page-standard sections 7, 8): only the body scrolls, labels above native inputs. */\n static styles = [\n CommonPopupStyles,\n PopupBodyStyles,\n FormFieldStyles,\n PopupFieldStyles,\n css`\n ox-input-select-buttons {\n align-self: flex-start;\n }\n\n [guide] {\n margin: 0;\n color: var(--ui-muted);\n line-height: var(--popup-line-height);\n }\n\n [invalid] {\n color: var(--ui-crit, var(--md-sys-color-error));\n font-size: var(--ui-t-small, 11.5px);\n }\n\n [invalid]:empty {\n display: none;\n }\n\n ul[same] {\n list-style: none;\n margin: 0;\n padding: 0;\n }\n\n ul[same] li {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: var(--spacing-medium, 8px);\n padding: 3px 0;\n }\n\n ul[same] small {\n color: var(--ui-muted);\n }\n `\n ]\n\n /** The name the picker was searched by - the form starts from it. */\n @property({ type: String }) name = ''\n\n @state() private kind = 'COMPANY'\n @state() private businessNumber = ''\n @state() private representative = ''\n /** The name asked about - set once the person stops typing. */\n @state() private asked = ''\n\n private timer?: ReturnType<typeof setTimeout>\n\n private sameNamed = new QueryController(this, SAME_NAMED, {\n variables: () => (this.asked ? { name: this.asked } : undefined),\n fetchPolicy: 'no-cache',\n context: gqlContext()\n } as any)\n\n private save = new MutationController(this, REGISTER, { context: gqlContext(), showsError: true } as any)\n\n connectedCallback() {\n super.connectedCallback()\n this.asked = this.name.trim()\n }\n\n /** What the name check says for the name now in the field. */\n private get check(): 'idle' | 'checking' | 'free' | 'taken' | 'failed' {\n const name = this.name.trim()\n if (!name || this.asked !== name) return 'idle'\n if (this.sameNamed.loading) return 'checking'\n const found = this.sameNamed.error ? undefined : this.sameNamed.data?.counterpartiesNamed\n if (!Array.isArray(found)) return 'failed'\n return found.length ? 'taken' : 'free'\n }\n\n private get registrable(): boolean {\n return this.check === 'free' && !this.save.pending\n }\n\n render() {\n const check = this.check\n return html`\n <div class=\"body\">\n <p guide>${i18next.t('text.counterparty-register-guide')}</p>\n\n <label class=\"field\">\n <span>${i18next.t('field.counterparty-name')}</span>\n <input name=\"name\" .value=${this.name} @input=${(e: Event) => this.onName((e.target as HTMLInputElement).value)} />\n <span invalid\n >${check === 'failed' ? i18next.t('text.counterparty-name-check-failed') : check === 'checking' ? i18next.t('text.counterparty-checking-name') : ''}</span\n >\n </label>\n\n ${check === 'taken' ? this.renderSameNamed() : nothing}\n\n <div class=\"field\">\n <span>${i18next.t('field.counterparty-kind')}</span>\n <ox-input-select-buttons\n .value=${this.kind}\n .options=${KINDS.map(kind => ({ display: i18next.t(`text.counterparty-kind-${kind.toLowerCase()}`), value: kind }))}\n @change=${(e: CustomEvent) => e.detail && (this.kind = e.detail)}\n ></ox-input-select-buttons>\n </div>\n\n <label class=\"field\">\n <span>${i18next.t('field.business-number')}</span>\n <input name=\"businessNumber\" .value=${this.businessNumber} inputmode=\"numeric\" @input=${(e: Event) => (this.businessNumber = (e.target as HTMLInputElement).value)} />\n <span>${i18next.t('text.business-number-hint')}</span>\n </label>\n\n <label class=\"field\">\n <span>${i18next.t('field.representative')}</span>\n <input name=\"representative\" .value=${this.representative} @input=${(e: Event) => (this.representative = (e.target as HTMLInputElement).value)} />\n </label>\n </div>\n\n <ox-popup-actions>\n <md-text-button slot=\"cancel\" @click=${() => this.dispatchEvent(new CustomEvent('close'))}>${i18next.t('button.cancel')}</md-text-button>\n <md-filled-button slot=\"confirm\" ?disabled=${!this.registrable} @click=${() => this.register()}>${i18next.t('button.counterparty-register')}</md-filled-button>\n </ox-popup-actions>\n `\n }\n\n private renderSameNamed() {\n const found: any[] = this.sameNamed.data?.counterpartiesNamed ?? []\n return html`\n <div class=\"field\">\n <span invalid>${i18next.t('text.counterparty-same-named')}</span>\n <ul same>\n ${found.map(\n one => html`<li>\n <span>${one.name} ${one.businessNumber ? html`<small>${one.businessNumber}</small>` : nothing}</span>\n <md-text-button @click=${() => this.take(one)}>${i18next.t('button.counterparty-choose-this')}</md-text-button>\n </li>`\n )}\n </ul>\n </div>\n `\n }\n\n private onName(value: string) {\n this.name = value\n clearTimeout(this.timer)\n this.timer = setTimeout(() => (this.asked = this.name.trim()), 300)\n }\n\n private async register() {\n if (!this.registrable) return\n const counterparty = {\n name: this.name.trim(),\n kind: this.kind,\n ...(this.businessNumber.trim() ? { businessNumber: this.businessNumber.trim() } : {}),\n ...(this.representative.trim() ? { representative: this.representative.trim() } : {})\n }\n const data: any = await this.save.run({ counterparty })\n const saved = data?.createCounterparty\n if (saved) this.take(saved)\n }\n\n private take(one: { id: string; name: string; businessNumber?: string | null; kind?: string | null }) {\n this.dispatchEvent(new CustomEvent('counterparty', { detail: { id: one.id, name: one.name, businessNumber: one.businessNumber ?? null, kind: one.kind ?? null } }))\n }\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import './counterparty-register-form.js';
|
|
2
|
+
/** A counterparty as one picks it - which one, its name and registration number (`counterpartyChoices`). */
|
|
3
|
+
export type CounterpartyPick = {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
businessNumber?: string | null;
|
|
7
|
+
kind?: string | null;
|
|
8
|
+
};
|
|
9
|
+
/** Registering a counterparty is the counterparty keeper's - the privilege `createCounterparty` asks (ADR-0195 decision 5). */
|
|
10
|
+
export declare const COUNTERPARTY_REGISTER_PRIVILEGE: {
|
|
11
|
+
category: string;
|
|
12
|
+
privilege: string;
|
|
13
|
+
domainOwnerGranted: boolean;
|
|
14
|
+
};
|
|
15
|
+
/** Whether this seat may register a counterparty - where it is not, the pickers offer no registering. */
|
|
16
|
+
export declare function mayRegisterCounterparty(): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Register a counterparty from the name a picker was searched by, in the short form (ADR-0195 decision 3). Resolves the
|
|
19
|
+
* counterparty to take - the one registered, or the one of the same name the form led to - or undefined when the
|
|
20
|
+
* person closed the form.
|
|
21
|
+
*/
|
|
22
|
+
export declare function registerCounterparty(name: string): Promise<CounterpartyPick | undefined>;
|
|
23
|
+
/**
|
|
24
|
+
* What a picker column of counterparties declares so a name not found can be registered there (`resource-object`'s
|
|
25
|
+
* `creatable`, ADR-0195 decision 2).
|
|
26
|
+
*/
|
|
27
|
+
export declare const counterpartyCreatable: {
|
|
28
|
+
allowed: typeof mayRegisterCounterparty;
|
|
29
|
+
label: (name: string) => string;
|
|
30
|
+
create: typeof registerCounterparty;
|
|
31
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import './counterparty-register-form.js';
|
|
2
|
+
import { html } from 'lit';
|
|
3
|
+
import { i18next } from '@operato/i18n';
|
|
4
|
+
import { openPopup } from '@operato/layout';
|
|
5
|
+
import { hasPrivilege } from '@things-factory/auth-base/dist-client';
|
|
6
|
+
/** Registering a counterparty is the counterparty keeper's - the privilege `createCounterparty` asks (ADR-0195 decision 5). */
|
|
7
|
+
export const COUNTERPARTY_REGISTER_PRIVILEGE = { category: 'counterparty', privilege: 'mutation', domainOwnerGranted: true };
|
|
8
|
+
/** Whether this seat may register a counterparty - where it is not, the pickers offer no registering. */
|
|
9
|
+
export async function mayRegisterCounterparty() {
|
|
10
|
+
try {
|
|
11
|
+
return !!(await hasPrivilege(COUNTERPARTY_REGISTER_PRIVILEGE));
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Register a counterparty from the name a picker was searched by, in the short form (ADR-0195 decision 3). Resolves the
|
|
19
|
+
* counterparty to take - the one registered, or the one of the same name the form led to - or undefined when the
|
|
20
|
+
* person closed the form.
|
|
21
|
+
*/
|
|
22
|
+
export function registerCounterparty(name) {
|
|
23
|
+
return new Promise(resolve => {
|
|
24
|
+
let taken;
|
|
25
|
+
const handle = openPopup(html `<counterparty-register-form
|
|
26
|
+
.name=${name}
|
|
27
|
+
@close=${() => handle.close()}
|
|
28
|
+
@counterparty=${(e) => ((taken = e.detail), handle.close())}
|
|
29
|
+
></counterparty-register-form>`, { backdrop: true, size: 'medium', title: i18next.t('title.counterparty-register') });
|
|
30
|
+
handle.onclosed = () => resolve(taken);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* What a picker column of counterparties declares so a name not found can be registered there (`resource-object`'s
|
|
35
|
+
* `creatable`, ADR-0195 decision 2).
|
|
36
|
+
*/
|
|
37
|
+
export const counterpartyCreatable = {
|
|
38
|
+
allowed: mayRegisterCounterparty,
|
|
39
|
+
label: (name) => i18next.t('button.counterparty-register-named', { name }),
|
|
40
|
+
create: registerCounterparty
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=counterparty-register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"counterparty-register.js","sourceRoot":"","sources":["../client/counterparty-register.ts"],"names":[],"mappings":"AAAA,OAAO,iCAAiC,CAAA;AAExC,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAE1B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAA;AAKpE,+HAA+H;AAC/H,MAAM,CAAC,MAAM,+BAA+B,GAAG,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAA;AAE5H,yGAAyG;AACzG,MAAM,CAAC,KAAK,UAAU,uBAAuB;IAC3C,IAAI,CAAC;QACH,OAAO,CAAC,CAAC,CAAC,MAAM,YAAY,CAAC,+BAA+B,CAAC,CAAC,CAAA;IAChE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC/C,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QAC3B,IAAI,KAAmC,CAAA;QACvC,MAAM,MAAM,GAAQ,SAAS,CAC3B,IAAI,CAAA;gBACM,IAAI;iBACH,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE;wBACb,CAAC,CAAc,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;qCAC3C,EAC/B,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,6BAA6B,CAAC,EAAE,CACpF,CAAA;QACD,MAAM,CAAC,QAAQ,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACxC,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,OAAO,EAAE,uBAAuB;IAChC,KAAK,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,oCAAoC,EAAE,EAAE,IAAI,EAAE,CAAC;IAClF,MAAM,EAAE,oBAAoB;CAC7B,CAAA","sourcesContent":["import './counterparty-register-form.js'\n\nimport { html } from 'lit'\n\nimport { i18next } from '@operato/i18n'\nimport { openPopup } from '@operato/layout'\nimport { hasPrivilege } from '@things-factory/auth-base/dist-client'\n\n/** A counterparty as one picks it - which one, its name and registration number (`counterpartyChoices`). */\nexport type CounterpartyPick = { id: string; name: string; businessNumber?: string | null; kind?: string | null }\n\n/** Registering a counterparty is the counterparty keeper's - the privilege `createCounterparty` asks (ADR-0195 decision 5). */\nexport const COUNTERPARTY_REGISTER_PRIVILEGE = { category: 'counterparty', privilege: 'mutation', domainOwnerGranted: true }\n\n/** Whether this seat may register a counterparty - where it is not, the pickers offer no registering. */\nexport async function mayRegisterCounterparty(): Promise<boolean> {\n try {\n return !!(await hasPrivilege(COUNTERPARTY_REGISTER_PRIVILEGE))\n } catch {\n return false\n }\n}\n\n/**\n * Register a counterparty from the name a picker was searched by, in the short form (ADR-0195 decision 3). Resolves the\n * counterparty to take - the one registered, or the one of the same name the form led to - or undefined when the\n * person closed the form.\n */\nexport function registerCounterparty(name: string): Promise<CounterpartyPick | undefined> {\n return new Promise(resolve => {\n let taken: CounterpartyPick | undefined\n const handle: any = openPopup(\n html`<counterparty-register-form\n .name=${name}\n @close=${() => handle.close()}\n @counterparty=${(e: CustomEvent) => ((taken = e.detail), handle.close())}\n ></counterparty-register-form>`,\n { backdrop: true, size: 'medium', title: i18next.t('title.counterparty-register') }\n )\n handle.onclosed = () => resolve(taken)\n })\n}\n\n/**\n * What a picker column of counterparties declares so a name not found can be registered there (`resource-object`'s\n * `creatable`, ADR-0195 decision 2).\n */\nexport const counterpartyCreatable = {\n allowed: mayRegisterCounterparty,\n label: (name: string) => i18next.t('button.counterparty-register-named', { name }),\n create: registerCounterparty\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import '@material/web/icon/icon.js';
|
|
2
|
+
import { LitElement } from 'lit';
|
|
3
|
+
import { type CounterpartyPick } from './counterparty-register.js';
|
|
4
|
+
declare const CounterpartySelect_base: (new (...args: any[]) => LitElement) & typeof LitElement;
|
|
5
|
+
/**
|
|
6
|
+
* Picking a counterparty - one field that finds as it is typed and lists what it found under it; a click takes one and
|
|
7
|
+
* fires `counterparty` with it (or with null when cleared). Every form that picks one counterparty picks it here -
|
|
8
|
+
* invoice, quotation, opportunity, expenditure request (ADR-0195 decision 1). Reads `counterpartyChoices`, which every
|
|
9
|
+
* seat may.
|
|
10
|
+
*
|
|
11
|
+
* A name not found can be registered from here and is taken at once (ADR-0195 decision 2) - offered only to a seat that
|
|
12
|
+
* may register counterparties.
|
|
13
|
+
*/
|
|
14
|
+
export declare class CounterpartySelect extends CounterpartySelect_base {
|
|
15
|
+
static styles: import("lit").CSSResult[];
|
|
16
|
+
/** The party chosen, shown as the field's placeholder until something is typed. */
|
|
17
|
+
party: CounterpartyPick | null;
|
|
18
|
+
disabled: boolean;
|
|
19
|
+
private search;
|
|
20
|
+
/** The words the list is found by - undefined while no list is open. */
|
|
21
|
+
private finding?;
|
|
22
|
+
private active;
|
|
23
|
+
/** Whether this seat may register a counterparty - the action under the list shows only then. */
|
|
24
|
+
private mayRegister;
|
|
25
|
+
private timer?;
|
|
26
|
+
private registering;
|
|
27
|
+
private choices;
|
|
28
|
+
/** The list under the field: what was found, or null while it is closed or not read. */
|
|
29
|
+
connectedCallback(): Promise<void>;
|
|
30
|
+
/** The words a new counterparty would be registered under - shown under the list when this seat may register. */
|
|
31
|
+
private get newName();
|
|
32
|
+
private get found();
|
|
33
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
34
|
+
private findSoon;
|
|
35
|
+
private find;
|
|
36
|
+
private key;
|
|
37
|
+
/** Register the name typed and take it - or the counterparty of that name the form led to. */
|
|
38
|
+
private register;
|
|
39
|
+
private choose;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import '@material/web/icon/icon.js';
|
|
3
|
+
import gql from 'graphql-tag';
|
|
4
|
+
import { css, html, LitElement, nothing } from 'lit';
|
|
5
|
+
import { customElement, property, state } from 'lit/decorators.js';
|
|
6
|
+
import { QueryController } from '@operato/graphql';
|
|
7
|
+
import { i18next, localize } from '@operato/i18n';
|
|
8
|
+
import { ButtonStyles } from '@operato/styles';
|
|
9
|
+
import { mayRegisterCounterparty, registerCounterparty } from './counterparty-register.js';
|
|
10
|
+
const CHOICES = gql `
|
|
11
|
+
query ($search: String, $pagination: Pagination) {
|
|
12
|
+
counterparties: counterpartyChoices(search: $search, pagination: $pagination) {
|
|
13
|
+
items { id name businessNumber }
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
17
|
+
/**
|
|
18
|
+
* Picking a counterparty - one field that finds as it is typed and lists what it found under it; a click takes one and
|
|
19
|
+
* fires `counterparty` with it (or with null when cleared). Every form that picks one counterparty picks it here -
|
|
20
|
+
* invoice, quotation, opportunity, expenditure request (ADR-0195 decision 1). Reads `counterpartyChoices`, which every
|
|
21
|
+
* seat may.
|
|
22
|
+
*
|
|
23
|
+
* A name not found can be registered from here and is taken at once (ADR-0195 decision 2) - offered only to a seat that
|
|
24
|
+
* may register counterparties.
|
|
25
|
+
*/
|
|
26
|
+
let CounterpartySelect = class CounterpartySelect extends localize(i18next)(LitElement) {
|
|
27
|
+
constructor() {
|
|
28
|
+
super(...arguments);
|
|
29
|
+
/** The party chosen, shown as the field's placeholder until something is typed. */
|
|
30
|
+
this.party = null;
|
|
31
|
+
this.disabled = false;
|
|
32
|
+
this.search = '';
|
|
33
|
+
this.active = 0;
|
|
34
|
+
/** Whether this seat may register a counterparty - the action under the list shows only then. */
|
|
35
|
+
this.mayRegister = false;
|
|
36
|
+
/* A name was registered from here: the focus the form hands back does not open the list again - typing or a click does. */
|
|
37
|
+
this.registering = false;
|
|
38
|
+
/* The choices for the words found by - only the answer to the last thing typed is shown, and the list found before
|
|
39
|
+
stays while the next is read (ADR-0190). */
|
|
40
|
+
this.choices = new QueryController(this, CHOICES, {
|
|
41
|
+
keepPrevious: true,
|
|
42
|
+
variables: () => this.finding === undefined || this.disabled ? undefined : { search: this.finding.trim() || undefined, pagination: { page: 1, limit: 30 } }
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
static { this.styles = [
|
|
46
|
+
ButtonStyles,
|
|
47
|
+
css `
|
|
48
|
+
:host {
|
|
49
|
+
position: relative;
|
|
50
|
+
display: block;
|
|
51
|
+
}
|
|
52
|
+
.field {
|
|
53
|
+
display: flex;
|
|
54
|
+
gap: var(--spacing-small, 4px);
|
|
55
|
+
align-items: center;
|
|
56
|
+
}
|
|
57
|
+
input {
|
|
58
|
+
flex: 1;
|
|
59
|
+
min-width: 0;
|
|
60
|
+
box-sizing: border-box;
|
|
61
|
+
height: var(--form-element-height-medium, 32px);
|
|
62
|
+
padding: 0 var(--spacing-medium, 8px);
|
|
63
|
+
border: var(--input-field-border, 1px solid var(--md-sys-color-outline));
|
|
64
|
+
border-radius: var(--input-field-border-radius, var(--md-sys-shape-corner-small, 4px));
|
|
65
|
+
background: var(--input-field-background, var(--md-sys-color-surface-container-highest));
|
|
66
|
+
font: inherit;
|
|
67
|
+
font-size: var(--ui-t-body, 13px);
|
|
68
|
+
color: var(--ui-ink, var(--md-sys-color-on-surface));
|
|
69
|
+
}
|
|
70
|
+
input:focus-visible {
|
|
71
|
+
outline: none;
|
|
72
|
+
border-color: var(--md-sys-color-primary);
|
|
73
|
+
}
|
|
74
|
+
ul {
|
|
75
|
+
position: absolute;
|
|
76
|
+
z-index: 10;
|
|
77
|
+
left: 0;
|
|
78
|
+
right: 0;
|
|
79
|
+
top: calc(100% + 2px);
|
|
80
|
+
max-height: 260px;
|
|
81
|
+
overflow-y: auto;
|
|
82
|
+
margin: 0;
|
|
83
|
+
padding: var(--spacing-small, 4px) 0;
|
|
84
|
+
list-style: none;
|
|
85
|
+
border: 1px solid var(--md-sys-color-outline-variant);
|
|
86
|
+
border-radius: var(--ui-r, 10px);
|
|
87
|
+
background: var(--md-sys-color-surface-container-lowest);
|
|
88
|
+
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
|
|
89
|
+
}
|
|
90
|
+
li {
|
|
91
|
+
display: flex;
|
|
92
|
+
justify-content: space-between;
|
|
93
|
+
gap: var(--spacing-large, 12px);
|
|
94
|
+
padding: 6px var(--spacing-large, 12px);
|
|
95
|
+
cursor: pointer;
|
|
96
|
+
font-size: var(--ui-t-body, 13px);
|
|
97
|
+
color: var(--ui-ink, var(--md-sys-color-on-surface));
|
|
98
|
+
}
|
|
99
|
+
li:hover,
|
|
100
|
+
li[active] {
|
|
101
|
+
background: var(--md-sys-color-surface-container-high);
|
|
102
|
+
}
|
|
103
|
+
li small {
|
|
104
|
+
white-space: nowrap;
|
|
105
|
+
}
|
|
106
|
+
li small,
|
|
107
|
+
li.none {
|
|
108
|
+
color: var(--ui-muted, var(--md-sys-color-on-surface-variant));
|
|
109
|
+
}
|
|
110
|
+
li.none {
|
|
111
|
+
cursor: default;
|
|
112
|
+
}
|
|
113
|
+
li.register {
|
|
114
|
+
border-top: 1px solid var(--md-sys-color-outline-variant);
|
|
115
|
+
color: var(--ui-accent, var(--md-sys-color-primary));
|
|
116
|
+
}
|
|
117
|
+
`
|
|
118
|
+
]; }
|
|
119
|
+
/** The list under the field: what was found, or null while it is closed or not read. */
|
|
120
|
+
async connectedCallback() {
|
|
121
|
+
super.connectedCallback();
|
|
122
|
+
this.mayRegister = await mayRegisterCounterparty();
|
|
123
|
+
}
|
|
124
|
+
/** The words a new counterparty would be registered under - shown under the list when this seat may register. */
|
|
125
|
+
get newName() {
|
|
126
|
+
return this.mayRegister && this.found ? this.search.trim() : '';
|
|
127
|
+
}
|
|
128
|
+
get found() {
|
|
129
|
+
if (this.finding === undefined || !this.choices.data)
|
|
130
|
+
return null;
|
|
131
|
+
return this.choices.data.counterparties?.items ?? [];
|
|
132
|
+
}
|
|
133
|
+
render() {
|
|
134
|
+
return html `
|
|
135
|
+
<div class="field">
|
|
136
|
+
<input
|
|
137
|
+
.value=${this.search}
|
|
138
|
+
placeholder=${this.party?.name ?? i18next.t('text.counterparty-search')}
|
|
139
|
+
aria-label=${i18next.t('field.counterparty')}
|
|
140
|
+
?disabled=${this.disabled}
|
|
141
|
+
@focus=${() => !this.registering && this.find()}
|
|
142
|
+
@mousedown=${() => (this.registering = false)}
|
|
143
|
+
@input=${(e) => ((this.registering = false), (this.search = e.target.value), this.findSoon())}
|
|
144
|
+
@keydown=${(e) => this.key(e)}
|
|
145
|
+
@blur=${() => setTimeout(() => (this.finding = undefined), 150)}
|
|
146
|
+
/>
|
|
147
|
+
${this.party && !this.disabled
|
|
148
|
+
? html `<button quiet icon-only title=${i18next.t('button.counterparty-clear')} aria-label=${i18next.t('button.counterparty-clear')} @click=${() => this.choose(null)}>
|
|
149
|
+
<md-icon>close</md-icon>
|
|
150
|
+
</button>`
|
|
151
|
+
: nothing}
|
|
152
|
+
</div>
|
|
153
|
+
${this.found
|
|
154
|
+
? html `<ul role="listbox">
|
|
155
|
+
${this.found.length
|
|
156
|
+
? this.found.map((one, index) => html `<li role="option" ?active=${index === this.active} @mousedown=${(e) => (e.preventDefault(), this.choose(one))}>
|
|
157
|
+
<span>${one.name}</span>${one.businessNumber ? html `<small>${one.businessNumber}</small>` : nothing}
|
|
158
|
+
</li>`)
|
|
159
|
+
: html `<li class="none">${i18next.t('text.counterparty-none')}</li>`}
|
|
160
|
+
${this.newName
|
|
161
|
+
? html `<li role="option" class="register" ?active=${this.active === this.found.length} @mousedown=${(e) => (e.preventDefault(), this.register())}>
|
|
162
|
+
<span>${i18next.t('button.counterparty-register-named', { name: this.newName })}</span>
|
|
163
|
+
</li>`
|
|
164
|
+
: nothing}
|
|
165
|
+
</ul>`
|
|
166
|
+
: nothing}
|
|
167
|
+
`;
|
|
168
|
+
}
|
|
169
|
+
findSoon() {
|
|
170
|
+
clearTimeout(this.timer);
|
|
171
|
+
this.timer = setTimeout(() => this.find(), 250);
|
|
172
|
+
}
|
|
173
|
+
find() {
|
|
174
|
+
if (this.disabled)
|
|
175
|
+
return;
|
|
176
|
+
this.finding = this.search;
|
|
177
|
+
this.active = 0;
|
|
178
|
+
}
|
|
179
|
+
key(e) {
|
|
180
|
+
const last = (this.found?.length ?? 0) + (this.newName ? 1 : 0) - 1;
|
|
181
|
+
if (last < 0 || e.isComposing)
|
|
182
|
+
return;
|
|
183
|
+
if (e.key === 'ArrowDown')
|
|
184
|
+
this.active = Math.min(this.active + 1, last);
|
|
185
|
+
else if (e.key === 'ArrowUp')
|
|
186
|
+
this.active = Math.max(this.active - 1, 0);
|
|
187
|
+
else if (e.key === 'Enter')
|
|
188
|
+
this.active < this.found.length ? this.choose(this.found[this.active]) : this.register();
|
|
189
|
+
else if (e.key === 'Escape')
|
|
190
|
+
this.finding = undefined;
|
|
191
|
+
else
|
|
192
|
+
return;
|
|
193
|
+
e.preventDefault();
|
|
194
|
+
}
|
|
195
|
+
/** Register the name typed and take it - or the counterparty of that name the form led to. */
|
|
196
|
+
async register() {
|
|
197
|
+
const name = this.newName;
|
|
198
|
+
this.finding = undefined;
|
|
199
|
+
this.registering = true;
|
|
200
|
+
const registered = await registerCounterparty(name);
|
|
201
|
+
if (registered)
|
|
202
|
+
this.choose(registered);
|
|
203
|
+
}
|
|
204
|
+
choose(party) {
|
|
205
|
+
this.search = '';
|
|
206
|
+
this.finding = undefined;
|
|
207
|
+
this.dispatchEvent(new CustomEvent('counterparty', { detail: party, bubbles: true, composed: true }));
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
__decorate([
|
|
211
|
+
property({ attribute: false }),
|
|
212
|
+
__metadata("design:type", Object)
|
|
213
|
+
], CounterpartySelect.prototype, "party", void 0);
|
|
214
|
+
__decorate([
|
|
215
|
+
property({ type: Boolean }),
|
|
216
|
+
__metadata("design:type", Object)
|
|
217
|
+
], CounterpartySelect.prototype, "disabled", void 0);
|
|
218
|
+
__decorate([
|
|
219
|
+
state(),
|
|
220
|
+
__metadata("design:type", Object)
|
|
221
|
+
], CounterpartySelect.prototype, "search", void 0);
|
|
222
|
+
__decorate([
|
|
223
|
+
state(),
|
|
224
|
+
__metadata("design:type", String)
|
|
225
|
+
], CounterpartySelect.prototype, "finding", void 0);
|
|
226
|
+
__decorate([
|
|
227
|
+
state(),
|
|
228
|
+
__metadata("design:type", Object)
|
|
229
|
+
], CounterpartySelect.prototype, "active", void 0);
|
|
230
|
+
__decorate([
|
|
231
|
+
state(),
|
|
232
|
+
__metadata("design:type", Object)
|
|
233
|
+
], CounterpartySelect.prototype, "mayRegister", void 0);
|
|
234
|
+
CounterpartySelect = __decorate([
|
|
235
|
+
customElement('counterparty-select')
|
|
236
|
+
], CounterpartySelect);
|
|
237
|
+
export { CounterpartySelect };
|
|
238
|
+
//# sourceMappingURL=counterparty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AAE5B;IAAhB,KAAK,EAAE;;kDAAoB;AAEX;IAAhB,KAAK,EAAE;;mDAAyB;AAChB;IAAhB,KAAK,EAAE;;kDAAmB;AAEV;IAAhB,KAAK,EAAE;;uDAA4B;AArFzB,kBAAkB;IAD9B,aAAa,CAAC,qBAAqB,CAAC;GACxB,kBAAkB,CA+L9B","sourcesContent":["import '@material/web/icon/icon.js'\n\nimport gql from 'graphql-tag'\nimport { css, html, LitElement, nothing } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\n\nimport { QueryController } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { ButtonStyles } from '@operato/styles'\nimport { mayRegisterCounterparty, registerCounterparty, type CounterpartyPick } from './counterparty-register.js'\n\nconst CHOICES = gql`\n query ($search: String, $pagination: Pagination) {\n counterparties: counterpartyChoices(search: $search, pagination: $pagination) {\n items { id name businessNumber }\n }\n }\n`\n\n/**\n * Picking a counterparty - one field that finds as it is typed and lists what it found under it; a click takes one and\n * fires `counterparty` with it (or with null when cleared). Every form that picks one counterparty picks it here -\n * invoice, quotation, opportunity, expenditure request (ADR-0195 decision 1). Reads `counterpartyChoices`, which every\n * seat may.\n *\n * A name not found can be registered from here and is taken at once (ADR-0195 decision 2) - offered only to a seat that\n * may register counterparties.\n */\n@customElement('counterparty-select')\nexport class CounterpartySelect extends localize(i18next)(LitElement) {\n static styles = [\n ButtonStyles,\n css`\n :host {\n position: relative;\n display: block;\n }\n .field {\n display: flex;\n gap: var(--spacing-small, 4px);\n align-items: center;\n }\n input {\n flex: 1;\n min-width: 0;\n box-sizing: border-box;\n height: var(--form-element-height-medium, 32px);\n padding: 0 var(--spacing-medium, 8px);\n border: var(--input-field-border, 1px solid var(--md-sys-color-outline));\n border-radius: var(--input-field-border-radius, var(--md-sys-shape-corner-small, 4px));\n background: var(--input-field-background, var(--md-sys-color-surface-container-highest));\n font: inherit;\n font-size: var(--ui-t-body, 13px);\n color: var(--ui-ink, var(--md-sys-color-on-surface));\n }\n input:focus-visible {\n outline: none;\n border-color: var(--md-sys-color-primary);\n }\n ul {\n position: absolute;\n z-index: 10;\n left: 0;\n right: 0;\n top: calc(100% + 2px);\n max-height: 260px;\n overflow-y: auto;\n margin: 0;\n padding: var(--spacing-small, 4px) 0;\n list-style: none;\n border: 1px solid var(--md-sys-color-outline-variant);\n border-radius: var(--ui-r, 10px);\n background: var(--md-sys-color-surface-container-lowest);\n box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);\n }\n li {\n display: flex;\n justify-content: space-between;\n gap: var(--spacing-large, 12px);\n padding: 6px var(--spacing-large, 12px);\n cursor: pointer;\n font-size: var(--ui-t-body, 13px);\n color: var(--ui-ink, var(--md-sys-color-on-surface));\n }\n li:hover,\n li[active] {\n background: var(--md-sys-color-surface-container-high);\n }\n li small {\n white-space: nowrap;\n }\n li small,\n li.none {\n color: var(--ui-muted, var(--md-sys-color-on-surface-variant));\n }\n li.none {\n cursor: default;\n }\n li.register {\n border-top: 1px solid var(--md-sys-color-outline-variant);\n color: var(--ui-accent, var(--md-sys-color-primary));\n }\n `\n ]\n\n /** The party chosen, shown as the field's placeholder until something is typed. */\n @property({ attribute: false }) party: CounterpartyPick | null = null\n @property({ type: Boolean }) disabled = false\n\n @state() private search = ''\n /** The words the list is found by - undefined while no list is open. */\n @state() private finding?: string\n @state() private active = 0\n /** Whether this seat may register a counterparty - the action under the list shows only then. */\n @state() private mayRegister = false\n\n private timer?: ReturnType<typeof setTimeout>\n /* A name was registered from here: the focus the form hands back does not open the list again - typing or a click does. */\n private registering = false\n\n /* The choices for the words found by - only the answer to the last thing typed is shown, and the list found before\n stays while the next is read (ADR-0190). */\n private choices = new QueryController(this, CHOICES, {\n keepPrevious: true,\n variables: () =>\n this.finding === undefined || this.disabled ? undefined : { search: this.finding.trim() || undefined, pagination: { page: 1, limit: 30 } }\n })\n\n /** The list under the field: what was found, or null while it is closed or not read. */\n async connectedCallback() {\n super.connectedCallback()\n this.mayRegister = await mayRegisterCounterparty()\n }\n\n /** The words a new counterparty would be registered under - shown under the list when this seat may register. */\n private get newName(): string {\n return this.mayRegister && this.found ? this.search.trim() : ''\n }\n\n private get found(): CounterpartyPick[] | null {\n if (this.finding === undefined || !this.choices.data) return null\n return this.choices.data.counterparties?.items ?? []\n }\n\n render() {\n return html`\n <div class=\"field\">\n <input\n .value=${this.search}\n placeholder=${this.party?.name ?? i18next.t('text.counterparty-search')}\n aria-label=${i18next.t('field.counterparty')}\n ?disabled=${this.disabled}\n @focus=${() => !this.registering && this.find()}\n @mousedown=${() => (this.registering = false)}\n @input=${(e: any) => ((this.registering = false), (this.search = e.target.value), this.findSoon())}\n @keydown=${(e: KeyboardEvent) => this.key(e)}\n @blur=${() => setTimeout(() => (this.finding = undefined), 150)}\n />\n ${this.party && !this.disabled\n ? html`<button quiet icon-only title=${i18next.t('button.counterparty-clear')} aria-label=${i18next.t('button.counterparty-clear')} @click=${() => this.choose(null)}>\n <md-icon>close</md-icon>\n </button>`\n : nothing}\n </div>\n ${this.found\n ? html`<ul role=\"listbox\">\n ${this.found.length\n ? this.found.map(\n (one, index) =>\n html`<li role=\"option\" ?active=${index === this.active} @mousedown=${(e: Event) => (e.preventDefault(), this.choose(one))}>\n <span>${one.name}</span>${one.businessNumber ? html`<small>${one.businessNumber}</small>` : nothing}\n </li>`\n )\n : html`<li class=\"none\">${i18next.t('text.counterparty-none')}</li>`}\n ${this.newName\n ? html`<li role=\"option\" class=\"register\" ?active=${this.active === this.found.length} @mousedown=${(e: Event) => (e.preventDefault(), this.register())}>\n <span>${i18next.t('button.counterparty-register-named', { name: this.newName })}</span>\n </li>`\n : nothing}\n </ul>`\n : nothing}\n `\n }\n\n private findSoon() {\n clearTimeout(this.timer)\n this.timer = setTimeout(() => this.find(), 250)\n }\n\n private find() {\n if (this.disabled) return\n this.finding = this.search\n this.active = 0\n }\n\n private key(e: KeyboardEvent) {\n const last = (this.found?.length ?? 0) + (this.newName ? 1 : 0) - 1\n if (last < 0 || e.isComposing) return\n if (e.key === 'ArrowDown') this.active = Math.min(this.active + 1, last)\n else if (e.key === 'ArrowUp') this.active = Math.max(this.active - 1, 0)\n else if (e.key === 'Enter') this.active < this.found!.length ? this.choose(this.found![this.active]) : this.register()\n else if (e.key === 'Escape') this.finding = undefined\n else return\n e.preventDefault()\n }\n\n /** Register the name typed and take it - or the counterparty of that name the form led to. */\n private async register() {\n const name = this.newName\n this.finding = undefined\n this.registering = true\n const registered = await registerCounterparty(name)\n if (registered) this.choose(registered)\n }\n\n private choose(party: CounterpartyPick | null) {\n this.search = ''\n this.finding = undefined\n this.dispatchEvent(new CustomEvent('counterparty', { detail: party, bubbles: true, composed: true }))\n }\n}\n"]}
|