Skip to content

pankajkumar1104/library-app

 
 

Repository files navigation

Ember.js 2.4 Tutorial - Demo Application

Updated: 29 Feb 2016

This is the original repository of the Library App.

For detailed, step by step implementation click here: Ember.js 2 tutorial

Live demo: library-app.firebaseapp.com

How can you run this application locally?

I assume, you have Node.js on your computer. Node.js installation

  • Please create an app on Firebase first. You can register there with one click and create a new app. You have to setup this app name in config/environment.js. (This will be your own cloud based database.)

  • Clone this repository in your project folder

$ git clone [email protected]:zoltan-nz/library-app.git
  • Change to the application directory
$ cd library-app
  • Install node and bower packages
$ npm install && bower install
  • Setup in config/environment.js file your Firebase app name. This will be your own database server.
// config/environment.js
firebase: 'https://YOUR-FIREBASE-APP-NAME-COMES-HERE.firebaseio.com/',
  • Launch the application with Ember server.
$ ember server
  • Open the application in your browser
$ open http://localhost:4200

Managing Books

Simple list and edit the title

Template (books.hbs):

<h1>Books</h1>

<table class="table table-bordered table-striped">
  <thead>
  <tr>
    <th class="vtop">Author</th>
    <th>
      Title
      <br><small class="small not-bold">(Click on the title for editing)</small>
    </th>
    <th class="vtop">Release Year</th>
    <th class="vtop">Library</th>
  </tr>
  </thead>
  <tbody>
  {{#each model as |book|}}
    <tr>

      <td>
        {{book.author.name}}
      </td>

      <td>
        {{#if book.isEditing}}
          <form {{action 'saveBook' book on='submit'}} class="form-inline">
            <div class="input-group">
              {{input value=book.title class='form-control'}}
              <div class="input-group-btn">
                <button type="submit" class="btn btn-success" disabled={{book.isNotValid}}>Save</button>
                <button class="btn btn-danger" {{action 'cancelBookEdit' book}}>Cancel</button>
              </div>
            </div>
          </form>
        {{else}}
          <span {{action 'editBook' book}}>{{book.title}}</span>
        {{/if}}
      </td>

      <td>{{book.releaseYear}}</td>
      <td>{{book.library.name}}</td>
    </tr>
  {{/each}}
  </tbody>
</table>

Route (books.js):

import Ember from 'ember';

export default Ember.Route.extend({

  model() {
    return this.store.findAll('book');
  },

  actions: {

    editBook(book) {
      book.set('isEditing', true);
    },

    cancelBookEdit(book) {
      book.set('isEditing', false);
      book.rollbackAttributes();
    },

    saveBook(book) {
      if (book.get('isNotValid')) {
        return;
      }

      book.set('isEditing', false);
      book.save();
    }
  }
});

About

Detailed Ember.js 2.0 tutorial for absolute beginners. www.yoember.com

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 54.0%
  • HTML 40.4%
  • CSS 5.6%