83 lines
2.4 KiB
Rust
83 lines
2.4 KiB
Rust
use graphql_client::reqwest::post_graphql;
|
|
use yew::prelude::*;
|
|
|
|
use crate::components;
|
|
use crate::graphql;
|
|
|
|
pub enum Msg {
|
|
StartAssignment,
|
|
StartAssignmentDone(Option<Vec<String>>),
|
|
}
|
|
|
|
#[derive(Properties, PartialEq, Eq)]
|
|
pub struct AssignmentsProps {
|
|
pub token: String,
|
|
}
|
|
|
|
pub struct Assignments {
|
|
errors: Option<Vec<String>>,
|
|
}
|
|
|
|
impl Component for Assignments {
|
|
type Message = Msg;
|
|
type Properties = AssignmentsProps;
|
|
|
|
fn create(_ctx: &Context<Self>) -> Self {
|
|
Self { errors: None }
|
|
}
|
|
|
|
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
|
|
match msg {
|
|
Msg::StartAssignment => {
|
|
let client = graphql::client(Some(&ctx.props().token)).unwrap();
|
|
ctx.link().send_future(async move {
|
|
let response =
|
|
post_graphql::<graphql::mutations::start_assignment::StartAssignment, _>(
|
|
&client,
|
|
graphql::URL.as_str(),
|
|
graphql::mutations::start_assignment::start_assignment::Variables,
|
|
)
|
|
.await
|
|
.unwrap();
|
|
|
|
Msg::StartAssignmentDone(components::graphql_errors::convert(response.errors))
|
|
});
|
|
|
|
false
|
|
}
|
|
Msg::StartAssignmentDone(errors) => {
|
|
self.errors = errors;
|
|
true
|
|
}
|
|
}
|
|
}
|
|
|
|
fn view(&self, ctx: &Context<Self>) -> Html {
|
|
html! {
|
|
<fieldset>
|
|
<legend>{ "Zuweisungen" }</legend>
|
|
<table>
|
|
<tr>
|
|
<th>{ "Aktion" }</th>
|
|
<th>{ "Optionen" }</th>
|
|
</tr>
|
|
<tr>
|
|
<td>{ "Zuweisung starten" }</td>
|
|
<td>
|
|
<ul>
|
|
<li>
|
|
<button onclick={ctx.link().callback(|_| Msg::StartAssignment)}>
|
|
{ "Ausführen" }
|
|
</button>
|
|
</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<components::graphql_errors::GraphQLErrors errors={self.errors.to_owned()} />
|
|
</fieldset>
|
|
}
|
|
}
|
|
}
|