Skip to content

Commit

Permalink
Merge pull request #349 from Mehradml/silabconsultants
Browse files Browse the repository at this point in the history
Resolving some ui and backend issues
  • Loading branch information
tecimovic authored Jan 3, 2022
2 parents 078c461 + f87e24b commit 908aa43
Show file tree
Hide file tree
Showing 20 changed files with 464 additions and 161 deletions.
4 changes: 3 additions & 1 deletion src-electron/ui/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const about = require('../main-process/about')
const commonUrl = require('../../src-shared/common-url.js')
const browserApi = require('./browser-api.js')
const rendApi = require('../../src-shared/rend-api.js')

let menuIsShown = true;
const newConfiguration = 'New Configuration'

const template = (httpPort) => [
Expand Down Expand Up @@ -352,6 +352,8 @@ function fileOpen(filePaths, httpPort) {
* @param {*} port
*/
function initMenu(httpPort) {
menuIsShown = !menuIsShown
if(!menuIsShown) return Menu.setApplicationMenu(null)
const menu = Menu.buildFromTemplate(template(httpPort))
Menu.setApplicationMenu(menu)
}
Expand Down
6 changes: 6 additions & 0 deletions src-electron/ui/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,11 @@ export function windowCreate(port: number, args?: WindowCreateArgs) {
}
}
)
w.webContents.on('before-input-event',(e,input)=>{
if(input.type === "keyUp" && input.key.toLowerCase()==="alt"){
console.log('key pressed')
menu.initMenu(port)
}
})
return w
}
36 changes: 29 additions & 7 deletions src-electron/util/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ async function typeSize(db, zclPackageId, type) {
* @returns Promise that resolves into the size of the attribute.
*/
async function typeSizeAttribute(db, zclPackageId, at, defaultValue = null) {
let sizeType;
let sizeType
if (at.typeInfo) {
if (!at.typeInfo.atomicType) {
if (at.storage != dbEnum.storageOption.external) {
throw new Error(
`ERROR: Unknown size for non-external attribute: ${at.label} / ${at.code}`
);
)
}
return 0;
return 0
}
sizeType = at.typeInfo.atomicType;
sizeType = at.typeInfo.atomicType
} else {
sizeType = at.type;
sizeType = at.type
}
let size = await queryZcl.selectAtomicSizeFromType(db, zclPackageId, sizeType)

Expand Down Expand Up @@ -179,14 +179,35 @@ function isFloat(type) {
}
}

/**
* Returns true if a given ZCL type is a signed integer.
* @param {*} type
* @returns true if type is signed integer, false otherwise
*/
function isSignedInteger(type) {
switch (type) {
case 'int8s':
case 'int16s':
case 'int24s':
case 'int32s':
case 'int40s':
case 'int48s':
case 'int56s':
case 'int64s':
return true
default:
return false
}
}

/**
* Checks if type is a one-byte lengh string.
*
* @param {*} type
* @returns true if the said type is a string prefixed by one byte length
*/
function isOneBytePrefixedString(type) {
type = type.toLowerCase();
type = type.toLowerCase()
return type == 'char_string' || type == 'octet_string'
}
/**
Expand All @@ -196,7 +217,7 @@ function isOneBytePrefixedString(type) {
* @returns true if the said type is a string prefixed by two byte length
*/
function isTwoBytePrefixedString(type) {
type = type.toLowerCase();
type = type.toLowerCase()
return type == 'long_char_string' || type == 'long_octet_string'
}

Expand All @@ -208,3 +229,4 @@ exports.isTwoBytePrefixedString = isTwoBytePrefixedString
exports.convertToCliType = convertToCliType
exports.isString = isString
exports.isFloat = isFloat
exports.isSignedInteger = isSignedInteger
16 changes: 11 additions & 5 deletions src-electron/validation/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ async function validateNoDuplicateEndpoints(
endpointIdentifier,
sessionRef
) {
let count = await queryConfig.selectCountOfEndpointsWithGivenEndpointIdentifier(
db,
endpointIdentifier,
sessionRef
)
let count =
await queryConfig.selectCountOfEndpointsWithGivenEndpointIdentifier(
db,
endpointIdentifier,
sessionRef
)
return count.length <= 1
}

