Skip to content

Commit 24147ac

Browse files
committed
webpack encore integration, frontend refactor
1 parent 0ea24b3 commit 24147ac

File tree

918 files changed

+6291
-143577
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

918 files changed

+6291
-143577
lines changed

.bowerrc

-3
This file was deleted.

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,8 @@
4545
/composer.phar
4646

4747
# Backup entities generated with doctrine:generate:entities command
48-
*/Entity/*~
48+
*/Entity/*~
49+
50+
# JS modules
51+
/node_modules/*
52+
/web/build/*

.jscsrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"preset": "jquery",
3+
"requireCurlyBraces": false,
4+
"requireSpacesInsideParentheses": false,
5+
"requireSpacesInsideBrackets": false,
6+
"disallowSpacesInsideParentheses": { "only": [ "{", "}", "\"" ] }
7+
}

.jshintrc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"undef": true,
3+
"node": true,
4+
"browser": true,
5+
"unused": true,
6+
"globals": {
7+
"MY_GLOBAL": true
8+
}
9+
}

.php_cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
$finder = Symfony\Component\Finder\Finder::create()
4+
->in(__DIR__.'/src')
5+
->name('*.php')
6+
;
7+
8+
return PhpCsFixer\Config::create()
9+
->setRiskyAllowed(true)
10+
->setRules([
11+
'@Symfony' => true,
12+
'@Symfony:risky' => true,
13+
'ordered_imports' => true,
14+
'strict_comparison' => true,
15+
'array_syntax' => ['syntax' => 'short'],
16+
'phpdoc_add_missing_param_annotation' => true,
17+
])
18+
->setFinder($finder)
19+
;

app/AppKernel.php

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public function registerBundles()
1212
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
1313
new Symfony\Bundle\TwigBundle\TwigBundle(),
1414
new Symfony\Bundle\MonologBundle\MonologBundle(),
15-
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
1615
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
1716
new Gamma\Pushpin\PushpinBundle\GammaPushpinBundle(),
1817
new AppBundle\AppBundle(),

app/config/config.yml

+2-9
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,14 @@ framework:
3131
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
3232
fragments: ~
3333
http_method_override: true
34-
assets: ~
34+
assets:
35+
json_manifest_path: '%kernel.project_dir%/web/build/manifest.json'
3536

3637
# Twig Configuration
3738
twig:
3839
debug: "%kernel.debug%"
3940
strict_variables: "%kernel.debug%"
4041

41-
# Swiftmailer Configuration
42-
swiftmailer:
43-
transport: "%mailer_transport%"
44-
host: "%mailer_host%"
45-
username: "%mailer_user%"
46-
password: "%mailer_password%"
47-
spool: { type: memory }
48-
4942
gamma_pushpin:
5043
proxy:
5144
control_uri: "%pushpin.control_uri%"

app/config/parameters.yml.dist

-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
parameters:
2-
database_host: 127.0.0.1
3-
database_port: ~
4-
database_name: ws-chat
5-
database_user: root
6-
database_password: ~
72
mailer_transport: smtp
83
mailer_host: 127.0.0.1
94
mailer_user: ~

app/frontend/js/http.chat.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
class HttpChat {
2+
3+
displayNewMessage(message) {
4+
let container = $("#default-messages");
5+
container.prepend(
6+
$(this._messageTemplate({ "dateTime": this._moment().format("lll"), "comment": message }))
7+
);
8+
}
9+
10+
sendMessage() {
11+
let _this = this;
12+
$.ajax({
13+
url: this._postUrl,
14+
async: "false",
15+
cache: "false",
16+
type: "POST",
17+
data: this._form.serialize(),
18+
success: function(response) {
19+
_this._form[0].reset();
20+
}
21+
});
22+
}
23+
24+
constructor(uri, formId, postUrl) {
25+
let connection = require("stream-http");
26+
let _this = this;
27+
28+
this._postUrl = postUrl;
29+
this._moment = require("moment");
30+
this._messageTemplate = require("./templates/new_message.hbs");
31+
this._form = $("#" + formId);
32+
33+
connection.get(uri, function(res) {
34+
res.on("data", function(buf) {
35+
_this.displayNewMessage(buf.toString());
36+
});
37+
});
38+
39+
this._form.on("submit", function(e) {
40+
e.preventDefault();
41+
e.stopPropagation();
42+
_this.sendMessage();
43+
44+
return false;
45+
});
46+
}
47+
}
48+
49+
connect = function(uri, formId, postUrl) {
50+
new HttpChat(uri, formId, postUrl);
51+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div class="panel panel-default">
2+
<div class="panel-heading">{{dateTime}}</div>
3+
<div class="panel-body">{{comment}}</div>
4+
</div>

app/frontend/js/templates/new_tab.hbs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<li data-chatroom="{{ room }}">
2+
<a href="#room-{{ room }}">{{ room }}
3+
<span class="close" style="margin-left: 5px;">×</span>
4+
</a>
5+
</li>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div class="tab-pane fade in" id="room-{{ room }}">
2+
<small>Messages from {{ room }} room</small>
3+
<div class="room-messages" id="{{ room }}-messages">
4+
<!--messages starts here-->
5+
</div>
6+
</div>

app/frontend/js/ws.chat.js

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
class WebSocketChat {
2+
3+
enterRoom(roomName) {
4+
let message = {
5+
room: roomName
6+
};
7+
this._connection.send("chatRoomEnter:" + JSON.stringify(message));
8+
}
9+
10+
leaveRoom(roomName) {
11+
let message = {
12+
room: roomName
13+
};
14+
this._connection.send("chatRoomLeave:" + JSON.stringify(message));
15+
}
16+
17+
createRoom(roomName) {
18+
if ($("#room-" + roomName ).length > 0) {
19+
$('[href="#room-' + roomName + '"]').tab("show");
20+
return false;
21+
}
22+
23+
let tab = require("./templates/new_tab.hbs");
24+
let tabContent = require("./templates/new_tab_content.hbs");
25+
$("#room-tabs").append(
26+
$(tab({ "room": roomName }))
27+
);
28+
$("#room-tabs-content").append(
29+
$(tabContent({ "room": roomName }))
30+
);
31+
32+
$('[href="#room-' + roomName + '"]').tab("show");
33+
34+
this.enterRoom(roomName);
35+
36+
return true;
37+
}
38+
39+
displayNewMessage(message) {
40+
let messageData;
41+
try {
42+
messageData = JSON.parse(message);
43+
} catch (e) {
44+
return;
45+
}
46+
47+
let container = $("#" + messageData.room + "-messages");
48+
container.prepend(
49+
$(this._messageTemplate({ "dateTime": this._moment().format("lll"), "comment": messageData.comment }))
50+
);
51+
}
52+
53+
sendMessage(roomName, comment) {
54+
let message = {
55+
room: roomName,
56+
comment: comment
57+
};
58+
this._connection.send("chatMessage:" + JSON.stringify(message));
59+
}
60+
61+
constructor(url) {
62+
this._connection = new WebSocket(url);
63+
this._moment = require("moment");
64+
this._messageTemplate = require("./templates/new_message.hbs");
65+
66+
let that = this;
67+
this._connection.onopen = function() {
68+
let init = {
69+
room:"default"
70+
};
71+
that._connection.send("chatRoomEnter:" + JSON.stringify(init));
72+
};
73+
74+
this._connection.onmessage = function(event) {
75+
that.displayNewMessage(event.data);
76+
};
77+
}
78+
}
79+
80+
(function($) {
81+
$.fn.onPressEnter = function(func) {
82+
this.bind("keypress", function(e) {
83+
if ( e.keyCode === 13 ) {
84+
e.preventDefault();
85+
func.apply(this, [e]);
86+
}
87+
});
88+
return this;
89+
};
90+
})(jQuery);
91+
92+
connect = function(url) {
93+
let chat = new WebSocketChat(url);
94+
let messageInput = $("input#new-message");
95+
let newRoomInput = $("input#new-room-name");
96+
let send = function() {
97+
if ("" === messageInput.val() ) {
98+
return;
99+
}
100+
chat.sendMessage($("li.active").data("chatroom"), messageInput.val());
101+
messageInput.val(null);
102+
};
103+
104+
let newRoom = function() {
105+
if ("" === newRoomInput.val() ) {
106+
return;
107+
}
108+
chat.createRoom(newRoomInput.val());
109+
newRoomInput.val(null);
110+
};
111+
112+
/**
113+
* Send message
114+
*/
115+
messageInput.onPressEnter(function() {
116+
send();
117+
});
118+
$("#btn-send").on("click", function() {
119+
send();
120+
});
121+
122+
/**
123+
* Create new room
124+
*/
125+
newRoomInput.onPressEnter( function() {
126+
newRoom();
127+
});
128+
$("#btn-add-room").on("click", function() {
129+
newRoom();
130+
});
131+
132+
/**
133+
* Remove a Tab
134+
*/
135+
$("#room-tabs").on("click", " li a .close", function() {
136+
let roomName = $( this ).parents("li.active").data("chatroom");
137+
chat.leaveRoom(roomName);
138+
139+
let tabId = $( this ).parents("li").children("a").attr("href");
140+
$( this ).parents("li").remove("li");
141+
$( tabId ).remove();
142+
143+
$("#room-tabs a:first").tab("show");
144+
});
145+
146+
/**
147+
* Click Tab to show its content
148+
*/
149+
$("#room-tabs").on("click", "a", function( e ) {
150+
e.preventDefault();
151+
$( this ).tab("show");
152+
});
153+
};

