Skip to content

Commit 9372249

Browse files
committed
PR updates
1 parent eb7f220 commit 9372249

16 files changed

+312
-98
lines changed

src/Umbraco.Cms.Integrations.Search.Algolia/AlgoliaComposer.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
using Microsoft.Extensions.DependencyInjection;
44

5-
using System.Dynamic;
6-
75
using Umbraco.Cms.Core.Composing;
86
using Umbraco.Cms.Core.DependencyInjection;
97
using Umbraco.Cms.Core.Notifications;
108
using Umbraco.Cms.Integrations.Search.Algolia;
119
using Umbraco.Cms.Integrations.Search.Algolia.Configuration;
10+
using Umbraco.Cms.Integrations.Search.Algolia.Handlers;
1211
using Umbraco.Cms.Integrations.Search.Algolia.Migrations;
1312
using Umbraco.Cms.Integrations.Search.Algolia.Models;
14-
using Umbraco.Cms.Integrations.Search.Algolia.Notifications;
1513
using Umbraco.Cms.Integrations.Search.Algolia.Services;
1614

1715
namespace Umbraco.Cms.Integrations.Crm.ActiveCampaign
@@ -22,16 +20,20 @@ public void Compose(IUmbracoBuilder builder)
2220
{
2321
builder.AddNotificationHandler<UmbracoApplicationStartingNotification, RunAlgoliaIndicesMigration>();
2422

23+
builder.AddNotificationAsyncHandler<ContentPublishedNotification, ContentPublishedHandler>();
24+
25+
builder.AddNotificationAsyncHandler<ContentDeletedNotification, ContentDeletedHandler>();
26+
27+
builder.AddNotificationAsyncHandler<ContentUnpublishedNotification, ContentUnpublishedHandler>();
28+
2529
var options = builder.Services.AddOptions<AlgoliaSettings>()
2630
.Bind(builder.Config.GetSection(Constants.SettingsPath));
2731

2832
builder.Services.AddSingleton<IAlgoliaIndexService, AlgoliaIndexService>();
2933

3034
builder.Services.AddSingleton<IAlgoliaSearchService<SearchResponse<Record>>, AlgoliaSearchService>();
3135

32-
builder.Services.AddScoped<IScopeService<AlgoliaIndex>, ScopeService>();
33-
34-
builder.AddNotificationHandler<ContentPublishedNotification, NewContentPublishedHandler>();
36+
builder.Services.AddScoped<IAlgoliaIndexDefinitionStorage<AlgoliaIndex>, AlgoliaIndexDefinitionStorage>();
3537
}
3638

3739
}

src/Umbraco.Cms.Integrations.Search.Algolia/App_Plugins/UmbracoCms.Integrations/Search/Algolia/js/algolia.resource.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
$http.post(`${apiEndpoint}/SaveIndex`, { name: name, contentData: contentData }),
1515
"Failed");
1616
},
17+
buildIndex: function (id) {
18+
return umbRequestHelper.resourcePromise(
19+
$http.post(`${apiEndpoint}/BuildIndex`, { id: id }),
20+
"Failed");
21+
},
1722
deleteIndex: function (id) {
1823
return umbRequestHelper.resourcePromise(
1924
$http.delete(`${apiEndpoint}/DeleteIndex?id=${id}`),

src/Umbraco.Cms.Integrations.Search.Algolia/App_Plugins/UmbracoCms.Integrations/Search/Algolia/js/algolia.service.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
id: data.groups[i].properties[j].id,
1616
alias: data.groups[i].properties[j].alias,
1717
name: data.groups[i].properties[j].label,
18+
display: `Group: ${data.groups[i].name} | Property: ${data.groups[i].properties[j].label}`,
1819
checked: false
1920
});
2021
}

