59
59
</ul >
60
60
</template >
61
61
<template #[` item.actions ` ]=" { item } " >
62
+ <!-- User logged in and is on its public profile page-->
62
63
<v-icon
64
+ v-if =" Number($route.params.id) === user().id"
65
+ @click =" deleteItem(item)"
66
+ >
67
+ mdi-delete
68
+ </v-icon >
69
+ <!-- User is on any other user's public profile page-->
70
+ <v-icon
71
+ v-else-if =" $route.name === 'PublicProfile'"
72
+ @click =" unlinkItem(item)"
73
+ >
74
+ mdi-link-off
75
+ </v-icon >
76
+ <!-- User is on its account profile page-->
77
+ <v-icon
78
+ v-else
63
79
@click =" deleteItem(item)"
64
80
>
65
81
mdi-delete
102
118
<v-spacer />
103
119
</v-card-actions >
104
120
</v-card >
121
+ <!-- Unlink -->
122
+ <v-card v-if =" unlinkSavedSearch" >
123
+ <v-card-title class =" text-h5" >
124
+ Are you sure you want to unlink this user?
125
+ </v-card-title >
126
+ <v-card-actions >
127
+ <v-spacer />
128
+ <v-btn
129
+ class =" white--text"
130
+ color =" accent3"
131
+ @click =" closeDialog"
132
+ >
133
+ Cancel
134
+ </v-btn >
135
+ <v-btn
136
+ class =" white--text"
137
+ color =" success"
138
+ :loading =" loading"
139
+ @click =" unlinkItemConfirm()"
140
+ >
141
+ OK
142
+ </v-btn >
143
+ <v-spacer />
144
+ </v-card-actions >
145
+ </v-card >
105
146
</v-dialog >
106
147
</div >
107
148
</template >
@@ -111,6 +152,7 @@ import { mapActions, mapGetters, mapState } from "vuex";
111
152
112
153
import RESTClient from " @/lib/Client/RESTClient" ;
113
154
import advancedSearch from " @/store" ;
155
+ import saveSearch from " @/store" ;
114
156
115
157
const restClient = new RESTClient ();
116
158
@@ -124,6 +166,7 @@ export default {
124
166
return {
125
167
modifyDialog: false ,
126
168
deleteSavedSearch: false ,
169
+ unlinkSavedSearch: false ,
127
170
selectedItem: {},
128
171
totalSearches: [],
129
172
loading: false ,
@@ -161,20 +204,28 @@ export default {
161
204
this .combinedSearches ();
162
205
},
163
206
methods: {
164
- ... mapActions (" users" , [" getUser" ]),
207
+ ... mapActions (" users" , [" getUser" , " getPublicUser " ]),
165
208
/**
166
209
* Fetch combinedSearches and savedSearches from the props
167
210
* removing the duplicates and displaying in user profile
168
211
* page
169
212
*/
170
- async combinedSearches (searchDeleted ) {
213
+ async combinedSearches (searchDeleted , searchUnlinked ) {
171
214
let createdSearches, savedSearches
172
215
173
216
if (searchDeleted) {
174
217
await this .getUser ();
175
218
createdSearches = this .getUserRecords .user [" createdSearches" ];
176
219
savedSearches = this .getUserRecords .user [" savedSearches" ];
177
- } else {
220
+ }
221
+ else if (searchUnlinked) {
222
+ let userId = this .$route .params .id ;
223
+ let userR = await this .getPublicUser (userId);
224
+ await this .getUser ();
225
+ createdSearches = userR .user [" createdSearches" ];
226
+ savedSearches = userR .user [" savedSearches" ];
227
+ }
228
+ else {
178
229
createdSearches = this .createdSearches ;
179
230
savedSearches = this .savedSearches ;
180
231
}
@@ -194,11 +245,12 @@ export default {
194
245
195
246
/**
196
247
* Delete the selection savedSearch
197
- * @param item
248
+ * @param item - {Object} - Saved Search details
198
249
*/
199
250
deleteItem (item ) {
200
251
this .selectedItem = item;
201
252
this .modifyDialog = true ;
253
+ this .unlinkSavedSearch = false ;
202
254
this .deleteSavedSearch = true ;
203
255
},
204
256
@@ -214,13 +266,59 @@ export default {
214
266
);
215
267
216
268
if (data[" message" ] === " success" ) {
217
- await this .combinedSearches (true );
269
+ await this .combinedSearches (true , false );
218
270
}
219
271
this .loading = false ;
220
272
this .deleteSavedSearch = false ;
221
273
this .closeDialog ();
222
274
},
223
275
276
+ /**
277
+ * Unlink saved search from the user
278
+ * @param item - {Object} - Saved Search details
279
+ */
280
+ unlinkItem (item ) {
281
+ this .selectedItem = item;
282
+ this .modifyDialog = true ;
283
+ this .deleteSavedSearch = false ;
284
+ this .unlinkSavedSearch = true ;
285
+ },
286
+
287
+ /**
288
+ * Confirmation dialog to unlink the savedSearch
289
+ * and close the dialog if pressed OK
290
+ */
291
+ async unlinkItemConfirm () {
292
+ this .loading = true ;
293
+ let additionalUsersArr = this .additionalUsers (this .selectedItem )
294
+
295
+ // Filter the user to unlink
296
+ let linkedUser = additionalUsersArr .filter (({id}) => id !== Number (this .$route .params .id ))
297
+
298
+ // Array of id of the remaining users
299
+ linkedUser = linkedUser .map (({id}) => id)
300
+
301
+ let saveSearchObj = {
302
+ user_ids: linkedUser,
303
+ };
304
+
305
+ let updatedSearchResult = await restClient .updateSaveSearch (
306
+ this .selectedItem [" id" ],
307
+ saveSearchObj,
308
+ this .user ().credentials .token
309
+ );
310
+
311
+ // Commit the updated result to store
312
+ saveSearch .commit (" saveSearch/setSaveSearchResult" , updatedSearchResult);
313
+
314
+ await this .combinedSearches (false , true );
315
+
316
+ this .loading = false ;
317
+ this .unlinkSavedSearch = false ;
318
+ this .closeDialog ();
319
+
320
+ },
321
+
224
322
/**
225
323
* Close dialog
226
324
*/
@@ -246,7 +344,8 @@ export default {
246
344
return e[' id' ] !== item .creator [' id' ]
247
345
})
248
346
return additionalUsersList;
249
- }
347
+ },
348
+
250
349
},
251
350
};
252
351
</script >
0 commit comments