Support trunk selection in frontend

This commit is contained in:
2026-04-01 17:38:41 +08:00
parent 03d60266cd
commit e6a7a40ea3

View File

@@ -12,7 +12,8 @@ pub struct Did {
did_number: String,
target_type: String,
target: Option<String>,
active: bool
active: bool,
trunk: String,
}
#[derive(Properties, PartialEq)]
@@ -22,6 +23,7 @@ pub struct DidProps {
pub target_type: String,
pub target: String,
pub active: bool,
pub trunk: String,
pub on_changed: Callback<()>
}
@@ -33,6 +35,7 @@ pub fn DidComponent(props: &DidProps) -> Html {
let target_type = use_state(||props.target_type.clone());
let target = use_state(||props.target.clone());
let active= use_state(||props.active);
let trunk= use_state(||props.trunk.clone());
let on_changed = props.on_changed.clone();
let dialog_ref: NodeRef = use_node_ref();
@@ -87,10 +90,21 @@ pub fn DidComponent(props: &DidProps) -> Html {
.unwrap();
target_type.set(t.value());
changed.set(true);
gloo_console::log!(t.value());
}
)};
let handle_trunk_change = {
let trunk = trunk.clone();
let changed = changed.clone();
Callback::from(move |event: Event| {
let t = event
.target()
.and_then(|t| t.dyn_into::<HtmlSelectElement>().ok())
.unwrap();
trunk.set(t.value());
changed.set(true);
}
)};
let handle_save = {
let changed = changed.clone();
let did_number = did_number.clone();
@@ -106,7 +120,8 @@ pub fn DidComponent(props: &DidProps) -> Html {
did_number: (*did_number).clone(),
target_type: (*target_type).clone(),
target: Some((*target).clone()),
active: (*active).clone()
active: (*active).clone(),
trunk: (*trunk).clone(),
};
let url = if id == 0 {
API_BASE.to_string()
@@ -187,6 +202,15 @@ pub fn DidComponent(props: &DidProps) -> Html {
oninput={handle_target_input.clone()}
/>
</td>
<td>
<select class="select select-ghost" onchange={handle_trunk_change}>
<option selected={props.trunk == "3229"}>{"3229"}</option>
<option selected={props.trunk == "3401"}>{"3401"}</option>
<option selected={props.trunk == "413"}>{"413"}</option>
<option selected={props.trunk == "435"}>{"435"}</option>
</select>
</td>
<td>
<input type="checkbox"
checked={*active}
@@ -272,6 +296,7 @@ pub fn DidListComponent() -> Html {
target_type={"NoService"}
target={""}
active=true
trunk="3229"
on_changed={handle_change.clone()}
/>
</table>
@@ -282,6 +307,7 @@ pub fn DidListComponent() -> Html {
<th>{"DID number"}</th>
<th>{"Target type"}</th>
<th>{"Target"}</th>
<th>{"Trunk"}</th>
<th>{"Active"}</th>
<th></th>
</tr>
@@ -296,6 +322,7 @@ pub fn DidListComponent() -> Html {
target_type={d.target_type.clone()}
target={d.target.clone().unwrap_or_default()}
active ={d.active}
trunk = {d.trunk.clone()}
on_changed={handle_change.clone()}
/>
}