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
1cd8deb0
Commit
1cd8deb0
authored
1 year ago
by
Sverre Frogner Haugen
Browse files
Options
Downloads
Plain Diff
Merge branch 'logic-fix' into 'master'
Logic fix See merge request
!36
parents
46062a2f
5d5dad14
No related branches found
Branches containing commit
No related tags found
1 merge request
!36
Logic fix
Pipeline
#278933
passed
1 year ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/utils/TransactionUtils.ts
+82
-78
82 additions, 78 deletions
src/utils/TransactionUtils.ts
src/views/HomePage/EconomyView.vue
+26
-12
26 additions, 12 deletions
src/views/HomePage/EconomyView.vue
with
108 additions
and
90 deletions
src/utils/TransactionUtils.ts
+
82
−
78
View file @
1cd8deb0
import
axios
from
'
axios
'
export
const
getTransactions
=
async
(
pageNumber
:
Number
,
pageSize
:
Number
):
Promise
<
any
>
=>
{
const
transactionsList
=
[
{
transactionId
:
1
,
transactionTitle
:
"
Kiwi
"
,
date
:
"
15-05-2003
"
,
debtorAccount
:
12312312312
,
debtorName
:
"
Kiwi AS
"
,
creditorAccount
:
32131232132
,
amount
:
250
,
currency
:
"
NOK
"
,
TransactionCategory
:
{
category
:
"
Groceries
"
}
},
{
transactionId
:
2
,
transactionTitle
:
"
Apple
"
,
date
:
"
16-05-2003
"
,
debtorAccount
:
12312312312
,
debtorName
:
"
Apple Inc.
"
,
creditorAccount
:
32131232132
,
amount
:
300
,
currency
:
"
NOK
"
,
TransactionCategory
:
{
category
:
"
Electronics
"
}
},
{
transactionId
:
3
,
transactionTitle
:
"
Banana
"
,
date
:
"
17-05-2003
"
,
debtorAccount
:
12312312312
,
debtorName
:
"
Banana Corp.
"
,
creditorAccount
:
32131232132
,
amount
:
350
,
currency
:
"
NOK
"
,
TransactionCategory
:
{
category
:
"
Banana criminality
"
}
},
{
transactionId
:
4
,
transactionTitle
:
"
Orange
"
,
date
:
"
18-05-2003
"
,
debtorAccount
:
12312312312
,
debtorName
:
"
Orange Ltd.
"
,
creditorAccount
:
32131232132
,
amount
:
400
,
currency
:
"
NOK
"
,
TransactionCategory
:
{
category
:
"
Annoying
"
}
},
{
transactionId
:
4
,
transactionTitle
:
"
Crab
"
,
date
:
"
18-05-2003
"
,
debtorAccount
:
12312312312
,
debtorName
:
"
Crab Narcotics.
"
,
creditorAccount
:
32131232132
,
amount
:
400
,
currency
:
"
NOK
"
,
TransactionCategory
:
{
category
:
"
Drugs hehe
"
}
}
];
export
const
getTransactions
=
async
(
token
:
string
,
pageNumber
:
Number
,
pageSize
:
Number
):
Promise
<
any
>
=>
{
const
config
=
{
headers
:
{
"
Content-type
"
:
"
application/json
"
,
"
Authorization
"
:
"
Bearer
"
+
"
Ddaddaaddasasda
"
}
}
const
transactionsList
=
[
{
transactionId
:
1
,
transactionTitle
:
"
Kiwi
"
,
date
:
"
15-05-2003
"
,
debtorAccount
:
12312312312
,
debtorName
:
"
Kiwi AS
"
,
creditorAccount
:
32131232132
,
amount
:
250
,
currency
:
"
NOK
"
,
TransactionCategory
:
{
category
:
"
Groceries
"
}
},
{
transactionId
:
2
,
transactionTitle
:
"
Apple
"
,
date
:
"
16-05-2003
"
,
debtorAccount
:
12312312312
,
debtorName
:
"
Apple Inc.
"
,
creditorAccount
:
32131232132
,
amount
:
300
,
currency
:
"
NOK
"
,
TransactionCategory
:
{
category
:
"
Electronics
"
}
},
{
transactionId
:
3
,
transactionTitle
:
"
Banana
"
,
date
:
"
17-05-2003
"
,
debtorAccount
:
12312312312
,
debtorName
:
"
Banana Corp.
"
,
creditorAccount
:
32131232132
,
amount
:
350
,
currency
:
"
NOK
"
,
TransactionCategory
:
{
category
:
"
Banana criminality
"
}
},
{
transactionId
:
4
,
transactionTitle
:
"
Orange
"
,
date
:
"
18-05-2003
"
,
debtorAccount
:
12312312312
,
debtorName
:
"
Orange Ltd.
"
,
creditorAccount
:
32131232132
,
amount
:
400
,
currency
:
"
NOK
"
,
TransactionCategory
:
{
category
:
"
Annoying
"
}
'
Authorization
'
:
`Bearer
${
token
}
`
},
{
transactionId
:
4
,
transactionTitle
:
"
Crab
"
,
date
:
"
18-05-2003
"
,
debtorAccount
:
12312312312
,
debtorName
:
"
Crab Narcotics.
"
,
creditorAccount
:
32131232132
,
amount
:
400
,
currency
:
"
NOK
"
,
TransactionCategory
:
{
category
:
"
Drugs hehe
"
}
params
:{
"
page
"
:
pageNumber
,
"
size
"
:
pageSize
}
];
const
pageable
=
{
pageNum
:
pageNumber
,
pageSize
:
pageSize
}
try
{
await
axios
.
post
(
"
localhost:8080/user/transaction/latest/expense
"
,
pageable
,
config
)
console
.
log
(
token
)
console
.
log
(
'
trying to get transactions
'
)
console
.
log
(
config
)
const
result
=
await
axios
.
get
(
"
http://localhost:8080/user/transaction/latest/expense
"
,
config
)
console
.
log
(
result
.
data
);
return
result
.
data
;
}
catch
(
e
:
any
)
{
console
.
log
(
"
sending test data
"
)
return
transactionsList
// throw "Failed to fetch transacions: "+e.response.data
console
.
log
(
e
)
throw
e
;
}
}
This diff is collapsed.
Click to expand it.
src/views/HomePage/EconomyView.vue
+
26
−
12
View file @
1cd8deb0
...
...
@@ -5,23 +5,33 @@ import { ArcElement, Chart as ChartJS, Colors, Legend, Tooltip } from 'chart.js'
import
TransactionComponent
from
'
@/components/economy/TransactionComponent.vue
'
import
ToggleButton
from
'
@/components/economy/ToggleButton.vue
'
import
{
getTransactions
}
from
'
@/utils/TransactionUtils
'
import
{
useTokenStore
}
from
'
@/stores/token
'
ChartJS
.
register
(
ArcElement
,
Tooltip
,
Legend
,
Colors
)
const
selectedOption
=
ref
<
string
|
null
>
(
""
)
interface
Transaction
{
"
transactionCategory
"
:
string
,
"
transactionTitle
"
:
string
,
"
amount
"
:
number
,
"
transactionId
"
:
number
,
"
date
"
:
string
,
}
const
token
:
string
=
useTokenStore
().
jwtToken
;
const
selectedOption
=
ref
<
string
|
null
>
(
""
)
//let page = 0;
let
pages
=
0
;
let
currentPage
=
0
;
const
transactions
=
ref
<
any
[]
>
([])
const
transactions
=
ref
<
Transaction
[]
>
([])
const
fetchTransactions
=
async
()
=>
{
try
{
transactions
.
value
=
await
getTransactions
(
1
,
2
)
//const response = await getTransactions(1,2)
//transactions.value = response.data
//fordi akk nå benytter vi av test data
const
response
=
await
getTransactions
(
token
,
0
,
6
)
transactions
.
value
=
response
console
.
log
(
transactions
.
value
)
}
catch
(
e
)
{
console
.
log
(
e
)
}
...
...
@@ -46,7 +56,9 @@ const handleSelectionChange = (value: string | null) => {
const
distinctCategories
=
computed
(()
=>
{
const
categories
=
new
Set
<
string
>
()
transactions
.
value
.
forEach
(
transaction
=>
{
categories
.
add
(
transaction
.
TransactionCategory
.
category
)
console
.
log
(
transaction
.
transactionCategory
)
categories
.
add
(
transaction
.
transactionCategory
)
console
.
log
(
categories
)
})
return
Array
.
from
(
categories
)
})
...
...
@@ -57,11 +69,13 @@ const dropdownOptions = computed(() => {
const
filteredTransactions
=
computed
(()
=>
{
if
(
selectedOption
.
value
===
'
Alle
'
||
!
selectedOption
.
value
)
{
console
.
log
(
transactions
.
value
)
return
transactions
.
value
}
else
{
return
transactions
.
value
.
filter
(
transaction
=>
transaction
.
T
ransactionCategory
.
category
===
selectedOption
.
value
)
return
transactions
.
value
.
filter
(
transaction
=>
transaction
.
t
ransactionCategory
===
selectedOption
.
value
)
}
})
const
chartData
=
computed
(()
=>
{
const
data
:
{
labels
:
string
[],
datasets
:
{
data
:
number
[],
label
:
string
,
backgroundColor
:
string
[]
}[]
}
=
{
labels
:
[],
...
...
@@ -75,9 +89,9 @@ const chartData = computed(() => {
const
categoryAmounts
:
{
[
key
:
string
]:
number
}
=
{};
transactions
.
value
.
forEach
(
transaction
=>
{
const
{
T
ransactionCategory
,
amount
}
=
transaction
;
console
.
log
(
T
ransactionCategory
)
const
category
=
T
ransactionCategory
.
category
const
{
t
ransactionCategory
,
amount
}
=
transaction
;
console
.
log
(
t
ransactionCategory
)
const
category
=
t
ransactionCategory
if
(
category
in
categoryAmounts
)
{
categoryAmounts
[
category
]
+=
amount
;
}
else
{
...
...
@@ -161,7 +175,7 @@ const getRandomColor = () => {
v-for=
"transaction in filteredTransactions"
:key=
"transaction.transactionId"
:title=
"transaction.transactionTitle"
:category=
"transaction.
T
ransactionCategory
.category
"
:category=
"transaction.
t
ransactionCategory"
:amount=
"transaction.amount"
:date=
"transaction.date"
></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