feat(profile,publications): integrate working Google Scholar import flow and unified faculty profile system

This commit is contained in:
Harshil Vora
2025-10-18 02:53:32 -07:00
parent 8fe0ef8112
commit ba28588e38
19 changed files with 915 additions and 139 deletions

View File

@@ -64,3 +64,6 @@ AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
VITE_APP_NAME="${APP_NAME}"
SERPAPI_KEY=75d51e578a0d0d2ac4cb1d6ae21410567a105d96b8df36411b4772d91beaa45c

2
.gitignore vendored
View File

@@ -18,6 +18,6 @@ yarn-error.log
/auth.json
/.fleet
/.idea
/.nova
/.novaP
/.vscode
/.zed

View File

@@ -73,8 +73,14 @@ class FacultyController extends Controller
public function viewPublicationsResponses()
{
$departments = Department::all();
return view('pages.publications.index', compact('departments'));
$user = auth()->user();
\Log::info('FacultyController: scholar_url = ' . ($user->scholar_url ?? 'NULL'));
return view('pages.publications.index', [
'scholarUrl' => $user->scholar_url,
]);
}
public function BooksPublishedForm()

View File

@@ -0,0 +1,120 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\FacultyProfile;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
class FacultyProfileController extends Controller
{
/**
* Show logged-in user's faculty profile.
*/
public function index()
{
$user = Auth::user();
$profile = FacultyProfile::firstOrCreate(
['user_id' => $user->id],
[
'name' => $user->name ?? '',
'email' => $user->email ?? '',
'phone_number' => '',
'vidhvan_id' => '',
'google_scholar_id' => '',
'linkedin_id' => '',
'designation' => '',
'salutation' => '',
'qualification' => '',
'address' => '',
'employee_id' => '',
'department_name' => '',
'programme_name' => '',
'date_of_joining' => now()->toDateString(),
]
);
return view('profile.index', compact('user', 'profile'));
}
/**
* Show the edit form for faculty profile.
*/
public function edit()
{
$user = Auth::user();
$profile = FacultyProfile::where('user_id', $user->id)->firstOrFail();
return view('profile.edit', compact('profile'));
}
/**
* Update faculty profile.
*/
public function update(Request $request)
{
$user = Auth::user();
$profile = FacultyProfile::where('user_id', $user->id)->firstOrFail();
$validated = $request->validate([
'name' => 'required|string|max:255',
'email' => 'required|email',
'phone_number' => 'nullable|string|max:20',
'employee_id' => 'nullable|string|max:255',
'department_name' => 'nullable|string|max:255',
'programme_name' => 'nullable|string|max:255',
'salutation' => 'nullable|string|max:50',
'designation' => 'nullable|string|max:255',
'date_of_joining' => 'nullable|date',
'qualification' => 'nullable|string|max:500',
'address' => 'nullable|string|max:500',
'google_scholar_id' => 'nullable|string|max:255',
'vidhvan_id' => 'nullable|string|max:255',
'linkedin_id' => 'nullable|string|max:255',
'profile_photo' => 'nullable|image|max:2048', // 2MB max
]);
// Handle profile photo upload
if ($request->hasFile('profile_photo')) {
if ($profile->profile_photo_path && Storage::exists($profile->profile_photo_path)) {
Storage::delete($profile->profile_photo_path);
}
$validated['profile_photo_path'] = $request->file('profile_photo')
->store('public/profile_photos');
}
// Update profile with validated data
$profile->update([
'name' => $validated['name'] ?? $profile->name,
'email' => $validated['email'] ?? $profile->email,
'phone_number' => $validated['phone_number'] ?? '',
'employee_id' => $validated['employee_id'] ?? '',
'department_name' => $validated['department_name'] ?? '',
'programme_name' => $validated['programme_name'] ?? '',
'salutation' => $validated['salutation'] ?? '',
'designation' => $validated['designation'] ?? '',
'date_of_joining' => $validated['date_of_joining'] ?? $profile->date_of_joining,
'qualification' => $validated['qualification'] ?? '',
'address' => $validated['address'] ?? '',
'google_scholar_id' => $validated['google_scholar_id'] ?? '',
'vidhvan_id' => $validated['vidhvan_id'] ?? '',
'linkedin_id' => $validated['linkedin_id'] ?? '',
'profile_photo_path' => $validated['profile_photo_path'] ?? $profile->profile_photo_path,
]);
// ✅ Update the main user record (used by PublicationsController)
if ($request->filled('google_scholar_id')) {
$user->scholar_url = $request->input('google_scholar_id');
$user->save();
}
// ✅ Refresh session to ensure it reflects the latest Scholar URL immediately
Auth::setUser($user->fresh());
return redirect()
->route('faculty.profile.index')
->with('success', 'Profile updated successfully.');
}
}

