Added trigger functions.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
This commit is contained in:
parent
1428b8984b
commit
245d099f38
@ -4767,7 +4767,8 @@ impl DocumentFile {
|
||||
&mut self,
|
||||
original: &InternalRecords,
|
||||
update: &Update,
|
||||
) -> Result<InternalRecords, MTTError> {
|
||||
msg: &Message,
|
||||
) -> Result<Records, MTTError> {
|
||||
let mut changes: HashMap<Uuid, &CalcValue> = HashMap::new();
|
||||
for (key, value) in update.get_values().iter() {
|
||||
let field_id = match self.docdef.get_field_id(key) {
|
||||
@ -4802,7 +4803,11 @@ impl DocumentFile {
|
||||
}
|
||||
self.docs.insert(oid.clone(), new_rec.clone());
|
||||
}
|
||||
Ok(updates.clone())
|
||||
let recs = Records::with_data(self.docdef.get_field_names().clone(), updates);
|
||||
self.queue
|
||||
.send(msg.response(MsgAction::OnUpdate(recs.clone())))
|
||||
.unwrap();
|
||||
Ok(recs)
|
||||
}
|
||||
|
||||
fn update(&mut self, msg: &Message) {
|
||||
@ -4818,7 +4823,7 @@ impl DocumentFile {
|
||||
return;
|
||||
}
|
||||
};
|
||||
let data = match self.run_update(&original, update) {
|
||||
let data = match self.run_update(&original, update, msg) {
|
||||
Ok(output) => output,
|
||||
Err(err) => {
|
||||
let reply = msg.response(err);
|
||||
@ -4826,11 +4831,7 @@ impl DocumentFile {
|
||||
return;
|
||||
}
|
||||
};
|
||||
let recs = Records::with_data(self.docdef.get_field_names().clone(), data);
|
||||
self.queue.send(msg.response(recs.clone())).unwrap();
|
||||
self.queue
|
||||
.send(msg.response(MsgAction::OnUpdate(recs)))
|
||||
.unwrap();
|
||||
self.queue.send(msg.response(data)).unwrap();
|
||||
}
|
||||
|
||||
fn existing_query(&mut self, msg: &Message, action: &MsgAction) {
|
||||
@ -4840,7 +4841,7 @@ impl DocumentFile {
|
||||
};
|
||||
match action {
|
||||
MsgAction::Update(change) => self
|
||||
.run_update(recs.get_internal_records(), change)
|
||||
.run_update(recs.get_internal_records(), change, msg)
|
||||
.unwrap(),
|
||||
_ => panic!("should not get here"),
|
||||
};
|
||||
@ -6345,13 +6346,12 @@ mod document_files {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn can_query_trigger_reaction() {
|
||||
let mut doc = TestDocument::new([FieldType::Integer].to_vec());
|
||||
let doc_name = doc.get_docdef().get_document_names()[0].clone();
|
||||
let path = Path::new(
|
||||
Include::All,
|
||||
Include::Some(doc_name.into()),
|
||||
Include::Some(doc_name.clone().into()),
|
||||
Include::Some(Action::OnQuery),
|
||||
);
|
||||
let mut update = Update::new(Query::new());
|
||||
@ -6362,7 +6362,14 @@ mod document_files {
|
||||
.get_values_mut()
|
||||
.add_field(Name::english("field0"), calc);
|
||||
let function = DocFuncType::ExistingQuery(update.into());
|
||||
doc.start(standard_paths());
|
||||
doc.get_docdef_mut().add_route(path, function);
|
||||
let mut paths = standard_paths();
|
||||
paths.push(Path::new(
|
||||
Include::All,
|
||||
Include::Some(doc_name.into()),
|
||||
Include::Some(Action::OnUpdate),
|
||||
));
|
||||
doc.start(paths);
|
||||
doc.populate([0.into()].to_vec());
|
||||
for i in 0..5 {
|
||||
let expected: Field = i.try_into().unwrap();
|
||||
@ -6378,6 +6385,17 @@ mod document_files {
|
||||
}
|
||||
_ => unreachable!("got {:?}, should have added entry", action),
|
||||
}
|
||||
let on_update = doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
|
||||
match on_update.get_action() {
|
||||
MsgAction::OnUpdate(recs) => {
|
||||
let expected: Field = (i + 1).into();
|
||||
assert_eq!(recs.len(), 1);
|
||||
for rec in recs.iter() {
|
||||
assert_eq!(rec.get(Name::english("field0")).unwrap(), expected);
|
||||
}
|
||||
}
|
||||
_ => unreachable!("should only be on update"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user