-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage-template.js
161 lines (149 loc) · 5.42 KB
/
page-template.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
const EnumEmployeeType = require('../lib/enum/EnumEmployeeType');
// creates the team
const generateTeam = (team) => {
// creates the manager html
const generateManager = (manager) => {
let managerCardHtmlTemplate = `
<div class="card employee-card mr-2 ml-2">
<div class="card-header d-flex flex-column align-items-stretch justify-content-between" style="min-height: 180px;">
<h2 class="card-title w-100 flex-grow-1">{{name}}</h2>
<h3 class="card-title w-100 flex-grow-1">
<i class="fas fa-mug-hot mr-2"></i>{{role}}
</h3>
</div>
<div class="card-body">
<ul class="list-group">
<li class="list-group-item">ID: {{id}}</li>
<li class="list-group-item">Email: <a href="mailto:{{email}}">{{email}}</a></li>
<li class="list-group-item">Office number: {{officeNumber}}</li>
</ul>
</div>
</div>`;
try {
managerCardHtmlTemplate = managerCardHtmlTemplate
.replace(/{{name}}/g, manager.getName())
.replace(/{{role}}/g, manager.getRole())
.replace(/{{id}}/g, manager.getId())
.replace(/{{email}}/g, manager.getEmail())
.replace(/{{officeNumber}}/g, manager.getOfficeNumber());
} catch (err) {
console.error(err);
} finally {
return managerCardHtmlTemplate;
}
};
// creates the html for engineers
const generateEngineer = (engineer) => {
let engineerCartHtmlTemplate = `
<div class="card employee-card mr-2 ml-2">
<div class="card-header d-flex flex-column align-items-stretch justify-content-between" style="min-height: 180px;">
<h2 class="card-title w-100 flex-grow-1">{{name}}</h2>
<h3 class="card-title w-100 flex-grow-1">
<i class="fas fa-glasses mr-2"></i>{{role}}
</h3>
</div>
<div class="card-body">
<ul class="list-group">
<li class="list-group-item">ID: {{id}}</li>
<li class="list-group-item">Email:<a href="mailto:{{email}}">{{email}}</a></li>
<li class="list-group-item">GitHub: <a href="https://github.com/{{github}}" target="_blank" rel="noopener noreferrer">{{github}}</a></li>
</ul>
</div>
</div>`;
try {
engineerCartHtmlTemplate = engineerCartHtmlTemplate
.replace(/{{name}}/g, engineer.getName())
.replace(/{{role}}/g, engineer.getRole())
.replace(/{{id}}/g, engineer.getId())
.replace(/{{email}}/g, engineer.getEmail())
.replace(/{{github}}/g, engineer.getGithub());
} catch (err) {
console.error(err);
} finally {
return engineerCartHtmlTemplate;
}
};
// creates the html for interns
const generateIntern = (intern) => {
let internCardHtmlTemplate = `
<div class="card employee-card mr-2 ml-2">
<div class="card-header d-flex flex-column align-items-stretch justify-content-between" style="min-height: 180px;">
<h2 class="card-title w-100 flex-grow-1">{{name}}</h2>
<h3 class="card-title w-100 flex-grow-1">
<i class="fas fa-user-graduate mr-2"></i>{{role}}
</h3>
</div>
<div class="card-body">
<ul class="list-group">
<li class="list-group-item">ID: {{id}}</li>
<li class="list-group-item">Email: <a href="mailto:{{email}}">{{email}}</a></li>
<li class="list-group-item">School: {{school}}</li>
</ul>
</div>
</div>`;
try {
internCardHtmlTemplate = internCardHtmlTemplate
.replace(/{{name}}/g, intern.getName())
.replace(/{{role}}/g, intern.getRole())
.replace(/{{id}}/g, intern.getId())
.replace(/{{email}}/g, intern.getEmail())
.replace(/{{school}}/g, intern.getSchool());
} catch (err) {
console.error(err);
} finally {
return internCardHtmlTemplate;
}
};
const html = [];
html.push(
team
.filter((employee) => employee.getRole() === EnumEmployeeType.MANAGER)
.map((manager) => generateManager(manager))
);
html.push(
team
.filter((employee) => employee.getRole() === EnumEmployeeType.ENGINEER)
.map((engineer) => generateEngineer(engineer))
.join('')
);
html.push(
team
.filter((employee) => employee.getRole() === EnumEmployeeType.INTERN)
.map((intern) => generateIntern(intern))
.join('')
);
return html.join('');
};
// exports function to generate entire page
module.exports = (team, teamName) => {
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>${teamName}</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="style.css">
<script src="https://kit.fontawesome.com/c502137733.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-12 jumbotron mb-3 team-heading">
<h1 class="text-center">${teamName}</h1>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="team-area col-12 d-flex justify-content-center">
${generateTeam(team)}
</div>
</div>
</div>
</body>
</html>
`;
};