src/Umbraco.Cms.Integrations.Search.Algolia/App_Plugins/UmbracoCms.Integrations/Search/Algolia/js/dashboard.controller.js

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
function dashboardController(notificationsService, algoliaService, umbracoCmsIntegrationsSearchAlgoliaResource) {
1+
function dashboardController(notificationsService, overlayService, eventsService, algoliaService, umbracoCmsIntegrationsSearchAlgoliaResource) {
22
var vm = this;
33

4+
vm.loading = false;
5+
46
vm.searchQuery = "";
57
vm.searchIndex = {};
68
vm.searchResults = {};
@@ -12,8 +14,9 @@
1214
vm.addIndex = addIndex;
1315
vm.saveIndex = saveIndex;
1416
vm.viewIndex = viewIndex;
15-
vm.deleteIndex = deleteIndex;
17+
vm.buildIndex = buildIndex;
1618
vm.search = search;
19+
vm.deleteIndex = deleteIndex;
1720

1821
function init() {
1922

@@ -59,9 +62,8 @@
5962
}
6063
},
6164
showProperties: function (contentType) {
62-
6365
algoliaService.getPropertiesByContentTypeId(contentType.id, (response) => {
64-
vm.manageIndex.properties = response;
66+
this.properties = response;
6567

6668
var contentTypeData = this.contentData.find(p => p.contentType == contentType.alias);
6769
if (contentTypeData && contentTypeData.properties.length > 0) {
@@ -102,13 +104,20 @@
102104
}
103105
};
104106

105-
algoliaService.getContentTypes((response) => vm.manageIndex.contentTypes = response);
106-
107107
getIndices();
108108
}
109109

110+
function getIndices() {
111+
vm.indices = [];
112+
113+
umbracoCmsIntegrationsSearchAlgoliaResource.getIndices().then(function (data) {
114+
vm.indices = data;
115+
});
116+
}
117+
110118
function addIndex() {
111119
vm.viewState = "manage";
120+
algoliaService.getContentTypes((response) => vm.manageIndex.contentTypes = response);
112121
}
113122

114123
function saveIndex() {
@@ -117,6 +126,9 @@
117126
notificationsService.error("Index name and content schema are required");
118127
return false;
119128
}
129+
130+
vm.loading = true;
131+
120132
umbracoCmsIntegrationsSearchAlgoliaResource
121133
.saveIndex(vm.manageIndex.name, vm.manageIndex.contentData)
122134
.then(function (response) {
@@ -130,6 +142,8 @@
130142
vm.viewState = "list";
131143

132144
getIndices();
145+
146+
vm.loading = false;
133147
});
134148
}
135149

@@ -144,17 +158,35 @@
144158
algoliaService.getContentTypes((response) => {
145159

146160
vm.manageIndex.contentTypes = response;
147-
161+
148162
for (var i = 0; i < vm.manageIndex.contentData.length; i++) {
149163
vm.manageIndex.contentTypes.find(p => p.alias === vm.manageIndex.contentData[i].contentType).checked = true;
150164
}
151165
});
152166
}
153167

154-
function deleteIndex(index) {
155-
umbracoCmsIntegrationsSearchAlgoliaResource.deleteIndex(index.id).then(function (response) {
156-
getIndices();
157-
});
168+
function buildIndex(index) {
169+
const dialogOptions = {
170+
view: "/App_Plugins/UmbracoCms.Integrations/Search/Algolia/views/index.build.html",
171+
index: index,
172+
submit: function (model) {
173+
vm.loading = true;
174+
175+
umbracoCmsIntegrationsSearchAlgoliaResource.buildIndex(model.index.id).then(function (response) {
176+
if (response.length > 0)
177+
notificationsService.warning("An error has occurred while building the index: " + response);
178+
else {
179+
vm.loading = false;
180+
overlayService.close();
181+
}
182+
});
183+
},
184+
close: function () {
185+
overlayService.close();
186+
}
187+
};
188+
189+
overlayService.open(dialogOptions);
158190
}
159191

160192
function search() {
@@ -163,11 +195,9 @@
163195
});
164196
}
165197

