]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
webui: add the field order feature (for grid) 359/head
authorJaroslav Kysela <perex@perex.cz>
Fri, 21 Mar 2014 08:21:20 +0000 (09:21 +0100)
committerJaroslav Kysela <perex@perex.cz>
Fri, 21 Mar 2014 08:21:20 +0000 (09:21 +0100)
src/idnode.c
src/idnode.h
src/input/mpegts/mpegts_service.c
src/webui/static/app/idnode.js

index b06756e82385af9328bbbc779df60e731aac7050..8a09687d3ec81a1dda610a55ece29121781589a0 100644 (file)
@@ -820,6 +820,17 @@ idclass_get_class (const idclass_t *idc)
   return NULL;
 }
 
+static const char *
+idclass_get_order (const idclass_t *idc)
+{
+  while (idc) {
+    if (idc->ic_class)
+      return idc->ic_order;
+    idc = idc->ic_super;
+  }
+  return NULL;
+}
+
 static int
 ic_cmp ( const idclass_link_t *a, const idclass_link_t *b )
 {
@@ -868,6 +879,8 @@ idclass_serialize0(const idclass_t *idc, int optmask)
     htsmsg_add_str(m, "caption", s);
   if ((s = idclass_get_class(idc)))
     htsmsg_add_str(m, "class", s);
+  if ((s = idclass_get_order(idc)))
+    htsmsg_add_str(m, "order", s);
 
   /* Props */
   if ((p = idnode_params(idc, NULL, optmask)))
index a10c1056b8f8547082f29ea5fb2403a491b8894f..cfd3194410b71c2a0b1f1c72c05f1fcff4b7f814 100644 (file)
@@ -48,6 +48,7 @@ typedef struct idclass {
   const struct idclass  *ic_super;      /// Parent class
   const char            *ic_class;      /// Class name
   const char            *ic_caption;    /// Class description
+  const char            *ic_order;      /// Property order (comma separated)
   const property_t      *ic_properties; /// Property list
   const char            *ic_event;      /// Events to fire on add/delete/title
 
index 763913388c88976b810238299a8c0013606d09b1..d32949b24cde1308df5ab50557d216ee018d0c9f 100644 (file)
@@ -60,6 +60,7 @@ const idclass_t mpegts_service_class =
   .ic_super      = &service_class,
   .ic_class      = "mpegts_service",
   .ic_caption    = "MPEGTS Service",
+  .ic_order      = "enabled,channel,svcname",
   .ic_properties = (const property_t[]){
     {
       .type     = PT_STR,
index 5a8577e337fcc52d61101b7b54185698cb7dd7cc..947e95e33dbf2dc2816da2c344ee5fc7b0491cd5 100644 (file)
@@ -121,6 +121,7 @@ tvheadend.IdNodeField = function (conf)
   this.store  = null;
   if (this.enum)
     this.store = tvheadend.idnode_enum_store(this);
+  this.ordered = false;
 
   /*
    * Methods
@@ -245,10 +246,41 @@ tvheadend.IdNode = function (conf)
   this.clazz  = conf.class;
   this.text   = conf.caption || this.clazz;
   this.props  = conf.props;
-  this.fields = []
+  this.order  = [];
+  this.fields = [];
   for (var i = 0; i < this.props.length; i++) {
     this.fields.push(new tvheadend.IdNodeField(this.props[i]));
   }
+  var o = [];
+  if (conf.order)
+    o = conf.order.split(',');
+  if (o) {
+    while (o.length < this.fields.length)
+      o.push(null);
+    for (var i = 0; i < o.length; i++) {
+      this.order[i] = null;
+      if (o[i]) {
+        for (var j = 0; j < this.fields.length; j++) {
+          if (this.fields[j].id == o[i]) {
+            this.order[i] = this.fields[j];
+            this.fields[j].ordered = true;
+            break;
+          }
+        }
+      }
+    }
+    for (var i = 0; i < o.length; i++) {
+      if (this.order[i] == null) {
+        for (var j = 0; j < this.fields.length; j++) {
+          if (!this.fields[j].ordered) {
+            this.fields[j].ordered = true;
+            this.order[i] = this.fields[j];
+            break;
+          }
+        }
+      }
+    }
+  }
 
   /*
    * Methods
@@ -257,6 +289,10 @@ tvheadend.IdNode = function (conf)
   this.length = function () {
     return this.fields.length;
   }
+  
+  this.field = function ( index ) {
+    if (this.order) return this.order[index]; else return this.fields[index];
+  }
 }
 
 
@@ -616,7 +652,7 @@ tvheadend.idnode_grid = function(panel, conf)
     /* Model */
     var idnode  = new tvheadend.IdNode(d);
     for (var i = 0; i < idnode.length(); i++) {
-      var f = idnode.fields[i];
+      var f = idnode.field(i);
       var c = f.column();
       fields.push(f.id);
       columns.push(c);