skeleton ready to try to activate

This commit is contained in:
Paul Liverman III 2018-04-23 05:22:27 -07:00
parent 58c3e88728
commit 4e8779c96b
5 changed files with 110 additions and 5 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
logs/
nginx.conf.compiled
*.lua

View File

@ -1,5 +1,32 @@
lapis = require "lapis"
import Application from require "lapis"
class extends lapis.Application
"/": =>
"Welcome to Lapis #{require "lapis.version"}!"
import
import autoload, locate, registry from require "locator"
import settings from autoload "utility"
class Simplex extends Application
@before_filter =>
settings.load!
registry.before_filter(@)
@include locate "users"
@include locate "api"
[index: "/"]: =>
-- NOTE TEMPORARY
if @user
@keys = APIKeys\select "WHERE user_id = ?", user_id: @user.id
@tasls = Tasks\select "WHERE user_id = ?", user_id: @user.id
unless @keys and #@keys > 0
@keys = {APIKeys\create(@user)}
return render: "index.logged_in"
else
return redirect_to: @url_for "user_login", nil, redirect: @url_for "index"
[new_api_key: "/new-api-key"]: =>
if @user
if key = APIKeys\create(@user)
return json: { success: true, :key }

View File

@ -17,4 +17,3 @@ config "production", ->
num_workers 4
code_cache "on"
digest_rounds 12 -- NOTE not sure if this is used anywhere

48
static/index.js Normal file
View File

@ -0,0 +1,48 @@
function request(url) {
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
return xhr;
}
function check(id) {
var checkbox = document.getElementById("task-"+id);
if (checkbox.checked) {
var xhr = request("/v1/do");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
// TODO handle success / errors
console.log(xhr.responseText);
}
}
xhr.send(JSON.stringify({api_key: API_KEY, id: id}));
} else {
var xhr = request("/v1/undo");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
// TODO handle success / errors
console.log(xhr.responseText);
}
}
xhr.send(JSON.stringify({api_key: API_KEY, id: id}));
}
}
function new_task() {
var text = document.getElementById("new-task");
console.log(text); // TEMPORARY
var xhr = request("/v1/new");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
// TODO handle success / errors
console.log(xhr.responseText);
}
}
xhr.send(JSON.stringify({api_key: API_KEY, text: text.value}));
return false; // prevent form submission
}
function new_api_key() {
// TODO
}

View File

@ -0,0 +1,28 @@
import Widget from require "lapis.html"
class LoggedIn extends Widget
content: =>
script -> raw "var API_KEY = '#{@keys[1].key}';"
script src: "/static/index.js"
p "API Keys:"
ul ->
if @keys
for key in *@keys
li key.key
li ->
a onclick: "new_api_key()"
p "Tasks:"
ul ->
if @tasks
for task in *@tasks
li ->
input type: "checkbox", id: "task-#{task.id}", onchange: "check(#{task.id});", checked: task.done
text " #{task.content}"
li ->
form {
onsubmit: "return new_task();"
}, ->
input type: "text", id: "new-task", placeholder: "new task"
input type: "submit", value: "+"