μ΄ μμ λ λΆλλ½κ² μ€ν¬λ‘€λλ μ§ν λ°λ₯Ό ꡬννλ λ°©λ²μ 보μ¬μ€λλ€.
μ°λ¦¬λ /start
λ‘ POST
μμ²μ λ³΄λ΄ μμ
μ μμνλ λ²νΌμ΄ μλ μ΄κΈ° μνλ‘ μμν©λλ€:
<div hx-target="this" hx-swap="outerHTML">
<h3>Start Progress</h3>
<button class="btn primary" hx-post="/start">
Start Job
</button>
</div>
μ΄ divλ μνμ μ§ν λ°κ° ν¬ν¨λ μλ‘μ΄ divλ‘ κ΅μ²΄λλ©°, μ΄ μ§ν λ°λ 600msλ§λ€ μλμΌλ‘ μλ‘ κ³ μ³μ§λλ€:
<div hx-trigger="done" hx-get="/job" hx-swap="outerHTML" hx-target="this">
<h3 role="status" id="pblabel" tabindex="-1" autofocus>Running</h3>
<div
hx-get="/job/progress"
hx-trigger="every 600ms"
hx-target="this"
hx-swap="innerHTML">
<div class="progress" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0" aria-labelledby="pblabel">
<div id="pb" class="progress-bar" style="width:0%">
</div>
</div>
</div>
μ΄ μ§ν λ°λ 600λ°λ¦¬μ΄λ§λ€ μ
λ°μ΄νΈλλ©°, width
μ€νμΌ μμ±κ³Ό aria-valuenow
μμ±μ΄ νμ¬ μ§ν μνλ‘ μ€μ λ©λλ€.
μ§ν λ° divμ IDκ° μκΈ° λλ¬Έμ, htmxλ μ€νμΌ μμ±μ μλ‘μ΄ κ°μΌλ‘ μ€μ νλ©΄μ μμ² μ¬μ΄μ λ³νλ₯Ό λΆλλ½κ² μ νν©λλ€.
μ΄λ CSS μ νκ³Ό κ²°ν©λμ΄ μκ°μ μΈ μ νμ΄ λκΉ μμ΄ λΆλλ½κ² μ§νλ©λλ€.
λ§μ§λ§μΌλ‘, νλ‘μΈμ€κ° μλ£λλ©΄ μλ²λ HX-Trigger: done
ν€λλ₯Ό λ°ννμ¬ UIλ₯Ό βCompleteβ μνλ‘ μ
λ°μ΄νΈνλ©°,
UIμ λ€μ μμ λ²νΌμ΄ μΆκ°λ©λλ€(μ΄ μμ μμλ λ²νΌμ νμ΄λμΈ ν¨κ³Όλ₯Ό μΆκ°νκΈ° μν΄ class-tools
νμ₯μ μ¬μ©νκ³ μμ΅λλ€):
<div hx-trigger="done" hx-get="/job" hx-swap="outerHTML" hx-target="this">
<h3 role="status" id="pblabel" tabindex="-1" autofocus>Complete</h3>
<div
hx-get="/job/progress"
hx-trigger="none"
hx-target="this"
hx-swap="innerHTML">
<div class="progress" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="122" aria-labelledby="pblabel">
<div id="pb" class="progress-bar" style="width:122%">
</div>
</div>
</div>
<button id="restart-btn" class="btn primary" hx-post="/start" classes="add show:600ms">
Restart Job
</button>
</div>
μ΄ μμ μμλ Bootstrap μ§ν λ°μ μ€νμΌμ μ°Έμ‘°νκ³ μμ΅λλ€.
.progress {
height: 20px;
margin-bottom: 20px;
overflow: hidden;
background-color: #f5f5f5;
border-radius: 4px;
box-shadow: inset 0 1px 2px rgba(0,0,0,.1);
}
.progress-bar {
float: left;
width: 0%;
height: 100%;
font-size: 12px;
line-height: 20px;
color: #fff;
text-align: center;
background-color: #337ab7;
-webkit-box-shadow: inset 0 -1px 0 rgba(0,0,0,.15);
box-shadow: inset 0 -1px 0 rgba(0,0,0,.15);
-webkit-transition: width .6s ease;
-o-transition: width .6s ease;
transition: width .6s ease;
}