Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions app/Http/Controllers/ChatController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace App\Http\Controllers;

use App\Models\Chat;
use App\Models\Ontology;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class ChatController extends Controller
{
/**
* Instantiate a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}

/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function updateChat(Request $request)
{
$mesagens = Chat::select()->where('ontology_id', $request->ontology_id)->latest("created_at")->limit(150)->orderBy("id")->get();
/*$ontology = $mesagens->ontology;

if (Auth::user()->id == $ontology['user_id'] || $ontology->users->contains(Auth::user()->id)) {*/

return view('ontologies.chat', compact('mesagens'));
//}
}

public function sendChat(Request $request)
{
if ($request->ontology_id > 0) {

$ontology = Ontology::where('id', $request->ontology_id)->first();

if (Auth::user()->id == $ontology['user_id'] || $ontology->users->contains(Auth::user()->id)) {
if (strlen($request['message']) > 0) {
if (Auth::user() != null) {
$data = $request->all();
$data['user_id'] = Auth::user()->id;

Chat::create($data);

$retorno['status'] = "SUCESSO";
} else {
$retorno['status'] = "ERRO";
}
} else {
$retorno['status'] = "ERRO";
}
} else {
$retorno['status'] = "ERRO";
}
} else {
$retorno['status'] = "ERRO";
}

echo json_encode($retorno);
}
}
39 changes: 39 additions & 0 deletions app/Models/Chat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Chat extends Model
{
use HasFactory;

protected $fillable = [
'message',
'ontology_id',
'user_id',
'created_at',
];

/*************************** Relations **********************************/

/**
* One to many relation with user Model.
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class);
}


/**
* One to many relation with user Model.
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function ontology()
{
return $this->belongsTo(Ontology::class);
}
}
36 changes: 36 additions & 0 deletions database/migrations/2022_01_13_234348_create_chats_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateChatsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('chats', function (Blueprint $table) {
$table->id();
$table->string('message');
$table->unsignedBigInteger('ontology_id');
$table->unsignedInteger('user_id');
$table->foreign('ontology_id')->references('id')->on('ontologies')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('chats');
}
}
19 changes: 18 additions & 1 deletion public/grapheditor/styles/grapheditor.css
Original file line number Diff line number Diff line change
Expand Up @@ -1862,4 +1862,21 @@ div.picker { z-index: 10007; }
.autosave input:checked + label:after {
left: calc(100% - 2px);
transform: translateX(-100%);
}
}

.chat-ontology {
position: fixed;
bottom: 0px;
z-index: 9999999;
margin-bottom: 0;
width: 400px!important;
}

.chat-ontology .box-body {
max-height: 280px;
overflow-y: scroll;
}

.direct-chat-messages {
height: auto;
}
11 changes: 9 additions & 2 deletions public/js/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,16 @@ function updateSaveButtonInFrontEnd(saved) {
saveOntology.innerHTML = message;
saveOntology.prepend(icon);

if (document.getElementById('id').value > 0) {
socket.emit('updateOntology', document.getElementById('id').value);
if (window.location.origin == ip_address) {
if (document.getElementById('id').value > 0) {
socket.emit('updateOntology', document.getElementById('id').value);
}
}


$('#message').removeAttr("disabled");
$('#send_msg').removeAttr("disabled");

} else {
if (getLanguage() == "pt")
message = "Alterações não salvas. Clique aqui para salvar";
Expand Down
22 changes: 15 additions & 7 deletions public/js/OntologyManager.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
var ontologyName = document.getElementById("ontology-name");

const ip_address = '127.0.0.1';
const ip_address = 'https://onto4alleditor.com/en';
const socket_port = '3000'; // porta node
let socket = io(ip_address + ":" + socket_port);

function saveName(event) {
if (event.key == 'Enter') {
Expand Down Expand Up @@ -82,6 +81,9 @@ document.addEventListener("DOMContentLoaded", function () {

// Select the collaborators on the <select> tag
$('#collaborators-select').val(data['collaborators']).trigger('change');

$('#message').removeAttr("disabled");
$('#send_msg').removeAttr("disabled");

//Allow to click on the IRI input and set route
document.getElementById('ontology-iri').disabled =false;
Expand All @@ -95,6 +97,8 @@ document.addEventListener("DOMContentLoaded", function () {
else
document.getElementById('favorite-ontology').innerHTML = '<i class="fa fa-fw fa-star-o"></i>';
updateSaveButtonInFrontEnd(true);

updateChat(data['id']);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(JSON.stringify(jqXHR));
Expand All @@ -109,11 +113,15 @@ document.addEventListener("DOMContentLoaded", function () {
updateOntology(this.getAttribute('id'));
});

socket.on('updateOntology', (ontologyID) => {
if (ontologyID == document.getElementById('id').value) {
updateOntology(document.getElementById('id').value);
}
});
if (window.location.origin == ip_address) {
let socket = io(ip_address + ":" + socket_port);

socket.on('updateOntology', (ontologyID) => {
if (ontologyID == document.getElementById('id').value) {
updateOntology(document.getElementById('id').value);
}
});
}
});


Expand Down
4 changes: 3 additions & 1 deletion resources/lang/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,8 @@
"The number of datatypeproperties in your current ontology": "O número de propriedades de dado na sua ontologia atual",
"General Information": "Informações Gerais",
"Save the ontology first to see its IRI": "Salve a ontologia primeiro para poder ver o IRI",
"Untitled Ontology": "Ontologia não nomeada"
"Untitled Ontology": "Ontologia não nomeada",
"With this chat it is possible to send this real chat to all the people who send a message in time editing this ontology, in addition, the messages are stored and can be read in the future.": "Com este chat é possível enviar mensagem em tempo real para todas as pessoas que estiverem editando esta ontologia, além disso as mensagens são armazendas e podem ser lidas no futuro.",
"Enter message...": "Digite a mensagem..."
}

Loading