Skip to content

Impl: basic icon downloader #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Impl: default icons for templates without icons
  • Loading branch information
fioan89 committed Dec 7, 2022
commit dd975200bc361d4d5001ecffd78b27d795742036
40 changes: 40 additions & 0 deletions src/main/kotlin/com/coder/gateway/icons/CoderIcons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,44 @@ object CoderIcons {
val RED_CIRCLE = IconLoader.getIcon("red_circle.svg", javaClass)

val DELETE = IconLoader.getIcon("delete.svg", javaClass)

val ZERO = IconLoader.getIcon("0.svg", javaClass)
val ONE = IconLoader.getIcon("1.svg", javaClass)
val TWO = IconLoader.getIcon("2.svg", javaClass)
val THREE = IconLoader.getIcon("3.svg", javaClass)
val FOUR = IconLoader.getIcon("4.svg", javaClass)
val FIVE = IconLoader.getIcon("5.svg", javaClass)
val SIX = IconLoader.getIcon("6.svg", javaClass)
val SEVEN = IconLoader.getIcon("7.svg", javaClass)
val EIGHT = IconLoader.getIcon("8.svg", javaClass)
val NINE = IconLoader.getIcon("9.svg", javaClass)

val A = IconLoader.getIcon("a.svg", javaClass)
val B = IconLoader.getIcon("b.svg", javaClass)
val C = IconLoader.getIcon("c.svg", javaClass)
val D = IconLoader.getIcon("d.svg", javaClass)
val E = IconLoader.getIcon("e.svg", javaClass)
val F = IconLoader.getIcon("f.svg", javaClass)
val G = IconLoader.getIcon("g.svg", javaClass)
val H = IconLoader.getIcon("h.svg", javaClass)
val I = IconLoader.getIcon("i.svg", javaClass)
val J = IconLoader.getIcon("j.svg", javaClass)
val K = IconLoader.getIcon("k.svg", javaClass)
val L = IconLoader.getIcon("l.svg", javaClass)
val M = IconLoader.getIcon("m.svg", javaClass)
val N = IconLoader.getIcon("n.svg", javaClass)
val O = IconLoader.getIcon("o.svg", javaClass)
val P = IconLoader.getIcon("p.svg", javaClass)
val Q = IconLoader.getIcon("q.svg", javaClass)
val R = IconLoader.getIcon("r.svg", javaClass)
val S = IconLoader.getIcon("s.svg", javaClass)
val T = IconLoader.getIcon("t.svg", javaClass)
val U = IconLoader.getIcon("u.svg", javaClass)
val V = IconLoader.getIcon("v.svg", javaClass)
val W = IconLoader.getIcon("w.svg", javaClass)
val X = IconLoader.getIcon("x.svg", javaClass)
val Y = IconLoader.getIcon("y.svg", javaClass)
val Z = IconLoader.getIcon("z.svg", javaClass)


}
49 changes: 44 additions & 5 deletions src/main/kotlin/com/coder/gateway/sdk/TemplateIconDownloader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ class TemplateIconDownloader {
private val coderClient: CoderRestClientService = service()

fun load(path: String, templateName: String): Icon {
if (path.isBlank()) {
return CoderIcons.UNKNOWN
}

var url: URL? = null
if (path.startsWith("http")) {
url = path.toURL()
Expand All @@ -36,6 +32,49 @@ class TemplateIconDownloader {
}
}

return CoderIcons.UNKNOWN
return iconForChar(templateName.lowercase().first())
}

private fun iconForChar(c: Char) = when (c) {
'0' -> CoderIcons.ZERO
'1' -> CoderIcons.ONE
'2' -> CoderIcons.TWO
'3' -> CoderIcons.THREE
'4' -> CoderIcons.FOUR
'5' -> CoderIcons.FIVE
'6' -> CoderIcons.SIX
'7' -> CoderIcons.SEVEN
'8' -> CoderIcons.EIGHT
'9' -> CoderIcons.NINE

'a' -> CoderIcons.A
'b' -> CoderIcons.B
'c' -> CoderIcons.C
'd' -> CoderIcons.D
'e' -> CoderIcons.E
'f' -> CoderIcons.F
'g' -> CoderIcons.G
'h' -> CoderIcons.H
'i' -> CoderIcons.I
'j' -> CoderIcons.J
'k' -> CoderIcons.K
'l' -> CoderIcons.L
'm' -> CoderIcons.M
'n' -> CoderIcons.N
'o' -> CoderIcons.O
'p' -> CoderIcons.P
'q' -> CoderIcons.Q
'r' -> CoderIcons.R
's' -> CoderIcons.S
't' -> CoderIcons.T
'u' -> CoderIcons.U
'v' -> CoderIcons.V
'w' -> CoderIcons.W
'x' -> CoderIcons.X
'y' -> CoderIcons.Y
'z' -> CoderIcons.Z

else -> CoderIcons.UNKNOWN
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
this.name,
this.templateID,
this.templateName,
iconDownloader.load(this@agentModels.templateIcon, this.templateName),
iconDownloader.load(this@agentModels.templateIcon, this.name),
WorkspaceVersionStatus.from(this),
WorkspaceAgentStatus.from(this),
this.latestBuild.transition,
Expand All @@ -470,7 +470,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
workspaceWithAgentName,
this.templateID,
this.templateName,
iconDownloader.load(this@agentModels.templateIcon, this.templateName),
iconDownloader.load(this@agentModels.templateIcon, workspaceWithAgentName),
WorkspaceVersionStatus.from(this),
WorkspaceAgentStatus.from(this),
this.latestBuild.transition,
Expand All @@ -489,7 +489,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
this.name,
this.templateID,
this.templateName,
iconDownloader.load(this@agentModels.templateIcon, this.templateName),
iconDownloader.load(this@agentModels.templateIcon, this.name),
WorkspaceVersionStatus.from(this),
WorkspaceAgentStatus.from(this),
this.latestBuild.transition,
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/4.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/5.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/6.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/7.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/8.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/9.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/a.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/b.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/c.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/d.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/e.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/f.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/g.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/h.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/i.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/j.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/k.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/l.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/m.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/n.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/o.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/p.svg
4 changes: 4 additions & 0 deletions src/main/resources/q.svg
4 changes: 4 additions & 0 deletions src/main/resources/r.svg
4 changes: 4 additions & 0 deletions src/main/resources/s.svg
4 changes: 4 additions & 0 deletions src/main/resources/t.svg
4 changes: 4 additions & 0 deletions src/main/resources/u.svg
4 changes: 4 additions & 0 deletions src/main/resources/v.svg
4 changes: 4 additions & 0 deletions src/main/resources/w.svg
4 changes: 4 additions & 0 deletions src/main/resources/x.svg
4 changes: 4 additions & 0 deletions src/main/resources/y.svg
4 changes: 4 additions & 0 deletions src/main/resources/z.svg