Skip to content

Commit 00510a1

Browse files
committed
Rendering component and strongly typed model.
1 parent 1c025b0 commit 00510a1

File tree

10 files changed

+168
-26
lines changed

10 files changed

+168
-26
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Integrations.PIM.Inriver.Models.ViewModels.InriverEntityViewModel>
2+
3+
<p>@Model.DisplayName</p>
4+
<p>@Model.DisplayDescription</p>
5+
@if(Model.Fields.Any())
6+
{
7+
<ul>
8+
@foreach(var field in Model.Fields)
9+
{
10+
<li><b>@field.Key</b>: @field.Value</li>
11+
}
12+
</ul>
13+
}

src/Umbraco.Cms.Integrations.PIM.Inriver/App_Plugins/UmbracoCms.Integrations/PIM/Inriver/js/entitypicker.controller.js

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
function entityPickerController($scope, editorService, notificationsService, umbracoCmsIntegrationsPimInriverResource) {
22

33
var vm = this;
4-
vm.error = '';
4+
5+
vm.selectedEntity = null;
6+
vm.error = "";
57

68
umbracoCmsIntegrationsPimInriverResource.checkApiAccess().then(function (response) {
79
if (response.failure)
810
vm.error = response.data;
911
});
1012

13+
if ($scope.model.value) {
14+
getEntitySummary($scope.model.value.entityId);
15+
}
16+
1117
vm.openInriverEntityPickerOverlay = function () {
1218
var options = {
1319
title: "Inriver Entities",
@@ -18,10 +24,9 @@
1824
},
1925
view: "/App_Plugins/UmbracoCms.Integrations/PIM/Inriver/views/entitypickereditor.html",
2026
size: "medium",
21-
select: function (entity) {
22-
//vm.saveForm(form);
23-
24-
//editorService.close();
27+
save: function (entityId) {
28+
vm.saveEntity(entityId);
29+
editorService.close();
2530
},
2631
close: function () {
2732
editorService.close();
@@ -30,22 +35,30 @@
3035

3136
editorService.open(options);
3237
};
38+
39+
vm.saveEntity = function (entityId) {
40+
$scope.model.value = JSON.stringify({
41+
entityId: entityId,
42+
displayFields: $scope.model.config.configuration.displayFieldTypeIds
43+
});
3344

34-
function closeEditor() {
35-
const dialog = document.getElementById('editorDialog');
36-
dialog.style.display = "none";
45+
getEntitySummary(entityId);
3746
}
3847

39-
//vm.saveForm = function (formId) {
40-
// $scope.model.value = formId;
48+
vm.removeEntity = function () {
49+
$scope.model.value = null;
50+
vm.selectedEntity = null;
51+
}
4152

42-
// getFormDetails(formId);
43-
//}
53+
function getEntitySummary(entityId) {
54+
umbracoCmsIntegrationsPimInriverResource.getEntitySummary(entityId).then(function (response) {
55+
if (response.success) {
56+
vm.selectedEntity = response.data;
4457

45-
//vm.removeForm = function () {
46-
// $scope.model.value = null;
47-
// vm.selectedForm = {};
48-
//}
58+
vm.selectedEntity.detail = $scope.model.config.configuration.displayFieldTypeIds.join(",");
59+
}
60+
});
61+
}
4962

5063
}
5164

src/Umbraco.Cms.Integrations.PIM.Inriver/App_Plugins/UmbracoCms.Integrations/PIM/Inriver/js/entitypickereditor.controller.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
}
2828
});
2929
}
30+
31+
vm.save = function (entityId) {
32+
$scope.model.save(entityId);
33+
}
3034
}
3135

3236
angular.module("umbraco")

src/Umbraco.Cms.Integrations.PIM.Inriver/App_Plugins/UmbracoCms.Integrations/PIM/Inriver/views/entitypicker.html

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
<div ng-controller="Umbraco.Cms.Integrations.PIM.Inriver.EntityPickerController as vm">
2-
<a class="umb-node-preview-add"
3-
ng-click="vm.openInriverEntityPickerOverlay()"
4-
prevent-default>
5-
<localize key="general_add">Add</localize>
6-
</a>
2+
<div ng-if="vm.selectedEntity !== null" style="max-width: 800px;">
3+
<uui-ref-node name="{{vm.selectedEntity.displayName}}"
4+
detail="{{vm.selectedEntity.detail}}">
5+
<uui-action-bar slot="actions">
6+
<uui-button label="Remove" ng-click="vm.removeEntity()">Remove</uui-button>
7+
</uui-action-bar>
8+
</uui-ref-node>
9+
</div>
10+
<div ng-if="vm.selectedEntity === null">
11+
<a class="umb-node-preview-add"
12+
ng-click="vm.openInriverEntityPickerOverlay()"
13+
prevent-default>
14+
<localize key="general_add">Add</localize>
15+
</a>
16+
</div>
717
<div ng-if="vm.error" class="alert alert-warning mt2" style="max-width: 800px;">
818
{{ vm.error }}
919
</div>

src/Umbraco.Cms.Integrations.PIM.Inriver/App_Plugins/UmbracoCms.Integrations/PIM/Inriver/views/entitypickereditor.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
<uui-form>
55
<uui-form-layout-item ng-if="vm.entities.length > 0">
66
<uui-table class="uui-text">
7-
<uui-table-column style="width: 60px;"></uui-table-column>
7+
<uui-table-column style="width: 120px !important"></uui-table-column>
88
<uui-table-head>
99
<uui-table-head-cell>Name</uui-table-head-cell>
1010
<uui-table-head-cell>Description</uui-table-head-cell>
1111
<uui-table-head-cell ng-repeat="displayField in vm.entities[0].displayFields">{{displayField.fieldTypeId}}</uui-table-head-cell>
1212
</uui-table-head>
1313