Expand All @@ -74,6 +75,11 @@ function validateSpecificAttribute(endpointAttribute, attribute) {
//Interpreting float values
if (!checkAttributeBoundsFloat(attribute, endpointAttribute))
defaultAttributeIssues.push('Out of range')
} else if (types.isSignedInteger(attribute.type)) {
if (!isValidSignedNumberString(endpointAttribute.defaultValue))
defaultAttributeIssues.push('Invalid Integer')
if (!checkAttributeBoundsInteger(attribute, endpointAttribute))
defaultAttributeIssues.push('Out of range')
} else {
if (!isValidNumberString(endpointAttribute.defaultValue))
defaultAttributeIssues.push('Invalid Integer')
Expand Down
22 changes: 22 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ limitations under the License.
<div id="q-app">
<q-ajax-bar color="grey" />
<router-view />
<q-btn
@click="viewExceptions"
class="fixed-bottom-right q-ma-lg"
flat
v-if="showExceptionIcon"
>
<q-icon name="warning" style="font-size: 2.5em; color: red" />
</q-btn>
</div>
</template>

Expand Down Expand Up @@ -56,6 +64,11 @@ function initLoad(store) {

export default {
name: 'App',
computed: {
showExceptionIcon() {
return this.$store.state.zap.showExceptionIcon
},
},
methods: {
setThemeMode(theme) {
// DO NOT call observable.setObservableAttribute(rendApi.observable.themeData) inside this function.
Expand All @@ -78,6 +91,15 @@ export default {
this.$q.loading.hide()
}
},
viewExceptions() {
this.$router.push('/')
if (!this.$store.state.zap.showDevTools)
this.$store.dispatch('zap/updateShowDevTools')
if (!this.$store.state.zap.isExceptionsExpanded)
this.$store.commit('zap/expandedExceptionsToggle')
this.$store.dispatch('zap/setDefaultUiMode', 'general')
this.$store.commit('zap/toggleShowExceptionIcon', false)
},
},
mounted() {
let theme = observable.getObservableAttribute(rendApi.observable.themeData)
Expand Down
13 changes: 12 additions & 1 deletion src/boot/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import axios from 'axios'
import { v4 as uuidv4 } from 'uuid'
import restApi from '../../src-shared/rest-api.js'
import * as Util from '../util/util.js'
import store from '../store/index.js'

const vuex = store()

Vue.prototype.$axios = axios({ withCredentials: true })

Expand Down Expand Up @@ -133,7 +136,15 @@ function serverPost(url, data, config = null) {
if (log) console.log(`POST → : ${url}, ${data}`)
return axios['post'](fillUrl(url), data, fillConfig(config))
.then((response) => processResponse('POST', url, response))
.catch((error) => console.log(error))
.catch((error) => {
vuex.dispatch('zap/updateExceptions', {
url,
method: 'post',
payload: data,
statusCode: error.response.status,
message: error.response.data.message,
})
})
}

/**
Expand Down
53 changes: 53 additions & 0 deletions src/components/Exceptions.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!--
Copyright (c) 2008,2020 Silicon Labs.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<template>
<div class="q-pa-md">
<q-list
bordered
separator
v-for="(item, index) in exceptions"
v-bind:key="index"
>
<q-item class="column">
<div><spam class="q-mr-sm text-bold">URL:</spam> {{ item.url }}</div>
<div>
<spam class="q-mr-sm text-bold">Method:</spam> {{ item.method }}
</div>
<div v-if="item.payload !== null">
<spam class="q-mr-sm text-bold">Payload:</spam> {{ item.payload }}
</div>
<div>
<spam class="q-mr-sm text-bold">Status Code:</spam>
{{ item.statusCode }}
</div>
<div>
<spam class="q-mr-sm text-bold">Message:</spam> {{ item.message }}
</div>
</q-item>
</q-list>
</div>
</template>

<script>
export default {
name: 'Exceptions',
computed: {
exceptions() {
return this.$store.state.zap.exceptions
},
},
}
</script>
16 changes: 10 additions & 6 deletions src/components/ZclAttributeReportingManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,16 @@ export default {
return !this.editableAttributesReporting[attributeId]
},
displayAttrWarning(row) {
// TODO display proper warnings
let reporableValue = this.selectionReportableChange[
this.hashAttributeIdClusterId(row.id, this.selectedCluster.id)
];
let typeMaxLimit = Number(row.type.match(/int(\d+)/i)?.[1]);
return typeMaxLimit && reporableValue && reporableValue>Math.pow(2,typeMaxLimit) ;
let indexOfValue = this.selectedReporting.indexOf(
this.hashAttributeIdClusterId(row.id, this.selectedCluster.id)
)
let isDisabled
if (indexOfValue === -1) {
isDisabled = true
} else {
isDisabled = false
}
return isDisabled && row.isReportable ;
},
isAttributeRequired(attribute) {
// TODO set by reporting required
Expand Down
1 change: 1 addition & 0 deletions src/components/ZclDomainClusterView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ limitations under the License.
<q-td key="enable" :props="props">
<q-select
:v-model="getClusterEnabledStatus(props.row.id)"
:value="getClusterEnabledStatus(props.row.id)"
:display-value="`${getClusterEnabledStatus(props.row.id)}`"
:options="clusterSelectionOptions"
dense
Expand Down
Loading

0 comments on commit 908aa43

Please sign in to comment.