Skip to content

Commit 29fbc32

Browse files
committed
Inriver integration
1 parent 32d3506 commit 29fbc32

File tree

9 files changed

+187
-100
lines changed

9 files changed

+187
-100
lines changed

src/Umbraco.Cms.Integrations.PIM.Inriver/App_Plugins/UmbracoCms.Integrations/PIM/Inriver/css/inriver.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,14 @@
1818
transform: translate(-70%,-70%);
1919
z-index: 1;
2020
}
21+
22+
.inriver-center {
23+
display: block;
24+
margin: auto;
25+
width: 50%;
26+
padding: 10px;
27+
}
28+
29+
.inriver-search {
30+
width:70%;
31+
}

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

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
vm.loading = false;
66
vm.entities = [];
7+
vm.filteredEntities = [];
8+
vm.searchTerm = "";
79

810
vm.pagination = {
911
pageNumber: 1,
@@ -13,6 +15,38 @@
1315

1416
query();
1517

18+
function registerListeners() {
19+
var paginationCtrl = document.querySelector("uui-pagination");
20+
paginationCtrl.setAttribute("current", 1);
21+
paginationCtrl.setAttribute("total", vm.pagination.totalPages);
22+
paginationCtrl.addEventListener("change", function () {
23+
vm.filteredEntities = vm.entities
24+
.slice((paginationCtrl.current - 1) * vm.pagination.itemsPerPage, paginationCtrl.current * vm.pagination.itemsPerPage);
25+
});
26+
27+
var inSearch = document.getElementById("inSearch");
28+
inSearch.addEventListener("change", function () {
29+
console.log(inSearch.value);
30+
});
31+
}
32+
33+
vm.search = search;
34+
function search() {
35+
var inSearch = document.getElementById("inSearch");
36+
var paginationCtrl = document.querySelector("uui-pagination");
37+
38+
if (inSearch.length == 0) return false;
39+
40+
let filteredArr = vm.entities.filter(obj => obj.displayName.includes(inSearch.value));
41+
vm.filteredEntities = filteredArr
42+
.slice((paginationCtrl.current - 1) * vm.pagination.itemsPerPage, paginationCtrl.current * vm.pagination.itemsPerPage);
43+
vm.pagination.totalPages = Math.ceil(filteredArr.length / vm.pagination.itemsPerPage);
44+
45+
console.log(vm.pagination.totalPages);
46+
47+
paginationCtrl.setAttribute("total", vm.pagination.totalPages);
48+
}
49+
1650
function query() {
1751

1852
var entityTypeId = $scope.model.configuration.entityType;
@@ -21,25 +55,23 @@
2155
vm.loading = true;
2256
umbracoCmsIntegrationsPimInriverResource.query(entityTypeId, fieldTypeIds).then(function (response) {
2357

24-
console.log(response);
25-
26-
//if (response.success) {
27-
// let data = [];
28-
// for (var i = 0; i < response.data.entityIds.length; i++) {
29-
// umbracoCmsIntegrationsPimInriverResource.getEntitySummary(response.data.entityIds[i]).then(function (summaryResponse) {
30-
// var entity = {
31-
// id: summaryResponse.data.id,
32-
// displayName: summaryResponse.data.displayName,
33-
// description: summaryResponse.data.description,
34-
// displayFields: summaryResponse.data.fields.filter(obj => {
35-
// var index = $scope.model.configuration.displayFieldTypeIds.indexOf(obj.fieldTypeId);
36-
// if (index > -1) return obj;
37-
// })
38-
// };
39-
// //vm.entities.push(entity);
40-
// });
41-
// }
42-
//}
58+
if (response.success) {
59+
vm.entities = response.data.map(obj => {
60+
return {
61+
id: obj.entityId,
62+
displayName: obj.summary.displayName,
63+
description: obj.summary.description,
64+
displayFields: obj.fieldValues
65+
};
66+
});
67+
68+
vm.pagination.totalPages = Math.ceil(vm.entities.length / vm.pagination.itemsPerPage);
69+
70+
vm.filteredEntities = vm.entities.slice(0, vm.pagination.itemsPerPage);
71+
72+
registerListeners();
73+
} else
74+
notificationsService.error("Inriver", response.error);
4375

4476
vm.loading = false;
4577
});

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,40 @@
22
<umb-load-indicator ng-if="vm.loading">
33
</umb-load-indicator>
44
<uui-box headline="{{model.title}}" class="inriver-container">
5-
<uui-scroll-container style="width:100%">
6-
<uui-form>
7-
<uui-form-layout-item ng-if="vm.entities.length > 0">
8-
5+
<div>
6+
<uui-icon-registry-essential>
7+
<uui-input id="inSearch" class="inriver-search" label="search" placeholder="Enter a name to search...">
8+
</uui-input>
9+
<uui-button type="button" label="Search" look="primary" color="positive" ng-click="vm.search()">
10+
<uui-icon name="search"></uui-icon>
11+
</uui-button>
12+
</uui-icon-registry-essential>
13+
</div>
14+
<uui-scroll-container class="mt2" style="width:100%">
15+
<uui-form ng-if="vm.filteredEntities.length > 0">
16+
<uui-form-layout-item>
917
<uui-table class="uui-text">
1018
<uui-table-column style="width: 120px !important"></uui-table-column>
1119
<uui-table-head>
1220
<uui-table-head-cell>Name</uui-table-head-cell>
1321
<uui-table-head-cell>Description</uui-table-head-cell>
14-
<uui-table-head-cell ng-repeat="displayField in vm.entities[0].displayFields">{{displayField.fieldTypeId}}</uui-table-head-cell>
22+
<uui-table-head-cell ng-repeat="displayField in vm.filteredEntities[0].displayFields">{{displayField.fieldTypeId}}</uui-table-head-cell>
1523
</uui-table-head>
1624

17-
<uui-table-row ng-repeat="entity in vm.entities" selectable ng-on-selected="vm.save(entity.id)">
25+
<uui-table-row ng-repeat="entity in vm.filteredEntities" selectable
26+
ng-on-selected="vm.save(entity.id)">
1827
<uui-table-cell>{{entity.displayName}}</uui-table-cell>
1928
<uui-table-cell>{{entity.description}}</uui-table-cell>
2029
<uui-table-cell ng-repeat="displayField in entity.displayFields">
2130
{{displayField.value | date : "dd.MM.y HH:mm"}}
2231
</uui-table-cell>
2332
</uui-table-row>
2433
</uui-table>
25-
{{vm.pagination.totalPages}}
26-
<uui-pagination ng-on-change="alert('aaa')" total={{vm.pagination.totalPages}}></uui-pagination>
2734
</uui-form-layout-item>
2835
</uui-form>
36+
<div ng-show="!vm.loading" class="inriver-center">
37+
<uui-pagination></uui-pagination>
38+
</div>
2939
</uui-scroll-container>
3040
</uui-box>
3141
<umb-editor-footer>

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,5 @@ public class Constants
88
public const string SettingsPath = "Umbraco:Cms:Integrations:PIM:Inriver:Settings";
99

1010
public const string InriverClient = "InriverClient";
11-
12-
public const string InriverFetchClient = "InriverFetchClient";
1311
}
1412
}

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