14-
<uui-table-row ng-repeat="entity in vm.entities" selectable>
15-
<uui-table-cell>{{entity.displayName}}</uui-table-cell>
14+
<uui-table-row ng-repeat="entity in vm.entities" selectable ng-on-selected="vm.save(entity.id)">
15+
<uui-table-cell style="width:30%;">{{entity.displayName}}</uui-table-cell>
1616
<uui-table-cell>{{entity.description}}</uui-table-cell>
1717
<uui-table-cell ng-repeat="displayField in entity.displayFields">{{displayField.value}}</uui-table-cell>
1818
</uui-table-row>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System.Text.Json.Nodes;
2+
using Umbraco.Cms.Core.Models.PublishedContent;
3+
using Umbraco.Cms.Core.PropertyEditors;
4+
5+
using Umbraco.Cms.Integrations.PIM.Inriver;
6+
using Umbraco.Cms.Integrations.PIM.Inriver.Models.ViewModels;
7+
using Umbraco.Cms.Integrations.PIM.Inriver.Services;
8+
9+
namespace Umbraco.Cms.Integrations.Pim.Inriver.Editors
10+
{
11+
public class EntityPickerValueConverter : PropertyValueConverterBase
12+
{
13+
private readonly IInriverService _inriverService;
14+
15+
public EntityPickerValueConverter(IInriverService inriverService)
16+
{
17+
_inriverService = inriverService;
18+
}
19+
20+
public override bool IsConverter(IPublishedPropertyType propertyType) => propertyType.EditorAlias.Equals(Constants.PropertyEditorAlias);
21+
22+
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType) => PropertyCacheLevel.Snapshot;
23+
24+
public override Type GetPropertyValueType(IPublishedPropertyType propertyType) => typeof(InriverEntityViewModel);
25+
26+
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
27+
{
28+
if (source == null)
29+
{
30+
return null;
31+
}
32+
33+
var node = JsonNode.Parse(source.ToString());
34+
35+
int entityId = (int) node["entityId"];
36+
37+
var displayFields = node["displayFields"] as JsonArray;
38+
39+
var entitySummary = _inriverService.GetEntitySummary(entityId).ConfigureAwait(false).GetAwaiter().GetResult();
40+
41+
if (entitySummary.Failure) return null;
42+
43+
var vm = new InriverEntityViewModel
44+
{
45+
DisplayName = entitySummary.Data.DisplayName,
46+
DisplayDescription = entitySummary.Data.Description
47+
};
48+
49+
var entityFieldValues = _inriverService.GetEntityFieldValues(entityId)
50+
.ConfigureAwait(false).GetAwaiter().GetResult();
51+
if (entityFieldValues.Failure) return vm;
52+
53+
foreach(var displayField in displayFields)
54+
{
55+
var field = entityFieldValues.Data.First(p => p.FieldTypeId == displayField.GetValue<string>());
56+
57+
vm.Fields.Add(field.FieldTypeId, field.Value);
58+
}
59+
60+
return vm;
61+
}
62+
}
63+
}
64+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.AspNetCore.Html;
2+
using Microsoft.AspNetCore.Mvc.Rendering;
3+
4+
using Umbraco.Cms.Integrations.PIM.Inriver.Models.ViewModels;
5+
6+
namespace Umbraco.Cms.Integrations.PIM.Inriver.Helpers
7+
{
8+
public static class InriverHtmlExtensions
9+
{
10+
public static IHtmlContent RenderInriverEntity(this IHtmlHelper<dynamic> htmlHelper,
11+
InriverEntityViewModel vm, string renderingViewPath = "")
12+
{
13+
return htmlHelper.Partial(string.IsNullOrEmpty(renderingViewPath)
14+
? "~/App_Plugins/UmbracoCms.Integrations/PIM/Inriver/Render/InriverEntity.cshtml"
15+
: renderingViewPath,
16+
vm ?? new InriverEntityViewModel());
17+
}
18+
}
19+
}

src/Umbraco.Cms.Integrations.PIM.Inriver/InriverComposer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void Compose(IUmbracoBuilder builder)
2323
.Add("X-inRiver-APIKey", builder.Config.GetSection(Constants.SettingsPath)[nameof(InriverSettings.ApiKey)]);
2424
});
2525

26-
builder.Services.AddScoped<IInriverService, InriverService>();
26+
builder.Services.AddSingleton<IInriverService, InriverService>();
2727
}
2828
}
2929
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+

2+
namespace Umbraco.Cms.Integrations.PIM.Inriver.Models.ViewModels
3+
{
4+
public class InriverEntityViewModel
5+
{
6+
public InriverEntityViewModel()
7+
{
8+
Fields = new Dictionary<string, string>();
9+
}
10+
11+
public int Id { get; set; }
12+
13+
public string DisplayName { get; set; }
14+
15+
public string DisplayDescription { get; set; }
16+
17+
public Dictionary<string, string> Fields { get; set; }
18+
}
19+
}

src/Umbraco.Cms.Integrations.PIM.Inriver/Umbraco.Cms.Integrations.PIM.Inriver.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
4343
</Content>
4444
</ItemGroup>
45-
45+
4646
<ItemGroup>
4747
<Content Include="inriver.png">
4848
<Pack>true</Pack>

0 commit comments

Comments
 (0)