Skip to content

Commit 6b1e2a3

Browse files
committed
Linked items updates and refactoring.
1 parent 81fb4ea commit 6b1e2a3

File tree

16 files changed

+187
-48
lines changed

16 files changed

+187
-48
lines changed

src/Umbraco.Cms.Integrations.PIM.Inriver/App_Plugins/UmbracoCms.Integrations/PIM/Inriver/Render/InriverEntity.cshtml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Integrations.PIM.Inriver.Models.ViewModels.InriverEntityViewModel>
22

33
<div>
4-
<img src="@Model.ResourceUrl" alt="@Model.ResourceUrl" />
4+
<img src="@Model.ResourceUrl" alt="@Model.ResourceUrl" width="100" />
55
<p>@Model.DisplayName</p>
66
<p>@Model.DisplayDescription</p>
77
@if (Model.Fields.Any())
88
{
99
<ul>
1010
@foreach (var field in Model.Fields)
1111
{
12-
<li><b>@field.Key</b>: @field.Value</li>
12+
<li>
13+
<b>@field.FieldTypeId</b>: @field.Value
14+
@field.Display
15+
</li>
1316
}
1417
</ul>
1518
}

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

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,50 @@
55

66
vm.configuration = {};
77

8-
vm.entityTypes = [];
9-
vm.fieldTypes = [];
10-
11-
vm.selectedEntityType = {};
12-
vm.selectedFieldTypes = [];
8+
// object for populating configuration data
9+
vm.data = {
10+
entityTypes: [],
11+
fieldTypes: [],
12+
linkedTypes: []
13+
};
14+
15+
// object for selected data
16+
vm.selectedData = {
17+
entityType: {},
18+
fieldTypes: [],
19+
linkedTypes: []
20+
};
1321

1422
if ($scope.model.value == null) {
1523
$scope.model.value = {
1624
entityType: '',
17-
fieldTypes: []
25+
fieldTypes: [],
26+
linkedTypes: []
1827
};
1928
}
2029
$scope.$on('formSubmitting', function (ev) {
21-
if (vm.selectedEntityType == undefined
22-
|| vm.selectedEntityType.length == 0
23-
|| vm.selectedFieldTypes.length == 0) {
30+
if (vm.selectedData.entityType == undefined
31+
|| vm.selectedData.entityType.length == 0
32+
|| vm.selectedData.fieldTypes.length == 0) {
2433
notificationsService.error("Inriver", "Entity type and display fields are required. Configuration was not saved.");
2534
ev.preventDefault();
2635
return;
2736
} else {
28-
$scope.model.value.entityType = vm.selectedEntityType.value;
29-
$scope.model.value.fieldTypes = vm.selectedFieldTypes;
37+
$scope.model.value = {
38+
entityType: vm.selectedData.entityType.value,
39+
fieldTypes: vm.selectedData.fieldTypes,
40+
linkedTypes: vm.selectedData.linkedTypes
41+
};
3042
}
3143
});
3244

3345
vm.entityTypeChange = function () {
34-
var selectedEntityType = vm.entityTypes.find(obj => obj.value == selEntityTypes.value);
46+
vm.selectedData.entityType = vm.entityTypes.find(obj => obj.value == selEntityTypes.value);;
3547

36-
vm.selectedEntityType = selectedEntityType;
37-
vm.fieldTypes = vm.selectedEntityType.fieldTypes;
48+
vm.data.fieldTypes = vm.selectedData.entityType.fieldTypes;
49+
vm.data.linkedTypes = vm.selectedData.entityType.linkedTypes;
3850

39-
vm.selectedFieldTypes = [];
51+
vm.selectedData.fieldTypes = [];
4052
}
4153

4254
umbracoCmsIntegrationsPimInriverResource.checkApiAccess().then(function (response) {
@@ -50,18 +62,22 @@
5062
var option = {
5163
value: obj.id,
5264
name: obj.name,
53-
fieldTypes: obj.fieldTypes
65+
fieldTypes: obj.fieldTypes,
66+
linkedTypes: obj.outboundLinkTypes
5467
};
5568
if ($scope.model.value !== null && $scope.model.value.entityType == obj.id) {
5669
option.selected = true;
5770

58-
vm.selectedEntityType = option;
71+
vm.selectedData.entityType = option;
5972
}
6073
return option;
6174
});
6275

6376
if ($scope.model.value.fieldTypes != null)
64-
vm.selectedFieldTypes = $scope.model.value.fieldTypes;
77+
vm.selectedData.fieldTypes = $scope.model.value.fieldTypes;
78+
79+
if ($scope.model.value.linkedTypes != null)
80+
vm.selectedData.linkedTypes = $scope.model.value.linkedTypes;
6581

6682
bindValues();
6783
});
@@ -71,23 +87,42 @@
7187

