import Application from require "lapis" import APIKeys, Tasks from require "models" import autoload, locate, registry from require "locator" import settings from autoload "utility" import main from autoload "layouts" class Simplex extends Application @before_filter => settings.load! registry.before_filter(@) layout: main @include locate "users" @include locate "api" -- TODO intentionally cause an error to see if this is working as intended handle_error: (err, trace) => if @original_request.route_name\find "api_" return status: 500, json: { errors: {err}, :trace } -- NOTE trace should be saved and NOT returned to the user else super! [index: "/"]: => @title = "Simplex Task Manager" if @user @keys = APIKeys\select "WHERE user_id = ? ORDER BY id ASC", @user.id @tasks = Tasks\select "WHERE user_id = ? ORDER BY id ASC", @user.id unless @keys and #@keys > 0 @keys = {APIKeys\create(@user)} return render: "index.logged_in" else @html -> a href: @url_for("user_login"), "log in" text " | " a href: @url_for("user_new"), "new user" [console: "/console"]: => if @user and @user.admin console = require "lapis.console" return console.make(env: "all")(@) else return status: 404, "Not found."