Skip to content

Commit 4abf99d

Browse files
committed
Version 0.3.0
Merge branch 'dev'
2 parents ced0744 + cc6696e commit 4abf99d

File tree

8 files changed

+82
-49
lines changed

8 files changed

+82
-49
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ticket-calc",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"description": "Simple ticket calculator",
55
"author": "Julien Tardot <[email protected]>",
66
"license": "MIT",
@@ -16,6 +16,7 @@
1616
"register-service-worker": "^1.6.2",
1717
"tailwindcss": "^1.0.0-beta.4",
1818
"vue": "^2.6.6",
19+
"vue-js-toggle-button": "^1.3.2",
1920
"vue-router": "^3.0.1",
2021
"vuex": "^3.0.1"
2122
},

src/assets/css/app.css

+2-5
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ hr {
1414
@apply py-1 px-6 rounded-full font-semibold uppercase;
1515
}
1616
.btn-square {
17-
@apply inline-block p-0 w-8 h-8 rounded font-bold text-3xl;
18-
line-height: 0.8;
19-
padding-bottom: 0.4rem;
17+
@apply inline-block p-0 w-8 h-8 rounded font-bold text-3xl leading-none;
2018
}
2119
.btn-round {
22-
@apply inline-block p-0 w-8 h-8 rounded-full font-bold text-xl;
23-
line-height: 1;
20+
@apply inline-block p-0 w-8 h-8 rounded-full font-bold text-xl leading-none;
2421
padding-bottom: 0.4rem;
2522
}
2623

src/components/AutoToggleButton.vue

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<template>
2+
3+
<toggle-button :value="value" @input="$emit('input', $event)" :sync="true"
4+
:labels="{checked: 'AUTO', unchecked: 'MANUAL'}"
5+
:width="115" :height="30" :margin="3"
6+
:css-colors="true"/>
7+
8+
</template>
9+
10+
<script>
11+
export default {
12+
name: 'AutoToggleButton',
13+
props: {
14+
value: {type: Boolean, default: false},
15+
}
16+
}
17+
</script>
18+
19+
<style>
20+
21+
.vue-js-switch .v-switch-core { @apply bg-grayBlue; }
22+
.vue-js-switch.toggled .v-switch-core { @apply bg-primary; }
23+
.vue-js-switch .v-switch-label { @apply text-base; }
24+
.vue-js-switch .v-switch-label.v-left { @apply ml-5; }
25+
.vue-js-switch .v-switch-label.v-right { @apply mr-1; }
26+
27+
</style>

src/components/SolutionButtons.vue

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
<template>
2-
<div>
2+
<div class="f-row flex-wrap justify-around">
33

4-
<button class="solution-btn solution-btn-exact"
4+
<button class="solution-btn solution-btn-exact tracking-tighter"
55
v-for="(solution, index) in solutions['exact'].solutions" :key="'exact-' + index"
66
@click="$emit('select', solution)">
7-
==
7+
===
88
</button>
99

10-
<button class="solution-btn solution-btn-over"
10+
<button class="solution-btn solution-btn-over tracking-tight"
1111
v-for="(solution, index) in solutions['over'].solutions" :key="'over-' + index"
1212
@click="$emit('select', solution)">
1313
&gt; {{ solutions['over'].diff | fixed2 }}
1414
</button>
1515

16-
<button class="solution-btn solution-btn-under"
16+
<button class="solution-btn solution-btn-under tracking-tight"
1717
v-for="(solution, index) in solutions['under'].solutions" :key="'under-' + index"
1818
@click="$emit('select', solution)">
19-
&lt;
20-
{{ solutions['under'].diff | fixed2 }}
19+
&lt; {{ solutions['under'].diff | fixed2 }}
2120
</button>
2221

2322
</div>
@@ -37,9 +36,7 @@
3736

