Created
October 24, 2019 02:55
-
-
Save lucis/643d82b26b431cf8f9b0faeee80b36c6 to your computer and use it in GitHub Desktop.
Importa notas de um array para a página de notas do Controle Acadêmico
This file contains hidden or 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
const SEM_NOTA = 'SEM_NOTA' | |
const SUBS = 'SUBS' | |
const importaNotas = (table, notas) => { | |
const erros = [] | |
const it = a => a.innerText | |
const grouped = notas.reduce((acc, cur) => ({...acc, [cur.matricula || cur.nome]: cur}),{}); | |
[...table.querySelectorAll('tr')].forEach(tr => { | |
const matricula = it(tr.children[1]) | |
const nome = it(tr.children[2]) | |
const entry = grouped[matricula] || grouped[nome] | |
if (!entry) { | |
return erros.push({type: SEM_NOTA, aluno: nome}) | |
} | |
const { nota1 = '', nota2 = '', nota3 = '', final = ''} = entry | |
const getIn = a => a.querySelector('input') | |
const getFinal = tr => [...tr.querySelectorAll('input')].filter(({id}) => id && id.includes('f_'))[0] | |
const campos = [getIn(tr.children[3]), getIn(tr.children[4]), getIn(tr.children[5]), getFinal(tr)] | |
const values = [nota1, nota2, nota3, final].map(nota => nota ? nota.replace('.', ',') : '') | |
campos.forEach((input, i) => { | |
if (input.value){ | |
erros.push({ type: SUBS, aluno: nome}) | |
} | |
input.value = values[i] | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment