Skip to content

Commit

Permalink
Merge pull request #151 from ResidenciaTICBrisa/FrontEnd
Browse files Browse the repository at this point in the history
Conclusão de Equipamentos
  • Loading branch information
AlefMemTav authored Aug 20, 2024
2 parents 3e68f31 + df703ab commit 4daaf81
Show file tree
Hide file tree
Showing 60 changed files with 3,945 additions and 1,720 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2 on 2024-08-14 13:05
# Generated by Django 4.2 on 2024-08-14 13:52

from django.db import migrations

Expand Down
1 change: 1 addition & 0 deletions api/equipments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class AtmosphericDischargeEquipmentByAreaList(generics.ListAPIView):
def get_queryset(self):
area_id = self.kwargs['area_id']
queryset = AtmosphericDischargeEquipment.objects.filter(area_id=area_id)

permitted_objects = []
for obj in queryset:
if self.check_object_permissions(self.request, obj):
Expand Down
6 changes: 3 additions & 3 deletions api/places/templates/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ <h3>{{ installation.area }}</h3>
</div>

{% endif %}

{% if installation.system == 'Quadros de Distribuição' %}
<div class="detail-item">
<strong>Potência:</strong>
<p>{{ installation.power }} KW</p>
</div>

<div class="detail-item">
<strong>DR:</strong>
<p>{{ installation.dr }}</p>
Expand Down Expand Up @@ -248,4 +248,4 @@ <h3>{{ installation.area }}</h3>
<p>Relatório gerado por: {{ generated_by }}</p>
</footer>
</body>
</html>
</html>
4 changes: 3 additions & 1 deletion api/places/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from rest_framework.response import Response
from rest_framework.exceptions import NotFound
from django.http import HttpResponse
from reportlab.lib.pagesizes import A4
from reportlab.pdfgen import canvas
from .models import Place, Area
from .serializers import PlaceSerializer, AreaSerializer
from django.template.loader import render_to_string
Expand Down Expand Up @@ -573,4 +575,4 @@ def get(self, request, pk=None):
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
response['Content-Disposition'] = 'attachment; filename="equipamentos_relatorio.xlsx"'

return response
return response
Binary file modified api/requirements.txt
Binary file not shown.
2 changes: 1 addition & 1 deletion api/sigeie/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

DEBUG = True

ALLOWED_HOSTS = ['127.0.0.1', '10.0.2.2', '192.168.1.123']
ALLOWED_HOSTS = ['127.0.0.1', '10.0.2.2', '192.168.1.142', '192.168.15.36']

MEDIA_URL = '/media/'

Expand Down
4 changes: 3 additions & 1 deletion api/sigeie/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@
path('auth/', include('rest_framework.urls')),
path('api/', include('equipments.urls')),
path('api/', include('places.urls'))
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
]

static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ class AtmosphericRequestModel {
int? area;
int? system;
int? quantity;
String? observation;

AtmosphericRequestModel(
{required this.area, required this.system, this.quantity});
{required this.area,
required this.system,
required this.quantity,
required this.observation});

