From a8b8cd7d51cafea253f3e7b2e3d1e76054d97135 Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 6 Feb 2019 18:44:02 -0500 Subject: WIP: settings --- src/CustomAnalyzer.js | 75 ++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 43 deletions(-) (limited to 'src/CustomAnalyzer.js') diff --git a/src/CustomAnalyzer.js b/src/CustomAnalyzer.js index f76fa5e..f140151 100644 --- a/src/CustomAnalyzer.js +++ b/src/CustomAnalyzer.js @@ -38,20 +38,23 @@ const styles = theme => ({ class CustomAnalyzer extends React.Component { state = { patterns: [], - calendars: [], - timeRange: null, + calendars: {}, + startDate: null, + endDate: null, patternGraphData: default_chart_data, calendarGraphData: default_chart_data, - activePattern: null }; constructor(props) { super(props); this.msgClient = new MsgClient('main'); - this.msgClient.sendMsg({ type: msgType.getPatterns }).then(msg => { + this.msgClient.sendMsg({ + type: msgType.getPatterns, + data: { id: 'analyze' } + }).then(msg => { this.setState({ patterns: msg.data.map(p => PatternEntry.revive(p)) }); }); - this.msgClient.sendMsg({ type: msgType.getCalendars }).then(msg => { + this.msgClient.sendMsg({ type: msgType.getCalendars, data: { enabledOnly: true }}).then(msg => { this.setState({ calendars: msg.data }); }); } @@ -59,8 +62,10 @@ class CustomAnalyzer extends React.Component { updatePattern = (field, idx, value) => { let patterns = this.state.patterns; patterns[idx][field] = value; - this.setState({ patterns }); - this.msgClient.sendMsg({ type: msgType.updatePatterns, data: patterns }); + this.msgClient.sendMsg({ + type: msgType.updatePatterns, + data: { id: 'analyze', patterns } + }).then(() => this.setState({ patterns })); }; removePattern = idx => { @@ -68,26 +73,27 @@ class CustomAnalyzer extends React.Component { patterns.splice(idx, 1); for (let i = 0; i < patterns.length; i++) patterns[i].idx = i; - this.setState({ patterns }); - this.msgClient.sendMsg({ type: msgType.updatePatterns, data: patterns }); + this.msgClient.sendMsg({ + type: msgType.updatePatterns, + data: { id: 'analyze', patterns } + }).then(() => this.setState({ patterns })); }; newPattern = () => { let patterns = [PatternEntry.defaultPatternEntry(0), ...this.state.patterns]; for (let i = 1; i < patterns.length; i++) patterns[i].idx = i; - this.setState({ patterns }); - this.msgClient.sendMsg({ type: msgType.updatePatterns, data: patterns }); + this.msgClient.sendMsg({ + type: msgType.updatePatterns, + data: { id: 'analyze', patterns } + }).then(() => this.setState({ patterns })); }; loadPatterns = patterns => { - this.setState({ patterns }); - this.msgClient.sendMsg({ type: msgType.updatePatterns, data: patterns }); - }; - - loadCalendars = calendars => { - this.setState({ calendars }); - this.msgClient.sendMsg({ type: msgType.updateCalendars, data: calendars }); + this.msgClient.sendMsg({ + type: msgType.updatePatterns, + data: { id: 'analyze', patterns } + }).then(() => this.setState({ patterns })); }; getCalEvents = (id, start, end) => { @@ -160,27 +166,10 @@ class CustomAnalyzer extends React.Component { }); }; - load = () => { - let colors = gapi.getAuthToken().then(gapi.getColors).then(color => { - return color.calendar; - }); - let cals = gapi.getAuthToken().then(gapi.getCalendars); - Promise.all([colors, cals]).then(([colors, items]) => { - var cals = {}; - items.forEach(item => { - cals[item.id] = { - name: item.summary, - color: colors[item.colorId], - //cal: new gapi.GCalendar(item.id, item.summary) - }}); - this.loadCalendars(cals); - this.loadPatterns(items.map((item, idx) => { - return new PatternEntry(item.summary, idx, - new Pattern(item.id, false, item.summary, item.summary), - Pattern.anyPattern()); - })); - }); - }; + reset = () => { + this.loadPatterns([]); + this.setState({ startDate: null, endDate: null }); + } render() { const { classes } = this.props; @@ -191,7 +180,7 @@ class CustomAnalyzer extends React.Component { - Event Patterns + Analyzed Events this.newPattern()}> @@ -224,12 +213,12 @@ class CustomAnalyzer extends React.Component { - + - + @@ -237,7 +226,7 @@ class CustomAnalyzer extends React.Component { - Graph + Results