Skip to content

Commit b4558a4

Browse files
committed
Implemented search
Closes #12
1 parent c85438a commit b4558a4

File tree

18 files changed

+284
-18
lines changed

18 files changed

+284
-18
lines changed

assets/js/Interface/NavBar.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import Mail from './NavBar/Mail';
33
export default class NavBar {
44
constructor() {
55
this.mails = {};
6+
7+
document.querySelector('#messages .search input').addEventListener('keyup', this.search.bind(this));
8+
document.querySelector('#messages .search input').addEventListener('keypress', this.search.bind(this));
9+
document.querySelector('#messages .search input').addEventListener('paste', this.search.bind(this));
10+
document.querySelector('#messages .search input').addEventListener('input', this.search.bind(this));
611
}
712

813
addMails(mails) {
@@ -35,4 +40,10 @@ export default class NavBar {
3540
this.mails[id].deactivate();
3641
});
3742
}
43+
44+
search(e) {
45+
Object.keys(this.mails).forEach((key)=> {
46+
this.mails[key].filter(e.target.value.toLowerCase());
47+
});
48+
}
3849
}

assets/js/Interface/NavBar/Mail.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export default class Mail {
1010
this.addSubject(mail.subject);
1111
this.addTimestamp(mail.timestamp);
1212
this.setReadStatus(mail.read);
13+
14+
this.searchableContent = mail.searchableContent;
1315
}
1416

1517
addToDom() {
@@ -63,4 +65,22 @@ export default class Mail {
6365
markAsRead() {
6466
this.element.classList.remove('new');
6567
}
68+
69+
filter(search) {
70+
if (this.searchableContent.indexOf(search)=== -1) {
71+
this.hide();
72+
73+
return;
74+
}
75+
76+
this.show();
77+
}
78+
79+
hide() {
80+
this.element.classList.add('filtered');
81+
}
82+
83+
show() {
84+
this.element.classList.remove('filtered');
85+
}
6686
}

assets/scss/components/messages.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ nav#messages {
2626
}
2727

2828
button {
29-
cursor: pointer;
3029
color: #ffffff;
3130
}
3231
}
@@ -41,6 +40,10 @@ nav#messages {
4140
color: #ffffff;
4241
}
4342

43+
&.filtered {
44+
display: none;
45+
}
46+
4447
time {
4548
font-size: 11px;
4649
padding: 10px 10px 10px 15px;

examples/test.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace PeeHaa\MailGrab\Examples;
4+
5+
use PHPMailer\PHPMailer\PHPMailer;
6+
7+
require_once __DIR__ . '/../vendor/autoload.php';
8+
9+
$mail = new PHPMailer();
10+
11+
$mail->isSMTP();
12+
$mail->Host = 'localhost';
13+
$mail->Port = 9025;
14+
$mail->SMTPDebug = true;
15+
16+
$mail->setFrom('[email protected]', 'Mailer');
17+
$mail->addAddress('[email protected]', 'Joe User'); // Add a recipient
18+
$mail->addAddress('[email protected]'); // Name is optional
19+
$mail->addReplyTo('[email protected]', 'Information');
20+
$mail->addCC('[email protected]');
21+
$mail->addBCC('[email protected]');
22+
23+
$mail->Subject = 'PHPMailer';
24+
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
25+
$mail->isHTML(true);
26+
27+
if(!$mail->send()) {
28+
echo 'Message could not be sent.';
29+
echo 'Mailer Error: ' . $mail->ErrorInfo;
30+
} else {
31+
echo 'Message has been sent';
32+
}

public/css/bundle.css

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/css/bundle.min.css

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/bundle.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17105,6 +17105,11 @@ var NavBar = function () {
1710517105
_classCallCheck(this, NavBar);
1710617106

1710717107
this.mails = {};
17108+
17109+
document.querySelector('#messages .search input').addEventListener('keyup', this.search.bind(this));
17110+
document.querySelector('#messages .search input').addEventListener('keypress', this.search.bind(this));
17111+
document.querySelector('#messages .search input').addEventListener('paste', this.search.bind(this));
17112+
document.querySelector('#messages .search input').addEventListener('input', this.search.bind(this));
1710817113
}
1710917114

1711017115
_createClass(NavBar, [{
@@ -17149,6 +17154,15 @@ var NavBar = function () {
1714917154
_this3.mails[id].deactivate();
1715017155
});
1715117156
}
17157+
}, {
17158+
key: 'search',
17159+
value: function search(e) {
17160+
var _this4 = this;
17161+
17162+
Object.keys(this.mails).forEach(function (key) {
17163+
_this4.mails[key].filter(e.target.value.toLowerCase());
17164+
});
17165+
}
1715217166
}]);
1715317167

1715417168
return NavBar;
@@ -17185,6 +17199,8 @@ var Mail = function () {
1718517199
this.addSubject(mail.subject);
1718617200
this.addTimestamp(mail.timestamp);
1718717201
this.setReadStatus(mail.read);
17202+
17203+
this.searchableContent = mail.searchableContent;
1718817204
}
1718917205

1719017206
_createClass(Mail, [{
@@ -17249,6 +17265,27 @@ var Mail = function () {
1724917265
value: function markAsRead() {
1725017266
this.element.classList.remove('new');
1725117267
}
17268+
}, {
17269+
key: 'filter',
17270+
value: function filter(search) {
17271+
if (this.searchableContent.indexOf(search) === -1) {
17272+
this.hide();
17273+
17274+
return;
17275+
}
17276+
17277+
this.show();
17278+
}
17279+
}, {
17280+
key: 'hide',
17281+
value: function hide() {
17282+
this.element.classList.add('filtered');
17283+
}
17284+
}, {
17285+
key: 'show',
17286+
value: function show() {
17287+
this.element.classList.remove('filtered');
17288+
}
1725217289
}]);
1725317290

1725417291
return Mail;

public/js/bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/bundle.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Http/Command/Init.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ private function buildList(): array
4141
/** @var Mail $mail */
4242
foreach ($this->storage as $mail) {
4343
$list[] = [
44-
'id' => $mail->getId(),
45-
'subject' => $mail->getSubject(),
46-
'timestamp' => $mail->getTimestamp()->format(\DateTime::RFC3339_EXTENDED),
47-
'read' => $mail->isRead(),
48-
'project' => $mail->getProject(),
44+
'id' => $mail->getId(),
45+
'subject' => $mail->getSubject(),
46+
'searchableContent' => $mail->getSearchableContent(),
47+
'timestamp' => $mail->getTimestamp()->format(\DateTime::RFC3339_EXTENDED),
48+
'read' => $mail->isRead(),
49+
'project' => $mail->getProject(),
4950
];
5051
}
5152

0 commit comments

Comments
 (0)