Skip to content

Commit 82b2563

Browse files
authored
Merge pull request #3 from rfcx/feature/CE-1327-user-can-see-the-comparison-box-at-the-top-of-report
CE-1327 User can see the comparison box at the top of report
2 parents a7fa746 + cf4501d commit 82b2563

12 files changed

+164
-20
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44

55
* **setup:** CE-1261 Setup biodiversity analytics project ([CE-1261](https://jira.rfcx.org/browse/CE-1261))
66
* **setup:** CE-1297 Setup biodiversity analytics deployment ([CE-1297](https://jira.rfcx.org/browse/CE-1297))
7+
8+
* **features:** CE-1327 User can see the comparison box at the top of report ([CE-1327](https://jira.rfcx.org/browse/CE-1327))

package-lock.json

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"build": "vue-tsc --project tsconfig.build.json --noEmit --skipLibCheck && vite build"
99
},
1010
"dependencies": {
11+
"dayjs": "^1.10.6",
1112
"node-sass": "^6.0.1",
1213
"sass-loader": "^12.1.0",
1314
"vue": "^3.0.5",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import dayjs from 'dayjs'
2+
import { Vue } from 'vue-class-component'
3+
import { Emit } from 'vue-property-decorator'
4+
5+
import { SpeciesRichnessFilter, Stream } from '@/models'
6+
7+
const defaultAllStreams: Stream = { id: 'all', name: 'All sites' }
8+
const defaultFilter = new SpeciesRichnessFilter(dayjs().subtract(7, 'days'), dayjs(), [defaultAllStreams])
9+
10+
export default class ComparisonBoxComponent extends Vue {
11+
public filters: SpeciesRichnessFilter[] = [defaultFilter]
12+
13+
public addFilterConfig (): void {
14+
this.filters.push(defaultFilter)
15+
}
16+
17+
// TODO: Have to improve this logic to check what is `all` meaning
18+
public get isDefaultFilter (): boolean {
19+
return this.filters.length === 1 && this.filters[0].streams[0].id === 'all'
20+
}
21+
22+
public removeFilterConfig (idx: number): void {
23+
this.filters.splice(idx, 1)
24+
if (this.filters.length === 0) {
25+
this.filters.push(defaultFilter)
26+
}
27+
}
28+
29+
public get showAddButton (): boolean {
30+
return this.filters.length < 5
31+
}
32+
33+
@Emit()
34+
public select (): SpeciesRichnessFilter[] {
35+
return this.filters
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<template>
2+
<div class="overflow-x-auto">
3+
<div class="flex flex-row flex-wrap">
4+
<div
5+
v-for="(filters, idx) in filters"
6+
:key="'stream-card' + idx"
7+
class="flex flex-col justify-center w-48 max-w-48 h-24 mr-4 mt-6 bg-clip-padding mirage-grey border-2 hover:bg-steel-grey cursor-pointer rounded-xl px-4 text-white text-sm"
8+
>
9+
<div class="flex flex-row">
10+
<div
11+
class="flex flex-row flex-1"
12+
:title="filters.displayTitle"
13+
>
14+
<i class="icon-pin mr-2" /> <div class="truncate max-w-24">
15+
{{ filters.displayTitle }}
16+
</div>
17+
</div>
18+
<div
19+
class="flex flex-col self-end"
20+
:class="{ 'invisible': isDefaultFilter }"
21+
@click="removeFilterConfig(idx)"
22+
>
23+
<i class="icon-close cursor-pointer" />
24+
</div>
25+
</div>
26+
<div class="flex flex-row items-center mt-2">
27+
<i class="icon-time mr-2" /> {{ filters.displayDate }}
28+
</div>
29+
</div>
30+
<div
31+
v-if="showAddButton"
32+
class="flex flex-col justify-center items-center w-48 max-w-48 h-24 mt-6 bg-clip-padding mirage-grey hover:bg-steel-grey cursor-pointer border-2 border-dashed rounded-xl p-4 text-white text-sm"
33+
@click="addFilterConfig"
34+
>
35+
<div class="uppercase">
36+
+ Add
37+
</div>
38+
</div>
39+
</div>
40+
</div>
41+
</template>
42+
<script src="./comparison-list.ts" lang="ts" />

src/models/Filter.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import dayjs, { Dayjs } from 'dayjs'
2+
3+
import { Stream } from './Stream'
4+
5+
export class SpeciesRichnessFilter {
6+
startDate: Dayjs= dayjs()
7+
endDate: Dayjs = dayjs()
8+
streams: Stream[] = []
9+
color: string = ''
10+
11+
constructor (startDate = dayjs(), endDate = dayjs(), streams: Stream[] = [], color = '') {
12+
this.startDate = startDate
13+
this.endDate = endDate
14+
this.streams = streams
15+
this.color = color
16+
}
17+
18+
get displayTitle (): string {
19+
return this.streams.map(s => s.name).join(', ')
20+
}
21+
22+
get displayDate (): string {
23+
return `${this.startDate.format('MMM D')} - ${this.endDate.format('D, YYYY')}`
24+
}
25+
}

src/models/Stream.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
// TODO: Update after connect to /stream endpoint
3+
export interface Stream {
4+
id: string
5+
name: string
6+
latitude?: number
7+
longitude?: number
8+
}

src/models/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './Filter'
2+
export * from './Stream'

src/pages/root/root.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div id="root-page">
22
<nav-bar />
3-
<div>
3+
<div class="max-w-screen-2xl mx-auto px-2 py-4 sm:px-6 lg:px-8">
44
<router-view />
55
</div>
66
</div>
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
<div id="species-richness-page">
2-
<div class="text-secondary">Species richness page</div>
2+
<div class="header-container">
3+
<div class="text-white text-4xl capitalize">
4+
Species Richness
5+
</div>
6+
<div class="text-white">
7+
Number of species found in the area
8+
</div>
9+
</div>
10+
<comparison-list @select="onFilterChange" />
311
</div>
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
import { Vue } from 'vue-class-component'
1+
import { Options, Vue } from 'vue-class-component'
22

3+
import ComparisonBoxComponent from '@/components/comparison-list/comparison-list.vue'
4+
import { SpeciesRichnessFilter } from '@/models'
5+
6+
@Options({
7+
components: {
8+
'comparison-list': ComparisonBoxComponent
9+
}
10+
})
311
export default class SpeciesRichnessPage extends Vue {
4-
mounted (): void {
5-
console.log('Species')
12+
onFilterChange (filters: SpeciesRichnessFilter[]): void {
13+
//
614
}
715
}

windi.config.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ import pluginIcons from '@windicss/plugin-icons'
88

99
export default defineConfig({
1010
darkMode: false,
11+
plugins: [
12+
plugin(({ addComponents }) => {
13+
const navbarItems = {
14+
'.navbar-item.router-link-active': {
15+
'box-shadow': 'inset 0 -3px 0 #31984f'
16+
}
17+
}
18+
addComponents(navbarItems)
19+
}),
20+
pluginAspectRatio,
21+
pluginForms,
22+
pluginIcons,
23+
pluginLineClamp
24+
],
1125
theme: {
1226
extend: {
1327
textColor: {
@@ -55,19 +69,5 @@ export default defineConfig({
5569
'btn-primary': 'bg-brand-primary hover:bg-brand-primary-dark',
5670
'btn-warning': 'bg-warning hover:bg-warning-dark',
5771
'btn-danger': 'bg-danger hover:bg-danger-dark'
58-
},
59-
plugins: [
60-
plugin(({ addComponents }) => {
61-
const navbarItems = {
62-
'.navbar-item.router-link-active': {
63-
'box-shadow': 'inset 0 -3px 0 #31984f'
64-
}
65-
}
66-
addComponents(navbarItems)
67-
}),
68-
pluginAspectRatio,
69-
pluginForms,
70-
pluginIcons,
71-
pluginLineClamp
72-
]
72+
}
7373
})

0 commit comments

Comments
 (0)