Commit e537cb58 authored by Kannan V M's avatar Kannan V M
Browse files

Add user permit logic

parent 79a85b18
......@@ -78,6 +78,7 @@ userNamespace.on('connection', (socket) => {
leavesData[roomId][socketId] = { userName }; // user
socket.emit('leaves data', leavesData[roomId]);
modNamespace.to(roomId).emit('leaves data', leavesData[roomId]);
socket.on('leaf text', (leafText) => {
const leafData = {};
......@@ -103,6 +104,10 @@ modNamespace.on('connection', (socket) => {
socket.join(roomId);
modNamespace.to(roomId).emit('leaves data', leavesData[roomId]);
socket.on('allow user', (socketId) => {
console.log(socketId);
userNamespace.to(socketId).emit('enter knowledge');
});
socket.on('leaf delete', (socketId) => {
deleteLeaf(socketId, roomId);
});
......
......@@ -325,12 +325,12 @@
<path d="m 398.322,407.792 13.026,1.491 14.178,-2.073 14.595,2.975 -13.631,-8.303 -9.18,3.412 z" style="fill:#3c3c3c" id="path401" />
</g>
</svg>
<form id="knowledge-form">
<input id="knowledge-input" type="text" maxlength="50">
<input id="knowledge-submit" type="submit" value="Submit" onclick="event.preventDefault(); addKnowledgeItem();">
<input id="knowledge-edit" type="submit" value="Edit" onclick="event.preventDefault(); editKnowledgeItem();">
<div id="input-fields">
<form id="user-form">
<input id="user-name" placeholder="Enter your name" type="text" maxlength="50">
<input id="user-submit" type="submit" value="Submit" onclick="event.preventDefault(); registerUser();">
</form>
</div>
<div id="knowledge"></div>
<div id="close-button">
......
......@@ -10,7 +10,6 @@ const tBody = document.querySelector('tbody');
mod.on('leaves data', (leavesData) => {
console.log(leavesData);
var text = {};
tBody.innerHTML = '';
for (socketId in leavesData) {
const rowData =
......@@ -19,6 +18,7 @@ mod.on('leaves data', (leavesData) => {
<td>${leavesData[socketId]["userName"]}</td>
<td><input type="text" id=${socketId} value=${leavesData[socketId]["leafText"]}></td>
<td>
<input type="button" onclick="allowUser(this.name); this.remove()" name=${socketId} value="allow user">
<input type="button" onclick="contentUpdate(this.name)" name=${socketId} value="update text">
<input type="button" onclick="contentRemove(this.name)" name=${socketId} value="delete text">
<input type="button" onclick="userRemove(this.name)" name=${socketId} value="delete user">
......@@ -29,6 +29,10 @@ mod.on('leaves data', (leavesData) => {
};
});
function allowUser(socketId) {
mod.emit('allow user', socketId);
}
function contentRemove(socketId){
mod.emit('leaf delete', socketId);
};
......
......@@ -104,22 +104,22 @@ input[type="submit"], button {
cursor: pointer;
}
#knowledge-form {
#knowledge-form, #user-form {
text-align: center;
}
#knowledge-input, #knowledge-submit, #knowledge-edit {
#knowledge-input, #user-name, #knowledge-submit, #user-submit, #knowledge-edit {
margin: 10px auto;
}
#knowledge-input {
#knowledge-input, #user-name {
border: none;
border-radius: 5px;
width: 420px;
padding: 10px;
}
#knowledge-submit {
#knowledge-submit, #user-submit {
background: #008CBA;
font-size: 14px;
color: white;
......@@ -167,11 +167,11 @@ input[type="submit"], button {
}
@media only screen and (max-width: 480px) {
#knowledge-form {
#knowledge-form, #user-form {
margin-top: -15vh;
}
#knowledge-input {
#knowledge-input, #user-name {
width: 280px;
}
......@@ -180,3 +180,6 @@ input[type="submit"], button {
}
}
.user-label {
}
/* @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=
* agpl-3.0.txt AGPL-3.0-or-later */
const ROOM = window.location.href.split('/')[3];
const socket = io('/user', {
query: {
roomId: ROOM,
}
});
const roomId = window.location.href.split('/')[3];
var socket;
function registerUser() {
userName = document.getElementById('user-name').value;
socket = io('/user', {
query: {
userName,
roomId,
}
});
socket.on('connection', document.getElementById('input-fields').innerHTML = '');
console.log(socket);
socket.on('leaves data', (leavesData) => {
let i = 0;
if (Object.keys(leavesData).length > 0) {
for(socketId in leavesData) {
leafData = leavesData[socketId];
if (leafData.leafText) {
growLeaves(i, socketId, leafData);
i++;
}
}
}
});
socket.on('leaf delete', (leafId) => {
const activeLeaf = document.getElementById(leafId);
activeLeaf.classList.add('leaf-inactive');
activeLeaf.classList.remove('leaf-active');
activeLeaf.removeEventListener('click', popupLeaf, false);
const knowledgeId = activeLeaf.id.replace('path', 'knowledge');
const leafDataInput = document.getElementById(knowledgeId);
leafDataInput.outerHTML = "";
});
socket.on('enter knowledge', () => {
const inputField = document.getElementById('input-fields');
const inputForm =
`<form id="knowledge-form">
<input id="knowledge-input" placeholder="Knowledge to preserve" type="text" maxlength="50">
<input id="knowledge-submit" type="submit" value="Submit" onclick="event.preventDefault(); addKnowledgeItem();">
<input id="knowledge-edit" type="submit" value="Edit" onclick="event.preventDefault(); editKnowledgeItem();">
</form>`;
inputField.innerHTML = inputForm;
});
socket.on('delete text', (leafId) => {
activeLeaf = document.getElementById(leafId);
activeLeaf.classList.remove("leaf-active");
activeLeaf.classList.add("leaf-inactive");
activeLeaf.removeEventListener("click", popupLeaf, false);
let knowledgeId = leafId.replace("path", "knowledge");
document.getElementById(knowledgeId).innerHTML = "";
});
}
function popupLeaf() {
let knowledgeId = this.id.replace('path', 'knowledge');
......@@ -51,29 +100,6 @@ function growLeaves(i, socketId, leafData) {
setTimeout(() => growLeaf(socketId, leafData), 300 * i);
}
socket.on('leaves data', (leavesData) => {
let i = 0;
if (Object.keys(leavesData).length > 0) {
for(socketId in leavesData) {
leafData = leavesData[socketId];
if (leafData.leafText) {
growLeaves(i, socketId, leafData);
i++;
}
}
}
});
socket.on('leaf delete', (leafId) => {
const activeLeaf = document.getElementById(leafId);
activeLeaf.classList.add('leaf-inactive');
activeLeaf.classList.remove('leaf-active');
activeLeaf.removeEventListener('click', popupLeaf, false);
const knowledgeId = activeLeaf.id.replace('path', 'knowledge');
const leafDataInput = document.getElementById(knowledgeId);
leafDataInput.outerHTML = "";
});
function addKnowledgeItem() {
leafText = document.getElementById('knowledge-input').value;
socket.emit("leaf text", leafText);
......@@ -109,13 +135,4 @@ window.onload = function() {
}
}
socket.on('delete text', (leafId) => {
activeLeaf = document.getElementById(leafId);
activeLeaf.classList.remove("leaf-active");
activeLeaf.classList.add("leaf-inactive");
activeLeaf.removeEventListener("click", popupLeaf, false);
let knowledgeId = leafId.replace("path", "knowledge");
document.getElementById(knowledgeId).innerHTML = "";
});
// @license-end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment