You'll need node.js for this workshop. If you don't have it already, you'll have to install it.
- on Ubuntu or other apt, node is available on universes repositories.
- on Window or MacOS, use the installer: http://nodejs.org/download/
-
Go to the projet folder and type "npm install".
-
Launch the server ("node server.js") and open localhost:4000.
-
Ensure the page is displayed correctly.
-
Open your favorite IDE then open index.html, which is filled with static content. The main objective of this workshop will be to make this content dynamic using Backbone and the data delivered by the server.
-
Open Backbone documentation and put your hands on!
In this first step, we gonna use a Backbone View (LogsView) to display the static data previously contained in index.html, then we gonna load the real data from the server and display it instead.
-
- Cut/paste the table in index.html#content into the templates/table.html
- Instantiate the LogView in app.js
- Bind #content to LogsView.el in app.js: 2 methods (at construct view or after)
- Implement LogsView "render" method: inject the html template in the "el" element. (Feel free to use your favorite template engine: underscore or Handlebars. Both are included in global scope.)
- Call "render" in initialize
- Test in navigator
-
- Define data url in LogsCollection
- In the initialize method of LogView:
- create a LogCollection as view collection attribute
- listenTo collection sync event for rendering view, (instead of calling explicitly render!)
- fetch the collection
- LogsView render method: inject collection.toJSON into template
- Make template dynamic: (using <%= underscore %> or {{#handlebars}} to the template markup)
- Format every data in the template file with <% any js code you need %> -!!! careful, json data from server doesn't match exactly the columns expected: you have to implement the parse method of the model (Log) of LogCollection
-
- We gonna use SearchView.
- Cut/past the header content in index.html into templates/search.tmpl
- Instantiate the SearchView in app.js
- Implement the SearchView "render" method (like step 1) and call it.
-
- Instantiate FilterModel and share it between views, we'll use it to share information among the app
- Listen and bind the keyup event to a new method that will set its model with the new input field value
- Add listener in LogsView in order to re-render filtered table on FilterModel change
- Create a method into LogsCollection to filter models by a search term (@see Backbone.Collection#filter method) (you can return a new collection with the filtered models)
- LogsView's "render" method should now only render the filtered logs :
- You should add a "filterCollection" method into LogsView that call the collection method and be called by render
-
- We gonna use LeftPanelView
- Cut/past the #navigation content in index.html into templates/filter.tmpl
- Instantiate the LeftPanelView in app.js (do not forget to define FilterModel too)
- Implement the LeftPanelView "render" method (like step 1 and 2) and call it
-
- Subscribe to status and method checkboxes click: it will filter logs list
- Add methods to update filterModel with the new filter's values
- Improve the filter method in LogsView to match new filters (statuses and methods)
In this final step, we gonna show details panel on the right, with selected log data. Each table line needs to know the log model it displays, to trigger an appropriate event.
-
- Cut/paste the #detail content in index.html into the templates/details.tmpl
- Create a DetailsView and instanciate it in app.js
- Use the template as dynamic html (look at previous views construction)
- Implement render method, and insert the template
- Call "render" in initialize
- Test in navigator
-
- Isolate logs table lines creating a new view: LogLineView
- as the DOM element we need is a tr (not a div), do not forget to specify the tagName attribute of the view (@see view extension with a tagName)
- Cut/past the each loop content from templates/table.tmpl to templates/table-line.tmpl
- Make the LogLineView render the template passing it its model
- Delegate rendering from LogsView to LogLineView:
- modify LogsView render method, in order to loop on the collection
- in this loop, append each time a new LogLineView that is responsible for its log as a model
- do not forget to declare the dependency to LogLineView with requirejs
- In LogLineView, bind the click event:
- to trigger a Backbone event (@see Backbone.trigger), for example "details:show", with the log as an argument
- to add the css class "selected" on the view el
- Isolate logs table lines creating a new view: LogLineView
-
- In DetailsView, subscribe to the "details:show" event with listenTo
- Call a method (that takes a parameter) that renders the template with the log model