|
@@ -3,6 +3,7 @@ package com.opengroupe.cloud.saas.web;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.ui.Model;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@@ -12,33 +13,42 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.opengroupe.cloud.saas.domain.Comment;
|
|
import com.opengroupe.cloud.saas.domain.Comment;
|
|
|
import com.opengroupe.cloud.saas.service.CommentService;
|
|
import com.opengroupe.cloud.saas.service.CommentService;
|
|
|
-import com.opengroupe.cloud.saas.util.React;
|
|
|
|
|
|
|
+import com.opengroupe.cloud.saas.util.JavaScriptEngine;
|
|
|
|
|
|
|
|
@Controller
|
|
@Controller
|
|
|
public class ViewController {
|
|
public class ViewController {
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private CommentService service;
|
|
private CommentService service;
|
|
|
|
|
+
|
|
|
|
|
+ @Bean
|
|
|
|
|
+ JavaScriptEngine nashornEngine() {
|
|
|
|
|
+ return new JavaScriptEngine().polyfillToNashorn()
|
|
|
|
|
+ .loadFromClassPath("META-INF/resources/webjars/react/0.14.7/react.min.js")
|
|
|
|
|
+ .loadFromClassPath("META-INF/resources/webjars/marked/0.3.2/marked.js")
|
|
|
|
|
+ .loadFromClassPath("static/js/app.js")
|
|
|
|
|
+ .loadFromClassPath("static/js/app.render.js");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
-
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private ObjectMapper objectMapper;
|
|
|
|
|
|
|
+ ObjectMapper objectMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ JavaScriptEngine nashorn;
|
|
|
|
|
|
|
|
- private React react = new React();
|
|
|
|
|
-
|
|
|
|
|
@RequestMapping("/greeting")
|
|
@RequestMapping("/greeting")
|
|
|
- public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
|
|
|
|
|
|
|
+ public String greeting(@RequestParam(value = "name", required = false, defaultValue = "World") String name,
|
|
|
|
|
+ Model model) {
|
|
|
model.addAttribute("name", name);
|
|
model.addAttribute("name", name);
|
|
|
return "greeting";
|
|
return "greeting";
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@RequestMapping("/index")
|
|
@RequestMapping("/index")
|
|
|
public String index(Model model) throws JsonProcessingException {
|
|
public String index(Model model) throws JsonProcessingException {
|
|
|
List<Comment> comments = service.getAll();
|
|
List<Comment> comments = service.getAll();
|
|
|
- String commentBox = react.renderCommentBox(comments);
|
|
|
|
|
- String data = objectMapper.writeValueAsString(comments);
|
|
|
|
|
- model.addAttribute("markup", commentBox);
|
|
|
|
|
- model.addAttribute("data", data);
|
|
|
|
|
|
|
+ String markup = nashorn.invokeFunction("renderServer", String::valueOf, comments);
|
|
|
|
|
+ String data = objectMapper.writeValueAsString(comments);
|
|
|
|
|
+ model.addAttribute("markup", markup);
|
|
|
|
|
+ model.addAttribute("data", data);
|
|
|
return "index";
|
|
return "index";
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|