-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
168 lines (145 loc) · 5.19 KB
/
main.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
$( document ).ready(function() {
// Current Event Data from Api
const currentEvent = {
"id": 13,
"title": "Prototyping Days #1",
"projectdeadline": null
}
// Set current event title
document.querySelector('.jumbotron .current-event').innerHTML = `
<span class="badge badge-secondary">Current Event</span>
<h4>${currentEvent.title}</h4>`;
// Goto current Event in Event Catalogue
document.querySelector('.jumbotron .btn').addEventListener('click', function(){
// Goto current Event in Event Catalogue
$(`#id${currentEvent.id}`).collapse('toggle');
$(`#id${currentEvent.id}`).parent().find(`[data-target="#id${currentEvent.id}"]`).find('i').toggleClass('fa-angle-left fa-angle-down');
})
// Fetch Project Data from Api
function getProjectData(){
fetch('API/projectData.json')
.then(function(response) {
return response.json();
})
.then(function(response) {
// console.log(response);
projectData = response;
})
}
var projectData = getProjectData();
var eventCatalogue = document.querySelector('#event-catalogue .card-body');
fetch('API/eventData.json')
.then(function(eventData) {
return eventData.json();
})
.then(function(eventData) {
placeEvents(eventData);
return eventData;
})
.then(function(){
// Sort Events by event title
document.querySelector('.dropdownEventCatalogue > .alphabatically').addEventListener('click', function(e){
$(this).parent().find('.active').removeClass('active');
$(this).addClass('active');
var events = document.querySelectorAll('.event-box');
var eventCatalogueBody = document.querySelector('#events');
sortAlpha(events,eventCatalogueBody);
})
// Sort Projects by project title
document.querySelectorAll('#sort-project .alphabatically').forEach(function(obj){
obj.addEventListener('click', function(e){
$(this).parent().find('.active').removeClass('active');
$(this).addClass('active');
var currentEventBox = e.path[3];
projects = currentEventBox.querySelectorAll('.project-box');
sortAlpha(projects, currentEventBox);
})
})
})
// Modal behavior on Projects
function createProjectModal(id, title, shortDescription, description){
var projectModal = `
<div class="project-box mx-4">
<button type="button" class="btn btn-primary my-2 d-block text-truncate mw-100" data-toggle="modal" data-target="#projectid${id}">
${title}
</button>
<div class="modal fade" id="projectid${id}" tabindex="-1" role="dialog" aria-labelledby="projectModalLongTitle" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="projectModalLongTitle"><strong>Project Title:</strong> ${title}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body text-justify">
<p><strong>Short Description: </strong>${shortDescription}</p>
<p><strong>Description: </strong>${description}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Like</button>
<button type="button" class="btn btn-primary">Comment</button>
<button type="button" class="btn btn-primary mr-auto">Join</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>`
return projectModal;
}
function placeEvents(eventData){
for(let i=0; i<eventData.length; i++){
var event = `
<div class="event-box">
<div class="card-header mb-1" data-toggle="collapse" data-target="#id${eventData[i].id}">
<div class="d-flex align-items-center">
<h6>${eventData[i].title}</h6>
<i class="fas fa-angle-left ml-auto"></i>
</div>
</div>
<div id="id${eventData[i].id}" class="event-body collapse">
</div>
</div>
`;
eventCatalogue.insertAdjacentHTML('beforeend',event);
var eventBody = document.querySelector(`#id${eventData[i].id}`);
var sortEvent = `
<div id="sort-project" class="dropdown ml-4">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdown-id${eventData[i].id}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Sort Projects
</button>
<div class="dropdown-menu">
<a class="dropdown-item alphabatically" href="#id${eventData[i].id}">Alphabatically</a>
<a class="dropdown-item" href="#id${eventData[i].id}">By Deadline</a>
</div>
</div>`;
eventBody.insertAdjacentHTML('beforeend',sortEvent);
for(let j=0; j<projectData.length; j++){
if(eventData[i].id === projectData[j]["event"]["id"]){
var project = createProjectModal(projectData[j]['id'], projectData[j]['title'], projectData[j]['short_description'], projectData[j]['description']);
eventBody.insertAdjacentHTML('beforeend',project);
}
}
}
angleUpDown();
}
function angleUpDown(){
// Angle UpDown Event
document.querySelectorAll('#event-catalogue #events .card-header').forEach(function(event){
event.addEventListener('click', function(e) {
$(e.target).parent().find('[class*="angle"]').toggleClass('fa-angle-down fa-angle-left');
});
})
}
function sortAlpha(nodeList,appendTo){
nodeArr = Array.from(nodeList);
nodeArr.sort(function (a, b) {
return a.textContent > b.textContent ? 1 : -1;
});
nodeArr.forEach(function (p) {
appendTo.appendChild(p);
});
}
//
});