Lines changed: 86 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ public async Task<IActionResult> GetEntityTypes()
4040
[HttpPost]
4141
public async Task<IActionResult> Query([FromBody] QueryRequest request)
4242
{
43-
var x = await _inriverService.FetchData(new FetchDataRequest
44-
{
45-
EntityIds = new int[] { 7,8,9},
46-
FieldTypeIds = "TaskName,TaskDescription"
47-
});
48-
4943
var result = await _inriverService.Query(new QueryRequest
5044
{
5145
SystemCriteria = new List<Criterion>
@@ -54,13 +48,97 @@ public async Task<IActionResult> Query([FromBody] QueryRequest request)
5448
}
5549
});
5650

57-
var dataResult = await _inriverService.FetchData(new FetchDataRequest
51+
if(result.Failure) return new JsonResult(ServiceResponse<IEnumerable<EntityData>>.Fail(result.Error));
52+
53+
var data = await _inriverService.FetchData(new FetchDataRequest
5854
{
5955
EntityIds = result.Data.EntityIds,
6056
FieldTypeIds = request.FieldTypeIds
6157
});
6258

63-
return new JsonResult(result);
59+
var dataResult = new List<EntityData>
60+
{
61+
new EntityData {
62+
EntityId = 7,
63+
Summary = new EntitySummary{ DisplayName = "Task1" , Description = "This is my task"} ,
64+
Fields = new List<FieldValue>
65+
{
66+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
67+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
68+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
69+
new FieldValue { FieldTypeId = "Test", Value = "Task" }
70+
}
71+
},
72+
new EntityData {
73+
EntityId = 7,
74+
Summary = new EntitySummary{ DisplayName = "Task2" , Description = "This is my task"} ,
75+
Fields = new List<FieldValue>
76+
{
77+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
78+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
79+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
80+
new FieldValue { FieldTypeId = "Test", Value = "Task" }
81+
}
82+
},
83+
new EntityData {
84+
EntityId = 7,
85+
Summary = new EntitySummary{ DisplayName = "Task3" , Description = "This is my task"} ,
86+
Fields = new List<FieldValue>
87+
{
88+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
89+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
90+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
91+
new FieldValue { FieldTypeId = "Test", Value = "Task" }
92+
}
93+
},
94+
new EntityData {
95+
EntityId = 7,
96+
Summary = new EntitySummary{ DisplayName = "Task4" , Description = "This is my task"} ,
97+
Fields = new List<FieldValue>
98+
{
99+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
100+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
101+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
102+
new FieldValue { FieldTypeId = "Test", Value = "Task" }
103+
}
104+
},
105+
new EntityData {
106+
EntityId = 7,
107+
Summary = new EntitySummary{ DisplayName = "Task5" , Description = "This is my task"} ,
108+
Fields = new List<FieldValue>
109+
{
110+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
111+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
112+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
113+
new FieldValue { FieldTypeId = "Test", Value = "Task" }
114+
}
115+
},
116+
new EntityData {
117+
EntityId = 7,
118+
Summary = new EntitySummary{ DisplayName = "Task6" , Description = "This is my task"} ,
119+
Fields = new List<FieldValue>
120+
{
121+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
122+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
123+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
124+
new FieldValue { FieldTypeId = "Test", Value = "Task" }
125+
}
126+
},
127+
new EntityData {
128+
EntityId = 7,
129+
Summary = new EntitySummary{ DisplayName = "Task7" , Description = "This is my task"} ,
130+
Fields = new List<FieldValue>
131+
{
132+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
133+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
134+
new FieldValue { FieldTypeId = "Test", Value = "Task" },
135+
new FieldValue { FieldTypeId = "Test", Value = "Task" }
136+
}
137+
}
138+
139+
};
140+
141+
return new JsonResult(ServiceResponse<IEnumerable<EntityData>>.Ok(dataResult));
64142
}
65143

66144
[HttpPost]
@@ -70,23 +148,5 @@ public async Task<IActionResult> FetchData([FromBody] FetchDataRequest request)
70148

71149
return new JsonResult(result);
72150
}
73-
74-
//[HttpGet]
75-
//public async Task<IActionResult> GetEntitySummary(int id)
76-
//{
77-
// var results = await _inriverService.GetEntitySummary(id);
78-
// if(results.Success)
79-
// {
80-
// var fields = await _inriverService.GetEntityFieldValues(id);
81-
// if(fields.Success)
82-
// {
83-
// results.Data.Fields = fields.Data;
84-
// }
85-
// }
86-
87-
// return new JsonResult(results);
88-
//}
89-
90-
91151
}
92152
}

src/Umbraco.Cms.Integrations.PIM.Inriver/Editors/EntityPickerValueConverter.cs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Umbraco.Cms.Core.PropertyEditors;
44

55
using Umbraco.Cms.Integrations.PIM.Inriver;
6+
using Umbraco.Cms.Integrations.PIM.Inriver.Models;
67
using Umbraco.Cms.Integrations.PIM.Inriver.Models.ViewModels;
78
using Umbraco.Cms.Integrations.PIM.Inriver.Services;
89

@@ -30,34 +31,29 @@ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPub
3031
return null;
3132
}
3233

