Browse Source

Added basic item management

keplyx 4 years ago
parent
commit
3677b8165c
7 changed files with 215 additions and 14 deletions
  1. 66
    0
      admin/index.php
  2. 25
    0
      assets/css/stock.css
  3. 102
    0
      assets/js/stock.js
  4. 1
    1
      includes/navbar.php
  5. 1
    1
      includes/sidenav.php
  6. 9
    9
      includes/template.php
  7. 11
    3
      index.php

+ 66
- 0
admin/index.php View File

@@ -0,0 +1,66 @@
1
+<?php
2
+$relativePath = "../";
3
+ob_start();
4
+?>
5
+<div class="stock-container">
6
+
7
+    <h1 class="text-center">Gestion des Stocks</h1>
8
+    <h2 class="text-center">Ajouter un article</h2>
9
+    <table>
10
+        <tbody>
11
+        <tr>
12
+            <th class="name-column">Nom</th>
13
+            <th>Quantité</th>
14
+            <th>Prix</th>
15
+            <th class="code-column">Code Barre</th>
16
+            <th class="image-column">Image</th>
17
+            <th class="actions-column">Actions</th>
18
+        </tr>
19
+        <tr>
20
+            <td>
21
+                <input type="text" class="form-control" id="nameInput" placeholder="Nom">
22
+            </td>
23
+            <td>
24
+                <input type="number" class="form-control" id="quantityInput" placeholder="Quantité">
25
+            </td>
26
+            <td>
27
+                <input type="text" class="form-control" id="priceInput" placeholder="Prix">
28
+            </td>
29
+            <td>
30
+                <input type="text" class="form-control" id="codeInput" placeholder="Code Barre">
31
+            </td>
32
+            <td>
33
+                <button class="btn btn-primary">Importer</button>
34
+            </td>
35
+            <td>
36
+                <button type="submit" class="btn btn-success" onclick="addNewItem()"><i class="fas fa-check"></i></button>
37
+            </td>
38
+        </tr>
39
+
40
+        </tbody>
41
+    </table>
42
+
43
+    <h2 class="text-center">Liste d'articles</h2>
44
+    <table id="stockTable">
45
+        <tbody>
46
+        <tr>
47
+            <th class="name-column">Nom</th>
48
+            <th>Quantité</th>
49
+            <th>Prix</th>
50
+            <th class="code-column">Code Barre</th>
51
+            <th class="image-column">Image</th>
52
+            <th class="actions-column">Actions</th>
53
+        </tr>
54
+        </tbody>
55
+    </table>
56
+</div>
57
+
58
+<link type="text/css" rel="stylesheet" href="<?= $relativePath ?>assets/css/stock.css" media="screen,projection"/>
59
+
60
+
61
+<?php
62
+$pageContent = ob_get_clean();
63
+$pageTitle = "Gestion";
64
+$pageScripts = "<script type=\"text/javascript\" src=\"" . $relativePath . "assets/js/stock.js\"></script>";
65
+include($relativePath . "includes/template.php");
66
+?>

+ 25
- 0
assets/css/stock.css View File

@@ -0,0 +1,25 @@
1
+table {
2
+    width: 100%;
3
+    margin-bottom: 20px;
4
+}
5
+
6
+.name-column {
7
+    width : 30%;
8
+}
9
+
10
+.code-column {
11
+    width: 20%;
12
+}
13
+
14
+.stock-container {
15
+    width: 90%;
16
+    margin: 50px auto auto auto;
17
+}
18
+
19
+.actions-column {
20
+    width: 100px;
21
+}
22
+
23
+.image-column {
24
+    width: 150px;
25
+}

+ 102
- 0
assets/js/stock.js View File

