-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
353 lines (284 loc) · 10.1 KB
/
script.js
File metadata and controls
353 lines (284 loc) · 10.1 KB
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
// ##### TASK #####
let task;
/**
* That object is used in AddTask when creating a new task.
* Familiar functions: templatePrioritySelection(i), changeSelectedPrioBtn(i), resetOtherPrioBtns(i)
*/
let priorities = [
{
'name': 'Urgent',
'prio-index': 0,
'image': './assets/img/red-prio.svg',
'color': '#FF3D00'
},
{
'name': 'Medium',
'prio-index': 1,
'image': './assets/img/orange-prio.svg',
'color': '#FFA800'
},
{
'name': 'Low',
'prio-index': 2,
'image': './assets/img/green-prio.svg',
'color': '#7AE229'
}
]
// ##### BOARD #####
/**
* That array is important when using the board searchbar for searching a ticket and than editting it. After the board reloads, only the search results are still visible,
* because the hiden tickets are pushed before to 'hiddenTickets'.
*/
let hiddenTickets = [];
/**
* That variable is important in board.html when closing the ticket info popup. When the ticket was editted, the board needs to be reloaded.
*/
let taskEditted = false;
let taskDeleted = false;
// ##### CONTACTS #####
let contacts = [];
/**
* That object is important when creating a new contact in contacts. Familiar functions: addAllInputValuesToContact()
*/
let newContact = {
'name': '',
'color': '',
'email': '',
'phone': '',
'abbreviation': '',
}
/**
* That object is important to for the scroll function, after editting or creating a new contact in "contacts"
* Familiar functions: settingContactValuesGlobaly(index, letter, number), cleanContactValues()
*/
let contactValues = {
'index' : '',
'letter' : '',
'number' : '',
}
/**
* That variable is important to scroll to the new contact after creating it.
* Find it in contacts.js. Familiar functions: filerContacts()
*/
let createdContactName;
/**
* This two variables are important for loading the right templates and buttons, if a contact will be editted or not (creating new contact).
* Familiar functions: settingValuesForEdittingContact(index), cleanValuesForEdittingContact()
*/
let edittingNewContact = false;
let indexOfChoosedContactToEdit;
/**
* Array for choosing a random color out of this array. Find it in contacts.js
* Familiar functions: addColorToContact(identifier)
*/
let colors = ['#0190e0','#ee00d6', '#02cf2f', '#ffa800', '#9327ff', '#ff5c00', '#4e963d', '#32daff', '#007cee', '#cb02cf']
/**
* That variable is important to get an alphabetic order in the contacts list.
* Familiar functions: filterContacts(list)
*/
let alphabet = [...'abcdefghijklmnopqrstuvwxyz'];
// ##### USERS #####
let users = [];
let usersContact = [];
// ##### CATEGORY #####
let category = [];
let categoryColors = ['#FF8A00', '#8AA4FF', '#FF0000', '#2AD300', '#E200BE', '#0038FF']
// ##### NAV #####
let selectedNavItem = 0;
/**
* That function marks the category/tab in the navbar on the same page.
* @param {number} n - The id of the category/tab in the nav
*/
function markNavItem(n) {
document.getElementById(`${n}`).classList.add('selected-nav-item');
}
// ##### HEADER RESPONSIVE #####
/**
* That function add a title-template into the content-container (in responsive view)
*/
function renderResponsiveHeaderTitle() {
document.getElementById('content-container').innerHTML = `<p class="header-title-resp cursor-d">Kanban Project Management Tool</p>`;
}
// ########## BACKEND ##########
setURL('https://join.simon-besenbaeck.com/smallest_backend_ever');
async function init() {
await downloadFromServer();
usersContact = await JSON.parse(backend.getItem('usersContact')) || [];
boardColumns = await JSON.parse(backend.getItem('boardColumns')) || [[], [], [], []]; // compare with line 6
category = await JSON.parse(backend.getItem('category')) || [];
contacts = await JSON.parse(backend.getItem('contacts')) || [];
isLoggedInn();
getIndexOfCurrentUser();
renderSiteRelatedTemplate();
console.clear();
}
/**
* That function helps us do delete all server-data, if we want to test for functionality.
*/
async function deleteServerData() {
await backend.deleteItem('usersContact');
await backend.deleteItem('boardColumns');
await backend.deleteItem('category');
await backend.deleteItem('contacts');
await backend.deleteItem('users');
}
/**
* That function gets the abbreviation of a given name (shortletter).
* @param {string} name - name is a user/contact name
* @returns an abbreviation, to letter from the name in uppercase.
*/
function getNameLetters(name) {
let firstLetter = name.toString().charAt(0).toUpperCase();
let index = name.indexOf(' ');
let secondLetter = name.toString().charAt(index+1).toUpperCase();
checkIfTwoNamesEntered(index);
return firstLetter + secondLetter;
}
/**
* This function is used to check if there were two names entered when creating the contact
*
* @param {Number} index - The index of the empty space in the input fiel (-1 if no second name)
*/
function checkIfTwoNamesEntered(index) {
if (index >= 0) {
firstAndLastName = true;
}
}
/**
* That function renders the site (url) related templates.
*/
function renderSiteRelatedTemplate() {
renderNavAndHeader();
if(window.location.pathname.includes('summary.html')) initSummary(1);
else if(window.location.pathname.includes('board.html')) initBoard(2);
else if(window.location.pathname.includes('add_task.html')) initAddtask(3);
else if(window.location.pathname.includes('contacts.html')) initContacts(4);
else if(window.location.pathname.includes('legal_notice.html')) markNavItem(5);
}
/**
* This function renders the navbar and the header. Almost on every site.
*/
function renderNavAndHeader() {
renderNav();
renderHeader();
}
/**
* That function is the site related init function with site related navbar-marking and content.
* @param {number} value - value is the a site related number for marking the right navbar element, when entering that site.
*/
function initSummary(value) {
greet();
markNavItem(value);
renderPopups();
renderSummary();
}
/**
* That function is the site related init function with site related navbar-marking and content.
* @param {string} value - value is the a site related number for marking the right navbar element, when entering that site.
*/
function initBoard(value) {
markNavItem(value);
renderPopupsInBoard();
renderBoard();
}
/**
* That function is the site related init function with site related navbar-marking and content.
* @param {string} value - value is the a site related number for marking the right navbar element, when entering that site.
*/
function initAddtask(value) {
markNavItem(value);
renderPopups();
initAddTask();
}
/**
* That function is the site related init function with site related navbar-marking and content.
* @param {string} value - value is the a site related number for marking the right navbar element, when entering that site.
*/
function initContacts(value) {
markNavItem(value);
renderPopupsInContacts();
renderContactsList();
}
// LOGIN
/**
* That function checks, if there are any login (signed-in user or guest) related data. If not, the user will be put back
* to the login site (index.html).
*/
function isLoggedInn() {
let itemSet = localStorage.getItem('usersEmail');
if(!(itemSet || anyCurrentUserHeaderData() || isGuestUser())) {
window.location.href = 'index.html?msg=Du hast dich erfolgreich abgemeldet';
}
}
// ADD
/**
* That function adds the contacts array to the server database and overwrites previous saved data on the server.
*/
async function addContact() {
await backend.setItem('contacts', JSON.stringify(contacts));
}
/**
* That function adds the boardColumns array to the server database and overwrites previous saved data on the server.
*/
async function addBoard() {
await backend.setItem('boardColumns', JSON.stringify(boardColumns));
}
// HELPFULL FUNCTIONS
/**
* That function is a smaller helpfull function to add a class name to an element.
* @param {string} id - id is the id of an element to which we want add a class to
* @param {string} classe - classe is a class name, that we want to add to the element
*/
function addClasslist(id, classe) {
document.getElementById(id).classList.add(classe);
}
/**
* That function is a smaller helpfull function to remove a class name from an element.
* @param {string} id - id is the id of an element from which we want remove a class from
* @param {string} classe - classe is a class name, that we want to remove from the element
*/
function removeClasslist(id, classe) {
document.getElementById(id).classList.remove(classe);
}
/**
* That function is needed in most popups, that have a close event onlick on the background.
* That function prevents the popup to close, if we click right on the popup.
* @param {event} event
*/
function doNotClose(event) {
event.stopPropagation();
}
/**
* Returns a random integer from 0 to 9:
* Math.random returns a number lower than 1
* Math.floor makes the decimal number to a 'no decimal' number
* 10 is the number of values we want, beginning from 0
* Using this function to get a random color out of the array 'colors'
*/
function getRandomNumberFromZeroToNine() {
return Math.floor(Math.random() * 10);
}
/**
* That function checks if the current site is equal to the add_taks.html url.
* If yes, it returns true.
* @returns a boolean
*/
function URLequalsAddTaskHtml() {
if ('/add_task.html' == window.location.pathname || '/join/add_task.html' == window.location.pathname) {
return true;
}
}
//// To get the index of the current user in usersContact
let indexOfCurrentUser;
/**
* That function gets the index of the current logged-in user by looping through usersContact and
* comparing the (in localstorage) stored email address.
*/
function getIndexOfCurrentUser() {
for (let i = 0; i < usersContact.length; i++) {
if (usersContact[i]['email'] == localStorage.getItem('usersEmail')) {
indexOfCurrentUser = i;
break;
}
}
}