Updated Google Avatar, Admin Features, All Pages with small changes, Filters in Publications Page

This commit is contained in:
tanmaychinchore
2025-12-11 18:01:16 +05:30
parent f81f73d614
commit 54725c2a05
12 changed files with 236 additions and 63 deletions

View File

@@ -43,9 +43,21 @@ class GoogleController extends Controller
[ [
'name' => $googleUser->getName() ?: $email, 'name' => $googleUser->getName() ?: $email,
'password' => bcrypt(Str::random(16)), // Generate a random password 'password' => bcrypt(Str::random(16)), // Generate a random password
'profile_image' => $googleUser->getAvatar(),
] ]
); );
// Update profile image if it changed or wasn't set (for existing users logging in)
if (!$user->profile_image) {
$user->update(['profile_image' => $googleUser->getAvatar()]);
}
// Sync to FacultyProfile
$profile = \App\Models\FacultyProfile::firstOrCreate(['user_id' => $user->id]);
if (!$profile->profile_photo_path) {
$profile->update(['profile_photo_path' => $googleUser->getAvatar()]);
}
Auth::login($user); Auth::login($user);
return redirect()->route('dashboard'); return redirect()->route('dashboard');

View File

@@ -77,12 +77,16 @@ class FacultyProfileController extends Controller
// Handle profile photo upload // Handle profile photo upload
if ($request->hasFile('profile_photo')) { if ($request->hasFile('profile_photo')) {
if ($profile->profile_photo_path && Storage::exists($profile->profile_photo_path)) { if ($profile->profile_photo_path && Storage::disk('public')->exists($profile->profile_photo_path)) {
Storage::delete($profile->profile_photo_path); Storage::disk('public')->delete($profile->profile_photo_path);
} }
$validated['profile_photo_path'] = $request->file('profile_photo') $path = $request->file('profile_photo')->store('profile_photos', 'public');
->store('public/profile_photos'); $validated['profile_photo_path'] = $path;
// Update user profile image as well
$user->profile_image = $path;
$user->save();
} }
// Update profile with validated data // Update profile with validated data

View File

@@ -142,8 +142,8 @@ class PublicationsController extends Controller
}); });
} }
if ($request->has('is_peer_reviewed') && !empty($request->is_peer_reviewed)) { if ($request->has('category') && !empty($request->category)) {
$publications->where('is_peer_reviewed', $request->is_peer_reviewed); $publications->where('category', $request->category);
} }
if ($request->has('dateFrom') && !empty($request->dateFrom)) { if ($request->has('dateFrom') && !empty($request->dateFrom)) {

View File

@@ -3,6 +3,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\Department; use App\Models\Department;
use App\Models\Role;
use App\Models\User; use App\Models\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Yajra\DataTables\Facades\DataTables; use Yajra\DataTables\Facades\DataTables;
@@ -22,7 +23,8 @@ class UserController extends Controller
public function index() public function index()
{ {
$departments = Department::all(); $departments = Department::all();
return view('pages.users.index', compact('departments')); $roles = Role::all();
return view('pages.users.index', compact('departments', 'roles'));
} }
public function getUsersData(Request $request) public function getUsersData(Request $request)
@@ -87,7 +89,11 @@ class UserController extends Controller
'email' => 'required|email|unique:users', 'email' => 'required|email|unique:users',
'password' => 'required|string|min:8', 'password' => 'required|string|min:8',
'role_id' => 'required|exists:roles,id', 'role_id' => 'required|exists:roles,id',
'department_id' => 'nullable|exists:departments,id', 'department_id' => 'required|exists:departments,id',
'mobile_no' => 'nullable|string|max:15',
'extension' => 'nullable|string|max:10',
'orcid_id' => 'nullable|string|max:19|unique:users',
'scopus_id' => 'nullable|string|max:20|unique:users',
]); ]);
$user = User::create([ $user = User::create([
@@ -96,9 +102,13 @@ class UserController extends Controller
'password' => bcrypt($request->password), 'password' => bcrypt($request->password),
'role_id' => $request->role_id, 'role_id' => $request->role_id,
'department_id' => $request->department_id, 'department_id' => $request->department_id,
'mobile_no' => $request->mobile_no,
'extension' => $request->extension,
'orcid_id' => $request->orcid_id,
'scopus_id' => $request->scopus_id,
]); ]);
return $user; return response()->json($user, 201);
} }
public function show(User $user) public function show(User $user)

