mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
delete messages
This commit is contained in:
parent
69a7705043
commit
1bbfa6f22b
|
@ -43,7 +43,7 @@
|
||||||
<i class="bi bi-download"></i>
|
<i class="bi bi-download"></i>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button disabled class="btn btn-outline-secondary border-0" @click="deleteMessage">
|
<button class="btn btn-outline-secondary border-0" @click="deleteMessage">
|
||||||
<i class="bi bi-trash"></i>
|
<i class="bi bi-trash"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
<i class="bi bi-info-circle"></i>
|
<i class="bi bi-info-circle"></i>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button disabled class="btn btn-outline-secondary border-0" @click="deleteMessage">
|
<button class="btn btn-outline-secondary border-0" @click="deleteMessage">
|
||||||
<i class="bi bi-trash"></i>
|
<i class="bi bi-trash"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -11,14 +11,14 @@ const chat = useChatStore(pinia);
|
||||||
import { settingsStore as settings, onChange } from "../store/settingsStore.js";
|
import { settingsStore as settings, onChange } from "../store/settingsStore.js";
|
||||||
import { sendModemTestFrame } from "../js/api";
|
import { sendModemTestFrame } from "../js/api";
|
||||||
import main_startup_check from "./main_startup_check.vue";
|
import main_startup_check from "./main_startup_check.vue";
|
||||||
import { newMessage } from '../js/messagesHandler.ts'
|
import { newMessage, deleteCallsignFromDB } from '../js/messagesHandler.ts'
|
||||||
|
|
||||||
function newChat(){
|
function newChat(){
|
||||||
newMessage(chat.newChatCallsign, chat.newChatMessage)
|
newMessage(chat.newChatCallsign, chat.newChatMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteChat() {
|
function deleteChat() {
|
||||||
return
|
deleteCallsignFromDB(chat.selectedCallsign);
|
||||||
}
|
}
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -46,6 +46,27 @@ export async function apiPost(endpoint, payload = {}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function apiDelete(endpoint, payload = {}) {
|
||||||
|
try {
|
||||||
|
const response = await fetch(buildURL(settings.local, endpoint), {
|
||||||
|
method: "DELETE",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`REST response not ok: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
return data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error deleting from REST:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function getVersion() {
|
export async function getVersion() {
|
||||||
let data = await apiGet("/version").then((res) => {
|
let data = await apiGet("/version").then((res) => {
|
||||||
return res;
|
return res;
|
||||||
|
@ -55,30 +76,30 @@ export async function getVersion() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getConfig() {
|
export async function getConfig() {
|
||||||
return apiGet("/config");
|
return await apiGet("/config");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setConfig(config) {
|
export async function setConfig(config) {
|
||||||
return apiPost("/config", config);
|
return await apiPost("/config", config);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAudioDevices() {
|
export async function getAudioDevices() {
|
||||||
return apiGet("/devices/audio");
|
return await apiGet("/devices/audio");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSerialDevices() {
|
export async function getSerialDevices() {
|
||||||
return apiGet("/devices/serial");
|
return await apiGet("/devices/serial");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setModemBeacon(enabled = false) {
|
export async function setModemBeacon(enabled = false) {
|
||||||
return apiPost("/modem/beacon", { enabled: enabled });
|
return await apiPost("/modem/beacon", { enabled: enabled });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendModemCQ() {
|
export async function sendModemCQ() {
|
||||||
return apiPost("/modem/cqcqcq");
|
return await apiPost("/modem/cqcqcq");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendModemPing(dxcall) {
|
export async function sendModemPing(dxcall) {
|
||||||
if (
|
if (
|
||||||
validateCallsignWithSSID(dxcall) === false &&
|
validateCallsignWithSSID(dxcall) === false &&
|
||||||
validateCallsignWithoutSSID(dxcall) === true
|
validateCallsignWithoutSSID(dxcall) === true
|
||||||
|
@ -88,11 +109,11 @@ export function sendModemPing(dxcall) {
|
||||||
}
|
}
|
||||||
dxcall = String(dxcall).toUpperCase().trim();
|
dxcall = String(dxcall).toUpperCase().trim();
|
||||||
if (validateCallsignWithSSID(dxcall))
|
if (validateCallsignWithSSID(dxcall))
|
||||||
return apiPost("/modem/ping_ping", { dxcall: dxcall });
|
return await apiPost("/modem/ping_ping", { dxcall: dxcall });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendModemARQRaw(mycall, dxcall, data, uuid) {
|
export async function sendModemARQRaw(mycall, dxcall, data, uuid) {
|
||||||
return apiPost("/modem/send_arq_raw", {
|
return await apiPost("/modem/send_arq_raw", {
|
||||||
mycallsign: mycall,
|
mycallsign: mycall,
|
||||||
dxcall: dxcall,
|
dxcall: dxcall,
|
||||||
data: data,
|
data: data,
|
||||||
|
@ -100,35 +121,35 @@ export function sendModemARQRaw(mycall, dxcall, data, uuid) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stopTransmission() {
|
export async function stopTransmission() {
|
||||||
return apiPost("/modem/stop_transmission");
|
return await apiPost("/modem/stop_transmission");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendModemTestFrame() {
|
export async function sendModemTestFrame() {
|
||||||
return apiPost("/modem/send_test_frame");
|
return await apiPost("/modem/send_test_frame");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function startModem() {
|
export async function startModem() {
|
||||||
return apiPost("/modem/start");
|
return await apiPost("/modem/start");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stopModem() {
|
export async function stopModem() {
|
||||||
return apiPost("/modem/stop");
|
return await apiPost("/modem/stop");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getModemState() {
|
export async function getModemState() {
|
||||||
return apiGet("/modem/state");
|
return await apiGet("/modem/state");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setRadioParameters(frequency, mode, rf_level) {
|
export async function setRadioParameters(frequency, mode, rf_level) {
|
||||||
return apiPost("/radio", {
|
return await apiPost("/radio", {
|
||||||
radio_frequency: frequency,
|
radio_frequency: frequency,
|
||||||
radio_mode: mode,
|
radio_mode: mode,
|
||||||
radio_rf_level: rf_level,
|
radio_rf_level: rf_level,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
export function getRadioStatus() {
|
export async function getRadioStatus() {
|
||||||
return apiGet("/radio");
|
return await apiGet("/radio");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getFreedataMessages(){
|
export async function getFreedataMessages(){
|
||||||
|
@ -141,4 +162,8 @@ export async function sendFreedataMessage(dxcall, body) {
|
||||||
dxcall: dxcall,
|
dxcall: dxcall,
|
||||||
body: body,
|
body: body,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteFreedataMessage(id) {
|
||||||
|
return await apiDelete(`/freedata/messages/${id}`);
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@ setActivePinia(pinia);
|
||||||
import { useChatStore } from "../store/chatStore.js";
|
import { useChatStore } from "../store/chatStore.js";
|
||||||
const chatStore = useChatStore(pinia);
|
const chatStore = useChatStore(pinia);
|
||||||
|
|
||||||
import { sendFreedataMessage } from "./api"
|
import { sendFreedataMessage, deleteFreedataMessage } from "./api"
|
||||||
|
|
||||||
interface Message {
|
interface Message {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -71,8 +71,15 @@ export function repeatMessageTransmission(id){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function deleteCallsignFromDB(callsign){
|
||||||
|
for (var message of chatStore.sorted_chat_list[callsign]) {
|
||||||
|
deleteFreedataMessage(message["id"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
export function deleteMessageFromDB(id){
|
export function deleteMessageFromDB(id){
|
||||||
return
|
deleteFreedataMessage(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function requestMessageInfo(id){
|
export function requestMessageInfo(id){
|
||||||
|
|
|
@ -166,6 +166,7 @@ class DatabaseManager:
|
||||||
session.delete(message)
|
session.delete(message)
|
||||||
session.commit()
|
session.commit()
|
||||||
self.log(f"Deleted: {message_id}")
|
self.log(f"Deleted: {message_id}")
|
||||||
|
self.event_manager.freedata_message_db_change()
|
||||||
return {'status': 'success', 'message': f'Message {message_id} deleted'}
|
return {'status': 'success', 'message': f'Message {message_id} deleted'}
|
||||||
else:
|
else:
|
||||||
return {'status': 'failure', 'message': 'Message not found'}
|
return {'status': 'failure', 'message': 'Message not found'}
|
||||||
|
@ -188,6 +189,7 @@ class DatabaseManager:
|
||||||
message.body = update_data['body']
|
message.body = update_data['body']
|
||||||
session.commit()
|
session.commit()
|
||||||
self.log(f"Updated: {message_id}")
|
self.log(f"Updated: {message_id}")
|
||||||
|
self.event_manager.freedata_message_db_change()
|
||||||
return {'status': 'success', 'message': f'Message {message_id} updated'}
|
return {'status': 'success', 'message': f'Message {message_id} updated'}
|
||||||
else:
|
else:
|
||||||
return {'status': 'failure', 'message': 'Message not found'}
|
return {'status': 'failure', 'message': 'Message not found'}
|
||||||
|
|
Loading…
Reference in a new issue