|
|
|
@ -13,11 +13,11 @@ |
|
|
|
|
:loading="isLoading" |
|
|
|
|
:multiple="true" |
|
|
|
|
:options="users" |
|
|
|
|
:placeholder="$t('Share with User')" |
|
|
|
|
:searchable="true" |
|
|
|
|
label="username" |
|
|
|
|
limit="3" |
|
|
|
|
limit-text="3" |
|
|
|
|
:placeholder="$t('Share with User')" |
|
|
|
|
track-by="id" |
|
|
|
|
@select="addUser" |
|
|
|
|
@search-change="asyncFind" |
|
|
|
@ -26,188 +26,185 @@ |
|
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
|
|
|
|
|
|
import ShowLinks from "../../components/resource_links/ShowLinks.vue"; |
|
|
|
|
import {computed, ref, toRefs} from "vue"; |
|
|
|
|
import axios from "axios"; |
|
|
|
|
import {ENTRYPOINT} from "../../config/entrypoint"; |
|
|
|
|
import useVuelidate from "@vuelidate/core"; |
|
|
|
|
import VueMultiselect from 'vue-multiselect' |
|
|
|
|
import isEmpty from 'lodash/isEmpty'; |
|
|
|
|
import {mapGetters, useStore} from "vuex"; |
|
|
|
|
import {RESOURCE_LINK_PUBLISHED} from "./visibility.js"; |
|
|
|
|
import ShowLinks from "../../components/resource_links/ShowLinks.vue" |
|
|
|
|
import { computed, ref, toRefs } from "vue" |
|
|
|
|
import axios from "axios" |
|
|
|
|
import { ENTRYPOINT } from "../../config/entrypoint" |
|
|
|
|
import useVuelidate from "@vuelidate/core" |
|
|
|
|
import VueMultiselect from "vue-multiselect" |
|
|
|
|
import isEmpty from "lodash/isEmpty" |
|
|
|
|
import { mapGetters, useStore } from "vuex" |
|
|
|
|
import { RESOURCE_LINK_PUBLISHED } from "./visibility.js" |
|
|
|
|
|
|
|
|
|
export default { |
|
|
|
|
name: 'EditLinks', |
|
|
|
|
name: "EditLinks", |
|
|
|
|
components: { |
|
|
|
|
VueMultiselect, |
|
|
|
|
ShowLinks |
|
|
|
|
ShowLinks, |
|
|
|
|
}, |
|
|
|
|
props: { |
|
|
|
|
item: { |
|
|
|
|
type: Object, |
|
|
|
|
required: true |
|
|
|
|
required: true, |
|
|
|
|
}, |
|
|
|
|
editStatus: { |
|
|
|
|
type: Boolean, |
|
|
|
|
required: false, |
|
|
|
|
default: true |
|
|
|
|
default: true, |
|
|
|
|
}, |
|
|
|
|
showStatus: { |
|
|
|
|
type: Boolean, |
|
|
|
|
required: false, |
|
|
|
|
default: true |
|
|
|
|
default: true, |
|
|
|
|
}, |
|
|
|
|
linksType: { |
|
|
|
|
type: String, |
|
|
|
|
required: true, |
|
|
|
|
default: 'user' |
|
|
|
|
default: "user", |
|
|
|
|
}, |
|
|
|
|
showShareWithUser: { |
|
|
|
|
type: Boolean, |
|
|
|
|
required: true, |
|
|
|
|
default: true |
|
|
|
|
} |
|
|
|
|
default: true, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
setup(props) { |
|
|
|
|
const users = ref([]); |
|
|
|
|
const selectedUsers = ref([]); |
|
|
|
|
const isLoading = ref(false); |
|
|
|
|
const store = useStore(); |
|
|
|
|
const { showShareWithUser } = toRefs(props); |
|
|
|
|
const users = ref([]) |
|
|
|
|
const selectedUsers = ref([]) |
|
|
|
|
const isLoading = ref(false) |
|
|
|
|
const store = useStore() |
|
|
|
|
const { showShareWithUser } = toRefs(props) |
|
|
|
|
|
|
|
|
|
function addUser(userResult) { |
|
|
|
|
if (isEmpty(props.item.resourceLinkListFromEntity)) { |
|
|
|
|
props.item.resourceLinkListFromEntity = []; |
|
|
|
|
props.item.resourceLinkListFromEntity = [] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const someLink = props.item.resourceLinkListFromEntity.some(link => link.user.username === userResult.username); |
|
|
|
|
const someLink = props.item.resourceLinkListFromEntity.some((link) => link.user.username === userResult.username) |
|
|
|
|
|
|
|
|
|
if (someLink) { |
|
|
|
|
return; |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
props.item.resourceLinkListFromEntity.push( |
|
|
|
|
{ |
|
|
|
|
uid: userResult.id, |
|
|
|
|
user: {username: userResult.username}, |
|
|
|
|
visibility: RESOURCE_LINK_PUBLISHED |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
props.item.resourceLinkListFromEntity.push({ |
|
|
|
|
uid: userResult.id, |
|
|
|
|
user: { username: userResult.username }, |
|
|
|
|
visibility: RESOURCE_LINK_PUBLISHED, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function findUsers(query) { |
|
|
|
|
axios |
|
|
|
|
.get(ENTRYPOINT + 'users', { |
|
|
|
|
params: { |
|
|
|
|
username: query |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.then(response => { |
|
|
|
|
isLoading.value = false; |
|
|
|
|
let data = response.data; |
|
|
|
|
users.value = data['hydra:member']; |
|
|
|
|
}) |
|
|
|
|
.catch(function (error) { |
|
|
|
|
isLoading.value = false; |
|
|
|
|
console.log(error); |
|
|
|
|
}); |
|
|
|
|
.get(ENTRYPOINT + "users", { |
|
|
|
|
params: { |
|
|
|
|
username: query, |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
.then((response) => { |
|
|
|
|
isLoading.value = false |
|
|
|
|
let data = response.data |
|
|
|
|
users.value = data["hydra:member"] |
|
|
|
|
}) |
|
|
|
|
.catch(function (error) { |
|
|
|
|
isLoading.value = false |
|
|
|
|
console.log(error) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function findUserRelUsers(query) { |
|
|
|
|
const currentUser = computed(() => store.getters['security/getUser']); |
|
|
|
|
const currentUser = computed(() => store.getters["security/getUser"]) |
|
|
|
|
|
|
|
|
|
axios |
|
|
|
|
.get(ENTRYPOINT + 'user_rel_users', { |
|
|
|
|
params: { |
|
|
|
|
user: currentUser.value['id'], |
|
|
|
|
'friend.username': query |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.then(response => { |
|
|
|
|
isLoading.value = false; |
|
|
|
|
|
|
|
|
|
users.value = response.data['hydra:member'].map(member => member.friend); |
|
|
|
|
}) |
|
|
|
|
.catch(function (error) { |
|
|
|
|
isLoading.value = false; |
|
|
|
|
}); |
|
|
|
|
.get(ENTRYPOINT + "user_rel_users", { |
|
|
|
|
params: { |
|
|
|
|
user: currentUser.value["id"], |
|
|
|
|
"friend.username": query, |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
.then((response) => { |
|
|
|
|
isLoading.value = false |
|
|
|
|
|
|
|
|
|
users.value = response.data["hydra:member"].map((member) => member.friend) |
|
|
|
|
}) |
|
|
|
|
.catch(function () { |
|
|
|
|
isLoading.value = false |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function findStudentsInCourse(query) { |
|
|
|
|
const searchParams = new URLSearchParams(window.location.search); |
|
|
|
|
const cId = parseInt(searchParams.get('cid')); |
|
|
|
|
const sId = parseInt(searchParams.get('sid')); |
|
|
|
|
const searchParams = new URLSearchParams(window.location.search) |
|
|
|
|
const cId = parseInt(searchParams.get("cid")) |
|
|
|
|
const sId = parseInt(searchParams.get("sid")) |
|
|
|
|
|
|
|
|
|
if (!cId && !sId) { |
|
|
|
|
return; |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let endpoint = ENTRYPOINT; |
|
|
|
|
let endpoint = ENTRYPOINT |
|
|
|
|
let params = { |
|
|
|
|
'user.username': query, |
|
|
|
|
}; |
|
|
|
|
"user.username": query, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (sId) { |
|
|
|
|
params.session = endpoint + `sessions/${sId}`; |
|
|
|
|
params.session = endpoint + `sessions/${sId}` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (cId) { |
|
|
|
|
if (sId) { |
|
|
|
|
endpoint += `session_rel_course_rel_users`; |
|
|
|
|
params.course = endpoint + `courses/${cId}`; |
|
|
|
|
endpoint += `session_rel_course_rel_users` |
|
|
|
|
params.course = endpoint + `courses/${cId}` |
|
|
|
|
} else { |
|
|
|
|
endpoint += `courses/${cId}/users`; |
|
|
|
|
endpoint += `courses/${cId}/users` |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
endpoint += `session_rel_users`; |
|
|
|
|
endpoint += `session_rel_users` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
axios |
|
|
|
|
.get(endpoint, { |
|
|
|
|
params |
|
|
|
|
}) |
|
|
|
|
.then(response => { |
|
|
|
|
isLoading.value = false; |
|
|
|
|
|
|
|
|
|
users.value = response.data['hydra:member'].map(member => member.user); |
|
|
|
|
}) |
|
|
|
|
.catch(function (error) { |
|
|
|
|
isLoading.value = false; |
|
|
|
|
}); |
|
|
|
|
.get(endpoint, { |
|
|
|
|
params, |
|
|
|
|
}) |
|
|
|
|
.then((response) => { |
|
|
|
|
isLoading.value = false |
|
|
|
|
|
|
|
|
|
users.value = response.data["hydra:member"].map((member) => member.user) |
|
|
|
|
}) |
|
|
|
|
.catch(function () { |
|
|
|
|
isLoading.value = false |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function asyncFind(query) { |
|
|
|
|
if (query.toString().length < 3) { |
|
|
|
|
return; |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
isLoading.value = true; |
|
|
|
|
isLoading.value = true |
|
|
|
|
|
|
|
|
|
switch (props.linksType) { |
|
|
|
|
case 'users': |
|
|
|
|
findUsers(query); |
|
|
|
|
break; |
|
|
|
|
case "users": |
|
|
|
|
findUsers(query) |
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
case 'user_rel_users': |
|
|
|
|
findUserRelUsers(query); |
|
|
|
|
break; |
|
|
|
|
case "user_rel_users": |
|
|
|
|
findUserRelUsers(query) |
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
case 'course_students': |
|
|
|
|
findStudentsInCourse(query); |
|
|
|
|
break; |
|
|
|
|
case "course_students": |
|
|
|
|
findStudentsInCourse(query) |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return {v$: useVuelidate(), users, selectedUsers, asyncFind, addUser, isLoading, showShareWithUser}; |
|
|
|
|
return { v$: useVuelidate(), users, selectedUsers, asyncFind, addUser, isLoading, showShareWithUser } |
|
|
|
|
}, |
|
|
|
|
computed: { |
|
|
|
|
...mapGetters({ |
|
|
|
|
'isAuthenticated': 'security/isAuthenticated', |
|
|
|
|
'currentUser': 'security/getUser', |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
isAuthenticated: "security/isAuthenticated", |
|
|
|
|
currentUser: "security/getUser", |
|
|
|
|
}), |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
<style src="vue-multiselect/dist/vue-multiselect.css"></style> |
|
|
|
|