Skip to content

Commit 2867fce

Browse files
committed
unlink from non-owning user
1 parent f0bc27d commit 2867fce

File tree

1 file changed

+105
-6
lines changed

1 file changed

+105
-6
lines changed

src/components/Users/Profiles/Private/ViewSavedSearchesTable.vue

Lines changed: 105 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,23 @@
5959
</ul>
6060
</template>
6161
<template #[`item.actions`]="{ item }">
62+
<!--User logged in and is on its public profile page-->
6263
<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
6379
@click="deleteItem(item)"
6480
>
6581
mdi-delete
@@ -102,6 +118,31 @@
102118
<v-spacer />
103119
</v-card-actions>
104120
</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>
105146
</v-dialog>
106147
</div>
107148
</template>
@@ -111,6 +152,7 @@ import { mapActions, mapGetters, mapState } from "vuex";
111152
112153
import RESTClient from "@/lib/Client/RESTClient";
113154
import advancedSearch from "@/store";
155+
import saveSearch from "@/store";
114156
115157
const restClient = new RESTClient();
116158
@@ -124,6 +166,7 @@ export default {
124166
return {
125167
modifyDialog: false,
126168
deleteSavedSearch: false,
169+
unlinkSavedSearch: false,
127170
selectedItem: {},
128171
totalSearches: [],
129172
loading: false,
@@ -161,20 +204,28 @@ export default {
161204
this.combinedSearches();
162205
},
163206
methods: {
164-
...mapActions("users", ["getUser"]),
207+
...mapActions("users", ["getUser", "getPublicUser"]),
165208
/**
166209
* Fetch combinedSearches and savedSearches from the props
167210
* removing the duplicates and displaying in user profile
168211
* page
169212
*/
170-
async combinedSearches(searchDeleted) {
213+
async combinedSearches(searchDeleted, searchUnlinked) {
171214
let createdSearches, savedSearches
172215
173216
if (searchDeleted) {
174217
await this.getUser();
175218
createdSearches = this.getUserRecords.user["createdSearches"];
176219
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 {
178229
createdSearches = this.createdSearches;
179230
savedSearches = this.savedSearches;
180231
}
@@ -194,11 +245,12 @@ export default {
194245
195246
/**
196247
* Delete the selection savedSearch
197-
* @param item
248+
* @param item - {Object} - Saved Search details
198249
*/
199250
deleteItem(item) {
200251
this.selectedItem = item;
201252
this.modifyDialog = true;
253+
this.unlinkSavedSearch = false;
202254
this.deleteSavedSearch = true;
203255
},
204256
@@ -214,13 +266,59 @@ export default {
214266
);
215267
216268
if (data["message"] === "success") {
217-
await this.combinedSearches(true);
269+
await this.combinedSearches(true, false);
218270
}
219271
this.loading = false;
220272
this.deleteSavedSearch = false;
221273
this.closeDialog();
222274
},
223275
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+
224322
/**
225323
* Close dialog
226324
*/
@@ -246,7 +344,8 @@ export default {
246344
return e['id'] !== item.creator['id']
247345
})
248346
return additionalUsersList;
249-
}
347+
},
348+
250349
},
251350
};
252351
</script>

0 commit comments

Comments
 (0)