浏览代码

Creadas 2 clases y finalizado dashboard, a falta de los colores de Gantt

Mario Martínez Hernández 2 周之前
父节点
当前提交
db24b85957

+ 35 - 0
src/main/java/es/uv/saic/domain/CursoValor.java

@@ -0,0 +1,35 @@
+package es.uv.saic.domain;
+
+public class CursoValor{
+    private String periodo;
+    private String valor;
+    private Integer curso;
+    
+    public CursoValor(){ }
+    
+    public CursoValor(String periodo, String valor) {
+        this.periodo = periodo;
+        this.valor = valor;
+        this.curso = Integer.parseInt(periodo.split("-")[1]);
+    }
+    
+    public String getPeriodo() {
+        return periodo;
+    }
+    public void setPeriodo(String periodo) {
+        this.periodo = periodo;
+    }
+    public Integer getCurso() {
+        return curso;
+    }
+    public void setValor(Integer curso) {
+        this.curso = curso;
+    }
+    public String getValor() {
+        return valor;
+    }
+    public void setValor(String valor) {
+        this.valor = valor;
+    }
+}
+

+ 8 - 35
src/main/java/es/uv/saic/domain/Indicador.java

@@ -24,6 +24,14 @@ public class Indicador {
 		this.valores = new ArrayList<CursoValor>();
 	}
 
+	public Indicador(String dimension, String indicador, String valor, String ambit, List<CursoValor> cursoValors) {
+		this.dimension = dimension;
+		this.indicador = indicador;
+		this.valor = valor;
+		this.ambit = ambit;
+		this.valores = cursoValors;
+	}
+
 	public String getDimension() {
 		return dimension;
 	}
@@ -81,39 +89,4 @@ public class Indicador {
 			return null;
 		}
 	}
-
-
-	public class CursoValor{
-		private String periodo;
-		private String valor;
-		private Integer curso;
-		
-		public CursoValor(){ }
-		
-		public CursoValor(String periodo, String valor) {
-			this.periodo = periodo;
-			this.valor = valor;
-			this.curso = Integer.parseInt(periodo.split("-")[1]);
-		}
-		
-		public String getPeriodo() {
-			return periodo;
-		}
-		public void setPeriodo(String periodo) {
-			this.periodo = periodo;
-		}
-		public Integer getCurso() {
-			return curso;
-		}
-		public void setValor(Integer curso) {
-			this.curso = curso;
-		}
-		public String getValor() {
-			return valor;
-		}
-		public void setValor(String valor) {
-			this.valor = valor;
-		}
-	}
-
 }

+ 97 - 0
src/main/java/es/uv/saic/dto/InstanciaGanttDTOImp.java

@@ -0,0 +1,97 @@
+package es.uv.saic.dto;
+
+import java.math.BigInteger;
+
+public class InstanciaGanttDTOImp implements InstanciaGanttDTO{
+    private BigInteger id;
+	private String name;
+	private String titCas;
+	private String titVal;
+	private String start;
+	private String end;
+	private Integer progress;
+	private String customClass;
+
+    public InstanciaGanttDTOImp(BigInteger id, String name, String titCas, String titVal, String start, String end,
+            Integer progress, String customClass) {
+        this.id = id;
+        this.name = name;
+        this.titCas = titCas;
+        this.titVal = titVal;
+        this.start = start;
+        this.end = end;
+        this.progress = progress;
+        this.customClass = customClass;
+    }
+
+    public InstanciaGanttDTOImp(InstanciaGanttDTO instanciaGanttDTO) {
+        this.id = instanciaGanttDTO.getId();
+        this.name = instanciaGanttDTO.getName();
+        this.titCas = instanciaGanttDTO.getTitCas();
+        this.titVal = instanciaGanttDTO.getTitVal();
+        this.start = instanciaGanttDTO.getStart();
+        this.end = instanciaGanttDTO.getEnd();
+        this.progress = instanciaGanttDTO.getProgress();
+        this.customClass = instanciaGanttDTO.getCustom_class();
+    }
+
+    public void setId(BigInteger id) {
+        this.id = id;
+    }
+    public void setName(String name) {
+        this.name = name;
+    }
+    public void setTitCas(String titCas) {
+        this.titCas = titCas;
+    }
+    public void setTitVal(String titVal) {
+        this.titVal = titVal;
+    }
+    public void setStart(String start) {
+        this.start = start;
+    }
+    public void setEnd(String end) {
+        this.end = end;
+    }
+    public void setProgress(Integer progress) {
+        this.progress = progress;
+    }
+    public void setCustomClass(String customClass) {
+        this.customClass = customClass;
+    }
+    @Override
+    public BigInteger getId() {
+        return id;
+    }
+    @Override
+    public String getName() {
+        return name;
+    }
+    @Override
+    public String getTitCas() {
+        return titCas;    
+    }
+    @Override
+    public String getTitVal() {
+        return titVal;
+    }
+    @Override
+    public String getStart() {
+        return start;
+    }
+    @Override
+    public String getEnd() {
+        return end;
+    }
+    @Override
+    public Integer getProgress() {
+        return progress;
+    }
+
+    @Override
+    public String getCustom_class() {
+        return customClass;
+    }
+
+    
+}

+ 4 - 1
src/main/java/es/uv/saic/service/UsuariService.java

@@ -26,7 +26,10 @@ public class UsuariService {
 	}
 	
 	public Usuari findByUsername(String usuari) {
-		return this.usuariRepository.findByUsername(usuari);
+		Usuari u = this.usuariRepository.findByUsername(usuari);
+		u.setAdmin(this.usuarisRolService.isAdminUser(u));
+		u.setGranted(this.usuarisRolService.isGrantedUser(u));
+		return u;
 	}
 	
 	public boolean hasActiveRol(Usuari usuari) {

+ 19 - 11
src/main/java/es/uv/saic/web/DashboardController.java

@@ -45,6 +45,7 @@ import es.uv.saic.domain.InformeProcessos;
 import es.uv.saic.domain.Instancia;
 import es.uv.saic.domain.Link;
 import es.uv.saic.domain.Categoria;
+import es.uv.saic.domain.CursoValor;
 import es.uv.saic.domain.Document;
 import es.uv.saic.domain.Grafica;
 import es.uv.saic.domain.Indicador;
@@ -61,6 +62,7 @@ import es.uv.saic.dto.DocumentTmpDTO;
 import es.uv.saic.dto.IndicadorDTO;
 import es.uv.saic.dto.InstanciaDTO;
 import es.uv.saic.dto.InstanciaGanttDTO;
+import es.uv.saic.dto.InstanciaGanttDTOImp;
 import es.uv.saic.dto.OrganDTO;
 import es.uv.saic.dto.TreeDTOAny;
 import es.uv.saic.dto.TreeDTODimensio;
@@ -79,7 +81,7 @@ import es.uv.saic.service.OrganService;
 import es.uv.saic.service.UsuariService;
 import es.uv.saic.service.UsuarisRolService;
 
-@Controller
+@RestController
 public class DashboardController {
 
 	@Autowired 
@@ -182,7 +184,7 @@ public class DashboardController {
 
 		if(!this.isSuitable(o, u)) {
 			model.put("redirect", "401");
-			return model;
+				return model;
 		}
 		
 		if(o.getTambit().equals("C") && o.getId().getTlugar().equals("C") && o.getId().getLugar() == 0) {
@@ -385,7 +387,7 @@ public class DashboardController {
 	// GET para conseguir el diagrama de gantt a partir del ruct
 	@GetMapping("/dashboard/gantt/{ruct}")
 	@ResponseBody
-	public List<InstanciaGanttDTO> loadGantt(@PathVariable Integer ruct) {
+	public List<InstanciaGanttDTOImp> loadGantt(@PathVariable Integer ruct) {
 		Organ o = os.findByRuct(ruct);
 		List<Integer> ambits = Arrays.asList(1, 2, 3, 0);
 		if(!o.getTambit().equals("C")) {
@@ -425,7 +427,7 @@ public class DashboardController {
 			}  
 		});
 						
-		return data;
+		return data.stream().map(InstanciaGanttDTOImp::new).toList();
 	}
 		
 	@GetMapping("/dashboard/documents/cats/{idCategoria}/{tambit}")
@@ -491,18 +493,18 @@ public class DashboardController {
 	public List<Indicador> getGraphDataTaxes(@PathVariable Integer lugar) throws ParserConfigurationException {
 		return this.ids.getGraphData(lugar);
 	}
-	
+
 	//GET para conseguir todos los datos concretos de cada gráfico
-	@GetMapping({"/dashboard/graphs/inds/{ruct}", "/dashboard/graphs/inds/{ruct}/{tambit}"})
+	@GetMapping("/dashboard/graphs/inds/{ruct}/{tambit}")
 	@ResponseBody
-	public List<Indicador> getGraphData(@PathVariable Integer ruct, @PathVariable Optional<String> tambit) throws ParserConfigurationException {
+	public List<Indicador> getGraphDataByRuctTambit(@PathVariable Integer ruct, @PathVariable String tambit) throws ParserConfigurationException {
 		Organ o = os.findByRuct(ruct);
 		int year = Year.now().getValue();
 		List<IndicadorDTO> data = new ArrayList<IndicadorDTO>();
 
 		if(o.getTambit().equals("C")) {
 			Integer centre = o.getId().getLugar();
-			data = this.ies.getGraphData(centre, tambit.get(), year-10);
+			data = this.ies.getGraphData(centre, tambit, year-10);
 		}
 		else {
 			List<Integer> tits = this.os.getEquivalents(o.getId().getLugar(), "T");
@@ -521,10 +523,10 @@ public class DashboardController {
 				in.setIndicador(i.getIndicador());
 				in.setDimension(i.getDimensio());
 				in.setAmbit(i.getAmbit());
-				in.getValores().add(in.new CursoValor(Integer.toString(Integer.parseInt(i.getCurs())-1)+"-"+i.getCurs(), i.getValor()));
+				in.getValores().add(new CursoValor(Integer.toString(Integer.parseInt(i.getCurs())-1)+"-"+i.getCurs(), i.getValor()));
 			}
 			else if(inAux.equals(i.getDimensio()+"_"+i.getIndicador()+"_"+i.getAmbit())) {
-				in.getValores().add(in.new CursoValor(Integer.toString(Integer.parseInt(i.getCurs())-1)+"-"+i.getCurs(), i.getValor()));
+				in.getValores().add(new CursoValor(Integer.toString(Integer.parseInt(i.getCurs())-1)+"-"+i.getCurs(), i.getValor()));
 			}
 			else {
 				inds.add(in);
@@ -533,7 +535,7 @@ public class DashboardController {
 				in.setIndicador(i.getIndicador());
 				in.setDimension(i.getDimensio());
 				in.setAmbit(i.getAmbit());
-				in.getValores().add(in.new CursoValor(Integer.toString(Integer.parseInt(i.getCurs())-1)+"-"+i.getCurs(), i.getValor()));
+				in.getValores().add(new CursoValor(Integer.toString(Integer.parseInt(i.getCurs())-1)+"-"+i.getCurs(), i.getValor()));
 			}
 			
 			if(count == data.size()) {
@@ -543,6 +545,12 @@ public class DashboardController {
 		return inds;
 	}
 
+	@GetMapping("/dashboard/graphs/inds/{ruct}")
+	@ResponseBody
+	public List<Indicador> getGraphDataByRuct(@PathVariable Integer ruct) throws ParserConfigurationException {
+		return getGraphDataByRuctTambit(ruct, null);
+	}
+
 	@GetMapping("/dashboard/links/{ruct}")
 	@ResponseBody
 	public List<Link> getLinks(@PathVariable Integer ruct) {