AppFlowy/frontend/rust-lib/flowy-database2/src/template.rs
Nathan.fooo 32bd0ffca2
feat: migrate flowy-database (#2373)
* feat: add flowy-database2

* chore: config type option data

* chore: impl type option

* feat: config group

* fix: group compile

* feat: add sort

* chore: setting

* chore: insert with specific type

* chore: custom group

* chore: rename any map

* chore: use group setting

* chore: update

* chore: open database event

* chore: update database editor

* chore: update

* chore: update view editor

* chore: update

* chore: update view editor

* chore: sort feat

* chore: update handler

* chore: update

* chore: config handler event

* feat: impl handlers

* feat: impl handlers

* chore: layout setting

* feat: impl handlers

* chore: remove flowy-folder ref

* chore: integrate flowy-database2

* feat: get cell

* chore: create database with data

* chore: create view

* chore: fix dart compile

* fix: some bugs

* chore: update

* chore: merge develop

* chore: fix warning

* chore: integrate rocksdb

* fix: rocksdb compile errros

* fix: update cell

* chore: update the bundle identifier

* fix: create row

* fix: switch to field

* fix: duplicate grid

* test: migrate tests

* test: migrate tests

* test: update test

* test: migrate tests

* chore: add patch
2023-04-28 14:08:53 +08:00

138 lines
4.1 KiB
Rust

use collab_database::database::{gen_database_id, gen_row_id};
use collab_database::rows::CreateRowParams;
use collab_database::views::{CreateDatabaseParams, DatabaseLayout, LayoutSettings};
use crate::entities::FieldType;
use crate::services::cell::{insert_select_option_cell, insert_text_cell};
use crate::services::field::{
FieldBuilder, SelectOption, SelectOptionColor, SingleSelectTypeOption,
};
use crate::services::setting::CalendarLayoutSetting;
pub fn make_default_grid(view_id: &str, name: &str) -> CreateDatabaseParams {
let text_field = FieldBuilder::from_field_type(FieldType::RichText)
.name("Name")
.visibility(true)
.primary(true)
.build();
let single_select = FieldBuilder::from_field_type(FieldType::SingleSelect)
.name("Type")
.visibility(true)
.build();
let checkbox_field = FieldBuilder::from_field_type(FieldType::Checkbox)
.name("Done")
.visibility(true)
.build();
CreateDatabaseParams {
database_id: gen_database_id(),
view_id: view_id.to_string(),
name: name.to_string(),
layout: DatabaseLayout::Grid,
layout_settings: Default::default(),
filters: vec![],
groups: vec![],
sorts: vec![],
created_rows: vec![
CreateRowParams::new(gen_row_id()),
CreateRowParams::new(gen_row_id()),
CreateRowParams::new(gen_row_id()),
],
fields: vec![text_field, single_select, checkbox_field],
}
}
pub fn make_default_board(view_id: &str, name: &str) -> CreateDatabaseParams {
// text
let text_field = FieldBuilder::from_field_type(FieldType::RichText)
.name("Description")
.visibility(true)
.primary(true)
.build();
let text_field_id = text_field.id.clone();
// single select
let to_do_option = SelectOption::with_color("To Do", SelectOptionColor::Purple);
let doing_option = SelectOption::with_color("Doing", SelectOptionColor::Orange);
let done_option = SelectOption::with_color("Done", SelectOptionColor::Yellow);
let mut single_select_type_option = SingleSelectTypeOption::default();
single_select_type_option
.options
.extend(vec![to_do_option.clone(), doing_option, done_option]);
let single_select = FieldBuilder::new(FieldType::SingleSelect, single_select_type_option)
.name("Status")
.visibility(true)
.build();
let single_select_field_id = single_select.id.clone();
let mut rows = vec![];
for i in 0..3 {
let mut row = CreateRowParams::new(gen_row_id());
row.cells.insert(
single_select_field_id.clone(),
insert_select_option_cell(vec![to_do_option.id.clone()], &single_select),
);
row.cells.insert(
text_field_id.clone(),
insert_text_cell(format!("Card {}", i + 1), &text_field),
);
rows.push(row);
}
CreateDatabaseParams {
database_id: gen_database_id(),
view_id: view_id.to_string(),
name: name.to_string(),
layout: DatabaseLayout::Board,
layout_settings: Default::default(),
filters: vec![],
groups: vec![],
sorts: vec![],
created_rows: rows,
fields: vec![text_field, single_select],
}
}
pub fn make_default_calendar(view_id: &str, name: &str) -> CreateDatabaseParams {
// text
let text_field = FieldBuilder::from_field_type(FieldType::RichText)
.name("Title")
.visibility(true)
.primary(true)
.build();
// date
let date_field = FieldBuilder::from_field_type(FieldType::DateTime)
.name("Date")
.visibility(true)
.build();
let date_field_id = date_field.id.clone();
// multi select
let multi_select_field = FieldBuilder::from_field_type(FieldType::MultiSelect)
.name("Tags")
.visibility(true)
.build();
let mut layout_settings = LayoutSettings::default();
layout_settings.insert(
DatabaseLayout::Calendar,
CalendarLayoutSetting::new(date_field_id).into(),
);
CreateDatabaseParams {
database_id: gen_database_id(),
view_id: view_id.to_string(),
name: name.to_string(),
layout: DatabaseLayout::Calendar,
layout_settings,
filters: vec![],
groups: vec![],
sorts: vec![],
created_rows: vec![],
fields: vec![text_field, date_field, multi_select_field],
}
}