View File

@@ -21,6 +21,7 @@ class User extends Authenticatable
'mobile_no', 'mobile_no',
'extension', 'extension',
'scholar_url', // ✅ added this line 'scholar_url', // ✅ added this line
'profile_image',
]; ];
protected $hidden = [ protected $hidden = [

View File

@@ -44,7 +44,20 @@
<div class="dropdown ms-2"> <div class="dropdown ms-2">
<a class="d-flex align-items-center text-white text-decoration-none dropdown-toggle" <a class="d-flex align-items-center text-white text-decoration-none dropdown-toggle"
href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false"> href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<img src="{{ asset('assets/frontend/images/user.png') }}" @php
$user = Auth::user();
$imagePath = $user->profile_image;
$imageUrl = asset('assets/frontend/images/user.png'); // Default
if ($imagePath) {
if (Str::startsWith($imagePath, ['http://', 'https://'])) {
$imageUrl = $imagePath;
} else {
$imageUrl = Storage::disk('public')->url($imagePath);
}
}
@endphp
<img src="{{ $imageUrl }}"
alt="profile" alt="profile"
class="navbar-profile-picture me-2"> class="navbar-profile-picture me-2">
<span>{{ Auth::user()->name }}</span> <span>{{ Auth::user()->name }}</span>

View File

@@ -64,7 +64,7 @@
<!-- Column Selector --> <!-- Column Selector -->
<div class="flex justify-between col-md-12 mt-3 mb-4"> <div class="flex justify-between col-md-12 mt-3 mb-4">
<!-- Include the reusable download-proofs component --> <!-- Include the reusable download-proofs component -->
<x-download-proofs :route="route('admin.downloadProofs')" :model="'ActivitiesOrganised'" /> <x-download-proofs :route="route('admin.downloadProofs')" :model="'ExternalEngagement'" />
@php @php
use Illuminate\Support\Str; use Illuminate\Support\Str;
$labels = [ $labels = [

View File

@@ -65,7 +65,7 @@
<!-- Column Selector --> <!-- Column Selector -->
<div class="flex justify-between col-md-12 mt-3 mb-4"> <div class="flex justify-between col-md-12 mt-3 mb-4">
<!-- Include the reusable download-proofs component --> <!-- Include the reusable download-proofs component -->
<x-download-proofs :route="route('admin.downloadProofs')" :model="'ActivitiesOrganised'" /> <x-download-proofs :route="route('admin.downloadProofs')" :model="'OnlineCourse'" />
@php @php
use Illuminate\Support\Str; use Illuminate\Support\Str;
$labels = [ $labels = [

View File

@@ -10,6 +10,8 @@
<h3 class="page-title m-0"> <h3 class="page-title m-0">
<i class="fas fa-book-open me-2 text-primary"></i>All Publications <i class="fas fa-book-open me-2 text-primary"></i>All Publications
</h3> </h3>
<!-- Include the reusable send-email component -->
<x-send-email />
@if(auth()->user()->role->name === 'Faculty') @if(auth()->user()->role->name === 'Faculty')
<input type="hidden" id="scholar-url" value="{{ $scholarUrl ?? '' }}"> <input type="hidden" id="scholar-url" value="{{ $scholarUrl ?? '' }}">
<button id="btn-fetch-scholar" class="btn btn-outline-primary"> <button id="btn-fetch-scholar" class="btn btn-outline-primary">
@@ -57,8 +59,6 @@
</div> </div>
</div> </div>
@endif @endif
<!-- Include the reusable send-email component -->
<x-send-email />
</div> </div>
<div class="card-body"> <div class="card-body">
@@ -88,14 +88,16 @@
<div class="col-md-4"> <div class="col-md-4">
<div class="input-group"> <div class="input-group">
<span class="input-group-text bg-light">Peer Reviewed</span> <span class="input-group-text bg-light">Category</span>
<select id="is_peer_reviewed-filter" class="form-select"> <select id="category-filter" class="form-select">
<option value="">All</option> <option value="">All</option>
<option value="Yes">Yes</option> <option value="SCI">SCI</option>
<option value="No">No</option> <option value="Scopus">Scopus</option>
<option value="Peer Reviewed">Peer Reviewed</option>
</select> </select>
</div> </div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<div class="input-group"> <div class="input-group">
<span class="input-group-text bg-light">Date Range</span> <span class="input-group-text bg-light">Date Range</span>
@@ -109,7 +111,7 @@
<!-- Column Selector --> <!-- Column Selector -->
<div class="flex justify-between col-md-12 mt-3 mb-4"> <div class="flex justify-between col-md-12 mt-3 mb-4">
<!-- Include the reusable download-proofs component --> <!-- Include the reusable download-proofs component -->
<x-download-proofs :route="route('admin.downloadProofs')" :model="'ActivitiesOrganised'" /> <x-download-proofs :route="route('admin.downloadProofs')" :model="'Publications'" />
@php @php
use Illuminate\Support\Str; use Illuminate\Support\Str;
$labels = [ $labels = [

View File

@@ -31,11 +31,19 @@
<select id="role-filter" class="form-select"> <select id="role-filter" class="form-select">
<option value="">All Roles</option> <option value="">All Roles</option>
<!-- Category options would be populated dynamically --> <!-- Category options would be populated dynamically -->
@foreach($roles as $role)
<option value="{{ $role->id }}">{{ $role->name }}</option>
@endforeach
</select> </select>
</div> </div>
</div> </div>
<div class="col-md-4 d-flex justify-content-end"> <div class="col-md-4 d-flex justify-content-end gap-2">
<!-- Add User Button -->
<button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#addUserModal">
<i class="fas fa-plus me-1"></i> Add User
</button>
<!-- Column Selector --> <!-- Column Selector -->
<div id="columnsSelector" class=""> <div id="columnsSelector" class="">
@php @php
@@ -95,6 +103,74 @@
</div> </div>
</div> </div>
<!-- Add User Modal -->
<div class="modal fade" id="addUserModal" tabindex="-1" aria-labelledby="addUserModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header bg-danger text-white">
<h5 class="modal-title" id="addUserModalLabel">Add New User</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form id="addUserForm">
<div class="modal-body">
<div class="row g-3">
<div class="col-md-6">
<label for="name" class="form-label">Name <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="col-md-6">
<label for="email" class="form-label">Email <span class="text-danger">*</span></label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="col-md-6">
<label for="password" class="form-label">Password <span class="text-danger">*</span></label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="col-md-6">
<label for="role_id" class="form-label">Role <span class="text-danger">*</span></label>
<select class="form-select" id="role_id" name="role_id" required>
<option value="" selected disabled>Select Role</option>
<option value="1">Admin</option>
<option value="2">HOD</option>
<option value="3">Faculty</option>
</select>
</div>
<div class="col-md-6">
<label for="department_id" class="form-label">Department</label>
<select class="form-select" id="department_id" name="department_id">
<option value="" selected disabled>Select Department</option>
@foreach($departments as $department)
<option value="{{ $department->id }}">{{ $department->name }}</option>
@endforeach
</select>
</div>
<div class="col-md-6">
<label for="mobile_no" class="form-label">Mobile No</label>
<input type="text" class="form-control" id="mobile_no" name="mobile_no">
</div>
<div class="col-md-6">
<label for="extension" class="form-label">Extension</label>
<input type="text" class="form-control" id="extension" name="extension">
</div>
<div class="col-md-6">
<label for="orcid_id" class="form-label">ORCID ID</label>
<input type="text" class="form-control" id="orcid_id" name="orcid_id">
</div>
<div class="col-md-6">
<label for="scopus_id" class="form-label">Scopus ID</label>
<input type="text" class="form-control" id="scopus_id" name="scopus_id">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-danger">Save User</button>
</div>
</form>
</div>
</div>
</div>
@endsection @endsection
@section('scripts') @section('scripts')
@@ -358,6 +434,44 @@
$('#department-filter').val(departmentId).trigger('change'); $('#department-filter').val(departmentId).trigger('change');
} }
}); });
// Handle Add User Form Submission
$('#addUserForm').on('submit', function(e) {
e.preventDefault();
// Clear previous errors
$('.is-invalid').removeClass('is-invalid');
$('.invalid-feedback').remove();
const formData = new FormData(this);
formData.append('_token', csrf_token);
$.ajax({
url: "{{ route('users.store') }}",
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(response) {
$('#addUserModal').modal('hide');
$('#addUserForm')[0].reset();
table.ajax.reload();
showToast('User added successfully', 'success');
},
error: function(xhr) {
if (xhr.status === 422) {
const errors = xhr.responseJSON.errors;
Object.keys(errors).forEach(function(key) {
const input = $(`#${key}`);
input.addClass('is-invalid');
input.after(`<div class="invalid-feedback">${errors[key][0]}</div>`);
});
} else {
showToast('Error adding user', 'danger');
}
}
});
});
}); });
</script> </script>
<style> <style>

