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