Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciusdandrade committed Jun 8, 2024
2 parents fc8c2c3 + 551cdc1 commit 4d69e91
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 100 deletions.
3 changes: 1 addition & 2 deletions app_client/static/css/app_client/rating.css
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,9 @@
margin-bottom: 20px;
}

.starErrorContainer span {
.error-message {
display: flex;
align-items: center;
justify-content: center;
gap: 4px;
color: var(--red-600);
margin-top: 16px;
Expand Down
86 changes: 63 additions & 23 deletions app_client/templates/RequestOrder/rateservice.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,31 @@
{% if rating %}
<input type="hidden" name="edit_rating">
{% endif %}
<input type="hidden" name="attendance" id="attendance" value="{{ rating.attendance }}">
<input type="hidden" name="service" id="service" value="{{ rating.service }}">
<input type="hidden" name="time" id="time" value="{{ rating.time }}">

{% if rating.attendance %}
<input type="hidden" name="attendance" id="attendance" value="{{ rating.attendance }}">
{% elif rating.attendance and attendance %}
<input type="hidden" name="attendance" id="attendance" value="{{ attendance }}">
{% else %}
<input type="hidden" name="attendance" id="attendance" value="{{ attendance }}">
{% endif %}

{% if rating.service %}
<input type="hidden" name="service" id="service" value="{{ rating.service }}">
{% elif rating.service and service %}
<input type="hidden" name="service" id="service" value="{{ service }}">
{% else %}
<input type="hidden" name="service" id="service" value="{{ service }}">
{% endif %}

{% if rating.time %}
<input type="hidden" name="time" id="time" value="{{ rating.time }}">
{% elif rating.time and time %}
<input type="hidden" name="time" id="time" value="{{ time }}">
{% else %}
<input type="hidden" name="time" id="time" value="{{ time }}">
{% endif %}


<h1>Avaliação de serviço</h1>

Expand All @@ -26,7 +48,8 @@ <h1>Avaliação de serviço</h1>
<label>Atendimento:</label>
<div class="starErrorContainer">
<div class="ratingAttendance">
{% if rating.attendance >= 1 %}
{{ rating.attendance }}
{% if rating.attendance >= 1 or attendance >= 1 %}
<button type="button" class="attendance active">
{% else %}
<button type="button" class="attendance">
Expand All @@ -41,7 +64,7 @@ <h1>Avaliação de serviço</h1>
C22.602,0.567,25.338,0.567,26.285,2.486z"/>
</svg>
</button>
{% if rating.attendance >= 2 %}
{% if rating.attendance >= 2 or attendance >= 2 %}
<button type="button" class="attendance active">
{% else %}
<button type="button" class="attendance">
Expand All @@ -56,7 +79,7 @@ <h1>Avaliação de serviço</h1>
C22.602,0.567,25.338,0.567,26.285,2.486z"/>
</svg>
</button>
{% if rating.attendance >= 3 %}
{% if rating.attendance >= 3 or attendance >= 3 %}
<button type="button" class="attendance active">
{% else %}
<button type="button" class="attendance">
Expand All @@ -71,7 +94,7 @@ <h1>Avaliação de serviço</h1>
C22.602,0.567,25.338,0.567,26.285,2.486z"/>
</svg>
</button>
{% if rating.attendance >= 4 %}
{% if rating.attendance >= 4 or attendance >= 4 %}
<button type="button" class="attendance active">
{% else %}
<button type="button" class="attendance">
Expand All @@ -86,7 +109,7 @@ <h1>Avaliação de serviço</h1>
C22.602,0.567,25.338,0.567,26.285,2.486z"/>
</svg>
</button>
{% if rating.attendance >= 5 %}
{% if rating.attendance >= 5 or attendance >= 5 %}
<button type="button" class="attendance active">
{% else %}
<button type="button" class="attendance">
Expand All @@ -105,7 +128,7 @@ <h1>Avaliação de serviço</h1>

{% for error in errors %}
{% if error.field == 'attendance' %}
<span>
<span class="error-message">
<i data-lucide="octagon-alert"></i>
{{ error.message }}
</span>
Expand All @@ -118,7 +141,7 @@ <h1>Avaliação de serviço</h1>
<label>Serviço:</label>
<div class="starErrorContainer">
<div class="ratingService">
{% if rating.service >= 1 %}
{% if rating.service >= 1 or service >= 1 %}
<button type="button" class="service active">
{% else %}
<button type="button" class="service">
Expand All @@ -133,7 +156,7 @@ <h1>Avaliação de serviço</h1>
C22.602,0.567,25.338,0.567,26.285,2.486z"/>
</svg>
</button>
{% if rating.service >= 2 %}
{% if rating.service >= 2 or service >= 2 %}
<button type="button" class="service active">
{% else %}
<button type="button" class="service">
Expand All @@ -148,7 +171,7 @@ <h1>Avaliação de serviço</h1>
C22.602,0.567,25.338,0.567,26.285,2.486z"/>
</svg>
</button>
{% if rating.service >= 3 %}
{% if rating.service >= 3 or service >= 3 %}
<button type="button" class="service active">
{% else %}
<button type="button" class="service">
Expand All @@ -163,7 +186,7 @@ <h1>Avaliação de serviço</h1>
C22.602,0.567,25.338,0.567,26.285,2.486z"/>
</svg>
</button>
{% if rating.service >= 4 %}
{% if rating.service >= 4 or service >= 4 %}
<button type="button" class="service active">
{% else %}
<button type="button" class="service">
Expand All @@ -178,7 +201,7 @@ <h1>Avaliação de serviço</h1>
C22.602,0.567,25.338,0.567,26.285,2.486z"/>
</svg>
</button>
{% if rating.service >= 5 %}
{% if rating.service >= 5 or service >= 5 %}
<button type="button" class="service active">
{% else %}
<button type="button" class="service">
Expand All @@ -197,7 +220,7 @@ <h1>Avaliação de serviço</h1>

{% for error in errors %}
{% if error.field == 'service' %}
<span>
<span class="error-message">
<i data-lucide="octagon-alert"></i>
{{ error.message }}
</span>
Expand All @@ -210,7 +233,7 @@ <h1>Avaliação de serviço</h1>
<label>Tempo:</label>
<div class="starErrorContainer">
<div class="ratingTime">
{% if rating.time >= 1 %}
{% if rating.time >= 1 or time >= 1 %}
<button type="button" class="time active">
{% else %}
<button type="button" class="time">
Expand All @@ -225,7 +248,7 @@ <h1>Avaliação de serviço</h1>
C22.602,0.567,25.338,0.567,26.285,2.486z"/>
</svg>
</button>
{% if rating.time >= 2 %}
{% if rating.time >= 2 or time >= 2 %}
<button type="button" class="time active">
{% else %}
<button type="button" class="time">
Expand All @@ -240,7 +263,7 @@ <h1>Avaliação de serviço</h1>
C22.602,0.567,25.338,0.567,26.285,2.486z"/>
</svg>
</button>
{% if rating.time >= 3 %}
{% if rating.time >= 3 or time >= 3 %}
<button type="button" class="time active">
{% else %}
<button type="button" class="time">
Expand All @@ -255,7 +278,7 @@ <h1>Avaliação de serviço</h1>
C22.602,0.567,25.338,0.567,26.285,2.486z"/>
</svg>
</button>
{% if rating.time >= 4 %}
{% if rating.time >= 4 or time >= 4 %}
<button type="button" class="time active">
{% else %}
<button type="button" class="time">
Expand All @@ -270,7 +293,7 @@ <h1>Avaliação de serviço</h1>
C22.602,0.567,25.338,0.567,26.285,2.486z"/>
</svg>
</button>
{% if rating.time >= 5 %}
{% if rating.time >= 5 or time >= 5 %}
<button type="button" class="time active">
{% else %}
<button type="button" class="time">
Expand All @@ -290,7 +313,7 @@ <h1>Avaliação de serviço</h1>

{% for error in errors %}
{% if error.field == 'time' %}
<span>
<span class="error-message">
<i data-lucide="octagon-alert"></i>
{{ error.message }}
</span>
Expand All @@ -299,8 +322,25 @@ <h1>Avaliação de serviço</h1>
</div>
</div>

<label for="notes">Comentários adicionais:</label>
<textarea type="text" id="notes" name="notes">{{ rating.notes }}</textarea>
<div class="textareaContainer">
<label for="notes">Comentários adicionais:</label>
{% if rating.notes %}
<textarea type="text" id="notes" name="notes">{{ rating.notes }}</textarea>
{% elif review_notes and rating.notes %}
<textarea type="text" id="notes" name="notes">{{ review_notes }}</textarea>
{% else %}
<textarea type="text" id="notes" name="notes">{{ review_notes }}</textarea>
{% endif %}

{% for error in errors %}
{% if error.field == 'review_notes' %}
<span class="error-message">
<i data-lucide="octagon-alert"></i>
{{ error.message }}
</span>
{% endif %}
{% endfor %}
</div>
</section>

<button type="submit" class="rating-submit">Avaliar</button>
Expand Down
2 changes: 1 addition & 1 deletion app_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def rating_treatment(attendance, service, time, review_notes):
if len(str(review_notes)) > 200:
errors.append({
'field': 'review_notes',
'message' : 'Este campo não pode ser maior que 200 caractéres!'
'message' : 'O seu comentário não pode ultrapassar 200 caracteres!'
})

return errors
Expand Down
32 changes: 23 additions & 9 deletions app_client/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import re
from datetime import date, timedelta
from datetime import date, datetime, timedelta

from django.shortcuts import render, redirect
from django.contrib import messages
Expand Down Expand Up @@ -245,14 +245,21 @@ def post(self, request, id):
time = request.POST.get('time')
notes = request.POST.get('notes')

ctx = {
'attendance': int(attendance),
'service': int(service),
'time': int(time),
'review_notes': notes,
}

errors = rating_treatment(attendance=attendance, service=service, time=time, review_notes=notes)

if len(errors) > 0:
order = OrderRequest.objects.get(id=id)
ctx = {
"order": order,
"errors": errors
}
ctx["order"] = order
ctx["errors"] = errors
for error in errors:
ctx.pop(error['field'], None)
return render(request, 'RequestOrder/rateservice.html', ctx)
else:
rating.attendance = attendance
Expand All @@ -268,14 +275,21 @@ def post(self, request, id):
time = request.POST.get('time')
review_notes = request.POST.get('notes')

ctx = {
'attendance': int(attendance),
'service': int(service),
'time': int(time),
'review_notes': review_notes,
}

errors = rating_treatment(attendance=attendance, service=service, time=time, review_notes=review_notes)

if len(errors) > 0:
order = OrderRequest.objects.filter(id=id).first()
ctx = {
"order": order,
"errors": errors
}
ctx["order"] = order
ctx["errors"] = errors
for error in errors:
ctx.pop(error['field'], None)
return render(request, 'RequestOrder/rateservice.html', ctx)
else:
rating = ServiceRating(attendance = attendance, time = time, service = service, notes = review_notes, os_id = id)
Expand Down
12 changes: 12 additions & 0 deletions app_company/templates/app_company/order-request-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,20 @@ <h1>Solicitação {{order_request.id}}</h1>
<div class="works">
<label for="detailed_problem_description">Descrição detalhada do problema:</label>
<textarea id="detailed_problem_description" name="detailed_problem_description" required></textarea>
{% if error %}
<span>
<i data-lucide="octagon-alert"></i>
{{ error.message }}
</span>
{% endif %}
<label for="necessary_parts">Partes necessárias:</label>
<textarea id="necessary_parts" name="necessary_parts" required></textarea>
{% if error %}
<span>
<i data-lucide="octagon-alert"></i>
{{ error.message }}
</span>
{% endif %}
<button type="submit">Gerar ordem de serviço.</button>
</div>
{% endif %}
Expand Down
20 changes: 19 additions & 1 deletion app_company/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,25 @@ def post(self, request, pk):
order_request.isOs = True
detailed_problem_description = request.POST.get('detailed_problem_description')
necessary_parts = request.POST.get('necessary_parts')


nule_detailed_problem_description = detailed_problem_description.strip()
nule_necessary_parts = necessary_parts.strip()
if not nule_detailed_problem_description or len(detailed_problem_description) <= 1:
ctx = {
"order_request": order_request,
"error": {
"message": f"O campo não pode ser vazio!"
}
}
return render(request, "app_company/order-request-detail.html", ctx)
if not nule_necessary_parts or len(necessary_parts) <= 1:
ctx = {
"order_request": order_request,
"error": {
"message": f"O campo não pode ser vazio!"
}
}
return render(request, "app_company/order-request-detail.html", ctx)
order_request.detailedProblemDescription = detailed_problem_description
order_request.necessaryParts = necessary_parts
order_request.status = 'EM_REPARO'
Expand Down
10 changes: 5 additions & 5 deletions cypress/e2e/ConvertOrderRequest.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('HomePage', () => {
cy.get('.content > form > button').click()
cy.get('.logout > button').click()
cy.GoToClient("[email protected]")
cy.get('.view > button').click()
cy.get(':nth-child(4) > a').click()
cy.get('.yes')
cy.get('.waitingForm > form > button').click()
cy.ClientLogout()
Expand Down Expand Up @@ -69,7 +69,7 @@ describe('HomePage', () => {
cy.get('.content > form > button').click()
cy.get('.logout > button').click()
cy.GoToClient("[email protected]")
cy.get('.view > button').click()
cy.get(':nth-child(4) > a').click()
cy.get('.waitingForm > form > button').click()
cy.get('.logout').click()
cy.get('#employee > a').click()
Expand Down Expand Up @@ -112,7 +112,7 @@ describe('HomePage', () => {
cy.get('.content > form > button').click()
cy.get('.logout > button').click()
cy.GoToClient("[email protected]")
cy.get('.view > button').click()
cy.get(':nth-child(4) > a').click()
cy.get('.yes')
cy.get('.waitingForm > form > button').click()
cy.ClientLogout()
Expand All @@ -122,7 +122,7 @@ describe('HomePage', () => {
cy.get('#detailed_problem_description').type(' ')
cy.get('#necessary_parts').type(' ')
cy.get('.works > button').click()


cy.get('.works > :nth-child(3)').invoke('text').should("have.string", "O campo não pode ser vazio!")
cy.get('.works > :nth-child(6)').invoke('text').should("have.string", "O campo não pode ser vazio!")
})
})
Loading

0 comments on commit 4d69e91

Please sign in to comment.