Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
idatt2106_2024_03_frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Scrum_Team_3
idatt2106_2024_03_frontend
Commits
9ef74c8a
Commit
9ef74c8a
authored
1 year ago
by
Tini Tran
Browse files
Options
Downloads
Patches
Plain Diff
Using the hook and fetching data from api call to the view
parent
60d815fd
No related branches found
No related tags found
1 merge request
!21
Resolve "Consumption page functionality"
Pipeline
#277656
passed
1 year ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/views/HomePage/EconomyView.vue
+67
-44
67 additions, 44 deletions
src/views/HomePage/EconomyView.vue
with
67 additions
and
44 deletions
src/views/HomePage/EconomyView.vue
+
67
−
44
View file @
9ef74c8a
<
script
setup
lang=
"ts"
>
<
script
setup
lang=
"ts"
>
import
{
computed
,
ref
}
from
'
vue
'
import
{
computed
,
onMounted
,
ref
}
from
'
vue
'
import
{
Pie
}
from
'
vue-chartjs
'
import
{
Pie
}
from
'
vue-chartjs
'
import
{
Chart
as
ChartJS
,
ArcElement
,
Tooltip
,
Legend
}
from
'
chart.js
'
import
{
ArcElement
,
Chart
as
ChartJS
,
Colors
,
Legend
,
Tooltip
}
from
'
chart.js
'
ChartJS
.
register
(
ArcElement
,
Tooltip
,
Legend
)
import
TransactionComponent
from
'
@/components/economy/TransactionComponent.vue
'
import
TransactionComponent
from
'
@/components/economy/TransactionComponent.vue
'
import
ToggleButton
from
'
@/components/economy/ToggleButton.vue
'
import
ToggleButton
from
'
@/components/economy/ToggleButton.vue
'
import
{
getTransactions
}
from
'
@/utils/TransactionUtils
'
ChartJS
.
register
(
ArcElement
,
Tooltip
,
Legend
,
Colors
)
const
selectedOption
=
ref
<
string
|
null
>
(
""
)
const
selectedOption
=
ref
<
string
|
null
>
(
""
)
...
@@ -13,38 +15,24 @@ const selectedOption = ref<string | null>("")
...
@@ -13,38 +15,24 @@ const selectedOption = ref<string | null>("")
let
pages
=
0
;
let
pages
=
0
;
let
currentPage
=
0
;
let
currentPage
=
0
;
const
transactions
=
ref
([
const
transactions
=
ref
<
any
[]
>
([])
{
id
:
1
,
const
fetchTransactions
=
async
()
=>
{
title
:
'
Rema 1000
'
,
try
{
date
:
'
2022-05-10
'
,
transactions
.
value
=
await
getTransactions
(
1
,
2
)
amount
:
100
,
//const response = await getTransactions(1,2)
category
:
'
Dagligvare
'
//transactions.value = response.data
},
//fordi akk nå benytter vi av test data
{
id
:
2
,
}
catch
(
e
)
{
title
:
'
Trondheim Kino
'
,
console
.
log
(
e
)
date
:
'
2022-05-15
'
,
}
amount
:
500
,
category
:
'
Underholdning
'
}
},
onMounted
(()
=>
{
{
id
:
3
,
fetchTransactions
()
title
:
'
SIT
'
,
})
date
:
'
2022-05-15
'
,
amount
:
4450
,
category
:
'
regninger
'
},
{
id
:
4
,
title
:
'
Superhero Burger
'
,
date
:
'
2022-05-15
'
,
amount
:
1500
,
category
:
'
Mat & Restaurant
'
},
{
id
:
6
,
title
:
'
Kiwi
'
,
date
:
'
2022-05-20
'
,
amount
:
100
,
category
:
'
Dagligvare
'
},
])
const
chartVisible
=
ref
(
false
)
const
chartVisible
=
ref
(
false
)
const
toggleChart
=
(
value
:
boolean
)
=>
{
const
toggleChart
=
(
value
:
boolean
)
=>
{
...
@@ -58,7 +46,7 @@ const handleSelectionChange = (value: string | null) => {
...
@@ -58,7 +46,7 @@ const handleSelectionChange = (value: string | null) => {
const
distinctCategories
=
computed
(()
=>
{
const
distinctCategories
=
computed
(()
=>
{
const
categories
=
new
Set
<
string
>
()
const
categories
=
new
Set
<
string
>
()
transactions
.
value
.
forEach
(
transaction
=>
{
transactions
.
value
.
forEach
(
transaction
=>
{
categories
.
add
(
transaction
.
category
)
categories
.
add
(
transaction
.
TransactionCategory
.
category
)
})
})
return
Array
.
from
(
categories
)
return
Array
.
from
(
categories
)
})
})
...
@@ -71,7 +59,7 @@ const filteredTransactions = computed(() => {
...
@@ -71,7 +59,7 @@ const filteredTransactions = computed(() => {
if
(
selectedOption
.
value
===
'
Alle
'
||
!
selectedOption
.
value
)
{
if
(
selectedOption
.
value
===
'
Alle
'
||
!
selectedOption
.
value
)
{
return
transactions
.
value
return
transactions
.
value
}
else
{
}
else
{
return
transactions
.
value
.
filter
(
transaction
=>
transaction
.
category
===
selectedOption
.
value
)
return
transactions
.
value
.
filter
(
transaction
=>
transaction
.
TransactionCategory
.
category
===
selectedOption
.
value
)
}
}
})
})
const
chartData
=
computed
(()
=>
{
const
chartData
=
computed
(()
=>
{
...
@@ -87,7 +75,9 @@ const chartData = computed(() => {
...
@@ -87,7 +75,9 @@ const chartData = computed(() => {
const
categoryAmounts
:
{
[
key
:
string
]:
number
}
=
{};
const
categoryAmounts
:
{
[
key
:
string
]:
number
}
=
{};
transactions
.
value
.
forEach
(
transaction
=>
{
transactions
.
value
.
forEach
(
transaction
=>
{
const
{
category
,
amount
}
=
transaction
;
const
{
TransactionCategory
,
amount
}
=
transaction
;
console
.
log
(
TransactionCategory
)
const
category
=
TransactionCategory
.
category
if
(
category
in
categoryAmounts
)
{
if
(
category
in
categoryAmounts
)
{
categoryAmounts
[
category
]
+=
amount
;
categoryAmounts
[
category
]
+=
amount
;
}
else
{
}
else
{
...
@@ -101,7 +91,6 @@ const chartData = computed(() => {
...
@@ -101,7 +91,6 @@ const chartData = computed(() => {
data
.
labels
.
forEach
(
label
=>
{
data
.
labels
.
forEach
(
label
=>
{
data
.
datasets
[
0
].
data
.
push
(
categoryAmounts
[
label
]);
data
.
datasets
[
0
].
data
.
push
(
categoryAmounts
[
label
]);
});
});
console
.
log
(
data
)
return
data
;
return
data
;
})
})
...
@@ -114,6 +103,40 @@ const getRandomColor = () => {
...
@@ -114,6 +103,40 @@ const getRandomColor = () => {
}
}
return
color
return
color
}
}
//
// const transactions1 = ref([
// { id: 1,
// title: 'Rema 1000',
// date: '2022-05-10',
// amount: 100,
// category: 'Dagligvare'
// },
// { id: 2,
// title: 'Trondheim Kino',
// date: '2022-05-15',
// amount: 500,
// category: 'Underholdning'
// },
// { id: 3,
// title: 'SIT',
// date: '2022-05-15',
// amount: 4450,
// category: 'regninger'
// },
// { id: 4,
// title: 'Superhero Burger',
// date: '2022-05-15',
// amount: 1500,
// category: 'Mat & Restaurant'
// },
// { id: 6,
// title: 'Kiwi',
// date: '2022-05-20',
// amount: 100,
// category: 'Dagligvare'
// },
// ])
</
script
>
</
script
>
<
template
>
<
template
>
...
@@ -133,12 +156,12 @@ const getRandomColor = () => {
...
@@ -133,12 +156,12 @@ const getRandomColor = () => {
<option
v-for=
"option in dropdownOptions"
:key=
"option"
:value=
"option"
>
{{
option
}}
</option>
<option
v-for=
"option in dropdownOptions"
:key=
"option"
:value=
"option"
>
{{
option
}}
</option>
</select>
</select>
</div>
</div>
<div
class=
"component-container"
>
<div
class=
"component-container"
v-if=
"filteredTransactions"
>
<transaction-component
<transaction-component
v-for=
"transaction in filteredTransactions"
v-for=
"transaction in filteredTransactions"
:key=
"transaction.
i
d"
:key=
"transaction.
transactionI
d"
:title=
"transaction.title"
:title=
"transaction.t
ransactionT
itle"
:category=
"transaction.category"
:category=
"transaction.
TransactionCategory.
category"
:amount=
"transaction.amount"
:amount=
"transaction.amount"
:date=
"transaction.date"
:date=
"transaction.date"
></transaction-component>
></transaction-component>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment