-
-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Thing Add: Validate Thing ID before saving
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
- Loading branch information
Showing
3 changed files
with
48 additions
and
8 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
21 changes: 21 additions & 0 deletions
21
bundles/org.openhab.ui/web/src/components/thing/thing-mixin.js
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,21 @@ | ||
export default { | ||
methods: { | ||
/** | ||
* Validate the Thing ID against valid characters and | ||
* if existing Things are available on `this.things`, | ||
* ensures that the Thing UID doesn't match an existing UID. | ||
* | ||
* @param {string} uid The Thing UID to validate | ||
* @param {string} id The Thing ID to validate | ||
* @returns {string} The error message if either the ID or the UID are invalid, or an empty string if they are valid. | ||
*/ | ||
validateThingUID (uid, id) { | ||
if (!/^[A-Za-z0-9_-]+$/.test(id)) { | ||
return 'Required. Must not start with a number. A-Z,a-z,0-9,_ only' | ||
} else if (this.things && this.things.some(thing => thing.UID === uid)) { | ||
return `A Thing with '${uid}' UID already exists` | ||
} | ||
return '' | ||
} | ||
} | ||
} |
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