@@ -0,0 +1,102 @@
1
+let defaultStock = [
2
+    {
3
+        name: 'Granola',
4
+        quantity: '2',
5
+        price: '1.3',
6
+        code: '7622210601988',
7
+        type: [
8
+            'Alimentaire',
9
+        ]
10
+    }
11
+];
12
+
13
+let currentDataset = [];
14
+
15
+$(document).ready(function () {
16
+    currentDataset = defaultStock;
17
+    generateTable(currentDataset);
18
+});
19
+
20
+
21
+function generateTable(dataset) {
22
+    for (let i = 0; i < dataset.length; i++) {
23
+        generateLine(dataset[i]);
24
+    }
25
+}
26
+
27
+
28
+function generateLine(item) {
29
+    $.selector_cache('#stockTable').append(
30
+        '<tr id="row_' + item.code + '">' +
31
+        '<td>' + item.name + '</td>' +
32
+        '<td>' + item.quantity + '</td>' +
33
+        '<td>' + item.price + '</td>' +
34
+        '<td>' + item.code + '</td>' +
35
+        '<td><a href="">LINK</a></td>' +
36
+        '<td>' +
37
+        '<button class="btn btn-danger" id="delete_' + item.code + '" onclick="deleteItem(this)"><i class="fas fa-times"></i></button>' +
38
+        '<button class="btn btn-primary" id="edit_' + item.code + '" onclick="editItem(this)"><i class="fas fa-edit"></i></button>' +
39
+        '</td>' +
40
+        '</tr>'
41
+    );
42
+}
43
+
44
+function getItemOfCode(code) {
45
+    let item = {};
46
+    for (let i = 0; i < currentDataset.length; i++) {
47
+        if (currentDataset[i].code === code) {
48
+            item = currentDataset[i];
49
+            break;
50
+        }
51
+    }
52
+    return item;
53
+}
54
+
55
+
56
+function editItem(elem) {
57
+    if (isItemInputEmpty()) {
58
+        let code = elem.id.replace('edit_', '');
59
+        let item = getItemOfCode(code);
60
+        console.log(item);
61
+        setEditFieldValues(item.name, item.quantity, item.price, item.code);
62
+        removeItemFromList(item); // Move the item in the edit fields
63
+    }
64
+}
65
+
66
+function deleteItem(elem) {
67
+    let code = elem.id.replace('delete_', '');
68
+    let item = getItemOfCode(code);
69
+    console.log(item);
70
+    removeItemFromList(item);
71
+}
72
+
73
+function removeItemFromList(item) {
74
+    currentDataset.splice(currentDataset.indexOf(item), 1);
75
+    $('#row_' + item.code).remove();
76
+}
77
+
78
+function setEditFieldValues(name, quantity, price, code) {
79
+    $.selector_cache('#nameInput').val(name);
80
+    $.selector_cache('#quantityInput').val(quantity);
81
+    $.selector_cache('#priceInput').val(price);
82
+    $.selector_cache('#codeInput').val(code);
83
+}
84
+
85
+function isItemInputEmpty() {
86
+    return $.selector_cache('#nameInput').val() === '' &&
87
+        $.selector_cache('#quantityInput').val() === '' &&
88
+        $.selector_cache('#priceInput').val() === '' &&
89
+        $.selector_cache('#codeInput').val() === '';
90
+}
91
+
92
+function addNewItem() {
93
+    let item = {
94
+        name: $.selector_cache('#nameInput').val(),
95
+        quantity: $.selector_cache('#quantityInput').val(),
96
+        price: $.selector_cache('#priceInput').val(),
97
+        code: $.selector_cache('#codeInput').val(),
98
+    };
99
+    setEditFieldValues('', '', '', '');
100
+    currentDataset.push(item);
101
+    generateLine(item);
102
+}

+ 1
- 1
includes/navbar.php View File

@@ -43,7 +43,7 @@
43 43
                 </li>
44 44
                 <li class="nav-item">
45 45
                     <div class="link-effect clipped"></div>
46
-                    <a class="nav-link" href="<?= $relativePath ?>about.php">
46
+                    <a class="nav-link" href="<?= $relativePath ?>admin">
47 47
                         <!--Place and access-->
48 48
                         <i class="fas fa-sign-in-alt mr-2"></i>
49 49
                         Connexion

