Merge pull request #50 from beatriceo/fixes-again

fixed modal (again)
This commit is contained in:
Beatrice Olivera 2018-09-04 11:24:03 +01:00 committed by GitHub
commit a48f955914
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 102 additions and 44 deletions

View File

@ -1,4 +1,5 @@
import "bootstrap";
import ActionCable from 'actioncable'
import { triggerModalEvent } from "../components/modal.js";
@ -36,8 +37,66 @@ if (contactsPage) {
removeActiveClass(contacts);
}
// const triggerCalleeModalEvent = () => {
// $("#calleeModal").modal('show');
// }
// export { triggerCalleeModalEvent }
const triggerCalleeModalEvent = () => {
$("#calleeModal").modal('show');
}
// export { triggerCalleeModalEvent }
// create App object with key cable == new consumer
(function() {
window.App || (window.App = {});
App.cable = ActionCable.createConsumer();
}).call(this);
const userIdElement = document.getElementById("my-user-id")
let userId = null
if (userIdElement) {
userId = parseInt(document.getElementById("my-user-id").dataset["userId"])
}
let chatRoomId = null
App.cable.subscriptions.create({
channel: 'NotificationsChannel'
}, {
connected: () => {
console.log('Connected to NotificationsChannel')
},
received: data => {
console.log("received broadcast")
if (data.head === 302 && data.body["caller"] === userId && data.path) {
window.location.pathname = data.path
} else if (data["message"]["user_id"] === userId) {
// DISPLAY ACCEPT BUTTON
const acceptButton = document.getElementById('accept-button')
acceptButton.style.display = "block"
triggerCalleeModalEvent()
document.getElementById('caller-name').innerHTML = data["message"]["caller_info"]
document.getElementById('caller-photo').src = data["message"]["caller_photo"]
chatRoomId = data["message"]["chat_room_id"]
console.log(`user with id: ${userId} needs to subscribe to chatroom ${[chatRoomId]}`)
} else {
console.log(data)
}
}
})
// Receive information from index.html.erb
const acceptButton = document.getElementById('accept-button')
if (acceptButton) {
acceptButton.addEventListener('click', event => {
document.getElementById('chat-room-id').value = chatRoomId
})
}

View File

@ -1,56 +1,55 @@
import ActionCable from 'actioncable'
// import ActionCable from 'actioncable'
// import { triggerCalleeModalEvent } from "./application";
const triggerCalleeModalEvent = () => {
$("#calleeModal").modal('show');
}
// const triggerCalleeModalEvent = () => {
// $("#calleeModal").modal('show');
// }
// // create App object with key cable == new consumer
// (function() {
// window.App || (window.App = {});
// create App object with key cable == new consumer
(function() {
window.App || (window.App = {});
// App.cable = ActionCable.createConsumer();
App.cable = ActionCable.createConsumer();
}).call(this);
// }).call(this);
const userId = parseInt(document.getElementById("my-user-id").dataset["userId"])
let chatRoomId = null
// const userId = parseInt(document.getElementById("my-user-id").dataset["userId"])
// let chatRoomId = null
App.cable.subscriptions.create({
channel: 'NotificationsChannel'
}, {
connected: () => {
console.log('Connected to NotificationsChannel')
},
received: data => {
console.log("received broadcast")
// App.cable.subscriptions.create({
// channel: 'NotificationsChannel'
// }, {
// connected: () => {
// console.log('Connected to NotificationsChannel')
// },
// received: data => {
// console.log("received broadcast")
if (data.head === 302 && data.body["caller"] === userId && data.path) {
window.location.pathname = data.path
} else if (data["message"]["user_id"] === userId) {
// if (data.head === 302 && data.body["caller"] === userId && data.path) {
// window.location.pathname = data.path
// } else if (data["message"]["user_id"] === userId) {
// DISPLAY ACCEPT BUTTON
const acceptButton = document.getElementById('accept-button')
acceptButton.style.display = "block"
// // DISPLAY ACCEPT BUTTON
// const acceptButton = document.getElementById('accept-button')
// acceptButton.style.display = "block"
triggerCalleeModalEvent()
document.getElementById('caller-name').innerHTML = data["message"]["caller_info"]
document.getElementById('caller-photo').src = data["message"]["caller_photo"]
// triggerCalleeModalEvent()
// document.getElementById('caller-name').innerHTML = data["message"]["caller_info"]
// document.getElementById('caller-photo').src = data["message"]["caller_photo"]
chatRoomId = data["message"]["chat_room_id"]
console.log(`user with id: ${userId} needs to subscribe to chatroom ${[chatRoomId]}`)
} else {
console.log(data)
}
// chatRoomId = data["message"]["chat_room_id"]
// console.log(`user with id: ${userId} needs to subscribe to chatroom ${[chatRoomId]}`)
// } else {
// console.log(data)
// }
}
})
// }
// })
// Receive information from index.html.erb
const acceptButton = document.getElementById('accept-button')
// // Receive information from index.html.erb
// const acceptButton = document.getElementById('accept-button')
acceptButton.addEventListener('click', event => {
document.getElementById('chat-room-id').value = chatRoomId
})
// acceptButton.addEventListener('click', event => {
// document.getElementById('chat-room-id').value = chatRoomId
// })

View File

@ -20,7 +20,7 @@
<%= render 'shared/navbar' unless params["action"] == "home" || params["action"] == "new" || params["action"] == "call" %>
<%= render 'shared/flashes' %>
<%= yield %>
<%= javascript_include_tag 'application' %>
<%= javascript_pack_tag 'application' %>
<%= javascript_include_tag 'application' %>
</body>
</html>

View File

@ -73,6 +73,6 @@
</div>
<%= javascript_pack_tag 'local_video' %>
<%= javascript_pack_tag 'notifications' %>
<%# javascript_pack_tag 'notifications' %>