Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
sparrowzz
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
sgool
sparrowzz
Commits
0cc2662b
Commit
0cc2662b
authored
Oct 24, 2024
by
dongshufeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(iesplan): add parameter query
parent
335f8e46
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
67 行增加
和
10 行删除
+67
-10
mems/examples/iesplan/src/lib.rs
+19
-1
mems/examples/iesplan/src/paracard.rs
+48
-9
没有找到文件。
mems/examples/iesplan/src/lib.rs
查看文件 @
0cc2662b
...
...
@@ -24,9 +24,27 @@ pub struct PointControl3 {
pub
commands
:
Vec
<
SetPointValue
>
,
}
#[derive(Serialize,
Deserialize,
Clone,
Debug)]
pub
struct
QueryWithId
{
pub
id
:
Option
<
u64
>
,
pub
ids
:
Option
<
String
>
,
}
impl
QueryWithId
{
pub
fn
query_str
(
&
self
)
->
String
{
let
mut
query
=
String
::
new
();
if
let
Some
(
id
)
=
self
.id
{
query
.push_str
(
&
format!
(
"?id={}"
,
id
));
}
else
if
let
Some
(
ids
)
=
&
self
.ids
{
query
.push_str
(
&
format!
(
"?ids={ids}"
));
}
query
}
}
#[derive(Clone,
Debug,
PartialEq)]
pub
enum
ParaType
{
// show expresion, true expression, false expression
// show expres
s
ion, true expression, false expression
Checkbox
,
Radio
,
Switch
,
...
...
mems/examples/iesplan/src/paracard.rs
查看文件 @
0cc2662b
...
...
@@ -4,11 +4,12 @@ use web_sys::InputEvent;
use
yew
::
prelude
::
*
;
use
yew_bulma
::
*
;
use
yew_bulma
::
calendar
::
get_timestamp
;
use
eig_domain
::
SetPointValue
;
use
eig_domain
::
{
MeasureValue
,
SetPointValue
}
;
use
eig_expr
::{
Expr
,
Token
};
use
crate
::{
get_headers
,
get_user_id
,
ParaType
,
Parameters
,
PointControl3
};
use
crate
::{
get_headers
,
get_user_id
,
ParaType
,
Parameters
,
PointControl3
,
QueryWithId
};
pub
enum
Msg
{
ParaLoaded
(
Vec
<
MeasureValue
>
),
SetBool
(
usize
,
bool
),
SetString
(
usize
),
SetOption
(
usize
,
String
),
...
...
@@ -22,6 +23,7 @@ pub struct Props {
pub
struct
ParaCard
{
bools
:
HashMap
<
usize
,
bool
>
,
floats
:
HashMap
<
usize
,
f64
>
,
}
impl
Component
for
ParaCard
{
...
...
@@ -30,21 +32,26 @@ impl Component for ParaCard {
fn
create
(
ctx
:
&
Context
<
Self
>
)
->
Self
{
let
mut
bools
=
HashMap
::
new
();
let
mut
floats
=
HashMap
::
new
();
for
index
in
0
..
ctx
.props
()
.paras.points
.len
()
{
let
input_type
=
&
ctx
.props
()
.paras.para_types
[
index
];
if
let
ParaType
::
Checkbox
=
input_type
{
bools
.insert
(
index
,
false
);
}
else
if
let
ParaType
::
Switch
=
input_type
{
bools
.insert
(
index
,
false
);
}
else
if
let
ParaType
::
Radio
=
input_type
{
if
ParaType
::
Checkbox
.eq
(
input_type
)
||
ParaType
::
Switch
.eq
(
input_type
)
||
ParaType
::
Radio
.eq
(
input_type
)
{
bools
.insert
(
index
,
false
);
}
else
{
floats
.insert
(
index
,
0.0
);
}
}
Self
{
bools
}
Self
::
query_para
(
ctx
);
Self
{
bools
,
floats
}
}
fn
update
(
&
mut
self
,
ctx
:
&
Context
<
Self
>
,
msg
:
Self
::
Message
)
->
bool
{
match
msg
{
Msg
::
ParaLoaded
(
values
)
=>
{
}
Msg
::
SetBool
(
i
,
b
)
=>
{
let
point_id
=
&
ctx
.props
()
.paras.points
[
i
];
let
input_type
=
&
ctx
.props
()
.paras.para_types
[
i
];
...
...
@@ -229,6 +236,36 @@ impl ParaCard {
}
impl
ParaCard
{
fn
query_para
(
ctx
:
&
Context
<
Self
>
)
{
let
ids
:
Vec
<
String
>
=
ctx
.props
()
.paras.points
.iter
()
.map
(|
s
|
s
.to_string
())
.collect
();
let
ids
=
ids
.join
(
","
)
.to_string
();
let
query
=
QueryWithId
{
id
:
None
,
ids
:
Some
(
ids
),
};
let
url
=
format!
(
"/api/v1/pscpu/points/values_cbor/0{}"
,
query
.query_str
());
ctx
.link
()
.send_future
(
async
move
{
match
async_ws_get
(
&
url
,
&
get_headers
())
.await
{
Ok
(
bytes
)
=>
{
if
let
Ok
(
values
)
=
serde_cbor
::
from_slice
::
<
Vec
<
MeasureValue
>>
(
&
bytes
)
{
return
Msg
::
ParaLoaded
(
values
);
}
else
{
alert
(
"Fail"
);
}
}
Err
(
err
)
=>
{
if
err
.to_string
()
.eq
(
HEADER_TOKEN_INVALID
)
{
alert
(
&
format!
(
"Invalid header token for url: {url}"
));
}
else
if
err
.to_string
()
.eq
(
HEADER_PERMISSION_DENIED
)
{
alert
(
&
format!
(
"Permission denied for url: {}"
,
url
));
}
else
{
alert
(
&
format!
(
"Failed to load parameter values, err: {:?}"
,
err
));
}
}
}
Msg
::
None
});
}
fn
set_point
(
&
self
,
ctx
:
&
Context
<
Self
>
,
cmd
:
PointControl3
)
{
let
url
=
"/api/v1/controls_cbor/points_by_expr"
;
ctx
.link
()
.send_future
(
async
move
{
...
...
@@ -247,7 +284,9 @@ impl ParaCard {
alert
(
&
format!
(
"Invalid header token for url: {url}"
));
}
else
if
err
.to_string
()
.eq
(
HEADER_PERMISSION_DENIED
)
{
alert
(
&
format!
(
"Permission denied for url: {}"
,
url
));
}
else
{}
}
else
{
alert
(
&
format!
(
"Failed to set parameter value, err: {:?}"
,
err
));
}
}
}
Msg
::
None
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论