Skip to content

Commit d76f90a

Browse files
committed
Fetching data API updates & UI bug fixes
1 parent 29fbc32 commit d76f90a

File tree

6 files changed

+65
-125
lines changed

6 files changed

+65
-125
lines changed

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

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

33
var vm = this;
44

@@ -20,7 +20,7 @@
2020
}
2121

2222
if ($scope.model.value) {
23-
getEntitySummary($scope.model.value.entityId);
23+
getEntityData($scope.model.value.entityId);
2424
}
2525

2626
vm.openInriverEntityPickerOverlay = function () {
@@ -51,23 +51,23 @@
5151
displayFields: $scope.model.config.configuration.displayFieldTypeIds
5252
});
5353

54-
//getEntitySummary(entityId);
54+
getEntityData(entityId);
5555
}
5656

5757
vm.removeEntity = function () {
5858
$scope.model.value = null;
5959
vm.selectedEntity = null;
6060
}
6161

62-
//function getEntitySummary(entityId) {
63-
// umbracoCmsIntegrationsPimInriverResource.getEntitySummary(entityId).then(function (response) {
64-
// if (response.success) {
65-
// vm.selectedEntity = response.data;
66-
67-
// vm.selectedEntity.detail = $scope.model.config.configuration.displayFieldTypeIds.join(",");
68-
// }
69-
// });
70-
//}
62+
function getEntityData(entityId) {
63+
umbracoCmsIntegrationsPimInriverResource.fetchEntityData(entityId).then(function (response) {
64+
if (response.success) {
65+
vm.selectedEntity = response.data[0];
66+
vm.selectedEntity.detail = $scope.model.config.configuration.displayFieldTypeIds.join(",");
67+
} else
68+
vm.error = response.error;
69+
});
70+
}
7171

7272
}
7373

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

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
vm.filteredEntities = [];
88
vm.searchTerm = "";
99

10+
const inSearch = document.getElementById("inSearch");
11+
const paginationCtrl = document.querySelector("uui-pagination");
12+
1013
vm.pagination = {
1114
pageNumber: 1,
1215
itemsPerPage: 3,
@@ -15,36 +18,30 @@
1518

1619
query();
1720

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-
21+
vm.search = () => {
3822
if (inSearch.length == 0) return false;
3923

4024
let filteredArr = vm.entities.filter(obj => obj.displayName.includes(inSearch.value));
4125
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);
26+
.slice((paginationCtrl.current - 1) * vm.pagination.itemsPerPage, paginationCtrl.current * vm.pagination.itemsPerPage);
4427

45-
console.log(vm.pagination.totalPages);
28+
vm.pagination.totalPages = Math.ceil(filteredArr.length / vm.pagination.itemsPerPage);
4629

47-
paginationCtrl.setAttribute("total", vm.pagination.totalPages);
30+
paginationCtrl.total = vm.pagination.totalPages;
31+
32+
/**
33+
* uui-pagination total property is not updating the pagination UI in version of the library lower than 11.0
34+
* */
35+
const umbracoVersionSplit = window.Umbraco.Sys.ServerVariables.application.version.split('.');
36+
if (Number(umbracoVersionSplit[0]) === 10) {
37+
let visiblePagesArr = [];
38+
for (var i = 0; i < vm.pagination.totalPages; i++) {
39+
visiblePagesArr.push(i + 1);
40+
}
41+
42+
paginationCtrl._visiblePages = visiblePagesArr;
43+
paginationCtrl.requestUpdate();
44+
}
4845
}
4946

5047
function query() {
@@ -77,6 +74,15 @@
7774
});
7875
}
7976

77+
function registerListeners() {
78+
paginationCtrl.setAttribute("current", 1);
79+
paginationCtrl.setAttribute("total", vm.pagination.totalPages);
80+
paginationCtrl.addEventListener("change", function () {
81+
vm.filteredEntities = vm.entities
82+
.slice((paginationCtrl.current - 1) * vm.pagination.itemsPerPage, paginationCtrl.current * vm.pagination.itemsPerPage);
83+
});
84+
}
85+
8086
vm.save = function (entityId) {
8187
$scope.model.save(entityId);
8288
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
fetchData: function (request) {
2424
return umbRequestHelper.resourcePromise(
2525
$http.post(`${apiEndpoint}/FetchData`, request), "Failed to access resource.")
26+
},
27+
fetchEntityData: function (entityId) {
28+
return umbRequestHelper.resourcePromise(
29+
$http.get(`${apiEndpoint}/FetchEntityData?entityId=${entityId}`), "Failed to access resource.")
2630
}
2731
};
2832
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div ng-controller="Umbraco.Cms.Integrations.PIM.Inriver.EntityPickerController as vm">
22
<div ng-if="vm.selectedEntity !== null" style="max-width: 800px;">
3-
<uui-ref-node name="{{vm.selectedEntity.displayName}}"
3+
<uui-ref-node name="{{vm.selectedEntity.summary.displayName}}"
44
detail="{{vm.selectedEntity.detail}}">
55
<uui-action-bar slot="actions">
66
<uui-button label="Remove" ng-click="vm.removeEntity()">Remove</uui-button>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
<uui-box headline="{{model.title}}" class="inriver-container">
55
<div>
66
<uui-icon-registry-essential>
7-
<uui-input id="inSearch" class="inriver-search" label="search" placeholder="Enter a name to search...">
7+
<uui-input id="inSearch" class="inriver-search" label="search"
8+
ng-on-input="vm.search()" ng-model="vm.searchTerm"
9+
placeholder="Enter a name to search...">
10+
<uui-icon style="padding-left: 10px;" slot="prepend" name="search"></uui-icon>
811
</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>
1212
</uui-icon-registry-essential>
1313
</div>
1414
<uui-scroll-container class="mt2" style="width:100%">

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

Lines changed: 14 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -50,95 +50,13 @@ public async Task<IActionResult> Query([FromBody] QueryRequest request)
5050

5151
if(result.Failure) return new JsonResult(ServiceResponse<IEnumerable<EntityData>>.Fail(result.Error));
5252

53-
var data = await _inriverService.FetchData(new FetchDataRequest
53+
var dataResult = await _inriverService.FetchData(new FetchDataRequest
5454
{
5555
EntityIds = result.Data.EntityIds,
5656
FieldTypeIds = request.FieldTypeIds
5757
});
5858

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));
59+
return new JsonResult(dataResult);
14260
}
14361

14462
[HttpPost]
@@ -148,5 +66,17 @@ public async Task<IActionResult> FetchData([FromBody] FetchDataRequest request)
14866

14967
return new JsonResult(result);
15068
}
69+
70+
[HttpGet]
71+
public async Task<IActionResult> FetchEntityData(int entityId)
72+
{
73+
var result = await _inriverService.FetchData(new FetchDataRequest
74+
{
75+
EntityIds = new int[] { entityId },
76+
FieldTypeIds = string.Empty
77+
});
78+
79+
return new JsonResult(result);
80+
}
15181
}
15282
}

0 commit comments

Comments
 (0)