From 2503607dde8d21b1e150d870fc5ffbaaa8cf4bc9 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sun, 19 Apr 2015 09:22:20 -0700 Subject: [PATCH] move pebble stuff to its own file --- controllers/controllers.php | 43 +++---------------------------------- controllers/pebble.php | 43 +++++++++++++++++++++++++++++++++++++ views/pebble-settings.php | 2 +- 3 files changed, 47 insertions(+), 41 deletions(-) create mode 100644 controllers/pebble.php diff --git a/controllers/controllers.php b/controllers/controllers.php index 6ec2895..11dced3 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -58,46 +58,6 @@ $app->get('/new', function() use($app) { } }); -$app->get('/pebble/settings', function() use($app) { - $html = render('pebble-settings-login', array( - 'title' => 'Log In' - )); - $app->response()->body($html); -}); - -$app->get('/pebble/settings/finished', function() use($app) { - if($user=require_login($app)) { - $token = JWT::encode(array( - 'user_id' => $_SESSION['user_id'], - 'me' => $_SESSION['me'], - 'created_at' => time() - ), Config::$jwtSecret); - - $html = render('pebble-settings', array( - 'title' => 'Pebble Settings', - 'token' => $token - )); - $app->response()->body($html); - } -}); - -$app->get('/pebble/options.json', function() use($app) { - $app->response()['Content-Type'] = 'application/json'; - $app->response()->body(json_encode(array( - 'sections' => array( - array( - 'title' => 'Caffeine', - 'items' => array_map(function($e){ return array('title'=>$e); }, caffeine_options()) - ), - array( - 'title' => 'Alcohol', - 'items' => array_map(function($e){ return array('title'=>$e); }, alcohol_options()) - ) - ) - ))); -}); - - $app->post('/prefs', function() use($app) { if($user=require_login($app)) { $params = $app->request()->params(); @@ -193,6 +153,9 @@ $app->post('/post', function() use($app) { if(k($params, 'drank')) { $entry->content = $params['drank']; $type = 'drink'; + } elseif(k($params, 'drink')) { + $entry->content = $params['drink']; + $type = 'drink'; } elseif(k($params, 'custom_drank')) { $entry->content = $params['custom_drank']; $type = 'drink'; diff --git a/controllers/pebble.php b/controllers/pebble.php new file mode 100644 index 0000000..d2d5fac --- /dev/null +++ b/controllers/pebble.php @@ -0,0 +1,43 @@ +get('/pebble/settings', function() use($app) { + $html = render('pebble-settings-login', array( + 'title' => 'Log In' + )); + $app->response()->body($html); +}); + +$app->get('/pebble/settings/finished', function() use($app) { + if($user=require_login($app)) { + $token = JWT::encode(array( + 'user_id' => $_SESSION['user_id'], + 'me' => $_SESSION['me'], + 'created_at' => time() + ), Config::$jwtSecret); + + $html = render('pebble-settings', array( + 'title' => 'Pebble Settings', + 'token' => $token + )); + $app->response()->body($html); + } +}); + +$app->get('/pebble/options.json', function() use($app) { + // TODO: if a token is provided, return the user's custom list + + $app->response()['Content-Type'] = 'application/json'; + $app->response()->body(json_encode(array( + 'sections' => array( + array( + 'title' => 'Caffeine', + 'items' => array_map(function($e){ return array('title'=>$e, 'type'=>'drink'); }, caffeine_options()) + ), + array( + 'title' => 'Alcohol', + 'items' => array_map(function($e){ return array('title'=>$e, 'type'=>'drink'); }, alcohol_options()) + ) + ) + ))); +}); + diff --git a/views/pebble-settings.php b/views/pebble-settings.php index a2d9a55..9812a1d 100644 --- a/views/pebble-settings.php +++ b/views/pebble-settings.php @@ -4,5 +4,5 @@ var options = { token: 'token ?>' }; -document.location = 'pebblejs://close#' + encodeURIComponent(JSON.stringify(options)); +location.href = 'pebblejs://close#' + encodeURIComponent(JSON.stringify(options)); \ No newline at end of file