From ebb56285a9e8244ff0863f59e12826f31036d23a Mon Sep 17 00:00:00 2001 From: Marcos Fragomeni Date: Thu, 10 Oct 2024 20:32:50 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20tratamento=20de=20mensagens=20cr=C3=ADti?= =?UTF-8?q?cas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs #928 --- package.json | 2 +- src/components/lexml-emenda.component.ts | 100 +++++------------- src/model/documento/classificacao.ts | 2 + .../reducer/atualizaMensagemCritical.ts | 27 +---- src/util/string-util.ts | 7 ++ ...reducer-atualiza-mensagem-critical.test.ts | 3 - 6 files changed, 39 insertions(+), 102 deletions(-) diff --git a/package.json b/package.json index 741fea32..05b4095d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lexml/lexml-eta", - "version": "1.8.0", + "version": "1.8.1", "description": "Webcomponent lexml-eta following open-wc recommendations", "author": "lexml-eta", "license": "GPL-2.0-only", diff --git a/src/components/lexml-emenda.component.ts b/src/components/lexml-emenda.component.ts index c147a956..450b966b 100644 --- a/src/components/lexml-emenda.component.ts +++ b/src/components/lexml-emenda.component.ts @@ -39,6 +39,7 @@ import { NOTA_RODAPE_CHANGE_EVENT, NOTA_RODAPE_REMOVE_EVENT, NotaRodape } from ' import { unsafeHTML } from 'lit-html/directives/unsafe-html.js'; import { DestinoComponent } from './destino/destino.component'; import { errorInicializarEdicaoAction } from '../model/lexml/acao/errorInicializarEdicaoAction'; +import { isHtmlSemTexto } from '../util/string-util'; import { ConfiguracaoPaginacao } from '../model/paginacao/paginacao'; import { TipoMensagem } from '../model/lexml/util/mensagem'; @@ -54,7 +55,7 @@ type TipoCasaLegislativa = 'SF' | 'CD' | 'CN'; * Parâmetros de inicialização de edição de documento */ export class LexmlEmendaParametrosEdicao { - modo = 'Emenda'; + modo = 'emenda'; // Identificação da proposição (texto) emendado. // Opcional se for informada a emenda ou o projetoNorma @@ -228,21 +229,6 @@ export class LexmlEmendaComponent extends connect(rootStore)(LitElement) { this.getComissoes(this.casaLegislativa).then(comissoes => (this.comissoes = comissoes)); } - private montarColegiadoApreciador(sigla: string, numero: string, ano: string): ColegiadoApreciador { - if (sigla.toUpperCase() === 'MPV') { - return { - siglaCasaLegislativa: 'CN', - tipoColegiado: 'Comissão', - siglaComissao: `CMMPV ${numero}/${ano}`, - }; - } - // Inicialmente registra destino plenário do SF para demais matérias - return { - siglaCasaLegislativa: 'SF', - tipoColegiado: 'Plenário', - }; - } - private montarLocalFromColegiadoApreciador(colegiado: ColegiadoApreciador): any { return colegiado.tipoColegiado === 'Comissão' ? 'Sala da comissão' : 'Sala das sessões'; } @@ -284,7 +270,7 @@ export class LexmlEmendaComponent extends connect(rootStore)(LitElement) { emenda.comandoEmendaTextoLivre.texto = ''; } else if (this.isEmendaTextoLivre()) { emenda.comandoEmendaTextoLivre.motivo = this.motivo; - emenda.comandoEmendaTextoLivre.texto = this._lexmlEmendaTextoRico.texto; // visualizar ? this.removeRevisaoFormat(this._lexmlEmendaTextoRico.texto) : this._lexmlEmendaTextoRico.texto; + emenda.comandoEmendaTextoLivre.texto = this._lexmlEmendaTextoRico.texto; emenda.anexos = this._lexmlEmendaTextoRico.anexos; emenda.comandoEmendaTextoLivre.textoAntesRevisao = this._lexmlEmendaTextoRico.textoAntesRevisao; } else { @@ -292,7 +278,7 @@ export class LexmlEmendaComponent extends connect(rootStore)(LitElement) { emenda.componentes[0].dispositivos = this._lexmlEta!.getDispositivosEmenda()!; emenda.comandoEmenda = this._lexmlEta!.getComandoEmenda(); } - emenda.justificativa = this._lexmlJustificativa.texto; // visualizar ? this.removeRevisaoFormat(this._lexmlJustificativa.texto) : this._lexmlJustificativa.texto; + emenda.justificativa = this._lexmlJustificativa.texto; emenda.notasRodape = this._lexmlJustificativa.notasRodape; emenda.autoria = this._lexmlAutoria.getAutoriaAtualizada(); emenda.data = this._lexmlData.data || undefined; @@ -320,17 +306,26 @@ export class LexmlEmendaComponent extends connect(rootStore)(LitElement) { private getPendenciasPreenchimentoEmenda(emenda: Emenda): string[] { const pendenciasPreenchimento: Array = []; - if (this.isEmendaSubstituicaoTermo()) { + if (this.isEmendaPadrao()) { + if (emenda.comandoEmenda.comandos.length === 0) { + pendenciasPreenchimento.push('Deve ser feita pelo menos uma modificação no texto da proposição para a geração do comando de emenda.'); + } + } else if (this.isEmendaSubstituicaoTermo()) { if (emenda.substituicaoTermo?.termo.replace('(termo a ser substituído)', '').trim() === '' || emenda.substituicaoTermo?.novoTermo.replace('(novo termo)', '').trim() === '') { pendenciasPreenchimento.push('Substituição de termo não preenchida.'); } - } else { - if (emenda.comandoEmenda.comandos.length === 0) { - pendenciasPreenchimento.push('Deve ser feita pelo menos uma modificação no texto da proposição para a geração do comando de emenda.'); + } else if (this.isEmendaTextoLivre()) { + if (isHtmlSemTexto(emenda.comandoEmendaTextoLivre.texto)) { + pendenciasPreenchimento.push('Emenda de texto livre não preenchida.'); } } - const messagesCritical = rootStore.getState().elementoReducer.mensagensCritical; //this.removeDuplicatasNodeList(this._lexmlEta!.querySelectorAll('.mensagem--danger')); + // Verifica preenchimento da justificação + if (isHtmlSemTexto(emenda.justificativa)) { + pendenciasPreenchimento.push('Não foi informado um texto de justificação.'); + } + + const messagesCritical = rootStore.getState().elementoReducer.mensagensCritical; for (let index = 0; index < messagesCritical.length; index++) { const element = messagesCritical[index]; @@ -340,52 +335,6 @@ export class LexmlEmendaComponent extends connect(rootStore)(LitElement) { return pendenciasPreenchimento; } - private removeDuplicatasNodeList(lista: any): any { - const novaLista: Array = []; - - for (let index = 0; index < lista.length; index++) { - const element = lista[index]; - - if (element.getAttribute('tipo') === TipoMensagem.CRITICAL) { - if (novaLista.length === 0) { - novaLista.push(element); - } else { - if (!this.existeInNodeList(novaLista, element.innerText)) { - novaLista.push(element); - } - } - } - } - - return novaLista; - } - - private existeInNodeList(lista: any, valor: any): boolean { - let existe = false; - - for (let index = 0; index < lista.length; index++) { - const element = lista[index]; - if (element.innerText === valor) { - existe = true; - break; - } - } - - return existe; - } - - private removeRevisaoFormat(texto: string): string { - let novoTexto = ''; - - if (texto !== '') { - texto = texto.replace(/]*>(.*?)<\/ins>/s, ''); - texto = texto.replace(/]*>(.*?)<\/del>/s, ''); - novoTexto = texto; - } - - return novoTexto; - } - private getRevisoes(): Revisao[] { const revisoes = ordernarRevisoes([...rootStore.getState().elementoReducer.revisoes]); @@ -402,7 +351,6 @@ export class LexmlEmendaComponent extends connect(rootStore)(LitElement) { try { this._lexmlEmendaComando.emenda = []; this.modo = params.modo; - (''); this.projetoNorma = params.projetoNorma; this.isMateriaOrcamentaria = params.isMateriaOrcamentaria || (!!params.emenda && params.emenda.colegiadoApreciador.siglaComissao === 'CMO'); this._lexmlDestino!.isMateriaOrcamentaria = this.isMateriaOrcamentaria; @@ -909,12 +857,20 @@ export class LexmlEmendaComponent extends connect(rootStore)(LitElement) { mostrarDialogDisclaimerRevisao(); } + private isEmendaPadrao(): boolean { + return this.modo === ClassificacaoDocumento.EMENDA; + } + + private isEmendaDispositivoOndeCouber(): boolean { + return this.modo === ClassificacaoDocumento.EMENDA_ARTIGO_ONDE_COUBER; + } + private isEmendaTextoLivre(): boolean { - return this.modo && this.modo === 'emendaTextoLivre'; + return this.modo === ClassificacaoDocumento.EMENDA_TEXTO_LIVRE; } private isEmendaSubstituicaoTermo(): boolean { - return this.modo === 'emendaSubstituicaoTermo'; + return this.modo === ClassificacaoDocumento.EMENDA_SUBSTITUICAO_TERMO; } private updateView(): void { diff --git a/src/model/documento/classificacao.ts b/src/model/documento/classificacao.ts index 4e25444f..3ec5dc56 100644 --- a/src/model/documento/classificacao.ts +++ b/src/model/documento/classificacao.ts @@ -1,6 +1,8 @@ export enum ClassificacaoDocumento { EMENDA = 'emenda', EMENDA_ARTIGO_ONDE_COUBER = 'emendaArtigoOndeCouber', + EMENDA_TEXTO_LIVRE = 'emendaTextoLivre', + EMENDA_SUBSTITUICAO_TERMO = 'emendaSubstituicaoTermo', NORMA = 'norma', PROJETO = 'projeto', } diff --git a/src/redux/elemento/reducer/atualizaMensagemCritical.ts b/src/redux/elemento/reducer/atualizaMensagemCritical.ts index 67c7c6b0..59429cf6 100644 --- a/src/redux/elemento/reducer/atualizaMensagemCritical.ts +++ b/src/redux/elemento/reducer/atualizaMensagemCritical.ts @@ -2,7 +2,7 @@ import { State } from '../../state'; import { TipoMensagem } from '../../../model/lexml/util/mensagem'; import { getDispositivoAndFilhosAsLista, isAdicionado, isModificado, isSuprimido } from '../../../model/lexml/hierarquia/hierarquiaUtil'; import { createElementoValidado } from '../../../model/elemento/elementoUtil'; -import { removeAllHtmlTags } from '../../../util/string-util'; +import { isHtmlSemTexto, removeAllHtmlTags } from '../../../util/string-util'; export const atualizaMensagemCritical = (state: State): State => { state.mensagensCritical = processaMensagensCriticalElementos(state); @@ -39,31 +39,6 @@ const processaMensagensCriticalElementos = (state: any): string[] | undefined => } } } - - const editorTextoRico = document.querySelectorAll('editor-texto-rico') as any; - - if (editorTextoRico) { - let texto = ''; - if (state.modo === 'emenda') { - if (editorTextoRico[1]) { - texto = removeAllHtmlTags(editorTextoRico[1]?.getTexto()) - .replace(/ /g, '') - .trim(); - if (texto === '') { - mensagensCritical.push('Não foi informado um texto de justificação.'); - } - } - } else if (state.modo === 'textoLivre') { - if (editorTextoRico[0]) { - texto = removeAllHtmlTags(editorTextoRico[0]?.getTexto()) - .replace(/ /g, '') - .trim(); - if (texto === '') { - mensagensCritical.push('Emenda de texto livre não preenchida.'); - } - } - } - } } mensagensCritical = [...new Set(mensagensCritical)]; diff --git a/src/util/string-util.ts b/src/util/string-util.ts index 352fb14a..434f8a0f 100644 --- a/src/util/string-util.ts +++ b/src/util/string-util.ts @@ -87,6 +87,13 @@ export const removeAllHtmlTagsExcept = (texto: string, tags: string[]): string = return texto.replace(regex, ''); }; +export function isHtmlSemTexto(html: string | undefined): boolean { + if(!html) { + return true; + } + return removeAllHtmlTags(html).replace(/ /g, '').trim() === ''; +} + export class StringBuilder { private strs = new Array(); diff --git a/test/redux/atualiza/reducer-atualiza-mensagem-critical.test.ts b/test/redux/atualiza/reducer-atualiza-mensagem-critical.test.ts index 507b34cc..9d43b4d0 100644 --- a/test/redux/atualiza/reducer-atualiza-mensagem-critical.test.ts +++ b/test/redux/atualiza/reducer-atualiza-mensagem-critical.test.ts @@ -60,9 +60,6 @@ describe('Testando situações de mensagem Critical na articulação.', () => { expect(existInArray(state.mensagensCritical, 'Existem dispositivos sem texto informado.')).to.equal(false); }); - // it('Deveria contemplar a mensagem de ausência da justificação.', () => { - // expect(existInArray(state.mensagensCritical, 'Não foi informado um texto de justificação.')).to.equal(true); - // }); }); }); });