diff --git a/ComposeRemoteServer/k8s/deploy.yaml b/ComposeRemoteServer/k8s/deploy.yaml
index 2237c62..344e28c 100644
--- a/ComposeRemoteServer/k8s/deploy.yaml
+++ b/ComposeRemoteServer/k8s/deploy.yaml
@@ -22,7 +22,7 @@ spec:
spec:
containers:
- name: server
- image: composeremote/server:1.0.0-editor5
+ image: composeremote/server:1.0.0-editor6
imagePullPolicy: Never
ports:
- name: http
diff --git a/ComposeRemoteServer/src/main/java/com/ttstd/composeremote/server/controller/LayoutAdminController.java b/ComposeRemoteServer/src/main/java/com/ttstd/composeremote/server/controller/LayoutAdminController.java
index 587ebb8..76bf43b 100644
--- a/ComposeRemoteServer/src/main/java/com/ttstd/composeremote/server/controller/LayoutAdminController.java
+++ b/ComposeRemoteServer/src/main/java/com/ttstd/composeremote/server/controller/LayoutAdminController.java
@@ -9,50 +9,61 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
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 org.springframework.web.server.ResponseStatusException;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* 布局编辑接口,供后台拖拽编辑器读写。
*
- *
布局以 JSON 落盘(目录由 {@code app.layout-dir} / {@code LAYOUT_DIR} 指定),
- * 保存后下一次 {@code GET /api/remote-ui/{page}} 就会编译新布局下发。
- * 当前演示环境不鉴权。
+ *
布局以 JSON 落盘(目录由 {@code app.layout-dir} / {@code LAYOUT_DIR} 指定)。
+ * 保存只写草稿,发布后才生效:{@code GET /api/remote-ui/{page}} 编译的是已发布布局,
+ * 编辑器看到的是草稿(没有草稿时回落到已发布)。当前演示环境不鉴权。
*/
@RestController
@RequestMapping("/api/layouts")
public class LayoutAdminController {
- /** 布局列表,编辑器启动时用来发现页面。 */
+ /** 布局列表,编辑器启动时用来发现页面;{@code draft} 标记该页面存在未发布草稿。 */
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public List list() {
- return LayoutStore.INSTANCE.all().stream()
- .map(document -> new LayoutSummary(
- document.getId(),
- document.getTitle(),
- document.getItems().size()
+ return LayoutStore.INSTANCE.summaries().stream()
+ .map(summary -> new LayoutSummary(
+ summary.getId(),
+ summary.getTitle(),
+ summary.getItems(),
+ summary.getDraft()
))
.toList();
}
- /** 读取单个布局;不存在返回 404。 */
+ /** 读取单个布局(优先草稿);不存在返回 404。 */
@GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
- public LayoutDocument get(@PathVariable("id") String id) {
- LayoutDocument document = LayoutStore.INSTANCE.get(id);
- if (document == null) {
+ public Map get(@PathVariable("id") String id) {
+ LayoutStore.EditableLayout editable = LayoutStore.INSTANCE.getEditable(id);
+ if (editable == null) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "布局不存在: " + id);
}
- return document;
+ LayoutDocument document = editable.getDocument();
+ Map body = new LinkedHashMap<>();
+ body.put("id", document.getId());
+ body.put("title", document.getTitle());
+ body.put("canvas", document.getCanvas());
+ body.put("backgroundColor", document.getBackgroundColor());
+ body.put("items", document.getItems());
+ body.put("draft", editable.getDraft());
+ return body;
}
/**
- * 保存布局。
+ * 保存草稿。
*
* 以路径上的 id 为准,避免请求体里的 id 与路径不一致;
* 校验失败返回 400,错误信息是直接给编辑器展示的中文提示。
@@ -76,6 +87,52 @@ public class LayoutAdminController {
return ResponseEntity.ok(document);
}
+ /** 发布草稿:把旧版本归档后覆盖已发布布局;页面完全不存在时返回 404。 */
+ @PostMapping(value = "/{id}/publish", produces = MediaType.APPLICATION_JSON_VALUE)
+ public ResponseEntity