+ 1
- 1
includes/sidenav.php View File

@@ -38,7 +38,7 @@
38 38
             </li>
39 39
             <li class="nav-item">
40 40
                 <div class="link-effect clipped"></div>
41
-                <a class="nav-link" href="<?= $relativePath ?>about.php">
41
+                <a class="nav-link" href="<?= $relativePath ?>admin">
42 42
                     <!--Place and access-->
43 43
                     <i class="fas fa-sign-in-alt mr-2"></i>
44 44
                     Connexion

+ 9
- 9
includes/template.php View File

@@ -6,6 +6,9 @@ if (!isset($relativePath))
6 6
 if (!isset($pageScripts))
7 7
     $pageScripts = "";
8 8
 
9
+if (!isset($hasHeader))
10
+    $hasHeader = false;
11
+
9 12
 ?>
10 13
 
11 14
 <!DOCTYPE html>
@@ -22,7 +25,8 @@ if (!isset($pageScripts))
22 25
     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.0/animate.min.css">
23 26
     <link type="text/css" rel="stylesheet" href="<?= $relativePath ?>assets/css/general.css" media="screen,projection"/>
24 27
     <link type="text/css" rel="stylesheet" href="<?= $relativePath ?>assets/css/index.css" media="screen,projection"/>
25
-    <link type="text/css" rel="stylesheet" href="<?= $relativePath ?>assets/css/hamburger.css" media="screen,projection"/>
28
+    <link type="text/css" rel="stylesheet" href="<?= $relativePath ?>assets/css/hamburger.css"
29
+          media="screen,projection"/>
26 30
     <link type="text/css" rel="stylesheet" href="<?= $relativePath ?>assets/css/sidenav.css" media="screen,projection"/>
27 31
     <link type="text/css" rel="stylesheet" href="<?= $relativePath ?>assets/css/bootstrapOverwrite.css"
28 32
           media="screen,projection"/>
@@ -35,22 +39,18 @@ if (!isset($pageScripts))
35 39
 
36 40
 <div id="mainContainer">
37 41
 
38
-    <div id="headerJumbotron" class="jumbotron text-center d-flex">
39
-        <div id="headerTitleContainer">
40
-            <h1 id="headerTitle"><?= $title ?></h1>
41
-            <h2 id="headerSubTitle"><?= $subTitle ?></h2>
42
-        </div>
43
-    </div>
44
-
45 42
 
46 43
     <?php
44
+    if (isset($header)) {
45
+        echo $header;
46
+    }
47 47
     include($relativePath . "includes/navbar.php");
48 48
     include($relativePath . "includes/sidenav.php");
49 49
     ?>
50
-
51 50
     <div class="mt-4" id="contentContainer">
52 51
         <?= $pageContent ?>
53 52
     </div>
53
+
54 54
     <?php include($relativePath . "includes/footer.php") ?>
55 55
 </div>
56 56
 

+ 11
- 3
index.php View File

@@ -1,6 +1,17 @@
1 1
 <?php
2 2
 ob_start();
3 3
 ?>
4
+<div id="headerJumbotron" class="jumbotron text-center d-flex">
5
+    <div id="headerTitleContainer">
6
+        <h1 id="headerTitle">Proximo</h1>
7
+        <h2 id="headerSubTitle">La supérette de l'INSA</h2>
8
+    </div>
9
+</div>
10
+<?php
11
+$header = ob_get_clean();
12
+ob_start();
13
+?>
14
+
4 15
 <div class="container">
5 16
     <h1 class="text-center">Coucou</h1>
6 17
     <p class="text-center">Ceci est du texte</p>
@@ -9,9 +20,6 @@ ob_start();
9 20
 <?php
10 21
 $pageContent = ob_get_clean();
11 22
 $pageTitle = "Accueil";
12
-$title = "Proximo";
13
-$subTitle = "La supérette de l'INSA !";
14 23
 $relativePath = "";
15
-
16 24
 include($relativePath . "includes/template.php");
17 25
 ?>

Loading…
Cancel
Save