Skip to content

Commit

Permalink
Merge pull request #3 from joshpme/feature/bibtex
Browse files Browse the repository at this point in the history
Fix bibtex formatting
  • Loading branch information
joshpme authored Apr 5, 2022
2 parents 0dc0144 + 84228ff commit c78e95c
Show file tree
Hide file tree
Showing 29 changed files with 512 additions and 121 deletions.
29 changes: 29 additions & 0 deletions migrations/Version20220214105551.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220214105551 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE reference ADD hits INT DEFAULT NULL');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE reference DROP hits');
}
}
31 changes: 31 additions & 0 deletions migrations/Version20220216071047.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220216071047 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE conference ADD conference_start DATE DEFAULT NULL, ADD conference_end DATE DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE conference DROP conference_start, DROP conference_end');
}
}
31 changes: 31 additions & 0 deletions migrations/Version20220216091608.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220216091608 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE reference ADD confirmed_in_proc TINYINT(1) DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE reference DROP confirmed_in_proc');
}
}
41 changes: 41 additions & 0 deletions public/js/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,45 @@ $(document).ready(function(){
$('input[type=file]').on('change',function(e){
var fileName = e.target.files[0].name;
$(this).closest(".custom-file").find('.custom-file-label').html(fileName);
});

$('.js-datepicker').datepicker({
format: 'dd/mm/yyyy'
});

function toDate(dateString) {
var dateParts = dateString.split("/");
return new Date(+dateParts[2], dateParts[1] - 1, +dateParts[0]);
}

function monthYear(date) {
month = date.toLocaleString('default', { month: 'long' });
year = date.getFullYear();

if (month.length > 3) {
month = month.substring(0, 3) + ".";
}
return {
month: month,
year: year
};
}

$(".conference-date").blur(function(){
start = monthYear(toDate($(".conference-date-start").val()));
end = monthYear(toDate($(".conference-date-end").val()));

if (!isNaN(end.year) && !isNaN(start.year)) {
newDate = "";
if (start.month != end.month) {
if (start.year != end.year) {
newDate = start.month + " " + start.year + "-" + end.month + " " + end.year
} else {
newDate = start.month + "-" + end.month + " " + end.year
}
} else {
newDate = end.month + " " + end.year
}
$(".conference-date-formatted").val(newDate);
}
});
23 changes: 22 additions & 1 deletion public/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,38 +102,55 @@ $(".conference-location-typeahead").typeahead({
$("form input").on("keyup", function(){
if ($("form").serialize() !== searchContent) {
adjustedText = true;
currentPage = 0;
}
date = new Date();
lastInput = date.getTime();
}).on("change", function(){
if ($("form").serialize() !== searchContent) {
adjustedText = true;
currentPage = 0;
}
date = new Date();
lastInput = date.getTime();
}).on("blur", function(){
if ($("form").serialize() !== searchContent) {
adjustedText = true;
currentPage = 0;
}
date = new Date();
lastInput = date.getTime();
});

var currentPage = 0;

setInterval(function() {
date = new Date();
if (adjustedText && (date.getTime() - lastInput > 600) && (date.getTime() - lastSearch > 600)) {
triggerSearch();
}
},200);


function prevPage() {
currentPage -= 5;
triggerSearch();
}

function nextPage() {
currentPage += 5;
triggerSearch();
}

function triggerSearch() {

adjustedText = false;
lastSearch = date.getTime();
$("#searching").toggle(true);
$("#no-results").toggle(false);
$("#results").empty();
searchContent = $("form").serialize();
$.post(Routing.generate('search'), searchContent, function(content){
$.post(Routing.generate('search', { page: currentPage }), searchContent, function(content){
$("#searching").toggle(false);
var results = $("#results");
favourites = content.favourites;
Expand All @@ -149,6 +166,10 @@ function triggerSearch() {
$(".show-total #current-total").text(content.results.length);
$(".show-total #overall-total").text(content.total);

let total = parseInt($("#overall-total").text());
$('.prev-page').toggle(currentPage > 0);
$('.next-page').toggle((currentPage + 5) <= total);
$('.page-number').text((currentPage / 5) + 1);

},"json");

Expand Down
7 changes: 4 additions & 3 deletions src/Controller/AuthorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ public function indexAction(Request $request, PaginatorInterface $paginator)
$manager = $this->getDoctrine()->getManager();
$search = $manager->getRepository(Author::class)
->createQueryBuilder("a");

$search->addSelect('SIZE(a.references) as HIDDEN total');
if ($form->isSubmitted() && $form->isValid()) {

$terms = $form->get('terms')->getData();

$parts = explode(".", $terms);

// get initials
Expand Down Expand Up @@ -68,10 +69,10 @@ public function indexAction(Request $request, PaginatorInterface $paginator)
$search->orWhere("LOWER(a.name) LIKE :terms")
->setParameter("terms", '%' . mb_strtolower($lastName) . '%');
}


}


$pagination = $paginator->paginate(
$search->getQuery(),
$request->query->getInt('page', 1),
Expand Down
45 changes: 45 additions & 0 deletions src/Controller/CleanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
use App\Entity\Author;
use App\Entity\Favourite;
use App\Entity\Reference;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use App\Service\AuthorService;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Knp\Component\Pager\PaginatorInterface;

/**
* Clean controller, for basic data cleansing purposes
Expand All @@ -17,6 +21,47 @@
*/
class CleanController extends AbstractController
{
/**
* @IsGranted("ROLE_ADMIN")
* @Route("/talks/{id}/{talk}", name="talk_update", options={"expose"=true})
*/
public function updatePossibleTalkAction(Reference $reference, bool $talk) {
$manager = $this->getDoctrine()->getManager();
$reference->setInProc($talk);
$reference->setConfirmedInProc(1);
$manager->flush();
return new JsonResponse();
}

/**
* @IsGranted("ROLE_ADMIN")
* @Route("/talks", name="talk_clean")
*/
public function talkAction(Request $request, PaginatorInterface $paginator)
{
$allPossibleTalks = $this->getDoctrine()->getManager()
->getRepository(Reference::class)
->createQueryBuilder("r")
->select("r.id")
->addSelect('SIZE(r.authors) as HIDDEN authorsCount')
->where('r.position is null or r.position = :empty')
->andWhere('r.inProc = 1')
->andWhere('r.confirmedInProc is null')
->setParameter("empty", "")
->having('authorsCount = 1')
->getQuery()
->getArrayResult();

$count = count($allPossibleTalks);
$referenceId = array_rand($allPossibleTalks);

$reference = $this->getDoctrine()->getManager()
->getRepository(Reference::class)
->find($allPossibleTalks[$referenceId]['id']);

// parameters to template
return $this->render('clean/talk.html.twig', array('reference' => $reference, 'count'=>$count));
}
/**
* Regenerate cache for all references.
* @Route("/duplicate", name="duplicate_clean")
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/ConferenceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function indexAction(Request $request, PaginatorInterface $paginator)

$manager = $this->getDoctrine()->getManager();
$search = $manager->getRepository(Conference::class)
->createQueryBuilder("c");
->createQueryBuilder("c")->orderBy("c.id", "DESC");

if ($form->isSubmitted() && $form->isValid()) {
$terms = mb_strtolower($form->get('terms')->getData());
Expand Down
3 changes: 1 addition & 2 deletions src/Controller/ReferenceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function indexAction(Request $request, PaginatorInterface $paginator)

$manager = $this->getDoctrine()->getManager();
$search = $manager->getRepository(Reference::class)
->createQueryBuilder("r");
->createQueryBuilder("r")->orderBy("r.hits", "DESC");

if ($form->isSubmitted() && $form->isValid()) {
$terms = mb_strtolower($form->get('terms')->getData());
Expand Down Expand Up @@ -127,7 +127,6 @@ public function showAction(Reference $reference)
$paperService = new PaperService();
$update = $paperService->check($reference);


if ($update || $reference->__toString() !== $reference->getCache()) {
$reference->setCache($reference->__toString());
$this->getDoctrine()->getManager()->flush();
Expand Down
12 changes: 7 additions & 5 deletions src/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function indexAction(Request $request, FavouriteService $favouriteService
$references = [];
if ($form->isSubmitted() && $form->isValid()) {
$query = $this->getDoctrine()->getManager()
->getRepository(Reference::class)->search($search);
->getRepository(Reference::class)->search($search)->orderBy('r.hits', 'DESC');

if ($query !== false) {
$references = $query->setMaxResults(5)
Expand Down Expand Up @@ -69,12 +69,12 @@ private function endsWith($string, $endString)
/**
* Search page
* JSON results only of page
* @Route("/search", name="search", options={"expose"=true})
* @Route("/search/{page}", name="search", options={"expose"=true}, requirements={"page"="\d+"})
* @param Request $request
* @return JsonResponse
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function searchAction(Request $request, FavouriteService $favouriteService, CurrentConferenceService $currentConferenceService) {
public function searchAction(int $page = 0, Request $request, FavouriteService $favouriteService, CurrentConferenceService $currentConferenceService) {

$response = ["favourites" => $favouriteService->getFavourites()];
$search = new Search();
Expand All @@ -90,8 +90,10 @@ public function searchAction(Request $request, FavouriteService $favouriteServic
if ($query !== false) {
$response["total"] = $query->select("COUNT(r)")->getQuery()->getSingleScalarResult();
$query = $this->getDoctrine()->getManager()
->getRepository(Reference::class)->search($search);
$results = $query->setMaxResults(5)
->getRepository(Reference::class)->search($search)->orderBy('r.hits', 'DESC');
$results = $query
->setFirstResult($page)
->setMaxResults(5)
->getQuery()
->getResult();

Expand Down
Loading

0 comments on commit c78e95c

Please sign in to comment.