View File

@@ -87,11 +87,23 @@
<label class="form-label fw-semibold">Profile Photo</label> <label class="form-label fw-semibold">Profile Photo</label>
<input type="file" name="profile_photo" class="form-control"> <input type="file" name="profile_photo" class="form-control">
@if ($profile->profile_photo_path) @php
$user = auth()->user();
$imagePath = $profile->profile_photo_path ?? $user->profile_image;
$imageUrl = asset('assets/frontend/images/profile-icon.svg'); // Default
if ($imagePath) {
if (Str::startsWith($imagePath, ['http://', 'https://'])) {
$imageUrl = $imagePath;
} else {
$imageUrl = Storage::disk('public')->url($imagePath);
}
}
@endphp
<div class="mt-2"> <div class="mt-2">
<img src="{{ Storage::url($profile->profile_photo_path) }}" alt="Profile Photo" width="100" class="rounded shadow-sm"> <img src="{{ $imageUrl }}" alt="Profile Photo" width="100" class="rounded shadow-sm">
</div> </div>
@endif
</div> </div>
</div> </div>

View File

@@ -14,17 +14,22 @@
<div class="card shadow-sm p-4"> <div class="card shadow-sm p-4">
<div class="row align-items-center mb-3"> <div class="row align-items-center mb-3">
<div class="col-md-2 text-center"> <div class="col-md-2 text-center">
@if($profile->profile_photo_path) @php
<img src="{{ Storage::url($profile->profile_photo_path) }}" $imagePath = $profile->profile_photo_path ?? auth()->user()->profile_image;
$imageUrl = asset('assets/frontend/images/default-avatar.png'); // Default
if ($imagePath) {
if (Str::startsWith($imagePath, ['http://', 'https://'])) {
$imageUrl = $imagePath;
} else {
$imageUrl = Storage::disk('public')->url($imagePath);
}
}
@endphp
<img src="{{ $imageUrl }}"
alt="Profile Photo" alt="Profile Photo"
class="rounded-circle shadow-sm" class="rounded-circle shadow-sm"
width="120" height="120"> width="120" height="120">
@else
<img src="{{ asset('assets/frontend/images/default-avatar.png') }}"
alt="Default Photo"
class="rounded-circle shadow-sm"
width="120" height="120">
@endif
</div> </div>
<div class="col-md-10"> <div class="col-md-10">
<h5 class="fw-bold mb-1">{{ $profile->salutation }} {{ $profile->name }}</h5> <h5 class="fw-bold mb-1">{{ $profile->salutation }} {{ $profile->name }}</h5>