Skip to content

Commit

Permalink
Added bookmarks for problems and table styling
Browse files Browse the repository at this point in the history
  • Loading branch information
PavlosIsaris committed Nov 14, 2024
1 parent 7160029 commit 880da04
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,4 @@ public function getCrowdSourcingProjectsForProblems(): Collection {
// get all projects that have at least one problem
return $this->crowdSourcingProjectRepository->getProjectsForProblems();
}

public function getProblemsForCrowdSourcingProjectForManagement(int $projectId): Collection {
return $this->crowdSourcingProjectProblemRepository->getProblemsForCrowdSourcingProjectForManagement($projectId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,8 @@ public function getProblemStatusesForManagementPage(): Collection {
public function updateProblemStatus(int $id, int $status_id) {
return $this->crowdSourcingProjectProblemRepository->update(['status_id' => $status_id], $id);
}

public function getProblemsForCrowdSourcingProjectForManagement(int $projectId): Collection {
return $this->crowdSourcingProjectProblemRepository->getProblemsForCrowdSourcingProjectForManagement($projectId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,4 @@ public function clone(int $id): RedirectResponse {
public function getCrowdSourcingProjectsForProblems(): JsonResponse {
return response()->json($this->crowdSourcingProjectManager->getCrowdSourcingProjectsForProblems());
}

public function getProblemsForCrowdSourcingProjectForManagement(): JsonResponse {
$this->validate(request(), [
'projectId' => 'required|numeric|exists:crowd_sourcing_projects,id',
]);

return response()->json($this->crowdSourcingProjectManager->getProblemsForCrowdSourcingProjectForManagement(request('projectId')));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,12 @@ public function updateStatus(Request $request, int $id): JsonResponse {

return response()->json($this->crowdSourcingProjectProblemManager->updateProblemStatus($id, $request->status_id));
}

public function getProblemsForCrowdSourcingProjectForManagement(): JsonResponse {
$this->validate(request(), [
'projectId' => 'required|numeric|exists:crowd_sourcing_projects,id',
]);

return response()->json($this->crowdSourcingProjectProblemManager->getProblemsForCrowdSourcingProjectForManagement(request('projectId')));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Http\Controllers\CrowdSourcingProject\Problem;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class CrowdSourcingProjectProblemUserBookmarkController extends Controller {
/**
* Create or delete a bookmark for a problem for a user.
*/
public function createOrDeleteProblemBookmarkForUser(Request $request) {
throw new \Exception('Not implemented');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ public function translations(): HasMany {
public function status(): HasOne {
return $this->hasOne(CrowdSourcingProjectProblemStatusLkp::class, 'id', 'status_id');
}

public function bookmarks(): HasMany {
return $this->hasMany(CrowdSourcingProjectProblemUserBookmark::class, 'problem_id', 'id');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Models\CrowdSourcingProject\Problem;

use App\Models\Language;
use App\Models\User;
use Awobaz\Compoships\Compoships;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class CrowdSourcingProjectProblemUserBookmark extends Model {
use Compoships;

protected $table = 'csp_problem_user_bookmarks';
protected $fillable = ['problem_id', 'user_id', 'problem_bookmark_language_id'];
protected $primaryKey = ['problem_id', 'user_id'];
public $incrementing = false;

public function problem(): BelongsTo {
return $this->belongsTo(CrowdSourcingProjectProblem::class, 'problem_id', 'id');
}

public function user(): BelongsTo {
return $this->belongsTo(User::class, 'user_id', 'id');
}

public function language(): BelongsTo {
return $this->belongsTo(Language::class, 'problem_bookmark_language_id', 'id');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function projectHasPublishedProblems(int $project_id): bool {
}

public function getProblemsForCrowdSourcingProjectForManagement(int $projectId): Collection {
return CrowdSourcingProjectProblem::where('project_id', $projectId)->with(['defaultTranslation', 'translations', 'translations.language', 'status'])->get();
return CrowdSourcingProjectProblem::where('project_id', $projectId)
->with(['defaultTranslation', 'translations', 'translations.language', 'status', 'bookmarks'])->get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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('csp_problem_user_bookmarks', function (Blueprint $table) {
$table->unsignedBigInteger('problem_id');
$table->foreign('problem_id')->references('id')->on('crowd_sourcing_project_problems');

$table->unsignedInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');

$table->primary(['problem_id', 'user_id'], 'csp_problem_user_bookmarks_primary');

// the language in which the user bookmarked the problem
$table->unsignedInteger('problem_bookmark_language_id');
$table->foreign('problem_bookmark_language_id')->references('id')->on('languages_lkp');

$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void {
Schema::dropIfExists('csp_problem_user_bookmarks');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,25 @@ export default {
await this.$nextTick(() => {
this.dataTableInstance = $("#problemsTable").DataTable({
pageLength: 5,
autoWidth: false,
data: [],
columns: [
{ title: "#", data: null },
{ title: "Title", data: "title" },
{ title: "Bookmarks", data: "bookmarks" },
{ title: "Languages", data: "languages" },
{ title: "Status", data: "status" },
{ title: "Actions", data: "actions" },
{ title: "#", data: null, width: "5%" },
{ title: "Title", data: "title", width: "30%" },
{ title: "Bookmarks", data: "bookmarks", width: "5%" },
{ title: "Languages", data: "languages", width: "20%" },
{ title: "Status", data: "status", width: "20%" },
{ title: "Actions", data: "actions", width: "20%" },
],
columnDefs: [
{
targets: 0,
render: (data, type, row, meta) => meta.row + 1,
},
{
targets: [0, 2, 4, 5], // Indices of columns to center
className: "text-center",
},
],
});
Expand Down Expand Up @@ -293,12 +298,12 @@ export default {
this.dataTableInstance.clear();
const tableData = this.filteredProblems.map((problem, index) => ({
title: problem.default_translation.title,
bookmarks: "TODO",
bookmarks: problem.bookmarks.length,
languages: problem.translations
? problem.translations.map((t) => t.language.language_name).join(", ")
: "",
status: `<span title="${this.getBadgeTitleForProblemStatus(problem.status)}"
class="p-2 badge ${this.getBadgeClassForProblemStatus(problem.status)}">
class="p-2 w-75 badge ${this.getBadgeClassForProblemStatus(problem.status)}">
${problem.status.title}</span>`,
actions: `<div class="dropdown">
<button class="btn btn-primary btn-slimmer dropdown-toggle" type="button"
Expand Down
2 changes: 1 addition & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
Route::post('/questionnaire/translate', [QuestionnaireController::class, 'translateQuestionnaire'])->name('api.questionnaire.translation.store');
Route::post('/questionnaire/mark-translations', [QuestionnaireController::class, 'markQuestionnaireTranslations'])->name('api.questionnaire.translations.mark');
Route::get('/crowd-sourcing-projects/for-problems', [CrowdSourcingProjectController::class, 'getCrowdSourcingProjectsForProblems'])->name('api.crowd-sourcing-projects.for-problems.get');
Route::post('/crowd-sourcing-projects/get-problems-for-management', [CrowdSourcingProjectController::class, 'getProblemsForCrowdSourcingProjectForManagement'])->name('api.crowd-sourcing-projects.problems.get-management');
Route::post('/crowd-sourcing-projects/get-problems-for-management', [CrowdSourcingProjectProblemController::class, 'getProblemsForCrowdSourcingProjectForManagement'])->name('api.crowd-sourcing-projects.problems.get-management');
Route::get('/problems/statuses/management', [CrowdSourcingProjectProblemController::class, 'getProblemStatusesForManagementPage'])->name('api.problems.statuses.management.get');
});

Expand Down

0 comments on commit 880da04

Please sign in to comment.