302 lines
14 KiB
Markdown
302 lines
14 KiB
Markdown
---
|
|
layout: default
|
|
title: Meu Perfil - MMPSearch
|
|
permalink: /perfil/
|
|
---
|
|
|
|
<main class="main-content">
|
|
<div class="publication">
|
|
<div class="container">
|
|
<br />
|
|
|
|
<div class="tabs is-centered is-boxed is-medium mb-6">
|
|
{% include sidebar.html %}
|
|
</div>
|
|
|
|
<div class="box p-0" style="overflow: hidden; border-radius: 12px; position: relative;">
|
|
<div id="cover-container" style="height: 200px; background-color: #ddd; background-size: cover; background-position: center; position: relative;">
|
|
<button class="button is-small is-white is-rounded" style="position: absolute; top: 10px; right: 10px; opacity: 0.8;" onclick="document.getElementById('cover-input').click()">
|
|
<i class="fa-solid fa-camera mr-1"></i> Alterar Capa
|
|
</button>
|
|
<input type="file" id="cover-input" class="is-hidden" accept="image/*">
|
|
</div>
|
|
|
|
<div class="p-5" style="position: relative;">
|
|
<div style="position: absolute; top: -60px; left: 30px;">
|
|
<figure class="image is-128x128">
|
|
<img id="avatar-img" class="is-rounded" src="https://bulma.io/images/placeholders/128x128.png" style="border: 4px solid white; background: white; object-fit: cover;">
|
|
</figure>
|
|
<button class="button is-small is-rounded is-light" style="position: absolute; bottom: 0; right: 0;" onclick="document.getElementById('avatar-input').click()">
|
|
<i class="fa-solid fa-pencil"></i>
|
|
</button>
|
|
<input type="file" id="avatar-input" class="is-hidden" accept="image/*">
|
|
</div>
|
|
|
|
<div class="columns" style="margin-top: 50px;">
|
|
<div class="column is-8">
|
|
<h1 class="title is-3" id="display-username">Carregando...</h1>
|
|
<p class="subtitle is-6 has-text-grey" id="display-bio">...</p>
|
|
<div class="tags mt-3" id="display-tags"></div>
|
|
</div>
|
|
<div class="column is-4 has-text-right">
|
|
<button class="button is-info is-outlined" id="btn-edit-profile">
|
|
<i class="fa-solid fa-edit mr-2"></i> Editar Perfil
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="edit-form-box" class="box is-hidden has-background-light">
|
|
<h3 class="title is-5"><i class="fa-solid fa-user-cog"></i> Editar Informações</h3>
|
|
<form id="profile-form">
|
|
<div class="field">
|
|
<label class="label">Nome de Usuário</label>
|
|
<div class="control has-icons-left">
|
|
<input class="input" type="text" name="username" id="input-username" required>
|
|
<span class="icon is-small is-left"><i class="fa-solid fa-user"></i></span>
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label class="label">Bio (Max 240)</label>
|
|
<div class="control">
|
|
<textarea class="textarea" name="bio" id="input-bio" maxlength="240" rows="2"></textarea>
|
|
</div>
|
|
<p class="help has-text-right" id="char-count">0/240</p>
|
|
</div>
|
|
<div class="field">
|
|
<label class="label">Tags</label>
|
|
<div class="control has-icons-left">
|
|
<input class="input" type="text" name="tags" id="input-tags" placeholder="Ex: Trap, Dark, Samples">
|
|
<span class="icon is-small is-left"><i class="fa-solid fa-hashtag"></i></span>
|
|
</div>
|
|
</div>
|
|
<div class="field is-grouped">
|
|
<div class="control"><button type="submit" class="button is-success">Salvar</button></div>
|
|
<div class="control"><button type="button" class="button is-light" id="btn-cancel-edit">Cancelar</button></div>
|
|
</div>
|
|
<div id="update-msg" class="notification is-hidden mt-2"></div>
|
|
</form>
|
|
</div>
|
|
|
|
<div class="box mt-5">
|
|
<div class="tabs is-boxed">
|
|
<ul>
|
|
<li class="is-active" data-tab="projects-tab"><a><span class="icon"><i class="fa-solid fa-folder"></i></span> <span>Projetos</span></a></li>
|
|
<li data-tab="samples-tab"><a><span class="icon"><i class="fa-solid fa-music"></i></span> <span>Samples</span></a></li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div id="projects-tab" class="content-tab-content">
|
|
<div class="table-container">
|
|
<table class="table is-fullwidth is-hoverable is-striped">
|
|
<thead><tr><th>Nome do Projeto</th><th>Data</th><th class="has-text-right">Ações</th></tr></thead>
|
|
<tbody id="projects-list">
|
|
</tbody>
|
|
</table>
|
|
<p id="no-projects" class="has-text-grey is-hidden has-text-centered p-4">Nenhum projeto encontrado.</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="samples-tab" class="content-tab-content is-hidden">
|
|
<p class="has-text-centered has-text-grey p-5">Em breve.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<div id="preview-modal" class="modal">
|
|
<div class="modal-background"></div>
|
|
<div class="modal-card" style="width: 90%; max-width: 900px; height: 80vh;">
|
|
<header class="modal-card-head" style="background-color: #f0f8ff; border-bottom: 1px solid #cfe8fc;">
|
|
<p class="modal-card-title" id="modal-title" style="color: #205081; font-weight: bold;">Preview</p>
|
|
<button class="delete" aria-label="close"></button>
|
|
</header>
|
|
<section class="modal-card-body p-0" style="background-color: #fff; overflow: hidden;">
|
|
<iframe id="preview-iframe" src="" style="width: 100%; height: 100%; border: none;"></iframe>
|
|
</section>
|
|
<footer class="modal-card-foot" style="justify-content: flex-end; background-color: #fff; border-top: 1px solid #cfe8fc;">
|
|
<button class="button" id="close-modal-btn">Fechar</button>
|
|
<a href="#" id="full-edit-btn" target="_blank" class="button is-info">
|
|
<span>Abrir em Nova Aba</span>
|
|
<span class="icon is-small ml-1"><i class="fa-solid fa-up-right-from-square"></i></span>
|
|
</a>
|
|
</footer>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
// --- Lógica do Perfil ---
|
|
const els = {
|
|
username: document.getElementById('display-username'),
|
|
bio: document.getElementById('display-bio'),
|
|
tags: document.getElementById('display-tags'),
|
|
projectList: document.getElementById('projects-list'),
|
|
// ... (referências do form de edição iguais ao anterior)
|
|
formBox: document.getElementById('edit-form-box'),
|
|
form: document.getElementById('profile-form'),
|
|
inpUser: document.getElementById('input-username'),
|
|
inpBio: document.getElementById('input-bio'),
|
|
inpTags: document.getElementById('input-tags'),
|
|
btnEdit: document.getElementById('btn-edit-profile'),
|
|
btnCancel: document.getElementById('btn-cancel-edit'),
|
|
msg: document.getElementById('update-msg')
|
|
};
|
|
|
|
// --- Lógica do Modal ---
|
|
const modal = document.getElementById('preview-modal');
|
|
const iframe = document.getElementById('preview-iframe');
|
|
const modalTitle = document.getElementById('modal-title');
|
|
const fullEditBtn = document.getElementById('full-edit-btn');
|
|
|
|
function openModal(url, title, fullLink) {
|
|
modalTitle.textContent = title;
|
|
iframe.src = url;
|
|
fullEditBtn.href = fullLink || url;
|
|
modal.classList.add('is-active');
|
|
document.documentElement.classList.add('is-clipped');
|
|
}
|
|
|
|
function closeModal() {
|
|
modal.classList.remove('is-active');
|
|
document.documentElement.classList.remove('is-clipped');
|
|
iframe.src = "";
|
|
}
|
|
|
|
// Fecha modal nos botões X e Background
|
|
document.querySelectorAll('.modal-background, .modal-card-head .delete, #close-modal-btn').forEach(el => {
|
|
el.addEventListener('click', closeModal);
|
|
});
|
|
|
|
// Limpa visual dentro do iframe para parecer um "modal nativo"
|
|
iframe.addEventListener('load', () => {
|
|
try {
|
|
const doc = iframe.contentDocument || iframe.contentWindow.document;
|
|
const style = doc.createElement('style');
|
|
style.textContent = `
|
|
.tabs, .navbar, .sidebar-wrapper, .main-header, footer { display: none !important; }
|
|
.publication { padding-top: 0 !important; }
|
|
body { background-color: #fff !important; overflow: auto !important; }
|
|
`;
|
|
doc.head.appendChild(style);
|
|
} catch(e) {}
|
|
});
|
|
|
|
// --- Carregar Dados ---
|
|
async function loadProfile() {
|
|
try {
|
|
const res = await fetch('/api/user/profile');
|
|
if (res.status === 401) { window.location.href = '/login/'; return; }
|
|
const data = await res.json();
|
|
|
|
// Preenche Header
|
|
els.username.textContent = data.username;
|
|
els.bio.textContent = data.bio || "Sem bio definida.";
|
|
els.tags.innerHTML = '';
|
|
if(data.tags) data.tags.split(',').forEach(t => {
|
|
if(t.trim()) els.tags.innerHTML += `<span class="tag is-info is-light mr-1">${t.trim()}</span>`;
|
|
});
|
|
|
|
// Preenche Forms
|
|
els.inpUser.value = data.username;
|
|
els.inpBio.value = data.bio || "";
|
|
els.inpTags.value = data.tags || "";
|
|
|
|
// Preenche Lista de Projetos com Lógica de Link e Modal
|
|
els.projectList.innerHTML = '';
|
|
if (data.projects && data.projects.length > 0) {
|
|
data.projects.forEach(p => {
|
|
// Prepara URLs
|
|
// Assume que o arquivo mmp gera uma pagina em /projetos/NOME_SEM_EXTENSAO/
|
|
const slug = p.filename.replace('.mmp', '').replace('.mmpz', '');
|
|
|
|
// URL da página pública do projeto
|
|
const pageUrl = `/mmpSearch/projetos/${slug}.html/`;
|
|
|
|
// URL do editor embedado
|
|
const editorUrl = `/mmpSearch/creation.html?project=${p.filename}&embed=true`;
|
|
|
|
els.projectList.innerHTML += `
|
|
<tr>
|
|
<td style="vertical-align: middle;">
|
|
<a href="${pageUrl}" class="has-text-weight-bold" style="color: #205081; text-decoration: none;">
|
|
<span class="icon is-small mr-1"><i class="fa-solid fa-music"></i></span>
|
|
${p.display_name}
|
|
</a>
|
|
</td>
|
|
<td style="vertical-align: middle;">${p.created_at}</td>
|
|
<td class="has-text-right">
|
|
<div class="buttons is-right">
|
|
<button class="button is-small is-info is-light"
|
|
onclick="openModal('${pageUrl}', 'Detalhes: ${p.display_name}', '${pageUrl}')"
|
|
title="Ver detalhes">
|
|
<i class="fa-solid fa-eye"></i>
|
|
</button>
|
|
|
|
<button class="button is-small is-warning is-light"
|
|
onclick="openModal('${editorUrl}', 'Editor: ${p.display_name}', '${editorUrl}')"
|
|
title="Editar no Navegador">
|
|
<i class="fa-solid fa-sliders"></i>
|
|
</button>
|
|
|
|
<a href="${p.download_link}" class="button is-small is-primary is-light" title="Baixar MMP">
|
|
<i class="fa-solid fa-download"></i>
|
|
</a>
|
|
|
|
<button class="button is-small is-danger is-light" onclick="deleteProject(${p.id})" title="Excluir">
|
|
<i class="fa-solid fa-trash"></i>
|
|
</button>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
`;
|
|
});
|
|
} else {
|
|
document.getElementById('no-projects').classList.remove('is-hidden');
|
|
}
|
|
} catch(e) { console.error(e); }
|
|
}
|
|
|
|
// --- Outros Handlers ---
|
|
els.btnEdit.onclick = () => els.formBox.classList.remove('is-hidden');
|
|
els.btnCancel.onclick = () => els.formBox.classList.add('is-hidden');
|
|
|
|
// Handler de update (mesmo do anterior)
|
|
els.form.onsubmit = async (e) => {
|
|
e.preventDefault();
|
|
// ... (Código de fetch /api/user/update igual ao anterior) ...
|
|
// Para economizar espaço, mantenha a lógica de POST aqui
|
|
// No sucesso, chame loadProfile() e esconda o form
|
|
|
|
// Simulação rápida para o exemplo:
|
|
const payload = { username: els.inpUser.value, bio: els.inpBio.value, tags: els.inpTags.value };
|
|
const res = await fetch('/api/user/update', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify(payload)});
|
|
if(res.ok) { els.formBox.classList.add('is-hidden'); loadProfile(); }
|
|
};
|
|
|
|
// Disponibiliza função global de delete
|
|
window.deleteProject = async (id) => {
|
|
if(!confirm("Apagar projeto permanentemente?")) return;
|
|
const res = await fetch(`/api/project/${id}`, { method: 'DELETE' });
|
|
if(res.ok) loadProfile();
|
|
};
|
|
|
|
// Disponibiliza função global para modal (usada no onclick inline)
|
|
window.openModal = openModal;
|
|
|
|
// Inicializa
|
|
loadProfile();
|
|
|
|
// Abas
|
|
document.querySelectorAll('.tabs li').forEach(tab => {
|
|
tab.addEventListener('click', () => {
|
|
document.querySelectorAll('.tabs li').forEach(t => t.classList.remove('is-active'));
|
|
tab.classList.add('is-active');
|
|
document.querySelectorAll('.content-tab-content').forEach(c => c.classList.add('is-hidden'));
|
|
document.getElementById(tab.dataset.tab).classList.remove('is-hidden');
|
|
});
|
|
});
|
|
});
|
|
</script> |