composer.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,23 @@
1919
"require": {
2020
"php": ">=5.5.9",
2121
"symfony/symfony": "3.4.*",
22-
"symfony/swiftmailer-bundle": "^2.3",
2322
"symfony/monolog-bundle": "^2.8",
2423
"symfony/polyfill-apcu": "^1.0",
2524
"sensio/distribution-bundle": "^5.0",
2625
"sensio/framework-extra-bundle": "^5.1",
2726
"incenteev/composer-parameter-handler": "^2.0",
28-
"gamma/pushpin-bundle" : "^0.1"
27+
"gamma/pushpin-bundle" : "dev-develop"
2928
},
3029
"require-dev": {
3130
"sensio/generator-bundle": "^3.0",
3231
"symfony/phpunit-bridge": "^3.0"
3332
},
33+
"repositories": [
34+
{
35+
"type": "path",
36+
"url": "/home/stas/projects/pushpin-bundle/"
37+
}
38+
],
3439
"scripts": {
3540
"symfony-scripts": [
3641
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
@@ -49,7 +54,7 @@
4954
},
5055
"config": {
5156
"platform": {
52-
"php": "5.5.9"
57+
"php": "7.1"
5358
}
5459
},
5560
"minimum-stability": "stable",

0 commit comments

Comments
 (0)