#45 Adjusting Shares Using Modifier Keys
Saturday, April 11, 2020
In our quest to increase the usability of our app we will follow up of the adding of some color to our home page by also increasing the font weight of the category row that corresponds to the security that the user is hovering over. With that done we will add a couple of buttons so that we can adjust the number of shares of a particular security. As a result of the way we have wired everything up when the number of shares is adjusted the new percentage of that category is recaculated along with the difference. To make it easier to adjust the shares we will also make use of the modifier keys 'Shift', 'Control', and 'Alt'.
Parts
- Part 45: Adjusting Shares
- Part 44: Plan Percentages
- Part 43: Home Securities
- Part 42: Updating Plans
- Part 41: Plan Details View
- Part 40: Portfolio Getters
- Part 39: Portfolio Plan
- Part 38: Portfolio Category
- Part 37: Account Securities
- Part 36: Account Transfer
- Part 35: View Account Security
- Part 34: Updating Deposit
- Part 33: View Account Deposit
- Part 32: Display Account Details
- Part 31: Account Getters
- Part 30: Deposits And Securities
- Part 29: Add Accounts Details
- Part 28: Refactoring Accounts
- Part 27: Add Security Models
- Part 26: Edit Security Details
- Part 25: View Security Details
- Part 24: Navigating To Details
- Part 23: Getters Validation
- Part 22: Query Parameters
- Part 21: Tab Entries
- Part 20: Tab Header
- Part 19: List View
- Part 18: Vuex Getters
- Part 17: End Domain Model
- Part 16: Start Domain Model
- Part 15: Pop Routes
- Part 14: Push Routes
- Part 13: Removing Accounts
- Part 12: Vuex (Decorators)
- Part 11: Vuex (Accounts)
- Part 10: The App Bar (Settings)
- Part 9: Remove Consumer Rxjs
- Part 8: The App Bar (Back)
- Part 7: Structuring Our App
- Part 6: Animation Between Views
- Part 5: Navigation Fade
- Part 4: Navigation Requests
- Part 3: Fade Animations (cont.)
- Part 2: Fade Animations
- Part 1: Splash Screen
Code Snippets
Home.vue (1:56)
<script lang="ts">
...
type AccountSecurityKeyArray = [string, AccountSecurityModel[]];
...
export default class Home extends Vue {
...
private activeKey = "";
...
private mouseOverAccountSecurities(array: AccountSecurityKeyArray) {
if (this.activeKey === array[0]) {
return;
}
this.activeKey = array[0];
}
private mouseLeaveAccountSecurities() {
this.activeKey = "";
}
...
}
</script>
Home.vue (4:10)
<template lang="pug">
div.home
div
...
div(v-if="selectedPlan")
ul
...
li.row(
...
v-bind:key="portfolioCategory.id"
v-bind:class="{ 'active': portfolioCategory.category.abbreviation === activeKey }")
...
ul.account-securities
...
li(
...
v-on:mouseover="mouseOverAccountSecurities(acctSecurityArray)"
v-on:mouseleave="mouseLeaveAccountSecurities")
ul
li(
...)
...
</template>
Home.vue (6:11)
<style lang="sass" scoped>
...
.active
font-weight: 600
</style>
Home.vue (7:03)
<script lang="ts">
...
export default class Home extends Vue {
...
private decrease(e: MouseEvent, accountSecurity: AccountSecurityModel) {
e.preventDefault();
console.log("decrease");
}
private increase(e: MouseEvent, accountSecurity: AccountSecurityModel) {
e.preventDefault();
console.log("increase");
}
...
}
</script>
Advertisement
Home.vue (8:06)
<template lang="pug">
div.home
...
ul.account-securities
li.row
label Symbol
label Account
label Shares
label Last
label
li(...)
ul
li(...)
div.row
...
div.row.btns
button.btn(v-on:click.prevent="(e) => decrease(e, acctSecurity)") -
button.btn(v-on:click.prevent="(e) => increase(e, acctSecurity)") +
</template>
Home.vue (9:51)
<style lang="sass" scoped>
...
.btns
margin-bottom: 0.125rem
.btn
padding: 0.75rem
min-width: 2.5rem
&:first-child
margin-right: 0.125rem
</style>
Home.vue
<script lang="ts">
...
export default class Home extends Vue {
...
private decrease(e: MouseEvent, accountSecurity: AccountSecurityModel) {
e.preventDefault();
accountSecurity.shares -= 1;
}
private increase(e: MouseEvent, accountSecurity: AccountSecurityModel) {
e.preventDefault();
accountSecurity.shares += 1;
}
...
}
</script>
Home.vue (11:44)
<script lang="ts">
...
export default class Home extends Vue {
...
private decrease(e: MouseEvent, accountSecurity: AccountSecurityModel) {
e.preventDefault();
if (e.getModifierState("Shift")) {
accountSecurity.shares -= 5;
} else if (e.getModifierState("Control")) {
accountSecurity.shares -= 10;
} else if (e.getModifierState("Alt")) {
accountSecurity.shares -= 20;
} else {
accountSecurity.shares -= 1;
}
}
private increase(e: MouseEvent, accountSecurity: AccountSecurityModel) {
e.preventDefault();
if (e.getModifierState("Shift")) {
accountSecurity.shares += 5;
} else if (e.getModifierState("Control")) {
accountSecurity.shares += 10;
} else if (e.getModifierState("Alt")) {
accountSecurity.shares += 20;
} else {
accountSecurity.shares += 1;
}
}
...
}
</script>
Exciton Interactive LLC