Skip to content

Commit

Permalink
Uploader improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
essenciary committed Jan 8, 2024
1 parent 9e17cc0 commit c2f47b3
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StippleUI"
uuid = "a3c5d34a-b254-4859-a8fa-b86abb7e84a3"
authors = ["Adrian Salceanu <[email protected]>"]
version = "0.22.14"
version = "0.22.15"

[deps]
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Expand Down
2 changes: 2 additions & 0 deletions demos/uploader/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
GenieAutoReload = "c6228e60-a24f-11e9-1776-c313472ebacc"
GenieFramework = "a59fdf5c-6bf0-4f5d-949c-a137c9e2f353"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Stipple = "4acbeb90-81a0-11ea-1966-bdaff8155998"
StippleUI = "a3c5d34a-b254-4859-a8fa-b86abb7e84a3"
43 changes: 28 additions & 15 deletions demos/uploader/app.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
module App

using Random, Base64
using GenieFramework
@genietools

@app begin
@out accept = ".jpg, .jpeg, .pdf, image/*"
@out imgsrc = "/img/placeholder-image.jpg"
@out maxfilesize = 10 * 1024 * 1024
@out caption = "No image selected"

@event rejected begin
@info "rejected"
# @info params(:payload)["event"]
notify("File rejected. Please make sure it is a valid image file.")
end

# @event added begin
Expand All @@ -29,28 +35,35 @@ using GenieFramework
# # @info params(:payload)["event"]
# end

# @event uploaded begin
# @info "uploaded"
# # @info params(:payload)["event"]
# end
@event uploaded begin
@info "uploaded"
end

# @event finished begin
# @info "finished"
# # @info params(:payload)["event"]
# end
@event finished begin
@info "finished"
end

# @event failed begin
# @info "failed"
# # @info params(:payload)["event"]
# end
@event failed begin
@info "failed"
notify("File upload failed. Please try again.")
end

@onchange fileuploads begin
if ! isempty(fileuploads)
@info "File was uploaded: " fileuploads
filename = Random.randstring(10) * "_" * base64encode(fileuploads["name"])

try
isdir(joinpath("public", "uploads")) || mkdir(joinpath("public", "uploads"))
mv(fileuploads["path"], joinpath("public", "uploads", filename))
catch e
@error "Error processing file: $e"
notify("Error processing file: $(fileuploads["name"])")
end

imgsrc = "/uploads/$filename"
fileuploads = Dict{AbstractString,AbstractString}()
end

@info "All good"
end
end

Expand Down
Binary file added demos/uploader/public/img/placeholder-image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 32 additions & 25 deletions demos/uploader/ui.jl
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
heading("File uploader demo")
uploader( multiple = true,
accept = ".jpg, .jpeg, .pdf, image/*",
maxfilesize = 102400000000,
maxfiles = 10,
autoupload = true,
hideuploadbtn = true,
method = "POST",
label = "Upload Images",
nothumbnails = false,
dark = false,
square = false,
flat = false,
bordered = false,
# url = "/upload",
# url! = "'foo' + 'bar'",
row() do
cell() do
heading("File uploader demo")
end
end
row() do
cell() do
uploader( multiple = true,
accept = :accept,
maxfilesize = :maxfilesize,
maxfiles = 10,
autoupload = true,
hideuploadbtn = true,
label = "Upload Images",
nothumbnails = true,
style="max-width: 95%; width: 95%; margin: 0 auto;",

# @on("rejected", :rejected),
# @on("added", :added),
# @on("removed", :removed),
# @on("uploaded", :uploaded),
# @on("uploading", :uploading),
# @on("start", :started),
# @on("finish", :finished),
# @on("failed", :failed)
)
@on("rejected", :rejected),
@on("uploaded", :uploaded),
@on("finish", :finished),
@on("failed", :failed),
# @on("uploading", :uploading),
# @on("start", :started),
# @on("added", :added),
# @on("removed", :removed),
)
end
end
row() do
cell() do
img(src! = "imgsrc", style="max-width: 95%; margin-left: 25px", placeholder__src="/img/placeholder-image.jpg")
end
end
2 changes: 1 addition & 1 deletion src/ImageViews.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ julia> imageview(src = :url, style = "height: 140px; max-width: 150px", [
* `sizes::String` - Same syntax as <img> sizes attribute. ex. `(max-width: 320px) 280px, (max-width: 480px) 440px, 800px`
* `width::String` - Forces image width; Must also include the unit (px or %) ex. `280px` `70%`
* `height::String` - Forces image height; Must also include the unit (px or %) ex. `280px` `70%`
* `placeholdersrc::String` - While waiting for your image to load, you can use a placeholder image ex. `(public folder) src="img/something.png"` `(assets folder) src="~assets/my-img.gif"` `(URL) src="https://placeimg.com/500/300/nature"`
* `placeholdersrc::String` - While waiting for your image to load, you can use a placeholder image ex. `(public folder) src="img/something.png"` `(assets folder) src="~assets/my-img.gif"` `(URL) src="https://placeimg.com/500/300/nature"`
4. Style
* `color::String` - Color name for component from the [Color Palette](https://quasar.dev/style/color-palette) eg. `primary` `teal-10`
* `imgclass::Union{Vector, String, Dict}` - Class definitions to be attributed to the container of image; Does not apply to the caption ex. `my-special-class` `imgclass!="{ 'my-special-class': <condition> }"`
Expand Down
11 changes: 4 additions & 7 deletions src/Uploaders.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,19 @@ julia> uploader(label="Upload Image", autoupload=true, multiple=true, method="PO
"""
function uploader(args...;
url::Union{AbstractString,Nothing} = nothing,
url!::Union{AbstractString,Nothing} = nothing,
method::AbstractString = "POST",
kwargs...)
kws = []
if url === nothing && url! === nothing && method == "POST"
url! = "'/____/upload/' + channel_"
push!(kws, :url! => url!)
elseif url! !== nothing
push!(kws, :url! => url!)

# use default upload url if none is provided and method is POST
if url === nothing && method == "POST"
url = Symbol("'/____/upload/' + channel_")
end

if url !== nothing
push!(kws, :url => url)
end


q__uploader(args...; kw([kws..., kwargs...])...)
end

Expand Down

2 comments on commit c2f47b3

@essenciary
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/98447

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.22.15 -m "<description of version>" c2f47b383e86cfd628f699c765d78d40a7c6f9f2
git push origin v0.22.15

Please sign in to comment.