3837
<style>
3938
.solution-btn {
40-
@apply py-1 px-3 rounded-full text-white font-bold;
41-
margin: .125rem;
42-
margin-top: 0;
39+
@apply py-1 px-3 mb-1 text-lg rounded-full text-white font-bold;
4340
}
4441
.solution-btn:focus {
4542
@apply outline-none;

src/main.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
import Vue from 'vue';
1+
import Vue from 'vue';
2+
import {ToggleButton} from 'vue-js-toggle-button'
23

34
import '@/assets/css/tailwind.css';
45
import '@/assets/css/app.css';
6+
import '@/registerServiceWorker';
57

68
import App from '@/App.vue';
7-
import '@/registerServiceWorker';
89
import router from '@/router';
910
import store from '@/store';
1011

1112
Vue.config.productionTip = false;
1213

14+
// Third-party components
15+
Vue.component('ToggleButton', ToggleButton);
16+
1317
// Custom filters
1418
Vue.filter('abs', value => Math.abs(value));
1519
Vue.filter('fixed2', value => Number.parseFloat(value).toFixed(2));

src/views/Calc.vue

+32-31
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
<template>
22
<div class="container f-col p-3">
33

4-
<div class="flex my-3">
5-
<label class="col-start">Target</label>
6-
<div class="col-end">
7-
<input type="number" min="0" step="0.01" autofocus
8-
v-model.number.lazy="target" @change="targetChanged()"/>
9-
</div>
4+
<div class="f-row items-center justify-between mb-5">
5+
<label for="target" class="inline-block">
6+
Target
7+
</label>
8+
<input type="number" id="target" min="0" step="0.01" autofocus
9+
class="inline-block w-1/3"
10+
v-model.number.lazy="target" @change="targetChanged($event)"/>
11+
<auto-toggle-button v-model="auto"></auto-toggle-button>
1012
</div>
1113

12-
<div class="flex">
13-
<div class="col-start-full">
14-
<solution-buttons v-if="solutions && mode === 'auto'"
15-
:solutions="solutions"
16-
@select="selectSolution"/>
17-
</div>
18-
19-
<span class="col-end pb-1">
20-
<button class="btn btn-primary" type="button" v-if="mode === 'manual'" @click="mode = 'auto'">Auto</button>
21-
<button class="btn btn-primary" type="button" v-if="mode === 'auto'" @click="mode = 'manual'">Manual</button>
22-
</span>
14+
<div class="solution-buttons-container px-5">
15+
<solution-buttons v-if="solutions && auto"
16+
:solutions="solutions"
17+
@select="selectSolution"/>
2318
</div>
2419

2520
<hr>
@@ -40,13 +35,13 @@
4035
<hr>
4136

4237
<div class="f-col">
43-
<div class="f-row my-2">
38+
<div class="f-row mt-2">
4439
<span class="col-start">Ticket total</span>
4540
<div class="col-end-value">
4641
<span class="input-value result-value">{{ ticketTotal | fixed2 }}</span>
4742
</div>
4843
</div>
49-
<div class="f-row my-2" :class="{'invisible': !target}">
44+
<div class="f-row mt-2" :class="{'invisible': !target}">
5045
<span class="col-start">
5146
{{ balanceLabel }}
5247
</span>
@@ -58,7 +53,7 @@
5853
</div>
5954
</div>
6055

61-
<div class="flex justify-end mt-4">
56+
<div class="flex justify-end mt-4 text-base">
6257
<div class="col-end">
6358
<button class="btn btn-primary" type="button"
6459
@click="reset()"
@@ -75,6 +70,7 @@
7570
import {cloneDeep, map, round, sumBy} from 'lodash';
7671
import {mapGetters} from 'vuex'
7772
73+
import AutoToggleButton from '@/components/AutoToggleButton';
7874
import SolutionButtons from "@/components/SolutionButtons";
7975
import TicketQuantityRow from "@/components/TicketQuantityRow";
8076
import TicketQuantity from '@/models/ticket-quantity';
@@ -83,6 +79,7 @@
8379
export default {
8480
name: 'Calc',
8581
components: {
82+
AutoToggleButton,
8683
SolutionButtons,
8784
TicketQuantityRow,
8885
},
@@ -92,9 +89,9 @@
9289
data() {
9390
return {
9491
target: null,
95-
mode: 'auto',
9692
ticketQuantities: [],
9793
solutions: null,
94+
auto: true,
9895
};
9996
},
10097
created() {
@@ -105,7 +102,7 @@
105102
'tickets'
106103
]),
107104
calcButtonsDisabled() {
108-
return this.mode === 'auto';
105+
return this.auto;
109106
},
110107
ticketTotal() {
111108
return round(
@@ -133,20 +130,23 @@
133130
}
134131
},
135132
methods: {
136-
targetChanged() {
133+
targetChanged(event) {
137134
138135
if (this.tickets.length === 0) { return; }
139136
140137
this.solutions = new Calculator(this.tickets)
141138
.optimizeCalc(this.target);
139+
140+
// Force blur to hide keyboard
141+
event.target.blur();
142142
},
143143
selectSolution(solution) {
144144
this.ticketQuantities = cloneDeep(solution.ticketQuantities);
145145
},
146146
reset() {
147147
this.target = null;
148148
this.ticketQuantities.forEach(tq => tq.quantity = 0);
149-
this.mode = 'auto';
149+
this.auto = true;
150150
this.solutions = null;
151151
}
152152
},
@@ -158,25 +158,26 @@
158158
.col-start {
159159
@apply flex-grow pl-2;
160160
}
161-
.col-start-full {
162-
@apply flex-grow;
163-
max-width: calc(100% - 10rem);
164-
}
165161
.col-end {
166162
@apply inline-block text-center;
167-
width: 10rem;
163+
width: 8rem;
168164
}
169165
.col-end-value {
170-
@apply text-right pr-8;
166+
@apply text-right pr-6;
171167
}
172168
173169
hr {
174170
width: 104%;
175171
margin-left: -2%;
176172
}
177173
174+
.solution-buttons-container {
175+
min-height: 2.5rem; /*min-h-10*/
176+
}
177+
178178
.result-value {
179-
@apply bg-gray-300 py-1 px-3 rounded-lg;
179+
@apply inline-block bg-gray-300 py-1 px-3 rounded-lg align-bottom leading-tight;
180+
min-width: 4.5rem;
180181
}
181182
.has-remaining { @apply text-positive; }
182183
.has-extra { @apply text-negative; }

tailwind.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88

99
primary: '#e3001b',
1010
secondary: '#0f204b',
11+
grayBlue: '#6a7b9c',
1112
danger: '#f53d3d',
1213
light: '#f2f2f2',
1314
dark: '#222',

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -9781,6 +9781,11 @@ vue-jest@^3.0.3:
97819781
tsconfig "^7.0.0"
97829782
vue-template-es2015-compiler "^1.6.0"
97839783

9784+
vue-js-toggle-button@^1.3.2:
9785+
version "1.3.2"
9786+
resolved "https://registry.yarnpkg.com/vue-js-toggle-button/-/vue-js-toggle-button-1.3.2.tgz#d2e538465c321967144d035824cb71eedd82984e"
9787+
integrity sha512-LS+pvX5lXEhX+Gei5MOAEw7bx99/A+9idFhMtBgz72ApsEHlW69Y7bk+ZKC1rLRUxchL5WlQ+MhJXqXewhkfjg==
9788+
97849789
vue-loader@^15.6.4:
97859790
version "15.7.0"
97869791
resolved "https://registry.yarnpkg.com/vue-loader/-/vue-loader-15.7.0.tgz#27275aa5a3ef4958c5379c006dd1436ad04b25b3"

0 commit comments

Comments
 (0)