|
1 |
| -function dashboardController(notificationsService, overlayService, eventsService, algoliaService, umbracoCmsIntegrationsSearchAlgoliaResource) { |
| 1 | +function dashboardController(algoliaService, umbracoCmsIntegrationsSearchAlgoliaResource) { |
2 | 2 | var vm = this;
|
3 | 3 |
|
4 | 4 | const CREATE_INDEX_DEFINITION = "Create Index Definition";
|
5 | 5 | const EDIT_INDEX_DEFINITION = "Edit Index Definition";
|
6 | 6 |
|
7 | 7 | vm.loading = false;
|
| 8 | + vm.delete = false; |
8 | 9 |
|
9 | 10 | vm.searchQuery = "";
|
10 | 11 | vm.selectedSearchIndex = {};
|
|
23 | 24 | vm.search = search;
|
24 | 25 | vm.back = back;
|
25 | 26 |
|
| 27 | + vm.showToast = showToast; |
| 28 | + vm.showDeleteDialog = showDeleteDialog; |
| 29 | + vm.showBuildDialog = showBuildDialog; |
| 30 | + |
26 | 31 | function init() {
|
27 | 32 | /* contentData property:
|
28 | 33 | [
|
|
77 | 82 | }
|
78 | 83 | });
|
79 | 84 | },
|
| 85 | + hideProperties: function () { |
| 86 | + this.selectedContentType = {}; |
| 87 | + this.propertiesList = []; |
| 88 | + }, |
80 | 89 | removeContentType: function (contentType) {
|
81 | 90 |
|
82 | 91 | const contentTypeIndex = this.contentData.map(obj => obj.contentType.alias).indexOf(contentType.alias);
|
|
176 | 185 |
|
177 | 186 | function saveIndex() {
|
178 | 187 |
|
179 |
| - console.log(vm.manageIndex.name); |
180 |
| - |
181 | 188 | if (vm.manageIndex.name.length == 0 || vm.manageIndex.contentData.length == 0) {
|
182 |
| - notificationsService.error("Algolia", "Index name and content schema are required."); |
| 189 | + vm.showToast({ |
| 190 | + color: 'danger', |
| 191 | + headline: 'Algolia', |
| 192 | + message: 'Index name and content schema are required.' |
| 193 | + }); |
183 | 194 | return false;
|
184 | 195 | }
|
185 | 196 |
|
|
191 | 202 | if (response.success) {
|
192 | 203 | vm.manageIndex.reset();
|
193 | 204 | algoliaService.getContentTypes((response) => vm.manageIndex.contentTypes = response);
|
194 |
| - notificationsService.success("Algolia", "Index saved."); |
| 205 | + vm.showToast({ |
| 206 | + color: 'positive', |
| 207 | + headline: 'Algolia', |
| 208 | + message: 'Index saved.' |
| 209 | + }); |
195 | 210 | } else {
|
196 |
| - notificationsService.error("Algolia", response.error); |
| 211 | + vm.showToast({ |
| 212 | + color: 'danger', |
| 213 | + headline: 'Algolia', |
| 214 | + message: response.error |
| 215 | + }); |
197 | 216 | }
|
198 | 217 |
|
199 | 218 | vm.viewState = "list";
|
|
230 | 249 | }
|
231 | 250 |
|
232 | 251 | function buildIndex(index) {
|
233 |
| - const dialogOptions = { |
234 |
| - view: "/App_Plugins/UmbracoCms.Integrations/Search/Algolia/views/index.build.html", |
235 |
| - index: index, |
236 |
| - submit: function (model) { |
237 |
| - vm.loading = true; |
238 |
| - |
239 |
| - umbracoCmsIntegrationsSearchAlgoliaResource.buildIndex(model.index.id).then(function (response) { |
240 |
| - if (response.failure) |
241 |
| - notificationsService.warning("Algolia", "An error has occurred while building the index: " + response.error); |
242 |
| - else { |
243 |
| - notificationsService.success("Algolia", "Index built successfully."); |
244 |
| - vm.loading = false; |
245 |
| - overlayService.close(); |
246 |
| - } |
247 |
| - }); |
248 |
| - }, |
249 |
| - close: function () { |
250 |
| - overlayService.close(); |
251 |
| - } |
252 |
| - }; |
253 |
| - |
254 |
| - overlayService.open(dialogOptions); |
| 252 | + vm.showBuildDialog(index); |
255 | 253 | }
|
256 | 254 |
|
257 | 255 | function searchIndex(index) {
|
|
260 | 258 | }
|
261 | 259 |
|
262 | 260 | function deleteIndex(index) {
|
263 |
| - const dialogOptions = { |
264 |
| - title: "Delete", |
265 |
| - content: "Are you sure you want to delete index <b>" + index.name + "</b>?", |
266 |
| - confirmType: "delete", |
267 |
| - submit: function () { |
268 |
| - umbracoCmsIntegrationsSearchAlgoliaResource.deleteIndex(index.id).then(function (response) { |
269 |
| - if (response.success) { |
270 |
| - notificationsService.success("Algolia", "Index deleted."); |
271 |
| - getIndices(); |
272 |
| - } else |
273 |
| - notificationsService.error("Algolia", response.error); |
274 |
| - |
275 |
| - overlayService.close(); |
276 |
| - }); |
277 |
| - } |
278 |
| - }; |
279 |
| - |
280 |
| - overlayService.confirm(dialogOptions); |
| 261 | + vm.showDeleteDialog(index); |
281 | 262 | }
|
282 | 263 |
|
283 | 264 | function search() {
|
|
295 | 276 |
|
296 | 277 | vm.viewState = "list";
|
297 | 278 | }
|
| 279 | + |
| 280 | + /* Toast Config properties: |
| 281 | + * color |
| 282 | + * headline |
| 283 | + * message |
| 284 | + */ |
| 285 | + function showToast(config) { |
| 286 | + const con = document.querySelector('uui-toast-notification-container'); |
| 287 | + |
| 288 | + const toast = document.createElement('uui-toast-notification'); |
| 289 | + toast.color = config.color; |
| 290 | + |
| 291 | + const toastLayout = document.createElement('uui-toast-notification-layout'); |
| 292 | + toastLayout.headline = config.headline; |
| 293 | + toast.appendChild(toastLayout); |
| 294 | + |
| 295 | + const messageEl = document.createElement('span'); |
| 296 | + messageEl.innerHTML = config.message; |
| 297 | + toastLayout.appendChild(messageEl); |
| 298 | + |
| 299 | + if (con) { |
| 300 | + con.appendChild(toast); |
| 301 | + } |
| 302 | + } |
| 303 | + |
| 304 | + /* delete handlers */ |
| 305 | + function showDeleteDialog(index) { |
| 306 | + const dialog = document.getElementById('deleteDialog'); |
| 307 | + dialog.style.display = "block"; |
| 308 | + |
| 309 | + const p = document.createElement('p'); |
| 310 | + p.innerHTML = "Are you sure you want to delete index <b>" + index.name + "</b>?"; |
| 311 | + |
| 312 | + const dialogLayout = dialog.querySelector('uui-dialog-layout'); |
| 313 | + dialogLayout.appendChild(p); |
| 314 | + |
| 315 | + // event listeners |
| 316 | + var btnCancel = dialog.querySelector('#btnCancel'); |
| 317 | + btnCancel.addEventListener('click', closeDeleteDialog); |
| 318 | + |
| 319 | + var btnDelete = dialog.querySelector('#btnDelete'); |
| 320 | + btnDelete.addEventListener('click', function () { |
| 321 | + umbracoCmsIntegrationsSearchAlgoliaResource.deleteIndex(index.id).then(function (response) { |
| 322 | + if (response.success) { |
| 323 | + vm.showToast({ |
| 324 | + color: 'positive', |
| 325 | + headline: 'Algolia', |
| 326 | + message: 'Index deleted' |
| 327 | + }); |
| 328 | + getIndices(); |
| 329 | + } else { |
| 330 | + vm.showToast({ |
| 331 | + color: 'danger', |
| 332 | + headline: 'Algolia', |
| 333 | + message: 'An error has occurred: ' + response.error |
| 334 | + }); |
| 335 | + } |
| 336 | + |
| 337 | + closeDeleteDialog(); |
| 338 | + }); |
| 339 | + }); |
| 340 | + } |
| 341 | + |
| 342 | + function closeDeleteDialog() { |
| 343 | + const dialog = document.getElementById('deleteDialog'); |
| 344 | + dialog.style.display = "none"; |
| 345 | + |
| 346 | + const dialogLayout = dialog.querySelector('uui-dialog-layout'); |
| 347 | + const p = dialogLayout.querySelector('p'); |
| 348 | + dialogLayout.removeChild(p); |
| 349 | + } |
| 350 | + |
| 351 | + /* build index handlers */ |
| 352 | + function showBuildDialog(index) { |
| 353 | + const dialog = document.getElementById('buildDialog'); |
| 354 | + dialog.style.display = "block"; |
| 355 | + |
| 356 | + // add event listeners |
| 357 | + var btnCancel = dialog.querySelector('#btnCancel'); |
| 358 | + btnCancel.addEventListener('click', closeBuildDialog); |
| 359 | + |
| 360 | + var btnBuild = dialog.querySelector('#btnBuild'); |
| 361 | + btnBuild.addEventListener('click', function () { |
| 362 | + vm.loading = true; |
| 363 | + |
| 364 | + umbracoCmsIntegrationsSearchAlgoliaResource.buildIndex(index.id).then(function (response) { |
| 365 | + if (response.failure) { |
| 366 | + vm.showToast({ |
| 367 | + color: 'warning', |
| 368 | + headline: 'Algolia', |
| 369 | + message: 'An error has occurred while building the index: ' + response.error |
| 370 | + }); |
| 371 | + } |
| 372 | + else { |
| 373 | + vm.showToast({ |
| 374 | + color: 'positive', |
| 375 | + headline: 'Algolia', |
| 376 | + message: 'Index built successfully' |
| 377 | + }); |
| 378 | + vm.loading = false; |
| 379 | + } |
| 380 | + }); |
| 381 | + |
| 382 | + closeBuildDialog(); |
| 383 | + }); |
| 384 | + } |
| 385 | + |
| 386 | + function closeBuildDialog() { |
| 387 | + const dialog = document.getElementById('buildDialog'); |
| 388 | + dialog.style.display = "none"; |
| 389 | + } |
298 | 390 | }
|
299 | 391 |
|
300 | 392 | angular.module("umbraco")
|
|
0 commit comments