masterlist.nas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # --------------------------------
  2. #
  3. # driver class for FND masterlist messages
  4. #
  5. # this is the generic part of the masterlist
  6. # drivers containing the masterlist class
  7. # --------------------------------
  8. var sliceout = func (a,b) {
  9. if (size(a) == 1) return [];
  10. if (b+1 > size(a)) return a;
  11. if (b+1 == size(a)) return a[0:-2];
  12. if (b == 0) return a[1:];
  13. return a[0:b-1, b+1:];
  14. }
  15. # defines colors
  16. white=[1, 0, 0];
  17. green=[2, 0, 0];
  18. red=[3, 0, 0];
  19. amber=[4, 0, 0];
  20. # masterlist class
  21. var masterlist = {
  22. new: func(path) {
  23. var m = { parents: [masterlist] };
  24. m.prio = 0;
  25. m.list = [];
  26. m.items= [];
  27. m.path = path;
  28. return m;
  29. },
  30. warning : func (f, c, txt1, txt2) {
  31. me.register(f, c, txt1, txt2, 300);},
  32. caution : func (f, c, txt1, txt2) {
  33. me.register(f, c, txt1, txt2, 200);},
  34. advisory: func (f, c, txt1, txt2) {
  35. me.register(f, c, txt1, txt2, 100);},
  36. info: func (f, c, txt1, txt2) {
  37. me.register(f, c, txt1, txt2, 0);},
  38. register: func (f, c, txt1, txt2, type) {
  39. if (me.prio < 100) {
  40. append(me.items, [f, c, txt1, txt2, me.prio+type]);
  41. me.prio +=1;
  42. } else {
  43. print("masterlist error");
  44. }
  45. },
  46. sort: func() {
  47. # sort by priority
  48. me.list = sort(me.list,
  49. func (a,b) {if (a[3] > b[3]) return -1; else return 1;} );
  50. },
  51. update: func {
  52. # test all conditions registered
  53. # in items
  54. foreach (var item; me.items) {
  55. if (call(item[0])) {
  56. me.show(item[1:4]);
  57. } else {
  58. me.hide(item[1:2]);
  59. }
  60. }
  61. me.sort();
  62. me.refresh();
  63. },
  64. refresh: func {
  65. # copy the internal representation of
  66. # the masterlist to the property tree
  67. k=0;
  68. foreach(var txt; me.list) {
  69. rgb = me.col(txt[3]);
  70. foreach(var i; [0,1,2]) {
  71. setprop(me.path ~ "[" ~ k ~ "]/msg[" ~ i ~ "]", txt[i]);
  72. setprop(me.path ~ "[" ~ k ~ "]/rgb[" ~ i ~ "]", rgb[i]);
  73. }
  74. k+=1;
  75. }
  76. if (k<7) me.clearlist(k);
  77. },
  78. show: func(item) {
  79. k = 0;
  80. #search if message alread active in list:
  81. foreach(var txt; me.list) {
  82. if (txt[2] == item[1]) {
  83. # insert ENG1/ENG2 in col. 0 or 1
  84. if (item[0] != 2) me.list[k][item[0]] = item[2];
  85. return;
  86. }
  87. k+=1;
  88. }
  89. #message not in list append new line to list:
  90. theline = ["","","",""];
  91. theline[item[0]] = item[2];
  92. theline[2] = item[1];
  93. theline[3] = item[3];
  94. append(me.list, theline);
  95. },
  96. ontop: func (theline) {
  97. newlist = [];
  98. append(newlist, theline);
  99. foreach (var x; me.list) append(newlist, x);
  100. me.list = newlist;
  101. },
  102. hide: func(item) {
  103. #search if message is active in list:
  104. k=0;
  105. foreach(var txt; me.list) {
  106. if (txt[2] == item[1]) {
  107. if (txt[0] != "" and txt[1] != "") {
  108. me.list[k][item[0]] = "";
  109. } else if (txt[item[0]] != "") {
  110. # remove list entry
  111. me.list = sliceout(me.list, k);
  112. }
  113. return;
  114. }
  115. k+=1;
  116. }
  117. },
  118. clearlist: func(k) {
  119. #max. 7 messages in masterlist
  120. while (k<7) {
  121. foreach (var i; [0,1,2]) setprop(me.path ~ "[" ~ k ~ "]/msg[" ~ i ~ "]", "");
  122. k+=1;
  123. }
  124. },
  125. col: func(c) {if (c<100) return green; else if (c<200) return white; else if (c<300) return amber else return red;}
  126. };