aboutsummaryrefslogblamecommitdiff
path: root/src/Analyze.js
blob: 0985b2da58269aea555e4900ebdec6237b17e548 (plain) (tree)
1
2
3
4
5
6
7
8






                                                      
                                                             










                                                         
                                                        
                                          
                                  
                                   


                                                
                                                         
 





                                             
                                       

                     


                        

                                              

                               


                                            




                                               
 



                                      
                                                                                    
           




                                       

                                                   
 

                                                                                             
 
                                          

     
                                

                                         
                                                                             
                                                   

      





                                            




                                                 
                                    





                                                                                     
                                    















                                                                               
                                                                                  



                                                                 




                                                        
           
     
 
                   
















                                                                                              
     
 








                                                                                          












                                                                         




                                          




                                                          




                                                        



                                                                                 
                                               





























                                                                                                    
                                                      
                                           
                                                                                                                            

                                            
                                                      
                                           
                                                                                                                   

                                            




                                                                                                                       




                                                                         
                               
                                 
                                    







                                                                          
                     


                                         
                                           
import React from 'react';
import PropTypes from 'prop-types';
import 'react-dates/initialize';
import 'react-dates/lib/css/_datepicker.css';
import { DateRangePicker } from 'react-dates';
import { withStyles } from '@material-ui/core/styles';
import cyan from '@material-ui/core/colors/cyan';
import deepOrange from '@material-ui/core/colors/deepOrange';
import CssBaseline from '@material-ui/core/CssBaseline';
import Typography from '@material-ui/core/Typography';
import Button from '@material-ui/core/Button';
import FormControl from '@material-ui/core/FormControl';
import FormGroup from '@material-ui/core/FormGroup';
import Grid from '@material-ui/core/Grid';
import AddCircleIcon from '@material-ui/icons/AddCircle';
import IconButton from '@material-ui/core/IconButton';
import * as gapi from './gapi';
import { msgType, MsgClient } from './msg';
import { Pattern, PatternEntry } from './pattern';
import { AnalyzePieChart, getChartData } from './Chart';
import PatternTable from './PatternTable';
import Snackbar from './Snackbar';
import AlertDialog from './Dialog';

const default_chart_data = [
    {name: 'Work', value: 10, color: cyan[300]},
    {name: 'Wasted', value: 10, color: deepOrange[300]}];

const styles = theme => ({
    buttonSpacer: {
        marginBottom: theme.spacing.unit * 4,
    },
});

class Analyze extends React.Component {
    state = {
        patterns: [],
        calendars: {},
        startDate: null,
        endDate: null,
        patternGraphData: default_chart_data,
        calendarGraphData: default_chart_data,
        snackBarOpen: false,
        snackBarMsg: 'unknown',
        snackBarVariant: 'error',
        dialogOpen: false,
        dialogMsg: {title: '', message: ''},
    };

    constructor(props) {
        super(props);
        this.msgClient = new MsgClient('main');

        this.msgClient.sendMsg({
            type: msgType.getPatterns,
            data: { id: 'analyze' }
        }).then(msg => {
            this.setState({ patterns: msg.data.map(p => PatternEntry.inflate(p)) });
        });

        this.msgClient.sendMsg({
            type: msgType.getCalendars,
            data: { enabledOnly: true }
        }).then(msg => {
            this.setState({ calendars: msg.data });
        });

        gapi.getLoggedIn().then(b => !b &&
            this.handleSnackbarOpen('Not logged in. Operating in offline mode.', 'warning'));

        this.dialogPromiseResolver = null;
    }

    loadPatterns = patterns => {
        this.msgClient.sendMsg({
            type: msgType.updatePatterns,
            data: { id: 'analyze', patterns: patterns.map(p => p.deflate()) }