Skip to content

Commit ec65402

Browse files
committed
✨ Added Support for making items of type checkable
1 parent 1c09794 commit ec65402

File tree

5 files changed

+67
-18
lines changed

5 files changed

+67
-18
lines changed

src/App.vue

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
<template>
2-
<tree-view :treeViewItems="treeViewNodes">
2+
<tree-view :treeViewItems="treeViewNodes" @created="customiseTreeView">
33
<template v-slot:icon="treeViewItem">
44
<img src="@/assets/folder.svg" alt="folder" v-if="treeViewItem.type === 'folder'" >
5-
<img src="@/assets/word.png" alt="vue-logo" v-else-if="treeViewItem.type === '.doc'" height="22" width="22">
6-
<img src="@/assets/excel.png" alt="vue-logo" v-else-if="treeViewItem.type === '.excel'" height="22" width="22">
5+
<img src="@/assets/word.svg" alt="vue-logo" v-else-if="treeViewItem.type === '.doc'" height="18" width="18">
6+
<img src="@/assets/excel.svg" alt="vue-logo" v-else-if="treeViewItem.type === '.excel'" height="18" width="18">
7+
<img src="@/assets/playlist.svg" alt="vue-logo" v-else-if="treeViewItem.type === 'media'" height="18" width="18">
78
</template>
89
</tree-view>
910
</template>
1011

