From 821377a72f4b6c961e4e90f7d22bcbc5a4b71899 Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Wed, 17 Apr 2024 00:09:30 +0200 Subject: [PATCH] added addview and download PDF --- .../ResearchController.java | 12 +++++ .../ResearchRepository.java | 2 + .../StatsRepository.java | 10 ++-- .../ResearchesService.java | 10 ++++ .../StatisticsService.java | 1 - .../ResearchComponent.vue | 9 ++-- .../ResearcherProfile.vue | 52 ++++++++----------- .../ResearcherProfile.js | 6 +++ 8 files changed, 63 insertions(+), 39 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScientificPublications/ResearchController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScientificPublications/ResearchController.java index a29917e..8a266a2 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScientificPublications/ResearchController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScientificPublications/ResearchController.java @@ -225,4 +225,16 @@ public class ResearchController { return new ResponseEntity<>(HttpStatus.OK); } + + + /////// + //views part + @PostMapping("/addView{url}") + public ResponseEntity addView(@PathVariable String url){ + Research research = researchesServ.getResearchByUrl(url); + if (research ==null) return new ResponseEntity<>(HttpStatus.NOT_FOUND); + + return new ResponseEntity<>(ResearchDTO.construct(researchesServ.addView(research)), HttpStatus.OK); + } + } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScientificPublications/ResearchRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScientificPublications/ResearchRepository.java index 9952212..ace303d 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScientificPublications/ResearchRepository.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScientificPublications/ResearchRepository.java @@ -12,4 +12,6 @@ public interface ResearchRepository extends CrudRepository { Iterable findByAuthor(Researcher author); + Research findByPdfLocation(String url); + } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScientificPublications/StatsRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScientificPublications/StatsRepository.java index 95f4da6..a228ac9 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScientificPublications/StatsRepository.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/ScientificPublications/StatsRepository.java @@ -11,7 +11,7 @@ public interface StatsRepository extends CrudRepository { @Query("select new map(to_char(r.releaseDate, 'month') as label, sum(r.views) as y) from Research r group by to_char(r.releaseDate, 'month')") Iterable> viewsByMonths(); - @Query("select new map(to_char(r.releaseDate,'year') as label, sum (r.views) as y) from Research r group by to_char(r.releaseDate,'year')") + @Query("select new map(to_char(r.releaseDate,'YYYY') as label, sum (r.views) as y) from Research r group by to_char(r.releaseDate,'YYYY')") Iterable> viewsByYears(); @@ -19,16 +19,16 @@ public interface StatsRepository extends CrudRepository { Iterable> viewsByTopics(); - @Query("select new map(r.domain as label, r.language as y) from Research r group by r.domain") + @Query("select new map(r.domain as label, count(r.language) as y) from Research r group by r.domain") Iterable> languageByTopics(); - @Query("select new map(to_char(r.releaseDate,'year') as label, r.language as y) from Research r group by to_char(r.releaseDate,'year')") + @Query("select new map(to_char(r.releaseDate,'YYYY') as label, count(r.language) as y) from Research r group by to_char(r.releaseDate,'YYYY')") Iterable> languageByYears(); - @Query("select new map(to_char(r.releaseDate, 'month') as label, r.language as y) from Research r group by to_char(r.releaseDate, 'month')") + @Query("select new map(to_char(r.releaseDate, 'month') as label, count(r.language) as y) from Research r group by to_char(r.releaseDate, 'month')") Iterable> languageByMonths(); - @Query("select new map(to_char(r.releaseDate,'year') as label, count(r) as y) from Research r group by to_char(r.releaseDate,'year')") + @Query("select new map(to_char(r.releaseDate,'YYYY') as label, count(r) as y) from Research r group by to_char(r.releaseDate,'YYYY')") Iterable> researchesByYears(); @Query("select new map(r.domain as label, count(r) as y) from Research r group by r.domain") diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/ScientificPublications/ResearchesService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/ScientificPublications/ResearchesService.java index 213c738..0d601c7 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/ScientificPublications/ResearchesService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/ScientificPublications/ResearchesService.java @@ -2,6 +2,7 @@ package ovh.herisson.Clyde.Services.ScientificPublications; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; +import ovh.herisson.Clyde.DTO.ScientificPublications.ResearchDTO; import ovh.herisson.Clyde.Repositories.ScientificPublications.ResearchCoAuthorsRepository; import ovh.herisson.Clyde.Repositories.ScientificPublications.ResearchRepository; import ovh.herisson.Clyde.Repositories.ScientificPublications.ResearcherRepository; @@ -186,4 +187,13 @@ public class ResearchesService { } researcherRepo.save(researcher); } + + public Research getResearchByUrl(String url) { + return articleRepo.findByPdfLocation(url); + } + + public Research addView(Research research) { + research.setViews(research.getViews()+1); + articleRepo.save(research); + } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/ScientificPublications/StatisticsService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/ScientificPublications/StatisticsService.java index 886285b..90a60d2 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/ScientificPublications/StatisticsService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/ScientificPublications/StatisticsService.java @@ -40,7 +40,6 @@ public class StatisticsService { toReturn.add(statsRepo.languageByYears()); toReturn.add(statsRepo.languageByMonths()); toReturn.add(statsRepo.languageByTopics()); - return toReturn; } } \ No newline at end of file diff --git a/frontend/src/Apps/ScientificPublications/ResearchComponent.vue b/frontend/src/Apps/ScientificPublications/ResearchComponent.vue index 4615c90..48c27e8 100644 --- a/frontend/src/Apps/ScientificPublications/ResearchComponent.vue +++ b/frontend/src/Apps/ScientificPublications/ResearchComponent.vue @@ -22,7 +22,7 @@ function format(date){ } -const emit = defineEmits(["modal-close"]); +const emit = defineEmits(["downloadPdf","downloadBibTex"]); const target = ref(null) onClickOutside(target, ()=>emit('modal-close')) @@ -43,11 +43,12 @@ onClickOutside(target, ()=>emit('modal-close'))
  • PaperType : {{article.paperType}}
  • Domain : {{article.domain}}
  • Access : {{article.access}}
  • -
    - - + +
    + +
    diff --git a/frontend/src/Apps/ScientificPublications/ResearcherProfile.vue b/frontend/src/Apps/ScientificPublications/ResearcherProfile.vue index eca4019..39180d3 100644 --- a/frontend/src/Apps/ScientificPublications/ResearcherProfile.vue +++ b/frontend/src/Apps/ScientificPublications/ResearcherProfile.vue @@ -9,7 +9,7 @@ import { ref, reactive } from "vue"; import FilterComponent from "@/Apps/ScientificPublications/FilterComponent.vue"; import ArticleComponent from "@/Apps/ScientificPublications/ResearchComponent.vue"; -import {fetchResearcher, fetchResearches} from "@/rest/ScientificPublications/ResearcherProfile.js"; +import {fetchResearcher, fetchResearches, fetchStats, addView} from "@/rest/ScientificPublications/ResearcherProfile.js"; const input = ref(""); const statsOf = ref(""); const statsBy = ref(""); @@ -17,16 +17,15 @@ const isFilterOpened = ref(false); const isResearchOpened = ref(false); const articleToDisplay = ref(Object) const filters = ref([]); -const researchList = ref(await fetchResearches(1)); let chart; + +const researchList = ref(await fetchResearches(1)); //todo changer dynamiquement le 1 ici en fct de sur quel profil on est -const researcher = ref(await fetchResearcher(1)); - - - +const researcher = ref(await fetchResearcher(1)); +const stats = ref(await fetchStats(1)) const props = defineProps({ - researcher: ref(Object), + researcherId: ref(), //int filters: ref([""]), }); @@ -53,7 +52,8 @@ const downloadBibTex = (research) => { } const downloadArticle = (research) => { - //todo + addView(research.url) + } function downloadCoAuthors(){ @@ -63,14 +63,6 @@ function downloadCoAuthors(){ } -const jsonMockViewsByYears= [ - {label: "2004", y:4}, - {label: "2005", y:99}, - {label: "2007", y:555}, - {label: "2009", y:22}, - {label: "2011", y:1666}, -] - function searchInList(list, searchInput) { let retList = [] for (let i = 0; i < list.length; i++) { @@ -121,23 +113,25 @@ const options = reactive({ }); function update(){ - options.title = { - fontColor: "white", - text: statsOf.value + " By "+ statsBy.value, - } - if (statsOf.value === "views" && statsBy.value === "years") { - options.data[0].dataPoints = jsonMockViewsByYears; - } + options.title = { + fontColor: "white", + text: statsOf.value + " By "+ statsBy.value, + } + const index = (0 ?statsOf.value === "views": 3 ? statsOf.value === "researches":6) + (0?statsBy.value ==="years":1?statsBy.value==="months":2) - options.title.text = statsOf.value + " By "+ statsBy.value; - chart.render() - } + + options.data[0].dataPoints = stats.value[index] + + + options.title.text = statsOf.value + " By "+ statsBy.value; + chart.render(); +}