Created
March 26, 2018 17:40
-
-
Save mgiagante/f5266874c468b801cded319ad9ec072c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "cuba" | |
require "mote" | |
require "mote/render" | |
Cuba.plugin Mote::Render | |
require_relative "controllers/pages" | |
require_relative "controllers/tasks" | |
require_relative "db/data_store" | |
require_relative "models/task" | |
DataStore.load_data | |
Cuba.define do | |
on get do | |
on "dashboard" do | |
with action: :dashboard do | |
run PagesController | |
end | |
end | |
end | |
on root do | |
res.redirect "dashboard" | |
end | |
on post do | |
on "tasks/:id" do |id| | |
on param(:event) do |event| | |
with action: :trigger, id: id.to_i, event: event do | |
run TasksController | |
end | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TasksController < Cuba | |
define do | |
on default do | |
res.write public_send(*vars.values) | |
res.redirect "/dashboard" | |
end | |
end | |
def trigger(id, event) | |
target_task = DataStore::Tasks.all.find { |task| task.id == id } | |
target_task.public_send(event) | |
target_task.status | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment