Skip to content

Commit 98ae19e

Browse files
committed
scan parent endpoint added
1 parent f05c369 commit 98ae19e

File tree

5 files changed

+53
-7
lines changed

5 files changed

+53
-7
lines changed
Binary file not shown.
Binary file not shown.

vue-frontend/warehouse-frontend/src/router/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const routes = [
1616
{ path: "", component: ModePage /*, meta: { requiresAuth: true }*/ },
1717
{ path: "home", component: HomePage /*, meta: { requiresAuth: true }*/ },
1818
{ path: "parent", component: ParentPage /*, meta: { requiresAuth: true }*/ },
19-
{ path: "location", component: LocationPage /*, meta: { requiresAuth: true }*/ },
2019
{ path: "transaction", component: TransactionPage /*, meta: { requiresAuth: true }*/ },
20+
{ path: "location", component: LocationPage /*, meta: { requiresAuth: true }*/ }
2121
],
2222
},
2323
];

vue-frontend/warehouse-frontend/src/views/ParentPage.vue

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ export default {
33
data() {
44
return {
55
parentId: "",
6-
mode: ""
6+
mode: "",
7+
isLoading: false,
8+
errorMessage: ""
79
};
810
},
911
mounted() {
@@ -13,16 +15,44 @@ export default {
1315
this.mode = localStorage.getItem("mode");
1416
},
1517
methods: {
16-
scanParentId() {
18+
async scanParentId() {
1719
// if (this.username) {
1820
// this.$router.push("/mode"); // Navigate to Home after login
1921
// } else {
2022
// alert("Please enter username");
2123
// }
22-
this.$router.push("/location");
23-
},
24+
this.isLoading = true;
25+
try {
26+
const response = await fetch(`https://stevett.pythonanywhere.com/v1/lookup/parent/${this.parentId}?operation_mode=${this.mode}`);
27+
const data = await response.json();
28+
29+
if (data.response_type === "OK") {
30+
playSuccessSound();
31+
this.$router.push("/transaction");
32+
} else {
33+
playErrorSound();
34+
this.errorMessage = data.message;
35+
}
36+
} catch (error) {
37+
console.error("API Error:", error);
38+
alert("API Error:", error);
39+
}
40+
finally {
41+
this.isLoading = false;
42+
}
43+
}
2444
}
2545
};
46+
47+
function playErrorSound(){
48+
const errorSound = new Audio(require('@/assets/sounds/error-sound.mp3'));
49+
errorSound.play();
50+
}
51+
52+
function playSuccessSound(){
53+
const successSound = new Audio(require('@/assets/sounds/success-sound.mp3'));
54+
successSound.play();
55+
}
2656
</script>
2757

2858
<template>
@@ -41,13 +71,23 @@ export default {
4171

4272
<div class="mb-3">
4373
<label for="parentId" class="form-label">Parent ID</label>
44-
<input type="text" class="form-control" id="parentId" v-model="parentId" ref="parentId">
74+
<input type="text" class="form-control" id="parentId" v-model="parentId" @keyup.enter="scanParentId" ref="parentId">
4575
</div>
4676

4777
<div class="form-group">
4878
<button class="btn btn-primary" @click="scanParentId" style="width: 237px; margin-right: 8px">Cancel</button>
49-
<button class="btn btn-primary" @click="scanParentId" style="width: 237px">Continue</button>
79+
<button class="btn btn-primary" @click="scanParentId" style="width: 237px">
80+
<span v-if="isLoading" class="spinner-border spinner-border-sm"></span>
81+
<span v-else>Continue</span>
82+
</button>
83+
</div>
84+
85+
<div v-if="errorMessage" class="mt-3">
86+
<p class="text-danger">
87+
<i class="bi bi-exclamation-octagon-fill" style="padding-right: 5px;"></i> {{ errorMessage }}
88+
</p>
5089
</div>
90+
5191
</div>
5292
</div>
5393
</template>

vue-frontend/warehouse-frontend/vue.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ module.exports = defineConfig({
88
target: "http://localhost:3000",
99
changeOrigin: true,
1010
},
11+
'/v1': { // Proxy for v1 API
12+
target: 'https://stevett.pythonanywhere.com',
13+
changeOrigin: true,
14+
secure: false,
15+
pathRewrite: { '^/v1': '/v1' }
16+
}
1117
},
1218
}
1319
})

0 commit comments

Comments
 (0)