Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Family direct json edition #57

Merged
merged 7 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/src/api/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ async fn admin_login(
delete,
path = "/api/admin/session",
responses(
(status = 200, description = "Logout", headers(("Set-Cookie" = CookieJar, description = "Cookie jar cleaned"))),
(status = 200, description = "Logout"),
(status = 404, description = "User or password not found", body = ErrorResponse),
)
)]
Expand Down
5 changes: 2 additions & 3 deletions backend/src/api/admin/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ pub async fn admin_category_update(

#[utoipa::path(
put,
path = "/api/admin/categories/:id/icon",
request_body = Icon,
path = "/api/admin/categories/{id}/icon",
params(
("id" = Uuid, Path, description = "Category identifier")
),
Expand Down Expand Up @@ -145,7 +144,7 @@ pub async fn admin_category_delete(

#[utoipa::path(
delete,
path = "/api/admin/categories/:id/icon",
path = "/api/admin/categories/{id}/icon",
params(
("id" = Uuid, Path, description = "Category identifier")
),
Expand Down
3 changes: 2 additions & 1 deletion backend/src/api/admin/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub struct AdminEntityWithRelations {
pub display_name: String,
pub category_id: Uuid,
pub family_id: Uuid,
#[schema(value_type = Object)]
pub locations: sqlx::types::Json<Vec<UnprocessedLocation>>,
pub data: Value,
pub tags: Vec<Uuid>,
Expand All @@ -63,7 +64,7 @@ pub struct AdminEntityWithRelations {
("page_size" = i64, Query, description = "Number of items per page (default: 20)")
),
responses(
(status = 200, description = "Search results for entities", body = AdminCachedEntitiesWithPagination),
(status = 200, description = "Search results for entities", body = PaginatedVec<AdminCachedEntity>),
(status = 401, description = "Invalid permissions", body = ErrorResponse),
)
)]
Expand Down
5 changes: 2 additions & 3 deletions backend/src/api/admin/families.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ pub async fn admin_family_update(

#[utoipa::path(
put,
path = "/api/admin/families/:id/icon",
request_body = Icon,
path = "/api/admin/families/{id}/icon",
params(
("id" = Uuid, Path, description = "Family identifier")
),
Expand Down Expand Up @@ -165,7 +164,7 @@ pub async fn admin_family_delete(

#[utoipa::path(
delete,
path = "/api/admin/families/:id/icon",
path = "/api/admin/families/{id}/icon",
params(
("id" = Uuid, Path, description = "Family identifier")
),
Expand Down
2 changes: 1 addition & 1 deletion backend/src/api/admin/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub async fn admin_home_stats(
get,
path = "/api/admin/stats/count-comments-entities",
responses(
(status = 200, description = "Dicts of entities and comments counts by family and category id", body = Json<CountResult>),
(status = 200, description = "Dicts of entities and comments counts by family and category id"),
(status = 401, description = "Invalid permissions", body = ErrorResponse),
)
)]
Expand Down
2 changes: 1 addition & 1 deletion backend/src/api/admin/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub async fn admin_users_list(
#[utoipa::path(
post,
path = "/api/admin/users",
request_body = NewUser,
request_body = NewOrUpdatedUser,
responses(
(status = 200, description = "User", body = User),
(status = 401, description = "Invalid permissions", body = ErrorResponse),
Expand Down
2 changes: 1 addition & 1 deletion backend/src/api/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl Display for SearchRequest {
path = "/api/map/search",
request_body = SearchRequest,
responses(
(status = 200, description = "List of entities", body = CachedEntitiesWithPagination),
(status = 200, description = "List of entities", body = PaginatedVec<ViewerSearchedCachedEntity>),
(status = 401, description = "Invalid token", body = ErrorResponse),
)
)]
Expand Down
9 changes: 6 additions & 3 deletions backend/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
AdminUserIdentity, LoginRequest, LoginResponse,
},
map::{
self, FetchedEntity, NewCommentRequest, PublicNewEntityRequest,
self, FetchEntityRequest, FetchedEntity, NewCommentRequest, PublicNewEntityRequest,
PublicNewEntityResponse, SearchRequest as MapSearchRequest, ViewRequest,
},
root::{self, BootstrapResponse, SafeMode, StatusResponse},
Expand All @@ -28,8 +28,8 @@ use crate::{
},
entity_cache::{
AdminCachedEntitiesWithPagination, AdminCachedEntity, Cluster, EntitiesAndClusters,
LocationRepresentation, ParentRepresentation, ViewerCachedEntitiesWithPagination,
ViewerCachedEntity, ViewerSearchedCachedEntity,
LocationRepresentation, PaginatedVec, ParentRepresentation,
ViewerCachedEntitiesWithPagination, ViewerCachedEntity, ViewerSearchedCachedEntity,
},
family::{Family, Field, FieldType, Form, NewOrUpdateFamily},
options::{
Expand Down Expand Up @@ -159,6 +159,8 @@ use utoipa::OpenApi;
PublicEntity,
PublicListedEntity,
PublicNewEntity,
PaginatedVec<ViewerSearchedCachedEntity>,
PaginatedVec<AdminCachedEntity>,
ViewerCachedEntity,
ViewerSearchedCachedEntity,
LocationRepresentation,
Expand Down Expand Up @@ -193,6 +195,7 @@ use utoipa::OpenApi;
MapSearchRequest,
NewCommentRequest,
PublicNewEntityRequest,
FetchEntityRequest,
FetchedEntity,
// helper postgis polygons
MultiPolygon,
Expand Down
5 changes: 1 addition & 4 deletions backend/src/helpers/postgis_polygons.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

pub type Coordinates = (f64, f64);
pub type Polygon = Vec<Coordinates>;

#[derive(Serialize, Deserialize, Debug, Clone, ToSchema)]
pub struct MultiPolygon(Vec<Polygon>);
pub struct MultiPolygon(Vec<Vec<(f64, f64)>>);

impl MultiPolygon {
pub fn to_polygon_string(&self, srid: Option<u32>) -> String {
Expand Down
5 changes: 5 additions & 0 deletions backend/src/models/access_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub struct PermissionPolicy {
pub struct NewOrUpdateAccessToken {
pub title: String,
pub token: String,
#[schema(value_type = Object)]
pub permissions: Json<Permissions>,
pub active: bool,
}
Expand All @@ -64,14 +65,18 @@ pub struct AccessToken {
pub id: Uuid,
pub title: String,
pub token: String,
#[schema(value_type = Object)]
pub permissions: Json<Permissions>,
pub last_week_visits: i64,
pub active: bool,
}

#[derive(Deserialize, Serialize, ToSchema, Debug)]
pub struct AccessTokenStats {
#[schema(value_type = Object)]
pub origins: Json<Value>,

#[schema(value_type = Object)]
pub visits_30_days: Json<Value>,
}

Expand Down
5 changes: 5 additions & 0 deletions backend/src/models/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ pub struct PublicEntity {
pub display_name: String,
pub category_id: Uuid,
pub family_id: Uuid,
#[schema(value_type = Object)]
pub locations: Json<Vec<UnprocessedLocation>>,
pub data: Value,
pub tags: Vec<Uuid>,
#[schema(value_type = Object)]
pub entity_form: Json<Form>,
#[schema(value_type = Object)]
pub comment_form: Json<Form>,
pub created_at: chrono::NaiveDateTime,
pub updated_at: chrono::NaiveDateTime,
Expand Down Expand Up @@ -193,6 +196,7 @@ impl PublicEntity {
pub struct AdminNewOrUpdateEntity {
pub display_name: String,
pub category_id: Uuid,
#[schema(value_type = Object)]
pub locations: Json<Vec<UnprocessedLocation>>,
pub data: Value,
pub tags: Vec<Uuid>,
Expand Down Expand Up @@ -220,6 +224,7 @@ pub struct AdminEntity {
pub display_name: String,
pub category_id: Uuid,
pub family_id: Uuid,
#[schema(value_type = Object)]
pub locations: Json<Vec<UnprocessedLocation>>,
pub data: Value,
pub tags: Vec<Uuid>,
Expand Down
2 changes: 2 additions & 0 deletions backend/src/models/entity_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ impl From<Vec<AdminPaginatedCachedEntity>> for AdminCachedEntitiesWithPagination

#[derive(Deserialize, Serialize, ToSchema, Debug)]
pub struct PaginatedVec<T> {
#[schema(value_type = Object)]
pub entities: Vec<T>,

pub total_results: i64,
pub total_pages: i64,
pub response_current_page: i64,
Expand Down
3 changes: 3 additions & 0 deletions backend/src/models/family.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub struct Field {
/// only for the frontend. For instance, if the field is an enum
/// use it to store possible values. If it is a SingleLineText, specify
/// if it's an email, a phone number, etc...
#[schema(value_type = Object)]
pub field_type_metadata: Option<Value>,

/// Sets if the field is indexed (used in full text search, or constraints search)
Expand Down Expand Up @@ -79,7 +80,9 @@ pub struct Family {
pub id: Uuid,
pub title: String,
pub icon_hash: Option<String>,
#[schema(value_type = Object)]
pub entity_form: Json<Form>,
#[schema(value_type = Object)]
pub comment_form: Json<Form>,
pub sort_order: i32,
pub version: i32,
Expand Down
1 change: 1 addition & 0 deletions backend/src/models/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub struct HomePageStats {
pub total_visits_30_days: i64,
pub total_visits_7_days: i64,

#[schema(value_type = Object)]
pub visits_30_days: Json<Value>,
}

Expand Down
3 changes: 2 additions & 1 deletion frontend/components/AppIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ const iconDict: Record<string, string> = {
addComment: mdi.mdiCommentPlus,
add: mdi.mdiPlus,
delete: mdi.mdiDelete,
save: mdi.mdiUpload,
upload: mdi.mdiUpload,
download: mdi.mdiDownload,
lightDark: mdi.mdiThemeLightDark,
loading: mdi.mdiLoading,
eye: mdi.mdiEye,
Expand Down
3 changes: 2 additions & 1 deletion frontend/components/admin/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ try {
await state.fetchFamilies()
await state.getEntitiesCommentsCounts()
}
catch {
catch (e) {
console.log(e)
// Do nothing
}

Expand Down
48 changes: 31 additions & 17 deletions frontend/components/admin/families/EditForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,37 @@ const props = defineProps<{
onSaveCallback: (editedFormFields: FormField[]) => Promise<{ error: Error | undefined }>
}>()

const edited_form_fields: Ref<FormField[]> = ref(JSON.parse(JSON.stringify(props.originalFormFields))) // deep copy
edited_form_fields.value.sort((field_a, field_b) => field_a.form_weight - field_b.form_weight)
const edited_form_fields: Ref<FormField[]> = ref([])

const page_count = ref(0)
const display_indexes: Ref<Record<string, 'notDisplayed' | number>> = ref({})
const max_display_index = ref(0)

function initOrResetComponent() {
edited_form_fields.value = (JSON.parse(JSON.stringify(props.originalFormFields))) // deep copy
edited_form_fields.value.sort((field_a, field_b) => field_a.form_weight - field_b.form_weight)

page_count.value = (1 + Math.max(0, ...edited_form_fields.value.map(field => field.form_page)))
display_indexes.value = {}
max_display_index.value = 0

// Initialize display_indexes and max_display_index
edited_form_fields.value.forEach((field) => {
if (field.user_facing) {
display_indexes.value[field.key] = field.display_weight
max_display_index.value = Math.max(max_display_index.value, field.display_weight)
}
else {
display_indexes.value[field.key] = 'notDisplayed'
}
})
}

initOrResetComponent()

watch(() => props.originalFormFields, () => {
initOrResetComponent()
})

const processingRequest = ref(false)
const toast = useToast()
Expand Down Expand Up @@ -562,21 +591,6 @@ const editEventsVisible = ref(false)
const editEventsField: Ref<FormField | null> = ref(null)
const editEventsEvents = ref<EventsFieldTypeMetadata['event_types']>([])

const page_count = ref(1 + Math.max(0, ...edited_form_fields.value.map(field => field.form_page)))
const display_indexes: Ref<Record<string, 'notDisplayed' | number>> = ref({})
const max_display_index = ref(0)

// Initialize display_indexes and max_display_index
edited_form_fields.value.forEach((field) => {
if (field.user_facing) {
display_indexes.value[field.key] = field.display_weight
max_display_index.value = Math.max(max_display_index.value, field.display_weight)
}
else {
display_indexes.value[field.key] = 'notDisplayed'
}
})

const searchableTypes = ['SingleLineText', 'MultiLineText', 'RichText']
const filterableTypes = ['EnumSingleOption', 'EnumMultiOption']
const indexableTypes = [...searchableTypes, ...filterableTypes]
Expand Down
Loading