Skip to content

Commit f84898a

Browse files
committed
Configuration validations
1 parent 00510a1 commit f84898a

File tree

4 files changed

+75
-16
lines changed

4 files changed

+75
-16
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
.inriver-container {
22
margin: 20px;
3-
/*position: absolute;
4-
left: 50%;
5-
top: 50%;
6-
transform: translate(-50%, -50%);*/
3+
}
4+
5+
.inriver-toast {
6+
top: 0;
7+
left: 0;
8+
right: 0;
9+
height: 100vh;
10+
padding: var(--uui-size-layout-4);
711
}
812

913
#editorDialog {

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

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function configurationController($scope, umbracoCmsIntegrationsPimInriverService, umbracoCmsIntegrationsPimInriverResource) {
1+
function configurationController($scope, notificationsService, umbracoCmsIntegrationsPimInriverService, umbracoCmsIntegrationsPimInriverResource) {
22
var vm = this;
33

44
const selEntityTypes = document.getElementById("selEntityTypes");
@@ -11,17 +11,31 @@
1111
vm.selectedEntityType = {};
1212
vm.selectedFieldTypes = [];
1313

14-
console.log($scope.model.value);
14+
vm.showToast = showToast;
15+
16+
//vm.showToast({
17+
// color: 'danger',
18+
// headline: 'Algolia',
19+
// message: 'Index name and content schema are required.'
20+
//});
1521

1622
if ($scope.model.value == null) {
1723
$scope.model.value = {
1824
entityType: '',
1925
displayFieldTypeIds: []
2026
};
2127
}
22-
$scope.$on('formSubmitting', function () {
23-
$scope.model.value.entityType = vm.selectedEntityType.value;
24-
$scope.model.value.displayFieldTypeIds = vm.selectedFieldTypes;
28+
$scope.$on('formSubmitting', function (ev) {
29+
if (vm.selectedEntityType != undefined
30+
|| vm.selectedEntityType.value.length == 0
31+
|| vm.selectedFieldTypes.length == 0) {
32+
notificationsService.error("Inriver", "Entity type and display fields are required. Configuration was not saved.");
33+
ev.preventDefault();
34+
return;
35+
} else {
36+
$scope.model.value.entityType = vm.selectedEntityType.value;
37+
$scope.model.value.displayFieldTypeIds = vm.selectedFieldTypes;
38+
}
2539
});
2640

2741
vm.entityTypeChange = function () {
@@ -54,7 +68,8 @@
5468
return option;
5569
});
5670

57-
vm.selectedFieldTypes = $scope.model.value.displayFieldTypeIds;
71+
if ($scope.model.value.displayFieldTypeIds != null)
72+
vm.selectedFieldTypes = $scope.model.value.displayFieldTypeIds;
5873

5974
bindValues();
6075
});
@@ -75,10 +90,36 @@
7590
selEntityTypes.options = vm.entityTypes;
7691
vm.fieldTypes = vm.selectedEntityType.fieldTypes;
7792

78-
$scope.model.value.displayFieldTypeIds.forEach(fieldTypeId => {
79-
umbracoCmsIntegrationsPimInriverService.waitForElement("#tr" + fieldTypeId)
80-
.then(element => element.setAttribute("selected", ""));
81-
});
93+
if ($scope.model.value.displayFieldTypeIds != null) {
94+
$scope.model.value.displayFieldTypeIds.forEach(fieldTypeId => {
95+
umbracoCmsIntegrationsPimInriverService.waitForElement("#tr" + fieldTypeId)
96+
.then(element => element.setAttribute("selected", ""));
97+
});
98+
}
99+
}
100+
101+
/* Toast Config properties:
102+
* color
103+
* headline
104+
* message
105+
*/
106+
function showToast(config) {
107+
const con = document.querySelector('uui-toast-notification-container');
108+
109+
const toast = document.createElement('uui-toast-notification');
110+
toast.color = config.color;
111+
112+
const toastLayout = document.createElement('uui-toast-notification-layout');
113+
toastLayout.headline = config.headline;
114+
toast.appendChild(toastLayout);
115+
116+
const messageEl = document.createElement('span');
117+
messageEl.innerHTML = config.message;
118+
toastLayout.appendChild(messageEl);
119+
120+
if (con) {
121+
con.appendChild(toast);
122+
}
82123
}
83124

84125
/**

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,20 @@
44

55
vm.selectedEntity = null;
66
vm.error = "";
7+
vm.configuration = $scope.model.config.configuration;
78

89
umbracoCmsIntegrationsPimInriverResource.checkApiAccess().then(function (response) {
910
if (response.failure)
1011
vm.error = response.data;
1112
});
13+
14+
if (vm.configuration.entityType == undefined
15+
|| vm.configuration.entityType.length == 0
16+
|| vm.configuration.displayFieldTypeIds == null
17+
|| vm.configuration.displayFieldTypeIds.length == 0) {
18+
vm.error = "Invalid Inriver configuration";
19+
return;
20+
}
1221

1322
if ($scope.model.value) {
1423
getEntitySummary($scope.model.value.entityId);

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<uui-form-layout-item ng-if="vm.fieldTypes.length > 0">
1717
<span style="font-weight:700;font-size:15px;">Field Types:</span>
1818
<div style="margin-bottom: 20px;">
19-
Please select the field types you want to display for the entity.
19+
Please select the field types you want to display for the entity.
2020
</div>
2121
<uui-table class="uui-text">
2222
<uui-table-column style="width: 60px;"></uui-table-column>
@@ -46,4 +46,9 @@
4646
</div>
4747
</uui-card-content-node>
4848
</uui-icon-registry-essential>
49-
</div>
49+
</div>
50+
51+
52+
<!-- Notifications -->
53+
<uui-toast-notification-container bottom-up="">
54+
</uui-toast-notification-container>

0 commit comments

Comments
 (0)