Procházet zdrojové kódy

files Input Screen

Andrew Grant před 4 měsíci
rodič
revize
b44d110673

+ 22 - 0
src/main/java/scot/carricksoftware/grantswriter/constants/AttributeConstants.java

@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.constants;
+
+import org.springframework.stereotype.Component;
+
+@Component
+public class AttributeConstants {
+
+    private AttributeConstants() {
+        // to stop checkstyle complaining
+    }
+
+    public static final String WRITER_FILES = "writerFiles";
+
+
+
+
+}

+ 4 - 2
src/main/java/scot/carricksoftware/grantswriter/controllers/FilesController.java

@@ -6,8 +6,10 @@
 package scot.carricksoftware.grantswriter.controllers;
 
 
+import org.springframework.ui.Model;
+
+
 public interface FilesController {
 
-    @SuppressWarnings({"unused", "SameReturnValue"})
-    String getFiles();
+    String getFiles(Model model);
 }

+ 13 - 3
src/main/java/scot/carricksoftware/grantswriter/controllers/FilesControllerImpl.java

@@ -8,19 +8,29 @@ package scot.carricksoftware.grantswriter.controllers;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.GetMapping;
+import scot.carricksoftware.grantswriter.constants.AttributeConstants;
 import scot.carricksoftware.grantswriter.constants.MappingConstants;
 import scot.carricksoftware.grantswriter.constants.ViewConstants;
+import scot.carricksoftware.grantswriter.files.WriterFiles;
 
 @Controller
 public class FilesControllerImpl implements FilesController {
 
     private static final Logger logger = LogManager.getLogger(FilesControllerImpl.class);
 
-   @Override
-   @GetMapping(MappingConstants.FILES)
-    public String getFiles() {
+    private final WriterFiles writerFiles;
+
+    public FilesControllerImpl(WriterFiles writerFiles) {
+        this.writerFiles = writerFiles;
+    }
+
+    @GetMapping(MappingConstants.FILES)
+    @Override
+    public String getFiles(Model model) {
        logger.debug("FilesControllerImpl::getSelectionPage");
+       model.addAttribute(AttributeConstants.WRITER_FILES, writerFiles);
        return ViewConstants.FILES;
     }
 }

+ 20 - 2
src/main/resources/templates/files.html

@@ -15,11 +15,29 @@
 </head>
 <body>
 
-<div th:insert="~{fragments/layout::banner}"></div>
-
 <div class="mx-auto" style="width:50%;text-align:center;">
     <h1 id="pageHeader">Writer Specify Files</h1>
     <div th:insert="~{fragments/layout::banner}"></div>
 </div>
+<div class="container border border-info
+rounded-3 text-center p-4">
+    <form th:object="${writerFiles}" th:action="@{/files}" method="post">
+
+        <div class="form-group row justify-content-center">
+            <div class="col-xs-3" style="margin-right:20px;">
+                <label for="latexFileName">Latex File (input):</label>
+                <input class="form-control" id="latexFileName"
+                       th:field="*{latexFileName}" type="text">
+            </div>
+            <div class="col-xs-3" style="margin-right:20px;">
+                <label for="pdfFileName">Latex File (input):</label>
+                <input class="form-control" id="pdfFileName"
+                       th:field="*{pdfFileName}" type="text">
+            </div>
+        </div>
+        <button type="submit" class="btn btn-primary">Commit</button>
+    </form>
+
+</div>
 </body>
 </html>

+ 12 - 3
src/test/java/scot/carricksoftware/grantswriter/controllers/FilesControllerTest.java

@@ -8,7 +8,10 @@ package scot.carricksoftware.grantswriter.controllers;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.ui.Model;
+import scot.carricksoftware.grantswriter.files.WriterFiles;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
@@ -17,13 +20,19 @@ class FilesControllerTest {
 
     private FilesController controller;
 
+    @Mock
+    private WriterFiles writerFilesMock;
+
+    @Mock
+    private Model modelMock;
+
     @BeforeEach
     void setUp() {
-        controller = new FilesControllerImpl();
+        controller = new FilesControllerImpl(writerFilesMock);
     }
 
     @Test
-    void dummyFilesReturnsTheCorrectPageTest(){
-        assertEquals("files", controller.getFiles());
+    void filesReturnsTheCorrectPageTest(){
+        assertEquals("files", controller.getFiles(modelMock));
     }
 }