|
@@ -1,9 +1,12 @@
|
|
|
|
+use crate::revision::filter_rev::GridFilterRevision;
|
|
|
|
+use crate::revision::group_rev::GridGroupRevision;
|
|
use crate::revision::{FieldRevision, FieldTypeRevision};
|
|
use crate::revision::{FieldRevision, FieldTypeRevision};
|
|
use indexmap::IndexMap;
|
|
use indexmap::IndexMap;
|
|
use nanoid::nanoid;
|
|
use nanoid::nanoid;
|
|
use serde::{Deserialize, Serialize};
|
|
use serde::{Deserialize, Serialize};
|
|
use serde_repr::*;
|
|
use serde_repr::*;
|
|
use std::collections::HashMap;
|
|
use std::collections::HashMap;
|
|
|
|
+use std::fmt::Debug;
|
|
use std::sync::Arc;
|
|
use std::sync::Arc;
|
|
|
|
|
|
pub fn gen_grid_filter_id() -> String {
|
|
pub fn gen_grid_filter_id() -> String {
|
|
@@ -18,41 +21,50 @@ pub fn gen_grid_sort_id() -> String {
|
|
nanoid!(6)
|
|
nanoid!(6)
|
|
}
|
|
}
|
|
|
|
|
|
-/// Each layout contains multiple key/value.
|
|
|
|
-/// Key: field_id
|
|
|
|
-/// Value: this value also contains key/value.
|
|
|
|
-/// Key: FieldType,
|
|
|
|
-/// Value: the corresponding filter.
|
|
|
|
-///
|
|
|
|
-/// This overall struct is described below:
|
|
|
|
-/// GridSettingRevision
|
|
|
|
-/// layout:
|
|
|
|
-/// field_id:
|
|
|
|
-/// FieldType: GridFilterRevision
|
|
|
|
-/// FieldType: GridFilterRevision
|
|
|
|
-/// field_id:
|
|
|
|
-/// FieldType: GridFilterRevision
|
|
|
|
-/// FieldType: GridFilterRevision
|
|
|
|
-/// layout:
|
|
|
|
-/// field_id:
|
|
|
|
-/// FieldType: GridFilterRevision
|
|
|
|
-/// FieldType: GridFilterRevision
|
|
|
|
-///
|
|
|
|
-/// Group and sorts will be the same structure as filters.
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Default, Eq, PartialEq)]
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Default, Eq, PartialEq)]
|
|
pub struct GridSettingRevision {
|
|
pub struct GridSettingRevision {
|
|
pub layout: GridLayoutRevision,
|
|
pub layout: GridLayoutRevision,
|
|
|
|
|
|
|
|
+ /// Each layout contains multiple key/value.
|
|
|
|
+ /// Key: field_id
|
|
|
|
+ /// Value: this value contains key/value.
|
|
|
|
+ /// Key: FieldType,
|
|
|
|
+ /// Value: the corresponding filters.
|
|
#[serde(with = "indexmap::serde_seq")]
|
|
#[serde(with = "indexmap::serde_seq")]
|
|
filters: IndexMap<GridLayoutRevision, IndexMap<String, GridFilterRevisionMap>>,
|
|
filters: IndexMap<GridLayoutRevision, IndexMap<String, GridFilterRevisionMap>>,
|
|
|
|
|
|
|
|
+ /// Each layout contains multiple key/value.
|
|
|
|
+ /// Key: field_id
|
|
|
|
+ /// Value: this value contains key/value.
|
|
|
|
+ /// Key: FieldType,
|
|
|
|
+ /// Value: the corresponding groups.
|
|
#[serde(skip, with = "indexmap::serde_seq")]
|
|
#[serde(skip, with = "indexmap::serde_seq")]
|
|
- pub groups: IndexMap<GridLayoutRevision, Vec<GridGroupRevision>>,
|
|
|
|
|
|
+ pub groups: IndexMap<GridLayoutRevision, IndexMap<String, GridGroupRevisionMap>>,
|
|
|
|
|
|
#[serde(skip, with = "indexmap::serde_seq")]
|
|
#[serde(skip, with = "indexmap::serde_seq")]
|
|
pub sorts: IndexMap<GridLayoutRevision, Vec<GridSortRevision>>,
|
|
pub sorts: IndexMap<GridLayoutRevision, Vec<GridSortRevision>>,
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize_repr, Deserialize_repr)]
|
|
|
|
+#[repr(u8)]
|
|
|
|
+pub enum GridLayoutRevision {
|
|
|
|
+ Table = 0,
|
|
|
|
+ Board = 1,
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+impl ToString for GridLayoutRevision {
|
|
|
|
+ fn to_string(&self) -> String {
|
|
|
|
+ let layout_rev = self.clone() as u8;
|
|
|
|
+ layout_rev.to_string()
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+impl std::default::Default for GridLayoutRevision {
|
|
|
|
+ fn default() -> Self {
|
|
|
|
+ GridLayoutRevision::Table
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
pub type FiltersByFieldId = HashMap<String, Vec<Arc<GridFilterRevision>>>;
|
|
pub type FiltersByFieldId = HashMap<String, Vec<Arc<GridFilterRevision>>>;
|
|
pub type GroupsByFieldId = HashMap<String, Vec<Arc<GridGroupRevision>>>;
|
|
pub type GroupsByFieldId = HashMap<String, Vec<Arc<GridGroupRevision>>>;
|
|
pub type SortsByFieldId = HashMap<String, Vec<Arc<GridSortRevision>>>;
|
|
pub type SortsByFieldId = HashMap<String, Vec<Arc<GridSortRevision>>>;
|
|
@@ -61,6 +73,36 @@ impl GridSettingRevision {
|
|
None
|
|
None
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ pub fn get_mut_groups(
|
|
|
|
+ &mut self,
|
|
|
|
+ layout: &GridLayoutRevision,
|
|
|
|
+ field_id: &str,
|
|
|
|
+ field_type: &FieldTypeRevision,
|
|
|
|
+ ) -> Option<&mut Vec<Arc<GridGroupRevision>>> {
|
|
|
|
+ self.groups
|
|
|
|
+ .get_mut(layout)
|
|
|
|
+ .and_then(|group_rev_map_by_field_id| group_rev_map_by_field_id.get_mut(field_id))
|
|
|
|
+ .and_then(|group_rev_map| group_rev_map.get_mut(field_type))
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pub fn insert_group(
|
|
|
|
+ &mut self,
|
|
|
|
+ layout: &GridLayoutRevision,
|
|
|
|
+ field_id: &str,
|
|
|
|
+ field_type: &FieldTypeRevision,
|
|
|
|
+ filter_rev: GridGroupRevision,
|
|
|
|
+ ) {
|
|
|
|
+ let filter_rev_map_by_field_id = self.groups.entry(layout.clone()).or_insert_with(IndexMap::new);
|
|
|
|
+ let filter_rev_map = filter_rev_map_by_field_id
|
|
|
|
+ .entry(field_id.to_string())
|
|
|
|
+ .or_insert_with(GridGroupRevisionMap::new);
|
|
|
|
+
|
|
|
|
+ filter_rev_map
|
|
|
|
+ .entry(field_type.to_owned())
|
|
|
|
+ .or_insert_with(Vec::new)
|
|
|
|
+ .push(Arc::new(filter_rev))
|
|
|
|
+ }
|
|
|
|
+
|
|
pub fn get_all_sort(&self) -> Option<SortsByFieldId> {
|
|
pub fn get_all_sort(&self) -> Option<SortsByFieldId> {
|
|
None
|
|
None
|
|
}
|
|
}
|
|
@@ -135,70 +177,50 @@ impl GridSettingRevision {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
|
|
|
|
+pub struct GridSortRevision {
|
|
|
|
+ pub id: String,
|
|
|
|
+ pub field_id: Option<String>,
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+pub type GridFilterRevisionMap = GridObjectRevisionMap<GridFilterRevision>;
|
|
|
|
+pub type GridGroupRevisionMap = GridObjectRevisionMap<GridGroupRevision>;
|
|
|
|
+
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Default, Eq, PartialEq)]
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Default, Eq, PartialEq)]
|
|
#[serde(transparent)]
|
|
#[serde(transparent)]
|
|
-pub struct GridFilterRevisionMap {
|
|
|
|
|
|
+pub struct GridObjectRevisionMap<T>
|
|
|
|
+where
|
|
|
|
+ T: Debug + Clone + Default + Eq + PartialEq + serde::Serialize + serde::de::DeserializeOwned + 'static,
|
|
|
|
+{
|
|
#[serde(with = "indexmap::serde_seq")]
|
|
#[serde(with = "indexmap::serde_seq")]
|
|
- pub filter_by_field_type: IndexMap<FieldTypeRevision, Vec<Arc<GridFilterRevision>>>,
|
|
|
|
|
|
+ pub object_by_field_type: IndexMap<FieldTypeRevision, Vec<Arc<T>>>,
|
|
}
|
|
}
|
|
|
|
|
|
-impl GridFilterRevisionMap {
|
|
|
|
|
|
+impl<T> GridObjectRevisionMap<T>
|
|
|
|
+where
|
|
|
|
+ T: Debug + Clone + Default + Eq + PartialEq + serde::Serialize + serde::de::DeserializeOwned + 'static,
|
|
|
|
+{
|
|
pub fn new() -> Self {
|
|
pub fn new() -> Self {
|
|
- GridFilterRevisionMap::default()
|
|
|
|
|
|
+ GridObjectRevisionMap::default()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-impl std::ops::Deref for GridFilterRevisionMap {
|
|
|
|
- type Target = IndexMap<FieldTypeRevision, Vec<Arc<GridFilterRevision>>>;
|
|
|
|
|
|
+impl<T> std::ops::Deref for GridObjectRevisionMap<T>
|
|
|
|
+where
|
|
|
|
+ T: Debug + Clone + Default + Eq + PartialEq + serde::Serialize + serde::de::DeserializeOwned + 'static,
|
|
|
|
+{
|
|
|
|
+ type Target = IndexMap<FieldTypeRevision, Vec<Arc<T>>>;
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
fn deref(&self) -> &Self::Target {
|
|
- &self.filter_by_field_type
|
|
|
|
|
|
+ &self.object_by_field_type
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-impl std::ops::DerefMut for GridFilterRevisionMap {
|
|
|
|
|
|
+impl<T> std::ops::DerefMut for GridObjectRevisionMap<T>
|
|
|
|
+where
|
|
|
|
+ T: Debug + Clone + Default + Eq + PartialEq + serde::Serialize + serde::de::DeserializeOwned + 'static,
|
|
|
|
+{
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
- &mut self.filter_by_field_type
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize_repr, Deserialize_repr)]
|
|
|
|
-#[repr(u8)]
|
|
|
|
-pub enum GridLayoutRevision {
|
|
|
|
- Table = 0,
|
|
|
|
- Board = 1,
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-impl ToString for GridLayoutRevision {
|
|
|
|
- fn to_string(&self) -> String {
|
|
|
|
- let layout_rev = self.clone() as u8;
|
|
|
|
- layout_rev.to_string()
|
|
|
|
|
|
+ &mut self.object_by_field_type
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-impl std::default::Default for GridLayoutRevision {
|
|
|
|
- fn default() -> Self {
|
|
|
|
- GridLayoutRevision::Table
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq, Hash)]
|
|
|
|
-pub struct GridFilterRevision {
|
|
|
|
- pub id: String,
|
|
|
|
- pub field_id: String,
|
|
|
|
- pub condition: u8,
|
|
|
|
- pub content: Option<String>,
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
|
|
|
|
-pub struct GridGroupRevision {
|
|
|
|
- pub id: String,
|
|
|
|
- pub field_id: Option<String>,
|
|
|
|
- pub sub_field_id: Option<String>,
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
|
|
|
|
-pub struct GridSortRevision {
|
|
|
|
- pub id: String,
|
|
|
|
- pub field_id: Option<String>,
|
|
|
|
-}
|
|
|