33-
var vm = new InriverEntityViewModel();
34-
3534
var node = JsonNode.Parse(source.ToString());
3635

3736
int entityId = (int) node["entityId"];
3837

3938
var displayFields = node["displayFields"] as JsonArray;
4039

41-
//var entitySummary = _inriverService.GetEntitySummary(entityId).ConfigureAwait(false).GetAwaiter().GetResult();
42-
43-
//if (entitySummary.Failure) return null;
44-
45-
//var vm = new InriverEntityViewModel
46-
//{
47-
// DisplayName = entitySummary.Data.DisplayName,
48-
// DisplayDescription = entitySummary.Data.Description
49-
//};
40+
var fetchDataResponse = _inriverService.FetchData(new FetchDataRequest
41+
{
42+
EntityIds = new[] { entityId },
43+
FieldTypeIds = string.Join(",", displayFields.Select(p => p.GetValue<string>()))
44+
}).ConfigureAwait(false).GetAwaiter().GetResult();
5045

51-
//var entityFieldValues = _inriverService.GetEntityFieldValues(entityId)
52-
// .ConfigureAwait(false).GetAwaiter().GetResult();
53-
//if (entityFieldValues.Failure) return vm;
46+
if (fetchDataResponse.Failure) return null;
5447

55-
//foreach(var displayField in displayFields)
56-
//{
57-
// var field = entityFieldValues.Data.First(p => p.FieldTypeId == displayField.GetValue<string>());
48+
var entityData = fetchDataResponse.Data.FirstOrDefault();
49+
if (entityData == null) return null;
5850

59-
// vm.Fields.Add(field.FieldTypeId, field.Value);
60-
//}
51+
var vm = new InriverEntityViewModel
52+
{
53+
DisplayName = entityData.Summary.DisplayName,
54+
DisplayDescription = entityData.Summary.Description,
55+
Fields = entityData.Fields.ToDictionary(x => x.FieldTypeId, x => x.Value)
56+
};
6157

6258
return vm;
6359
}

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,7 @@ public void Compose(IUmbracoBuilder builder)
1818
builder.Services
1919
.AddHttpClient(Constants.InriverClient, client =>
2020
{
21-
client.BaseAddress = new Uri($"{builder.Config.GetSection(Constants.SettingsPath)[nameof(InriverSettings.ApiBaseUrl)]}api/v1.0.0/");
22-
client.DefaultRequestHeaders
23-
.Add("X-inRiver-APIKey", builder.Config.GetSection(Constants.SettingsPath)[nameof(InriverSettings.ApiKey)]);
24-
});
25-
builder.Services
26-
.AddHttpClient(Constants.InriverFetchClient, client =>
27-
{
28-
client.BaseAddress = new Uri($"{builder.Config.GetSection(Constants.SettingsPath)[nameof(InriverSettings.ApiBaseUrl)]}api/v1.0.1/");
21+
client.BaseAddress = new Uri($"{builder.Config.GetSection(Constants.SettingsPath)[nameof(InriverSettings.ApiBaseUrl)]}");
2922
client.DefaultRequestHeaders
3023
.Add("X-inRiver-APIKey", builder.Config.GetSection(Constants.SettingsPath)[nameof(InriverSettings.ApiKey)]);
3124
});

src/Umbraco.Cms.Integrations.PIM.Inriver/Models/EntityData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class EntityData
1010
[JsonPropertyName("summary")]
1111
public EntitySummary Summary { get; set; }
1212

13-
[JsonPropertyName("fields")]
13+
[JsonPropertyName("fieldValues")]
1414
public IEnumerable<FieldValue> Fields { get; set; }
1515
}
1616
}

0 commit comments

Comments
 (0)