Skip to content

Commit

Permalink
wip: convert templates to pure crystal data
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-aires committed Apr 12, 2022
1 parent 96ca90b commit bc295ce
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 158 deletions.
Binary file modified dist/ecmo-linux-x64.bin
Binary file not shown.
12 changes: 6 additions & 6 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ shards:

ameba:
git: https://github.com/veelenga/ameba.git
version: 0.14.3
version: 1.0.0

baked_file_system:
git: https://github.com/schovi/baked_file_system.git
version: 0.10.0

crikey:
git: https://github.com/abidon/crikey.git
version: 0.1.0+git.commit.f019441940648bbee7895a258fdd14c68f316f89

cron_parser:
git: https://github.com/kostya/cron_parser.git
version: 0.4.0
Expand Down Expand Up @@ -48,17 +52,13 @@ shards:
git: https://github.com/gabriel-aires/psutil.cr.git
version: 0.2.2

slang:
git: https://github.com/jeromegn/slang.git
version: 1.7.3

sqlite3:
git: https://github.com/crystal-lang/crystal-sqlite3.git
version: 0.18.0

ssh2:
git: https://github.com/spider-gazelle/ssh2.cr.git
version: 1.5.2
version: 1.5.3

tasker:
git: https://github.com/spider-gazelle/tasker.git
Expand Down
17 changes: 3 additions & 14 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: ecmo
version: 0.9
version: 0.11

authors:
- Gabriel Aires <[email protected]>
Expand All @@ -10,37 +10,26 @@ description: |
dependencies:
granite:
github: amberframework/granite
version: ~> 0.23
kilt:
github: jeromegn/kilt
version: ~> 0.6
slang:
github: jeromegn/slang
version: ~> 1.7
crikey:
github: abidon/crikey
action-controller:
github: spider-gazelle/action-controller
version: ~> 4.0
tasker:
github: spider-gazelle/tasker
version: ~> 2.0
ssh2:
github: spider-gazelle/ssh2.cr
version: ~> 1.5
sqlite3:
github: crystal-lang/crystal-sqlite3
version: ~> 0.18
future:
github: crystal-community/future.cr
version: ~> 1.0
baked_file_system:
github: schovi/baked_file_system
version: ~> 0.10
hardware:
github: gabriel-aires/hardware
version: ~> 0.5
psutil:
github: gabriel-aires/psutil.cr
version: ~> 0.2

development_dependencies:
ameba:
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/metrics.cr
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ class Metrics < Application
{ download: n.map(&.received_mb), upload: n.map(&.sent_mb), time: t }
when "disk"
usage = Hash(String, Array(Int64) | Array(Float64)).new
dk = Disk.all("JOIN partition p on p.id = disk.partition_id ORDER BY disk.seconds ASC")
Partition.all.each do |p|
d = p.disk.all
d = dk.select { |disk| disk.partition.mountpoint == p.mountpoint }
usage["#{p.mountpoint}_time" ] = d.map &.seconds
usage["#{p.mountpoint}_total"] = d.map &.size_mb
usage["#{p.mountpoint}_used" ] = d.map &.used_mb
Expand Down
14 changes: 7 additions & 7 deletions src/models/load.cr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class Load < Granite::Base
connection embedded
table load
connection embedded
table load

column id : Int64, primary: true
column seconds : Int64
column load1 : Float64
column load5 : Float64
column load15 : Float64
column id : Int64, primary: true
column seconds : Int64
column load1 : Float64
column load5 : Float64
column load15 : Float64
end
14 changes: 7 additions & 7 deletions src/models/memory.cr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class Memory < Granite::Base
connection embedded
table memory
connection embedded
table memory

column id : Int64, primary: true
column seconds : Int64
column total_mb : Float64
column used_mb : Float64
column free_mb : Float64
column id : Int64, primary: true
column seconds : Int64
column total_mb : Float64
column used_mb : Float64
column free_mb : Float64
end
16 changes: 8 additions & 8 deletions src/models/net.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class Net < Granite::Base
connection embedded
table net
connection embedded
table net

column id : Int64, primary: true
column seconds : Int64
column received_mb : Float64
column sent_mb : Float64
column received_packets : Int64
column sent_packets : Int64
column id : Int64, primary: true
column seconds : Int64
column received_mb : Float64
column sent_mb : Float64
column received_packets : Int64
column sent_packets : Int64
end
2 changes: 1 addition & 1 deletion src/models/partition.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Partition < Granite::Base
connection embedded
table partition
has_many :disk
has_many disks : Disk

column id : Int64, primary: true
column mountpoint : String
Expand Down
25 changes: 25 additions & 0 deletions src/views/backup.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[
[:h4, "Database details"],
[:table,
[:thead,
[:tr,
[:th, "Size"],
[:th, "File"]]],
[:tbody,
du_output.split("\n").map do |line|
[:tr,
line.split("\t").map do |field|
[:td, field]
end
]
end
]
],

[:p, "Perform backup?"],

[:form, {method: "post", action: Jobs.bkp_db},
[:p,
[:a, {class: "btn #{tone}", href: Jobs.index}, "Cancel"]],
[:p,
[:input, {class: "btn solid #{tone}", type: "submit", value: "Start"}]]]]
20 changes: 0 additions & 20 deletions src/views/backup.slang

