123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- use crate::entities::{FieldMeta, FieldType, RowMeta};
- use flowy_derive::ProtoBuf;
- use std::collections::HashMap;
- use std::sync::Arc;
- #[derive(Debug, Clone, Default, ProtoBuf)]
- pub struct Grid {
- #[pb(index = 1)]
- pub id: String,
- #[pb(index = 2)]
- pub field_orders: Vec<FieldOrder>,
- #[pb(index = 3)]
- pub block_orders: Vec<GridBlockOrder>,
- }
- #[derive(Debug, Clone, Default, ProtoBuf)]
- pub struct Field {
- #[pb(index = 1)]
- pub id: String,
- #[pb(index = 2)]
- pub name: String,
- #[pb(index = 3)]
- pub desc: String,
- #[pb(index = 4)]
- pub field_type: FieldType,
- #[pb(index = 5)]
- pub frozen: bool,
- #[pb(index = 6)]
- pub visibility: bool,
- #[pb(index = 7)]
- pub width: i32,
- }
- #[derive(Debug, Clone, Default, ProtoBuf)]
- pub struct FieldOrder {
- #[pb(index = 1)]
- pub field_id: String,
- }
- impl std::convert::From<&FieldMeta> for FieldOrder {
- fn from(field_meta: &FieldMeta) -> Self {
- Self {
- field_id: field_meta.id.clone(),
- }
- }
- }
- impl std::convert::From<FieldMeta> for Field {
- fn from(field_meta: FieldMeta) -> Self {
- Self {
- id: field_meta.id,
- name: field_meta.name,
- desc: field_meta.desc,
- field_type: field_meta.field_type,
- frozen: field_meta.frozen,
- visibility: field_meta.visibility,
- width: field_meta.width,
- }
- }
- }
- #[derive(Debug, Default, ProtoBuf)]
- pub struct CreateEditFieldContextParams {
- #[pb(index = 1)]
- pub grid_id: String,
- #[pb(index = 2)]
- pub field_type: FieldType,
- }
- #[derive(Debug, Default, ProtoBuf)]
- pub struct EditFieldContext {
- #[pb(index = 1)]
- pub grid_id: String,
- #[pb(index = 2)]
- pub grid_field: Field,
- #[pb(index = 3)]
- pub type_option_data: Vec<u8>,
- }
- #[derive(Debug, Default, ProtoBuf)]
- pub struct RepeatedField {
- #[pb(index = 1)]
- pub items: Vec<Field>,
- }
- impl std::ops::Deref for RepeatedField {
- type Target = Vec<Field>;
- fn deref(&self) -> &Self::Target {
- &self.items
- }
- }
- impl std::ops::DerefMut for RepeatedField {
- fn deref_mut(&mut self) -> &mut Self::Target {
- &mut self.items
- }
- }
- impl std::convert::From<Vec<Field>> for RepeatedField {
- fn from(items: Vec<Field>) -> Self {
- Self { items }
- }
- }
- #[derive(Debug, Clone, Default, ProtoBuf)]
- pub struct RepeatedFieldOrder {
- #[pb(index = 1)]
- pub items: Vec<FieldOrder>,
- }
- impl std::ops::Deref for RepeatedFieldOrder {
- type Target = Vec<FieldOrder>;
- fn deref(&self) -> &Self::Target {
- &self.items
- }
- }
- #[derive(Debug, Default, Clone, ProtoBuf)]
- pub struct RowOrder {
- #[pb(index = 1)]
- pub row_id: String,
- #[pb(index = 2)]
- pub block_id: String,
- #[pb(index = 3)]
- pub height: i32,
- }
- impl std::convert::From<&RowMeta> for RowOrder {
- fn from(row: &RowMeta) -> Self {
- Self {
- row_id: row.id.clone(),
- block_id: row.block_id.clone(),
- height: row.height,
- }
- }
- }
- impl std::convert::From<&Arc<RowMeta>> for RowOrder {
- fn from(row: &Arc<RowMeta>) -> Self {
- Self {
- row_id: row.id.clone(),
- block_id: row.block_id.clone(),
- height: row.height,
- }
- }
- }
- #[derive(Debug, Default, ProtoBuf)]
- pub struct Row {
- #[pb(index = 1)]
- pub id: String,
- #[pb(index = 2)]
- pub cell_by_field_id: HashMap<String, Cell>,
- #[pb(index = 3)]
- pub height: i32,
- }
- #[derive(Debug, Default, ProtoBuf)]
- pub struct RepeatedRow {
- #[pb(index = 1)]
- pub items: Vec<Row>,
- }
- impl std::convert::From<Vec<Row>> for RepeatedRow {
- fn from(items: Vec<Row>) -> Self {
- Self { items }
- }
- }
- #[derive(Debug, Default, ProtoBuf)]
- pub struct RepeatedGridBlock {
- #[pb(index = 1)]
- pub items: Vec<GridBlock>,
- }
- impl std::convert::From<Vec<GridBlock>> for RepeatedGridBlock {
- fn from(items: Vec<GridBlock>) -> Self {
- Self { items }
- }
- }
- #[derive(Debug, Clone, Default, ProtoBuf)]
- pub struct GridBlockOrder {
- #[pb(index = 1)]
- pub block_id: String,
- }
- impl std::convert::From<&str> for GridBlockOrder {
- fn from(s: &str) -> Self {
- GridBlockOrder { block_id: s.to_owned() }
- }
- }
- #[derive(Debug, Default, ProtoBuf)]
- pub struct GridBlock {
- #[pb(index = 1)]
- pub id: String,
- #[pb(index = 2)]
- pub row_orders: Vec<RowOrder>,
- }
- impl GridBlock {
- pub fn new(block_id: &str, row_orders: Vec<RowOrder>) -> Self {
- Self {
- id: block_id.to_owned(),
- row_orders,
- }
- }
- }
- #[derive(Debug, Default, ProtoBuf)]
- pub struct Cell {
- #[pb(index = 1)]
- pub field_id: String,
- #[pb(index = 2)]
- pub content: String,
- }
- impl Cell {
- pub fn new(field_id: &str, content: String) -> Self {
- Self {
- field_id: field_id.to_owned(),
- content,
- }
- }
- }
- #[derive(Debug, Default, ProtoBuf)]
- pub struct RepeatedCell {
- #[pb(index = 1)]
- pub items: Vec<Cell>,
- }
- impl std::ops::Deref for RepeatedCell {
- type Target = Vec<Cell>;
- fn deref(&self) -> &Self::Target {
- &self.items
- }
- }
- impl std::ops::DerefMut for RepeatedCell {
- fn deref_mut(&mut self) -> &mut Self::Target {
- &mut self.items
- }
- }
- impl std::convert::From<Vec<Cell>> for RepeatedCell {
- fn from(items: Vec<Cell>) -> Self {
- Self { items }
- }
- }
- #[derive(ProtoBuf, Default)]
- pub struct CreateGridPayload {
- #[pb(index = 1)]
- pub name: String,
- }
- #[derive(Clone, ProtoBuf, Default, Debug)]
- pub struct GridId {
- #[pb(index = 1)]
- pub value: String,
- }
- impl AsRef<str> for GridId {
- fn as_ref(&self) -> &str {
- &self.value
- }
- }
- #[derive(Clone, ProtoBuf, Default, Debug)]
- pub struct GridBlockId {
- #[pb(index = 1)]
- pub value: String,
- }
- impl AsRef<str> for GridBlockId {
- fn as_ref(&self) -> &str {
- &self.value
- }
- }
- impl std::convert::From<&str> for GridBlockId {
- fn from(s: &str) -> Self {
- GridBlockId { value: s.to_owned() }
- }
- }
- #[derive(ProtoBuf, Default)]
- pub struct CreateRowPayload {
- #[pb(index = 1)]
- pub grid_id: String,
- #[pb(index = 2, one_of)]
- pub start_row_id: Option<String>,
- }
- #[derive(ProtoBuf, Default)]
- pub struct CreateFieldPayload {
- #[pb(index = 1)]
- pub grid_id: String,
- #[pb(index = 2)]
- pub field: Field,
- #[pb(index = 3)]
- pub type_option_data: Vec<u8>,
- #[pb(index = 4, one_of)]
- pub start_field_id: Option<String>,
- }
- #[derive(ProtoBuf, Default)]
- pub struct QueryFieldPayload {
- #[pb(index = 1)]
- pub grid_id: String,
- #[pb(index = 2)]
- pub field_orders: RepeatedFieldOrder,
- }
- #[derive(ProtoBuf, Default)]
- pub struct QueryGridBlocksPayload {
- #[pb(index = 1)]
- pub grid_id: String,
- #[pb(index = 2)]
- pub block_orders: Vec<GridBlockOrder>,
- }
- #[derive(ProtoBuf, Default)]
- pub struct QueryRowPayload {
- #[pb(index = 1)]
- pub grid_id: String,
- #[pb(index = 2)]
- pub block_id: String,
- #[pb(index = 3)]
- pub row_id: String,
- }
|