-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server-demo: Use Timestamp for Time value of REST API.
- Loading branch information
1 parent
9bd4844
commit f98f949
Showing
7 changed files
with
114 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
leshan-server-demo/webapp/src/components/values/input/DateTimeValueInput.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<!----------------------------------------------------------------------------- | ||
* Copyright (c) 2021 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
-----------------------------------------------------------------------------> | ||
<template> | ||
<v-row> | ||
<v-col> | ||
<v-text-field | ||
single-line | ||
:label="resourcedef.type" | ||
suffix="seconds" | ||
v-model="dateValue" | ||
:rules="[(v) => !v || isValidTimestamp(v) || 'Invalid timestamp']" | ||
hint="Timestamp in seconds" | ||
clearable | ||
/> | ||
</v-col> | ||
</v-row> | ||
</template> | ||
<script> | ||
import { isInteger } from "../../../js/utils.js"; | ||
/** | ||
* An input for TIME single value LWM2M node ("Single Instance Resource" or "Resource Instance") | ||
*/ | ||
export default { | ||
props: { | ||
value: null, // the input value for this LWM2M Node (v-model) : timestamp in milliseconds | ||
resourcedef: Object, // the model of the resource | ||
}, | ||
data() { | ||
return { | ||
localValue: null, // timestamp in seconds | ||
}; | ||
}, | ||
watch: { | ||
value(v) { | ||
if (this.isValidTimestamp(v)) { | ||
this.localValue = Math.floor(parseInt(v) / 1000); | ||
} else { | ||
this.localValue = v; | ||
} | ||
}, | ||
}, | ||
methods: { | ||
isValidTimestamp(v) { | ||
return isInteger(v); | ||
}, | ||
}, | ||
computed: { | ||
dateValue: { | ||
get() { | ||
return this.localValue; | ||
}, | ||
set(v) { | ||
this.$emit("input", this.isValidTimestamp(v) ? v * 1000 : v); | ||
}, | ||
}, | ||
}, | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
*******************************************************************************/ | ||
|
||
/** | ||
* @param {*} value the value to check | ||
* @returns true if the value is a integer | ||
*/ | ||
function isInteger(value) { | ||
if (typeof value === "number") { | ||
return value === Math.round(value); | ||
} else if (typeof value === "string" && value.trim() !== "") { | ||
return value === String(Math.round(Number(value))); | ||
} | ||
return false; | ||
} | ||
|
||
export { isInteger }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters