diff --git a/functions.rb b/functions.rb new file mode 100644 index 0000000..afc0b6c --- /dev/null +++ b/functions.rb @@ -0,0 +1,10 @@ +#!/bin/env ruby + +def get_boolean(value) + if value + ret = "✅" + else + ret = "❌" + end + return ret +end diff --git a/server.rb b/server.rb index ea65d21..f845929 100755 --- a/server.rb +++ b/server.rb @@ -3,8 +3,19 @@ Bundler.require(:default, :development) require 'slim/include' +require './functions' use BetterErrors::Middleware DB = Sequel.connect('sqlite://database.db') set :port, 8091 +set :nav, [ + { title: 'Χρήστες', href: '/users' } +] + +get '/users' do + l = {} + l[:users] = DB[:user].all + slim :users, locals: l +end + diff --git a/views/head.slim b/views/head.slim index 983af52..74bcdb5 100644 --- a/views/head.slim +++ b/views/head.slim @@ -8,5 +8,8 @@ script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.m link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous" / Bootstrap JS script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous" +/ Boostrap table +link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.14.2/dist/bootstrap-table.min.css" +script src="https://unpkg.com/bootstrap-table@1.14.2/dist/bootstrap-table.min.js" / Custom meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" diff --git a/views/users.slim b/views/users.slim new file mode 100644 index 0000000..a3f8c14 --- /dev/null +++ b/views/users.slim @@ -0,0 +1,35 @@ +doctype html +html + head + include head + body + include nav + #main.mx-auto + table#myTable.table.table-hover.table-inverse.table-sortable data-toggle="table" + thead + tr + th data-sortable="true" Name + th data-sortable="true" Email + th data-sortable="true" Phone + th data-sortable="true" Card # + th data-sortable="true" Active + th data-sortable="true" Proedreio + th data-sortable="true" Banned + th data-sortable="true" Asylia + th data-sortable="true" Apousies + th data-sortable="true" Balance + th data-sortable="true" Telegram ID + - users.each do |u| + tr + td data-field="name" + a href="user?uid=#{u[:id]}"=u[:name] + td data-field="email"=u[:email] + td data-field="phone"=u[:phone] + td data-field="card_number"=u[:card_number] + td data-field="active"=get_boolean(u[:active]) + td data-field="proedreio"=get_boolean(u[:proedreio]) + td data-field="banned"=get_boolean(u[:banned]) + td data-field="asylia"=get_boolean(u[:asylia]) + td data-field="apousies"=u[:apousies] + td data-field="balance"=u[:balance] + td data-field="telegram-id"=u[:telegram_id]