Compare commits
2 Commits
9a59326afa
...
62ced07731
| Author | SHA1 | Date | |
|---|---|---|---|
| 62ced07731 | |||
| 70866b1a53 |
66
www/src/modals/delete-command-modal.jsx
Normal file
66
www/src/modals/delete-command-modal.jsx
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import { createSignal } from "solid-js";
|
||||||
|
import Command from "../data/command.js";
|
||||||
|
import RemotesService from "../services/remotes-service.js";
|
||||||
|
import EventEmitter from "../tools/event-emitter.js";
|
||||||
|
import ModalHandler from "./modal-handler.js";
|
||||||
|
import Modal from "./modal.jsx";
|
||||||
|
|
||||||
|
const [command, setCommand] = createSignal(new Command());
|
||||||
|
const eventEmitter = new EventEmitter();
|
||||||
|
const COMMAND_DELETED_EVENT = "success";
|
||||||
|
|
||||||
|
function DeleteCommandModal(props) {
|
||||||
|
const [error, setError] = createSignal("");
|
||||||
|
|
||||||
|
async function handleDeleteCommand() {
|
||||||
|
try {
|
||||||
|
await RemotesService.deleteCommand(command().getId());
|
||||||
|
} catch (e) {
|
||||||
|
setError(e.message);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
DeleteCommandModal.Handler.hide();
|
||||||
|
eventEmitter.dispatchEvent(COMMAND_DELETED_EVENT, command);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
ref={props.ref}
|
||||||
|
id="deleteCommandModal"
|
||||||
|
modalTitle="Delete command"
|
||||||
|
centered={true}
|
||||||
|
>
|
||||||
|
<div class="modal-body">
|
||||||
|
<Show when={error() !== ""}>
|
||||||
|
<div class="alert alert-danger" role="alert">
|
||||||
|
{error()}
|
||||||
|
</div>
|
||||||
|
</Show>
|
||||||
|
<div class="mb-3 row">
|
||||||
|
<span>
|
||||||
|
Do you really want to delete the command {command().getTitle()} ({command().getId()})?
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleDeleteCommand}
|
||||||
|
class="btn btn-danger"
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
DeleteCommandModal.Handler = new ModalHandler();
|
||||||
|
DeleteCommandModal.setCommand = setCommand;
|
||||||
|
DeleteCommandModal.onCommandDeleted = (callback) =>
|
||||||
|
eventEmitter.on(COMMAND_DELETED_EVENT, callback);
|
||||||
|
|
||||||
|
export default DeleteCommandModal;
|
||||||
@ -7,6 +7,7 @@ import CreateDeviceModal from "./create-device-modal.jsx";
|
|||||||
import ShowRegistrationCodeModal from "./show-registration-code-modal.jsx";
|
import ShowRegistrationCodeModal from "./show-registration-code-modal.jsx";
|
||||||
import DeleteIntegrationModal from "./delete-integration-modal.jsx";
|
import DeleteIntegrationModal from "./delete-integration-modal.jsx";
|
||||||
import CreateCommandModal from "./create-command-modal.jsx";
|
import CreateCommandModal from "./create-command-modal.jsx";
|
||||||
|
import DeleteCommandModal from "./delete-command-modal.jsx";
|
||||||
|
|
||||||
const ModalRegistry = (function () {
|
const ModalRegistry = (function () {
|
||||||
const modals = [
|
const modals = [
|
||||||
@ -45,6 +46,11 @@ const ModalRegistry = (function () {
|
|||||||
component: CreateCommandModal,
|
component: CreateCommandModal,
|
||||||
ref: null,
|
ref: null,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "deleteCommandModal",
|
||||||
|
component: DeleteCommandModal,
|
||||||
|
ref: null,
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
function getModals(props) {
|
function getModals(props) {
|
||||||
|
|||||||
@ -10,17 +10,27 @@ function RemotesService() {
|
|||||||
async function getCommands() {
|
async function getCommands() {
|
||||||
return [].concat(commands);
|
return [].concat(commands);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createCommand(commandObject) {
|
async function createCommand(commandObject) {
|
||||||
let command = Serializer.deserializeCommand(commandObject);
|
let command = Serializer.deserializeCommand(commandObject);
|
||||||
|
let id = Math.random().toString(36).substr(2, 9);
|
||||||
|
command.setId(id);
|
||||||
commands.push(command);
|
commands.push(command);
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function deleteCommand(commandId) {
|
||||||
|
let index = commands.findIndex((command) => command.getId() === commandId);
|
||||||
|
if (index >= 0) {
|
||||||
|
commands.splice(index, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getRemotes,
|
getRemotes,
|
||||||
getCommands,
|
getCommands,
|
||||||
createCommand,
|
createCommand,
|
||||||
|
deleteCommand,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { createSignal, onMount } from "solid-js";
|
import { createSignal, onMount } from "solid-js";
|
||||||
import Spinner from "../modules/spinner";
|
import Spinner from "../components/spinner";
|
||||||
import MainView from "./main-view";
|
import MainView from "./main-view";
|
||||||
import LoginView from "./login-view";
|
import LoginView from "./login-view";
|
||||||
import UserService from "../services/user-service";
|
import UserService from "../services/user-service";
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import {
|
|||||||
Show,
|
Show,
|
||||||
} from "solid-js";
|
} from "solid-js";
|
||||||
|
|
||||||
import List from "../modules/list";
|
import List from "../components/list";
|
||||||
import CreateDeviceModal from "../modals/create-device-modal";
|
import CreateDeviceModal from "../modals/create-device-modal";
|
||||||
import DeviceService from "../services/device-service";
|
import DeviceService from "../services/device-service";
|
||||||
import ShowRegistrationCodeModal from "../modals/show-registration-code-modal";
|
import ShowRegistrationCodeModal from "../modals/show-registration-code-modal";
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { createSignal, mergeProps } from "solid-js";
|
import { createSignal, mergeProps } from "solid-js";
|
||||||
import UserService from "../services/user-service";
|
import UserService from "../services/user-service";
|
||||||
import Spinner from "../modules/spinner";
|
import Spinner from "../components/spinner";
|
||||||
|
|
||||||
const IDLE = "idle";
|
const IDLE = "idle";
|
||||||
const LOGGING_IN = "logging-in";
|
const LOGGING_IN = "logging-in";
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import { createResource, onMount } from "solid-js";
|
import { createResource, onMount } from "solid-js";
|
||||||
import List from "../../modules/list";
|
import List from "../../components/list";
|
||||||
import RemotesService from "../../services/remotes-service";
|
import RemotesService from "../../services/remotes-service";
|
||||||
import CreateCommandModal from "../../modals/create-command-modal";
|
import CreateCommandModal from "../../modals/create-command-modal";
|
||||||
|
import DeleteCommandModal from "../../modals/delete-command-modal";
|
||||||
|
|
||||||
function CommandsList(props) {
|
function CommandsList(props) {
|
||||||
const [commands, { refetch: refetchCommands }] = createResource(
|
const [commands, { refetch: refetchCommands }] = createResource(
|
||||||
@ -13,7 +14,10 @@ function CommandsList(props) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CreateCommandModal.onCommandCreated(() => {
|
CreateCommandModal.onCommandCreated(() => {
|
||||||
console.log("CREATED");
|
refetchCommands();
|
||||||
|
});
|
||||||
|
|
||||||
|
DeleteCommandModal.onCommandDeleted(() => {
|
||||||
refetchCommands();
|
refetchCommands();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -23,6 +27,8 @@ function CommandsList(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleDeleteCommand(command) {
|
function handleDeleteCommand(command) {
|
||||||
|
DeleteCommandModal.setCommand(command);
|
||||||
|
DeleteCommandModal.Handler.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -83,7 +89,7 @@ function CommandsList(props) {
|
|||||||
html: (
|
html: (
|
||||||
<>
|
<>
|
||||||
<button
|
<button
|
||||||
class="btn btn-outline-secondary me-2"
|
class="btn btn-sm btn-outline-secondary me-2"
|
||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
handleDeleteCommand(command);
|
handleDeleteCommand(command);
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { createResource, onMount } from "solid-js";
|
import { createResource, onMount } from "solid-js";
|
||||||
import List from "../../modules/list";
|
import List from "../../components/list";
|
||||||
import RemotesService from "../../services/remotes-service";
|
import RemotesService from "../../services/remotes-service";
|
||||||
|
|
||||||
function RemotesList(props) {
|
function RemotesList(props) {
|
||||||
@ -49,14 +49,14 @@ function RemotesList(props) {
|
|||||||
id: {
|
id: {
|
||||||
html: <span class="font-monospace">{remote.getId()}</span>,
|
html: <span class="font-monospace">{remote.getId()}</span>,
|
||||||
},
|
},
|
||||||
name: {
|
title: {
|
||||||
text: remote.getTitle(),
|
text: remote.getTitle(),
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
html: (
|
html: (
|
||||||
<>
|
<>
|
||||||
<button
|
<button
|
||||||
class="btn btn-outline-secondary me-2"
|
class="btn btn-sm btn-outline-secondary me-2"
|
||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
handleDeleteRemote(remote);
|
handleDeleteRemote(remote);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { Show, createEffect, createResource, createSignal } from "solid-js";
|
import { Show, createEffect, createResource, createSignal } from "solid-js";
|
||||||
import ChangePasswordSettings from "../modules/settings/change-password";
|
import ChangePasswordSettings from "../components/settings/change-password";
|
||||||
import UserList from "../modules/settings/users-list";
|
import UserList from "../components/settings/users-list";
|
||||||
import UserService from "../services/user-service";
|
import UserService from "../services/user-service";
|
||||||
|
|
||||||
function SettingsView(props) {
|
function SettingsView(props) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user