Skip to content

Commit ebb5628

Browse files
committed
fix: tratamento de mensagens críticas
refs #928
1 parent 9305188 commit ebb5628

File tree

6 files changed

+39
-102
lines changed

6 files changed

+39
-102
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lexml/lexml-eta",
3-
"version": "1.8.0",
3+
"version": "1.8.1",
44
"description": "Webcomponent lexml-eta following open-wc recommendations",
55
"author": "lexml-eta",
66
"license": "GPL-2.0-only",

src/components/lexml-emenda.component.ts

+28-72
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { NOTA_RODAPE_CHANGE_EVENT, NOTA_RODAPE_REMOVE_EVENT, NotaRodape } from '
3939
import { unsafeHTML } from 'lit-html/directives/unsafe-html.js';
4040
import { DestinoComponent } from './destino/destino.component';
4141
import { errorInicializarEdicaoAction } from '../model/lexml/acao/errorInicializarEdicaoAction';
42+
import { isHtmlSemTexto } from '../util/string-util';
4243
import { ConfiguracaoPaginacao } from '../model/paginacao/paginacao';
4344
import { TipoMensagem } from '../model/lexml/util/mensagem';
4445

@@ -54,7 +55,7 @@ type TipoCasaLegislativa = 'SF' | 'CD' | 'CN';
5455
* Parâmetros de inicialização de edição de documento
5556
*/
5657
export class LexmlEmendaParametrosEdicao {
57-
modo = 'Emenda';
58+
modo = 'emenda';
5859

5960
// Identificação da proposição (texto) emendado.
6061
// Opcional se for informada a emenda ou o projetoNorma
@@ -228,21 +229,6 @@ export class LexmlEmendaComponent extends connect(rootStore)(LitElement) {
228229
this.getComissoes(this.casaLegislativa).then(comissoes => (this.comissoes = comissoes));
229230
}
230231

231-
private montarColegiadoApreciador(sigla: string, numero: string, ano: string): ColegiadoApreciador {
232-
if (sigla.toUpperCase() === 'MPV') {
233-
return {
234-
siglaCasaLegislativa: 'CN',
235-
tipoColegiado: 'Comissão',
236-
siglaComissao: `CMMPV ${numero}/${ano}`,
237-
};
238-
}
239-
// Inicialmente registra destino plenário do SF para demais matérias
240-
return {
241-
siglaCasaLegislativa: 'SF',
242-
tipoColegiado: 'Plenário',
243-
};
244-
}
245-
246232
private montarLocalFromColegiadoApreciador(colegiado: ColegiadoApreciador): any {
247233
return colegiado.tipoColegiado === 'Comissão' ? 'Sala da comissão' : 'Sala das sessões';
248234
}
@@ -284,15 +270,15 @@ export class LexmlEmendaComponent extends connect(rootStore)(LitElement) {
284270
emenda.comandoEmendaTextoLivre.texto = '';
285271
} else if (this.isEmendaTextoLivre()) {
286272
emenda.comandoEmendaTextoLivre.motivo = this.motivo;
287-
emenda.comandoEmendaTextoLivre.texto = this._lexmlEmendaTextoRico.texto; // visualizar ? this.removeRevisaoFormat(this._lexmlEmendaTextoRico.texto) : this._lexmlEmendaTextoRico.texto;
273+
emenda.comandoEmendaTextoLivre.texto = this._lexmlEmendaTextoRico.texto;
288274
emenda.anexos = this._lexmlEmendaTextoRico.anexos;
289275
emenda.comandoEmendaTextoLivre.textoAntesRevisao = this._lexmlEmendaTextoRico.textoAntesRevisao;
290276
} else {
291277
emenda.comandoEmendaTextoLivre.texto = '';
292278
emenda.componentes[0].dispositivos = this._lexmlEta!.getDispositivosEmenda()!;
293279
emenda.comandoEmenda = this._lexmlEta!.getComandoEmenda();
294280
}
295-
emenda.justificativa = this._lexmlJustificativa.texto; // visualizar ? this.removeRevisaoFormat(this._lexmlJustificativa.texto) : this._lexmlJustificativa.texto;
281+
emenda.justificativa = this._lexmlJustificativa.texto;
296282
emenda.notasRodape = this._lexmlJustificativa.notasRodape;
297283
emenda.autoria = this._lexmlAutoria.getAutoriaAtualizada();
298284
emenda.data = this._lexmlData.data || undefined;
@@ -320,17 +306,26 @@ export class LexmlEmendaComponent extends connect(rootStore)(LitElement) {
320306
private getPendenciasPreenchimentoEmenda(emenda: Emenda): string[] {
321307
const pendenciasPreenchimento: Array<string> = [];
322308

323-
if (this.isEmendaSubstituicaoTermo()) {
309+
if (this.isEmendaPadrao()) {
310+
if (emenda.comandoEmenda.comandos.length === 0) {
311+
pendenciasPreenchimento.push('Deve ser feita pelo menos uma modificação no texto da proposição para a geração do comando de emenda.');
312+
}
313+
} else if (this.isEmendaSubstituicaoTermo()) {
324314
if (emenda.substituicaoTermo?.termo.replace('(termo a ser substituído)', '').trim() === '' || emenda.substituicaoTermo?.novoTermo.replace('(novo termo)', '').trim() === '') {
325315
pendenciasPreenchimento.push('Substituição de termo não preenchida.');
326316
}
327-
} else {
328-
if (emenda.comandoEmenda.comandos.length === 0) {
329-
pendenciasPreenchimento.push('Deve ser feita pelo menos uma modificação no texto da proposição para a geração do comando de emenda.');
317+
} else if (this.isEmendaTextoLivre()) {
318+
if (isHtmlSemTexto(emenda.comandoEmendaTextoLivre.texto)) {
319+
pendenciasPreenchimento.push('Emenda de texto livre não preenchida.');
330320
}
331321
}
332322

333-
const messagesCritical = rootStore.getState().elementoReducer.mensagensCritical; //this.removeDuplicatasNodeList(this._lexmlEta!.querySelectorAll('.mensagem--danger'));
323+
// Verifica preenchimento da justificação
324+
if (isHtmlSemTexto(emenda.justificativa)) {
325+
pendenciasPreenchimento.push('Não foi informado um texto de justificação.');
326+
}
327+
328+
const messagesCritical = rootStore.getState().elementoReducer.mensagensCritical;
334329

335330
for (let index = 0; index < messagesCritical.length; index++) {
336331
const element = messagesCritical[index];
@@ -340,52 +335,6 @@ export class LexmlEmendaComponent extends connect(rootStore)(LitElement) {
340335
return pendenciasPreenchimento;
341336
}
342337

343-
private removeDuplicatasNodeList(lista: any): any {
344-
const novaLista: Array<any> = [];
345-
346-
for (let index = 0; index < lista.length; index++) {
347-
const element = lista[index];
348-
349-
if (element.getAttribute('tipo') === TipoMensagem.CRITICAL) {
350-
if (novaLista.length === 0) {
351-
novaLista.push(element);
352-
} else {
353-
if (!this.existeInNodeList(novaLista, element.innerText)) {
354-
novaLista.push(element);
355-
}
356-
}
357-
}
358-
}
359-
360-
return novaLista;
361-
}
362-
363-
private existeInNodeList(lista: any, valor: any): boolean {
364-
let existe = false;
365-
366-
for (let index = 0; index < lista.length; index++) {
367-
const element = lista[index];
368-
if (element.innerText === valor) {
369-
existe = true;
370-
break;
371-
}
372-
}
373-
374-
return existe;
375-
}
376-
377-
private removeRevisaoFormat(texto: string): string {
378-
let novoTexto = '';
379-
380-
if (texto !== '') {
381-
texto = texto.replace(/<ins\b[^>]*>(.*?)<\/ins>/s, '');
382-
texto = texto.replace(/<del\b[^>]*>(.*?)<\/del>/s, '');
383-
novoTexto = texto;
384-
}
385-
386-
return novoTexto;
387-
}
388-
389338
private getRevisoes(): Revisao[] {
390339
const revisoes = ordernarRevisoes([...rootStore.getState().elementoReducer.revisoes]);
391340

@@ -402,7 +351,6 @@ export class LexmlEmendaComponent extends connect(rootStore)(LitElement) {
402351
try {
403352
this._lexmlEmendaComando.emenda = [];
404353
this.modo = params.modo;
405-
('');
406354
this.projetoNorma = params.projetoNorma;
407355
this.isMateriaOrcamentaria = params.isMateriaOrcamentaria || (!!params.emenda && params.emenda.colegiadoApreciador.siglaComissao === 'CMO');
408356
this._lexmlDestino!.isMateriaOrcamentaria = this.isMateriaOrcamentaria;
@@ -909,12 +857,20 @@ export class LexmlEmendaComponent extends connect(rootStore)(LitElement) {
909857
mostrarDialogDisclaimerRevisao();
910858
}
911859

860+
private isEmendaPadrao(): boolean {
861+
return this.modo === ClassificacaoDocumento.EMENDA;
862+
}
863+
864+
private isEmendaDispositivoOndeCouber(): boolean {
865+
return this.modo === ClassificacaoDocumento.EMENDA_ARTIGO_ONDE_COUBER;
866+
}
867+
912868
private isEmendaTextoLivre(): boolean {
913-
return this.modo && this.modo === 'emendaTextoLivre';
869+
return this.modo === ClassificacaoDocumento.EMENDA_TEXTO_LIVRE;
914870
}
915871

916872
private isEmendaSubstituicaoTermo(): boolean {
917-
return this.modo === 'emendaSubstituicaoTermo';
873+
return this.modo === ClassificacaoDocumento.EMENDA_SUBSTITUICAO_TERMO;
918874
}
919875

920876
private updateView(): void {

src/model/documento/classificacao.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export enum ClassificacaoDocumento {
22
EMENDA = 'emenda',
33
EMENDA_ARTIGO_ONDE_COUBER = 'emendaArtigoOndeCouber',
4+
EMENDA_TEXTO_LIVRE = 'emendaTextoLivre',
5+
EMENDA_SUBSTITUICAO_TERMO = 'emendaSubstituicaoTermo',
46
NORMA = 'norma',
57
PROJETO = 'projeto',
68
}

src/redux/elemento/reducer/atualizaMensagemCritical.ts

+1-26
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { State } from '../../state';
22
import { TipoMensagem } from '../../../model/lexml/util/mensagem';
33
import { getDispositivoAndFilhosAsLista, isAdicionado, isModificado, isSuprimido } from '../../../model/lexml/hierarquia/hierarquiaUtil';
44
import { createElementoValidado } from '../../../model/elemento/elementoUtil';
5-
import { removeAllHtmlTags } from '../../../util/string-util';
5+
import { isHtmlSemTexto, removeAllHtmlTags } from '../../../util/string-util';
66

77
export const atualizaMensagemCritical = (state: State): State => {
88
state.mensagensCritical = processaMensagensCriticalElementos(state);
@@ -39,31 +39,6 @@ const processaMensagensCriticalElementos = (state: any): string[] | undefined =>
3939
}
4040
}
4141
}
42-
43-
const editorTextoRico = document.querySelectorAll('editor-texto-rico') as any;
44-
45-
if (editorTextoRico) {
46-
let texto = '';
47-
if (state.modo === 'emenda') {
48-
if (editorTextoRico[1]) {
49-
texto = removeAllHtmlTags(editorTextoRico[1]?.getTexto())
50-
.replace(/&nbsp;/g, '')
51-
.trim();
52-
if (texto === '') {
53-
mensagensCritical.push('Não foi informado um texto de justificação.');
54-
}
55-
}
56-
} else if (state.modo === 'textoLivre') {
57-
if (editorTextoRico[0]) {
58-
texto = removeAllHtmlTags(editorTextoRico[0]?.getTexto())
59-
.replace(/&nbsp;/g, '')
60-
.trim();
61-
if (texto === '') {
62-
mensagensCritical.push('Emenda de texto livre não preenchida.');
63-
}
64-
}
65-
}
66-
}
6742
}
6843

6944
mensagensCritical = [...new Set(mensagensCritical)];

src/util/string-util.ts

+7
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ export const removeAllHtmlTagsExcept = (texto: string, tags: string[]): string =
8787
return texto.replace(regex, '');
8888
};
8989

90+
export function isHtmlSemTexto(html: string | undefined): boolean {
91+
if(!html) {
92+
return true;
93+
}
94+
return removeAllHtmlTags(html).replace(/&nbsp;/g, '').trim() === '';
95+
}
96+
9097
export class StringBuilder {
9198
private strs = new Array<string>();
9299

test/redux/atualiza/reducer-atualiza-mensagem-critical.test.ts

-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ describe('Testando situações de mensagem Critical na articulação.', () => {
6060
expect(existInArray(state.mensagensCritical, 'Existem dispositivos sem texto informado.')).to.equal(false);
6161
});
6262

63-
// it('Deveria contemplar a mensagem de ausência da justificação.', () => {
64-
// expect(existInArray(state.mensagensCritical, 'Não foi informado um texto de justificação.')).to.equal(true);
65-
// });
6663
});
6764
});
6865
});

0 commit comments

Comments
 (0)