Newer
Older
<div
id="page-content-wrapper"
class="flex flex-wrap justify-center"
>
<base-toaster
:open="toasterIsOpen"
@close="hideDialog"
>
<div class="flex justify-between space-x-4 items-center">
<font-awesome-icon
class="ml-3"
icon="fa-solid fa-thumbs-up "
size="lg"
/>
<h4>{{toasterMessage}}</h4>
<button
class="btn btn-outline"
@click="hideDialog"
>
<font-awesome-icon
icon="fa-regular fa-circle-xmark"
size="2x"
/>
</button>
</div>
</base-toaster>
<template slot-scope="{ response, loading, error: profile_error }">
<slot
:response="response"
:loading="loading"
:error="profile_error"
>
<div v-if="loading">
<base-spinner />
</div>
<div v-else-if="!loading && profile_error">
<p class="text-red-500 text-2xl">
{{ response }}
</p>
</div>
<div v-else>
<!-- {{response}}-->
<div class="panel panel-default">
<div class="panel-body">
<div class="container-fluid col-md-12">
<div class="row">
<div class="col-sm-9">
<div class="flex justify-between">
<b>{{ response.username }}</b>
<div class="relative">
<button
class="
text-white
bg-blue-500
hover:bg-blue-700
focus:ring-2 focus:ring-blue-300
rounded-lg
items-center
px-5
py-3
text-center
font-bold
mr-2
font-bold
"
@click="isOpen = !isOpen"
>
Edit
<font-awesome-icon
class="ml-2"
icon="fa-solid fa-user-pen"
/>
</button>
<button
v-if="isOpen"
tabindex="-1"
class="fixed inset-0 cursor-default h-full w-full"
mt-2
grid grid-cols-1
bg-black
min-w-max
border border-gray-200
divide-y divide-white-base
>
<!-- Active: "bg-gray-100 text-gray-900", Not Active: "text-gray-700" -->
<a
class="
px-4
rounded-lg
text-2xl text-white-base
hover:text-pink-base hover:no-underline
px-4
rounded-lg
text-2xl text-white-base
hover:text-pink-base hover:no-underline
px-4
rounded-lg
text-2xl text-white-base
hover:text-pink-base hover:no-underline
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-9">
{{ setRole(response.role.name) }}
</div>
</div>
<div class="col-sm-9">
<p>
{{ response.motivation_text }}
</p>
</div>
</div>
<div class="col-sm-9">
<div>
{{ response.current_affiliation }}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="panel-body">
<div class="container-fluid col-md-12">
<div v-if="showEditScientificDis">
<h3 class="mb-6 border-b">
Update Scientific Discipline
</h3>
<div class="row">
<div class="text col-sm-3 p-4">
Scientific Discipline
</div>
<div class="col-sm-9 p-4">
<div
v-for="options in scientificDisciplineOptions"
:key="options.id"
>
<input
:id="options.id"
v-model="selected"
type="checkbox"
class="h-6 w-6"
:name="options"
:value="options.discipline"
<p
v-if="profile_error && scientificErrMsg"
class="text-red-500 font-bold mt-2"
>
{{ scientificErrMsg }}
</p>
</div>
</div>
<div class="col-sm-9 p-4">
<input
id="inline-profile-link"
v-model.trim="profile_link"
class="
bg-white
w-1/3
py-4
px-4
rounded-lg
text-gray-700
bg-transparent
border border-gray-500
hover:border-gray-700
"
<p
v-if="profile_error && profileLinkErrMsg"
class="text-red-500 font-bold mt-2"
>
{{ profileLinkErrMsg }}
</p>
</div>
</div>
<div class="col-sm-9 p-4">
<input
id="current-password"
v-model.trim="currentPassword"
class="
bg-white
w-1/3
py-4
px-4
rounded-lg
text-gray-700
bg-transparent
border border-gray-500
hover:border-gray-700
"
<div class="col-sm-9 p-4">
<input
id="inline-password"
v-model.trim="newPassword"
class="
bg-white
w-1/3
py-4
px-4
rounded-lg
text-gray-700
bg-transparent
border border-gray-500
hover:border-gray-700
"
<div class="row">
<div class="text col-sm-3 p-4">
Confirm New Password
</div>
<div class="col-sm-9 p-4">
<input
id="confirm-password"
v-model.trim="confirmPassword"
class="
bg-white
w-1/3
py-4
px-4
rounded-lg
text-gray-700
bg-transparent
border border-gray-500
hover:border-gray-700
"
<p
v-if="profile_error && passwordErrMsg"
class="text-red-500 font-bold mt-2"
>
{{ passwordErrMsg }}
</p>
</div>
</div>
bg-blue-500
text-xl
font-bold
rounded-lg
px-5
py-4
text-white
hover:bg-blue-700
"
@click="update(response)"
>
Update Profile
</button>
<button
class="
bg-gray-500
text-xl
font-bold
rounded-lg
px-5
py-4
text-white
hover:bg-gray-700
"
</div>
</div>
<p
v-if="profile_error && errorMsg"
class="text-red-500 font-bold mt-2"
>
{{ errorMsg }}
</p>
<!-- <button v-if="userData !== null && (getRole === 'Contributor' || getRole === 'Maintainer')"
class="btn btn-primary" @click="$router.push('/updateitem/new')">
</button> -->
<fetch-users v-if="getRole === 'Administrator'" :key="'users-' + updatedUsersKey">
<h4 class="round">
User List
</h4>
<user-table
id="usersTable"
:data="response"
@approve="approve"
import FetchProfile from '@/components/CMS/fetchProfile';
import FetchUpdateItems from '@/components/CMS/fetchUpdateItems';
import FetchUsers from '@/components/CMS/fetchUsers';
import UserTable from '../components/UserTable.vue';
import BaseSpinner from '../components/UI/BaseSpinner.vue';
import BaseToaster from '../components/UI/BaseToaster.vue';
const _ = require('lodash');
let host = require('@/components/js/const').apiHost;
FetchProfile,
UserTable,
FetchUsers,
BaseSpinner,
BaseToaster,
msg: String,
scientific_discipline: [],
current_affiliation: '',
profile_link: '',
currentPassword: '',
newPassword: '',
confirmPassword: '',
isDev: process.env.NODE_ENV === 'development',
editMode: false,
toasterIsOpen: false,
toasterMessage: 'Profile update successful!',
error: false,
scientificDisciplineOptions: [
{ id: '1', discipline: 'Physics' },
{ id: '2', discipline: 'Chemistry' },
{ id: '3', discipline: 'Biology' },
{ id: '4', discipline: 'Computer Science' },
{ id: '5', discipline: 'Mathematics' },
],
selected: [],
isOpen: false,
showEditScientificDis: false,
showEditProfileLink: false,
showChangePassword: false,
scientificErrMsg: '',
profileLinkErrMsg: '',
passwordErrMsg: '',
errorMsg: '',
updatedUsersKey: 0,
};
jwt: function () {
getRole: function () {
},
mounted: function () {
const vm = this;
if (vm.userData === null) {
} else {
vm.user = vm.userData.id;
vm.current_role = vm.userData.current_role;
vm.scientific_discipline = vm.userData.scientific_discipline;
if (vm.scientific_discipline === null) {
vm.scientific_discipline = [];
}
}
},
close() {
this.editMode = false;
this.showEditScientificDis = false;
this.showEditProfileLink = false;
this.showChangePassword = false;
this.error = false;
this.scientificErrMsg = '';
this.profileLinkErrMsg = '';
this.passwordErrMsg = '';
this.selected = [];
},
openScientificDisciplineEdit() {
this.editMode = true;
this.showEditScientificDis = true;
this.showEditProfileLink = false;
this.showChangePassword = false;
},
openProfileLinkEdit() {
this.editMode = true;
this.showEditScientificDis = false;
this.showEditProfileLink = true;
this.showChangePassword = false;
},
openChangePassword() {
this.editMode = true;
this.showEditScientificDis = false;
this.showEditProfileLink = false;
this.showChangePassword = true;
},
showDialog() {
this.toasterMessage = 'Profile update successful!';
this.toasterIsOpen = true;
},
hideDialog() {
this.toasterIsOpen = false;
},
showEditMode() {
this.editMode = true;
},
//console.log("role name is,", roleName);
const vm = this;
window.localStorage.setItem('roleName', roleName);
vm.$store.dispatch('User/setUserRole', roleName);
return roleName;
async update(e) {
const vm = this;
if (vm.isDev) {
}
const jwt = vm.jwt;
if (jwt === null) {
vm.loaded = false;
return;
vm.user = e.id;
let dat;
if (this.showEditScientificDis) {
if (this.selected.length === 0) {
this.error = true;
return;
}
dat = {
id: vm.user,
scientific_discipline: vm.selected,
};
} else if (this.showEditProfileLink) {
if (!this.profile_link) {
this.error = true;
return;
}
dat = {
id: vm.user,
profile_link: vm.profile_link,
};
} else if (this.showChangePassword) {
this.error = true;
return;
}
dat = {
identifier: vm.user,
password: vm.currentPassword,
newPassword: vm.newPassword,
confirmPassword: vm.confirmPassword,
};
}
this.error = false;
this.scientificErrMsg = '';
this.profileLinkErrMsg = '';
this.passwordErrMsg = '';
// let dat = {
// id: vm.user,
// profile_link: vm.profile_link,
// scientific_discipline: vm.selected,
// password: vm.password,
// };
try {
let res;
if (this.showChangePassword) {
res = await this.axios.post(`${host}/api/password`, dat, {
headers: {
Authorization: `Bearer ${jwt}`,
},
});
// console.log(res.data);
const newJwt = res.data.jwt;
window.localStorage.setItem('jwt', newJwt);
this.$store.dispatch('User/setJwt', newJwt);
} else {
res = await this.axios.put(`${host}/api/users/${vm.user}`, dat, {
headers: {
Authorization: `Bearer ${jwt}`,
},
});
}
this.error = false;
this.toasterMessage = 'Profile update successful!';
this.toasterIsOpen = true;
this.editMode = false;
this.isOpen = false;
setTimeout(() => {
this.selected = [];
} catch (error) {
// console.log(error.response.data.error.message)
// console.log(error.response)
this.error = true;
this.errorMsg = error;
}
},
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
async approve(e) {
const vm = this
try {
vm.user = e.id;
if (vm.isDev) {
host = require('@/components/js/const').devApiHost;
}
let jwt = vm.jwt;
if (jwt === null) {
vm.loaded = false;
return;
}
const dat = {
id: vm.user,
role: 3, // Make the user contributor
};
let res = await this.axios.put(`${host}/api/users/${vm.user}`, dat, {
headers: {
Authorization: `Bearer ${jwt}`,
},
});
jwt = require('@/components/js/const').wikiApikey;
const query = `mutation User {
users {
create (email: "${e.email}",
name: "${e.full_name}",
passwordRaw: "welcome2cdcode",
providerKey: "local",
groups: 3,
mustChangePassword: true,
sendWelcomeEmail: true) {
responseResult {
succeeded,
errorCode,
slug,
message
},
user {
email,
name
}
}
}
}`
res = await this.axios.post(`https://wiki.cd-code.org/graphql`, { query }, {
headers: {
Authorization: `Bearer ${jwt}`,
},
});
vm.error = false;
vm.toasterMessage = 'Approved and a welcome email sent!';
vm.toasterIsOpen = true;
setTimeout(() => {
vm.toasterIsOpen = false;
}, 2000);
vm.updatedUsersKey += 1;
} catch (error) {
this.error = true;
this.errorMsg = error;
}
}
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
@import url("~@/assets/bootstrap.css");
.main {
margin: 1.5rem;
}
h3 {
margin: 40px 0 0;
}
/* a {
color: #ef0087 !important;
} */