Map<String, dynamic> toJson() {
return {'area': area, 'system': system, 'quantity': quantity};
return {
'area': area,
'system': system,
'quantity': quantity,
'observation': observation
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@ class AtmosphericEquipmentResponseByAreaModel {
String equipmentCategory;
int system;
int quantity;
String? observation;

AtmosphericEquipmentResponseByAreaModel({
required this.id,
required this.area,
required this.equipmentCategory,
required this.system,
required this.quantity,
});
AtmosphericEquipmentResponseByAreaModel(
{required this.id,
required this.area,
required this.equipmentCategory,
required this.system,
required this.quantity,
required this.observation});

factory AtmosphericEquipmentResponseByAreaModel.fromJson(
Map<String, dynamic> json) {
return AtmosphericEquipmentResponseByAreaModel(
id: json['id'],
area: json['area'],
equipmentCategory: json['equipment_category'],
system: json['system'],
quantity: json['quantity'],
);
id: json['id'],
area: json['area'],
equipmentCategory: json['equipment_category'],
system: json['system'],
quantity: json['quantity'],
observation: json['observation']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ class AtmosphericResponseModel {
int equipment;
int system;
int quantity;
String? observation;

AtmosphericResponseModel({
required this.id,
required this.area,
required this.equipment,
required this.system,
required this.quantity,
});
AtmosphericResponseModel(
{required this.id,
required this.area,
required this.equipment,
required this.system,
required this.quantity,
required this.observation});

factory AtmosphericResponseModel.fromJson(Map<String, dynamic> json) {
return AtmosphericResponseModel(
id: json['id'],
area: json['area'],
equipment: json['equipment'],
system: json['system'],
quantity: json['quantity'],
);
id: json['id'],
area: json['area'],
equipment: json['equipment'],
system: json['system'],
quantity: json['quantity'],
observation: json['observation']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ class AtmosphericEquipmentService {

Future<List<AtmosphericEquipmentResponseByAreaModel>>
getAtmosphericListByArea(int areaId) async {
var url = Uri.parse('${baseUrl}structured-cabling/by-area/$areaId/');
var url = Uri.parse('${baseUrl}atmospheric-discharges/by-area/$areaId/');
try {
var response = await client.get(url);

print('Status Code: ${response.statusCode}');
print('Response Body: ${response.body}');
if (response.statusCode == 200) {
List<dynamic> dataList = jsonDecode(response.body);
return dataList
Expand All @@ -30,56 +31,57 @@ class AtmosphericEquipmentService {
.toList();
} else {
_logger.info(
'Failed to load structured cabling equipment with status code: ${response.statusCode}');
'Failed to load atmospheric discharges equipment with status code: ${response.statusCode}');
_logger.info('Response body: ${response.body}');
throw Exception('Failed to load structured cabling equipment');
throw Exception('Failed to load atmospheric discharges equipment');
}
} catch (e) {
_logger.info('Error during get structured cabling equipment list: $e');
throw Exception('Failed to load structured cabling equipment');
_logger
.info('Error during get atmospheric discharges equipment list: $e');
throw Exception('Failed to load atmospheric discharges equipment');
}
}

Future<void> deleteAtmospheric(int AtmosphericId) async {
var url = Uri.parse('${baseUrl}structured-cabling/$AtmosphericId/');
var url = Uri.parse('${baseUrl}atmospheric-discharges/$AtmosphericId/');
try {
var response = await client.delete(url);
if (response.statusCode == 204) {
_logger.info(
'Successfully deleted structured cabling equipment with ID: $AtmosphericId');
'Successfully deleted atmospheric discharges equipment with ID: $AtmosphericId');
} else {
_logger.info(
'Failed to delete structured cabling equipment with status code: ${response.statusCode}');
'Failed to delete atmospheric discharges equipment with status code: ${response.statusCode}');
_logger.info('Response body: ${response.body}');
throw Exception('Failed to delete structured cabling equipment');
throw Exception('Failed to delete atmospheric discharges equipment');
}
} catch (e) {
_logger.info('Error during delete structured cabling equipment: $e');
throw Exception('Failed to delete structured cabling equipment');
_logger.info('Error during delete atmospheric discharges equipment: $e');
throw Exception('Failed to delete atmospheric discharges equipment');
}
}

Future<AtmosphericResponseModel> getAtmosphericById(int AtmosphericId) async {
var url = Uri.parse('${baseUrl}structured-cabling/$AtmosphericId/');
var url = Uri.parse('${baseUrl}atmospheric-discharges/$AtmosphericId/');
try {
var response = await client.get(url);
if (response.statusCode == 200) {
var jsonResponse = jsonDecode(response.body);
return AtmosphericResponseModel.fromJson(jsonResponse);
} else {
_logger.info(
'Failed to load structured cabling with status code: ${response.statusCode}');
throw Exception('Failed to load structured cabling');
'Failed to load atmospheric discharges with status code: ${response.statusCode}');
throw Exception('Failed to load atmospheric discharges');
}
} catch (e) {
_logger.info('Error during get structured cabling: $e');
throw Exception('Failed to load structured cabling');
_logger.info('Error during get atmospheric discharges: $e');
throw Exception('Failed to load atmospheric discharges');
}
}

Future<bool> updateAtmospheric(int AtmosphericId,
AtmosphericRequestModel AtmosphericIdRequestModel) async {
var url = Uri.parse('${baseUrl}structured-cabling/$AtmosphericId/');
var url = Uri.parse('${baseUrl}atmospheric-discharges/$AtmosphericId/');

try {
var response = await client.put(
Expand All @@ -90,15 +92,15 @@ class AtmosphericEquipmentService {

if (response.statusCode == 200) {
_logger.info(
'Successfully updated structured cabling equipment with ID: $AtmosphericId');
'Successfully updated atmospheric discharges equipment with ID: $AtmosphericId');
return true;
} else {
_logger.info(
'Failed to update structured cabling equipment with status code: ${response.statusCode}');
'Failed to update atmospheric discharges equipment with status code: ${response.statusCode}');
return false;
}
} catch (e) {
_logger.info('Error during update structured cabling equipment: $e');
_logger.info('Error during update atmospheric discharges equipment: $e');
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DistributionEquipmentRequestModel {
return {
'generic_equipment_category': genericEquipmentCategory,
'personal_equipment_category': personalEquipmentCategory,
'structured_cabling_equipment': distributionRequestModel?.toJson(),
'distribution_board_equipment': distributionRequestModel?.toJson(),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ class DistributionRequestModel {
int? area;
int? system;
int? quantity;
String? power;
bool dr;
bool dps;
bool grounding;
int? power;
bool? dr;
bool? dps;
bool? grounding;
String? typeMaterial;
String? methodInstallation;
String? observation;

DistributionRequestModel(
{required this.area,
Expand All @@ -18,7 +19,9 @@ class DistributionRequestModel {
required this.dps,
required this.grounding,
required this.typeMaterial,
required this.methodInstallation});
required this.methodInstallation,
required this.observation});

Map<String, dynamic> toJson() {
return {
'area': area,
Expand All @@ -30,6 +33,7 @@ class DistributionRequestModel {
'grounding': grounding,
'type_material': typeMaterial,
'method_installation': methodInstallation,
'observation': observation
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,26 @@ class DistributionEquipmentResponseByAreaModel {
String equipmentCategory;
int system;
int quantity;
String? power;
bool dr;
bool dps;
bool grounding;
String? typeMaterial;
String? methodInstallation;
String? observation;

DistributionEquipmentResponseByAreaModel(
{required this.id,
required this.area,
required this.equipmentCategory,
required this.system,
required this.quantity,
required this.power,
required this.dr,
required this.dps,
required this.grounding,
required this.typeMaterial,
required this.methodInstallation});
DistributionEquipmentResponseByAreaModel({
required this.id,
required this.area,
required this.equipmentCategory,
required this.system,
required this.quantity,
required this.observation,
});

factory DistributionEquipmentResponseByAreaModel.fromJson(
Map<String, dynamic> json) {
return DistributionEquipmentResponseByAreaModel(
id: json['id'],
area: json['area'],
equipmentCategory: json['equipment_category'],
system: json['system'],
quantity: json['quantity'],
power: json['power'],
dr: json['dr'],
dps: json['dps'],
grounding: json['grounding'],
typeMaterial: json['typeMaterial'],
methodInstallation: json['methodInstallation']);
id: json['id'],
area: json['area'],
equipmentCategory: json['equipment_category'],
system: json['system'],
quantity: json['quantity'],
observation: json['observation'],
);
}
}
Loading

0 comments on commit 4daaf81

Please sign in to comment.