Skip to content

Commit 8327d9c

Browse files
committed
V14: Integrations (Dynamics)
- Refactoring
1 parent cddea53 commit 8327d9c

File tree

5 files changed

+102
-50
lines changed

5 files changed

+102
-50
lines changed

src/Umbraco.Cms.Integrations.Crm.Dynamics/Client/src/config/authorization/authorization-property-editor.element.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ export class DynamicsAuthorizationElement extends UmbElementMixin(LitElement){
3838
}
3939

4040
async #checkOAuthConfiguration(){
41-
//const { data } = await this.#dynamicsContext.checkOauthConfiguration();
42-
if (!this.#settingsModel) {
43-
return;
44-
}
41+
if (!this.#settingsModel) return;
4542

4643
if (!this.#settingsModel.isAuthorized) {
4744
this._showError("Unable to connect to Dynamics. Please review the settings of the form picker property's data type.")

src/Umbraco.Cms.Integrations.Crm.Dynamics/Client/src/config/authorization/manifests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const manifests : ManifestPropertyEditorUi = {
44
type: 'propertyEditorUi',
55
alias: 'Dynamics.PropertyEditorUi.Authorization',
66
name: 'Dynamics Form Picker Authorization Setting',
7-
element: () => import('./authorization-property-editor.element.js'),
7+
js: () => import('./authorization-property-editor.element.js'),
88
meta: {
99
label: 'Authorization',
1010
icon: 'icon-autofill',

src/Umbraco.Cms.Integrations.Crm.Dynamics/Client/src/modal/dynamics-form-modal.element.ts

Lines changed: 77 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,35 @@ import { customElement, html, repeat, state } from "@umbraco-cms/backoffice/exte
22
import { UmbModalBaseElement } from "@umbraco-cms/backoffice/modal";
33
import { DynamicsFormPickerModalData, DynamicsFormPickerModalValue } from "./dynamics.modal-token";
44
import { DYNAMICS_CONTEXT_TOKEN } from "../context/dynamics.context";
5-
import { FormDtoModel, OAuthConfigurationDtoModel, OAuthRequestDtoModel } from "@umbraco-integrations/dynamics/generated";
5+
import { DynamicsModuleModel, FormDtoModel, OAuthConfigurationDtoModel } from "@umbraco-integrations/dynamics/generated";
66
import { UMB_NOTIFICATION_CONTEXT, UmbNotificationColor } from "@umbraco-cms/backoffice/notification";
7-
import { DynamicsOAuthSetup } from "../models/dynamics-service.model";
7+
import { UUIInputEvent } from "@umbraco-cms/backoffice/external/uui";
8+
import { UmbPropertyValueChangeEvent } from "@umbraco-cms/backoffice/property-editor";
9+
import { UmbArrayState } from "@umbraco-cms/backoffice/observable-api";
810

911
const elementName = "dynamics-forms-modal";
12+
enum testEnum {
13+
OUTBOUND = "1",
14+
REAL_TIME = "2"
15+
}
1016

1117
@customElement(elementName)
1218
export default class DynamicsFormModalElement extends UmbModalBaseElement<DynamicsFormPickerModalData, DynamicsFormPickerModalValue>{
1319
#dynamicsContext!: typeof DYNAMICS_CONTEXT_TOKEN.TYPE;
1420
#settingsModel?: OAuthConfigurationDtoModel;
21+
//#selectionState: UmbArrayState<FormDtoModel> = [];
1522

1623
@state()
1724
private _loading = false;
1825
@state()
1926
private _forms: Array<FormDtoModel> = [];
27+
@state()
28+
private _filterForms: Array<FormDtoModel> = [];
29+
@state()
30+
private renderWithIFrame: boolean = false;
31+
@state()
32+
private toggleLabel: string = "Render with Script";
33+
2034

2135
constructor() {
2236
super();
@@ -36,15 +50,13 @@ export default class DynamicsFormModalElement extends UmbModalBaseElement<Dynami
3650
}
3751

3852
async #checkOAuthConfiguration(){
39-
4053
if (!this.#settingsModel) {
4154
return;
4255
}
4356

4457
if (!this.#settingsModel.isAuthorized) {
45-
this._showError("Unable to connect to Dynamics. Please review the settings of the form picker property's data type.")
58+
this._showError("Unable to connect to Dynamics. Please review the settings of the form picker property's data type.");
4659
} else {
47-
4860
await this.#getForms();
4961
}
5062
}
@@ -55,12 +67,29 @@ export default class DynamicsFormModalElement extends UmbModalBaseElement<Dynami
5567
if(!data) return;
5668

5769
this._forms = data;
70+
this._filterForms = data;
71+
//this.#selectionState.setValue(data);
5872
this._loading = false;
5973
}
6074

61-
_onSelect(form: FormDtoModel){
62-
this.value = { selectedForm: form };
63-
this._submitModal();
75+
async _onSelect(form: FormDtoModel){
76+
var result = await this.checkEmbed(form);
77+
if (result){
78+
this.value = { selectedForm: form };
79+
this._submitModal();
80+
}
81+
}
82+
83+
async checkEmbed(form: FormDtoModel){
84+
if(this.renderWithIFrame && form.module.toString() === testEnum.REAL_TIME){
85+
var { data } = await this.#dynamicsContext.getEmbedCode(form.id);
86+
if (!data || data.result.length == 0){
87+
this._showError("Unable to embed selected form. Please check if it is live.");
88+
return false;
89+
}
90+
}
91+
92+
return true;
6493
}
6594

6695
private async _showError(message: string) {
@@ -74,25 +103,54 @@ export default class DynamicsFormModalElement extends UmbModalBaseElement<Dynami
74103
});
75104
}
76105

106+
onMessageOnSubmitIsHtmlChange(){
107+
this.renderWithIFrame = !this.renderWithIFrame;
108+
this.toggleLabel = !this.renderWithIFrame ? "Render with Script" : "Render with iFrame";
109+
}
110+
111+
onSearchChange(e: UUIInputEvent){
112+
var searchText = e.target?.value as string;
113+
this._filterForms = this._forms.filter(f => f.name.toLowerCase().includes(searchText.toLowerCase()));
114+
this.dispatchEvent(new UmbPropertyValueChangeEvent());
115+
}
116+
77117
render(){
78118
return html`
79119
<umb-body-layout>
80-
81120
${this._loading ?
82121
html`<div class="center loader"><uui-loader></uui-loader></div>` :
83122
html`
84123
<uui-box headline=${this.data!.headline}>
85-
<div slot="header">Select a form</div>
86-
87-
${repeat(this._forms, (form) => html`
88-
<uui-ref-node-form
89-
selectable
90-
name=${form.name ?? ""}
91-
@selected=${() => this._onSelect(form)}>
92-
</uui-ref-node-form>
93-
`)}
94-
</uui-box>
124+
<div slot="header">Select a form</div>
125+
126+
<uui-input placeholder="Type to search..." @change=${(e: UUIInputEvent) => this.onSearchChange(e)}>
127+
<div slot="append" style="background:#f3f3f3; padding-left:var(--uui-size-2, 6px)">
128+
<uui-icon-registry-essential>
129+
<uui-icon name="search"></uui-icon>
130+
</uui-icon-registry-essential>
131+
</div>
132+
</uui-input>
133+
134+
${this._filterForms.length > 0 ?
135+
html`
136+
${repeat(this._filterForms, (form) => html`
137+
<uui-ref-node-form
138+
selectable
139+
name=${form.name ?? ""}
140+
@selected=${() => this._onSelect(form)}>
141+
</uui-ref-node-form>
142+
`)}
143+
144+
<uui-toggle
145+
?checked=${this.renderWithIFrame}
146+
.label=${this.toggleLabel}
147+
@change=${this.onMessageOnSubmitIsHtmlChange}></uui-toggle>
148+
` :
149+
html``}
150+
</uui-box>
151+
95152
<br />
153+
96154
<uui-box headline="Dynamics - OAuth Status">
97155
<div slot="header">Please connect with your Microsoft account.</div>
98156
<dynamics-authorization></dynamics-authorization>

src/Umbraco.Cms.Integrations.Crm.Dynamics/Client/src/property-editor/dynamics-form-picker-property-editor.element.ts

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ export class DynamicsFormPickerPropertyEditor extends UmbLitElement implements U
5757

5858
if (this.value == null || this.value.length == 0) return;
5959

60-
await this.#checkOAuthConfiguration();
61-
}
62-
63-
async #checkOAuthConfiguration(){
6460
if(!this.#settingsModel) return;
6561
if(!this.#settingsModel.isAuthorized) this._showError("Unable to connect to Dynamics. Please review the settings of the form picker property's data type.");
6662

@@ -72,12 +68,12 @@ export class DynamicsFormPickerPropertyEditor extends UmbLitElement implements U
7268
this.selectedForm = model;
7369
}
7470

75-
deleteForm(formId: string){
76-
71+
#deleteForm(){
72+
this.value = "";
73+
this.dispatchEvent(new CustomEvent('property-value-change'));
7774
}
7875

7976
private async _openModal() {
80-
console.log(this._config?.module);
8177
const module = this._config?.module == "Both" ? "Outbound | Real-Time" : this._config?.module;
8278
const pickerContext = this.#modalManagerContext?.open(this, DYNAMICS_MODAL_TOKEN, {
8379
data: {
@@ -102,24 +98,25 @@ export class DynamicsFormPickerPropertyEditor extends UmbLitElement implements U
10298

10399
render() {
104100
return html`
105-
<div>
106-
<uui-button
107-
class="add-button"
108-
@click=${this._openModal}
109-
label=${this.localize.term('general_add')}
110-
look="placeholder"></uui-button>
111-
</div>
112-
${this.selectedForm ?
113-
html`
114-
<div>
115-
<uui-ref-node-form name=${this.selectedForm!.name}>
116-
<uui-action-bar slot="actions">
117-
<uui-button label="Remove" @click=${() => this.deleteForm(this.selectedForm!.id)}>Remove</uui-button>
118-
</uui-action-bar>
119-
</uui-ref-node-form>
120-
</div>
121-
` :
122-
html``}
101+
${this.value == null || this.value.length == 0 ?
102+
html`
103+
<div>
104+
<uui-button
105+
class="add-button"
106+
@click=${this._openModal}
107+
label=${this.localize.term('general_add')}
108+
look="placeholder"></uui-button>
109+
</div>
110+
` :
111+
html`
112+
<div>
113+
<uui-ref-node-form name=${this.selectedForm?.name ?? ""}>
114+
<uui-action-bar slot="actions">
115+
<uui-button label="Remove" @click=${this.#deleteForm}>Remove</uui-button>
116+
</uui-action-bar>
117+
</uui-ref-node-form>
118+
</div>
119+
`}
123120
`;
124121
}
125122

src/Umbraco.Cms.Integrations.Crm.Dynamics/Client/src/property-editor/manifests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const propertyEditorUiManifest : ManifestPropertyEditorUi = {
55
type: "propertyEditorUi",
66
alias: "Dynamics.PropertyEditorUi.FormPicker",
77
name: "Dynamics Form Picker Property Editor UI",
8-
element: () => import("./dynamics-form-picker-property-editor.element"),
8+
js: () => import("./dynamics-form-picker-property-editor.element"),
99
meta: {
1010
label: "Dynamics Form Picker",
1111
icon: "icon-book",

0 commit comments

Comments
 (0)