Skip to content

Commit

Permalink
Refine the exposure wizard to include profiles
Browse files Browse the repository at this point in the history
- The underlying API should include all relevant data to generate the UI
  needed to set up an exposure.
- API backend for listing for profiles.
  • Loading branch information
metatoaster committed Jan 10, 2025
1 parent 632ca64 commit f4ca290
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 16 deletions.
35 changes: 28 additions & 7 deletions pmrapp/src/exposure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::{
list,
get_exposure_info,
resolve_exposure_path,
wizard,
ExposureInfo,
},
view::{
Expand Down Expand Up @@ -382,17 +383,37 @@ pub fn ExposureFile() -> impl IntoView {

#[component]
pub fn Wizard() -> impl IntoView {
let wizard_view = move || Suspend::new(async move {
view! {
// render content
<h1>"Wizard"</h1>
// <ActionForm action=action>
// <button type="submit">"Build"</button>
// </ActionForm>
let params = use_params::<ExposureParams>();
let wizard_res = Resource::new_blocking(
move || params.get().map(|p| p.id),
|p| async move {
match p {
Err(_) => Err(AppError::InternalServerError),
Ok(Some(id)) => wizard(id)
.await
.map(EnforcedOk::notify_into)
.map_err(AppError::from),
_ => Err(AppError::NotFound),
}
}
);

let wizard_view = move || Suspend::new(async move {
wizard_res.await.map(|info| {
let unassigned_files = info.files.iter()
.filter_map(|(name, status)| status.is_none().then_some(name.as_str()))
.collect::<Vec<_>>();
let files = unassigned_files.iter()
.map(|name| view! { <li>{name.to_string()}</li>} )
.collect_view();
view! {
<ul>{files}</ul>
}
})
});

view! {
<h1>"Exposure Wizard"</h1>
<Transition>
{wizard_view}
</Transition>
Expand Down
22 changes: 18 additions & 4 deletions pmrapp/src/exposure/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ use pmrcore::{
exposure::{
Exposure,
Exposures,
profile::ExposureFileProfile,
},
profile::{
Profile,
UserPromptGroups,
},
profile::UserPromptGroups,
task_template::UserArgs,
workspace::Workspace,
};
Expand Down Expand Up @@ -252,7 +256,8 @@ pub async fn create_exposure(
#[derive(Clone, Serialize, Deserialize)]
pub struct WizardInfo {
pub exposure: Exposure,
pub files: Vec<(String, Option<(UserPromptGroups, UserArgs)>)>,
pub files: Vec<(String, Option<(ExposureFileProfile, UserPromptGroups)>)>,
pub profiles: Vec<Profile>,
}

#[server]
Expand All @@ -263,16 +268,25 @@ pub async fn wizard(
let platform = platform().await?;
let ctrl = platform.get_exposure(id).await
.map_err(|_| AppError::InternalServerError)?;
let prompts = ctrl.list_files_prompts().await
let prompts = ctrl.list_files_profile_prompt_groups().await
.map_err(|_| AppError::InternalServerError)?;
let profiles = platform.list_profiles().await
.map_err(|_| AppError::InternalServerError)?;

let exposure = ctrl.exposure().clone_inner();
let files = prompts.into_iter()
.map(|(path, value)| (path.to_owned(), value.map(|(upg, ua)| (upg.to_owned(), ua.to_owned()))))
.map(|(path, value)| (
path.to_owned(),
value.map(|(profile, upg)| (
profile,
upg.to_owned(),
))
))
.collect::<Vec<_>>();

Ok(policy_state.to_enforced_ok(WizardInfo {
exposure,
files,
profiles,
}))
}
2 changes: 2 additions & 0 deletions pmrcore/src/exposure/profile.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use serde::{Serialize, Deserialize};
use crate::task_template::UserInputMap;

#[derive(Clone, Serialize, Deserialize)]
pub struct ExposureFileProfile {
pub id: i64,
pub exposure_file_id: i64,
Expand Down
4 changes: 3 additions & 1 deletion pmrcore/src/profile/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ pub trait ProfileBackend {
&self,
id: i64,
) -> Result<Profile, BackendError>;
// TODO listing/query for set of profiles.
async fn list_profiles(
&self,
) -> Result<Vec<Profile>, BackendError>;
// This may be implemented at the backends for the linked types.
}

Expand Down
10 changes: 7 additions & 3 deletions pmrctrl/src/handle/exposure/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use parking_lot::{
};
use pmrcore::{
exposure::{
profile::ExposureFileProfile,
traits::{
Exposure,
ExposureFile,
Expand Down Expand Up @@ -372,16 +373,19 @@ impl<'p> ExposureCtrl<'p> {
})
}

pub async fn list_files_prompts(
pub async fn list_files_profile_prompt_groups(
&'p self,
) -> Result<Vec<(&'p str, Option<(UserPromptGroupRefs<'p>, UserArgRefs<'p>)>)>, PlatformError> {
) -> Result<
Vec<(&'p str, Option<(ExposureFileProfile, UserPromptGroupRefs<'p>)>)>,
PlatformError
> {
let efvttsc = self.list_files_efvttcs().await?;
let mut result = Vec::new();
for (path, value) in efvttsc.iter() {
let item = if let Some(efvttsc) = value {
Some((
efvttsc.exposure_file_ctrl().profile().await?,
efvttsc.create_user_prompt_groups()?,
efvttsc.create_user_arg_refs()?,
))
} else {
None
Expand Down
11 changes: 11 additions & 0 deletions pmrctrl/src/handle/exposure_file/impls.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use futures::future;
use pmrcore::{
exposure::{
profile::{
traits::ExposureFileProfileBackend,
ExposureFileProfile,
},
task::traits::ExposureTaskTemplateBackend,
traits::{
Exposure as _,
Expand Down Expand Up @@ -224,6 +228,13 @@ impl<'p> ExposureFileCtrl<'p> {
Ok(results)
}

pub async fn profile(&self) -> Result<ExposureFileProfile, PlatformError> {
Ok(ExposureFileProfileBackend::get_ef_profile(
self.0.platform.mc_platform.as_ref(),
self.0.exposure_file.id(),
).await?)
}

pub fn pathinfo(&self) -> &GitHandleResult<'p> {
&self.0.pathinfo
}
Expand Down
4 changes: 4 additions & 0 deletions pmrctrl/src/handle/view_task_template/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ impl<'p> EFViewTaskTemplatesCtrl<'p> {
.collect::<Result<Vec<_>, BuildArgErrors>>()?;
Ok(tasks)
}

pub fn exposure_file_ctrl(&'p self) -> ExposureFileCtrl<'p> {
self.exposure_file_ctrl.clone()
}
}

impl<'p> EFViewTaskTemplateCtrl<'p> {
Expand Down
14 changes: 13 additions & 1 deletion pmrctrl/src/platform/impls/profile.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use futures::future;
use pmrcore::{
profile::{
Profile,
ViewTaskTemplateProfile,
traits::ViewTaskTemplateProfileBackend,
traits::{
ProfileBackend,
ViewTaskTemplateProfileBackend,
},
},
task_template::traits::TaskTemplateBackend,
};
Expand All @@ -12,6 +16,14 @@ use crate::{
};

impl Platform {
pub async fn list_profiles(
&self,
) -> Result<Vec<Profile>, PlatformError> {
Ok(ProfileBackend::list_profiles(
self.mc_platform.as_ref(),
).await?)
}

pub async fn create_view_profile(
&self,
) -> Result<(), PlatformError> {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions pmrmodel/src/model/db/sqlite/profile/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,28 @@ WHERE id = ?1
Ok(result)
}

async fn list_profiles_sqlite(
sqlite: &SqliteBackend,
) -> Result<Vec<Profile>, BackendError> {
let result = sqlx::query!(
r#"
SELECT
id,
title,
description
FROM profile
"#,
)
.map(|row| Profile {
id: row.id,
title: row.title,
description: row.description,
})
.fetch_all(&*sqlite.pool)
.await?;
Ok(result)
}

#[async_trait]
impl ProfileBackend for SqliteBackend {
async fn insert_profile(
Expand All @@ -105,6 +127,11 @@ impl ProfileBackend for SqliteBackend {
) -> Result<Profile, BackendError> {
select_profile_by_id_sqlite(&self, id).await
}
async fn list_profiles(
&self,
) -> Result<Vec<Profile>, BackendError> {
list_profiles_sqlite(&self).await
}
}

#[cfg(test)]
Expand Down
3 changes: 3 additions & 0 deletions testing/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ mock! {
&self,
id: i64,
) -> Result<Profile, BackendError>;
async fn list_profiles(
&self,
) -> Result<Vec<Profile>, BackendError>;
// TODO listing/query for set of profiles.
// This may be implemented at the backends for the linked types.
}
Expand Down

0 comments on commit f4ca290

Please sign in to comment.