-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
executable file
·377 lines (300 loc) · 10.6 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
const connectEvent = document.getElementById('connectId');
const cloudsEvent = document.getElementById('CloudsId');
const filesEvent = document.getElementById('FilesId');
const workspaceEvent = document.getElementById('WorkspaceId');
const logoutEvent = document.getElementById('logout');
const changeInP = document.getElementById('changeIt');
const addUsingJs = document.getElementById('addUsingJs');
const cardInsertion = document.getElementById('cardInsertion');
const settingEvent = document.getElementById('setting');
const settingInsideItem = document.getElementById('settingMenu');
const notificationEvent = document.getElementById('notification');
const notificationInsideItem = document.getElementById('notificationMenu');
const profileEvent = document.getElementById('profile');
const profileInsideItem = document.getElementById('profileMenu');
var time;
var name;
var size;
var socket = null ;
function addUsingJsHtmlSnippetConnect(change,placeholder,creds){
if (socket){
socket.close();
socket = null;
}
// create a container element to hold the button and input
const container = document.createElement('p');
container.id = 'main-connect';
//create an input element
const inputElement = document.createElement('input');
inputElement.type = 'text';
inputElement.id = 'UserInput';
inputElement.placeholder = placeholder;
//create a button element
const buttonElement = document.createElement('button');
buttonElement.type = 'button';
buttonElement.id = 'connect';
//buttonElement.textContent = 'click me';
container.appendChild(inputElement);
container.appendChild(buttonElement);
const existingChild = document.getElementById('connect');
//append the container to the body or a specific element
if (existingChild){
if( existingChild.placeholder == change){
return
}else{
let topConnectPtag = document.getElementById('main-connect');
addUsingJs.removeChild(topConnectPtag);
}
}
addUsingJs.appendChild(container);
buttonElement.addEventListener('click', ()=>{
let topUserInput = document.getElementById('UserInput');
creds[placeholder] = topUserInput.value;
topUserInput.value = "";
if (placeholder == 'password'){
document.getElementById('connect').disabled = true;
fetch('http://localhost:3000/connect',{
method:'POST',
headers:{
'Content-Type': 'application/json'
},
body: JSON.stringify(creds)
})
.then(response => response.json())
.then(async data => {
let responseFromFile = await data;
console.log('data',data);
if (data['data'] == 0){
//code here for showing error usin button issue
}
addUsingJsHtmlSnippetConnect('connect','ip',creds);
})
.catch((error) =>{
console.error(error);
})
}else{
addUsingJsHtmlSnippetConnect('connect','password',creds);
}
});
}
function addUsingJsHtmlSnippet(change,placeholder){
// create a container element to hold the button and input
const container = document.createElement('p');
container.id = 'main-connect';
//create an input element
const inputElement = document.createElement('input');
inputElement.type = 'text';
inputElement.id = 'UserInput';
inputElement.placeholder = placeholder;
//create a button element
const buttonElement = document.createElement('button');
buttonElement.type = 'button';
buttonElement.id = 'connect';
//buttonElement.textContent = 'click me';
container.appendChild(inputElement);
container.appendChild(buttonElement);
const existingChild = document.getElementById('connect');
//append the container to the body or a specific element
if (existingChild){
if( existingChild.placeholder == change){
return
}else{
let topConnectPtag = document.getElementById('main-connect');
addUsingJs.removeChild(topConnectPtag);
}
}
addUsingJs.appendChild(container);
}
function cardInsertionHtmlSnippet(name,time,type,sz){
const cardContainer = document.createElement('div');
cardContainer.setAttribute('class', 'cardContainer');
const mainMid = document.createElement('div');
mainMid.setAttribute('class','main-mid');
const iconFile = document.createElement('img');
iconFile.setAttribute('class', 'iconFileType');
iconFile.src = `./iconimg/${type}.png`;
const dottedThree = document.createElement('button');
dottedThree.setAttribute('class', 'dottedThree');
dottedThree.textContent = ':';
const property = document.createElement('div');
property.setAttribute('class', 'property');
const folderName = document.createElement('p');
folderName.setAttribute('class', 'FolderName');
folderName.textContent = `${name}`;
const propertyTime = document.createElement('p');
propertyTime.setAttribute('class', 'propertyTime');
propertyTime.textContent = `${time}`;
const bottomOfCard = document.createElement('div');
bottomOfCard.setAttribute('class', 'bottomOfCard');
const size = document.createElement('p');
size.setAttribute('class', 'size');
size.textContent = `${sz}`;
const sharedWith = document.createElement('p');
sharedWith.setAttribute('class', 'sharedWith');
sharedWith.textContent = 'people';
cardContainer.appendChild(mainMid);
mainMid.appendChild(iconFile);
mainMid.appendChild(dottedThree);
mainMid.appendChild(property);
property.appendChild(folderName);
property.appendChild(propertyTime);
cardContainer.appendChild(bottomOfCard);
bottomOfCard.appendChild(size);
bottomOfCard.appendChild(sharedWith);
return cardContainer;
}
function ShowTemplate(){
}
//workspace funtions
function WorkspaceEvent(){
if (socket){
socket.send('workspace');
}
var data;
console.log('workspace');
changeInP.innerText = "WORKSPACE";
addUsingJsHtmlSnippet("workSpacePath",'example');
//making a socket for constant update
if (socket == null){
socket = new WebSocket('ws://localhost:3001');
socket.addEventListener('message',(event)=>{
data = JSON.parse(event.data);
if (data.data[0] == 'err'){
alert('reconfig file');
socket.close()
socket = null;
}
console.log(data);
});
socket.addEventListener('open',()=>{
console.log('established');
socket.send('workspace');
});
socket.addEventListener('close',()=>{
console.log('closed');
});
}
}
// connect options funtions
function ConnectEvent(){
if (socket){
socket.close();
socket = null;
console.log('web socket closed');
}
changeInP.innerText = "Connect";
var creds={};
addUsingJsHtmlSnippetConnect("Connect",'ip',creds);
console.log(creds);
// attaches event to the top of mid section
cardInsertion.appendChild(cardInsertionHtmlSnippet('m.txt','1:00','folder','9G'))
}
function CloudsEvent(){
changeInP.innerText = "CLOUD";
//let addUsingJsHtmlSnippet = `<p id="main-connect">${change}:<input type="text" id="UserInput"><button id="connect" type="button"></button></p>`;
addUsingJs.innerHTML = "";
cardInsertion.innerHTML = ""
}
function FilesEvent(){
if (socket){
socket.send('file');
}
if (socket == null){
socket = new WebSocket('ws://localhost:3001');
socket.addEventListener('message',(event)=>{
data = JSON.parse(event.data);
console.log(data);
});
socket.addEventListener('open',()=>{
console.log('established');
socket.send('file');
});
socket.addEventListener('close',()=>{
console.log('closed');
});
}
changeInP.innerText = "FILES";
//let addUsingJsHtmlSnippet = `<p id="main-connect">${change}:<input type="text" id="UserInput"><button id="connect" type="button"></button></p>`;
addUsingJs.innerHTML = "";
cardInsertion.innerHTML = "";
}
function LgoutEvent(){
}
//settings top bar
//function settings(){
// //let canvas =
// if (settingInsideItem.style.display === "none"){
// //show the menu above button
// const rect = settingEvent.getBoundingClientRect();
// settingInsideItem.style.top = rect.bottom + 'px';
// settingInsideItem.style.left = rect.left + 'px';
//
// setting.style.display = 'block';
// }else{
// //hide the menu
// settingInsideItem.style.display = "none";
// }
//
//}
//
ConnectEvent();
workspaceEvent.addEventListener('click',WorkspaceEvent);
connectEvent.addEventListener('click',ConnectEvent);
cloudsEvent.addEventListener('click',CloudsEvent);
filesEvent.addEventListener('click',FilesEvent);
settingEvent.addEventListener('click',()=>{
if (notificationInsideItem.style.display){
notificationMenu.style.display = 'none';
}
if (profileInsideItem.style.display){
profileMenu.style.display = 'none'
}
if (settingInsideItem.style.display){
settingInsideItem.style.display = 'none';
}
settingInsideItem.style.display = 'block';
});
notificationEvent.addEventListener('click',()=>{
if (settingInsideItem.style.display){
settingInsideItem.style.display = 'none';
}
if (profileInsideItem.style.display){
profileInsideItem.style.display = 'none'
}
notificationInsideItem.style.display = 'block';
});
profileEvent.addEventListener('click',()=>{
if (settingInsideItem.style.display){
settingInsideItem.style.display = 'none';
}
if (notificationInsideItem.style.display){
notificationInsideItem.style.display = 'none'
}
profileInsideItem.style.display = 'block';
});
const check = document.getElementsByTagName('div');
check[1].addEventListener('click',()=>{
settingInsideItem.style.display = 'none';
notificationInsideItem.style.display = 'none';
profileInsideItem.style.display = 'none';
});
check[6].addEventListener('click',()=>{
settingInsideItem.style.display = 'none';
notificationInsideItem.style.display = 'none';
profileInsideItem.style.display = 'none';
});
check[8].addEventListener('click',()=>{
settingInsideItem.style.display = 'none';
notificationInsideItem.style.display = 'none';
profileInsideItem.style.display = 'none';
});
//settingEvent.addEventListener('click',()=>{
// settings();
//});
//document.addEventListener('click',(event) =>{
// if (!settingInsideItem.contains(event.target) && event.target !== settingEvent){
// settingInsideItem.style.display = "none";
// }
//});
//TODO: setting event and other check , create a setting pop up thingy
//TODO:connect color button , while loading let it show or disable it ,do something with password thingy after trying to connect