mardi 24 mars 2015

EmberJS regular refresh array data on one page

I have a Host model that is, for the moment, pretty simple:



App.Host = DS.Model.extend
name: DS.attr 'string'


The data adapter is handle by ember-data, my route looks like this:



App.HostsRoute = Ember.Route.extend
model: ->
@store.find 'host',
problematic: 1

App.HostRoute = Ember.Route.extend
model: (params) ->
@store.find 'host', params.id


My template will show a list of boxes to list and manage nagios alerts:



<h2>Hosts list</h2>

<div class="row">
<div class="col-md-8">
{{#each host in controller}}
<div class="box box-solid box-default collapsed-box">
<div class="box-header">
<h5 class="box-title">
<i class="fa fa-server"></i>
{{ host.name }}
</h5>
<div class="box-tools pull-right">
<button class="btn btn-default btn-sm" data-widget="collapse"><i class="fa fa-plus"></i></button>
</div>
</div>
<div class="box-body no-padding table-responsive" style="display: none">
{{#link-to 'host' host}}{{host.name}}{{/link-to}}
<table class="table table-hover">
<colgroup>
<col/>
<col style="width: 100%"/>
<col/>
<col/>
</colgroup>
<thead>
<tr>
<th>Service</th>
<th>Message</th>
<th>State</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>

{{/each}}
</div>

<div class="col-md-4">
{{outlet}}
</div>
</div>


Everything works like a charm.


Now, I want to refresh all the list every 10 seconds and automaticaly update the data, which means:



  • Update hosts attributes on boxes

  • Add boxes for new hosts

  • Remove boxes of deleted hosts


But I can't figure out how to do this. On Controller? On View? Route? Somewhere else?


I can't find a simple answer after Googling from hours although I think is not really hard to do this.


Thanks for your help.





Aucun commentaire:

Enregistrer un commentaire