1112
<script lang='ts'>
1213
import { Vue, Component} from 'vue-property-decorator';
1314
14-
import { TreeViewItem } from '@/businessLogic/contracts/types';
15+
import { TreeViewCreatedEventPayload, TreeViewItem } from '@/businessLogic/contracts/types';
1516
1617
@Component
1718
export default class App extends Vue {
19+
20+
customiseTreeView(treeCreatedEvent: TreeViewCreatedEventPayload) {
21+
const customisations = treeCreatedEvent.itemCustomisations;
22+
23+
customisations.makeItemsCheckable([".doc", ".excel", "media" ]);
24+
}
25+
1826
treeViewNodes: TreeViewItem[] = [
1927
{
2028
name: 'Desktop',
@@ -75,14 +83,14 @@ export default class App extends Vue {
7583
children: [
7684
{
7785
name: 'Pictures',
78-
type: 'docs',
86+
type: 'media',
7987
id: '1203-29f3-1hdklsjdl-93',
8088
parentId: '1203-39029f3-1hdklsjdl-93',
8189
checkedStatus: 'False',
8290
},
8391
{
8492
name: 'Videos',
85-
type: 'docs',
93+
type: 'media',
8694
id: '1203-29fbb3-1hdklsjdl-93',
8795
parentId: '1203-39029f3-1hdklsjdl-93',
8896
checkedStatus: 'False',
@@ -91,7 +99,7 @@ export default class App extends Vue {
9199
},
92100
{
93101
name: 'Repositories',
94-
type: 'custom-file',
102+
type: 'code',
95103
id: '1203-39b293-1hdklsjdl-93',
96104
parentId: '1203-390293-1hfdkl-903923',
97105
checkedStatus: 'False'

src/businessLogic/contracts/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface ItemTypeCustomisations {
1313
}
1414

1515
export interface TreeViewCreatedEventPayload {
16-
itemCustomisations:
16+
itemCustomisations: ItemTypeCustomisations;
1717
}
1818

1919
export interface Customisations {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TreeViewCreatedEventPayload } from "@/businessLogic/contracts/types";
2+
import { mount } from "@vue/test-utils";
3+
import TreeView from "./treeView.vue";
4+
5+
6+
describe("treeview.vue", () => {
7+
it("onCreated should emit events customisation payload", () => {
8+
const treeView = mount(TreeView);
9+
10+
const emittedEvent = treeView.emitted().created;
11+
if (!emittedEvent) fail("Did not emit created event");
12+
13+
const payload = emittedEvent[0][0] as TreeViewCreatedEventPayload;
14+
expect(payload.itemCustomisations).not.toBe(undefined);
15+
})
16+
});

src/components/treeView.vue/treeView.vue

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
<img src="@/assets/folder.svg" alt="folder" v-if="treeViewItem.type.toLowerCase() == 'folder'">
1717
</slot>
1818
</div>
19-
<treeview-item :item="treeViewItem" :treeViewModel="viewModel" @changed="updateItemCheckedStatus"/>
20-
<span class="node-name cursor">{{ treeViewItem.name }}</span>
19+
<treeview-item :item="treeViewItem" :treeViewModel="viewModel" @changed="updateItemCheckedStatus"
20+
:customisations="getItemCustomisation(treeViewItem.type)" />
2121
</div>
2222

2323
<div class="node-child hide">
@@ -35,12 +35,26 @@
3535
<script lang='ts'>
3636
import {Vue, Component, Prop} from 'vue-property-decorator';
3737
import { TreeViewViewModel } from '@/businessLogic/treviewViewModel/treeViewViewModel'
38-
import { CheckedState, ItemCheckedChangedEvent, TreeViewItem } from '@/businessLogic/contracts/types';
38+
import { CheckedState, Customisations, ItemCheckedChangedEvent, TreeViewCreatedEventPayload, TreeViewItem } from '@/businessLogic/contracts/types';
39+
import { ItemCustomisations } from "@/businessLogic/itemCustomisations/itemCustomisations";
3940
4041
@Component
4142
export default class TreeView extends Vue {
4243
@Prop({ default: () => { return [] }}) treeViewItems!: TreeViewItem[];
4344
viewModel = TreeViewViewModel;
45+
itemCustomisations = ItemCustomisations;
46+
47+
created(): void {
48+
const payload: TreeViewCreatedEventPayload = {
49+
itemCustomisations: this.itemCustomisations
50+
};
51+
52+
this.$emit("created", payload);
53+
}
54+
55+
getItemCustomisation(type: string): Customisations {
56+
return this.itemCustomisations.typeCustomisations()[type];
57+
}
4458
4559
updateItemCheckedStatus(checkedEvent: ItemCheckedChangedEvent): void {
4660
const { item, status } = checkedEvent;

src/components/treeViewItem/treeViewItemView.vue

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
<template>
2-
<div>
3-
<input @contextmenu.prevent
4-
@change="updateCheckState"
5-
type="checkbox"
6-
ref="checkbox"
7-
v-model="isChecked" />
2+
<div>
3+
<div v-if="isCheckable">
4+
<input @contextmenu.prevent
5+
@change="updateCheckState"
6+
type="checkbox"
7+
ref="checkbox"
8+
v-model="isChecked" />
9+
<label for="checkbox" >{{ item.name }}</label>
10+
</div>
11+
12+
<span v-else>{{item.name}}</span>
13+
814
</div>
915
</template>
1016

1117
<script lang='ts'>
1218
import { TreeViewViewModel } from '@/businessLogic/treviewViewModel/treeViewViewModel';
13-
import { ItemCheckedChangedEvent, TreeViewItem } from '@/businessLogic/contracts/types';
19+
import { Customisations, ItemCheckedChangedEvent, TreeViewItem } from '@/businessLogic/contracts/types';
1420
import { Vue, Component, Prop, Watch } from 'vue-property-decorator';
1521
import VueTippy, { TippyComponent } from "vue-tippy";
1622
import "tippy.js/themes/light.css";
@@ -22,8 +28,13 @@ Vue.component("tippy", TippyComponent);
2228
export default class TreeViewItemView extends Vue {
2329
@Prop() item!: TreeViewItem;
2430
@Prop() treeViewModel!: TreeViewViewModel;
31+
@Prop() customisations!: Customisations
2532
isChecked = false;
2633
34+
get isCheckable(): boolean {
35+
return this.customisations && this.customisations.isCheckable == true;
36+
}
37+
2738
updateCheckState(): void {
2839
const event: ItemCheckedChangedEvent = { item: this.item, status: this.isChecked ? 'True' : 'False' };
2940
this.$emit('changed', event);

0 commit comments

Comments
 (0)