166-
function getIndices() {
167-
vm.indices = [];
168-
169-
umbracoCmsIntegrationsSearchAlgoliaResource.getIndices().then(function (data) {
170-
vm.indices = data;
198+
function deleteIndex(index) {
199+
umbracoCmsIntegrationsSearchAlgoliaResource.deleteIndex(index.id).then(function (response) {
200+
getIndices();
171201
});
172202
}
173203
}

src/Umbraco.Cms.Integrations.Search.Algolia/App_Plugins/UmbracoCms.Integrations/Search/Algolia/views/dashboard.html

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<div ng-controller="Umbraco.Cms.Integrations.Search.Algolia.DashboardController as vm">
22

3+
<div ng-show="vm.loading">
4+
<umb-load-indicator></umb-load-indicator>
5+
</div>
6+
37
<div class="umb-panel-group__details">
48

59
<div ng-if="vm.viewState == 'list'" class="umb-panel-group__details-group">
@@ -20,43 +24,52 @@
2024
</umb-button>
2125
</div>
2226
</div>
23-
<div ng-if="vm.indices.length > 0" class="umb-panel-group__details-status" ng-repeat="index in vm.indices">
24-
<div class="umb-panel-group__details-status-content">
25-
<div class="row">
26-
<div class="flex justify-between">
27-
<div class="flx-b4 ml2">
28-
<div class="flex content-center">
29-
<div>
30-
<button type="button" class="btn-link -underline" ng-click="vm.viewIndex(index)">
31-
{{index.name}}
32-
</button>
33-
</div>
34-
<div style="margin-left:10px;padding-top:2px">
35-
<p ng-repeat="item in index.contentData">{{ item.contentType }} - {{ item.properties.join() }}</p>
36-
</div>
37-
<div style="margin-left: 10px; padding-top: 2px">
38-
<a href="javascript:void(0)" style="display: block; margin-top: 2px;" ng-click="vm.searchIndex=index;vm.viewState = 'search';">
39-
<i class="icon-search"></i>
40-
</a>
41-
</div>
42-
<div style="padding-top: 2px">
43-
<a href="javascript:void(0)" ng-click="vm.deleteIndex(index)" style="display: block; margin-top: 2px;">
44-
<i class="icon-trash"></i>
45-
</a>
46-
</div>
47-
</div>
48-
</div>
49-
</div>
50-
</div>
51-
</div>
27+
<div ng-if="vm.indices.length > 0" class="ml2 mr7 umb-panel-group__details-status">
28+
<table class="table table-striped table-hover">
29+
<thead>
30+
<tr>
31+
<th>Name</th>
32+
<th>Schema</th>
33+
<th></th>
34+
</tr>
35+
</thead>
36+
<tbody>
37+
<tr ng-repeat="index in vm.indices">
38+
<td>
39+
<button type="button" class="btn-link -underline" ng-click="vm.viewIndex(index)">
40+
{{index.name}}
41+
</button>
42+
</td>
43+
<td>
44+
<p ng-repeat="item in index.contentData">{{ item.contentType }} - {{ item.properties.join() }}</p>
45+
</td>
46+
<td>
47+
<umb-button label="build"
48+
type="button"
49+
button-style="danger"
50+
action="vm.buildIndex(index)">
51+
</umb-button>
52+
<umb-button label="search"
53+
type="button"
54+
button-style="success">
55+
</umb-button>
56+
<umb-button label="delete"
57+
type="button"
58+
button-style="inverse"
59+
action="vm.deleteIndex(index)">
60+
</umb-button>
61+
</td>
62+
</tr>
63+
</tbody>
64+
</table>
5265
</div>
5366
</div>
5467
</div>
5568
<br />
5669
<div ng-if="vm.viewState === 'manage'">
5770
<umb-editor-sub-header>
5871
<umb-editor-sub-header-content-left>
59-
<button type="button" class="umb-package-details__back-action" ng-click="vm.viewState = 'list'">
72+
<button type="button" class="umb-package-details__back-action" ng-click="vm.manageIndex.reset();vm.viewState = 'list';">
6073
<span aria-hidden="true">&larr;</span>
6174
Back
6275
</button>
@@ -83,7 +96,7 @@
8396
<label>Index Name</label>
8497
</div>
8598
<div class="ml2">
86-
<input type="text" ng-model="vm.manageIndex.name" />
99+
<input type="text" ng-model="vm.manageIndex.name" no-dirty-check />
87100
</div>
88101
</div>
89102
</div>
@@ -103,7 +116,8 @@ <h5>Content Types</h5>
103116
</umb-toggle>
104117
</div>
105118
<div class="ml2">
106-
<button type="button"
119+
<button ng-if="contentType.checked"
120+
type="button"
107121
style="border-top-width: 0;padding-top:0;"
108122
class="btn-link -underline" ng-click="vm.manageIndex.showProperties(contentType)">
109123
show properties
@@ -120,8 +134,8 @@ <h5>Properties</h5>
120134
<umb-toggle checked="property.checked"
121135
on-click="vm.manageIndex.selectProperty(property)"
122136
show-labels="true"
123-
label-on="{{property.name}}"
124-
label-off="{{property.name}}"
137+
label-on="{{ property.display }}"
138+
label-off="{{ property.display }}"
125139
label-position="right">
126140
</umb-toggle>
127141
</div>
@@ -172,7 +186,7 @@ <h5>Properties</h5>
172186
<div class="row">
173187
<div class="flex">
174188
<div class="mt2" style="width:50%">
175-
<input type="text" style="width:100%" ng-model="vm.searchQuery" />
189+
<input type="text" style="width:100%" ng-model="vm.searchQuery" no-dirty-check />
176190
</div>
177191
<div class="mt2">
178192
<umb-button type="button"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div>
2+
<div class="umb-alert umb-alert--warning mb2">
3+
This will cause the index to be built.<br>
4+
Depending on how much content there is in your site this could take a while.<br>
5+
It is not recommended to rebuild an index during times of high website traffic
6+
or when editors are editing content.
7+
</div>
8+
</div>

0 commit comments

Comments
 (0)