#24 Navigating To The Security Details Page
Saturday, November 16, 2019
In this article we will start off by unifying our approach to binding the required properties for the list views that we are using in our securities view. What this means is that we will use a factory method to create the on click handlers for all of the list views instead of special methods for the securities and categories. While we are at it we will also create a factory method for creating new items and we will also bind the results of invoking that method to our list views so that we have the ability to create new items to add to our vuex store. We will then finish up by making a few changes to our securities details view. The first up is a small tweek that will make sure that our routing history always has it's top entry pointing to the securities view page if we are on the details page even if the user refreshes and therefore clears the history. Lastly we will use the getters that we created in a previous article to retrieve the appropriate item from the store when the user clicks on and existing item.
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
ListView.vue (1:43)
<script lang="tsx">
...
export default class ListView extends Vue {
...
@Prop() private readonly onClickCreate!: () => void;
...
private render() {
...
return (
<ul>
{ this.onClickCreate &&
<li>
<a class="list-item-content create" href="#void" onClick={() => this.onClickCreate()}>
<div class="list-item-text">Create</div>
<span>+</span>
</a>
</li>
}
...
</ul>
);
}
}
</script>
types.ts (4:18)
export enum SecurityDescriptors {
Categories,
Markets,
None,
Securities,
Segments,
Territories,
Types,
}
Securities.vue (5:12)
<script lang="tsx">
...
import { SecurityDescriptors } from "@/views/types";
...
export default class Securities extends Vue {
...
private readonly descriptorCategories = SecurityDescriptors.Categories;
private readonly descriptorMarkets = SecurityDescriptors.Markets;
private readonly descriptorSecurities = SecurityDescriptors.Securities;
private readonly descriptorSegments = SecurityDescriptors.Segments;
private readonly descriptorTerritories = SecurityDescriptors.Territories;
private readonly descriptorTypes = SecurityDescriptors.Types;
...
private onClickCreateFactory(which: SecurityDescriptors) {
return () => {
console.log(`${SecurityDescriptors[which]}`);
};
}
private onClickFactory(which: SecurityDescriptors) {
return (descriptor: SecurityModel | SecurityCategoryModel | SecurityDescriptor) => {
console.log(`${SecurityDescriptors[which]} ${descriptor.id}`);
};
}
...
}
</script>
Securities.vue (8:03)
<template lang="pug">
TabContainer(v-bind:tabs="tabs")
ListView(
...
v-bind:onClick="onClickFactory(descriptorSecurities)"
v-bind:onClickCreate="onClickCreateFactory(descriptorSecurities)"
...)/
ListView(
...
v-bind:onClick="onClickFactory(descriptorCategories)"
v-bind:onClickCreate="onClickCreateFactory(descriptorCategories)"
...)/
ListView(
...
v-bind:onClick="onClickFactory(descriptorMarkets)"
v-bind:onClickCreate="onClickCreateFactory(descriptorMarkets)"
...)/
ListView(
...
v-bind:onClick="onClickFactory(descriptorSegments)"
v-bind:onClickCreate="onClickCreateFactory(descriptorSegments)"
...)/
ListView(
...
v-bind:onClick="onClickFactory(descriptorTerritories)"
v-bind:onClickCreate="onClickCreateFactory(descriptorTerritories)"
...)/
ListView(
...
v-bind:onClick="onClickFactory(descriptorTypes)"
v-bind:onClickCreate="onClickCreateFactory(descriptorTypes)"
...)/
</template>
ListView.vue (9:04)
<style lang="sass" scoped>
...
.list-item-content
...
&.create
background-color: $green
color: white
font-weight: 600
&:hover
background-color: darken($green, 10%)
...
</style>
Advertisement
Securities.vue (10:26)
<script lang="tsx">
import { ... Inject, ... } from "vue-property-decorator";
...
import {
IRoute,
Routes,
RoutingService,
} from "@/components/routing";
...
export default class Securities extends Vue {
...
@Inject() private readonly routingService!: RoutingService;
...
private onClickCreateFactory(which: SecurityDescriptors) {
return () => {
this.routingService.navigateTo(Routes.SecuritiesDetails, {
query: { id: "0", which: `${which}` },
});
};
}
private onClickFactory(which: SecurityDescriptors) {
return (descriptor: SecurityModel | SecurityCategoryModel | SecurityDescriptor) => {
this.routingService.navigateTo(Routes.SecuritiesDetails, {
query: { id: `${descriptor.id}`, which: `${which}` },
});
};
}
...
}
</script>
SecuritiesDetails.vue (13:14)
<script lang="ts">
...
import { Routes, ... } from "@/components/routing";
import {
ACTION_PUSH_ROUTE,
Action,
ActionFn,
IRouteState,
PushRoutePayload,
STATE_ROUTES,
State,
} from "@/store";
...
export default class SecuritiesDetails extends Vue {
@Action(ACTION_PUSH_ROUTE) private readonly pushRoute!: ActionFn<PushRoutePayload>;
...
@State(STATE_ROUTES) private readonly routeState!: IRouteState;
private mounted() {
if (this.routeState.history.length === 0 || this.routeState.history[0].id !== Routes.Securities) {
this.pushRoute(this.routingService.createRoute(Routes.Securities));
}
...
}
}
</script>
SecuritiesDetails.vue (16:14)
<script lang="ts">
...
import {
...
GETTER_SECURITY,
GETTER_SECURITY_CATEGORY,
GETTER_SECURITY_MARKET,
GETTER_SECURITY_SEGMENT,
GETTER_SECURITY_TERRITORY,
GETTER_SECURITY_TYPE,
Getter,
GetterCategory,
GetterMarket,
GetterSecurity,
GetterSegment,
GetterTerritory,
GetterType,
...
} from "@/store";
...
import { SecurityDescriptors } from "@/views/types";
...
export default class SecuritiesDetails extends Vue {
...
@Getter(GETTER_SECURITY_CATEGORY) private getterCategory!: GetterCategory;
@Getter(GETTER_SECURITY_MARKET) private getterMarket!: GetterMarket;
@Getter(GETTER_SECURITY) private getterSecurity!: GetterSecurity;
@Getter(GETTER_SECURITY_SEGMENT) private getterSegment!: GetterSegment;
@Getter(GETTER_SECURITY_TERRITORY) private getterTerritory!: GetterTerritory;
@Getter(GETTER_SECURITY_TYPE) private getterType!: GetterType;
...
private id = 0;
private which = SecurityDescriptors.None;
private mounted() {
...
this.id = this.routingService.queryParam<IQuery, number>((x) => x.id, parseInt);
this.which = this.routingService.queryParam<IQuery, SecurityDescriptors>((x) => x.which, parseInt);
if (this.id <= 0) {
return;
}
this.load();
}
private load() {
switch (this.which) {
case SecurityDescriptors.Categories:
const category = this.getterCategory(this.id);
console.log(category.constructor.name);
return;
case SecurityDescriptors.Markets:
const market = this.getterMarket(this.id);
console.log(market.constructor.name);
return;
case SecurityDescriptors.Securities:
const security = this.getterSecurity(this.id);
console.log(security.constructor.name);
return;
case SecurityDescriptors.Segments:
const segment = this.getterSegment(this.id);
console.log(segment.constructor.name);
return;
case SecurityDescriptors.Territories:
const territory = this.getterTerritory(this.id);
console.log(territory.constructor.name);
return;
case SecurityDescriptors.Types:
const type = this.getterType(this.id);
console.log(type.constructor.name);
return;
}
}
}
</script>
Exciton Interactive LLC