Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc183d04

Browse files
DataField
1 parent3fe5afd commitc183d04

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

‎src/controls/prelude.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ pub use crate::controls::{
2222
token_selector::TokenSelector,
2323
};
2424
pubusecrate::form::{FormData,FormDataValue,FormHandler};
25+
pubusecrate::DataField;
2526
pubtypeUXResult<T> = workflow_ux::result::Result<T>;

‎src/data_field.rs‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
usecrate::prelude::*;
2+
usecrate::result::Result;
3+
4+
#[derive(Clone)]
5+
pubstructDataField<T:Clone>{
6+
data:Arc<Mutex<Option<T>>>
7+
}
8+
9+
impl<T:Clone>DataField<T>{
10+
pubfnnew(_:&ElementLayout, _:&Attributes, _:&Docs) ->Result<Self>{
11+
Ok(Self{
12+
data:Arc::new(Mutex::new(None))
13+
})
14+
}
15+
pubfnvalue(&self)->Result<Option<T>>{
16+
Ok(self.data.lock()?.clone())
17+
}
18+
19+
pubfnset_value(&self,data:Option<T>)->Result<()>{
20+
*self.data.lock()? = data;
21+
Ok(())
22+
}
23+
}

‎src/form.rs‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ use crate::{
1212
error,
1313
form_footer::FormFooter,
1414
layout::{ElementLayout,ElementLayoutStyle,Elemental},
15-
prelude::i18n,
15+
prelude::{i18n,CallbackFn},
1616
result::Result,
17+
error::Error,
1718
//view::Layout,
1819
//document,
1920
//module::ModuleInterface
@@ -188,6 +189,7 @@ pub struct FormStages {
188189
pubstages:Arc<Mutex<Vec<Arc<dynFormStage>>>>,
189190
pubdata:Arc<Mutex<FormData>>,
190191
pubtitle:Arc<Mutex<String>>,
192+
error_cb:Arc<Mutex<Option<CallbackFn<Error>>>>,
191193
}
192194

193195
unsafeimplSendforFormStages{}
@@ -203,14 +205,15 @@ impl FormStages {
203205
let layout =ElementLayout::new(parent_layout, layout_style, attributes)?;
204206
let title = attributes
205207
.get("title")
206-
.unwrap_or(&"Step [INDEX]".to_string())
208+
.unwrap_or(&"Step [INDEX]/[STEPS]".to_string())
207209
.clone();
208210
let layout =FormStages{
209211
layout,
210212
title:Arc::new(Mutex::new(title)),
211213
index:Arc::new(Mutex::new(0)),
212214
stages:Arc::new(Mutex::new(Vec::new())),
213215
data:Arc::new(Mutex::new(FormData::new(None))),
216+
error_cb:Arc::new(Mutex::new(None)),
214217
};
215218

216219
Ok(layout)
@@ -360,11 +363,24 @@ impl FormStages {
360363
ifletSome(el) =self.layout.element().query_selector(".layout-title")?{
361364
let title = title
362365
.as_ref()
363-
.replace("[INDEX]",&format!("{}",self.index()? +1));
366+
.replace("[INDEX]",&format!("{}",self.index()? +1))
367+
.replace("[STEPS]",&format!("{}",self.len()?));
364368
el.set_inner_html(&title)
365369
}
366370
Ok(())
367371
}
372+
373+
pubfnon_error(&self,callback:CallbackFn<Error>){
374+
*self.error_cb.lock().unwrap() =Some(callback);
375+
}
376+
377+
pubfnshow_error(&self,error:Error)->Result<()>{
378+
ifletSome(cb) =self.error_cb.lock()?.as_mut(){
379+
cb(error)?;
380+
}
381+
382+
Ok(())
383+
}
368384
}
369385

370386
implElementalforFormStages{

‎src/lib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ pub mod style;
4141
pubmod task;
4242
pubmod user_agent;
4343
pubuse workflow_async_trait::{async_trait, async_trait_with_send, async_trait_without_send};
44+
pubmod data_field;
45+
pubuse data_field::DataField;
4446

4547
/// dynamically configured re-export of async_trait as workflow_async_trait
4648
/// that imposes `Send` restriction in native (non-WASM) and removes `Send`

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp