This repository has been archived by the owner on Jun 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
/
App.vue
144 lines (126 loc) · 4.13 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
# Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0.
*/
<template>
<div id="app">
<div id="userProfile">
<userprofile ref="userprofile" @logout="logout"></userprofile>
</div>
<div id="reportContainer">
<report ref="report"> </report>
</div>
<lex-web-ui v-on:updateLexState="onUpdateLexState"></lex-web-ui>
</div>
</template>
<script>
/* eslint-disable prefer-arrow-callback, no-var, no-use-before-define */
/* eslint-disable prefer-template, no-use-before-define, prefer-template */
/* eslint-disable no-undef, comma-dangle, no-multi-spaces, no-unused-vars, space-before-blocks */
/* eslint-disable no-unsafe-negation, no-shadow, no-extra-semi, eqeqeq, quotes */
/* eslint-disable space-before-function-paren, wrap-iife, func-names, max-len, no-alert, object-shorthand */
import Vue from 'vue';
import Vuex from 'vuex';
import Vuetify from 'vuetify';
import AWS from 'aws-sdk';
import LexRuntime from 'aws-sdk/clients/lexruntime';
import Polly from 'aws-sdk/clients/polly';
import { Plugin as LexWebUi, Store as LexWebUiStore } from 'aws-lex-web-ui';
import Report from './components/Report';
import UserProfile from './components/UserProfile';
import model from './assets/TrackingBotModel.json';
import Logger from './logger';
Vue.use(Vuetify);
Vue.use(Vuex);
/**
* defined in index.html for use in multiple components
*/
const poolId = localStorage.getItem('poolid');
const region = localStorage.getItem('awsregionname');
const idtoken = localStorage.getItem('idtokenjwt');
const poolName = localStorage.getItem('poolname');
const noauth = localStorage.getItem('noauth');
const config = {
cognito: { poolId },
lex: { botName: appBotName, initialText: model.bot.ui.initialText, initialSpeechInstruction: model.bot.ui.initialSpeechInstruction },
ui: { toolbarLogo: '', toolbarTitle: model.bot.ui.titleBar },
};
let credentials;
const logins = {};
logins[poolName] = idtoken;
if (noauth === 'true') {
credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: poolId,
}, { region });
} else {
credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: poolId,
Logins: logins,
}, { region });
}
const localConfig = new AWS.Config({ region, credentials });
const store = new Vuex.Store(LexWebUiStore);
const lexRuntimeClient = new LexRuntime(localConfig);
const pollyClient = new Polly(localConfig);
Vue.component('report', Report);
Vue.component('userprofile', UserProfile);
Vue.use(LexWebUi, { config, awsConfig: localConfig, lexRuntimeClient, pollyClient, store });
export default {
name: 'app',
data() {
return {
};
},
props: ['awsconfig'],
store: store,
beforeCreate() {
},
mounted() {
Logger.debug('awsconfig pass as properties: ' + JSON.stringify(this.awsconfig, null, 2));
Logger.debug('region', this.awsconfig.region);
const child = this.$refs.report;
child.setCredentials(this.awsconfig.credentials);
child.performUpdate(this.awsconfig.credentials, config.lex.botName, region);
Logger.info('App Vue Mounted');
},
methods: {
onUpdateLexState(lexState) {
Logger.debug('handle update: ' + JSON.stringify(lexState, null, 2));
if (lexState.dialogState === 'Fulfilled') {
const child = this.$refs.report;
child.performUpdate(this.awsconfig.credentials, config.lex.botName, region);
}
},
logout () {
Logger.debug('logout');
window.location.href = 'index.html?dosignout';
}
},
};
</script>
<style>
@import '../node_modules/roboto-fontface/css/roboto/roboto-fontface.css';
@import '../node_modules/material-design-icons/iconfont/material-icons.css';
@import '../node_modules/vuetify/dist/vuetify.min.css';
@import '../node_modules/aws-lex-web-ui/dist/lex-web-ui.css';
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 15px;
}
#userProfile {
width: 100%;
margin-top: 55px;
}
#lex-web {
width: 35%;
height: 85%;
position: absolute;
right: 0px;
top: 0px;
margin-right: 10px;
}
</style>