styling, new api placeholders, template system

This commit is contained in:
Paul Liverman III 2018-04-24 15:56:40 -07:00
parent b5d6db88fe
commit 2b581f2685
3 changed files with 30 additions and 8 deletions

View File

@ -21,8 +21,8 @@ class API extends Application
)
-- TODO intentionally cause an error to see if this is working as intended
handle_error: (err, trace) =>
return status: 500, json: { errors: {err}, :trace } -- NOTE trace should be saved and NOT returned to the user
-- handle_error: (err, trace) =>
-- return status: 500, json: { errors: {err}, :trace } -- NOTE trace should be saved and NOT returned to the user
[err_test: "/err"]: =>
error "this is a testing error"
@ -84,6 +84,10 @@ class API extends Application
return json: { success: true, :task }
[get: "/get"]: capture_errors_json json_params =>
-- TODO
return status: 501, json: { errors: {"Not implemented."} }
[random: "/random"]: capture_errors_json json_params =>
assert_valid @params, {
{"count", exists: true, is_integer: true, optional: true, "Count is not an integer."}
@ -136,6 +140,14 @@ class API extends Application
-- returns page in case it returned a different page than you asked for! (in the case you ask for a page beyond the end)
return json: { success: true, page: @params.page, :tasks }
[new_key: "/key/new"]: capture_errors_json json_params =>
-- TODO
return status: 501, json: { errors: {"Not implemented."} }
[delete_key: "/key/delete"]: capture_errors_json json_params =>
-- TODO
return status: 501, json: { errors: {"Not implemented."} }
-- /new { content: "string" }
-- /do { id: # } or content
-- /undo { id: # } or content
@ -143,3 +155,5 @@ class API extends Application
-- /random { count: #, done: bool } (both args optional, defaults count 1, done false)
-- /list { count: #, done: bool, page: #, order: asc/desc } (if done not specified, returns all,
-- default count is 50, default page is 1, default order is latest first
-- /key/new
-- /key/delete { id: #, key: "str" }

View File

@ -15,19 +15,19 @@ function check(id) {
function new_task() {
let input = $("#new-task-input");
$.post("/v1/new", {api_key: API_KEY, content: input.prop("value")}, function(data, status) {
$.post("/v1/new", {api_key: API_KEY, content: input.val()}, function(data, status) {
if (status == "success") {
$("#new-task").before("<li><input type='checkbox' id='task-" + data.task.id + "' onchange='check(" + data.task.id + ")'> " + data.task.content + "</li>");
} else {
console.log(data); // NOTE TEMPORARY (need to handle errors better)
}
});
input.prop("value", "");
input.val("");
return false; // prevent form submission
}
function new_api_key() {
$.get("/new-api-key", function(data, status) {
$.get("/v1/key/new", function(data, status) {
if (status == "success") {
let template = $("#api-key-template").html();
$("code", template).text(data.api_key.key);
@ -38,3 +38,11 @@ function new_api_key() {
}
});
}
function delete_item(e) {
e = $(e);
while (!e.is("li")) {
e = e.parent();
}
e.remove();
}

View File

@ -5,10 +5,10 @@ class LoggedIn extends Widget
api_key_item = (key="") ->
li ->
div class: "row", ->
div class: "column column-80", ->
div class: "column column-60", ->
code key
div class: "column column-20", ->
button class: "delete", "x"
div class: "column column-offset-20 column-20", ->
button class: "delete", onclick: "delete_item(this);", "x"
script -> raw "var API_KEY = '#{@keys[1].key}';"
script src: "/static/index.js"