1use rwf::controller::{Engine, StaticFiles};
2use rwf::http::{Handler, Path};
3use rwf::prelude::*;
4
5mod controllers;
6use controllers::*;
7
8mod models;
9
10pub fn routes() -> Result<Vec<Handler>, Error> {
11 Ok(vec![engine!("/admin" => engine()), static_files()?])
12}
13
14pub fn engine() -> Engine {
15 Engine::new(vec![
16 route!("/" => index::Index),
17 route!("/jobs" => jobs::Jobs),
18 route!("/requests" => requests::Requests),
19 route!("/models" => controllers::models::ModelsController),
20 route!("/models/model" => controllers::models::ModelController),
21 route!("/models/new" => controllers::models::NewModelController),
22 ])
23 .remount(&Path::parse("/admin").unwrap())
24}
25
26pub fn install() -> Result<(), Error> {
27 use rwf::view::Templates;
28
29 Templates::cache().preload_str(
30 "templates/rwf_admin/requests.html",
31 include_str!("../templates/rwf_admin/requests.html"),
32 )?;
33 Templates::cache().preload_str(
34 "templates/rwf_admin/model_pages.html",
35 include_str!("../templates/rwf_admin/model_pages.html"),
36 )?;
37 Templates::cache().preload_str(
38 "templates/rwf_admin/jobs.html",
39 include_str!("../templates/rwf_admin/jobs.html"),
40 )?;
41 Templates::cache().preload_str(
42 "templates/rwf_admin/head.html",
43 include_str!("../templates/rwf_admin/head.html"),
44 )?;
45 Templates::cache().preload_str(
46 "templates/rwf_admin/nav.html",
47 include_str!("../templates/rwf_admin/nav.html"),
48 )?;
49 Templates::cache().preload_str(
50 "templates/rwf_admin/model.html",
51 include_str!("../templates/rwf_admin/model.html"),
52 )?;
53 Templates::cache().preload_str(
54 "templates/rwf_admin/model_new.html",
55 include_str!("../templates/rwf_admin/model_new.html"),
56 )?;
57 Templates::cache().preload_str(
58 "templates/rwf_admin/reload.html",
59 include_str!("../templates/rwf_admin/reload.html"),
60 )?;
61 Templates::cache().preload_str(
62 "templates/rwf_admin/models.html",
63 include_str!("../templates/rwf_admin/models.html"),
64 )?;
65 Templates::cache().preload_str(
66 "templates/rwf_admin/footer.html",
67 include_str!("../templates/rwf_admin/footer.html"),
68 )?;
69
70 Ok(())
71}
72
73pub fn static_files() -> Result<Handler, Error> {
74 let static_files = StaticFiles::new("static")?.prefix("static/rwf_admin");
75 let static_files = static_files
76 .preload(
77 "/static/rwf_admin/images/logo.svg",
78 include_bytes!("../static/rwf_admin/images/logo.svg"),
79 )
80 .preload(
81 "/static/rwf_admin/js/bootstrap.min.js",
82 include_bytes!("../static/rwf_admin/js/bootstrap.min.js"),
83 )
84 .preload(
85 "/static/rwf_admin/js/reload_controller.js",
86 include_bytes!("../static/rwf_admin/js/reload_controller.js"),
87 )
88 .preload(
89 "/static/rwf_admin/js/requests_controller.js",
90 include_bytes!("../static/rwf_admin/js/requests_controller.js"),
91 )
92 .preload(
93 "/static/rwf_admin/js/bootstrap.min.js.map",
94 include_bytes!("../static/rwf_admin/js/bootstrap.min.js.map"),
95 )
96 .preload(
97 "/static/rwf_admin/css/bootstrap.min.css.map",
98 include_bytes!("../static/rwf_admin/css/bootstrap.min.css.map"),
99 )
100 .preload(
101 "/static/rwf_admin/css/bootstrap.min.css",
102 include_bytes!("../static/rwf_admin/css/bootstrap.min.css"),
103 );
104
105 Ok(static_files.handler())
106}