This file was deleted.

6 changes: 2 additions & 4 deletions src/views/jobs.slang
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ h4 Scheduled Jobs
tr
th Definition
td
code
pre= File.read(job.path)
pre= File.read(job.path)
tr
th Version
td= job.rev
Expand Down Expand Up @@ -47,8 +46,7 @@ h4 On-Demand Jobs
tr
th Definition
td
code
pre= File.read(job.path)
pre= File.read(job.path)
tr
th Version
td= job.rev
Expand Down
112 changes: 112 additions & 0 deletions src/views/layout.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
[
%|<!doctype html>|,
[:html {lang: "en"},

[:head,
[:title, "Ecmo"],
[:meta, {charset: "UTF-8"}],
[:link, {rel: "icon", href: Assets.show(id: "activity.svg")}],
[:link, {rel: "stylesheet", href: Assets.show(id: "gralig.min.css")}],
[:link, {rel: "stylesheet", href: Assets.show(id: "ecmo.css")}],
[:script, {src: Assets.show(id: "dygraph.min.js")}],
[:script, {src: Assets.show(id: "htmx.min.js")}],
[:style,
<<-CSS
pre {
color: black;
background: rgb(245, 242, 240) none repeat scroll 0% 0%;
text-shadow: white 0px 1px;
font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
overflow-wrap: normal;
line-height: 1.5;
tab-size: 4;
hyphens: none;
padding: 1em;
margin: 0.5em;
overflow: auto;
}
.dark pre {
background : black;
color: rgb(245, 242, 240);
text-shadow: black 0px 1px;
}
CSS
]]

[:body,

[:header, {class: "gra-navbar dark"},
[:div, {class: "gra-container gra-bold-text"},
[:div, {class: "gra-navbar-logo"},
[:a, {class: "gra-navbar-logo-link gra-pd-left-l", href: Home.index},
Storage.read("assets/activity.svg"),
[:span, " " + App::NAME]]],

[:div, {class: "gra-navbar-content"},
[:nav,
[:ul, {class: "gra-nav"},
[:li, {class: "gra-nav-item"},
[:a, {class: "gra-nav-link", href: "#"},
[:div, {class: "user-text"},
"#{current_user.not_nil!.name}/#{current_user.not_nil!.type}",
[:div, {class: "user-icon"}, Storage.read("assets/user.svg")]]]],

[:li, {class: "gra-nav-item"},
[:a, {class: "gra-nav-link", "hx-delete": Sessions.destroy(id: "close"), "hx-target": "body"},
[:div, {class: "logoff-text"}, "Logout"],
[:div, {class: "logoff-icon"}, Storage.read("assets/power.svg")]]],

[:li, {class: "gra-nav-item"},
[:a, {class: "gra-nav-link", onclick: "toggleTheme();"},
[:div, {class: "sun"}, Storage.read("assets/sun.svg")],
[:div, {class: "moon"}, Storage.read("assets/moon.svg")]]]]]]]],

[:div, {class: "gra-container"},

[:div, {class: "row"},
[:div, {class: "col gra-center-text"}, [:span, {class: "gra-alert #{tone}", role: "alert"}, notice] if notice?]],

[:div, {class: "row"},
[:div, {class: "col col-80 col-span-10 gra-center-text"},
[:h1, {class: "gra-heading"}, @title],
[:h2, {class: "gra-subheading"}, @description]]],

[:div, {class: "row"},
[:div, {class: "col col-80 col-span-10"}, content]],

[:div, {class: "row"}]],

[:footer, {class: "gra-footer"},
[:nav,
[:ul, {class: "gra-nav gra-nav-fill"},
[:li, {class: "gra-nav-item"},
[:a, {class: "gra-nav-link", href: "https://spider-gazelle.net"}, "Built with S2 and Spider-Gazelle"]],
[:li, {class: "gra-nav-item"},
[:a, {class: "gra-nav-link", href: "https://github.com/gabriel-aires/ecmo"}, "Check the Github Repo"]]]]],

[:script,
<<-JAVASCRIPT
var notice = document.querySelector("span.gra-alert");
if (notice) {
notice.addEventListener("click", function() {
notice.style.display = "none";
});
}
var pref = (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches);
toggleTheme();
function toggleTheme() {
var sun = document.querySelector(".sun");
var moon = document.querySelector(".moon");
document.body.className = pref ? "dark" : "";
sun.style.display = pref ? "none" : "block";
moon.style.display = pref ? "block" : "none";
pref = !pref
}
JAVASCRIPT
]]]]
Loading

0 comments on commit bc295ce

Please sign in to comment.