|
1 | 1 | function dashboardController(notificationsService, overlayService, eventsService, algoliaService, umbracoCmsIntegrationsSearchAlgoliaResource) {
|
2 | 2 | var vm = this;
|
3 | 3 |
|
| 4 | + const CREATE_INDEX_DEFINITION = "Create Index Definition"; |
| 5 | + const EDIT_INDEX_DEFINITION = "Edit Index Definition"; |
| 6 | + |
4 | 7 | vm.loading = false;
|
5 | 8 |
|
6 | 9 | vm.searchQuery = "";
|
|
18 | 21 | vm.searchIndex = searchIndex;
|
19 | 22 | vm.deleteIndex = deleteIndex;
|
20 | 23 | vm.search = search;
|
| 24 | + vm.back = back; |
21 | 25 |
|
22 | 26 | function init() {
|
23 | 27 | /* contentData property:
|
24 | 28 | [
|
25 |
| - { |
26 |
| - "contentType": { |
27 |
| - "alias": "", |
28 |
| - "name": "", |
29 |
| - "icon": "" |
30 |
| - }, |
31 |
| - "properties": [ |
32 |
| - { |
33 |
| - "alias": "", |
34 |
| - "name": "" |
35 |
| - } |
36 |
| - ] |
37 |
| - } |
| 29 | + { |
| 30 | + "contentType": { |
| 31 | + "alias": "", |
| 32 | + "name": "", |
| 33 | + "icon": "" |
| 34 | + }, |
| 35 | + "properties": [ |
| 36 | + { |
| 37 | + "alias": "", |
| 38 | + "name": "" |
| 39 | + } |
| 40 | + ] |
| 41 | + } |
38 | 42 | ]
|
39 | 43 | */
|
40 | 44 | vm.manageIndex = {
|
41 | 45 | id: 0,
|
| 46 | + viewTitle: CREATE_INDEX_DEFINITION, |
42 | 47 | name: "",
|
43 | 48 | selectedContentType: {},
|
44 | 49 | contentTypesList: [],
|
|
55 | 60 | ],
|
56 | 61 | contentData: [],
|
57 | 62 | showProperties: function (contentType) {
|
58 |
| - |
59 | 63 | this.selectedContentType = contentType;
|
60 | 64 |
|
61 | 65 | algoliaService.getPropertiesByContentTypeId(contentType.id, (response) => {
|
|
88 | 92 | this.propertiesList = [];
|
89 | 93 | },
|
90 | 94 | selectProperty: function (property) {
|
91 |
| - |
92 | 95 | var contentDataItem = vm.manageIndex.contentData.find(obj => obj.contentType.alias == vm.manageIndex.selectedContentType.alias);
|
93 | 96 |
|
94 |
| - var selected = !property.selected; |
95 |
| - if (selected) { |
96 |
| - // mark item selected |
97 |
| - vm.manageIndex.propertiesList.find(obj => obj.alias == property.alias).selected = true; |
98 |
| - |
99 |
| - // check if content type exists in the contentData array |
100 |
| - if (!contentDataItem) { |
101 |
| - var contentItem = { |
102 |
| - contentType: { |
103 |
| - alias: vm.manageIndex.selectedContentType.alias, |
104 |
| - name: vm.manageIndex.selectedContentType.name, |
105 |
| - icon: vm.manageIndex.selectedContentType.icon |
106 |
| - }, |
107 |
| - properties: [] |
108 |
| - }; |
109 |
| - vm.manageIndex.contentData.push(contentItem); |
110 |
| - |
111 |
| - // select content type |
112 |
| - vm.manageIndex.contentTypesList.forEach(obj => { |
113 |
| - if (obj.alias == vm.manageIndex.selectedContentType.alias) { |
114 |
| - obj.selected = true; |
115 |
| - obj.allowRemove = true; |
116 |
| - } |
117 |
| - }); |
118 |
| - } |
119 |
| - |
120 |
| - // add property |
121 |
| - vm.manageIndex.contentData |
122 |
| - .find(obj => obj.contentType.alias == vm.manageIndex.selectedContentType.alias) |
123 |
| - .properties.push({ |
124 |
| - alias: property.alias, |
125 |
| - name: property.name |
126 |
| - }); |
| 97 | + // mark item selected |
| 98 | + vm.manageIndex.propertiesList.find(obj => obj.alias == property.alias).selected = true; |
| 99 | + |
| 100 | + // check if content type exists in the contentData array |
| 101 | + if (!contentDataItem) { |
| 102 | + var contentItem = { |
| 103 | + contentType: { |
| 104 | + alias: vm.manageIndex.selectedContentType.alias, |
| 105 | + name: vm.manageIndex.selectedContentType.name, |
| 106 | + icon: vm.manageIndex.selectedContentType.icon |
| 107 | + }, |
| 108 | + properties: [] |
| 109 | + }; |
| 110 | + vm.manageIndex.contentData.push(contentItem); |
| 111 | + |
| 112 | + // select content type |
| 113 | + vm.manageIndex.contentTypesList.forEach(obj => { |
| 114 | + if (obj.alias == vm.manageIndex.selectedContentType.alias) { |
| 115 | + obj.selected = true; |
| 116 | + obj.allowRemove = true; |
| 117 | + } |
| 118 | + }); |
127 | 119 | }
|
128 |
| - else { |
129 |
| - // deselect item |
130 |
| - vm.manageIndex.propertiesList.find(obj => obj.alias == property.alias).selected = false; |
131 |
| - |
132 |
| - // remove property item |
133 |
| - const propertyIndex = vm.manageIndex.contentData |
134 |
| - .find(obj => obj.contentType.alias == vm.manageIndex.selectedContentType.alias) |
135 |
| - .properties.map(obj => obj.alias).indexOf(property.alias); |
136 |
| - vm.manageIndex.contentData |
137 |
| - .find(obj => obj.contentType.alias == vm.manageIndex.selectedContentType.alias).properties.splice(propertyIndex, 1); |
138 |
| - |
139 |
| - // remove content type item with no properties and deselect |
140 |
| - if (vm.manageIndex.contentData.find(obj => obj.contentType.alias == vm.manageIndex.selectedContentType.alias).properties.length == 0) { |
141 |
| - vm.manageIndex.contentTypesList.find(obj => obj.alias == vm.manageIndex.selectedContentType.alias).selected = false; |
142 |
| - vm.manageIndex.contentTypesList.find(obj => obj.alias == vm.manageIndex.selectedContentType.alias).allowRemove = false; |
143 |
| - |
144 |
| - const contentTypeIndex = vm.manageIndex.contentData.map(obj => obj.contentType.alias).indexOf(vm.manageIndex.selectedContentType.alias); |
145 |
| - vm.manageIndex.contentData.splice(contentTypeIndex, 1); |
146 |
| - } |
| 120 | + |
| 121 | + // add property |
| 122 | + vm.manageIndex.contentData |
| 123 | + .find(obj => obj.contentType.alias == vm.manageIndex.selectedContentType.alias) |
| 124 | + .properties.push({ |
| 125 | + alias: property.alias, |
| 126 | + name: property.name |
| 127 | + }); |
| 128 | + }, |
| 129 | + removeProperty: function (property) { |
| 130 | + // deselect item |
| 131 | + vm.manageIndex.propertiesList.find(obj => obj.alias == property.alias).selected = false; |
| 132 | + |
| 133 | + // remove property item |
| 134 | + const propertyIndex = vm.manageIndex.contentData |
| 135 | + .find(obj => obj.contentType.alias == vm.manageIndex.selectedContentType.alias) |
| 136 | + .properties.map(obj => obj.alias).indexOf(property.alias); |
| 137 | + vm.manageIndex.contentData |
| 138 | + .find(obj => obj.contentType.alias == vm.manageIndex.selectedContentType.alias).properties.splice(propertyIndex, 1); |
| 139 | + |
| 140 | + // remove content type item with no properties and deselect |
| 141 | + if (vm.manageIndex.contentData.find(obj => obj.contentType.alias == vm.manageIndex.selectedContentType.alias).properties.length == 0) { |
| 142 | + vm.manageIndex.contentTypesList.find(obj => obj.alias == vm.manageIndex.selectedContentType.alias).selected = false; |
| 143 | + vm.manageIndex.contentTypesList.find(obj => obj.alias == vm.manageIndex.selectedContentType.alias).allowRemove = false; |
| 144 | + |
| 145 | + const contentTypeIndex = vm.manageIndex.contentData.map(obj => obj.contentType.alias).indexOf(vm.manageIndex.selectedContentType.alias); |
| 146 | + vm.manageIndex.contentData.splice(contentTypeIndex, 1); |
147 | 147 | }
|
148 | 148 | },
|
149 | 149 | reset: function () {
|
150 | 150 | this.visible = false;
|
151 | 151 | this.id = 0;
|
| 152 | + this.viewTitle = CREATE_INDEX_DEFINITION |
152 | 153 | this.name = "";
|
153 | 154 | this.selectedContentType = {};
|
154 | 155 | this.contentTypesList = [];
|
|
175 | 176 |
|
176 | 177 | function saveIndex() {
|
177 | 178 |
|
| 179 | + console.log(vm.manageIndex.name); |
| 180 | + |
178 | 181 | if (vm.manageIndex.name.length == 0 || vm.manageIndex.contentData.length == 0) {
|
179 | 182 | notificationsService.error("Algolia", "Index name and content schema are required.");
|
180 | 183 | return false;
|
181 | 184 | }
|
182 |
| - |
| 185 | + |
183 | 186 | vm.loading = true;
|
184 | 187 |
|
185 | 188 | umbracoCmsIntegrationsSearchAlgoliaResource
|
|
206 | 209 | vm.viewState = "manage";
|
207 | 210 |
|
208 | 211 | vm.manageIndex.id = index.id;
|
| 212 | + vm.manageIndex.viewTitle = EDIT_INDEX_DEFINITION; |
209 | 213 | vm.manageIndex.name = index.name;
|
210 | 214 | vm.manageIndex.contentData = index.contentData;
|
211 | 215 |
|
|
281 | 285 | vm.searchResults = response;
|
282 | 286 | });
|
283 | 287 | }
|
| 288 | + |
| 289 | + function back() { |
| 290 | + vm.manageIndex.reset(); |
| 291 | + |
| 292 | + vm.searchQuery = ''; |
| 293 | + vm.selectedSearchIndex = {}; |
| 294 | + vm.searchResults = {}; |
| 295 | + |
| 296 | + vm.viewState = "list"; |
| 297 | + } |
284 | 298 | }
|
285 | 299 |
|
286 | 300 | angular.module("umbraco")
|
|
0 commit comments