22 <div >
33 <h2 >{{ msg }}</h2 >
44 <div v-if =" isLoading" class =" spinner spinner-lg" ></div >
5- <div v-if =" (user.account_type == 'admin') || (user.account_type == 'reseller') && !isLoading" class =" form-group select-search col-xs-12 col-sm-12 col-md-12 col-lg-12" >
6- <label v-if =" !isLoading" class =" col-sm-2 control-label" for =" textInput-markup" >Hotspot</label >
5+ <div
6+ v-if ="
7+ user.account_type == 'admin' ||
8+ (user.account_type == 'reseller' && !isLoading)
9+ "
10+ class =" form-group select-search col-xs-12 col-sm-12 col-md-12 col-lg-12"
11+ >
12+ <label
13+ v-if =" !isLoading"
14+ class =" col-sm-2 control-label"
15+ for =" textInput-markup"
16+ >Hotspot</label
17+ >
718 <div v-if =" !isLoading" class =" col-sm-4" >
8- <select v-on:change =" getAll(true)" v-model =" hotspotSearchId" class =" form-control" >
9- <option v-for =" hotspot in hotspots" v-bind:key =" hotspot.id" v-bind:value =" hotspot.id" >
10- {{ hotspot.name }} - {{ hotspot.description}}
19+ <select
20+ v-on:change =" getAll(true)"
21+ v-model =" hotspotSearchId"
22+ class =" form-control"
23+ >
24+ <option
25+ v-for =" hotspot in hotspots"
26+ v-bind:key =" hotspot.id"
27+ v-bind:value =" hotspot.id"
28+ >
29+ {{ hotspot.name }} - {{ hotspot.description }}
1130 </option >
1231 </select >
1332 </div >
1433 </div >
15- <div v-if =" !isLoading" class =" form-group select-search col-xs-12 col-sm-12 col-md-12 col-lg-12" >
34+ <div
35+ v-if =" !isLoading"
36+ class =" form-group select-search col-xs-12 col-sm-12 col-md-12 col-lg-12"
37+ >
1638 <div class =" col-sm-3" >
17- <button class =" btn btn-primary" @click =" getAll()" >{{$t('session.refresh')}}</button >
39+ <button class =" btn btn-primary" @click =" getAll()" >
40+ {{ $t("session.refresh") }}
41+ </button >
1842 </div >
1943 </div >
20- <div v-if =" !isLoading" class =" form-group select-search col-xs-12 col-sm-12 col-md-12 col-lg-12" >
21- <div class =" result-list" >{{total}} {{total == 1 ? $t('result') : $t('results')}}</div >
44+ <div
45+ v-if =" !isLoading"
46+ class =" form-group select-search col-xs-12 col-sm-12 col-md-12 col-lg-12"
47+ >
48+ <div class =" result-list" >
49+ {{ total }} {{ total == 1 ? $t("result") : $t("results") }}
50+ </div >
2251 </div >
2352 <div v-if =" !isLoading" >
2453 <form v-on:submit.prevent =" searchFn($event)" >
25- <input class =" form-control input-lg search-table-input" type =" text" :placeholder =" tableLangsTexts.globalSearchPlaceholder" >
54+ <input
55+ class =" form-control input-lg search-table-input"
56+ type =" text"
57+ :placeholder =" tableLangsTexts.globalSearchPlaceholder"
58+ />
2659 </form >
2760 </div >
28- <div v-if =" !isLoading && isLoadingTable" class =" spinner spinner-lg spinner-adjust" ></div >
29- <vue-good-table v-if =" !isLoadingTable && !isLoading" @perPageChanged =" handlePerPage" :customRowsPerPageDropdown =" [25,50,100]" :perPage =" hotspotPerPage"
30- :columns =" columns" :rows =" rows" :lineNumbers =" false" :defaultSortBy =" {field: 'name', type: 'asc'}" :globalSearch =" true"
31- :globalSearchFn =" searchFn" :paginate =" false" styleClass =" table" :nextText =" tableLangsTexts.nextText" :prevText =" tableLangsTexts.prevText"
32- :rowsPerPageText =" tableLangsTexts.rowsPerPageText" :globalSearchPlaceholder =" tableLangsTexts.globalSearchPlaceholder"
33- :ofText =" tableLangsTexts.ofText" >
61+ <div
62+ v-if =" !isLoading && isLoadingTable"
63+ class =" spinner spinner-lg spinner-adjust"
64+ ></div >
65+ <vue-good-table
66+ v-if =" !isLoadingTable && !isLoading"
67+ @perPageChanged =" handlePerPage"
68+ :customRowsPerPageDropdown =" [25, 50, 100]"
69+ :perPage =" hotspotPerPage"
70+ :columns =" columns"
71+ :rows =" rows"
72+ :lineNumbers =" false"
73+ :defaultSortBy =" { field: 'name', type: 'asc' }"
74+ :globalSearch =" true"
75+ :globalSearchFn =" searchFn"
76+ :paginate =" false"
77+ styleClass =" table"
78+ :nextText =" tableLangsTexts.nextText"
79+ :prevText =" tableLangsTexts.prevText"
80+ :rowsPerPageText =" tableLangsTexts.rowsPerPageText"
81+ :globalSearchPlaceholder =" tableLangsTexts.globalSearchPlaceholder"
82+ :ofText =" tableLangsTexts.ofText"
83+ >
3484 <template slot="table-row" slot-scope="props">
3585 <td class =" fancy" >
36- <a :href =" '#/units/'+ props.row.id" >{{ props.row.name || '-' }}</a >
86+ <a :href =" '#/units/' + props.row.id" >{{ props.row.name || "-" }}</a >
3787 </td >
3888 <td class =" fancy" >{{ props.row.description }}</td >
3989 <td >
4090 <strong >{{ props.row.mac_address }}</strong >
4191 </td >
42- <td class =" fancy" >{{ props.row.uuid || '-' }}</td >
92+ <td class =" fancy" >{{ props.row.uuid || "-" }}</td >
93+ <td class =" fancy" >
94+ <div
95+ v-if =" unitStates[props.row.id].isLoading"
96+ class =" spinner spinner-sm"
97+ ></div >
98+ <span class =" font" v-if =" !unitStates[props.row.id].isLoading"
99+ ><span class =" fa fa-list" ></span
100+ >{{
101+ unitStates[props.row.id].length == 0
102+ ? $t("unit.inactive")
103+ : unitStates[props.row.id].length + " " + $t("unit.active")
104+ }}</span
105+ >
106+ </td >
43107 <td >
44- <unit-action details =" true" :obj =" props.row" :update =" getAll" ></unit-action >
108+ <unit-action
109+ details =" true"
110+ :obj =" props.row"
111+ :update =" getAll"
112+ ></unit-action >
45113 </td >
46114 </template >
47115 </vue-good-table >
48116 <div v-if =" !isLoadingTable && !isLoading" class =" right paginator" >
49117 <span class =" page-count" >
50- <b >{{hotspotPage}}</b > {{tableLangsTexts.ofText}} {{total / hotspotPerPage | adjustPage}} (
51- <b >{{hotspotPerPage}}</b > {{tableLangsTexts.rowsPerPageText}})</span >
52- <button :disabled =" availablePrevPage()" @click =" prevPage()" class =" btn btn-default" >{{tableLangsTexts.prevText}}</button >
53- <button :disabled =" availableNextPage()" @click =" nextPage()" class =" btn btn-default" >{{tableLangsTexts.nextText}}</button >
118+ <b >{{ hotspotPage }}</b > {{ tableLangsTexts.ofText }}
119+ {{ (total / hotspotPerPage) | adjustPage }} (
120+ <b >{{ hotspotPerPage }}</b > {{ tableLangsTexts.rowsPerPageText }})</span
121+ >
122+ <button
123+ :disabled =" availablePrevPage()"
124+ @click =" prevPage()"
125+ class =" btn btn-default"
126+ >
127+ {{ tableLangsTexts.prevText }}
128+ </button >
129+ <button
130+ :disabled =" availableNextPage()"
131+ @click =" nextPage()"
132+ class =" btn btn-default"
133+ >
134+ {{ tableLangsTexts.nextText }}
135+ </button >
54136 </div >
55137 </div >
56138</template >
@@ -59,14 +141,14 @@ import UnitService from "../services/unit";
59141import StorageService from " ../services/storage" ;
60142import HotspotService from " ../services/hotspot" ;
61143import UtilService from " ../services/util" ;
62-
144+ import moment from " moment " ;
63145import UnitAtion from " ../directives/UnitAction" ;
64146
65147export default {
66148 name: " Unit" ,
67149 mixins: [UnitService, StorageService, UtilService, HotspotService],
68150 components: {
69- unitAction: UnitAtion
151+ unitAction: UnitAtion,
70152 },
71153 data () {
72154 return {
@@ -77,28 +159,33 @@ export default {
77159 {
78160 label: this .$i18n .t (" unit.name" ),
79161 field: " name" ,
80- filterable: true
162+ filterable: true ,
81163 },
82164 {
83165 label: this .$i18n .t (" unit.description" ),
84166 field: " description" ,
85- filterable: true
167+ filterable: true ,
86168 },
87169 {
88170 label: this .$i18n .t (" unit.mac_address" ),
89171 field: " mac_address" ,
90- filterable: true
172+ filterable: true ,
91173 },
92174 {
93175 label: this .$i18n .t (" unit.uuid" ),
94176 field: " uuid" ,
95- filterable: true
177+ filterable: true ,
178+ },
179+ {
180+ label: this .$i18n .t (" unit.sessions" ),
181+ field: " sessions" ,
182+ filterable: true ,
96183 },
97184 {
98185 label: this .$i18n .t (" action" ),
99186 field: " " ,
100- sortable: false
101- }
187+ sortable: false ,
188+ },
102189 ],
103190 rows: [],
104191 tableLangsTexts: this .tableLangs (),
@@ -108,7 +195,8 @@ export default {
108195 hotspotPage: 1 ,
109196 total: 0 ,
110197 user: this .get (" loggedUser" ) || null ,
111- searchString: " "
198+ searchString: " " ,
199+ unitStates: {},
112200 };
113201 },
114202 mounted () {
@@ -120,7 +208,7 @@ export default {
120208 }
121209 // get unit list
122210 var context = this ;
123- this .getAllHotspots (function () {
211+ this .getAllHotspots (function () {
124212 context .getAll ();
125213 });
126214 },
@@ -138,7 +226,7 @@ export default {
138226 null ,
139227 null ,
140228 null ,
141- success => {
229+ ( success ) => {
142230 this .hotspots = success .body .data ;
143231 var hsId = this .get (" selected_hotspot_id" ) || this .hotspots [0 ].id ;
144232 if (
@@ -155,7 +243,7 @@ export default {
155243
156244 callback ();
157245 },
158- error => {
246+ ( error ) => {
159247 console .error (error);
160248 callback ();
161249 }
@@ -179,13 +267,47 @@ export default {
179267 this .hotspotPage ,
180268 this .hotspotPerPage ,
181269 encodeURIComponent (this .searchString ),
182- success => {
270+ ( success ) => {
183271 this .rows = success .body .data ;
184272 this .total = success .body .total ;
185273 this .isLoading = false ;
186274 this .isLoadingTable = false ;
275+ var m = moment;
276+ var context = this ;
277+ for (var i = 0 ; i < success .body .data .length ; i++ ) {
278+ var unit = success .body .data [i];
279+ context .unitStates [unit .id ] = {
280+ isLoading: true ,
281+ length: 0 ,
282+ };
283+ this .unitGetStatus (
284+ 1 ,
285+ 25 ,
286+ unit .id ,
287+ m ().subtract (30 , " minutes" ).toISOString (),
288+ m ().toISOString (),
289+ (success ) => {
290+ const url = new URL (success .url );
291+ var parsed = url .pathname ;
292+ var urlParams = new URLSearchParams (parsed);
293+ var unitID = urlParams .get (" unit" );
294+ context .unitStates [unitID].isLoading = false ;
295+ context .unitStates [unitID].length = success .body .data .length ;
296+ context .$forceUpdate ();
297+ },
298+ (error ) => {
299+ var url = new URL (error .url );
300+ var parsed = url .pathname ;
301+ var urlParams = new URLSearchParams (parsed);
302+ var unitID = urlParams .get (" unit" );
303+ context .unitStates [unitID].isLoading = false ;
304+ context .unitStates [unitID].length = 0 ;
305+ context .$forceUpdate ();
306+ }
307+ );
308+ }
187309 },
188- error => {
310+ ( error ) => {
189311 this .isLoading = false ;
190312 this .isLoadingTable = false ;
191313 this .rows = [];
@@ -212,8 +334,8 @@ export default {
212334 },
213335 availableNextPage () {
214336 return this .hotspotPage == Math .ceil (this .total / this .hotspotPerPage );
215- }
216- }
337+ },
338+ },
217339};
218340 </script >
219341<style scoped>
0 commit comments