7288
// table rows selection
7389
vm.selectFieldType = function (fieldType) {
74-
vm.selectedFieldTypes.push(fieldType);
90+
vm.selectedData.fieldTypes.push(fieldType);
7591
}
7692

7793
vm.unselectFieldType = function (fieldTypeId) {
78-
vm.selectedFieldTypes = vm.selectedFieldTypes.filter(obj => obj.fieldTypeId != fieldTypeId);
94+
vm.selectedData.fieldTypes = vm.selectedData.fieldTypes.filter(obj => obj.fieldTypeId != fieldTypeId);
95+
}
96+
97+
vm.toggleLinkedType = function (linkedType) {
98+
const chkEl = document.getElementById("chk" + linkedType);
99+
100+
if (chkEl.checked)
101+
vm.selectedData.linkedTypes.push(linkedType);
102+
else
103+
vm.selectedData.linkedTypes = vm.selectedData.linkedTypes.filter(obj => obj != linkedType);
79104
}
80105

81106
function bindValues() {
82107
selEntityTypes.options = vm.entityTypes;
83-
vm.fieldTypes = vm.selectedEntityType.fieldTypes;
108+
vm.data.fieldTypes = vm.selectedData.entityType.fieldTypes;
109+
vm.data.linkedTypes = vm.selectedData.entityType.linkedTypes;
84110

111+
// select field types
85112
if ($scope.model.value.fieldTypes != null) {
86113
$scope.model.value.fieldTypes.forEach(obj => {
87114
umbracoCmsIntegrationsPimInriverService.waitForElement("#tr" + obj.fieldTypeId)
88115
.then(element => element.setAttribute("selected", ""));
89116
});
90117
}
118+
119+
// select linked types
120+
if ($scope.model.value.linkedTypes != null) {
121+
$scope.model.value.linkedTypes.forEach(obj => {
122+
umbracoCmsIntegrationsPimInriverService.waitForElement("#chk" + obj)
123+
.then(element => element.setAttribute("checked", ""));
124+
});
125+
}
91126
}
92127
}
93128

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@
2727
var options = {
2828
title: "Inriver " + $scope.model.config.configuration.entityType,
2929
subtitle: "Select a " + $scope.model.config.configuration.entityType,
30-
configuration: {
31-
entityType: $scope.model.config.configuration.entityType,
32-
fieldTypes: $scope.model.config.configuration.fieldTypes
33-
},
30+
configuration: $scope.model.config.configuration,
3431
view: "/App_Plugins/UmbracoCms.Integrations/PIM/Inriver/views/entitypickereditor.html",
3532
size: "medium",
3633
save: function (entityId) {
@@ -48,7 +45,8 @@
4845
vm.saveEntity = function (entityId) {
4946
$scope.model.value = JSON.stringify({
5047
entityId: entityId,
51-
displayFields: $scope.model.config.configuration.fieldTypes
48+
displayFields: $scope.model.config.configuration.fieldTypes,
49+
linkedTypes: $scope.model.config.configuration.linkedTypes
5250
});
5351

5452
getEntityData(entityId);

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function entityPickerEditorController($scope, editorService, notificationsService, umbracoCmsIntegrationsPimInriverResource) {
1+
function entityPickerEditorController($scope, editorState, notificationsService, umbracoCmsIntegrationsPimInriverResource) {
22

33
var vm = this;
44

@@ -7,6 +7,8 @@
77
vm.filteredEntities = [];
88
vm.searchTerm = "";
99

10+
var currentVariant = editorState.current.variants.find(x => x.active === true);
11+
1012
const inSearch = document.getElementById("inSearch");
1113
const paginationCtrl = document.querySelector("uui-pagination");
1214

@@ -49,11 +51,10 @@
4951

5052
function query() {
5153

52-
var entityTypeId = $scope.model.configuration.entityType;
5354
var fieldTypes = $scope.model.configuration.fieldTypes;
5455

5556
vm.loading = true;
56-
umbracoCmsIntegrationsPimInriverResource.query(entityTypeId, fieldTypes).then(function (response) {
57+
umbracoCmsIntegrationsPimInriverResource.query($scope.model.configuration, currentVariant.language.culture).then(function (response) {
5758
if (response.success) {
5859
vm.entities = response.data.map(obj => {
5960
return {
@@ -93,6 +94,10 @@
9394
vm.save = function (entityId) {
9495
$scope.model.save(entityId);
9596
}
97+
98+
vm.entitiesHaveResources = function () {
99+
return vm.filteredEntities.filter(obj => obj.summary.resourceUrl !== null).length > 0;
100+
}
96101
}
97102

98103
angular.module("umbraco")

src/Umbraco.Cms.Integrations.PIM.Inriver/App_Plugins/UmbracoCms.Integrations/PIM/Inriver/js/inriver.resource.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
return umbRequestHelper.resourcePromise(
1414
$http.get(`${apiEndpoint}/GetEntityTypes`), "Failed to access resource.")
1515
},
16-
query: function (entityTypeId, fieldTypes) {
16+
query: function (configuration, culture) {
1717
return umbRequestHelper.resourcePromise(
1818
$http.post(`${apiEndpoint}/Query`, {
19-
entityTypeId: entityTypeId,
20-
fieldTypes: fieldTypes
19+
entityTypeId: configuration.entityType,
20+
fieldTypes: configuration.fieldTypes,
21+
linkedTypes: configuration.linkedTypes,
22+
culture: culture
2123
}), "Failed to access resource.")
2224
},
2325
fetchData: function (request) {

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<uui-select id="selEntityTypes" label="Entity Types" placeholder="Please select an entity type"
1414
ng-on-change="vm.entityTypeChange()"></uui-select>
1515
</uui-form-layout-item>
16-
<uui-form-layout-item ng-if="vm.fieldTypes.length > 0">
16+
<uui-form-layout-item ng-if="vm.data.fieldTypes.length > 0">
1717
<span style="font-weight:700;font-size:15px;">Field Types:</span>
1818
<div style="margin-bottom: 20px;">
1919
Please select the field types you want to display for the entity.
@@ -26,14 +26,37 @@
2626
</uui-table-head>
2727

2828
<uui-table-row id="tr{{fieldType.fieldTypeId}}"
29-
ng-repeat="fieldType in vm.fieldTypes" selectable
29+
ng-repeat="fieldType in vm.data.fieldTypes" selectable
3030
ng-on-selected="vm.selectFieldType(fieldType)"
3131
ng-on-unselected="vm.unselectFieldType(fieldType.fieldTypeId)">
3232
<uui-table-cell>{{fieldType.fieldTypeId}}</uui-table-cell>
3333
<uui-table-cell>{{fieldType.fieldTypeDisplayName}}</uui-table-cell>
3434
</uui-table-row>
3535
</uui-table>
3636
</uui-form-layout-item>
37+
<uui-form-layout-item ng-if="vm.data.linkedTypes.length > 0">
38+
<span style="font-weight:700;font-size:15px;">Includes:</span>
39+
<div style="margin-bottom: 20px;">
40+
Please select the linked entity you would like to include to retrieve additional data.
41+
</div>
42+
<uui-table class="uui-text">
43+
<uui-table-column style="width: 20%;"></uui-table-column>
44+
<uui-table-column style="width: 80%;"></uui-table-column>
45+
46+
<uui-table-head>
47+
<uui-table-head-cell></uui-table-head-cell>
48+
<uui-table-head-cell>Linked Type</uui-table-head-cell>
49+
</uui-table-head>
50+
51+
<uui-table-row ng-repeat="linkedType in vm.data.linkedTypes">
52+
<uui-table-cell>
53+
<uui-checkbox id="chk{{linkedType}}" ng-on-change="vm.toggleLinkedType(linkedType)"></uui-checkbox>
54+
</uui-table-cell>
55+
<uui-table-cell>{{linkedType}}</uui-table-cell>
56+
</uui-table-row>
57+
58+
</uui-table>
59+
</uui-form-layout-item>
3760
</uui-form>
3861
</div>
3962
</uui-card-content-node>

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
@@ -17,7 +17,7 @@
1717
<uui-table class="uui-text">
1818
<uui-table-column style="width: 120px !important"></uui-table-column>
1919
<uui-table-head>
20-
<uui-table-head-cell></uui-table-head-cell>
20+
<uui-table-head-cell ng-if="vm.entitiesHaveResources()"></uui-table-head-cell>
2121
<uui-table-head-cell>Name</uui-table-head-cell>
2222
<uui-table-head-cell>Description</uui-table-head-cell>
2323
<uui-table-head-cell ng-repeat="field in vm.filteredEntities[0].fields">
@@ -27,8 +27,8 @@
2727

2828
<uui-table-row ng-repeat="entity in vm.filteredEntities" selectable
2929
ng-on-selected="vm.save(entity.id)">
30-
<uui-table-cell>
31-
<img ng-if="entity.summary.resourceUrl.length > 0" ng-src="{{entity.summary.resourceUrl}}" width="100" />
30+
<uui-table-cell ng-if="entity.summary.resourceUrl.length > 0">
31+
<img ng-src="{{entity.summary.resourceUrl}}" width="100" />
3232
</uui-table-cell>
3333
<uui-table-cell>{{entity.summary.displayName}}</uui-table-cell>
3434
<uui-table-cell>{{entity.summary.displayDescription}}</uui-table-cell>

src/Umbraco.Cms.Integrations.PIM.Inriver/Configuration/EditorSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ public class EditorSettings
1111

1212
[JsonProperty("fieldTypes")]
1313
public FieldType[] FieldTypes { get; set; }
14+
15+
[JsonProperty("linkedTypes")]
16+
public string[] LinkedTypes { get; set; }
1417
}
1518
}

src/Umbraco.Cms.Integrations.PIM.Inriver/Controllers/EntityController.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Microsoft.AspNetCore.Mvc;
22
using Microsoft.Extensions.Options;
33

4+
using Umbraco.Cms.Core.Models;
5+
using Umbraco.Cms.Core.Services;
46
using Umbraco.Cms.Integrations.PIM.Inriver.Configuration;
57
using Umbraco.Cms.Integrations.PIM.Inriver.Models;
68
using Umbraco.Cms.Integrations.PIM.Inriver.Services;
@@ -16,11 +18,15 @@ public class EntityController : UmbracoAuthorizedApiController
1618

1719
private readonly IInriverService _inriverService;
1820

19-
public EntityController(IOptions<InriverSettings> options, IInriverService inriverService)
21+
private readonly ILocalizationService _localizationService;
22+
23+
public EntityController(IOptions<InriverSettings> options, IInriverService inriverService, ILocalizationService localizationService)
2024
{
2125
_settings = options.Value;
2226

2327
_inriverService = inriverService;
28+
29+
_localizationService = localizationService;
2430
}
2531

2632
[HttpGet]
@@ -40,6 +46,8 @@ public async Task<IActionResult> GetEntityTypes()
4046
[HttpPost]
4147
public async Task<IActionResult> Query([FromBody] QueryRequest request)
4248
{
49+
var language = _localizationService.GetLanguageByIsoCode(request.Culture);
50+
4351
var result = await _inriverService.Query(new QueryRequest
4452
{
4553
SystemCriteria = new List<Criterion>
@@ -48,14 +56,29 @@ public async Task<IActionResult> Query([FromBody] QueryRequest request)
4856
}
4957
});
5058

51-
if(result.Failure) return new JsonResult(ServiceResponse<IEnumerable<EntityData>>.Fail(result.Error));
59+
if (result.Failure) return new JsonResult(ServiceResponse<IEnumerable<EntityData>>.Fail(result.Error));
5260

5361
var dataResult = await _inriverService.FetchData(new FetchDataRequest
5462
{
5563
EntityIds = result.Data.EntityIds,
56-
FieldTypeIds = string.Join(",", request.FieldTypes.Select(p => p.Id))
64+
FieldTypeIds = string.Empty,
65+
Outbound = request.LinkedTypes != null && request.LinkedTypes.Length > 0
66+
? new Outbound { LinkTypeIds = string.Join(",", request.LinkedTypes) }
67+
: null
5768
});
5869

70+
foreach (var item in dataResult.Data)
71+
{
72+
item.Fields = item.Fields.Where(p => request.FieldTypes.Any(q => q.Id == p.FieldTypeId));
73+
foreach (var field in item.Fields)
74+
{
75+
if (field.ValueDictionary != null)
76+
{
77+
field.Value = field.ValueDictionary.First(p => p.Key == language.CultureInfo.TwoLetterISOLanguageName).Value;
78+
}
79+
}
80+
}
81+
5982
return new JsonResult(dataResult);
6083
}
6184

0 commit comments

Comments
 (0)