Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
boco-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
Container 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
idatt2106_2022_02
boco-frontend
Commits
f56fff44
Commit
f56fff44
authored
3 years ago
by
Titus Netland
Browse files
Options
Downloads
Plain Diff
Merge branch 'add-new-item-groups' into 'main'
new item with communities See merge request
!76
parents
35ae8b32
91cc524c
No related branches found
No related tags found
1 merge request
!76
new item with communities
Pipeline
#179438
passed
3 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/components/ItemComponents/NewItemForm.vue
+84
-38
84 additions, 38 deletions
src/components/ItemComponents/NewItemForm.vue
with
84 additions
and
38 deletions
src/components/ItemComponents/NewItemForm.vue
+
84
−
38
View file @
f56fff44
...
@@ -66,43 +66,58 @@
...
@@ -66,43 +66,58 @@
</div>
</div>
</div>
</div>
<!-- Select Group -->
<div
class=
"mb-6"
>
<div
class=
"mb-6"
>
<label
<label
class=
"block mb-2 text-sm font-medium text-gray-900 dark:text-gray-400"
class=
"block text-sm font-medium text-gray-900 dark:text-gray-400"
id=
"selectCommunityLabel"
>
Grupper
</label>
>
Gruppe
</label
<div
>
class=
"overflow-auto w-full h-32 mt-2 text-base list-none bg-white rounded divide-y divide-gray-100 dark:bg-gray-700"
<select
v-model=
"v$.item.selectGroup.$model"
class=
"block w-full px-4 py-2 mt-2 text-gray-700 placeholder-gray-500 bg-white border rounded-md dark:bg-gray-800 dark:border-gray-600 dark:placeholder-gray-400 focus:border-primary-light dark:focus:border-primary-light focus:ring-opacity-40 focus:outline-none focus:ring focus:ring-primary-light"
>
>
<option
class=
"text-gray-400"
value=
""
disabled
selected
>
<ul
class=
"py-1"
aria-labelledby=
"dropdownDefault"
>
Velg en gruppe
<li>
</option>
<div
class=
"form-check"
v-for=
"group in groups"
:key=
"group"
>
<option
<input
v-for=
"group in groups"
:key=
"group"
class=
"form-check-input appearance-none h-4 w-4 border border-gray-300 rounded-sm bg-white checked:bg-primary-medium checked:bg-primary-medium focus:outline-none transition duration-200 mt-1 align-top bg-no-repeat bg-center bg-contain float-left mr-2 cursor-pointer"
class=
"text-gray-900 text-sm"
type=
"checkbox"
>
:value=
"group.communityId"
{{
group
}}
@
change=
"onChangeGroup($event)"
</option>
>
</select>
<label
class=
"form-check-label inline-block text-gray-800"
>
{{
group
.
name
}}
</label>
</div>
</li>
</ul>
</div>
<label
class=
"text-error text-sm block"
>
{{
groupErrorMessage
}}
</label>
</div>
<!-- error message for select box -->
<!-- error message for select box -->
<div
<div
class=
"text-error"
class=
"overflow-auto w-full h-32 mt-2 text-base list-none bg-white rounded divide-y divide-gray-100 dark:bg-gray-700"
v-for=
"(error, index) of v$.item.selectGroup.$errors"
:key=
"index"
>
>
<div
class=
"text-error text-sm"
>
<ul
class=
"py-1"
aria-labelledby=
"dropdownDefault"
>
{{
error
.
$message
}}
<li>
</div>
<div
class=
"form-check"
v-for=
"group in groups"
:key=
"group"
>
<input
class=
"form-check-input appearance-none h-4 w-4 border border-gray-300 rounded-sm bg-white checked:bg-primary-medium checked:bg-primary-medium focus:outline-none transition duration-200 mt-1 align-top bg-no-repeat bg-center bg-contain float-left mr-2 cursor-pointer"
type=
"checkbox"
:value=
"group.communityId"
@
change=
"onChangeGroup($event)"
>
<label
class=
"form-check-label inline-block text-gray-800"
>
{{
group
.
name
}}
</label>
</div>
</li>
</ul>
</div>
</div>
</div
>
<label
class=
"text-error text-sm block"
>
{{
groupErrorMessage
}}
</label
>
<!-- price -->
<!-- price -->
<div
class=
"mb-6"
:class=
"
{ error: v$.item.price.$errors.length }">
<div
class=
"mb-6
mt-4
"
:class=
"
{ error: v$.item.price.$errors.length }">
<label
<label
class=
"block mb-2 text-sm font-medium text-gray-900 dark:text-gray-300"
class=
"block mb-2 text-sm font-medium text-gray-900 dark:text-gray-300"
id=
"priceLabel"
id=
"priceLabel"
...
@@ -217,7 +232,7 @@
...
@@ -217,7 +232,7 @@
<
script
>
<
script
>
import
useVuelidate
from
"
@vuelidate/core
"
;
import
useVuelidate
from
"
@vuelidate/core
"
;
import
{
parseUserFromToken
}
from
"
@/utils/token-utils
"
;
import
{
parseUserFromToken
}
from
"
@/utils/token-utils
"
;
import
{
postNewItem
}
from
"
@/utils/apiutil
"
;
import
{
postNewItem
,
getMyGroups
}
from
"
@/utils/apiutil
"
;
import
Button
from
"
@/components/BaseComponents/ColoredButton
"
;
import
Button
from
"
@/components/BaseComponents/ColoredButton
"
;
import
{
import
{
...
@@ -276,9 +291,6 @@ export default {
...
@@ -276,9 +291,6 @@ export default {
select
:
{
select
:
{
required
:
helpers
.
withMessage
(()
=>
`Velg en kategori`
,
required
),
required
:
helpers
.
withMessage
(()
=>
`Velg en kategori`
,
required
),
},
},
selectGroup
:
{
required
:
helpers
.
withMessage
(()
=>
`Velg en gruppe`
,
required
),
},
address
:
{
address
:
{
required
:
helpers
.
withMessage
(
required
:
helpers
.
withMessage
(
()
=>
"
Addressen kan ikke være tom
"
,
()
=>
"
Addressen kan ikke være tom
"
,
...
@@ -305,11 +317,13 @@ export default {
...
@@ -305,11 +317,13 @@ export default {
type
:
""
,
type
:
""
,
images
:
[],
images
:
[],
userId
:
-
1
,
userId
:
-
1
,
selectGroup
:
null
,
selectedGroupId
:
-
1
,
selectedGroups
:
[],
},
},
//Kategorier skal legges inn ved api/hente fra db, her må det endres etterhvert
//Kategorier skal legges inn ved api/hente fra db, her må det endres etterhvert
categories
:
[
"
Hage
"
,
"
Kjøkken
"
,
"
Musikk
"
,
"
Annet
"
],
categories
:
[
"
Hage
"
,
"
Kjøkken
"
,
"
Musikk
"
,
"
Annet
"
],
groups
:
[
4040
,
4041
],
groups
:
[],
groupErrorMessage
:
''
,
};
};
},
},
methods
:
{
methods
:
{
...
@@ -317,7 +331,10 @@ export default {
...
@@ -317,7 +331,10 @@ export default {
console
.
log
(
"
sjekker validering
"
);
console
.
log
(
"
sjekker validering
"
);
this
.
v$
.
item
.
$touch
();
this
.
v$
.
item
.
$touch
();
if
(
this
.
v$
.
item
.
$invalid
)
{
if
(
this
.
v$
.
item
.
$invalid
||
this
.
item
.
selectedGroups
.
length
===
0
)
{
if
(
this
.
item
.
selectedGroups
.
length
===
0
){
this
.
groupErrorMessage
=
"
Velg gruppe/grupper
"
;
}
console
.
log
(
"
Invalid, avslutter...
"
);
console
.
log
(
"
Invalid, avslutter...
"
);
return
false
;
return
false
;
}
}
...
@@ -340,7 +357,7 @@ export default {
...
@@ -340,7 +357,7 @@ export default {
console
.
log
(
"
Addressen:
"
+
this
.
item
.
address
);
console
.
log
(
"
Addressen:
"
+
this
.
item
.
address
);
console
.
log
(
"
Pris:
"
+
this
.
item
.
price
);
console
.
log
(
"
Pris:
"
+
this
.
item
.
price
);
console
.
log
(
"
bilder:
"
+
this
.
item
.
images
);
console
.
log
(
"
bilder:
"
+
this
.
item
.
images
);
console
.
log
(
"
gruppe:
"
+
this
.
item
.
selectGroup
);
console
.
log
(
"
gruppe:
"
+
this
.
item
.
select
ed
Group
s
);
const
itemInfo
=
{
const
itemInfo
=
{
title
:
this
.
item
.
title
,
title
:
this
.
item
.
title
,
...
@@ -349,7 +366,7 @@ export default {
...
@@ -349,7 +366,7 @@ export default {
address
:
this
.
item
.
address
,
address
:
this
.
item
.
address
,
userID
:
this
.
item
.
userId
,
userID
:
this
.
item
.
userId
,
categoryNames
:
[],
categoryNames
:
[],
communityIDs
:
[
this
.
item
.
selectGroup
]
,
communityIDs
:
this
.
item
.
select
ed
Group
s
,
};
};
console
.
log
(
itemInfo
);
console
.
log
(
itemInfo
);
...
@@ -357,20 +374,49 @@ export default {
...
@@ -357,20 +374,49 @@ export default {
const
postRequest
=
await
postNewItem
(
itemInfo
);
const
postRequest
=
await
postNewItem
(
itemInfo
);
console
.
log
(
"
posted:
"
+
postRequest
);
console
.
log
(
"
posted:
"
+
postRequest
);
this
.
$router
.
push
(
'
/
'
);
}
}
},
},
checkUser
:
async
function
()
{
checkUser
:
async
function
()
{
let
user
=
parseUserFromToken
(
this
.
$store
.
state
.
user
.
token
);
let
user
=
parseUserFromToken
(
this
.
$store
.
state
.
user
.
token
);
this
.
item
.
userId
=
parseInt
(
user
.
accountId
);
this
.
item
.
userId
=
parseInt
(
user
.
accountId
);
console
.
log
(
"
id:
"
+
this
.
item
.
userId
);
},
},
addImage
:
function
(
event
)
{
addImage
:
function
(
event
)
{
console
.
log
(
event
.
target
.
files
);
console
.
log
(
event
.
target
.
files
);
this
.
item
.
images
.
push
(
URL
.
createObjectURL
(
event
.
target
.
files
[
0
]));
this
.
item
.
images
.
push
(
URL
.
createObjectURL
(
event
.
target
.
files
[
0
]));
console
.
log
(
"
antall bilder:
"
+
this
.
item
.
images
.
length
);
},
getGroups
:
async
function
(){
this
.
groups
=
await
getMyGroups
();
},
onChangeGroup
:
function
(
e
){
this
.
selectedGroupId
=
e
.
target
.
value
;
let
alreadyInGroupList
=
false
;
console
.
log
(
"
selected clicked
"
);
for
(
let
i
=
0
;
i
<=
this
.
item
.
selectedGroups
.
length
;
i
++
)
{
if
(
this
.
selectedGroupId
==
this
.
item
.
selectedGroups
[
i
])
{
const
index
=
this
.
item
.
selectedGroups
.
indexOf
(
this
.
selectedGroupId
);
if
(
index
>
-
1
)
{
this
.
item
.
selectedGroups
.
splice
(
index
,
1
);
}
alreadyInGroupList
=
true
;
}
}
if
(
!
alreadyInGroupList
){
this
.
item
.
selectedGroups
.
push
(
this
.
selectedGroupId
);
this
.
groupErrorMessage
=
""
;
}
},
},
},
},
beforeMount
()
{
this
.
getGroups
();
}
};
};
</
script
>
</
script
>
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