Render projects from the database and starting in on the Project page
This commit is contained in:
parent
641c774788
commit
81451f888c
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
agents:
|
agents:
|
||||||
'local':
|
'Local':
|
||||||
url: 'http://localhost:9000'
|
url: 'http://localhost:9000'
|
||||||
'Duplicate Local':
|
'Duplicate Local':
|
||||||
url: 'http://localhost:9000'
|
url: 'http://localhost:9000'
|
||||||
|
|
|
@ -186,6 +186,36 @@
|
||||||
},
|
},
|
||||||
"query": "SELECT * FROM scm_info WHERE uuid = ?"
|
"query": "SELECT * FROM scm_info WHERE uuid = ?"
|
||||||
},
|
},
|
||||||
|
"8482da66fb4c815cf21576e0b5c8121f5cb3a96b0a3f5e8241dbd677860c62af": {
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "uuid",
|
||||||
|
"ordinal": 0,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "name",
|
||||||
|
"ordinal": 1,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "created_at",
|
||||||
|
"ordinal": 2,
|
||||||
|
"type_info": "Datetime"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nullable": [
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"query": "SELECT * FROM projects"
|
||||||
|
},
|
||||||
"980b3cb885d26d06b4178df215617e26aecd79f4d813df14770ec8ae540d0ce2": {
|
"980b3cb885d26d06b4178df215617e26aecd79f4d813df14770ec8ae540d0ce2": {
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
|
|
|
@ -3,11 +3,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use chrono::{DateTime, NaiveDateTime, Utc};
|
use chrono::{DateTime, NaiveDateTime, Utc};
|
||||||
|
use serde::Serialize;
|
||||||
use sqlx::sqlite::SqliteQueryResult;
|
use sqlx::sqlite::SqliteQueryResult;
|
||||||
use sqlx::{Sqlite, SqlitePool, Transaction};
|
use sqlx::{Sqlite, SqlitePool, Transaction};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, Serialize)]
|
||||||
pub struct Project {
|
pub struct Project {
|
||||||
uuid: String,
|
uuid: String,
|
||||||
name: String,
|
name: String,
|
||||||
|
@ -39,6 +40,12 @@ impl Project {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn list(pool: &SqlitePool) -> Result<Vec<Project>, sqlx::Error> {
|
||||||
|
sqlx::query_as!(Project, "SELECT * FROM projects")
|
||||||
|
.fetch_all(pool)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
project: &Project,
|
project: &Project,
|
||||||
tx: &SqlitePool,
|
tx: &SqlitePool,
|
||||||
|
|
|
@ -241,8 +241,12 @@ async fn main() -> Result<(), tide::Error> {
|
||||||
*/
|
*/
|
||||||
app.at("/apidocs").serve_dir("apidocs/")?;
|
app.at("/apidocs").serve_dir("apidocs/")?;
|
||||||
app.at("/static").serve_dir("static/")?;
|
app.at("/static").serve_dir("static/")?;
|
||||||
|
|
||||||
debug!("Configuring routes");
|
debug!("Configuring routes");
|
||||||
app.at("/").get(routes::index);
|
app.at("/").get(routes::index);
|
||||||
|
app.at("/project/:name").get(routes::project);
|
||||||
|
|
||||||
|
debug!("Configuring API routes");
|
||||||
app.at("/api/v1/projects/:name")
|
app.at("/api/v1/projects/:name")
|
||||||
.post(routes::api::execute_project);
|
.post(routes::api::execute_project);
|
||||||
app.listen(opts.listen).await?;
|
app.listen(opts.listen).await?;
|
||||||
|
|
|
@ -15,6 +15,7 @@ pub async fn index(req: Request<AppState<'_>>) -> Result<Body, tide::Error> {
|
||||||
"page": "home",
|
"page": "home",
|
||||||
"agents" : req.state().agents,
|
"agents" : req.state().agents,
|
||||||
"config" : req.state().config,
|
"config" : req.state().config,
|
||||||
|
"projects" : crate::dao::Project::list(&req.state().db).await?,
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut body = req.state().render("index", ¶ms).await?;
|
let mut body = req.state().render("index", ¶ms).await?;
|
||||||
|
@ -22,6 +23,20 @@ pub async fn index(req: Request<AppState<'_>>) -> Result<Body, tide::Error> {
|
||||||
Ok(body)
|
Ok(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /project/:name
|
||||||
|
*/
|
||||||
|
pub async fn project(req: Request<AppState<'_>>) -> Result<Body, tide::Error> {
|
||||||
|
let name: String = req.param("name")?.into();
|
||||||
|
let params = json!({
|
||||||
|
"name" : name,
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut body = req.state().render("project", ¶ms).await?;
|
||||||
|
body.set_mime("text/html");
|
||||||
|
Ok(body)
|
||||||
|
}
|
||||||
|
|
||||||
pub mod api {
|
pub mod api {
|
||||||
use crate::{AppState, JankyYml, Scm};
|
use crate::{AppState, JankyYml, Scm};
|
||||||
use log::*;
|
use log::*;
|
||||||
|
|
|
@ -43,16 +43,15 @@
|
||||||
<strong>Actions</strong>
|
<strong>Actions</strong>
|
||||||
</td>
|
</td>
|
||||||
</thead>
|
</thead>
|
||||||
{{#each config.projects}}
|
{{#each projects}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<a class="text-reset" href="/projects/{{@key}}"><strong>{{@key}}</strong></a>
|
<a class="text-reset" href="/project/{{this.name}}"><strong>{{this.name}}</strong></a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{this.description}}
|
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<form method="POST" action="/api/v1/projects/{{@key}}">
|
<form method="POST" action="/api/v1/projects/{{this.name}}">
|
||||||
<input type="submit" value="Execute"/>
|
<input type="submit" value="Execute"/>
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>Janky - {{name}}</title>
|
||||||
|
<link type="text/css" rel="stylesheet" href="/static/bootstrap.min.css"/>
|
||||||
|
<script src="/static/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body class="text-center">
|
||||||
|
{{> _navbar }}
|
||||||
|
|
||||||
|
<div class="cover-container d-flex h-100 p-3 mx-auto flex-column">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col col-sm-2">
|
||||||
|
Links go here
|
||||||
|
</div>
|
||||||
|
<div class="col col-lg">
|
||||||
|
<main role="main" class="inner cover"> <div id="projects">
|
||||||
|
Runs go here
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue