Compare commits

...

5 Commits

18 changed files with 3544 additions and 7 deletions

71
.gitignore vendored
View File

@ -1,8 +1,67 @@
# ---> Composer
composer.phar
/vendor/
# ---> Ruby
*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/spec/examples.txt
/test/tmp/
/test/version_tmp/
/tmp/
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
# Used by dotenv library to load environment variables.
# .env
# Ignore Byebug command history file.
.byebug_history
## Specific to RubyMotion:
.dat*
.repl_history
build/
*.bridgesupport
build-iPhoneOS/
build-iPhoneSimulator/
## Specific to RubyMotion (use of CocoaPods):
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# vendor/Pods/
## Documentation cache and generated files:
/.yardoc/
/_yardoc/
/doc/
/rdoc/
## Environment normalization:
/.bundle/
/vendor/bundle
/lib/bundler/man/
# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# Gemfile.lock
# .ruby-version
# .ruby-gemset
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
# .rubocop-https?--*
# Local database storage
data/raven.db
# Node modules for Grunt.js
node_modules/
# Compiled CSS and JS
public/css/
public/js/

11
Gemfile Normal file
View File

@ -0,0 +1,11 @@
source 'https://rubygems.org'
gem 'sinatra', '~> 3.0'
gem 'puma', '~> 6.0'
gem 'sequel', '~> 5.63'
gem 'sqlite3', '~> 1.5'
# Use rerun gem to auto-reload app
gem 'rerun'

45
Gemfile.lock Normal file
View File

@ -0,0 +1,45 @@
GEM
remote: https://rubygems.org/
specs:
ffi (1.15.5)
ffi (1.15.5-x64-mingw-ucrt)
listen (3.7.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
nio4r (2.5.8)
puma (6.0.0)
nio4r (~> 2.0)
rack (2.2.4)
rack-protection (3.0.4)
rack
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rerun (0.13.1)
listen (~> 3.0)
ruby2_keywords (0.0.5)
sequel (5.63.0)
sinatra (3.0.4)
mustermann (~> 3.0)
rack (~> 2.2, >= 2.2.4)
rack-protection (= 3.0.4)
tilt (~> 2.0)
sqlite3 (1.5.4-x64-mingw-ucrt)
sqlite3 (1.5.4-x86_64-linux)
tilt (2.0.11)
PLATFORMS
x64-mingw-ucrt
x86_64-linux
DEPENDENCIES
puma (~> 6.0)
rerun
sequel (~> 5.63)
sinatra (~> 3.0)
sqlite3 (~> 1.5)
BUNDLED WITH
2.3.7

41
Gruntfile.js Normal file
View File

@ -0,0 +1,41 @@
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
dist: {
options: {
style: 'compressed'
},
files: [{
expand: true,
cwd: 'assets/styles',
src: ['**/*.scss'],
dest: 'public/css',
ext: '.css'
}]
}
},
watch: {
css: {
files: ['assets/styles/**/*.scss'],
tasks: ['sass'],
options: {
atBegin: true,
spawn: false
}
}
}
});
// Load plugins.
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-sass');
// CLI tasks.
grunt.registerTask('default', ['sass']);
};

View File

@ -1,4 +1,4 @@
Copyright (c) <year> <owner>
Copyright (c) 2022 Metaunix.net
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

62
assets/styles/kraken.scss Normal file
View File

@ -0,0 +1,62 @@
$nav-width: 200px;
$box-shadow-1: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
$box-shadow-2: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
body{
background: lightgrey;
}
#main-nav{
position: fixed;
top: 0;
left: 0;
width: $nav-width;
height: 100%;
padding: 20px 0;
background: #212121;
color: white;
box-shadow: $box-shadow-1;
box-sizing: border-box;
h3{
text-align: center;
}
ul{
list-style: none;
li{
margin: 0;
border-bottom: 1px solid #999;
&:first-child{
border-top: 1px solid #999;
}
}
a{
display: block;
box-sizing: border-box;
width: $nav-width;
padding: 10px 15px;
color: limegreen;
font-size: 2.5rem;
text-decoration: none;
transition: all 230ms ease-in-out;
&:hover{
background: rgba(255, 255, 255, 0.1);
}
}
}
}
#main-wrapper{
max-width: 1200px;
margin-top: 25px;
padding: 20px 30px;
background: white;
border-radius: 5px;
box-shadow: $box-shadow-2;
}

3
data/defaults.yaml Normal file
View File

@ -0,0 +1,3 @@
database:
adapter: 'sqlite'
database: 'data/raven.db'

View File

@ -0,0 +1,22 @@
Sequel.migration do
up do
create_table(:items) do
primary_key :id
String :name, null: false
String :manufacturer
String :serial_number
String :sku_number
String :type
String :purchased_from
DateTime :purchased_at
DateTime :created_at
DateTime :updated_at
end
end
down do
drop_table(:items)
end
end

20
lib/config.rb Normal file
View File

@ -0,0 +1,20 @@
require 'yaml'
class Config
def initialize(config_path)
@data = YAML::load_file(config_path)
end
def get(key, depth = 0)
bits = key.split('.')
value = @data
bits.each do |bit|
value = value[bit]
end
return value
end
end

5
lib/models/item.rb Normal file
View File

@ -0,0 +1,5 @@
class Item < Sequel::Model
end

37
lib/routes.rb Normal file
View File

@ -0,0 +1,37 @@
get '/' do
items = Item.all
erb :index, :locals => {
:title => 'Dashboard',
:items => items
}
end
get '/item' do
redirect '/item/list'
end
get '/item/list' do
items = Item.all
erb :'item/list', :locals => {
:title => 'List of Items',
:items => items
}
end
get '/item/create' do
erb :'item/create', :locals => {
:title => 'Create New Item'
}
end
post '/item/create' do
item = Item.create(
name: params[:item_name],
serial_number: params[:item_serial],
sku_number: params[:item_sku],
purchased_from: params[:item_purchase_from],
purchased_at: params[:item_purchase_date],
manufacturer: params[:item_manufacturer],
type: params[:item_type]
)
redirect "/item/#{item.id}"
end

3064
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

33
package.json Normal file
View File

@ -0,0 +1,33 @@
{
"name": "raven",
"version": "0.1.0",
"description": "Self-hosted inventory tracker",
"main": "index.js",
"scripts": {
"grunt": "grunt",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "gitea@git.metaunix.net:Metaunix/raven.git"
},
"keywords": [
"inventory",
"tracking"
],
"author": "Gregory Ballanine <gballantine@metaunix.net>",
"uploaders": [
{
"name": "Gregory Ballantine",
"email": "gballantine@metaunix.net"
}
],
"license": "BSD-2-Clause",
"devDependencies": {
"grunt": "^1.5.3",
"grunt-cli": "^1.4.3",
"grunt-contrib-sass": "^2.0.0",
"grunt-contrib-watch": "^1.1.0",
"sass": "^1.55.0"
}
}

27
raven.rb Normal file
View File

@ -0,0 +1,27 @@
require 'logger'
require 'sequel'
require 'sqlite3'
require 'sinatra'
require_relative 'lib/config.rb'
set :public_folder, __dir__ + '/public'
set :views, settings.root + '/views'
# Load configuration file
conf = Config.new(File.join(__dir__, 'data/defaults.yaml'))
# Initialize logging
logger = Logger.new(STDOUT)
logger.level = Logger::INFO
# Load the Sequel timestamps plugin
Sequel::Model.plugin :timestamps
# Initialize Sequel gem for database actions
DB = Sequel.connect(adapter: conf.get('database.adapter'), database: conf.get('database.database'))
# Load models
require_relative 'lib/models/item.rb'
# Register route handlers
require_relative 'lib/routes.rb'

11
views/index.erb Normal file
View File

@ -0,0 +1,11 @@
<p>This is a test.</p>
<% if items.length > 0 %>
<ul>
<% items.each do |item| %>
<li><%= item.name %></li>
<% end %>
</ul>
<% else %>
<p>There are no items to display.</p>
<% end %>

64
views/item/create.erb Normal file
View File

@ -0,0 +1,64 @@
<div class="row">
<div class="twelve columns">
<h1>Create new item</h1>
</div>
</div>
<div class="row">
<div class="twelve columns">
<form action="/item/create" method="POST" class="u-full-width">
<div class="row">
<div class="columns twelve">
<label for="item_name">Item name:</label>
<input class="u-full-width" type="text" placeholder="My new item" id="item_name" name="item_name" required>
</div>
</div>
<div class="row">
<div class="six columns">
<label for="item_serial">Serial number:</label>
<input class="u-full-width" type="text" placeholder="0123456789" id="item_serial" name="item_serial">
</div>
<div class="six columns">
<label for="item_sku">SKU number:</label>
<input class="u-full-width" type="text" placeholder="ABC12345678" id="item_sku" name="item_sku">
</div>
</div>
<div class="row">
<div class="six columns">
<label for="item_purchase_from">Purchased from:</label>
<input class="u-full-width" type="text" placeholder="Newegg" id="item_purchase_from" name="item_purchase_from">
</div>
<div class="six columns">
<label for="item_purchase_date">Purchased at:</label>
<input class="u-full-width" type="datetime-local" id="item_purchase_date" name="item_purchase_date">
</div>
</div>
<div class="row">
<div class="six columns">
<label for="item_manufacturer">Manufacturer:</label>
<input class="u-full-width" type="text" placeholder="Manufacturer" id="item_manufacturer" name="item_manufacturer">
</div>
<div class="six columns">
<label for="item_type">Item type</label>
<select class="u-full-width" id="item_type" name="item_type">
<option value="cpu">Processor</option>
<option value="motherboard">Motherboard</option>
<option value="memory">Memory (RAM)</option>
<option value="psu">Power Supply</option>
<option value="case">Case</option>
<option value="storage">Storage Device</option>
<option value="gpu">Graphics Card</option>
</select>
</div>
</div>
<input class="button-primary u-full-width" type="submit" value="Submit">
</form>
</div>
</div>

7
views/item/list.erb Normal file
View File

@ -0,0 +1,7 @@
<p><a href="/item/create">Create new item</a></p>
<ul>
<% items.each do |item| %>
<li><%= item.name %></li>
<% end %>
</ul>

26
views/layout.erb Normal file
View File

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= title %> | Raven</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="/css/kraken.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
</head>
<body>
<!-- Main navigation -->
<nav id="main-nav">
<h3>Raven</h3>
<ul>
<li><a href="/">Dashboard</a></li>
<li><a href="/item/list">Items</a></li>
<li><a href="/license/list">Licenses</a></li>
</ul>
</nav>
<div id="main-wrapper" class="container">
<%= yield %>
</div>
</body>
</html>