View File

@@ -1,60 +0,0 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\ProfileUpdateRequest;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use Illuminate\View\View;
class ProfileController extends Controller
{
/**
* Display the user's profile form.
*/
public function edit(Request $request): View
{
return view('profile.edit', [
'user' => $request->user(),
]);
}
/**
* Update the user's profile information.
*/
public function update(ProfileUpdateRequest $request): RedirectResponse
{
$request->user()->fill($request->validated());
if ($request->user()->isDirty('email')) {
$request->user()->email_verified_at = null;
}
$request->user()->save();
return Redirect::route('profile.edit')->with('status', 'profile-updated');
}
/**
* Delete the user's account.
*/
public function destroy(Request $request): RedirectResponse
{
$request->validateWithBag('userDeletion', [
'password' => ['required', 'current_password'],
]);
$user = $request->user();
Auth::logout();
$user->delete();
$request->session()->invalidate();
$request->session()->regenerateToken();
return Redirect::to('/');
}
}

View File

@@ -6,9 +6,19 @@ use Illuminate\Http\Request;
use Yajra\DataTables\Facades\DataTables;
use App\Models\Publication;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use App\Services\ScholarService;
class PublicationsController extends Controller
{
public function index()
{
$user = auth()->user();
$scholarUrl = $user->scholar_url;
return view('pages.publications.index', compact('scholarUrl'));
}
public function edit($id)
{
$publication = Publication::findOrFail($id);
@@ -23,7 +33,6 @@ class PublicationsController extends Controller
{
$publication = Publication::findOrFail($id);
// Validate the request data
$validated = $request->validate([
'first_author_name' => 'required|string',
'co_authors' => 'nullable|string',
@@ -43,34 +52,27 @@ class PublicationsController extends Controller
'paper_file' => 'nullable|mimes:jpg,jpeg,png,pdf,doc,docx,zip',
]);
// Combine start date and time
$startDateTime = date('Y-m-d H:i:s', strtotime("{$validated['start_date']} {$validated['start_time']}"));
$endDateTime = date('Y-m-d H:i:s', strtotime("{$validated['end_date']} {$validated['end_time']}"));
// Handle the file upload if a new file is provided
if ($request->hasFile('paper_file')) {
// Delete old file if exists
if ($publication->paper_file && Storage::disk('public')->exists($publication->paper_file)) {
Storage::disk('public')->delete($publication->paper_file);
}
// Extract year from start_date
$year = date('Y', strtotime($validated['start_date']));
$username = $publication->user->name;
$originalName = $request->file('paper_file')->getClientOriginalName();
$fileName = $username . '_' . $originalName;
// Create path structure: year/faculty_name/Publications
$folderPath = 'proofs/' . $year . '/' . $username . '/Publications';
// Store file in the specified path
$paperFilePath = $request->file('paper_file')->storeAs($folderPath, $fileName, 'public');
$publication->paper_file = $paperFilePath;
}
// Update other fields
$publication->first_author_name = $validated['first_author_name'];
$publication->co_authors = $validated['co_authors'];
$publication->start_date = $startDateTime;
@@ -96,7 +98,6 @@ class PublicationsController extends Controller
return redirect()->route('coordinator.PublicationsResponses')
->with('status', 'Publication updated successfully');
} else {
// For regular users
return redirect()->route('faculty.PublicationsResponses')
->with('status', 'Publication updated successfully');
}
@@ -106,7 +107,6 @@ class PublicationsController extends Controller
{
$publication = Publication::findOrFail($id);
// Delete the file if it exists
if ($publication->paper_file && Storage::disk('public')->exists($publication->paper_file)) {
Storage::disk('public')->delete($publication->paper_file);
}
@@ -122,18 +122,14 @@ class PublicationsController extends Controller
$isAdmin = $user->role->name === 'Admin';
$isCoordinator = $user->role->name === 'Coordinator';
// Query based on role
if ($isAdmin) {
// Admin sees all records
$publications = Publication::with('user', 'department');
} elseif ($isCoordinator) {
// Coordinator sees only their department's records
$publications = Publication::with('user', 'department')
->whereHas('user', function ($query) use ($user) {
$query->where('department_id', $user->department_id);
});
} else {
// Regular users see only their own records
$publications = Publication::with('user', 'department')
->where('faculty_id', $user->id);
}
@@ -166,16 +162,13 @@ class PublicationsController extends Controller
->addColumn('action', function ($publication) {
$actions = [];
// View paper_file button for everyone
if ($publication->paper_file) {
$actions[] = '<a href="' . asset('storage/' . $publication->paper_file) . '" target="_blank" class="btn btn-sm btn-primary mr-1">View Paper</a>';
} else {
$actions[] = 'No Paper';
}
// Edit button with role-appropriate route
$userRole = auth()->user()->role->name;
// Determine the appropriate route based on user role
if ($userRole === 'Admin') {
$editRoute = route('admin.Publications.edit', $publication->id);
} elseif ($userRole === 'Coordinator') {
@@ -194,4 +187,135 @@ class PublicationsController extends Controller
->rawColumns(['action'])
->make(true);
}
/**
* Fetch all publications from user's linked Google Scholar profile.
*/
public function fetchScholar(Request $request)
{
try {
$user = auth()->user();
\Log::info('📡 FetchScholar Triggered', ['scholar_url' => $user->scholar_url]);
if (!$user || !$user->scholar_url) {
return response()->json([
'success' => false,
'message' => 'No Google Scholar URL found for the logged-in user.'
], 400);
}
$scholarService = new \App\Services\ScholarService();
$publications = $scholarService->fetchPublications($user->scholar_url);
if (empty($publications)) {
return response()->json([
'success' => false,
'message' => 'No publications found from the provided Scholar profile.'
]);
}
return response()->json([
'success' => true,
'count' => count($publications),
'data' => $publications,
]);
} catch (\Throwable $e) {
return response()->json([
'success' => false,
'message' => 'Error fetching publications: '.$e->getMessage(),
], 500);
}
}
/**
* Import selected publications (skipping duplicates).
*/
public function importScholar(Request $request)
{
try {
$user = auth()->user();
$facultyId = $user->id;
$validated = $request->validate([
'publications' => 'required|array',
'publications.*.title' => 'required|string',
'publications.*.authors' => 'nullable|string',
'publications.*.journal' => 'nullable|string',
'publications.*.year' => 'nullable|string',
'publications.*.link' => 'nullable|url',
]);
$rows = $validated['publications'];
$imported = 0;
$skipped = 0;
foreach ($rows as $pub) {
$exists = \App\Models\Publication::where('faculty_id', $facultyId)
->whereRaw('LOWER(title) = ?', [strtolower($pub['title'])])
->exists();
if ($exists) {
$skipped++;
continue;
}
// 🔹 Derive year safely (default to current year if blank)
$year = (int)($pub['year'] ?? date('Y'));
$year = ($year < 1900 || $year > date('Y') + 1) ? date('Y') : $year;
// 🔹 Set start/end to that year's first/last day
$startDate = "{$year}-01-01";
$endDate = "{$year}-12-31";
// 🔍 Smart Tag Detection
$journalLower = strtolower($pub['journal'] ?? '');
// Detect peer-reviewed journals
$isPeerReviewed = (
str_contains($journalLower, 'ieee') ||
str_contains($journalLower, 'elsevier') ||
str_contains($journalLower, 'springer') ||
str_contains($journalLower, 'scopus') ||
str_contains($journalLower, 'wiley') ||
str_contains($journalLower, 'nature') ||
str_contains($journalLower, 'taylor & francis')
) ? 'yes' : 'no';
// Detect Scopus / SCI tags
$isScopus = str_contains($journalLower, 'scopus') ? 'Yes' : 'No';
$isSci = str_contains($journalLower, 'sci') ? 'Yes' : 'No';
\App\Models\Publication::create([
'faculty_id' => $facultyId,
'department_id' => $user->department_id,
'affiliation' => $pub['journal'] ?? '-',
'organizing_institute' => null,
'venue_address' => null,
'title' => $pub['title'],
'first_author_name' => $user->name,
'co_authors' => $pub['authors'] ?? '-',
'journal_name' => $pub['journal'] ?? '-',
'start_date' => $startDate,
'end_date' => $endDate,
'num_days' => 365,
'activity_type' => 'Google Scholar',
'is_peer_reviewed' => $isPeerReviewed,
'is_scopus_indexed' => $isScopus,
'is_sci_indexed' => $isSci,
'external_link' => $pub['link'] ?? null,
]);
$imported++;
}
return response()->json([
'message' => "Imported $imported publications, skipped $skipped duplicates."
]);
} catch (\Throwable $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class FacultyProfile extends Model
{
use HasFactory;
protected $fillable = [
'user_id',
'name',
'email',
'phone_number',
'vidhvan_id',
'google_scholar_id',
'linkedin_id',
'designation',
'salutation',
'qualification',
'address',
'employee_id',
'department_name',
'programme_name',
'date_of_joining',
'profile_photo_path',
];
protected $casts = [
'qualification' => 'array',
'date_of_joining' => 'date',
];
// Each profile belongs to one user
public function user()
{
return $this->belongsTo(User::class);
}
}

View File

@@ -2,21 +2,14 @@
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'name',
'email',
@@ -27,24 +20,14 @@ class User extends Authenticatable
'scopus_id',
'mobile_no',
'extension',
'scholar_url', // ✅ added this line
];
/**
* The attributes that should be hidden for serialization.
*
* @var list<string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
@@ -53,7 +36,6 @@ class User extends Authenticatable
];
}
public function role()
{
return $this->belongsTo(Role::class);

View File

@@ -0,0 +1,67 @@
<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
class ScholarService
{
public function fetchPublications(string $url): array
{
try {
// Extract Google Scholar profile ID (e.g., ssU-uBEAAAAJ)
preg_match('/user=([^&]+)/', $url, $match);
$profileId = $match[1] ?? null;
if (!$profileId) {
\Log::warning('No Google Scholar ID found in URL: ' . $url);
return [];
}
// Load API key from .env
$apiKey = env('SERPAPI_KEY');
if (!$apiKey) {
\Log::error('SERPAPI_KEY not found in environment variables');
return [];
}
$endpoint = 'https://serpapi.com/search.json';
$response = Http::get($endpoint, [
'engine' => 'google_scholar_author',
'author_id' => $profileId,
'api_key' => $apiKey,
]);
if (!$response->successful()) {
\Log::error('Scholar API request failed: ' . $response->status());
return [];
}
$json = $response->json();
// Support multiple possible structures
$articles = $json['articles']
?? $json['publications']
?? $json['results']
?? [];
// ✅ Format and return
return collect($articles)
->map(function ($a) {
return [
'title' => $a['title'] ?? $a['name'] ?? null,
'authors' => $a['authors'] ?? ($a['author'] ?? null),
'journal' => $a['publication'] ?? $a['journal'] ?? null,
'year' => $a['year'] ?? ($a['publication_year'] ?? null),
'link' => $a['link'] ?? $a['citation_link'] ?? null,
];
})
->toArray();
} catch (\Throwable $e) {
\Log::error('ScholarService API error: ' . $e->getMessage());
return [];
}
}
}

View File

@@ -34,7 +34,7 @@ return new class extends Migration
$table->timestamps();
});
// Add ISSN format check constraint manually
DB::statement("ALTER TABLE books_published ADD CONSTRAINT chk_issn_format CHECK (issn REGEXP '^[0-9]{4}-[0-9]{3}[0-9X]$')");
}

View File

@@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->string('scholar_url')->nullable()->after('scopus_id');
});
}
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('scholar_url');
});
}
};

View File

@@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('publications', function (Blueprint $table) {
$table->string('organizing_institute')->nullable()->change();
$table->string('venue_address')->nullable()->change();
$table->string('affiliation')->nullable()->change();
});
}
public function down(): void
{
Schema::table('publications', function (Blueprint $table) {
$table->string('organizing_institute')->nullable(false)->change();
$table->string('venue_address')->nullable(false)->change();
$table->string('affiliation')->nullable(false)->change();
});
}
};

View File

@@ -0,0 +1,45 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('faculty_profiles', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->string('name');
$table->string('email')->unique();
$table->string('phone_number')->nullable();
$table->string('vidhvan_id');
$table->string('google_scholar_id');
$table->string('linkedin_id')->nullable();
$table->string('designation')->nullable();
$table->string('salutation');
$table->json('qualification')->nullable(); // multiple quals
$table->text('address')->nullable();
$table->string('employee_id');
$table->string('department_name');
$table->string('programme_name');
$table->date('date_of_joining');
$table->string('profile_photo_path')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('faculty_profiles');
}
};

View File

@@ -0,0 +1,14 @@
@extends('layouts.app')
@section('content')
<div class="container py-5">
<h1 class="mb-4">Faculty Profile</h1>
<div class="card p-4 shadow-sm">
<p><strong>Name:</strong> {{ $profile->name }}</p>
<p><strong>Email:</strong> {{ $profile->email }}</p>
<p><strong>Phone Number:</strong> {{ $profile->phone_number ?: 'N/A' }}</p>
<p><strong>Department:</strong> {{ $profile->department_name ?: 'N/A' }}</p>
</div>
</div>
@endsection

View File

@@ -1,4 +1,6 @@
<link rel="stylesheet" href="{{ asset('assets/frontend/css/app.css') }}">
<!-- Add Font Awesome for icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.navbar-profile-picture {
width: 40px;
@@ -12,6 +14,16 @@
body {
padding-top: 70px;
}
/* Style for dropdown toggle without underline */
.dropdown-toggle:hover {
text-decoration: none;
}
/* Ensure dropdown menu appears above other content */
.dropdown-menu {
z-index: 1030;
}
</style>
<nav class="navbar navbar-expand-lg navbar-dark bgGrad text-white fixed-top">
<div class="container-fluid">
@@ -29,9 +41,31 @@
@if (!Auth::guest())
<ul class="navbar-nav me-md-5">
<div class="d-flex align-items-center bgRightShade">
<div class="dropdown ms-2">
<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">
<img src="{{ asset('assets/frontend/images/user.png') }}"
alt="profile"
class="navbar-profile-picture me-2">
<span>{{ Auth::user()->name }}</span>
</a>
<div class="d-none d-md-inline ms-2">
{{ auth()->user()->name }}
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
<li>
<a class="dropdown-item" href="{{ route('faculty.profile.index') }}">
<i class="fa-solid fa-id-card me-2 text-primary"></i> Profile
</a>
</li>
<li><hr class="dropdown-divider"></li>
<li>
<form method="POST" action="{{ route('logout') }}">
@csrf
<button type="submit" class="dropdown-item text-danger">
<i class="fa-solid fa-right-from-bracket me-2"></i> Logout
</button>
</form>
</li>
</ul>
</div>
</div>
</ul>

View File

@@ -1,6 +1,7 @@
@extends('layouts.app')
@section('content')
<meta name="csrf-token" content="{{ csrf_token() }}">
<div class="container py-4">
<div class="row">
<div class="col-12">
@@ -9,8 +10,54 @@
<h3 class="page-title m-0">
<i class="fas fa-book-open me-2 text-primary"></i>All Publications
</h3>
@if(auth()->user()->role->name === 'Faculty')
<input type="hidden" id="scholar-url" value="{{ $scholarUrl ?? '' }}">
<button id="btn-fetch-scholar" class="btn btn-outline-primary">
<i class="fab fa-google me-1"></i> Import from Google Scholar
</button>
@endif
</div>
<div class="card-body">
<!-- 🔹 Google Scholar Modal -->
@if(auth()->user()->role->name === 'Faculty')
<div class="modal fade" id="scholarModal" tabindex="-1" aria-labelledby="scholarModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="scholarModalLabel">Select Publications to Import</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div id="scholar-loading" class="text-center my-4 d-none">
<div class="spinner-border text-primary"></div>
<p class="mt-2">Fetching from Google Scholar...</p>
</div>
<div id="scholar-table-wrapper" class="table-responsive d-none">
<table class="table table-bordered align-middle">
<thead>
<tr>
<th><input type="checkbox" id="select-all"></th>
<th>Title</th>
<th>Authors</th>
<th>Journal</th>
<th>Year</th>
<th>Link</th>
</tr>
</thead>
<tbody id="scholar-table-body"></tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button id="btn-import-selected" class="btn btn-success" disabled>Import Selected</button>
</div>
</div>
</div>
</div>
@endif
<!-- Table -->
<div class="table-responsive">
<table id="publications-table" class="table table-striped table-hover">
@@ -45,6 +92,9 @@
@section('scripts')
<script>
// 🔹 Global CSRF setup for all fetch() calls
window.csrfToken = document.querySelector('meta[name="csrf-token"]').content;
$(document).ready(function() {
const sheetName = "Publications";
@@ -111,5 +161,129 @@
initAjaxRoute(dataRoute);
});
// 🔹 Handle delete button click (for AJAX DataTable)
$(document).on('click', '.delete-btn', function () {
const button = $(this);
const id = button.data('id');
const url = button.data('url');
if (!confirm('Are you sure you want to delete this publication?')) return;
fetch(url, {
method: 'DELETE',
headers: {
'X-CSRF-TOKEN': window.csrfToken,
'Accept': 'application/json',
},
})
.then(res => res.json())
.then(data => {
alert(data.success || 'Deleted successfully');
$('#publications-table').DataTable().ajax.reload(null, false);
})
.catch(err => {
console.error(err);
alert('Failed to delete publication.');
});
});
// 🔹 Google Scholar Integration Script (Faculty Only)
@if(auth()->user()->role->name === 'Faculty')
const fetchBtn = document.getElementById('btn-fetch-scholar');
if (fetchBtn) {
const modal = new bootstrap.Modal(document.getElementById('scholarModal'));
const body = document.getElementById('scholar-table-body');
const loading = document.getElementById('scholar-loading');
const tableWrap = document.getElementById('scholar-table-wrapper');
const importBtn = document.getElementById('btn-import-selected');
const scholarUrlInput = document.getElementById('scholar-url');
fetchBtn.addEventListener('click', () => {
const scholarUrl = scholarUrlInput.value.trim();
if (!scholarUrl) {
alert('Please set your Google Scholar profile URL in your profile settings first.');
return;
}
modal.show();
loading.classList.remove('d-none');
tableWrap.classList.add('d-none');
body.innerHTML = '';
// ✅ No need to redeclare scholarUrl here again
fetch("{{ route('faculty.publications.fetchScholar') }}", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-CSRF-TOKEN": window.csrfToken
},
body: JSON.stringify({ url: scholarUrl })
})
.then(res => res.json())
.then(data => {
loading.classList.add('d-none');
if (data.error) {
body.innerHTML = `<tr><td colspan='6' class='text-danger text-center'>${data.error}</td></tr>`;
} else {
const pubs = data.data;
pubs.forEach((p, i) => {
body.innerHTML += `
<tr>
<td><input type="checkbox" class="pub-check" data-index="${i}"></td>
<td>${p.title}</td>
<td>${p.authors || '-'}</td>
<td>${p.journal || '-'}</td>
<td>${p.year || '-'}</td>
<td><a href="${p.link}" target="_blank">View</a></td>
</tr>`;
});
tableWrap.classList.remove('d-none');
importBtn.disabled = false;
}
})
.catch(() => {
loading.classList.add('d-none');
body.innerHTML = `<tr><td colspan='6' class='text-danger text-center'>Failed to fetch data.</td></tr>`;
});
});
document.getElementById('select-all').addEventListener('change', function() {
document.querySelectorAll('.pub-check').forEach(cb => cb.checked = this.checked);
});
importBtn.addEventListener('click', () => {
const selected = Array.from(document.querySelectorAll('.pub-check:checked')).map(cb => {
const row = cb.closest('tr').children;
return {
title: row[1].innerText.trim(),
authors: row[2].innerText.trim(),
journal: row[3].innerText.trim(),
year: row[4].innerText.trim(),
link: row[5].querySelector('a')?.href || null
};
});
if (selected.length === 0) return alert("Please select at least one publication.");
fetch("{{ route('faculty.publications.importScholar') }}", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-CSRF-TOKEN": window.csrfToken
},
body: JSON.stringify({ publications: selected })
})
.then(res => res.json())
.then(data => {
alert(data.message);
modal.hide();
location.reload();
})
.catch(() => alert("Import failed!"));
});
}
@endif
</script>
@endsection

View File

@@ -1,29 +1,105 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Profile') }}
</h2>
</x-slot>
@extends('layouts.app')
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-6">
<div class="p-4 sm:p-8 bg-white shadow sm:rounded-lg">
<div class="max-w-xl">
@include('profile.partials.update-profile-information-form')
@section('content')
<div class="container mt-4">
<h4 class="mb-4">Edit Faculty Profile</h4>
<form action="{{ route('faculty.profile.update') }}" method="POST" enctype="multipart/form-data" class="card shadow-sm p-4">
@csrf
@method('PUT')
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label fw-semibold">Full Name</label>
<input type="text" name="name" class="form-control" value="{{ old('name', $profile->name) }}" required>
</div>
<div class="col-md-6 mb-3">
<label class="form-label fw-semibold">Email</label>
<input type="email" name="email" class="form-control" value="{{ old('email', $profile->email) }}" required>
</div>
<div class="col-md-6 mb-3">
<label class="form-label fw-semibold">Phone Number</label>
<input type="text" name="phone_number" class="form-control" value="{{ old('phone_number', $profile->phone_number) }}">
</div>
<div class="col-md-6 mb-3">
<label class="form-label fw-semibold">Employee ID</label>
<input type="text" name="employee_id" class="form-control" value="{{ old('employee_id', $profile->employee_id) }}">
</div>
<div class="col-md-6 mb-3">
<label class="form-label fw-semibold">Department</label>
<input type="text" name="department_name" class="form-control" value="{{ old('department_name', $profile->department_name) }}">
</div>
<div class="col-md-6 mb-3">
<label class="form-label fw-semibold">Programme</label>
<input type="text" name="programme_name" class="form-control" value="{{ old('programme_name', $profile->programme_name) }}">
</div>
<div class="col-md-4 mb-3">
<label class="form-label fw-semibold">Salutation</label>
<input type="text" name="salutation" class="form-control" value="{{ old('salutation', $profile->salutation) }}">
</div>
<div class="col-md-4 mb-3">
<label class="form-label fw-semibold">Designation</label>
<input type="text" name="designation" class="form-control" value="{{ old('designation', $profile->designation) }}">
</div>
<div class="col-md-4 mb-3">
<label class="form-label fw-semibold">Date of Joining</label>
<input type="date" name="date_of_joining" class="form-control" value="{{ old('date_of_joining', $profile->date_of_joining?->format('Y-m-d')) }}">
</div>
<div class="col-md-6 mb-3">
<label class="form-label fw-semibold">Google Scholar ID</label>
<input type="text" class="form-control" id="google_scholar_id" name="google_scholar_id"
value="{{ old('google_scholar_id', $profile->google_scholar_id) }}">
</div>
<div class="col-md-6 mb-3">
<label class="form-label fw-semibold">Vidhwan ID</label>
<input type="text" class="form-control" id="vidhwan_id" name="vidhwan_id"
value="{{ old('vidhwan_id', $profile->vidhwan_id) }}">
</div>
<div class="col-md-6 mb-3">
<label class="form-label fw-semibold">LinkedIn Profile</label>
<input type="text" class="form-control" id="linkedin_id" name="linkedin_id"
value="{{ old('linkedin_id', $profile->linkedin_id) }}">
</div>
<div class="col-md-12 mb-3">
<label class="form-label fw-semibold">Qualification</label>
<textarea name="qualification" class="form-control" rows="2">{{ is_array($profile->qualification) ? implode(', ', $profile->qualification) : $profile->qualification }}</textarea>
<small class="text-muted">Separate multiple qualifications with commas (e.g., B.Tech, M.Tech, Ph.D)</small>
</div>
<div class="col-md-12 mb-3">
<label class="form-label fw-semibold">Address</label>
<textarea name="address" class="form-control" rows="2">{{ old('address', $profile->address) }}</textarea>
</div>
<div class="col-md-6 mb-3">
<label class="form-label fw-semibold">Profile Photo</label>
<input type="file" name="profile_photo" class="form-control">
@if ($profile->profile_photo_path)
<div class="mt-2">
<img src="{{ Storage::url($profile->profile_photo_path) }}" alt="Profile Photo" width="100" class="rounded shadow-sm">
</div>
@endif
</div>
</div>
<div class="p-4 sm:p-8 bg-white shadow sm:rounded-lg">
<div class="max-w-xl">
@include('profile.partials.update-password-form')
<div class="text-end mt-3">
<button type="submit" class="btn btn-primary">
<i class="fa fa-save me-1"></i> Save Changes
</button>
</div>
</form>
</div>
<div class="p-4 sm:p-8 bg-white shadow sm:rounded-lg">
<div class="max-w-xl">
@include('profile.partials.delete-user-form')
</div>
</div>
</div>
</div>
</x-app-layout>
@endsection

View File

@@ -0,0 +1,89 @@
@extends('layouts.app')
@section('content')
<div class="container mt-4">
@if(session('success'))
<div class="alert alert-success alert-dismissible fade show" role="alert">
{{ session('success') }}
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
@endif
<h4 class="mb-4">Faculty Profile</h4>
<div class="card shadow-sm p-4">
<div class="row align-items-center mb-3">
<div class="col-md-2 text-center">
@if($profile->profile_photo_path)
<img src="{{ Storage::url($profile->profile_photo_path) }}"
alt="Profile Photo"
class="rounded-circle shadow-sm"
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 class="col-md-10">
<h5 class="fw-bold mb-1">{{ $profile->salutation }} {{ $profile->name }}</h5>
<p class="mb-0"><strong>{{ $profile->designation }}</strong></p>
<p class="text-muted mb-0">{{ $profile->department_name }} {{ $profile->programme_name }}</p>
{{-- Compact links row --}}
<div class="mt-2 text-md-start text-center">
@if($profile->google_scholar_id)
<a href="{{ $profile->google_scholar_id }}" target="_blank" rel="noopener noreferrer"
class="btn btn-outline-primary btn-sm me-2">
<i class="fa fa-graduation-cap me-1"></i> Scholar
</a>
@endif
@if($profile->vidhwan_id)
<a href="https://vidwan.inflibnet.ac.in/profile/{{ $profile->vidhwan_id }}"
target="_blank" rel="noopener noreferrer"
class="btn btn-outline-secondary btn-sm me-2">
<i class="fa fa-id-card me-1"></i> Vidhwan
</a>
@endif
@if($profile->linkedin_id)
<a href="{{ $profile->linkedin_id }}" target="_blank" rel="noopener noreferrer"
class="btn btn-outline-info btn-sm">
<i class="fa fa-linkedin"></i> LinkedIn
</a>
@endif
</div>
</div>
</div>
<hr>
<div class="row">
<div class="col-md-6">
<p><strong>Email:</strong> {{ $profile->email }}</p>
<p><strong>Phone:</strong> {{ $profile->phone_number ?: 'N/A' }}</p>
<p><strong>Employee ID:</strong> {{ $profile->employee_id ?: 'N/A' }}</p>
<p><strong>Date of Joining:</strong>
{{ $profile->date_of_joining ? $profile->date_of_joining->format('d M Y') : 'N/A' }}
</p>
</div>
<div class="col-md-6">
<p><strong>Qualification:</strong>
{{ is_array($profile->qualification) ? implode(', ', $profile->qualification) : ($profile->qualification ?: 'N/A') }}
</p>
<p><strong>Address:</strong> {{ $profile->address ?: 'N/A' }}</p>
<p><strong>Vidhwan ID:</strong> {{ $profile->vidhwan_id ?: 'N/A' }}</p>
</div>
</div>
<div class="text-end mt-3">
<a href="{{ route('faculty.profile.edit') }}" class="btn btn-primary">
<i class="fa fa-pen me-1"></i> Edit Profile
</a>
</div>
</div>
</div>
@endsection

View File

@@ -2,8 +2,6 @@
use App\Http\Controllers\ActivitiesAttendedController;
use App\Http\Controllers\ActivitiesOrganisedController;
use App\Http\Controllers\ProfileController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\DepartmentController;
use App\Http\Controllers\UserController;
@@ -18,6 +16,7 @@ use App\Http\Controllers\OnlineCoursesController;
use App\Http\Controllers\PatentsController;
use App\Http\Controllers\PublicationsController;
use App\Http\Middleware\CheckRole;
use App\Http\Controllers\FacultyProfileController;
Route::get('/', function () {
return redirect('/login');
@@ -39,12 +38,6 @@ Route::get('/dashboard', function () {
})->middleware(['auth', 'verified'])->name('dashboard');
Route::middleware('auth')->group(function () {
Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});
// Activities Attended common routes
Route::delete('/activities-attended/{id}', [ActivitiesAttendedController::class, 'destroy'])->name('activitiesAttended.destroy');
@@ -199,6 +192,11 @@ Route::middleware(['auth', CheckRole::class . ':Coordinator'])->group(function (
Route::middleware(['auth', CheckRole::class . ':Faculty'])->group(function () {
Route::get('/faculty', [FacultyController::class, 'index'])->name('faculty.dashboard');
// Faculty Profile Routes - KEPT AS REQUESTED
Route::get('/faculty/profile', [FacultyProfileController::class, 'index'])->name('faculty.profile.index');
Route::get('/faculty/profile/edit', [FacultyProfileController::class, 'edit'])->name('faculty.profile.edit');
Route::put('/faculty/profile', [FacultyProfileController::class, 'update'])->name('faculty.profile.update');
// Activities Attended Routes
Route::get('/faculty/ActivitiesAttendedForm', [FacultyController::class, 'ActivitiesAttendedForm'])->name('faculty.ActivitiesAttendedForm');
Route::post('/faculty/ActivitiesAttendedFormResponse', [FacultyController::class, 'ActivitiesAttendedFormResponse'])->name('faculty.ActivitiesAttendedFormResponse');
@@ -262,6 +260,16 @@ Route::middleware(['auth', CheckRole::class . ':Faculty'])->group(function () {
Route::get('/faculty/PatentsResponses/data', [PatentsController::class, 'getPatentsResponses'])->name('faculty.PatentsResponses.data');
Route::get('/faculty/Patents/{id}/edit', [PatentsController::class, 'edit'])->name('faculty.Patents.edit');
Route::put('/faculty/Patents/{id}', [PatentsController::class, 'update'])->name('faculty.Patents.update');
// Google Scholar import routes (FIXED: changed fetchFromScholar to fetchScholar)
Route::post('/faculty/publications/fetch-scholar', [PublicationsController::class, 'fetchScholar'])
->name('faculty.publications.fetchScholar');
Route::post('/faculty/publications/import-scholar', [PublicationsController::class, 'importScholar'])
->name('faculty.publications.importScholar');
Route::post('/faculty/publications/import-selected', [PublicationsController::class, 'importSelected'])
->name('faculty.publications.importSelected');
});
Route::post('/missing-proofs/check', [MissingProofsController::class, 'checkAndSendEmails'])->name('missing-proofs.check');
@@ -296,3 +304,8 @@ Route::post('/admin/download-proofs', [AdminController::class, 'downloadProofs']
// Google Login Route
Route::get('/auth/google', [App\Http\Controllers\Auth\GoogleController::class, 'redirectToGoogle'])->name('google.login');
Route::get('/auth/google/callback', [App\Http\Controllers\Auth\GoogleController::class, 'handleGoogleCallback'])->name('google.callback');
// ✅ Fallback route alias to avoid 'profile.edit' missing error
Route::get('/profile', function () {
return redirect()->route('faculty.profile.edit');
})->name('profile.edit');