Browse Source

3030 migrar tela de parlamentar para vuejs (#3048)

* Configurando app parlamentaares para frontend

* Adaptando pagina de parlamentar para vuejs Fix #3030

* Mudando endpoints para drf

* Tirando arquivos desnecessarios

* Update sapl/api/serializers.py

Co-Authored-By: Leandro  Silva <leandroroberto.br@gmail.com>

* Update sapl/templates/parlamentares/parlamentares_list.html

Co-Authored-By: Leandro  Silva <leandroroberto.br@gmail.com>

* Update sapl/templates/parlamentares/parlamentares_list.html

Co-Authored-By: Leandro  Silva <leandroroberto.br@gmail.com>

* Corrigindo apresentação de parlamentar na pesquisa

* Atualiza arquivos VueJS
pull/3057/head
Ulysses Lara 5 years ago
committed by Edward
parent
commit
c27eef4ecb
  1. 31
      sapl/api/serializers.py
  2. 29
      sapl/api/views.py
  3. 126
      sapl/static/sapl/frontend/css/chunk-vendors.aa0d128d.css
  4. BIN
      sapl/static/sapl/frontend/css/chunk-vendors.aa0d128d.css.gz
  5. 0
      sapl/static/sapl/frontend/css/global.3b8f6afb.css
  6. 0
      sapl/static/sapl/frontend/css/global.3b8f6afb.css.gz
  7. 0
      sapl/static/sapl/frontend/css/parlamentar.0e433876.css
  8. 293
      sapl/static/sapl/frontend/js/chunk-vendors.a7ec6d73.js
  9. BIN
      sapl/static/sapl/frontend/js/chunk-vendors.a7ec6d73.js.gz
  10. 1
      sapl/static/sapl/frontend/js/compilacao.1d56171e.js
  11. BIN
      sapl/static/sapl/frontend/js/compilacao.1d56171e.js.gz
  12. 7
      sapl/static/sapl/frontend/js/global.6c17a26c.js
  13. BIN
      sapl/static/sapl/frontend/js/global.6c17a26c.js.gz
  14. 0
      sapl/static/sapl/frontend/js/painel.fcb12a07.js
  15. 0
      sapl/static/sapl/frontend/js/painel.fcb12a07.js.gz
  16. 1
      sapl/static/sapl/frontend/js/parlamentar.fc55c492.js
  17. BIN
      sapl/static/sapl/frontend/js/parlamentar.fc55c492.js.gz
  18. 112
      sapl/templates/parlamentares/parlamentares_list.html

31
sapl/api/serializers.py

@ -1,9 +1,9 @@
from django.conf import settings from django.conf import settings
from rest_framework import serializers from rest_framework import serializers
from rest_framework.relations import StringRelatedField from rest_framework.relations import StringRelatedField
from sapl.parlamentares.models import Parlamentar, Mandato, Filiacao, Legislatura
from sapl.base.models import Autor, CasaLegislativa from sapl.base.models import Autor, CasaLegislativa
from sapl.utils import filiacao_data
class IntRelatedField(StringRelatedField): class IntRelatedField(StringRelatedField):
def to_representation(self, value): def to_representation(self, value):
@ -56,3 +56,30 @@ class CasaLegislativaSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = CasaLegislativa model = CasaLegislativa
fields = '__all__' fields = '__all__'
class ParlamentarResumeSerializer(serializers.ModelSerializer):
titular = serializers.SerializerMethodField('check_titular')
partido = serializers.SerializerMethodField('check_partido')
def check_titular(self,obj):
is_titular = None
if Legislatura.objects.exists():
legislatura = self.context.get('legislatura')
if not legislatura:
legislatura = Legislatura.objects.first()
mandato = Mandato.objects.filter(legislatura=legislatura,parlamentar=obj).first()
is_titular = mandato.titular if mandato else False
return is_titular
def check_partido(self,obj):
legislatura_id = self.context.get('legislatura')
if not legislatura_id:
legislatura = Legislatura.objects.first()
else:
legislatura = Legislatura.objects.get(id=legislatura_id)
filiacao = filiacao_data(obj, legislatura.data_inicio, legislatura.data_fim)
return filiacao
class Meta:
model = Parlamentar
fields = ['id', 'nome_parlamentar', 'fotografia', 'ativo', 'partido', 'titular']

29
sapl/api/views.py

@ -21,7 +21,7 @@ from rest_framework.viewsets import ModelViewSet
from sapl.api.forms import SaplFilterSetMixin from sapl.api.forms import SaplFilterSetMixin
from sapl.api.permissions import SaplModelPermissions from sapl.api.permissions import SaplModelPermissions
from sapl.api.serializers import ChoiceSerializer from sapl.api.serializers import ChoiceSerializer, ParlamentarResumeSerializer
from sapl.base.models import Autor, AppConfig, DOC_ADM_OSTENSIVO from sapl.base.models import Autor, AppConfig, DOC_ADM_OSTENSIVO
from sapl.materia.models import Proposicao, TipoMateriaLegislativa,\ from sapl.materia.models import Proposicao, TipoMateriaLegislativa,\
MateriaLegislativa, Tramitacao MateriaLegislativa, Tramitacao
@ -31,6 +31,7 @@ from sapl.protocoloadm.models import DocumentoAdministrativo,\
DocumentoAcessorioAdministrativo, TramitacaoAdministrativo, Anexado DocumentoAcessorioAdministrativo, TramitacaoAdministrativo, Anexado
from sapl.sessao.models import SessaoPlenaria, ExpedienteSessao from sapl.sessao.models import SessaoPlenaria, ExpedienteSessao
from sapl.utils import models_with_gr_for_model, choice_anos_com_sessaoplenaria from sapl.utils import models_with_gr_for_model, choice_anos_com_sessaoplenaria
from sapl.parlamentares.models import Mandato, Parlamentar
class BusinessRulesNotImplementedMixin: class BusinessRulesNotImplementedMixin:
@ -303,6 +304,16 @@ class _AutorViewSet:
@customize(Parlamentar) @customize(Parlamentar)
class _ParlamentarViewSet: class _ParlamentarViewSet:
class ParlamentarPermission(SaplModelPermissions):
def has_permission(self, request, view):
if request.method == 'GET':
return True
else:
perm = super().has_permission(request, view)
return perm
permission_classes = (ParlamentarPermission, )
@action(detail=True) @action(detail=True)
def proposicoes(self, request, *args, **kwargs): def proposicoes(self, request, *args, **kwargs):
""" """
@ -334,6 +345,22 @@ class _ParlamentarViewSet:
serializer = self.get_serializer(page, many=True) serializer = self.get_serializer(page, many=True)
return Response(serializer.data) return Response(serializer.data)
@action(detail=True)
def parlamentares_by_legislatura(self,request,*args,**kwargs):
"""
Pega lista de parlamentares pelo id da legislatura.
"""
parlamentares = Parlamentar.objects.filter(mandato__legislatura=kwargs['pk'])
serializer_class = ParlamentarResumeSerializer(parlamentares,many=True,context={'legislatura':kwargs['pk']})
return Response(serializer_class.data)
@action(detail=False,methods=['GET'])
def search_parlamentares(self,request,*args,**kwargs):
nome = request.query_params.get('nome_parlamentar','')
parlamentares = Parlamentar.objects.filter(nome_parlamentar__icontains=nome)
serializer_class= ParlamentarResumeSerializer(parlamentares,many=True)
return Response(serializer_class.data)
@customize(Proposicao) @customize(Proposicao)
class _ProposicaoViewSet(): class _ProposicaoViewSet():

126
sapl/static/sapl/frontend/css/chunk-vendors.aa0d128d.css

File diff suppressed because one or more lines are too long

BIN
sapl/static/sapl/frontend/css/chunk-vendors.aa0d128d.css.gz

Binary file not shown.

0
sapl/static/sapl/frontend/css/global.a77827ad.css → sapl/static/sapl/frontend/css/global.3b8f6afb.css

0
sapl/static/sapl/frontend/css/global.a77827ad.css.gz → sapl/static/sapl/frontend/css/global.3b8f6afb.css.gz

0
sapl/static/sapl/frontend/css/parlamentar.0e433876.css

293
sapl/static/sapl/frontend/js/chunk-vendors.a7ec6d73.js

File diff suppressed because one or more lines are too long

BIN
sapl/static/sapl/frontend/js/chunk-vendors.a7ec6d73.js.gz

Binary file not shown.

1
sapl/static/sapl/frontend/js/compilacao.1d56171e.js

File diff suppressed because one or more lines are too long

BIN
sapl/static/sapl/frontend/js/compilacao.1d56171e.js.gz

Binary file not shown.

7
sapl/static/sapl/frontend/js/global.6c17a26c.js

File diff suppressed because one or more lines are too long

BIN
sapl/static/sapl/frontend/js/global.6c17a26c.js.gz

Binary file not shown.

0
sapl/static/sapl/frontend/js/painel.35e9809a.js → sapl/static/sapl/frontend/js/painel.fcb12a07.js

0
sapl/static/sapl/frontend/js/painel.35e9809a.js.gz → sapl/static/sapl/frontend/js/painel.fcb12a07.js.gz

1
sapl/static/sapl/frontend/js/parlamentar.fc55c492.js

@ -0,0 +1 @@
!function(e){function a(a){for(var t,o,i=a[0],u=a[1],l=a[2],p=0,f=[];p<i.length;p++)o=i[p],Object.prototype.hasOwnProperty.call(n,o)&&n[o]&&f.push(n[o][0]),n[o]=0;for(t in u)Object.prototype.hasOwnProperty.call(u,t)&&(e[t]=u[t]);for(c&&c(a);f.length;)f.shift()();return s.push.apply(s,l||[]),r()}function r(){for(var e,a=0;a<s.length;a++){for(var r=s[a],t=!0,i=1;i<r.length;i++){var u=r[i];0!==n[u]&&(t=!1)}t&&(s.splice(a--,1),e=o(o.s=r[0]))}return e}var t={},n={parlamentar:0},s=[];function o(a){if(t[a])return t[a].exports;var r=t[a]={i:a,l:!1,exports:{}};return e[a].call(r.exports,r,r.exports,o),r.l=!0,r.exports}o.m=e,o.c=t,o.d=function(e,a,r){o.o(e,a)||Object.defineProperty(e,a,{enumerable:!0,get:r})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,a){if(1&a&&(e=o(e)),8&a)return e;if(4&a&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(o.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&a&&"string"!=typeof e)for(var t in e)o.d(r,t,function(a){return e[a]}.bind(null,t));return r},o.n=function(e){var a=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(a,"a",a),a},o.o=function(e,a){return Object.prototype.hasOwnProperty.call(e,a)},o.p="/static/sapl/frontend/";var i=window.webpackJsonp=window.webpackJsonp||[],u=i.push.bind(i);i.push=a,i=i.slice();for(var l=0;l<i.length;l++)a(i[l]);var c=u;s.push([3,"chunk-vendors"]),r()}({3:function(e,a,r){e.exports=r("71e4")},"49c2":function(e,a,r){},"71e4":function(e,a,r){"use strict";r.r(a),function(e){r("cadf"),r("551c"),r("f751"),r("097d"),r("49c2");var a=r("a026"),t=r("44d4"),n=r("bc3a"),s=r.n(n);s.a.defaults.xsrfCookieName="csrftoken",s.a.defaults.xsrfHeaderName="X-CSRFToken",a.a.use(t.a),new a.a({delimiters:["[[","]]"],el:"#app2",data:function(){return{nome_pesquisa:"",is_pesquisa:!1,legislatura_selecionada:"",legislaturas:[],parlamentares:[]}},watch:{nome_pesquisa:function(e){this.debouncepesquisaParlamentar()}},created:function(){this.debouncepesquisaParlamentar=e.debounce(this.pesquisaParlamentar,500)},methods:{getParlamentares:function(e){var a=this;this.legislatura_selecionada&&s.a.get("/api/parlamentares/parlamentar/"+this.legislatura_selecionada+"/parlamentares_by_legislatura/").then((function(e){a.parlamentares=e.data})).catch((function(e){console.error("Ocorreu um erro ao obter os dados de parlamentares:"+e)}))},pesquisaParlamentar:function(e){var a=this;s.a.get("/api/parlamentares/parlamentar/search_parlamentares/",{params:{nome_parlamentar:this.nome_pesquisa}}).then((function(e){a.parlamentares=e.data})).catch((function(e){console.error("Erro ao procurar parlamentar:"+e)}))},pesquisaChange:function(e){this.is_pesquisa=!this.is_pesquisa,this.is_pesquisa?this.parlamentares=[]:this.getParlamentares()}},mounted:function(){var e=this;s.a.get("/api/parlamentares/legislatura/").then((function(a){e.legislaturas=a.data.results,e.legislatura_selecionada=a.data.results[0].id})).then((function(a){e.getParlamentares()})).catch((function(e){console.error("Ocorreu um erro ao obter os dados de legislação: "+e)}))}})}.call(this,r("2ef0"))}});

BIN
sapl/static/sapl/frontend/js/parlamentar.fc55c492.js.gz

Binary file not shown.

112
sapl/templates/parlamentares/parlamentares_list.html

@ -1,76 +1,94 @@
{% extends "crud/list.html" %} {% extends "base.html" %}
{% load i18n %} {% load i18n %}
{% load crispy_forms_tags cropping%} {% load crispy_forms_tags cropping%}
{% block actions %} {% load common_tags %}
{% load render_bundle from webpack_loader %}
{% load webpack_static from webpack_loader %}
{% block base_content %}
<div id="app2">
<div class="actions btn-group float-right btn-group-sm" role="group"> <div class="actions btn-group float-right btn-group-sm" role="group">
<a href="{% url 'sapl.parlamentares:pesquisar_parlamentar' %}" class="btn btn-outline-primary">Pesquisar Parlamentar</a> <a v-if="is_pesquisa" v-on:click="pesquisaChange" class="btn btn-primary text-white">Listar Parlamentar</a>
<a v-else v-on:click="pesquisaChange" class="btn btn-outline-primary text-info">Pesquisar Parlamentar</a>
{% if not request.user.is_anonymous %} {% if not request.user.is_anonymous %}
<a href="{% url 'sapl.parlamentares:vincular_parlamentar' %}" class="btn btn-outline-primary">Vincular Parlamentar</a> <a href="{% url 'sapl.parlamentares:vincular_parlamentar' %}" class="btn btn-outline-primary">Vincular Parlamentar</a>
{% endif %} {% endif %}
{% block more_buttons %}{% endblock more_buttons %} {% block more_buttons %}{% endblock more_buttons %}
</div> </div>
{% endblock actions %} <div class="clearfix"></div>
{% block extra_content %} <!--Pesquisa parlamentares-->
<div v-if="is_pesquisa">
<h2>Pesquisar Parlamentar</h2>
<div class="input-group input-group-lg">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-lg">Pesquisar</span>
</div>
<input v-model="nome_pesquisa" type="text" class="form-control" aria-label="Pesquisa" aria-describedby="inputGroup-sizing-sm">
</div>
</div>
<!--Lista parlamentares-->
<div v-else>
<fieldset class="form-group"> <fieldset class="form-group">
<legend>Selecione o Período</legend> <legend>Selecione o Período</legend>
<form method="GET"> <form method="GET">
<select name="pk" class="form-control" onChange="form.submit();"> <select @change="getParlamentares" class="form-control" v-model="legislatura_selecionada">
{% for l in legislaturas %} <option v-for="option in legislaturas" v-bind:value="option.id">
<option value="{{l.id}}" {% if l.id == legislatura_id %} selected {% endif %}> [[ option.__str__ ]]
{{l}}
</option> </option>
{% endfor %}
</select> </select>
</form> </form>
</fieldset> </fieldset>
<br/> <br/>
{% endblock %} </div>
{% block container_table_list %}
{% if not rows %}
<p>{{ NO_ENTRIES_MSG }}</p>
{% else %}
<div class="container-table lista-parlamentares"> <div class="container-table lista-parlamentares">
<div class="result-count">{% blocktrans with verbose_name_plural=view.verbose_name_plural %}Total de {{ verbose_name_plural }}: <strong>{{count}}</strong>{% endblocktrans %}</div> <div class="result-count">Total de Parlamentares: <strong>[[parlamentares.length]]</strong></div>
<table class="table table-striped table-hover table-link-ordering"> <table class="table table-striped table-hover table-link-ordering">
<thead> <thead>
<tr> <tr>
{% for name in headers %} <th colspan=2 >Parlamentar</th>
{% if forloop.first %} <th>Parido</th>
<th colspan=2> <th>Ativo?</th>
{% else %} <th v-if="!is_pesquisa" >Titlar?</th>
<th>
{% endif %}
{{ name }}
</th>
{% endfor %}
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for value_list in rows %} <tr v-for="parlamentar in parlamentares">
<tr> <th>
{% for value, href, obj in value_list %} <img class="img-fluid img-thumbnail" v-bind:src="parlamentar.fotografia" @error="(() => parlamentar.fotografia = '')"/>
{% if forloop.first %} </th>
<td> <th>
{% if obj.fotografia %} <a v-bind:href="'/parlamentar/'+parlamentar.id">[[ parlamentar.nome_parlamentar]]</a>
<div id="w-100"> </th>
<img class="img-fluid img-thumbnail" src="{% cropped_thumbnail obj "cropping"%}"> <th>
</div> [[ parlamentar.partido ]]
{% endif %} </th>
</td> <th>
{% endif %} <p v-if="[[ parlamentar.ativo ]]">Sim</p>
<td> <p v-else>Não</p>
{% if href %} </th>
<a href="{{ href }}">{{ value|safe|default:"" }}</a> <th v-if="!is_pesquisa">
{% else %} <p v-if='[[ parlamentar.titular]]'>Sim</p>
{{ value|safe|default:"" }} <p v-else>Não</p>
{% endif %} </th>
</td>
{% endfor %}
</tr> </tr>
{% endfor %}
</tbody> </tbody>
</table> </table>
</div> </div>
{% endif %}
{% endblock base_content %}
{% block webpack_loader_css %}
{{ block.super }}
{% render_bundle 'parlamentar' 'css' %}
{% endblock %}
{% block webpack_loader_js %}
{% render_chunk_vendors 'js' %}
{% render_bundle 'global' 'js' %}
{% render_bundle 'parlamentar' 'js' %}
{% endblock %} {% endblock %}

Loading…
Cancel
Save