1
0
Fork 0

Display reports

This commit is contained in:
Alex Kotov 2020-10-22 10:15:58 +05:00
parent 1243d19e55
commit ff780d8d4d
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
14 changed files with 73 additions and 3 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,7 +1,9 @@
mod donation_crypto_address;
mod employee;
mod report;
mod user;
pub use self::donation_crypto_address::*;
pub use self::employee::*;
pub use self::report::*;
pub use self::user::*;

20
src/models/report.rs Normal file
View File

@ -0,0 +1,20 @@
use crate::database::DbConn;
use crate::schema::reports;
use diesel::prelude::*;
#[derive(Debug, Identifiable, Serialize, Queryable)]
pub struct Report {
pub id: i32,
pub datetime: std::time::SystemTime,
pub party: String,
pub amount: String,
pub download: String,
}
impl Report {
pub fn all(db_conn: DbConn) -> Result<Vec<Self>, diesel::result::Error> {
reports::table.load::<Self>(&*db_conn)
}
}

View File

@ -1,5 +1,5 @@
use crate::database;
// use crate::models;
use crate::models;
use crate::states;
use crate::views;
@ -13,13 +13,19 @@ use rocket_csrf::CsrfToken;
#[get("/reports")]
pub fn index(
_i18n: State<I18n>,
_db_conn: database::DbConn,
db_conn: database::DbConn,
csrf_token: CsrfToken,
current_user: states::MaybeCurrentUser,
) -> Result<Template, CommonResponse> {
let reports = models::Report::all(db_conn)?;
let page_context = views::reports::Index {
reports,
};
let context = views::Site {
page: "reports/index".to_string(),
page_context: (),
page_context,
authenticity_token: csrf_token.authenticity_token().to_string(),
current_user: current_user.0,
};

View File

@ -32,6 +32,15 @@ pub mod home {
}
}
pub mod reports {
use crate::models;
#[derive(Serialize)]
pub struct Index {
pub reports: Vec<models::Report>,
}
}
pub mod sessions {
#[derive(Serialize)]
pub struct New {

View File

@ -0,0 +1,33 @@
<div class="container mt-4">
<h1>Reports</h1>
<table class="table table-striped mt-3">
<thead>
<tr>
<th scope="col">
Year, month
</th>
<th scope="col">
Seller/source
</th>
<th scope="col">
Amount
</th>
<th scope="col">
Download
</th>
</tr>
</thead>
<tbody>
{{#each reports}}
<tr>
<td>{{ this.datetime }}</td>
<td>{{ this.party }}</td>
<td>{{ this.amount }}</td>
<td><a href="{{ this.download }}">PDF</a></td>
</tr>
{{/each}}
</tbody>
</table>
</div>