Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use API v2 in web client #1153

Merged
merged 24 commits into from
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
format string
  • Loading branch information
RomainMaillot committed Oct 31, 2022
commit 8b9d45a1887e36294b43d3a4ba91e906f11fef9c
6 changes: 5 additions & 1 deletion web/client/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ const isValid = (number: string): boolean => {
return formatted.match(/^[0-9]+$/) !== null && formatted.length > 2;
};

export { formatNumber, isValid };
const formatString = (string: string): string => {
return string.replace(/([A-Z])/g, " $1").trim();
};

export { formatNumber, isValid, formatString };
35 changes: 23 additions & 12 deletions web/client/src/views/Number.vue
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
<template>
<div>
<b-container v-if="isLookup" class="border p-4 mb-3">
<h3 class="text-center">Information</h3>
<b-container>
<b-row v-for="(value, name) in localData" :key="name" align-v="center">
<h5 class="text-capitalize m-0 mr-4">{{ name }}:</h5>
<b-card
v-if="isLookup || showInformations"
header="Informations"
class="mb-3 mt-3 text-center"
>
<b-list-group flush>
<b-list-group-item
v-for="(value, name) in localData"
:key="name"
class="text-left d-flex"
>
<h5 class="text-capitalize m-0 mr-4">{{ formatString(name) }}:</h5>
<p class="m-0">{{ value }}</p>
</b-row>
</b-container>
</b-container>
</b-list-group-item>
</b-list-group>
</b-card>

<b-container v-if="isLookup" class="border p-4">
<h3 class="text-center">Scanners</h3>
<b-card v-if="isLookup" header="Scanners" class="text-center">
<Scanner
v-for="(scanner, index) in scanners"
:key="index"
:name="scanner.name.charAt(0).toUpperCase() + scanner.name.slice(1)"
:scanId="scanner.name"
/>
</b-container>
</b-card>
</div>
</template>

<script lang="ts">
import Vue from "vue";
import { mapMutations, mapState } from "vuex";
import { formatNumber, isValid } from "../utils";
import { formatNumber, isValid, formatString } from "../utils";
import Scanner from "../components/Scanner.vue";
import axios, { AxiosResponse } from "axios";
import config from "@/config";
Expand All @@ -38,6 +44,7 @@ interface ScannerObject {
interface Data {
loading: boolean;
isLookup: boolean;
showInformations: boolean;
scanners: Array<ScannerObject>;
localData: {
valid: boolean;
Expand Down Expand Up @@ -67,6 +74,7 @@ export default Vue.extend({
return {
loading: false,
isLookup: false,
showInformations: false,
scanners: [],
localData: {
valid: false,
Expand All @@ -84,6 +92,7 @@ export default Vue.extend({
this.runScans();
},
methods: {
formatString: formatString,
async getScanners() {
try {
const res = await axios.get(`${config.apiUrl}/v2/scanners`);
Expand Down Expand Up @@ -116,6 +125,8 @@ export default Vue.extend({
if (this.localData.valid) {
this.getScanners();
this.isLookup = true;
} else {
this.showInformations = true;
}
} catch (error) {
this.$store.commit("pushError", { message: error });
Expand Down
6 changes: 3 additions & 3 deletions web/client/src/views/Scan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@
header="Informations"
class="mb-3 mt-3 text-center"
>
<!-- <h3 class="text-center">Information</h3> -->
<b-list-group flush>
<b-list-group-item
v-for="(value, name) in localData"
:key="name"
class="text-left d-flex"
>
<h5 class="text-capitalize m-0 mr-4">{{ name }}:</h5>
<h5 class="text-capitalize m-0 mr-4">{{ formatString(name) }}:</h5>
<p class="m-0">{{ value }}</p>
</b-list-group-item>
</b-list-group>
Expand All @@ -63,7 +62,7 @@
<script lang="ts">
import Vue from "vue";
import { mapMutations, mapState } from "vuex";
import { formatNumber, isValid } from "../utils";
import { formatNumber, isValid, formatString } from "../utils";
import VuePhoneNumberInput from "vue-phone-number-input";
import Scanner from "../components/Scanner.vue";
import axios, { AxiosResponse } from "axios";
Expand Down Expand Up @@ -142,6 +141,7 @@ export default Vue.extend({
};
},
methods: {
formatString: formatString,
clearData() {
this.isLookup = false;
this.showInformations = false;
Expand Down