add nave list type
This commit is contained in:
parent
40cdd962ce
commit
59c35e13ea
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
|||||||
{"default":{"identifier":"default","description":"Capability for the main window","local":true,"windows":["main"],"permissions":["core:default","opener:default","shell:allow-open","sql:default","sql:allow-load","sql:allow-execute"]}}
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -2,5 +2,5 @@
|
|||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
sooome_lib::run()
|
wdb_lib::run()
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
{
|
{
|
||||||
"title": "wdb",
|
"title": "wdb",
|
||||||
"width": 800,
|
"width": 800,
|
||||||
"height": 600
|
"height": 600,
|
||||||
|
"decorations": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"security": {
|
"security": {
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
<script>
|
<script>
|
||||||
export let name = "";
|
export let name = "";
|
||||||
|
export let is_vertical = false;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="w-auto flex justify-start items-center my-1">
|
<div
|
||||||
|
class="w-auto my-1
|
||||||
|
{is_vertical ? 'flex-col items-start' : 'items-center'}
|
||||||
|
flex justify-start"
|
||||||
|
>
|
||||||
<h1>{name}</h1>
|
<h1>{name}</h1>
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
|
47
src/lib/components/form/ItemList.svelte
Normal file
47
src/lib/components/form/ItemList.svelte
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<script>
|
||||||
|
import Select from "./Select.svelte";
|
||||||
|
import Button from "../ui/Button.svelte";
|
||||||
|
import x from "$lib/components/ui/x.svg";
|
||||||
|
|
||||||
|
/** @type {Array<number>} */
|
||||||
|
export let value = [];
|
||||||
|
|
||||||
|
export let on_change = () => {};
|
||||||
|
|
||||||
|
export let item_list_query;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#each value as _, item_index}
|
||||||
|
<div class="w-full mb-2 space-x-2 flex justify-center items-center">
|
||||||
|
<Select
|
||||||
|
bind:value={value[item_index]}
|
||||||
|
query={item_list_query}
|
||||||
|
{on_change}
|
||||||
|
let:vtype
|
||||||
|
>
|
||||||
|
{vtype.name}
|
||||||
|
{vtype.id}
|
||||||
|
</Select>
|
||||||
|
<Button
|
||||||
|
type={"second"}
|
||||||
|
class_name={"bg-red-500 my-0"}
|
||||||
|
on_click={async () => {
|
||||||
|
value.splice(item_index, 1);
|
||||||
|
value = value;
|
||||||
|
await on_change();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<img src={x} class="w-[30px] invert" alt="x close img" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
|
||||||
|
<Button
|
||||||
|
on_click={async () => {
|
||||||
|
value.push(1);
|
||||||
|
value = value;
|
||||||
|
await on_change();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
+ Добавить
|
||||||
|
</Button>
|
@ -3,13 +3,16 @@
|
|||||||
|
|
||||||
export let query;
|
export let query;
|
||||||
export let is_required = true;
|
export let is_required = true;
|
||||||
|
|
||||||
|
export let on_change = () => {};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if is_required}
|
{#if is_required}
|
||||||
<select
|
<select
|
||||||
required
|
required
|
||||||
bind:value
|
bind:value
|
||||||
class="w-full p-2 mx-2
|
on:change={on_change}
|
||||||
|
class="w-full h-min p-2
|
||||||
border-2 border-black dark:border-none
|
border-2 border-black dark:border-none
|
||||||
bg-white dark:bg-black
|
bg-white dark:bg-black
|
||||||
text-black dark:text-white
|
text-black dark:text-white
|
||||||
|
@ -48,16 +48,17 @@
|
|||||||
/**
|
/**
|
||||||
* @param {string} table_name
|
* @param {string} table_name
|
||||||
* @param {Array<string>} columns
|
* @param {Array<string>} columns
|
||||||
|
* @param {string | null} ex
|
||||||
*/
|
*/
|
||||||
async function sql_insert_short(table_name, columns) {
|
async function sql_insert_short(table_name, columns, ex) {
|
||||||
let q = `insert into ${table_name} (${columns.join(", ")}) values (${columns
|
let q = `insert into ${table_name} (${columns.join(", ")}) values (${columns
|
||||||
.map((el) => format_type_insert(current_item[el]))
|
.map((el) => format_type_insert(current_item[el]))
|
||||||
.filter((el) => el !== null)
|
.filter((el) => el !== null)
|
||||||
.join(", ")})`;
|
.join(", ")}) ${ex ? ex : ""}`;
|
||||||
console.log(current_item, q);
|
const res = await db.execute(q);
|
||||||
await db.execute(q);
|
|
||||||
is_item_dialog_open = false;
|
is_item_dialog_open = false;
|
||||||
toggle_update();
|
toggle_update();
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@param {string} name
|
@param {string} name
|
||||||
@ -163,16 +164,14 @@ WHERE id = ${current_item.id}`;
|
|||||||
bind:current_view
|
bind:current_view
|
||||||
bind:is_view_open
|
bind:is_view_open
|
||||||
db_scheme={db_scheme[current_page]}
|
db_scheme={db_scheme[current_page]}
|
||||||
check_access={(name) =>
|
check_access={(name) => check_access(access_level, current_page, name)}
|
||||||
check_access(access_level, current_page, name)}
|
|
||||||
></SideMenu>
|
></SideMenu>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="w-full pr-4 overflow-y-auto rounded-tl-xl
|
class="w-full pr-4 overflow-y-auto rounded-tl-xl
|
||||||
bg-[var(--w-bg-second)] dark:bg-[#111]"
|
bg-[var(--w-bg-second)] dark:bg-[#111]"
|
||||||
>
|
>
|
||||||
<LoginForm bind:is_logedin bind:access_level {check_login}
|
<LoginForm bind:is_logedin bind:access_level {check_login}></LoginForm>
|
||||||
></LoginForm>
|
|
||||||
{#if is_loaded && is_logedin}
|
{#if is_loaded && is_logedin}
|
||||||
<slot
|
<slot
|
||||||
{current_page}
|
{current_page}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
import Field from "$lib/components/form/Field.svelte";
|
import Field from "$lib/components/form/Field.svelte";
|
||||||
import TextInput from "$lib/components/form/TextInput.svelte";
|
import TextInput from "$lib/components/form/TextInput.svelte";
|
||||||
import NumberInput from "$lib/components/form/NumberInput.svelte";
|
import NumberInput from "$lib/components/form/NumberInput.svelte";
|
||||||
|
import ItemList from "$lib/components/form/ItemList.svelte";
|
||||||
// import DateInput from "$lib/components/form/DateInput.svelte";
|
// import DateInput from "$lib/components/form/DateInput.svelte";
|
||||||
import PhoneInput from "$lib/components/form/PhoneInput.svelte";
|
import PhoneInput from "$lib/components/form/PhoneInput.svelte";
|
||||||
import Select from "$lib/components/form/Select.svelte";
|
import Select from "$lib/components/form/Select.svelte";
|
||||||
@ -76,6 +77,24 @@ initial_date DATE DEFAULT CURRENT_TIMESTAMP, -- not editable by user
|
|||||||
description TEXT,
|
description TEXT,
|
||||||
duration FLOAT NULL -- hours
|
duration FLOAT NULL -- hours
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS Ingredients (id INTEGER PRIMARY KEY, name VARCHAR(256), price INTEGER);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS Pizzas (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
name VARCHAR(256),
|
||||||
|
price INTEGER
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS PizzasIngredientsJoin (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
pizza_id INTEGER REFERENCES Pizzas(id) ON DELETE CASCADE,
|
||||||
|
ingredient_id INTEGER REFERENCES Ingredients(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS IdBuffer;
|
||||||
|
CREATE TABLE IF NOT EXISTS IdBuffer (id INTEGER);
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,6 +108,9 @@ duration FLOAT NULL -- hours
|
|||||||
Запросы: {
|
Запросы: {
|
||||||
/** @type {any} */
|
/** @type {any} */
|
||||||
tables: {
|
tables: {
|
||||||
|
Ingredients: "Ингридиенты",
|
||||||
|
Pizzas: "Пиццы",
|
||||||
|
PizzasIngredientsJoin: "test",
|
||||||
Requests: "Запросы",
|
Requests: "Запросы",
|
||||||
Clients: "Клиенты",
|
Clients: "Клиенты",
|
||||||
},
|
},
|
||||||
@ -181,6 +203,14 @@ WHERE Accounts.login = "${login}" AND Accounts.password = "${passowrd}";`);
|
|||||||
return [true, access_type[0].name];
|
return [true, access_type[0].name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@param {Array<number>} ar
|
||||||
|
*/
|
||||||
|
async function id_buffer(ar) {
|
||||||
|
await db.execute(`delete from IdBuffer;
|
||||||
|
insert into IdBuffer (id) values (${ar.join("), (")});`);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ScreenWrap
|
<ScreenWrap
|
||||||
@ -205,7 +235,247 @@ WHERE Accounts.login = "${login}" AND Accounts.password = "${passowrd}";`);
|
|||||||
let:sql_delete_short
|
let:sql_delete_short
|
||||||
>
|
>
|
||||||
{#if !is_view_open && current_page === "Запросы"}
|
{#if !is_view_open && current_page === "Запросы"}
|
||||||
{#if current_table === "Clients"}
|
<!-- CREATE TABLE IF NOT EXISTS PizzasIngredientsJoin ( -->
|
||||||
|
<!-- id INTEGER PRIMARY KEY, -->
|
||||||
|
<!-- pizza_id INTEGER REFERENCES Pizzas(id) ON DELETE CASCADE -->
|
||||||
|
<!-- ingredient_id INTEGER REFERENCES Ingredients(id) ON DELETE CASCADE -->
|
||||||
|
<!-- ); -->
|
||||||
|
<!-- CREATE TABLE IF NOT EXISTS Pizzas ( -->
|
||||||
|
<!-- id INTEGER PRIMARY KEY, -->
|
||||||
|
<!-- name VARCHAR(256), -->
|
||||||
|
<!-- price INTEGER -->
|
||||||
|
<!-- ); -->
|
||||||
|
{#if current_table === "Pizzas"}
|
||||||
|
{@const cur_cols = ["name", "price"]}
|
||||||
|
<Dialog
|
||||||
|
bind:is_open={is_item_dialog_open}
|
||||||
|
name={cur_dialog_name}
|
||||||
|
let:form
|
||||||
|
>
|
||||||
|
{#if !is_dialog_item_add}
|
||||||
|
<h1>id {current_item.id}</h1>
|
||||||
|
{/if}
|
||||||
|
<Field name={"название"}>
|
||||||
|
<TextInput bind:value={current_item.name}></TextInput>
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
<Field name={"Ингридиенты"} is_vertical={true}>
|
||||||
|
<ItemList
|
||||||
|
bind:value={current_item.ingredients_ids}
|
||||||
|
item_list_query={db.select("select id, name from Ingredients")}
|
||||||
|
on_change={async () => {
|
||||||
|
await id_buffer(current_item.ingredients_ids);
|
||||||
|
const query = `
|
||||||
|
select sum(price) as value
|
||||||
|
from Ingredients
|
||||||
|
join IdBuffer on IdBuffer.id = Ingredients.id
|
||||||
|
`;
|
||||||
|
const price = await db.select(query);
|
||||||
|
current_item.price = price[0].value;
|
||||||
|
}}
|
||||||
|
></ItemList>
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
<Field name={"цена"}>
|
||||||
|
<NumberInput bind:value={current_item.price}></NumberInput>
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
<TableCudButtons
|
||||||
|
{form}
|
||||||
|
bind:is_dialog_item_add
|
||||||
|
on_add={async () => {
|
||||||
|
const las_id = await sql_insert_short(
|
||||||
|
current_table,
|
||||||
|
cur_cols,
|
||||||
|
"returning id",
|
||||||
|
);
|
||||||
|
console.log(las_id.lastInsertId);
|
||||||
|
|
||||||
|
const query = `insert into PizzasIngredientsJoin (pizza_id, ingredient_id) values
|
||||||
|
${current_item.ingredients_ids.map((el) => "(" + las_id.lastInsertId + "," + el + ")").join(",")}
|
||||||
|
`;
|
||||||
|
console.log(query);
|
||||||
|
await db.execute(query);
|
||||||
|
}}
|
||||||
|
on_save={async () => {
|
||||||
|
const query = `
|
||||||
|
delete from PizzasIngredientsJoin where pizza_id = ${current_item.id};
|
||||||
|
insert into PizzasIngredientsJoin (pizza_id, ingredient_id) values
|
||||||
|
${current_item.ingredients_ids.map((el) => "(" + current_item.id + "," + el + ")").join(",")}
|
||||||
|
`;
|
||||||
|
await db.execute(query);
|
||||||
|
await sql_update_short(current_table, cur_cols);
|
||||||
|
}}
|
||||||
|
on_delete={sql_delete_short}
|
||||||
|
></TableCudButtons>
|
||||||
|
</Dialog>
|
||||||
|
<TableButtonsWrap
|
||||||
|
{current_table}
|
||||||
|
{current_item}
|
||||||
|
{toggle_add_dialog}
|
||||||
|
on_add_click={() => {
|
||||||
|
current_item = {
|
||||||
|
id: 0,
|
||||||
|
name: "",
|
||||||
|
price: 0,
|
||||||
|
ingredients_ids: [],
|
||||||
|
};
|
||||||
|
}}
|
||||||
|
columns={cur_cols}
|
||||||
|
let:is_searching
|
||||||
|
let:search_query_result
|
||||||
|
>
|
||||||
|
<Table
|
||||||
|
{is_searching}
|
||||||
|
search_query={db.select(search_query_result)}
|
||||||
|
columns={["id", ...cur_cols]}
|
||||||
|
query={db.select(`select * from ${current_table}`)}
|
||||||
|
let:item
|
||||||
|
let:index
|
||||||
|
>
|
||||||
|
<Tr
|
||||||
|
{index}
|
||||||
|
on_click={async () => {
|
||||||
|
const ingredients_ids = await db.select(
|
||||||
|
`select ingredient_id from PizzasIngredientsJoin where pizza_id = ${item.id}`,
|
||||||
|
);
|
||||||
|
open_item_edit(item);
|
||||||
|
current_item.ingredients_ids = ingredients_ids.map(
|
||||||
|
(/** @type {any} */ el) => el.ingredient_id,
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Atd {item} names={["id", ...cur_cols]}></Atd>
|
||||||
|
</Tr>
|
||||||
|
</Table>
|
||||||
|
</TableButtonsWrap>
|
||||||
|
{:else if current_table === "PizzasIngredientsJoin"}
|
||||||
|
{@const cur_cols = ["pizza_id", "ingredient_id"]}
|
||||||
|
<Dialog
|
||||||
|
bind:is_open={is_item_dialog_open}
|
||||||
|
name={cur_dialog_name}
|
||||||
|
let:form
|
||||||
|
>
|
||||||
|
{#if !is_dialog_item_add}
|
||||||
|
<h1>id {current_item.id}</h1>
|
||||||
|
{/if}
|
||||||
|
<Field name={"питса"}>
|
||||||
|
<Select
|
||||||
|
bind:value={current_item.pizza_id}
|
||||||
|
query={db.select("select id, name from Pizzas")}
|
||||||
|
let:vtype
|
||||||
|
>
|
||||||
|
{vtype.name}
|
||||||
|
{vtype.id}
|
||||||
|
</Select>
|
||||||
|
</Field>
|
||||||
|
<Field name={"ингридиент"}>
|
||||||
|
<Select
|
||||||
|
bind:value={current_item.ingredient_id}
|
||||||
|
query={db.select("select id, name from Ingredients")}
|
||||||
|
let:vtype
|
||||||
|
>
|
||||||
|
{vtype.name}
|
||||||
|
{vtype.id}
|
||||||
|
</Select>
|
||||||
|
</Field>
|
||||||
|
<TableCudButtons
|
||||||
|
{form}
|
||||||
|
bind:is_dialog_item_add
|
||||||
|
on_add={async () => {
|
||||||
|
await sql_insert_short(current_table, cur_cols);
|
||||||
|
}}
|
||||||
|
on_save={async () => {
|
||||||
|
await sql_update_short(current_table, cur_cols);
|
||||||
|
}}
|
||||||
|
on_delete={sql_delete_short}
|
||||||
|
></TableCudButtons>
|
||||||
|
</Dialog>
|
||||||
|
<TableButtonsWrap
|
||||||
|
{current_table}
|
||||||
|
{current_item}
|
||||||
|
{toggle_add_dialog}
|
||||||
|
on_add_click={() => {
|
||||||
|
current_item = {
|
||||||
|
id: 0,
|
||||||
|
pizza_id: null,
|
||||||
|
ingredient_id: null,
|
||||||
|
};
|
||||||
|
}}
|
||||||
|
columns={cur_cols}
|
||||||
|
let:is_searching
|
||||||
|
let:search_query_result
|
||||||
|
>
|
||||||
|
<Table
|
||||||
|
{is_searching}
|
||||||
|
search_query={db.select(search_query_result)}
|
||||||
|
columns={["id", "питса", "ингридиент"]}
|
||||||
|
query={db.select(`select * from ${current_table}`)}
|
||||||
|
let:item
|
||||||
|
let:index
|
||||||
|
>
|
||||||
|
<Tr {index} on_click={() => open_item_edit(item)}>
|
||||||
|
<Atd {item} names={["id", ...cur_cols]}></Atd>
|
||||||
|
</Tr>
|
||||||
|
</Table>
|
||||||
|
</TableButtonsWrap>
|
||||||
|
{:else if current_table === "Ingredients"}
|
||||||
|
{@const cur_cols = ["name", "price"]}
|
||||||
|
<Dialog
|
||||||
|
bind:is_open={is_item_dialog_open}
|
||||||
|
name={cur_dialog_name}
|
||||||
|
let:form
|
||||||
|
>
|
||||||
|
{#if !is_dialog_item_add}
|
||||||
|
<h1>id {current_item.id}</h1>
|
||||||
|
{/if}
|
||||||
|
<Field name={"название"}>
|
||||||
|
<TextInput bind:value={current_item.name}></TextInput>
|
||||||
|
</Field>
|
||||||
|
<Field name={"цена"}>
|
||||||
|
<NumberInput bind:value={current_item.price}></NumberInput>
|
||||||
|
</Field>
|
||||||
|
<TableCudButtons
|
||||||
|
{form}
|
||||||
|
bind:is_dialog_item_add
|
||||||
|
on_add={async () => {
|
||||||
|
await sql_insert_short(current_table, cur_cols);
|
||||||
|
}}
|
||||||
|
on_save={async () => {
|
||||||
|
await sql_update_short(current_table, cur_cols);
|
||||||
|
}}
|
||||||
|
on_delete={sql_delete_short}
|
||||||
|
></TableCudButtons>
|
||||||
|
</Dialog>
|
||||||
|
<TableButtonsWrap
|
||||||
|
{current_table}
|
||||||
|
{current_item}
|
||||||
|
{toggle_add_dialog}
|
||||||
|
on_add_click={() => {
|
||||||
|
current_item = {
|
||||||
|
id: 0,
|
||||||
|
name: "",
|
||||||
|
price: 0,
|
||||||
|
};
|
||||||
|
}}
|
||||||
|
columns={cur_cols}
|
||||||
|
let:is_searching
|
||||||
|
let:search_query_result
|
||||||
|
>
|
||||||
|
<Table
|
||||||
|
{is_searching}
|
||||||
|
search_query={db.select(search_query_result)}
|
||||||
|
columns={["id", ...cur_cols]}
|
||||||
|
query={db.select(`select * from ${current_table}`)}
|
||||||
|
let:item
|
||||||
|
let:index
|
||||||
|
>
|
||||||
|
<Tr {index} on_click={() => open_item_edit(item)}>
|
||||||
|
<Atd {item} names={["id", ...cur_cols]}></Atd>
|
||||||
|
</Tr>
|
||||||
|
</Table>
|
||||||
|
</TableButtonsWrap>
|
||||||
|
{:else if current_table === "Clients"}
|
||||||
<Dialog
|
<Dialog
|
||||||
bind:is_open={is_item_dialog_open}
|
bind:is_open={is_item_dialog_open}
|
||||||
name={cur_dialog_name}
|
name={cur_dialog_name}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user