@@ -36,22 +36,39 @@ interface QueryOptions {
3636
3737// initial state
3838const _state = {
39- top_apps : [ ] ,
40- top_titles : [ ] ,
41-
42- browser_duration : [ ] ,
43- top_domains : [ ] ,
44- top_urls : [ ] ,
45-
46- editor_duration : [ ] ,
47- top_editor_files : [ ] ,
48- top_editor_languages : [ ] ,
49- top_editor_projects : [ ] ,
50-
51- top_categories : [ ] ,
52- active_events : [ ] ,
53- active_duration : 0 ,
54- active_history : { } ,
39+ window : {
40+ available : false ,
41+ top_apps : [ ] ,
42+ top_titles : [ ] ,
43+ } ,
44+
45+ browser : {
46+ available : false ,
47+ duration : [ ] ,
48+ top_domains : [ ] ,
49+ top_urls : [ ] ,
50+ } ,
51+
52+ editor : {
53+ available : false ,
54+ duration : [ ] ,
55+ top_files : [ ] ,
56+ top_languages : [ ] ,
57+ top_projects : [ ] ,
58+ } ,
59+
60+ category : {
61+ available : false ,
62+ top : [ ] ,
63+ } ,
64+
65+ active : {
66+ available : false ,
67+ duration : 0 ,
68+ events : [ ] ,
69+ history : { } ,
70+ } ,
71+
5572 query_options : {
5673 browser_buckets : 'all' ,
5774 editor_buckets : 'all' ,
@@ -84,8 +101,8 @@ const getters = {
84101 getActiveHistoryAroundTimeperiod : state => ( timeperiod : TimePeriod ) => {
85102 const periods = timeperiodStrsAroundTimeperiod ( timeperiod ) ;
86103 const _history = periods . map ( tp => {
87- if ( _ . has ( state . active_history , tp ) ) {
88- return state . active_history [ tp ] ;
104+ if ( _ . has ( state . active . history , tp ) ) {
105+ return state . active . history [ tp ] ;
89106 } else {
90107 // A zero-duration placeholder until new data has been fetched
91108 return [ { timestamp : moment ( tp . split ( '/' ) [ 0 ] ) . format ( ) , duration : 0 , data : { } } ] ;
@@ -109,19 +126,16 @@ const actions = {
109126 await dispatch ( 'get_buckets' , query_options ) ;
110127
111128 // TODO: These queries can actually run in parallel, but since server won't process them in parallel anyway we won't.
129+ await dispatch ( 'set_available' , query_options ) ;
112130
113- if ( state . buckets . afk_buckets . length > 0 && state . buckets . window_buckets . length > 0 ) {
131+ if ( state . window . available ) {
114132 await dispatch ( 'query_window' , query_options ) ;
115133 } else {
116134 console . log ( 'Cannot call query_window as we are missing either an afk or window bucket' ) ;
117135 await dispatch ( 'query_window_empty' , query_options ) ;
118136 }
119137
120- if (
121- state . buckets . afk_buckets . length > 0 &&
122- state . buckets . window_buckets . length > 0 &&
123- state . buckets . browser_buckets . length > 0
124- ) {
138+ if ( state . browser . available ) {
125139 await dispatch ( 'query_browser' , query_options ) ;
126140 } else {
127141 console . log (
@@ -130,14 +144,14 @@ const actions = {
130144 await dispatch ( 'query_browser_empty' , query_options ) ;
131145 }
132146
133- if ( state . buckets . afk_buckets . length > 0 ) {
147+ if ( state . active . available ) {
134148 await dispatch ( 'query_active_history' , query_options ) ;
135149 } else {
136150 console . log ( 'Cannot call query_active_history as we do not have an afk bucket' ) ;
137151 await dispatch ( 'query_active_history_empty' , query_options ) ;
138152 }
139153
140- if ( state . buckets . editor_buckets . length > 0 ) {
154+ if ( state . editor . available ) {
141155 await dispatch ( 'query_editor' , query_options ) ;
142156 } else {
143157 console . log ( 'Cannot call query_editor as we do not have any editor buckets' ) ;
@@ -217,7 +231,7 @@ const actions = {
217231
218232 async query_active_history ( { commit, state } , { timeperiod } : QueryOptions ) {
219233 const periods = timeperiodStrsAroundTimeperiod ( timeperiod ) . filter ( tp_str => {
220- return ! _ . includes ( state . active_history , tp_str ) ;
234+ return ! _ . includes ( state . active . history , tp_str ) ;
221235 } ) ;
222236 const bucket_id_afk = state . buckets . afk_buckets [ 0 ] ;
223237 const data = await this . _vm . $aw . query ( periods , queries . dailyActivityQuery ( bucket_id_afk ) ) ;
@@ -233,6 +247,23 @@ const actions = {
233247 commit ( 'query_active_history_completed' , data ) ;
234248 } ,
235249
250+ async set_available ( { commit, state } ) {
251+ const window_available =
252+ state . buckets . afk_buckets . length > 0 && state . buckets . window_buckets . length > 0 ;
253+ const browser_available =
254+ state . buckets . afk_buckets . length > 0 &&
255+ state . buckets . window_buckets . length > 0 &&
256+ state . buckets . browser_buckets . length > 0 ;
257+ const active_available = state . buckets . afk_buckets . length > 0 ;
258+ const editor_available = state . buckets . editor_buckets . length > 0 ;
259+ commit ( 'set_available' , {
260+ window_available : window_available ,
261+ browser_available : browser_available ,
262+ active_available : active_available ,
263+ editor_available : editor_available ,
264+ } ) ;
265+ } ,
266+
236267 async get_buckets ( { commit, rootGetters } , { host } ) {
237268 const buckets = {
238269 afk_buckets : rootGetters [ 'buckets/afkBucketsByHost' ] ( host ) ,
@@ -410,54 +441,62 @@ const mutations = {
410441 state . query_options = query_options ;
411442
412443 // Resets the store state while waiting for new query to finish
413- state . top_apps = null ;
414- state . top_titles = null ;
444+ state . window . top_apps = null ;
445+ state . window . top_titles = null ;
415446
416- state . browser_duration = 0 ;
447+ state . browser . duration = 0 ;
417448 state . top_domains = null ;
418449 state . top_urls = null ;
419450
420- state . editor_duration = 0 ;
421- state . top_editor_files = null ;
422- state . top_editor_languages = null ;
423- state . top_editor_projects = null ;
451+ state . editor . duration = 0 ;
452+ state . editor . top_files = null ;
453+ state . editor . top_languages = null ;
454+ state . editor . top_projects = null ;
455+
456+ state . category . top = null ;
424457
425- state . top_categories = null ;
426- state . active_duration = null ;
427- state . active_events = null ;
458+ state . active . duration = null ;
459+ state . active . events = null ;
460+
461+ state . active . history = { } ;
462+ } ,
428463
429- state . active_history = { } ;
464+ set_available ( state , data ) {
465+ state . window . available = data [ 'window_available' ] ;
466+ state . browser . available = data [ 'browser_available' ] ;
467+ state . active . available = data [ 'active_available' ] ;
468+ state . editor . available = data [ 'editor_available' ] ;
469+ state . category . available = data [ 'window_available' ] ;
430470 } ,
431471
432472 query_window_completed ( state , data ) {
433- state . top_apps = data [ 'app_events' ] ;
434- state . top_titles = data [ 'title_events' ] ;
435- state . top_categories = data [ 'cat_events' ] ;
436- state . active_duration = data [ 'duration' ] ;
437- state . app_chunks = data [ 'app_chunks' ] ;
438- state . active_events = data [ 'active_events' ] ;
473+ state . window . top_apps = data [ 'app_events' ] ;
474+ state . window . top_titles = data [ 'title_events' ] ;
475+ state . category . top = data [ 'cat_events' ] ;
476+ state . active . duration = data [ 'duration' ] ;
477+ state . active . events = data [ 'active_events' ] ;
439478 } ,
440479
441480 query_browser_completed ( state , data ) {
442- state . top_domains = data [ 'domains' ] ;
443- state . top_urls = data [ 'urls' ] ;
444- state . browser_duration = data [ 'duration' ] ;
481+ state . browser . top_domains = data [ 'domains' ] ;
482+ state . browser . top_urls = data [ 'urls' ] ;
483+ state . browser . duration = data [ 'duration' ] ;
445484
446485 // FIXME: This one might take up a lot of size in the request, move it to a seperate request
447486 // (or remove entirely, since we have the other timeline now)
448487 state . web_chunks = data [ 'chunks' ] ;
449488 } ,
450489
451490 query_editor_completed ( state , data ) {
452- state . editor_duration = data [ 'duration' ] ;
453- state . top_editor_files = data [ 'files' ] ;
454- state . top_editor_languages = data [ 'languages' ] ;
455- state . top_editor_projects = data [ 'projects' ] ;
491+ state . editor . duration = data [ 'duration' ] ;
492+ state . editor . top_files = data [ 'files' ] ;
493+ state . editor . top_languages = data [ 'languages' ] ;
494+ state . editor . top_projects = data [ 'projects' ] ;
456495 } ,
457496
458497 query_active_history_completed ( state , { active_history } ) {
459- state . active_history = {
460- ...state . active_history ,
498+ state . active . history = {
499+ ...state . active . history ,
461500 ...active_history ,
462501 } ;
463502 } ,
0 commit comments