Skip to content

Commit

Permalink
chore: checklist
Browse files Browse the repository at this point in the history
Signed-off-by: ivelin <[email protected]>
  • Loading branch information
ivelin committed Nov 16, 2021
1 parent f88dc75 commit 1e0fe25
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 21 deletions.
10 changes: 10 additions & 0 deletions src/remote/edgeAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ export class EdgeAPI {
return response
}

async testNotifications () {
const apiRoot = this._getRootURL()
const request = {
url: `${apiRoot}notifications/test`
}
const response = await this._getJSON(request)
console.debug('testNotifications() received response', { request }, { response })
return response
}

async auth () {
console.debug('PEER_AUTHENTICATE auth() start')
const authURL = `${API_SCHEMA}://${API_HOST}:${API_PORT}/`
Expand Down
9 changes: 8 additions & 1 deletion src/store/mydevices.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,20 @@ const actions = {
console.debug('Updating display name: ', { peerID, displayName })
if (displayName) {
await localdb.myDevices.update(peerID, { displayName: displayName })
console.debug('saved new display name for peer ID', { peerID, displayName })
console.debug('saved localdb new display name for peer ID', { peerID, displayName })
} else {
throw new Error('Device Display Name cannot have an empty value')
}
// refresh vuex state
await dispatch('syncState')
},
async updateNotificationsEnabled ({ state, dispatch }, { peerID, enabled }) {
console.debug('Updating notifications enabled state: ', { peerID, enabled })
await localdb.myDevices.update(peerID, { notificationsEnabled: enabled })
console.debug('saved in localdb new notifications enabled state for peer ID', { peerID, enabled })
// refresh vuex state
await dispatch('syncState')
},
/**
*
* Load all stored EdgeDeviceCard objects into local state object
Expand Down
25 changes: 19 additions & 6 deletions src/views/DeviceCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@
</v-list-item-avatar>
<v-list-item-content>
<v-switch
v-model="enableNotifications"
:label="`Notifications ${ enableNotifications ? &quot;On&quot; : &quot;Off&quot; }`"
v-model="notificationsEnabled"
:label="`Notifications ${ notificationsEnabled ? &quot;On&quot; : &quot;Off&quot; }`"
:disabled="!isEdgeConnected"
@change="onEnableNotifications"
/>
</v-list-item-content>
<v-list-item-action
Expand Down Expand Up @@ -258,7 +259,7 @@ export default {
counter: value => (!!value && value.length >= 5 && value.length <= 20) || 'Min 5 and Max 20 characters'
},
forgetDeviceDialog: false,
enableNotifications: false,
notificationsEnabled: false,
breadcrumbs: [
{
text: 'Settings',
Expand All @@ -279,6 +280,7 @@ export default {
// If a connection to the edge device is already established
// let's pull the latest info from it in case there are changes
// this UI client does not know about yet.
this.notificationsEnabled = this.currentDeviceCard.notificationsEnabled
if (this.isEdgeConnected) {
await this.fetchEdgeDetails()
}
Expand All @@ -288,6 +290,7 @@ export default {
deleteCurrentDeviceConnection: REMOVE_REMOTE_PEER_ID,
forgetDeviceCard: 'myDevices/forget',
updateDisplayName: 'myDevices/updateDisplayName',
updateNotificationsEnabled: 'myDevices/updateNotificationsEnabled',
updateFromRemote: 'myDevices/updateFromRemote',
setCurrentDevice: 'myDevices/setCurrent',
peerConnect: PEER_CONNECT
Expand Down Expand Up @@ -332,6 +335,18 @@ export default {
}
return updated
},
async onEnableNotifications () {
try {
this.isSyncing = true
await this.pnp.edgeAPI.enableNotifications(this.notificationsEnabled)
await this.updateNotificationsEnabled({ peerID: this.edgePeerId, enabled: this.notificationsEnabled })
} catch (e) {
this.edgeDeviceError = 'Error updating notifications settings. Edge device offline or has outdated API.'
console.error('Exception calling onEnableNotifications()', { e })
} finally {
this.isSyncing = false
}
},
async connectToEdgeDevice () {
await this.peerConnect(this.edgePeerId)
},
Expand Down Expand Up @@ -371,6 +386,7 @@ export default {
isEdgeConnected: async function (isConnected) {
if (isConnected) {
await this.fetchEdgeDetails()
this.notificationsEnabled = this.currentDeviceCard.notificationsEnabled
}
},
isPeerConnectionError: async function (isError) {
Expand All @@ -395,9 +411,6 @@ export default {
this.edgeVersion = ''
this.edgeDisplayName = ''
}
},
enableNotifications: async function (newVal, oldVal) {
await this.pnp.edgeAPI.enableNotifications(newVal)
}
}
}
Expand Down
68 changes: 54 additions & 14 deletions src/views/DeviceNotificationsConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,29 @@
cols="12"
class="pa-0 ma-0 fill-height"
>
<amb-banner
banner-class="text-left"
icon="cloud-check-outline"
text="Device connected!"
data-cy="edge-device-connected"
ref="edge-device-connected"
/>
<v-card
class="mx-auto text-left"
flat
>
<v-list
two-line
>
<v-list-item>
<!-- Notifications list item -->
<v-list-item-avatar>
<v-icon>
mdi-bell-outline
</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-switch
v-model="notificationsEnabled"
:label="`Notifications ${ notificationsEnabled ? &quot;On&quot; : &quot;Off&quot; }`"
:disabled="!isEdgeConnected"
@change="onEnableNotifications"
/>
</v-list-item-content>
</v-list-item>
<amb-list-item
ref="list-item-notificationsProvider"
data-cy="list-item-notificationsProvider"
Expand Down Expand Up @@ -102,12 +111,20 @@
</v-card-text>
<v-card-actions>
<v-btn
@click="testNotifications"
:disabled="isEdgeConnecting"
@click="onTestNotifications"
:disabled="!notificationsEnabled"
color="primary"
>
Test
</v-btn>
<v-fade-transition>
<v-icon
large
v-if="testSent"
>
check
</v-icon>
</v-fade-transition>
<v-spacer />
</v-card-actions>
</v-card>
Expand Down Expand Up @@ -151,7 +168,6 @@ import {
export default {
components: {
AmbBanner: () => import('@/components/shared/Banner.vue'),
AmbListItem: () => import('@/components/shared/ListItem.vue'),
AmbAppFrame: () => import('@/components/AppFrame.vue')
},
Expand All @@ -167,6 +183,7 @@ export default {
},
forgetDeviceDialog: false,
notificationsEnabled: false,
testSent: false,
breadcrumbs: [
{
text: 'Settings',
Expand All @@ -188,9 +205,11 @@ export default {
created () {
},
async mounted () {
this.notificationsEnabled = this.currentDeviceCard.notificationsEnabled
},
methods: {
...mapActions({
updateNotificationsEnabled: 'myDevices/updateNotificationsEnabled'
}),
async onIftttKeyChanged (newIftttKey) {
console.debug(`onIftttKeyChanged(): ${newIftttKey}`)
Expand All @@ -207,16 +226,37 @@ export default {
updated = true
} catch (e) {
this.edgeDeviceError = 'Error updating IFTTT Key. Edge device offline or has outdated API.'
console.error('Exception calling setIftttKey()', { e })
console.error('Exception thrown by setIftttKey()', { e })
} finally {
this.isSyncing = false
}
}
return updated
},
async testNotifications () {
// TODO
// remote API call to edge device: /api/notifications/test
async onTestNotifications () {
try {
this.isSyncing = true
await this.pnp.edgeAPI.testNotifications()
} catch (e) {
this.edgeDeviceError = 'Problem occured while sending test notification.'
console.error('Exception thrown by testNotifications()', { e })
} finally {
this.isSyncing = false
this.testSent = true
setTimeout(() => { this.testSent = false }, 1000)
}
},
async onEnableNotifications () {
try {
this.isSyncing = true
await this.pnp.edgeAPI.enableNotifications(this.notificationsEnabled)
await this.updateNotificationsEnabled({ peerID: this.edgePeerId, enabled: this.notificationsEnabled })
} catch (e) {
this.edgeDeviceError = 'Error updating notifications settings. Edge device offline or has outdated API.'
console.error('Exception thrown by onEnableNotifications()', { e })
} finally {
this.isSyncing = false
}
}
},
computed: {
Expand Down

0 comments on commit 1e0fe25

Please sign in to comment.