Fixed a bug when moving items to top of a list, and other small fixes

master
Eirik Th S 2021-08-12 00:24:51 +02:00
parent f5581d2490
commit ae840610d8
6 changed files with 206 additions and 24 deletions

View File

@ -98,6 +98,9 @@ body.dollars span.price::before {
body.dollars span.price::after {
content: '';
}
span.recipeItemAmount::after {
content: 'x';
}
.subtotal {
font-weight: bold;

View File

@ -90,7 +90,11 @@ if(!empty($data) && isset($user_id)){
returns("Missing a value: $temp", 1);
}
if( ($itemID = addItem($data['storeID'], $data['name'], $data['price'])) !== false ){
if(!isset($data['amount'])){
$data['amount'] = 1;
}
if( ($itemID = addItem($data['storeID'], $data['name'], $data['price'], $data['amount'])) !== false ){
returns($itemID);
}
else {
@ -370,13 +374,13 @@ function deleteStore($storeID, $storeName, $itemsLength){
return false;
}
function addItem($storeID, $name, $price){
function addItem($storeID, $name, $price, $amount){
global $db, $spaceID;
$verifyUserOwnershipSQL = "SELECT plan_store_id FROM plan_store WHERE `space_id` = '$spaceID' AND plan_store_id = '$storeID'";
$insertItemSQL = "INSERT INTO plan_store_item (`plan_store_id`, `pos`, `name`, `price`)
SELECT ($verifyUserOwnershipSQL), count(0)+1, '$name', $price FROM plan_store_item WHERE plan_store_id = '$storeID';";
$insertItemSQL = "INSERT INTO plan_store_item (`plan_store_id`, `pos`, `name`, `price`, `amount`)
SELECT ($verifyUserOwnershipSQL), count(0)+1, '$name', $price, $amount FROM plan_store_item WHERE plan_store_id = '$storeID';";
if($db->query($insertItemSQL)){
return $db->insert_id;
@ -418,7 +422,7 @@ function moveItem($storeID, $itemID, $afterID){
if($sameStoreCheck = $db->query($sameStoreCheckSQL)){
$stores = $sameStoreCheck->fetch_array();
if($stores[0] != $stores[1]){
if(isset($stores[1]) && $stores[0] != $stores[1]){
// DIFFERENT STORES
$storeID = $stores[1];
$differentStoreAddSQL = ", plan_store_id = $storeID";

View File

@ -28,15 +28,55 @@
<div id='totalPriceWrapper'>Space subtotal: <span id="totalPrice" class="priceWrapper price">00.00</span></div>
<br>
<button id="addStore">Add store</button><br><br>
<button id="refreshAll">Refresh all</button>
<button class="btn btn-primary mb-2" id="addStore">Add store</button><br>
<button class="btn btn-secondary" id="refreshAll">Refresh all</button>
</div>
<script src='plan.js'></script>
<script src='recipe.js'></script>
<script src='draggingClass.js'></script>
</div>
<?php include $rPath.'webdata/footer.html'; ?>
</div>
<div class="modal" tabindex="-1" id="addStoreModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Add store</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body align-content-center">
<button class="btn btn-primary" id="addEmptyStore">Empty store</button>
<hr>
<div class="accordion mb-2" id="addStoreRecipe"></div>
</div>
</div>
</div>
</div>
<script>
let addStoreModal = new bootstrap.Modal( document.getElementById('addStoreModal') );
$("#addStore").on('click', ev=>{
ev.stopPropagation();
addStoreModal.show();
});
$("#addStoreModal").on('show.bs.modal', ev=> {
$("#addStoreRecipe").html('');
$.getJSON('/api/v1/recipe', {}, resp => {
let recipes = new Recipe(resp);
recipes.getAccordionHtml('#addStoreRecipe');
});
});
$("#addEmptyStore").click(ev => {
stores.push(new Store());
addStoreModal.hide();
});
</script>
</body>
</html>

View File

@ -27,7 +27,7 @@ class Store {
html += " <div class='card-body'>";
html += " <ul class='list-group list-group-flush storeItems dragHolder'>";
html += " <li class='list-group-item emptyList'>No items added</li>";
html += " <li class='list-group-item draggable' style='height: 10px; width: 100%;'></li>";
html += " <li class='list-group-item draggable' data-itemid='0' data-storeid='"+this.storeID+"' style='height: 10px; width: 100%;'></li>";
html += " </ul>";
html += " <span class='addItemFormWrapper'>";
@ -203,19 +203,20 @@ class Store {
}
}
addItem(text, price){
addItem(text, price, amount){
amount = amount || 1;
if(text.length > 0){
if(this.storeID === null){
this.getStoreID().done(json => { this.addItem(text, price); });
this.getStoreID().done(json => { this.addItem(text, price, amount); });
return $.ajax();
}
let that = this;
return ajaxReq({ plan: 'addItem', storeID: this.storeID, name: text, price: price })
return ajaxReq({ plan: 'addItem', storeID: this.storeID, name: text, price: price, amount: amount })
.done(json => {
return that.addItemHtml(text, price, json['data']);
return that.addItemHtml(text, price, json['data'], amount);
});
}
@ -233,6 +234,7 @@ class Store {
let html = "\n";
html += "<li class='list-group-item draggable"+(checked?' checkedItem':'')+"' id='item_"+itemID+"' data-itemid='"+itemID+"' style='height: 100%; min-width: 200px;'>"; // draggable='true'
// html += " <span style='float: left; margin-right: 0px; width: 32px; margin-left: -22px;'><svg xmlns='http://www.w3.org/2000/svg' fill='gray' class='bi bi-grip-vertical' viewBox='0 0 16 16' height='32' width='32'> <path d='M7 2a1 1 0 1 1-2 0 1 1 0 0 1 2 0zm3 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0zM7 5a1 1 0 1 1-2 0 1 1 0 0 1 2 0zm3 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0zM7 8a1 1 0 1 1-2 0 1 1 0 0 1 2 0zm3 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0zm-3 3a1 1 0 1 1-2 0 1 1 0 0 1 2 0zm3 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0zm-3 3a1 1 0 1 1-2 0 1 1 0 0 1 2 0zm3 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0z'></path></svg></span>";
html += " <span style='float: left; display: none; margin-right: 5px;' class='checkItems'><input type='checkbox'"+(checked?" checked":"")+"></span>";
html += " <span style='float: left;'>"+text+"</span>";
@ -524,13 +526,10 @@ class Store {
var stores = [];
$("#stores").html("");
$("#addStore").click(ev => {
stores.push(new Store());
});
$("#refreshAll").on('click', ev => {
$("#stores").css('height', $("#stores").height());
$(".tooltip").remove();
$(".elemHolder").remove();
getStores(spaceID).done(json => { $("#stores").css('height', ''); });
});

View File

@ -12,6 +12,15 @@ if(!isset($config) || empty($config)){
$projectRoot = $config["general"]["projectRoot"];
function getConfig($val, $group = "general"){
global $config;
if(isset($config[$group][ $val ])){
return $config[$group][$val];
}
return false;
}
function database(){
global $config;

View File

@ -1,5 +1,15 @@
<?php
$err = array();
$msg = array();
$missingConfig = false;
if($_SERVER['HTTP_HOST'] != "localhost"){
$err[] = "You need to use this page from localhost";
$fatalErr = true;
}
// CREATE USER IN DATABASE
@ -16,18 +26,15 @@ $sql = "CREATE OR REPLACE TABLE `user` (
`ctime` VARCHAR(220)
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
INSERT INTO `user` (full_name, user_email, user_level, pwd)
VALUES ('Admin', 'admin@svagard.no', 5, '-');
CREATE OR REPLACE TABLE plan_space (
CREATE OR REPLACE TABLE `plan_space` (
`space_id` INT auto_increment PRIMARY KEY,
`space_name` tinytext,
`owner_id` BIGINT(20),
CONSTRAINT plan_space_owner_FK FOREIGN KEY (`owner_id`) REFERENCES `user`(`user_id`)
);
CREATE OR REPLACE TABLE plan_space_member (
CREATE OR REPLACE TABLE `plan_space_member` (
`space_id` INT auto_increment NOT NULL,
`member_id` BIGINT(20) NOT NULL,
`timestamp` DATETIME default current_timestamp() NOT NULL,
@ -36,7 +43,7 @@ CREATE OR REPLACE TABLE plan_space_member (
CONSTRAINT space_member_space_FK FOREIGN KEY (`space_id`) REFERENCES `plan_space`(`space_id`)
);
CREATE OR REPLACE TABLE plan_store (
CREATE OR REPLACE TABLE `plan_store` (
`plan_store_id` INT auto_increment,
`space_id` INT NOT NULL,
`name` varchar(100) NOT NULL,
@ -46,7 +53,7 @@ CREATE OR REPLACE TABLE plan_store (
CONSTRAINT plan_store_user_FK FOREIGN KEY (`space_id`) REFERENCES `plan_space`(`space_id`)
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
CREATE OR REPLACE TABLE plan_store_item (
CREATE OR REPLACE TABLE `plan_store_item` (
`plan_item_id` INT auto_increment NOT NULL,
`plan_store_id` INT NOT NULL,
`pos` tinyint(3) unsigned,
@ -58,6 +65,126 @@ CREATE OR REPLACE TABLE plan_store_item (
CONSTRAINT plan_store_item_FK FOREIGN KEY (plan_store_id) REFERENCES `plan_store`(`plan_store_id`)
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
";
$recipeSQL = "
DROP TABLE `recipe_item`;
CREATE OR REPLACE TABLE `recipe` (
`recipe_id` INT AUTO_INCREMENT PRIMARY KEY NOT NULL ,
`name` TEXT NOT NULL,
`author` BIGINT(20) NOT NULL,
`portions` SMALLINT DEFAULT 1,
`public` BOOLEAN DEFAULT 0,
CONSTRAINT author_FK FOREIGN KEY (`author`) REFERENCES user(`user_id`)
);
CREATE OR REPLACE TABLE `recipe_item` (
`recipe_id` INT NOT NULL,
`recipe_item_id` INT AUTO_INCREMENT PRIMARY KEY,
`item_num` SMALLINT NOT NULL,
`name` TEXT NOT NULL,
`price` DECIMAL(8,2) DEFAULT 0.00,
`amount` INT DEFAULT 1,
`item_id` BIGINT(20),
CONSTRAINT recipe_FK FOREIGN KEY (`recipe_id`) REFERENCES recipe(`recipe_id`)
);";
if(!empty($_POST) && !isset($fatalErr)){
include "init.php";
$db = database();
if(isset($_POST['setupDB'])){
$db->multi_query($sql);
if($error = $db->error){
$err[] = $error;
}
else {
$msg[] = "Database tables are setup/reset.";
}
}
elseif (isset($_POST['recipeTables'])){
$db->multi_query($recipeSQL);
if($error = $db->error){
$err[] = $error;
}
else {
$msg[] = "Recipe tables are setup/reset.";
}
}
elseif (isset($_POST['goProject'])){
header("Location: ".getConfig('projectRoot')."/");
}
$db->close();
}
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Setup</title>
<style>
.alert-danger {
color: #842029;
background-color: #f8d7da;
border-color: #f5c2c7;
}
.alert-success {
color: #0f5132;
background-color: #d1e7dd;
border-color: #badbcc;
}
.alert {
position: relative;
padding: 1rem 1rem;
margin-bottom: 1rem;
border: 1px solid transparent;
border-radius: .25rem;
}
</style>
</head>
<body>
<div style='max-width: 500px; margin: auto; text-align: center;'>
<h1>Setup</h1>
<?php
if(!empty($err)){
foreach ($err as $e) {
echo "<div class='alert alert-danger'>$e</div>";
}
}
if(!empty($msg)){
foreach ($msg as $m) {
echo "<div class='alert alert-success'>$m</div>";
}
}
if(isset($fatalErr)){
die();
}
?>
<form action='setup.php' method='POST'>
<?php if($missingConfig){ ?>
<p>Configuration-file is missing or lacks content. Fill out the data here:</p>
<h4>Users Database</h4>
<p><label>Host: <input type='text' name='DatabaseUser-host' value='<?=$co['DatabaseUser']['host']??''?>' placeholder='localhost:3306' required></label></p>
<p><label>User: <input type='text' name='DatabaseUser-user' value='<?=$co['DatabaseUser']['user']??''?>' placeholder='LuxFictus' required></label></p>
<p><label>Password: <input type='password' name='DatabaseUser-password' value='<?=$co['DatabaseUser']['password']??''?>' placeholder='******' required></label></p>
<p><label>Database: <input type='text' name='DatabaseUser-database' value='<?=$co['DatabaseUser']['database']??''?>' placeholder='journal' required></label></p>
<input type='submit' value="Save" name='setup'>
<?php } ?>
<p><button name="setupDB">Setup tables</button></p>
<p><button name="recipeTables">Setup recipe tables</button></p>
<br>
<p><button name="goProject">Go to project</button></p>
</form>
</body>
</html>