Skip to content

Commit 1d0a0a6

Browse files
committed
Form picker and rendering component.
1 parent db09508 commit 1d0a0a6

18 files changed

+208
-31
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@using Umbraco.Cms.Integrations.Crm.Dynamics.Models.ViewModels;
2+
3+
@inherits Umbraco.Web.Mvc.UmbracoViewPage<FormViewModel>
4+
5+
@Html.Raw(Model.EmbedCode)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@using Umbraco.Cms.Integrations.Crm.Dynamics.Models.ViewModels;
2+
3+
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<FormViewModel>
4+
5+
<p>@Model.Name</p>

src/Umbraco.Cms.Integrations.Crm.Dynamics/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/js/configuration.controller.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
vm.oauthConfig = {};
55

66
umbracoCmsIntegrationsCrmDynamicsResource.checkOAuthConfiguration().then(function(response) {
7-
8-
if (response) {
7+
if (response && response.isAuthorized) {
98
vm.oauthConfig.isConnected = true;
109
vm.oauthConfig.fullName = response.fullName;
1110
}

src/Umbraco.Cms.Integrations.Crm.Dynamics/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/js/dynamics.resource.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
$http.get(`${apiEndpoint}/GetForms`),
3030
"Failed");
3131
},
32+
getEmbedCode: function (formId) {
33+
return umbRequestHelper.resourcePromise(
34+
$http.get(`${apiEndpoint}/GetEmbedCode?formId=${formId}`),
35+
"Failed");
36+
},
3237
checkOAuthConfiguration: function () {
3338
return umbRequestHelper.resourcePromise(
3439
$http.get(`${apiEndpoint}/CheckOAuthConfiguration`),

src/Umbraco.Cms.Integrations.Crm.Dynamics/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/js/formpicker.controller.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
function formPickerController($scope, editorService, notificationsService, umbracoCmsIntegrationsCrmDynamicsResource) {
2+
23
var vm = this;
34

45
vm.loading = false;
56
vm.dynamicsFormsList = [];
67
vm.searchTerm = "";
78

8-
loadForms();
9+
umbracoCmsIntegrationsCrmDynamicsResource.checkOAuthConfiguration().then(function (response) {
10+
if (response.isAuthorized) {
11+
loadForms();
12+
} else {
13+
let error = "Unable to connect to Dynamics. Please review the settings of the form picker property's data type.";
14+
notificationsService.error("Dynamics API", error);
15+
vm.error = error;
16+
}
17+
});
18+
19+
vm.saveForm = function (form) {
20+
21+
umbracoCmsIntegrationsCrmDynamicsResource.getEmbedCode(form.id).then(function (response) {
22+
23+
form.embedCode = response;
24+
25+
$scope.model.value = form;
26+
});
27+
}
28+
29+
vm.removeForm = function () {
30+
$scope.model.value = null;
31+
}
932

1033
vm.openDynamicsFormPickerOverlay = function () {
1134

@@ -15,7 +38,7 @@
1538
view: "/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/views/formpickereditor.html",
1639
size: "medium",
1740
selectForm: function (form) {
18-
//vm.saveForm(form);
41+
vm.saveForm(form);
1942

2043
editorService.close();
2144
},
@@ -33,10 +56,10 @@
3356
response.value.forEach(item => {
3457
vm.dynamicsFormsList.push({
3558
id: item.msdyncrm_marketingformid,
36-
name: item.msdyncrm_name
59+
name: item.msdyncrm_name,
60+
embedCode: ""
3761
});
3862
});
39-
console.log(vm.dynamicsFormsList);
4063
}
4164
});
4265
}

src/Umbraco.Cms.Integrations.Crm.Dynamics/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/views/formpicker.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55

66
<umb-node-preview ng-if="model.value"
77
name="model.value.name"
8-
icon="model.icon"
9-
description="model.value.fields"
108
allow-remove="true" ,
11-
on-remove="vm.remove()">
9+
on-remove="vm.removeForm()">
1210
</umb-node-preview>
1311

1412
<a ng-if="!model.value && !vm.loading"

src/Umbraco.Cms.Integrations.Crm.Dynamics/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/views/formpickereditor.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</div>
1313
<div class="dynOverlayGroup">
1414
<ul class="dynFormsList">
15-
<li ng-repeat="form in vm.dynamicsFormsList | orderBy:'name' | filter:vm.searchTerm" ng-click="model.pickForm(form)" class="ng-scope" role="button" tabindex="0">
15+
<li ng-repeat="form in vm.dynamicsFormsList | orderBy:'name' | filter:vm.searchTerm" ng-click="model.selectForm(form)" class="ng-scope" role="button" tabindex="0">
1616
<a href="" ng-attr-title="form.name">
1717
<i class="icon-umb-contour"></i>
1818
<span class="formLine">{{form.name}}</span>

src/Umbraco.Cms.Integrations.Crm.Dynamics/Controllers/FormsController.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using Umbraco.Cms.Integrations.Crm.Dynamics.Configuration;
2323
using Umbraco.Cms.Integrations.Crm.Dynamics.Models.Dtos;
2424
using Umbraco.Cms.Integrations.Crm.Dynamics.Services;
25+
using System.Linq;
2526

2627
namespace Umbraco.Cms.Integrations.Crm.Dynamics.Controllers
2728
{
@@ -47,8 +48,8 @@ public FormsController(IOptions<DynamicsSettings> options, IAuthorizationService
4748
DynamicsService dynamicsService,
4849
DynamicsConfigurationService dynamicsConfigurationService)
4950
#else
50-
public FormsController(IAuthorizationService authorizationService,
51-
DynamicsService dynamicsService,
51+
public FormsController(IAuthorizationService authorizationService,
52+
DynamicsService dynamicsService,
5253
DynamicsConfigurationService dynamicsConfigurationService)
5354
#endif
5455
{
@@ -69,7 +70,20 @@ public FormsController(IAuthorizationService authorizationService,
6970
public string GetAuthorizationUrl() => _authorizationService.GetAuthorizationUrl();
7071

7172
[HttpGet]
72-
public OAuthConfigurationDto CheckOAuthConfiguration() => _dynamicsConfigurationService.GetOAuthConfiguration();
73+
public async Task<OAuthConfigurationDto> CheckOAuthConfiguration()
74+
{
75+
var oauthConfiguration = _dynamicsConfigurationService.GetOAuthConfiguration();
76+
77+
if (oauthConfiguration == null) return new OAuthConfigurationDto();
78+
79+
var identity = await _dynamicsService.GetIdentity(oauthConfiguration.AccessToken);
80+
81+
if (!identity.IsAuthorized) return new OAuthConfigurationDto();
82+
83+
oauthConfiguration.IsAuthorized = true;
84+
85+
return oauthConfiguration;
86+
}
7387

7488
[HttpPost]
7589
public async Task<string> GetAccessToken([FromBody] OAuthRequestDto authRequestDto)
@@ -99,8 +113,8 @@ public async Task<string> GetAccessToken([FromBody] OAuthRequestDto authRequestD
99113

100114
var identity = await _dynamicsService.GetIdentity(tokenDto.AccessToken);
101115

102-
if(identity != null)
103-
_dynamicsConfigurationService.AddorUpdateOAuthConfiguration(tokenDto.AccessToken, identity.UserId, identity.FullName);
116+
if (identity != null)
117+
_dynamicsConfigurationService.AddorUpdateOAuthConfiguration(tokenDto.AccessToken, identity.UserId, identity.FullName);
104118

105119
return result;
106120
}
@@ -138,6 +152,9 @@ public async Task<ResponseDto<FormDto>> GetForms()
138152
return JsonConvert.DeserializeObject<ResponseDto<FormDto>>(result);
139153
}
140154

155+
[HttpGet]
156+
public async Task<string> GetEmbedCode(string formId) => await _dynamicsService.GetEmbedCode(formId);
157+
141158
[HttpGet]
142159
public string GetSystemUserFullName() => _dynamicsConfigurationService.GetSystemUserFullName();
143160

src/Umbraco.Cms.Integrations.Crm.Dynamics/DynamicsFormPickerPropertyEditor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ namespace Umbraco.Cms.Integrations.Crm.Dynamics
1313
name: "Dynamics Form Picker",
1414
view: "~/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/views/formpicker.html",
1515
Group = "Pickers",
16-
Icon = "icon-handshake"
16+
Icon = "icon-handshake",
17+
ValueType = ValueTypes.Json
1718
)]
1819
public class DynamicsFormPickerPropertyEditor : DataEditor
1920
{
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Linq;
3+
4+
using System;
5+
6+
using Umbraco.Cms.Integrations.Crm.Dynamics.Models.ViewModels;
7+
using Umbraco.Cms.Integrations.Crm.Dynamics.Services;
8+
9+
#if NETCOREAPP
10+
using Microsoft.Extensions.Options;
11+
12+
using Umbraco.Cms.Core.PropertyEditors;
13+
using Umbraco.Cms.Core.Models.PublishedContent;
14+
#else
15+
using Umbraco.Core.Models.PublishedContent;
16+
using Umbraco.Core.PropertyEditors;
17+
#endif
18+
19+
namespace Umbraco.Cms.Integrations.Crm.Dynamics.Editors
20+
{
21+
public class DynamicsFormPickerValueConverter : PropertyValueConverterBase
22+
{
23+
public override bool IsConverter(IPublishedPropertyType propertyType) => propertyType.EditorAlias.Equals("Umbraco.Cms.Integrations.Crm.Dynamics.FormPicker");
24+
25+
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType) => PropertyCacheLevel.Snapshot;
26+
27+
public override Type GetPropertyValueType(IPublishedPropertyType propertyType) => typeof(FormViewModel);
28+
29+
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
30+
{
31+
if (source == null) return null;
32+
33+
return JsonConvert.DeserializeObject<FormViewModel>(source.ToString());
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)