12
Todo App with Meteor » Long Nguyen » @vangnol

Simple todo app with meteor

Embed Size (px)

Citation preview

Page 1: Simple todo app with meteor

Todo App with Meteor» Long Nguyen

» @vangnol

Page 2: Simple todo app with meteor

What is Meteor?

Meteor is a framework for building incredible web application. Meteor helps you build complex web application but in minimal amount of time. It's full-stack framework. On the server it runs on Nodejs, which means Meteor written in Javascript. Meteor has out of the box integration with MongoDB database. Meteor uses DDP Protocal to communicate between client and server.

Page 3: Simple todo app with meteor

Setup

» MacOS or Ubuntucurl https://install.meteor.com/ | sh

» WindowsGo get a Mac or a Ubuntu laptop

Page 4: Simple todo app with meteor

DemoSimple Todo App with Meteor ♡♡♡

Page 5: Simple todo app with meteor

task.html

<head> <title>Simple Todo App</title></head>

<body> <h1>Awesome Todo App</h1> <hr/>

<div class="container"> {{> CreateTask}} {{> ListTasks}} {{> CompleteCounter}} </div></body>

<template name="ListTasks"> <ul> {{#each tasks}} <li class="task {{doneClass}}">{{> Task}}</li> {{/each}} </ul></template>

Page 6: Simple todo app with meteor

<template name="Task"> <input type="checkbox" name="is_done" {{isDoneChecked}} /> {{subject}}</template>

<template name="CreateTask"><form class="create-task" > <input type="text" placeholder="Creating new task...!" /></form></template>

<template name="CompleteCounter"> <h3>{{completeTask}} / {{totalTasks}} tasks completed</h3></template>

Page 7: Simple todo app with meteor

task.css

.task{ font-size: 20px; background-color: #EBEBEB; padding: 10px; margin-bottom: 2px;}

.done{ text-decoration: line-through;}

Page 8: Simple todo app with meteor

task.js

Todos = new Meteor.Collection('todos');

if(Meteor.isClient){ Template.ListTasks.helpers({ tasks: function(){ return Todos.find(); },

doneClass: function(){ return this.is_done ? 'done' : ''; } });

Template.Task.helpers({ isDoneChecked: function(){ return this.is_done ? 'checked' : '' } });

Page 9: Simple todo app with meteor

Template.Task.events({ "click [name=is_done]": function(e, tmpl){ var id = this._id; var isDone = tmpl.find('input').checked; Todos.update({_id: id}, {$set: { is_done: isDone}}); } });

Template.CreateTask.events({ 'submit form': function(e, tmpl){ e.preventDefault();

var subject = tmpl.find('input').value;

Todos.insert({subject: subject, created_at: new Date, is_done: false});

var form = tmpl.find('form'); form.reset(); } });}

Page 10: Simple todo app with meteor

Template.CompleteCounter.helpers({ completeTask: function(){ return Todos.find({is_done: true}).count(); },

totalTasks: function(){ return Todos.find({}).count(); } });}

if(Meteor.isServer){

}

Page 12: Simple todo app with meteor

Thank you!