rajah 7 месяцев назад
Родитель
Сommit
5cc35970a6

+ 140 - 4
src/main/java/fr/triplea/demovote/web/controller/PresentationController.java

@@ -17,6 +17,7 @@ import org.springframework.context.MessageSource;
 import org.springframework.core.io.ByteArrayResource;
 import org.springframework.core.io.Resource;
 import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -52,7 +53,6 @@ public class PresentationController
   //@SuppressWarnings("unused") 
   private static final Logger LOG = LoggerFactory.getLogger(PresentationController.class);
 
-  // TODO version diaporama pour affichage sur écran de régie
   // TODO raccourci ouvrir/fermer/calculer les votes
   
   @Autowired
@@ -165,7 +165,7 @@ public class PresentationController
               .ok()
               .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"presentations.pdf\"")
               .header(HttpHeaders.CONTENT_LENGTH, "" + binaire.length)
-              .header(HttpHeaders.CONTENT_TYPE, "application/pdf")
+              .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_PDF.toString())
               .body(r); 
     }
     
@@ -209,7 +209,7 @@ public class PresentationController
   private Row createProductionRow(ProductionShort production, int nombre) 
   {
     return Row.builder()
-              .add(createCell("#" + (nombre < 27 ? LETTRES.charAt(nombre - 1) : "?")))
+              .add(createCell("#" + ((nombre < 27) ? LETTRES.charAt(nombre - 1) : "?")))
               .add(createCell(production.titre()))
               .add(createCell(production.auteurs()))
               .add(createCell(production.groupes()))
@@ -232,7 +232,143 @@ public class PresentationController
 
   
   
-  
+  @GetMapping(value = "/diapos/{id}")
+  @PreAuthorize("hasRole('ADMIN')")
+  public ResponseEntity<String> getDiaporama(@PathVariable int id, HttpServletRequest request) 
+  {
+    Locale locale = localeResolver.resolveLocale(request);
+
+    Categorie categorie = categorieRepository.findById(id);
+    
+    List<Presentation> presentations = presentationRepository.findByCategorie(id);
+    
+    if ((categorie != null) && (presentations != null))
+    {
+      String libelleCategorie = categorie.getLibelle();
+         
+      StringBuffer sb = new StringBuffer();
+
+      sb.append("<html>\n");
+      sb.append("<header>\n");
+      
+      // TODO version diaporama en HTML pour affichage sur écran de régie
+
+      /*
+       .diapo_compo_start {  }
+       .diapo_compo_page {  }
+       .diapo_compo_finish {  }
+       .diapo_bouton {  }
+       .diapo_compo {  }
+       .diapo_order {  }
+       .diapo_title {  }
+       .diapo_authors {  }
+       .diapo_comments {  }
+       .diapo_warning {  }
+       .diapo_alert {  }
+       .diapo_image_container {  }
+       .diapo_image_content {  }
+       .diapo_image {  }
+       .diapo_audio_container {  }
+       .diapo_video_container {  }
+      */
+      
+      sb.append("</header>\n");
+      sb.append("<body>\n");
+
+      sb.append("<div class=\"diapo_compo_start\" id=\"diapo_page_0\">\n");
+      
+        sb.append("<div class=\"diapo_compo\">").append(libelleCategorie).append("</div>\n");
+
+        sb.append("<div class=\"diapo_hub\">\n");
+        sb.append("<button class=\"diapo_bouton\" title=\"").append(messageSource.getMessage("show.file.next", null, locale)).append("\">&#9658;</button>\n");
+        sb.append("</div>\n");
+      
+      sb.append("</div>\n");
+
+      int n = 1;
+      
+      for (int i = 0; i < presentations.size(); i++)
+      {
+        Presentation d = presentations.get(i);
+        Production p = d.getProduction();
+
+        sb.append("<div class=\"diapo_compo_page\" id=\"diapo_page_" + n + "\">\n");
+
+          sb.append("<div class=\"diapo_compo\">").append(libelleCategorie).append("</div>\n");
+          sb.append("<div class=\"diapo_order\">").append("#").append((i < 26) ? LETTRES.charAt(i) : "?").append("</div>\n");
+          sb.append("<div class=\"diapo_title\">").append(p.getTitre()).append("</div>\n");
+          sb.append("<div class=\"diapo_authors\">").append(p.getAuteurs()).append(" / ").append(p.getGroupes()).append("</div>\n");
+          sb.append("<div class=\"diapo_comments\">").append(p.getCommentaire()).append("</div>\n");
+
+        switch (d.getEtatMedia())
+        {
+        case 1:
+          
+          if (d.getMimeMedia().startsWith("image/"))
+          {
+            sb.append("<div id=\"\" class=\"diapo_image_container\"><div class=\" class=\"diapo_image_content\">");
+            sb.append("<img src=\"").append(d.getDataMediaAsString()).append("\" alt=\"\" class=\"diapo_image\" />");
+            sb.append("</div></div>\n");
+          }
+          else if (d.getMimeMedia().startsWith("audio/"))
+          {
+            sb.append("<div id=\"\" class=\"diapo_audio_container\">");
+            sb.append("<audio controls><source src=\"").append(d.getDataMediaAsString()).append("\" type=\"").append(d.getMimeMedia()).append("\" />").append("</audio>");
+            sb.append("</div>\n");
+          }
+          else if (d.getMimeMedia().startsWith("video/"))
+          {
+            sb.append("<div id=\"\" class=\"diapo_video_container\">");
+            sb.append("<video controls width=\"480\" height=\"240\"><source src=\"").append(d.getDataMediaAsString()).append("\" type=\"").append(d.getMimeMedia()).append("\" />");
+            sb.append("</video>");
+            sb.append("</div>\n");
+          }
+          
+          break;
+        case 2:
+
+          sb.append("<div class=\"diapo_warning\">").append(messageSource.getMessage("show.file.acknowlegded", null, locale)).append("</div>\n");
+
+          break;
+        default:
+
+          sb.append("<div class=\"diapo_alert\">").append(messageSource.getMessage("show.file.missing", null, locale)).append("</div>\n");
+          
+          break;
+        }
+
+          sb.append("<div class=\"diapo_hub\">\n");
+          sb.append("<button class=\"diapo_bouton\" title=\"").append(messageSource.getMessage("show.file.previous", null, locale)).append("\">&#9668;</button>\n");
+          sb.append("<button class=\"diapo_bouton\" title=\"").append(messageSource.getMessage("show.file.next", null, locale)).append("\">&#9658;</button>\n");
+          sb.append("</div>\n");
+
+        sb.append("</div>");
+        n++;
+      }
+      
+      sb.append("<div class=\"diapo_compo_finish\" id=\"diapo_page_" + n + "\">\n");
+      
+        sb.append("<div class=\"diapo_compo\">").append(libelleCategorie).append("</div>\n");
+
+        sb.append("<div class=\"diapo_hub\">\n");
+        sb.append("<button class=\"diapo_bouton\" title=\"").append(messageSource.getMessage("show.file.previous", null, locale)).append("\">&#9668;</button>\n");
+        sb.append("</div>\n");
+      
+      sb.append("</div>\n");
+
+      sb.append("</body>\n");
+      sb.append("</html>\n");
+      
+      return ResponseEntity
+              .ok()
+              .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + libelleCategorie +".html\"")
+              .header(HttpHeaders.CONTENT_LENGTH, "" + sb.length())
+              .header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML.toString())
+              .body(sb.toString());
+    }
+    
+    return ResponseEntity.notFound().build();
+  }  
   
   
   @GetMapping(value = "/list-linked/{id}")

