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:
|
||||
'local':
|
||||
'Local':
|
||||
url: 'http://localhost:9000'
|
||||
'Duplicate Local':
|
||||
url: 'http://localhost:9000'
|
||||
|
|
|
@ -186,6 +186,36 @@
|
|||
},
|
||||
"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": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
*/
|
||||
|
||||
use chrono::{DateTime, NaiveDateTime, Utc};
|
||||
use serde::Serialize;
|
||||
use sqlx::sqlite::SqliteQueryResult;
|
||||
use sqlx::{Sqlite, SqlitePool, Transaction};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
pub struct Project {
|
||||
uuid: String,
|
||||
name: String,
|
||||
|
@ -39,6 +40,12 @@ impl Project {
|
|||
.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(
|
||||
project: &Project,
|
||||
tx: &SqlitePool,
|
||||
|
|
|
@ -241,8 +241,12 @@ async fn main() -> Result<(), tide::Error> {
|
|||
*/
|
||||
app.at("/apidocs").serve_dir("apidocs/")?;
|
||||
app.at("/static").serve_dir("static/")?;
|
||||
|
||||
debug!("Configuring routes");
|
||||
app.at("/").get(routes::index);
|
||||
app.at("/project/:name").get(routes::project);
|
||||
|
||||
debug!("Configuring API routes");
|
||||
app.at("/api/v1/projects/:name")
|
||||
.post(routes::api::execute_project);
|
||||
app.listen(opts.listen).await?;
|
||||
|
|
|
@ -15,6 +15,7 @@ pub async fn index(req: Request<AppState<'_>>) -> Result<Body, tide::Error> {
|
|||
"page": "home",
|
||||
"agents" : req.state().agents,
|
||||
"config" : req.state().config,
|
||||
"projects" : crate::dao::Project::list(&req.state().db).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)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
use crate::{AppState, JankyYml, Scm};
|
||||
use log::*;
|
||||
|
|
|
@ -43,16 +43,15 @@
|
|||
<strong>Actions</strong>
|
||||
</td>
|
||||
</thead>
|
||||
{{#each config.projects}}
|
||||
{{#each projects}}
|
||||
<tr>
|
||||
<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>
|
||||
{{this.description}}
|
||||
</td>
|
||||
<td>
|
||||
<form method="POST" action="/api/v1/projects/{{@key}}">
|
||||
<form method="POST" action="/api/v1/projects/{{this.name}}">
|
||||
<input type="submit" value="Execute"/>
|
||||
</form>
|
||||
</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