Upload files to "/"
This commit is contained in:
commit
afc6814985
BIN
SQLiteToProlog.class
Normal file
BIN
SQLiteToProlog.class
Normal file
Binary file not shown.
12
prolog.pl
Normal file
12
prolog.pl
Normal file
@ -0,0 +1,12 @@
|
||||
has_duplicates(List) :-
|
||||
member(X, List),
|
||||
select(X, List, Rest),
|
||||
member(X, Rest), !.
|
||||
collect_todos(Ys) :-
|
||||
findall(Y, todo(_, Y), Ys).
|
||||
todos_have_duplicates :-
|
||||
collect_todos(Ys),
|
||||
has_duplicates(Ys).
|
||||
todo(24, 'koko').
|
||||
todo(25, 'xasda').
|
||||
todo(26, 'dsadsa').
|
8
readme.txt
Normal file
8
readme.txt
Normal file
@ -0,0 +1,8 @@
|
||||
sudo apt update
|
||||
sudo apt install nodejs npm
|
||||
cd ~/projParadyg
|
||||
npm install express
|
||||
node server.js
|
||||
|
||||
javac -cp ".:lib/sqlite-jdbc-3.45.3.0.jar:lib/slf4j-api-2.1.0-alpha1.jar" -encoding UTF-8 SQLiteToProlog.java
|
||||
java -cp ".:lib/sqlite-jdbc-3.45.3.0.jar:lib/slf4j-api-2.1.0-alpha1.jar" SQLiteToProlog
|
70
script.js
Normal file
70
script.js
Normal file
@ -0,0 +1,70 @@
|
||||
$(document).ready(function(){
|
||||
const apiUrl = 'http://localhost:3000';
|
||||
|
||||
// funkcja która dodaje zadania do listy
|
||||
const appendTaskToList = (task) => {
|
||||
$("#todoList").append("<li data-id='" + task.id + "'>" + task.task + " <button class='rmBtn'>Remove task</button></li>");
|
||||
};
|
||||
|
||||
// funkcja która zwraca błąd gdy nie można dodać zadania
|
||||
const handleAjaxError = (message) => () => alert(message);
|
||||
|
||||
// pobieranie zdań
|
||||
const fetchTasks = () => {
|
||||
$.ajax({
|
||||
url: `${apiUrl}/tasks`,
|
||||
method: 'GET',
|
||||
success: function(tasks) {
|
||||
tasks.forEach(appendTaskToList);
|
||||
},
|
||||
error: handleAjaxError("Error fetching tasks")
|
||||
});
|
||||
};
|
||||
|
||||
// funkcja która dodaje zadanie
|
||||
const addTask = (task) => {
|
||||
if (task !== "") {
|
||||
$.ajax({
|
||||
url: `${apiUrl}/addTask`,
|
||||
method: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({ task: task }),
|
||||
success: function(response) {
|
||||
appendTaskToList(response);
|
||||
$("#todoInput").val("");
|
||||
},
|
||||
error: handleAjaxError("Error adding task")
|
||||
});
|
||||
} else {
|
||||
alert("Enter task");
|
||||
}
|
||||
};
|
||||
|
||||
// funkcja która usuwa zadanie
|
||||
const deleteTask = (taskId, listItem) => {
|
||||
$.ajax({
|
||||
url: `${apiUrl}/deleteTask/${taskId}`,
|
||||
method: 'DELETE',
|
||||
success: function(response) {
|
||||
listItem.remove();
|
||||
},
|
||||
error: handleAjaxError("Error deleting task")
|
||||
});
|
||||
};
|
||||
|
||||
// pobieranie i wyświetlanie zadań
|
||||
fetchTasks();
|
||||
|
||||
// dodawanie nowego zadania
|
||||
$("#addBtn").click(function(){
|
||||
const task = $("#todoInput").val();
|
||||
addTask(task);
|
||||
});
|
||||
|
||||
// usuwanie zadania
|
||||
$(document).on("click", ".rmBtn", function(){
|
||||
const listItem = $(this).parent();
|
||||
const taskId = listItem.data('id');
|
||||
deleteTask(taskId, listItem);
|
||||
});
|
||||
});
|
65
server.js
Normal file
65
server.js
Normal file
@ -0,0 +1,65 @@
|
||||
const express = require('express');
|
||||
const bodyParser = require('body-parser');
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
// Ustawienia bodyParser do obsługi danych w formacie JSON
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
|
||||
// Połączenie z bazą danych SQLite
|
||||
const db = new sqlite3.Database('tasks.db');
|
||||
|
||||
// tworzenie tabeli tasks, jeśli jeszcze nie istnieje
|
||||
db.serialize(() => {
|
||||
db.run("CREATE TABLE IF NOT EXISTS tasks (id INTEGER PRIMARY KEY AUTOINCREMENT, task TEXT)");
|
||||
});
|
||||
|
||||
// Obsługa CORS, czyli ograniczenie żądań stron internetowych z innej domeny
|
||||
app.use((req, res, next) => {
|
||||
res.header('Access-Control-Allow-Origin', '*');
|
||||
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
|
||||
res.header('Access-Control-Allow-Methods', 'GET, POST, DELETE, OPTIONS');
|
||||
next();
|
||||
});
|
||||
|
||||
// Dodawanie zadania
|
||||
app.post('/addTask', (req, res) => {
|
||||
const task = req.body.task;
|
||||
if (task) {
|
||||
db.run("INSERT INTO tasks (task) VALUES (?)", task, function(err) {
|
||||
if (err) {
|
||||
return res.status(500).json({ error: err.message });
|
||||
}
|
||||
res.json({ id: this.lastID, task: task });
|
||||
});
|
||||
} else {
|
||||
res.status(400).json({ error: "No task provided" });
|
||||
}
|
||||
});
|
||||
|
||||
// Usuwanie zadania
|
||||
app.delete('/deleteTask/:id', (req, res) => {
|
||||
const id = req.params.id;
|
||||
db.run("DELETE FROM tasks WHERE id = ?", id, function(err) {
|
||||
if (err) {
|
||||
return res.status(500).json({ error: err.message });
|
||||
}
|
||||
res.json({ success: true });
|
||||
});
|
||||
});
|
||||
|
||||
// Pobieranie wszystkich zadań
|
||||
app.get('/tasks', (req, res) => {
|
||||
db.all("SELECT * FROM tasks", [], (err, rows) => {
|
||||
if (err) {
|
||||
return res.status(500).json({ error: err.message });
|
||||
}
|
||||
res.json(rows);
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Server running at http://localhost:${port}/`);
|
||||
});
|
Loading…
Reference in New Issue
Block a user