MOON
Server: Apache
System: Linux vps.erhabenn.com.br 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User: sonne (1011)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: //matrixSwot/backend/services/email/generateLayout.js
//No params
const { actionsTitle } = require('./actionsTitle');
//Receive link
const { buttonMatrix } = require('./buttonMatrix');
//image = image of user 
//Receive object into {name, description, link, image}
const { collaboratorComment } = require('./collaboratorComment');
//Ro params
const { footer } = require('./footer');
//Receive array of objects {status, description, link, imageIcon}
const { goal } = require('./goal');
//Receive object {quantityActions, quantityGoals}
const { goalsAndActions } = require('./goalsAndActions');
//No params
const { goalsTitle } = require('./goalsTitle');
//No params
const { header } = require('./header');
//Receive object {name, image}
const { imageLeft } = require('./imageLeft');
//image = image of user
//Receive array of objects [{name, description, image, description, link}]
const { imageLeftDescription } = require('./imageLeftDescription');
//Receiva variable of name plan 
const { lastCommentHeader } = require('./lastCommentHeader');
//No params
const { line } = require('./lineEmail');
//Receive title
const { headerBlue } = require('./headerBlue');
//image = image of icon comment
//deskIcon = ex: 'Problema sinalizado'
//Receive object {image, type, descIcon, description, link}
const { sinalizeComment } = require('./sinalizeComment');
//Receive object {description, link}
const { singleComment } = require('./singleComment');
//Receive object {title, description, link}
const { subtitleEmail } = require('./subtitleEmail');
//Receive object {title, description, link}
const { titleEmail } = require('./titleEmail');
const { atrasadas } = require('./atrasadas');
const { headerLates } = require('./headerLates');
const { headerLatesGoals } = require('./headerLatesGoals');
const { colItems } = require('./colItems');

const generateLayout = (data, options) => {
    let image = 'https://blobmatrix.blob.core.windows.net/thumbnails/problema.png';
    let link = 'https://app.matrixswot.ai/TimeAndMotion';
    let layout = header();
    layout += titleEmail({
        title: `Olá, ${data.name}!`,
        description: 'Estas são suas metas e ações com prazo previsto para hoje',
        link
    });
    if (data.plans.length > 0) {
        layout += goalsAndActions({ quantityActions: data.plans[0].action.length, quantityGoals: data.plans[0].goal.length })
        layout += moduleComments(data, image, link)
    }

    if (data.plansLate.length > 0) {
        layout += moduleLates(data.plansLate)
        layout += line()
    }

    layout += footer()
    return layout
}


const moduleComments = (data, image, link, layout = '') => {

    for (let x = 0; x < data.plans.length; x++) {
        for (let y = 0; y < data.plans[x].goal.length; y++) {
            if (data.plans[x].goal[y]) {
                for (let z = 0; z < data.plans[x].goal[y].warning.length; z++) {
                    if (data.plans[x].goal[y].warning[z]) {
                        layout += sinalizeComment({
                            image,
                            planName: data.plans[x].name.toUpperCase(),
                            goalName: data.plans[x].goal[y].name.toUpperCase(),
                            description: data.plans[x].goal[y].warning[z].text
                        })
                    }
                }
            }
        }

        for (let y = 0; y < data.plans[x].action.length; y++) {
            if (data.plans[x].action[y]) {
                for (let z = 0; z < data.plans[x].action[y].warning.length; z++) {
                    if (data.plans[x].action[y].warning[z]) {
                        layout += sinalizeComment({
                            image,
                            planName: data.plans[x].name.toUpperCase(),
                            goalName: data.plans[x].action[y].name.toUpperCase(),
                            description: data.plans[x].action[y].warning[z].text
                        })
                    }
                }
            }
        }
    }
    if (layout) {
        layout += buttonMatrix(link)
        layout += line()
    }
    return layout
}

const moduleLates = (data, layout = '') => {
    let goals = [];
    let actions = [];
    if (data.length > 0) {
        layout += headerLatesGoals()
        for (let x = 0; x < data.length; x++) {
            for (let y = 0; y < data[x].goal.length; y++) {
                goals.push(data[x].goal[y]);
            }
        }
    }

    for (let x = 0; x < goals.length; x += 2) {
        if (goals[x + 1]) {
            layout += colItems(goals[x], goals[x + 1]);
        }
        else {
            layout += colItems(goals[x], { name: '', start_date: '', end_date: '' });
        }
    }

    if (data.length > 0) {
        layout += headerLates()
        for (let x = 0; x < data.length; x++) {
            for (let y = 0; y < data[x].action.length; y++) {
                actions.push(data[x].action[y]);
            }
        }
    }

    for (let x = 0; x < actions.length; x += 2) {
        if (actions[x + 1]) {
            layout += colItems(actions[x], actions[x + 1]);
        }
        else {
            layout += colItems(actions[x], { name: '', start_date: '', end_date: '' });
        }
    }

    return layout
}

module.exports = { generateLayout }