Skip to content

Commit

Permalink
Angular demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Way committed Dec 17, 2013
1 parent b1a39ea commit d00a4bb
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 200 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
composer.phar
composer.lock
.DS_Store
Thumbs.db
Thumbs.db
.idea/
186 changes: 0 additions & 186 deletions .idea/workspace.xml

This file was deleted.

34 changes: 34 additions & 0 deletions app/database/migrations/2013_12_17_154848_create_todos_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateTodosTable extends Migration {

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('todos', function(Blueprint $table) {
$table->increments('id');
$table->text('body');
$table->boolean('completed');
$table->timestamps();
});
}


/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('todos');
}

}
10 changes: 10 additions & 0 deletions app/models/Todo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

class Todo extends Eloquent {
protected $guarded = []; // just for demo

public function getCompletedAttribute($value)
{
return (boolean) $value;
}
}
27 changes: 14 additions & 13 deletions app/routes.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

Route::get('/', function()
{
return View::make('hello');
});
return View::make('index');
});

Route::get('todos', function()
{
return Todo::all();
});

Route::post('todos', function()
{
return Todo::create(Input::all());
});


35 changes: 35 additions & 0 deletions app/views/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!doctype html>
<html lang="en" ng-app>
<head>
<meta charset="UTF-8">
<title>Angular Training</title>
<style>
small { font-size: .8em; color: grey; }
</style>
</head>
<body ng-controller="TodosController">
<h1>
Todos
<small ng-if="remaining()">({{ remaining() }} remaining)</small>
</h1>
<input type="text" placeholder="Filter todos" ng-model="search">
<ul>
<li ng-repeat="todo in todos | filter:search">
<input type="checkbox" ng-model="todo.completed">
{{ todo.body }}
</li>
</ul>
<form ng-submit="addTodo()">
<input type="text" placeholder="Add new task" ng-model="newTodoText">
<button type="submit">Add Task</button>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script>
<script src="/js/main.js"></script>
</body>
</html>
28 changes: 28 additions & 0 deletions public/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function TodosController($scope, $http) {

$http.get('/todos').success(function(todos) {
$scope.todos = todos;
});

$scope.remaining = function() {
var count = 0;

angular.forEach($scope.todos, function(todo) {
count += todo.completed ? 0 : 1;
});

return count;
}

$scope.addTodo = function() {
var todo = {
body: $scope.newTodoText,
completed: false
};

$scope.todos.push(todo);

$http.post('todos', todo);
};

}

0 comments on commit d00a4bb

Please sign in to comment.