status.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. 'use strict';
  2. 'require ui';
  3. 'require view';
  4. 'require poll';
  5. 'require dom';
  6. 'require modemmanager_helper as helper';
  7. return view.extend({
  8. load: function() {
  9. return helper.getModems().then(function (modems) {
  10. return Promise.all(modems.filter(function (modem){
  11. return modem != null;
  12. }).map(function (modem) {
  13. return helper.getModemSims(modem.modem).then(function (sims) {
  14. modem.sims = sims.filter(function (sim) {
  15. return sim != null;
  16. });
  17. return helper.getModemLocation(modem.modem).then(function (location) {
  18. modem.location = location;
  19. return modem;
  20. });
  21. });
  22. }));
  23. });
  24. },
  25. pollData: function (container) {
  26. poll.add(L.bind(function () {
  27. return this.load().then(L.bind(function (modems) {
  28. dom.content(container, this.renderContent(modems));
  29. }, this));
  30. }, this));
  31. },
  32. renderSections: function (name, sections) {
  33. if (sections.length == 0) {
  34. sections.push(E('div', { 'class': 'cbi-section' }, [
  35. E('span', {}, _('Section %s is empty.').format(name))
  36. ]));
  37. }
  38. return E('div', { 'class': 'cbi-section' }, [
  39. E('h1', {}, name),
  40. ...sections
  41. ]);
  42. },
  43. renderSection: function (name, table) {
  44. var rowNodes = table.filter(function (row) {
  45. return row[1] != null;
  46. }).map(function (row) {
  47. return E('tr', { 'class': 'tr' }, [
  48. E('td', { 'class': 'td', 'width': '33%' }, E('strong', {}, [row[0]])),
  49. E('td', { 'class': 'td' }, [row[1]])
  50. ]);
  51. });
  52. var tableNode;
  53. if (rowNodes.length == 0) {
  54. tableNode = E('div', { 'class': 'cbi-section' }, [
  55. E('span', {}, _('Section %s is empty.').format(name))
  56. ])
  57. } else {
  58. tableNode = E('table', { 'class': 'table', }, rowNodes);
  59. }
  60. return E('div', { 'class': 'cbi-section' }, [
  61. E('h2', {}, [name]),
  62. tableNode
  63. ]);
  64. },
  65. renderContent: function (modems) {
  66. var node = E('div', {}, E('div'));
  67. modems.forEach(L.bind(function (modem) {
  68. var generic = modem.modem.generic;
  69. var modem3gpp = modem.modem['3gpp'];
  70. var modemSection = this.renderSection(_('Modem Info'), [
  71. [_('Manufacturer'), generic.manufacturer],
  72. [_('Model'), generic.model],
  73. [_('Revision'), generic.revision],
  74. [E('abbr', { 'title': _('International Mobile Station Equipment Identity') }, [
  75. _('IMEI')
  76. ]), modem3gpp.imei],
  77. [_('Device Identifier'), generic['device-identifier']],
  78. [_('Power State'), generic['power-state']],
  79. [_('State'), generic.state],
  80. [_('Failed Reason'), generic['state-failed-reason']]
  81. ]);
  82. var ownNumbersStr = generic['own-numbers'].join(', ');
  83. var accessTechnologiesStr = generic['access-technologies'].join(', ');
  84. var signalQualityValue = parseInt(generic['signal-quality'].value);
  85. var networkSection = this.renderSection(_('Network Registration'), [
  86. [_('Own Numbers'), ownNumbersStr],
  87. [_('Access Technologies'), accessTechnologiesStr],
  88. [_('Operator') , modem3gpp['operator-name']],
  89. [_('Operator Code'), modem3gpp['operator-code']],
  90. [_('Registration State'), modem3gpp['registration-state']],
  91. [_('Packet Service State'), modem3gpp['packet-service-state']],
  92. [_('Signal Quality'), E('div', { 'class': 'cbi-progressbar', 'title': '%d %'.format(signalQualityValue) }, [
  93. E('div', { 'style': 'width: %d%%'.format(signalQualityValue) })
  94. ])]
  95. ]);
  96. var location3gpp = {};
  97. if (modem.location != null) {
  98. location3gpp = modem.location.modem.location['3gpp'];
  99. }
  100. var locationSection = this.renderSection(_('Cell Location'), [
  101. [E('abbr', { 'title': _('Cell ID') }, [
  102. 'CID'
  103. ]), location3gpp.cid],
  104. [E('abbr', { 'title': _('Location Area Code') }, [
  105. 'LAC'
  106. ]), location3gpp.lac],
  107. [E('abbr', { 'title': _('Mobile Country Code') }, [
  108. 'MCC'
  109. ]), location3gpp.mcc],
  110. [E('abbr', { 'title': _('Mobile Network Code') }, [
  111. 'MNC'
  112. ]), location3gpp.mnc],
  113. [E('abbr', { 'title': _('Tracking Area Code') }, [
  114. 'TAC'
  115. ]), location3gpp.tac]
  116. ]);
  117. var simTables = modem.sims.map(function (sim) {
  118. var properties = sim.sim.properties;
  119. return [
  120. [_('Active'), properties.active],
  121. [_('Operator Name'), properties['operator-name']],
  122. [E('abbr', { 'title': _('Integrated Circuit Card Identifier') }, [
  123. 'ICCID'
  124. ]), properties.iccid],
  125. [E('abbr', { 'title': _('International Mobile Subscriber Identity') }, [
  126. 'IMSI'
  127. ]), properties.imsi]
  128. ];
  129. });
  130. var simSubSections = simTables.map(L.bind(function (table, index) {
  131. return this.renderSection(_('SIM %d').format(index + 1), table)
  132. }, this));
  133. var simSection = this.renderSections(_('SIMs'), simSubSections);
  134. var sections = [
  135. E('div', { 'class': 'cbi-map-descr'}, []),
  136. modemSection,
  137. networkSection,
  138. locationSection,
  139. simSection
  140. ].filter(function (section) {
  141. return section != null;
  142. });
  143. node.firstElementChild.appendChild(E('div', { 'data-tab': generic.device, 'data-tab-title': generic.device }, sections));
  144. }, this));
  145. ui.tabs.initTabGroup(node.firstElementChild.childNodes);
  146. return node;
  147. },
  148. render: function (modems) {
  149. var content = E([], [
  150. E('h2', {}, [_('Cellular Network')]),
  151. E('div')
  152. ]);
  153. var container = content.lastElementChild;
  154. dom.content(container, this.renderContent(modems));
  155. this.pollData(container);
  156. return content;
  157. },
  158. handleSaveApply: null,
  159. handleSave: null,
  160. handleReset: null
  161. });