Commit b350f857 authored by Kevin Robert's avatar Kevin Robert
Browse files

UNOTOPLYS-246 et UNOTOPLYS-250 : Mise en place des statistiques sur les cartes.

parent 8e29b846
......@@ -83,4 +83,10 @@ public interface WorkspaceRepository extends JpaRepository<Workspace, Long>, Rol
)
@Modifying
void addRoleWithPermission(@Param("idUser") Long idUser, @Param("idRole") int idRole, @Param("idWorkspace") Long idWorkspace);
@Query(
value = "select count(*) from form where workspace_id = :idWorkspace",
nativeQuery = true
)
Integer countForms(@Param("idWorkspace") Long idWorkspace);
}
......@@ -245,4 +245,14 @@ public class AnswerService {
}
return new ResultsPreview(viewNumber, completedNumber, formCompletionTime);
}
/**
* Récupération du nombre de réponses complètes pour un formulaire.
*
* @param formId L'identifiant du formulaire.
* @return Le nombre de réponses complètes.
*/
public Integer numberOfCompletedAnswerForForm(Long formId) {
return answerRepository.numberOfCompletedAnswerForForm(formId);
}
}
......@@ -180,4 +180,10 @@ public class WorkspaceService extends PermissionService<WorkspaceDTO> {
// Le workspace n'ayant pas de parent, on peut directement utilisé le find.
return find(user, null);
}
@PreAuthorize("hasAuthority('VIEW_WORKSPACE')")
public Integer countForms(Long idWorkspace) {
// Le workspace n'ayant pas de parent, on peut directement utilisé le find.
return workspaceRepository.countForms(idWorkspace);
}
}
......@@ -4,21 +4,31 @@ import com.unantes.orientactive.repository.AnswerRepository;
import com.unantes.orientactive.service.AnswerService;
import com.unantes.orientactive.service.dto.AnswerDTO;
import com.unantes.orientactive.web.rest.errors.BadRequestAlertException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tech.jhipster.web.util.HeaderUtil;
import tech.jhipster.web.util.ResponseUtil;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
* REST controller for managing {@link com.unantes.orientactive.domain.Answer}.
*/
......@@ -65,7 +75,7 @@ public class AnswerResource {
/**
* {@code PUT /answers/:id} : Updates an existing answer.
*
* @param id the id of the answerDTO to save.
* @param id the id of the answerDTO to save.
* @param answerDTO the answerDTO to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated answerDTO,
* or with status {@code 400 (Bad Request)} if the answerDTO is not valid,
......@@ -99,7 +109,7 @@ public class AnswerResource {
/**
* {@code PATCH /answers/:id} : Partial updates given fields of an existing answer, field will ignore if it is null
*
* @param id the id of the answerDTO to save.
* @param id the id of the answerDTO to save.
* @param answerDTO the answerDTO to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated answerDTO,
* or with status {@code 400 (Bad Request)} if the answerDTO is not valid,
......@@ -187,4 +197,16 @@ public class AnswerResource {
public ResultsPreview getResultPreview(@PathVariable Long formId) {
return answerService.getResultPreview(formId);
}
/**
* Récupération du nombre de réponses complètes d'un formulaire.
*
* @param idForm L'identifiant du formulaire.
* @return Le nombre de formulaire.
*/
@GetMapping("/answers/countCompleted/{idForm}")
public Integer countForms(@PathVariable Long idForm) {
return answerService.numberOfCompletedAnswerForForm(idForm);
}
}
......@@ -4,21 +4,30 @@ import com.unantes.orientactive.repository.WorkspaceRepository;
import com.unantes.orientactive.service.WorkspaceService;
import com.unantes.orientactive.service.dto.WorkspaceDTO;
import com.unantes.orientactive.web.rest.errors.BadRequestAlertException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.jhipster.web.util.HeaderUtil;
import tech.jhipster.web.util.ResponseUtil;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
* REST controller for managing {@link com.unantes.orientactive.domain.Workspace}.
*/
......@@ -65,7 +74,7 @@ public class WorkspaceResource {
/**
* {@code PUT /workspaces/:id} : Updates an existing workspace.
*
* @param id the id of the workspaceDTO to save.
* @param id the id of the workspaceDTO to save.
* @param workspaceDTO the workspaceDTO to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated workspaceDTO,
* or with status {@code 400 (Bad Request)} if the workspaceDTO is not valid,
......@@ -99,7 +108,7 @@ public class WorkspaceResource {
/**
* {@code PATCH /workspaces/:id} : Partial updates given fields of an existing workspace, field will ignore if it is null
*
* @param id the id of the workspaceDTO to save.
* @param id the id of the workspaceDTO to save.
* @param workspaceDTO the workspaceDTO to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated workspaceDTO,
* or with status {@code 400 (Bad Request)} if the workspaceDTO is not valid,
......@@ -171,4 +180,15 @@ public class WorkspaceResource {
.headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, id.toString()))
.build();
}
/**
* Récupération du nombre de formulaires d'un workspace.
*
* @param idWorkspace L'identifiant du workspace.
* @return Le nombre de formulaire.
*/
@GetMapping("/workspaces/{idWorkspace}/countForms")
public Integer countForms(@PathVariable Long idWorkspace) {
return workspaceService.countForms(idWorkspace);
}
}
......@@ -13,8 +13,10 @@ export default class Card extends Vue {
@Prop()
public title: string;
public number: string = 'N/A';
@Prop()
public number: string;
public statsFetcher;
@Prop()
public type: string;
......@@ -25,6 +27,13 @@ export default class Card extends Vue {
@Prop()
public link: string;
public beforeMount() {
this.statsFetcher.fetchNumber()
.then(res => {
this.number = res.data
});
}
public get contentType() {
let suffix: string;
if (Number.parseInt(this.number, 10) > 1) {
......
......@@ -6,7 +6,7 @@
<h2 class="mb-2 font-semibold line-clamp-3">{{ title }}</h2>
<div class="absolute bottom-4 left-4">
<div class="mb-2 leading-tight">
<div class="text-3xl text-gray-400">{{ number || 0 }}</div>
<div class="text-3xl text-gray-400">{{ number }}</div>
<p>{{ contentType }}</p>
</div>
</div>
......
......@@ -82,4 +82,8 @@ export default class AnswerService {
});
});
}
public countAnswers(idForm: number): Promise<any> {
return axios.get(`${baseApiUrl}/countCompleted/${idForm}`);
}
}
......@@ -103,4 +103,8 @@ export default class WorkspaceService {
public removePermission(loginUser: string, idWorkspace: number): Promise<any> {
return axios.get(`${baseApiUrl}/removePermission/${loginUser}/${idWorkspace}`);
}
public countForms(idWorkspace: number): Promise<any> {
return axios.get(`${baseApiUrl}/${idWorkspace}/countForms`);
}
}
......@@ -2,11 +2,12 @@ import Vue from 'vue';
import Component from 'vue-class-component';
import FormService from '@/services/form.service';
import { Inject } from 'vue-property-decorator';
import {Inject} from 'vue-property-decorator';
import Card from '@/components/card/card.vue';
import Toolbar from '@/components/toolbar/toolbar.vue';
import HeaderService from '@/shared/service/header-service';
import AnswerService from "@/services/answer.service";
@Component({
components: {
......@@ -26,6 +27,12 @@ export default class FormList extends Vue {
@Inject('formService')
private formService: () => FormService;
/**
* Service des réponses.
*/
@Inject('answerService')
private answerService: () => AnswerService;
/**
* Service du header.
*/
......@@ -63,4 +70,17 @@ export default class FormList extends Vue {
public getLink(element): string {
return `/admin/workspace/${element.workspaceId}/form/${element.id}/view`;
}
/**
* Récuération du nombre de réponses complètes d'un formulaire.
* @param idForm L'identifiant du formulaire.
*/
public getNumberOfAnswers(idForm) {
let service = this.answerService();
return {
fetchNumber: function () {
return service.countAnswers(idForm);
}
}
}
}
......@@ -7,7 +7,7 @@
type="form"
:key="index"
:title="element.name"
:number="element.number_element"
:statsFetcher="getNumberOfAnswers(element.id)"
:link="getLink(element)"
></card>
</div>
......
......@@ -60,4 +60,13 @@ export default class WorkspaceList extends Vue {
public getWorkspaceLink(workspaceId: number) {
return `/admin/workspace/${workspaceId}/view`;
}
public getNumberOfForms(idWorkspace) {
let service = this.workspaceService();
return {
fetchNumber: function() {
return service.countForms(idWorkspace);
}
}
}
}
......@@ -11,7 +11,7 @@
type="workspace"
:key="index"
:title="workspace.name"
:number="workspace.number_element"
:statsFetcher="getNumberOfForms(workspace.id)"
:link="getWorkspaceLink(workspace.id)"
></card>
</div>
......
......@@ -9,6 +9,7 @@ import { IForm } from '@/shared/model/form.model';
import Card from '@/components/card/card.vue';
import Toolbar from '@/components/toolbar/toolbar.vue';
import EmptyList from '@/components/empty-list/empty-list.vue';
import AnswerService from "@/services/answer.service";
@Component({
components: {
......@@ -39,6 +40,12 @@ export default class WorkspaceView extends Vue {
public loaded = false;
/**
* Service des réponses.
*/
@Inject('answerService')
private answerService: () => AnswerService;
/**
* Récupération des workspaces avant de faire l'affichage.
*/
......@@ -82,4 +89,17 @@ export default class WorkspaceView extends Vue {
},
};
}
/**
* Récuération du nombre de réponses complètes d'un formulaire.
* @param idForm L'identifiant du formulaire.
*/
public getNumberOfAnswers(idForm) {
let service = this.answerService();
return {
fetchNumber: function () {
return service.countAnswers(idForm);
}
}
}
}
......@@ -7,7 +7,7 @@
type="form"
:key="index"
:title="form.name"
:number="form.number_element"
:statsFetcher="getNumberOfAnswers(form.id)"
:link="getFormLink(form.id)"
></card>
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment