Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
EPG/ExtJS: add incremental updates (finally)
  • Loading branch information
perexg committed May 5, 2015
1 parent 9fdbaaf commit bab49c6
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 7 deletions.
47 changes: 47 additions & 0 deletions src/api/api_epg.c
Expand Up @@ -484,6 +484,7 @@ api_epg_alternative
pthread_mutex_unlock(&global_lock);

/* Build response */
*resp = htsmsg_create_map();
htsmsg_add_u32(*resp, "totalCount", entries);
htsmsg_add_msg(*resp, "entries", l);

Expand Down Expand Up @@ -524,6 +525,51 @@ api_epg_related
pthread_mutex_unlock(&global_lock);

/* Build response */
*resp = htsmsg_create_map();
htsmsg_add_u32(*resp, "totalCount", entries);
htsmsg_add_msg(*resp, "entries", l);

return 0;
}

static int
api_epg_byid
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
uint32_t id = 0, entries = 0;
htsmsg_t *l = htsmsg_create_list(), *ids = NULL, *m;
htsmsg_field_t *f;
epg_broadcast_t *e;
const char *lang = htsmsg_get_str(args, "lang");

if (!(f = htsmsg_field_find(args, "eventId")))
return -EINVAL;
if (!(ids = htsmsg_field_get_list(f)))
if (htsmsg_field_get_u32(f, &id))
return -EINVAL;

/* Main Job */
pthread_mutex_lock(&global_lock);
if (ids) {
HTSMSG_FOREACH(f, ids) {
if (htsmsg_field_get_u32(f, &id)) continue;
e = epg_broadcast_find_by_id(id);
if (e == NULL) continue;
if ((m = api_epg_entry(e, lang, perm)) == NULL) continue;
htsmsg_add_msg(l, NULL, m);
entries++;
}
} else {
e = epg_broadcast_find_by_id(id);
if (e != NULL && (m = api_epg_entry(e, lang, perm)) != NULL) {
htsmsg_add_msg(l, NULL, m);
entries++;
}
}
pthread_mutex_unlock(&global_lock);

/* Build response */
*resp = htsmsg_create_map();
htsmsg_add_u32(*resp, "totalCount", entries);
htsmsg_add_msg(*resp, "entries", l);

Expand Down Expand Up @@ -565,6 +611,7 @@ void api_epg_init ( void )
{ "epg/events/grid", ACCESS_ANONYMOUS, api_epg_grid, NULL },
{ "epg/events/alternative", ACCESS_ANONYMOUS, api_epg_alternative, NULL },
{ "epg/events/related", ACCESS_ANONYMOUS, api_epg_related, NULL },
{ "epg/events/byid", ACCESS_ANONYMOUS, api_epg_byid, NULL },
{ "epg/brand/list", ACCESS_ANONYMOUS, api_epg_brand_list, NULL },
{ "epg/content_type/list", ACCESS_ANONYMOUS, api_epg_content_type_list, NULL },

Expand Down
59 changes: 52 additions & 7 deletions src/webui/static/app/epg.js
Expand Up @@ -859,15 +859,60 @@ tvheadend.epg = function() {
});

/**
* Listener for DVR notifications. We want to update the EPG grid when a
* recording is finished/deleted etc. so the status icon gets updated.
* Only do this when the tab is visible, otherwise it won't work as
* expected.
* Listener for EPG and DVR notifications.
* We want to update the EPG grid when a recording is finished/deleted etc.
* so the status icon gets updated. Only do this when the tab is visible,
* otherwise it won't work as expected.
*/
tvheadend.comet.on('epg', function(m) {
if (m.dvr_update || m.dvr_change)
if (panel.isVisible())
epgStore.reload();
if (!panel.isVisible())
return;
if (m.delete) {
for (var i = 0; i < m.delete.length; i++) {
var r = epgStore.getById(m.delete[i]);
if (r)
epgStore.remove(r);
}
}
if (m.update || m.dvr_update) {
if (m.update && m.dvr_update)
var a = m.update.concat(m.dvr_update);
else
var a = m.update || m.dvr_update;
var ids = [];
for (var i = 0; i < a.length; i++) {
var r = epgStore.getById(a[i]);
if (r)
ids.push(r.id);
}
if (ids) {
Ext.Ajax.request({
url: 'api/epg/events/byid',
params: {
eventId: ids
},
success: function(d) {
d = json_decode(d);
for (var i = 0; i < d.length; i++) {
var r = epgStore.getById(d[i].eventId);
if (r) {
for (var j = 0; j < r.store.fields.items.length; j++) {
var n = r.store.fields.items[j];
var v = d[i][n.name];
r.data[n.name] = n.convert((v !== undefined) ? v : n.defaultValue, v);
}
r.json = d[i];
r.commit();
}
}
panel.getView().refresh();
},
failure: function(response, options) {
Ext.MessageBox.alert('EPG Update', response.statusText);
}
});
}
}
});

// Always reload the store when the tab is activated
Expand Down

0 comments on commit bab49c6

Please sign in to comment.