Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
imageboard-web
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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Trirst
imageboard-web
Commits
6ac68096
Commit
6ac68096
authored
Oct 5, 2021
by
Trirst
Browse files
Options
Downloads
Patches
Plain Diff
Componentize image's metadata fields
parent
bec299e8
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/App.vue
+1
-7
1 addition, 7 deletions
src/App.vue
src/components/ImageMetadataFields.vue
+105
-0
105 additions, 0 deletions
src/components/ImageMetadataFields.vue
src/components/ImageUpload.vue
+7
-83
7 additions, 83 deletions
src/components/ImageUpload.vue
with
113 additions
and
90 deletions
src/App.vue
+
1
−
7
View file @
6ac68096
...
...
@@ -9,9 +9,3 @@
<router-view
/>
</div>
</
template
>
\ No newline at end of file
<
style
>
.inputBox
{
@apply
border-2
focus
:
outline-none
focus
:
ring-2
focus
:
ring-blue-300
;
}
</
style
>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/components/ImageMetadataFields.vue
0 → 100644
+
105
−
0
View file @
6ac68096
<
template
>
<div
class=
"flex flex-col flex-1"
>
<form
id=
"payloadFields"
class=
"flex flex-col flex-1"
>
<input
type=
"text"
placeholder=
"Source"
name=
"source"
autocomplete=
"off"
class=
"imageInfoFields"
/>
<input
type=
"text"
placeholder=
"Parent"
name=
"parent"
autocomplete=
"off"
class=
"imageInfoFields"
/>
<textarea
type=
"text"
placeholder=
"Commentary"
name=
"commentary"
autocomplete=
"off"
class=
"imageInfoFields resize-none flex-1"
/>
<textarea
type=
"text"
placeholder=
"Commentary translation"
name=
"commentary_translation"
autocomplete=
"off"
class=
"imageInfoFields resize-none flex-1"
/>
</form>
<input
id=
"tagField"
type=
"text"
placeholder=
"Tags"
name=
"tags"
autocomplete=
"off"
class=
"imageInfoFields"
/>
</div>
</
template
>
<
script
>
import
{
mapState
}
from
"
vuex
"
;
import
paths
from
"
@/assets/js/paths.js
"
;
export
default
{
props
:
{
id
:
{
required
:
true
,
},
},
created
()
{
this
.
$parent
.
$on
(
`update-image-info-
${
this
.
id
}
`
,
this
.
updateImageMetadata
);
},
computed
:
{
...
mapState
([
"
stateUser
"
]),
},
methods
:
{
updateImageMetadata
(
flake
)
{
this
.
updateImageInfo
(
flake
,
this
.
serializeForm
(
"
payloadFields
"
));
this
.
updateImageTags
(
flake
,
"
tagField
"
);
},
// Serialize form inputs into JSON object that can be sent to API endpoints
serializeForm
(
formID
)
{
return
JSON
.
stringify
(
Object
.
fromEntries
(
new
FormData
(
document
.
getElementById
(
formID
)))
);
},
// Send an image update payload including 4 fields:
// "source", "parent", "commentary", "commentary translation" to paths.ImageField
async
updateImageInfo
(
flake
,
imageUpdatePayload
)
{
const
options
=
{
method
:
"
PATCH
"
,
headers
:
{
secret
:
this
.
stateUser
.
secret
,
},
body
:
imageUpdatePayload
,
};
await
fetch
(
`/api/image/
${
flake
}
`
,
options
);
},
async
updateImageTags
(
flake
,
tagsInputID
)
{
// Multiple tags are delimited by a white space
const
tags
=
document
.
getElementById
(
tagsInputID
)
.
value
.
split
(
"
"
)
.
filter
((
element
)
=>
element
.
length
>
0
);
const
options
=
{
method
:
"
PUT
"
,
};
for
(
let
i
=
0
;
i
<
tags
.
length
;
i
++
)
{
await
fetch
(
paths
.
ImageTagField
(
flake
,
tags
[
i
]),
options
);
}
},
},
};
</
script
>
<
style
scoped
>
.imageInfoFields
{
@apply
border-2
focus
:
outline-none
focus
:
ring-2
focus
:
ring-blue-300
pl-1
my-2
;
}
</
style
>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/components/ImageUpload.vue
+
7
−
83
View file @
6ac68096
...
...
@@ -68,46 +68,7 @@
alt=
""
class=
"max-w-xs m-4"
/>
<div
class=
"flex flex-col flex-1"
>
<form
:id=
"'image-update-form-' + id"
class=
"flex flex-col flex-1"
>
<input
type=
"text"
placeholder=
"Source"
name=
"source"
autocomplete=
"off"
class=
"inputBox inputPayload"
/>
<input
type=
"text"
placeholder=
"Parent"
name=
"parent"
autocomplete=
"off"
class=
"inputBox inputPayload"
/>
<textarea
type=
"text"
placeholder=
"Commentary"
name=
"commentary"
autocomplete=
"off"
class=
"inputBox inputPayload resize-none flex-1"
/>
<textarea
type=
"text"
placeholder=
"Commentary translation"
name=
"commentary_translation"
autocomplete=
"off"
class=
"inputBox inputPayload resize-none flex-1"
/>
</form>
<input
type=
"text"
placeholder=
"Tags"
name=
"tags"
autocomplete=
"off"
:id=
"'tagsInput' + id"
class=
"inputBox inputPayload"
/>
</div>
<ImageMetadataFields
:id=
"id"
></ImageMetadataFields>
</div>
</div>
</
template
>
...
...
@@ -115,11 +76,13 @@
<
script
>
import
{
mapActions
,
mapState
}
from
"
vuex
"
;
import
WarningBox
from
"
@/components/WarningBox.vue
"
;
import
ImageMetadataFields
from
"
@/components/ImageMetadataFields.vue
"
;
import
paths
from
"
@/assets/js/paths.js
"
;
export
default
{
components
:
{
WarningBox
,
ImageMetadataFields
,
},
data
:
()
=>
{
return
{
...
...
@@ -173,47 +136,14 @@ export default {
for
(
let
i
=
0
;
i
<
this
.
imageUploadList
.
length
;
i
++
)
{
formData
.
set
(
"
image
"
,
this
.
imageUploadList
[
i
].
file
);
let
data
=
await
this
.
postImageFile
(
formData
);
this
.
setImageInfo
(
data
.
snowflake
,
this
.
serializeForm
(
"
image-update-form-
"
+
i
)
);
this
.
setImageTags
(
data
.
snowflake
,
"
tagsInput
"
+
i
);
// Signal ImageUpdateFields along with sending the image's snowflake
// to update corresponding image information
this
.
$emit
(
`update-image-info-
${
i
}
`
,
data
.
snowflake
);
}
// Clean up
this
.
invalidType
=
false
;
this
.
imageUploadList
=
[];
},
// Serialize form inputs into JSON object that can be sent to API
serializeForm
(
formID
)
{
return
JSON
.
stringify
(
Object
.
fromEntries
(
new
FormData
(
document
.
getElementById
(
formID
)))
);
},
// Send an image update payload including 4 fields: "source", "parent", "commentary",
// "commentary translation" to paths.ImageField
async
setImageInfo
(
flake
,
imageUpdatePayload
)
{
const
options
=
{
method
:
"
PATCH
"
,
headers
:
{
secret
:
this
.
stateUser
.
secret
,
},
body
:
imageUpdatePayload
,
};
await
fetch
(
`/api/image/
${
flake
}
`
,
options
);
},
async
setImageTags
(
flake
,
tagsInputID
)
{
const
tags
=
document
.
getElementById
(
tagsInputID
)
.
value
.
split
(
"
"
)
.
filter
((
element
)
=>
element
.
length
>
0
);
const
options
=
{
method
:
"
PUT
"
,
};
for
(
let
i
=
0
;
i
<
tags
.
length
;
i
++
)
{
await
fetch
(
paths
.
ImageTagField
(
flake
,
tags
[
i
]),
options
);
}
},
async
postImageFile
(
fd
)
{
const
options
=
{
method
:
"
POST
"
,
...
...
@@ -231,9 +161,3 @@ export default {
},
};
</
script
>
\ No newline at end of file
<
style
scoped
>
.inputPayload
{
@apply
pl-1
my-2;
}
</
style
>
\ No newline at end of file
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