Bỏ qua, đến nội dung

@digiforce-nc/plugin-ui-core

Plugin UI Core engine — quản lý widget tree, xử lý biến template, và cung cấp query service cho giao diện động.

Plugin này làm gì?

Nếu plugin-ui-schema-storage lưu cấu trúc giao diện, thì plugin-ui-corebộ máy vận hành — nó biết cách đọc widget schema, resolve biến template thành giá trị thực, và chạy query để lấy dữ liệu hiển thị. Ba thành phần này phối hợp tạo nên hệ thống giao diện động hoàn chỉnh.

Ba nhiệm vụ chính

#Nhiệm vụChi tiết
1Widget managementCRUD uiWidgets, duplicate, attach vào parent, move, mutate batch
2Variables resolutionResolve biến template (cú pháp mustache) thành giá trị thực tế
3Query serviceChạy query dữ liệu, lưu query tái sử dụng, data binding cho widget

Kiến trúc — luồng render widget

API endpoints

Widget resource

EndpointMô tả
uiWidgets:findOneLấy widget theo UID
uiWidgets:schemaLấy schema đơn lẻ của widget
uiWidgets:schemasLấy nhiều schema cùng lúc
uiWidgets:schemaBundleBundle schema + toàn bộ descendants
uiWidgets:saveLưu widget (tạo mới hoặc cập nhật)
uiWidgets:duplicateNhân bản widget kèm descendants
uiWidgets:attachGắn widget vào parent tại vị trí chỉ định
uiWidgets:moveDi chuyển widget sang parent khác
uiWidgets:destroyXóa widget kèm descendants
uiWidgets:mutateThực hiện batch operations trên nhiều widget

Variables

EndpointMô tả
variables:resolveResolve biến template — nhận danh sách biến dạng path (VD: ctx.currentUser.id), trả về giá trị tương ứng

Lưu ý: Cú pháp biến sử dụng dạng mustache — tên biến được bao trong cặp ngoặc nhọn kép. Tuy nhiên, plugin thực tế nhận path string qua API, không parse template phía server.

Query service

EndpointMô tả
queryService:runChạy query trực tiếp (truyền SQL/filter)
queryService:runByIdChạy query đã lưu theo ID
queryService:saveLưu query để tái sử dụng
queryService:getBindLấy data binding — ánh xạ giữa query result và widget field

Database — 3 bảng chính

BảngChứa gìVí dụ
uiWidgetsWidget definitions (uid, type, options JSON){ uid: 'w1', type: 'table', options: {...} }
uiWidgetTreePathQuan hệ cây widget (closure table){ ancestor: 'w1', descendant: 'w2', depth: 1 }
queryServiceQuery đã lưu (uid, dataSourceKey, sql){ uid: 'q1', sql: 'SELECT * FROM orders' }

Thành phần chính phía server

Thành phầnMô tả
UiWidgetRepositoryRepository xử lý CRUD widget + tree operations
UiWidgetSchemaServiceService resolve schema bundle, xử lý inheritance
Widget Schema RegistryRegistry đăng ký widget type mới từ plugin khác
VariablesServiceService resolve biến template thành giá trị
QueryServiceManagerQuản lý query execution và caching

Dependencies

PackageVai trò
@digiforce-nc/databaseDatabase ORM (peer)
@digiforce-nc/serverServer framework (peer)
@digiforce-nc/clientClient framework (peer)
@digiforce-nc/plugin-localizationLocalization cho widget labels

Mục lục chi tiết

  • Kiến trúc — Widget repository, schema service, variable resolution, query service
  • API reference — uiWidgets resource, variables:resolve, queryService
  • Database schema — ER diagram, closure table, 3 bảng
  • FAQ — Câu hỏi thường gặp