Skip to content

Commit

Permalink
Add Read and Observe support at Object level to server-demo UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Nov 30, 2023
1 parent fbd9d32 commit caf3f35
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 6 deletions.
96 changes: 91 additions & 5 deletions leshan-server-demo/webapp/src/components/object/ObjectControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,27 @@
<request-button
@on-click="openCreateDialog"
ref="C"
:title="'Create Instance /' + objectdef.id"
:title="'Create Instance ' + path"
>Create</request-button
>
<request-button @on-click="observe" :title="'Observe ' + path"
>Obs</request-button
>
<request-button
@on-click="stopPassiveObserve"
:title="'Passive Cancel Obverse ' + path"
>
<v-icon dense small>{{ $icons.mdiEyeOffOutline }}</v-icon></request-button
>
<request-button
@on-click="stopActiveObserve"
:title="'Active Cancel Obverse ' + path"
>
<v-icon dense small>{{
$icons.mdiEyeRemoveOutline
}}</v-icon></request-button
>
<request-button @on-click="read" :title="'Read ' + path">R</request-button>
<instance-create-dialog
v-model="showDialog"
:objectdef="objectdef"
Expand All @@ -43,6 +61,9 @@ export default {
};
},
computed: {
path() {
return "/" + this.objectdef.id;
},
showDialog: {
get() {
return this.dialog;
Expand All @@ -55,9 +76,10 @@ export default {
},
methods: {
requestPath() {
return `api/clients/${encodeURIComponent(this.endpoint)}/${
this.objectdef.id
}?timeout=${timeout.get()}&format=${format.get()}`;
return `api/clients/${encodeURIComponent(this.endpoint)}${this.path}`;
},
requestOption() {
return `?timeout=${timeout.get()}&format=${format.get()}`;
},
updateState(content, requestButton) {
let state = !content.valid
Expand All @@ -74,9 +96,73 @@ export default {
let requestButton = this.$refs.C;
let data = instanceToREST(this.objectdef, value.id, value.resources);
this.axios
.post(this.requestPath(), data)
.post(`${this.requestPath()}${this.requestOption()}`, data)
.then((response) => {
this.updateState(response.data, requestButton);
})
.catch(() => {
requestButton.resetState();
});
},
read(requestButton) {
this.axios
.get(`${this.requestPath()}${this.requestOption()}`)
.then((response) => {
this.updateState(response.data, requestButton);
if (response.data.success) {
this.$store.newObjectValue(
this.endpoint,
this.path,
response.data.content.instances
);
}
})
.catch(() => {
requestButton.resetState();
});
},
observe(requestButton) {
this.axios
.post(`${this.requestPath()}/observe${this.requestOption()}`)
.then((response) => {
this.updateState(response.data, requestButton);
if (response.data.success) {
this.$store.newObjectValue(
this.endpoint,
this.path,
response.data.content.instances
);
this.$store.setObserved(this.endpoint, this.path, true);
}
})
.catch(() => {
requestButton.resetState();
});
},
stopPassiveObserve(requestButton) {
this.axios
.delete(this.requestPath() + "/observe")
.then(() => {
requestButton.changeState("success");
this.$store.setObserved(this.endpoint, this.path, false);
})
.catch(() => {
requestButton.resetState();
});
},
stopActiveObserve(requestButton) {
this.axios
.delete(this.requestPath() + `/observe?active&timeout=${timeout.get()}`)
.then((response) => {
this.updateState(response.data, requestButton);
if (response.data.success) {
this.$store.newObjectValue(
this.endpoint,
this.path,
response.data.content.instances
);
this.$store.setObserved(this.endpoint, this.path, false);
}
})
.catch(() => {
requestButton.resetState();
Expand Down
9 changes: 8 additions & 1 deletion leshan-server-demo/webapp/src/views/Client.vue
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,14 @@ export default {
true
);
} else if (msg.kind == "single") {
if (msg.val.kind === "instance") {
if (msg.val.kind === "obj") {
this.$store.newObjectValue(
this.$route.params.endpoint,
msg.res,
msg.val.instances,
false
);
} else if (msg.val.kind === "instance") {
this.$store.newInstanceValue(
this.$route.params.endpoint,
msg.res,
Expand Down

0 comments on commit caf3f35

Please sign in to comment.