2022-07-01 12:32:11 +00:00
|
|
|
use crate::entities::FieldType;
|
2022-03-12 13:06:15 +00:00
|
|
|
use crate::services::field::*;
|
2022-08-10 09:59:28 +00:00
|
|
|
use crate::services::row::RowRevisionBuilder;
|
2022-06-15 07:13:50 +00:00
|
|
|
use flowy_grid_data_model::revision::BuildGridContext;
|
2022-03-19 08:52:28 +00:00
|
|
|
use flowy_sync::client_grid::GridBuilder;
|
2022-08-12 14:58:43 +00:00
|
|
|
use lib_infra::util::timestamp;
|
2022-03-12 13:06:15 +00:00
|
|
|
|
2022-03-15 11:00:28 +00:00
|
|
|
pub fn make_default_grid() -> BuildGridContext {
|
2022-07-12 07:49:14 +00:00
|
|
|
let mut grid_builder = GridBuilder::new();
|
2022-04-11 13:14:45 +00:00
|
|
|
// text
|
2022-03-24 09:09:05 +00:00
|
|
|
let text_field = FieldBuilder::new(RichTextTypeOptionBuilder::default())
|
2022-03-12 13:06:15 +00:00
|
|
|
.name("Name")
|
|
|
|
.visibility(true)
|
2022-04-20 08:32:12 +00:00
|
|
|
.primary(true)
|
2022-03-12 13:06:15 +00:00
|
|
|
.build();
|
2022-07-12 07:49:14 +00:00
|
|
|
grid_builder.add_field(text_field);
|
2022-03-12 13:06:15 +00:00
|
|
|
|
2022-04-07 07:34:00 +00:00
|
|
|
// single select
|
2022-04-11 13:14:45 +00:00
|
|
|
let single_select = SingleSelectTypeOptionBuilder::default();
|
|
|
|
let single_select_field = FieldBuilder::new(single_select).name("Type").visibility(true).build();
|
2022-07-12 07:49:14 +00:00
|
|
|
grid_builder.add_field(single_select_field);
|
2022-04-07 07:34:00 +00:00
|
|
|
|
2022-04-11 13:14:45 +00:00
|
|
|
// checkbox
|
2022-04-07 12:15:00 +00:00
|
|
|
let checkbox_field = FieldBuilder::from_field_type(&FieldType::Checkbox)
|
2022-04-11 13:14:45 +00:00
|
|
|
.name("Done")
|
2022-04-07 12:15:00 +00:00
|
|
|
.visibility(true)
|
|
|
|
.build();
|
2022-07-12 07:49:14 +00:00
|
|
|
grid_builder.add_field(checkbox_field);
|
2022-04-07 12:15:00 +00:00
|
|
|
|
2022-07-12 07:49:14 +00:00
|
|
|
grid_builder.add_empty_row();
|
|
|
|
grid_builder.add_empty_row();
|
|
|
|
grid_builder.add_empty_row();
|
|
|
|
grid_builder.build()
|
2022-03-12 13:06:15 +00:00
|
|
|
}
|
2022-08-10 09:59:28 +00:00
|
|
|
|
|
|
|
pub fn make_default_board() -> BuildGridContext {
|
|
|
|
let mut grid_builder = GridBuilder::new();
|
|
|
|
// text
|
|
|
|
let text_field = FieldBuilder::new(RichTextTypeOptionBuilder::default())
|
|
|
|
.name("Name")
|
|
|
|
.visibility(true)
|
|
|
|
.primary(true)
|
|
|
|
.build();
|
2022-08-12 14:58:43 +00:00
|
|
|
let text_field_id = text_field.id.clone();
|
2022-08-10 09:59:28 +00:00
|
|
|
grid_builder.add_field(text_field);
|
|
|
|
|
2022-08-12 14:58:43 +00:00
|
|
|
// date
|
|
|
|
let date_type_option = DateTypeOptionBuilder::default();
|
|
|
|
let date_field = FieldBuilder::new(date_type_option)
|
|
|
|
.name("Date")
|
|
|
|
.visibility(true)
|
|
|
|
.build();
|
|
|
|
let date_field_id = date_field.id.clone();
|
|
|
|
let timestamp = timestamp();
|
|
|
|
grid_builder.add_field(date_field);
|
|
|
|
|
2022-08-10 09:59:28 +00:00
|
|
|
// single select
|
|
|
|
let in_progress_option = SelectOptionPB::new("In progress");
|
|
|
|
let not_started_option = SelectOptionPB::new("Not started");
|
|
|
|
let done_option = SelectOptionPB::new("Done");
|
2022-08-12 14:58:43 +00:00
|
|
|
let single_select_type_option = SingleSelectTypeOptionBuilder::default()
|
2022-08-10 09:59:28 +00:00
|
|
|
.add_option(not_started_option.clone())
|
2022-08-11 07:00:36 +00:00
|
|
|
.add_option(in_progress_option)
|
|
|
|
.add_option(done_option);
|
2022-08-12 14:58:43 +00:00
|
|
|
let single_select_field = FieldBuilder::new(single_select_type_option)
|
|
|
|
.name("Status")
|
|
|
|
.visibility(true)
|
|
|
|
.build();
|
2022-08-10 09:59:28 +00:00
|
|
|
let single_select_field_id = single_select_field.id.clone();
|
|
|
|
grid_builder.add_field(single_select_field);
|
|
|
|
|
2022-08-11 07:00:36 +00:00
|
|
|
// Insert rows
|
2022-08-12 14:58:43 +00:00
|
|
|
for i in 0..10 {
|
2022-08-11 07:00:36 +00:00
|
|
|
let mut row_builder = RowRevisionBuilder::new(grid_builder.block_id(), grid_builder.field_revs());
|
|
|
|
row_builder.insert_select_option_cell(&single_select_field_id, not_started_option.id.clone());
|
2022-08-12 14:58:43 +00:00
|
|
|
row_builder.insert_cell(&text_field_id, format!("Card {}", i));
|
|
|
|
row_builder.insert_date_cell(&date_field_id, timestamp);
|
2022-08-11 07:00:36 +00:00
|
|
|
let row = row_builder.build();
|
|
|
|
grid_builder.add_row(row);
|
2022-08-11 02:08:42 +00:00
|
|
|
}
|
2022-08-10 09:59:28 +00:00
|
|
|
|
|
|
|
grid_builder.build()
|
|
|
|
}
|