+ 2 - 1
src/main/java/fr/triplea/demovote/web/controller/ProductionController.java

@@ -11,6 +11,7 @@ import java.util.Locale;
 import java.util.UUID;
 import java.util.stream.Collectors;
 
+import org.apache.tika.mime.MediaType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -120,7 +121,7 @@ public class ProductionController
                 .ok()
                 .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + p.getNomArchive() + "\"")
                 .header(HttpHeaders.CONTENT_LENGTH, "" + data.length)
-                .header(HttpHeaders.CONTENT_TYPE, "application/zip")
+                .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_ZIP.toString())
                 .body(r); 
       }
     }

+ 4 - 0
src/main/resources/langs/messages_en.properties

@@ -45,3 +45,7 @@ show.pdf.productions=prod(s)
 show.file.loaded=The media for this production is uploaded.
 show.file.acknowlegded=The media for this production is known and managed externaly.
 show.file.cleaned=The media for this production is deleted.
+show.file.missing=The media for this production is missing.
+show.file.previous=Go to previous page
+show.file.next=Go to next page
+show.file.open=Open

+ 4 - 0
src/main/resources/langs/messages_fr.properties

@@ -45,3 +45,7 @@ show.pdf.productions=production(s)
 show.file.loaded=Le média de présentation pour cette production a été chargé.
 show.file.acknowlegded=Le média de présentation pour cette production est géré en externe.
 show.file.cleaned=Le média de présentation pour cette production est effacé.
+show.file.missing=Le média est manquant pour la production.
+show.file.previous=Aller à la page précédente
+show.file.next=Aller à la page suivante
+show.file.open=Ouvrir