-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Módulo de Áreas casi completo, Falta conectarlo a CT
- Loading branch information
Showing
9 changed files
with
431 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
""" | ||
Área, formularios | ||
""" | ||
|
||
from flask_wtf import FlaskForm | ||
from wtforms import StringField, SubmitField | ||
from wtforms.validators import DataRequired, Length, Optional | ||
|
||
|
||
class AreaForm(FlaskForm): | ||
"""Formulario Area""" | ||
|
||
nombre = StringField("Nombre", validators=[DataRequired(), Length(max=128)]) | ||
centro_trabajo = StringField("Centro de Trabajo", validators=[DataRequired(), Length(max=256)]) | ||
guardar = SubmitField("Guardar") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
Áreas, modelos | ||
""" | ||
|
||
from typing import List | ||
|
||
from sqlalchemy import ForeignKey, String | ||
from sqlalchemy.orm import Mapped, mapped_column, relationship | ||
|
||
from lib.universal_mixin import UniversalMixin | ||
from orion.extensions import database | ||
|
||
|
||
class Area(database.Model, UniversalMixin): | ||
"""Area""" | ||
|
||
# Nombre de la tabla | ||
__tablename__ = "areas" | ||
|
||
# Clave primaria | ||
id: Mapped[int] = mapped_column(primary_key=True) | ||
|
||
# Clave foránea | ||
# centro_trabajo_id = db.Column(db.Integer, db.ForeignKey("centros_trabajos.id"), index=True, nullable=True) | ||
# centro_trabajo = db.relationship("CentroTrabajo", back_populates="areas") | ||
|
||
# Columnas | ||
nombre: Mapped[str] = mapped_column(String(128), unique=True) | ||
|
||
# Hijos | ||
# atribuciones_ct = db.relationship("AtribucionCT", back_populates="area") | ||
|
||
def __repr__(self): | ||
"""Representación""" | ||
return f"<Area {self.id}>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{% extends 'layouts/app.jinja2' %} | ||
{% import 'macros/detail.jinja2' as detail %} | ||
{% import 'macros/modals.jinja2' as modals %} | ||
{% import 'macros/topbar.jinja2' as topbar %} | ||
|
||
{% block title %}Área {{ area.id }}{% endblock %} | ||
|
||
{% block topbar_actions %} | ||
{% call topbar.page_buttons('Área ' + area.id | string ) %} | ||
{{ topbar.button_previous('Áreas', url_for('areas.list_active')) }} | ||
{% if current_user.can_edit('AREAS') %} | ||
{{ topbar.button_edit('Editar', url_for('areas.edit', area_id=area.id)) }} | ||
{% endif %} | ||
{% if current_user.can_admin('AREAS') %} | ||
{% if area.estatus == 'A' %}{{ topbar.button_delete('Eliminar', url_for('areas.delete', area_id=area.id)) }}{% endif %} | ||
{% if area.estatus == 'B' %}{{ topbar.button_recover('Recuperar', url_for('areas.recover', area_id=area.id)) }}{% endif %} | ||
{% endif %} | ||
{% endcall %} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
{% call detail.card(estatus=area.estatus) %} | ||
{{ detail.label_value('Nombre del área', area.nombre) }} | ||
{{ detail.label_value('Centro de Trabajo', 'FALTA', '#') }}<!-- TODO: Nombre del Centro de Trabajo con URL --> | ||
{% endcall %} | ||
{% endblock %} | ||
|
||
{% block custom_javascript %} | ||
{% if current_user.can_admin('AREAS') %} | ||
{% if area.estatus == 'A' %}{{ modals.custom_javascript_delete('Eliminar', '¿Eliminar el área ' + area.nombre + '?') }}{% endif %} | ||
{% if area.estatus == 'B' %}{{ modals.custom_javascript_recover('Recuperar', '¿Recuperar el área ' + area.nombre + '?') }}{% endif %} | ||
{% endif %} | ||
{{ detail.moment_js(moment) }} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{% extends 'layouts/app.jinja2' %} | ||
{% import 'macros/form.jinja2' as f with context %} | ||
{% import 'macros/topbar.jinja2' as topbar %} | ||
|
||
{% block title %}Editar Área {{ area.id }}{% endblock %} | ||
|
||
{% block topbar_actions %} | ||
{% call topbar.page_buttons('Editar ' + area.id | string) %} | ||
{{ topbar.button_cancel() }} | ||
{% endcall %} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
{% call f.card() %} | ||
{% set form_kwargs = {'area_id': area.id} %} | ||
{% call f.form_tag('areas.edit', fid='area_form', **form_kwargs) %} | ||
{% call f.form_group(form.nombre) %}{% endcall %} | ||
{% call f.form_group(form.centro_trabajo) %}{% endcall %} | ||
<div><p>FALTA centro de trabajo con Select2</p></div> | ||
{% call f.form_group(form.guardar) %}{% endcall %} | ||
{% endcall %} | ||
{% endcall %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
{% extends 'layouts/app.jinja2' %} | ||
{% import 'macros/list.jinja2' as list %} | ||
{% import 'macros/topbar.jinja2' as topbar %} | ||
|
||
{% block title %}{{ titulo }}{% endblock %} | ||
|
||
{% block topbar_actions %} | ||
{% call topbar.page_buttons(titulo) %} | ||
{% if current_user.can_admin('AREAS') %} | ||
{% if estatus == 'A' %}{{ topbar.button_list_inactive('Inactivos', url_for('areas.list_inactive')) }}{% endif %} | ||
{% if estatus == 'B' %}{{ topbar.button_list_active('Activos', url_for('areas.list_active')) }}{% endif %} | ||
{% endif %} | ||
{% if current_user.can_insert('AREAS') %} | ||
{{ topbar.button_new('Nueva Área', url_for('areas.new')) }} | ||
{% endif %} | ||
{% endcall %} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
{% call list.card() %} | ||
<!-- Filtros areas --> | ||
<div class="row"> | ||
<div class="col"> | ||
<form class="row g-1 mb-3" id="filtradorForm" onsubmit="filtrosAreas.buscar(); return false;"> | ||
<div class="col-5"> | ||
<div class="form-floating"> | ||
<input id="filtroNombre" type="text" class="form-control" aria-label="Area" style="text-transform: uppercase;"> | ||
<label for="filtroNombre">Área</label> | ||
</div> | ||
</div> | ||
<div class="col-5"> | ||
<div class="form-floating"> | ||
<input id="filtroCentroDeTrabajo" type="text" class="form-control" aria-label="CentroDeTrabajo" style="text-transform: uppercase;"> | ||
<label for="filtroCentroDeTrabajo">Centro de Trabajo</label> | ||
</div> | ||
</div> | ||
<div class="col-2 text-end"> | ||
<button title="Buscar" class="btn btn-primary btn-lg" onclick="filtrosAreas.buscar(); return false;" id="button-buscar"><span class="iconify" data-icon="mdi:magnify"></span></button> | ||
<button title="Limpiar" class="btn btn-warning btn-lg" type="reset" onclick="filtrosAreas.limpiar();" id="button-limpiar"><span class="iconify" data-icon="mdi:broom"></span></button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
<!-- DataTable areas --> | ||
<table id="areas_datatable" class="table {% if estatus == 'B'%}table-dark{% endif %} display nowrap" style="width:100%"> | ||
<thead> | ||
<tr> | ||
<th>Nombre</th> | ||
<th>Centro de Trabajo</th> | ||
</tr> | ||
</thead> | ||
</table> | ||
{% endcall %} | ||
{% endblock %} | ||
|
||
{% block custom_javascript %} | ||
<script src="/static/js/datatables-constructor.js"></script> | ||
<script src="/static/js/datatables-filtros.js"></script> | ||
<script> | ||
// DataTable areas | ||
const constructorDataTable = new ConfigDataTable( '{{ csrf_token() }}' ); | ||
let configDataTable = constructorDataTable.config(); | ||
configDataTable['ajax']['url'] = '/areas/datatable_json'; | ||
configDataTable['ajax']['data'] = {{ filtros }}; | ||
configDataTable['columns'] = [ | ||
{ data: 'detalle' }, | ||
{ data: 'centro_trabajo' } | ||
]; | ||
configDataTable['columnDefs'] = [ | ||
{ | ||
targets: 0, // detalle | ||
data: null, | ||
render: function(data, type, row, meta) { | ||
let texto = data.nombre; | ||
if (data.nombre.length > 32) { | ||
texto_corto = data.nombre.substr(0, 32) + '…'; | ||
return '<a href="' + data.url + '"><span title="' + texto + '">' + texto_corto + '</span></a>'; | ||
} | ||
return '<a href="' + data.url + '">' + texto + '</a>'; | ||
} | ||
}, | ||
{ | ||
targets: 1, // centro_trabajo | ||
data: null, | ||
render: function(data, type, row, meta) { | ||
let texto = data.nombre; | ||
if (data.nombre.length > 32) { | ||
texto_corto = data.nombre.substr(0, 32) + '…'; | ||
return '<a href="' + data.url + '"><span title="' + texto + '">' + texto_corto + '</span></a>'; | ||
} | ||
return '<a href="' + data.url + '">' + texto + '</a>'; | ||
} | ||
} | ||
]; | ||
// Filtros areas | ||
const filtrosAreas = new FiltrosDataTable('#areas_datatable', configDataTable); | ||
filtrosAreas.agregarInput('filtroNombre', 'nombre'); | ||
filtrosAreas.agregarInput('filtroCentroDeTrabajo', 'centro_trabajo'); | ||
filtrosAreas.precargar(); | ||
</script> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{% extends 'layouts/app.jinja2' %} | ||
{% import 'macros/form.jinja2' as f with context %} | ||
{% import 'macros/topbar.jinja2' as topbar %} | ||
|
||
{% block title %}Nueva Área{% endblock %} | ||
|
||
{% block topbar_actions %} | ||
{% call topbar.page_buttons('Nueva Área') %} | ||
{{ topbar.button_cancel() }} | ||
{% endcall %} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
{% call f.card() %} | ||
{% call f.form_tag('areas.new', fid='area_form') %} | ||
{% call f.form_group(form.nombre) %}{% endcall %} | ||
{% call f.form_group(form.centro_trabajo) %}{% endcall %} | ||
<div><p>FALTA centro de trabajo con Select2</p></div> | ||
{% call f.form_group(form.guardar) %}{% endcall %} | ||
{% endcall %} | ||
{% endcall %} | ||
{% endblock %} |
Oops, something went wrong.