From 1dc5306967a2a32306bc27e9a5062f5e4245917c Mon Sep 17 00:00:00 2001 From: lubiana Date: Fri, 14 Jun 2024 17:41:00 +0200 Subject: [PATCH] add order --- config/services.php | 3 + migrations/Version20240610175726.php | 32 ----- migrations/Version20240614153440.php | 44 ++++++ public/static/css/simple.min.css | 1 + public/static/js/htmx.min.js | 1 + src/Controller/FoodOrderController.php | 72 ++++++++++ src/Controller/FoodVendorController.php | 11 -- src/Controller/Home.php | 15 -- src/Controller/HomeController.php | 17 +++ src/Controller/OrderItemController.php | 81 +++++++++++ src/Entity/FoodOrder.php | 128 ++++++++++++++++++ src/Entity/FoodVendor.php | 41 ++++++ src/Entity/OrderItem.php | 70 ++++++++++ src/Form/FoodOrderType.php | 37 +++++ src/Form/OrderItemType.php | 29 ++++ src/Repository/FoodOrderRepository.php | 26 ++++ src/Repository/OrderItemRepository.php | 43 ++++++ templates/_form.html.twig | 4 + templates/base.html.twig | 14 +- templates/food_order/edit.html.twig | 12 ++ templates/food_order/index.html.twig | 34 +++++ templates/food_order/new.html.twig | 2 + templates/food_order/show.html.twig | 31 +++++ templates/food_order/table_row.html.twig | 8 ++ templates/food_vendor/_delete_form.html.twig | 4 - templates/food_vendor/show.html.twig | 2 - templates/order_item/_delete_form.html.twig | 4 + templates/order_item/_form.html.twig | 4 + templates/order_item/edit.html.twig | 13 ++ templates/order_item/index.html.twig | 37 +++++ templates/order_item/new.html.twig | 11 ++ templates/order_item/show.html.twig | 30 ++++ tests/Controller/FoodOrderControllerTest.php | 114 ++++++++++++++++ tests/Controller/FoodVendorControllerTest.php | 38 ++---- tests/Controller/HomeTest.php | 17 --- tests/Controller/OrderItemControllerTest.php | 108 +++++++++++++++ tests/DbWebTest.php | 35 +++++ 37 files changed, 1060 insertions(+), 113 deletions(-) delete mode 100644 migrations/Version20240610175726.php create mode 100644 migrations/Version20240614153440.php create mode 100644 public/static/css/simple.min.css create mode 100644 public/static/js/htmx.min.js create mode 100644 src/Controller/FoodOrderController.php delete mode 100644 src/Controller/Home.php create mode 100644 src/Controller/HomeController.php create mode 100644 src/Controller/OrderItemController.php create mode 100644 src/Entity/FoodOrder.php create mode 100644 src/Entity/OrderItem.php create mode 100644 src/Form/FoodOrderType.php create mode 100644 src/Form/OrderItemType.php create mode 100644 src/Repository/FoodOrderRepository.php create mode 100644 src/Repository/OrderItemRepository.php create mode 100644 templates/_form.html.twig create mode 100644 templates/food_order/edit.html.twig create mode 100644 templates/food_order/index.html.twig create mode 100644 templates/food_order/new.html.twig create mode 100644 templates/food_order/show.html.twig create mode 100644 templates/food_order/table_row.html.twig delete mode 100644 templates/food_vendor/_delete_form.html.twig create mode 100644 templates/order_item/_delete_form.html.twig create mode 100644 templates/order_item/_form.html.twig create mode 100644 templates/order_item/edit.html.twig create mode 100644 templates/order_item/index.html.twig create mode 100644 templates/order_item/new.html.twig create mode 100644 templates/order_item/show.html.twig create mode 100644 tests/Controller/FoodOrderControllerTest.php delete mode 100644 tests/Controller/HomeTest.php create mode 100644 tests/Controller/OrderItemControllerTest.php create mode 100644 tests/DbWebTest.php diff --git a/config/services.php b/config/services.php index 01396a0..e6e151e 100644 --- a/config/services.php +++ b/config/services.php @@ -14,5 +14,8 @@ return static function (ContainerConfigurator $containerConfigurator): void { __DIR__ . '/../src/DependencyInjection/', __DIR__ . '/../src/Entity/', __DIR__ . '/../src/Kernel.php', + __DIR__ . '/../src/Controller/', ]); + $services->load('App\\Controller\\', __DIR__ . '/../src/Controller/') + ->tag('controller.service_arguments'); }; diff --git a/migrations/Version20240610175726.php b/migrations/Version20240610175726.php deleted file mode 100644 index 382db2f..0000000 --- a/migrations/Version20240610175726.php +++ /dev/null @@ -1,32 +0,0 @@ -addSql('CREATE TABLE food_vendor (id BLOB NOT NULL --(DC2Type:ulid) - , name VARCHAR(50) NOT NULL, PRIMARY KEY(id))'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP TABLE food_vendor'); - } -} diff --git a/migrations/Version20240614153440.php b/migrations/Version20240614153440.php new file mode 100644 index 0000000..bc9b3d5 --- /dev/null +++ b/migrations/Version20240614153440.php @@ -0,0 +1,44 @@ +addSql('CREATE TABLE food_order (id BLOB NOT NULL --(DC2Type:ulid) + , food_vendor_id BLOB NOT NULL --(DC2Type:ulid) + , created_at DATETIME NOT NULL --(DC2Type:datetime_immutable) + , closed_at DATETIME DEFAULT NULL --(DC2Type:datetime_immutable) + , PRIMARY KEY(id), CONSTRAINT FK_44856726EF983E8 FOREIGN KEY (food_vendor_id) REFERENCES food_vendor (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('CREATE INDEX IDX_44856726EF983E8 ON food_order (food_vendor_id)'); + $this->addSql('CREATE TABLE food_vendor (id BLOB NOT NULL --(DC2Type:ulid) + , name VARCHAR(50) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE order_item (id BLOB NOT NULL --(DC2Type:ulid) + , food_order_id BLOB NOT NULL --(DC2Type:ulid) + , name VARCHAR(255) NOT NULL, extras VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id), CONSTRAINT FK_52EA1F09A5D24A7A FOREIGN KEY (food_order_id) REFERENCES food_order (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('CREATE INDEX IDX_52EA1F09A5D24A7A ON order_item (food_order_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP TABLE food_order'); + $this->addSql('DROP TABLE food_vendor'); + $this->addSql('DROP TABLE order_item'); + } +} diff --git a/public/static/css/simple.min.css b/public/static/css/simple.min.css new file mode 100644 index 0000000..9db8fe6 --- /dev/null +++ b/public/static/css/simple.min.css @@ -0,0 +1 @@ +:root,::backdrop{--sans-font:-apple-system,BlinkMacSystemFont,"Avenir Next",Avenir,"Nimbus Sans L",Roboto,"Noto Sans","Segoe UI",Arial,Helvetica,"Helvetica Neue",sans-serif;--mono-font:Consolas,Menlo,Monaco,"Andale Mono","Ubuntu Mono",monospace;--standard-border-radius:5px;--bg:#fff;--accent-bg:#f5f7ff;--text:#212121;--text-light:#585858;--border:#898ea4;--accent:#0d47a1;--accent-hover:#1266e2;--accent-text:var(--bg);--code:#d81b60;--preformatted:#444;--marked:#fd3;--disabled:#efefef}@media (prefers-color-scheme:dark){:root,::backdrop{color-scheme:dark;--bg:#212121;--accent-bg:#2b2b2b;--text:#dcdcdc;--text-light:#ababab;--accent:#ffb300;--accent-hover:#ffe099;--accent-text:var(--bg);--code:#f06292;--preformatted:#ccc;--disabled:#111}img,video{opacity:.8}}*,:before,:after{box-sizing:border-box}textarea,select,input,progress{-webkit-appearance:none;-moz-appearance:none;appearance:none}html{font-family:var(--sans-font);scroll-behavior:smooth}body{color:var(--text);background-color:var(--bg);grid-template-columns:1fr min(45rem,90%) 1fr;margin:0;font-size:1.15rem;line-height:1.5;display:grid}body>*{grid-column:2}body>header{background-color:var(--accent-bg);border-bottom:1px solid var(--border);text-align:center;grid-column:1/-1;padding:0 .5rem 2rem}body>header>:only-child{margin-block-start:2rem}body>header h1{max-width:1200px;margin:1rem auto}body>header p{max-width:40rem;margin:1rem auto}main{padding-top:1.5rem}body>footer{color:var(--text-light);text-align:center;border-top:1px solid var(--border);margin-top:4rem;padding:2rem 1rem 1.5rem;font-size:.9rem}h1{font-size:3rem}h2{margin-top:3rem;font-size:2.6rem}h3{margin-top:3rem;font-size:2rem}h4{font-size:1.44rem}h5{font-size:1.15rem}h6{font-size:.96rem}p{margin:1.5rem 0}p,h1,h2,h3,h4,h5,h6{overflow-wrap:break-word}h1,h2,h3{line-height:1.1}@media only screen and (width<=720px){h1{font-size:2.5rem}h2{font-size:2.1rem}h3{font-size:1.75rem}h4{font-size:1.25rem}}a,a:visited{color:var(--accent)}a:hover{text-decoration:none}button,.button,a.button,input[type=submit],input[type=reset],input[type=button],label[type=button]{border:1px solid var(--accent);background-color:var(--accent);color:var(--accent-text);padding:.5rem .9rem;line-height:normal;text-decoration:none}.button[aria-disabled=true],input:disabled,textarea:disabled,select:disabled,button[disabled]{cursor:not-allowed;background-color:var(--disabled);border-color:var(--disabled);color:var(--text-light)}input[type=range]{padding:0}abbr[title]{cursor:help;text-decoration-line:underline;text-decoration-style:dotted}button:enabled:hover,.button:not([aria-disabled=true]):hover,input[type=submit]:enabled:hover,input[type=reset]:enabled:hover,input[type=button]:enabled:hover,label[type=button]:hover{background-color:var(--accent-hover);border-color:var(--accent-hover);cursor:pointer}.button:focus-visible,button:focus-visible:where(:enabled),input:enabled:focus-visible:where([type=submit],[type=reset],[type=button]){outline:2px solid var(--accent);outline-offset:1px}header>nav{padding:1rem 0 0;font-size:1rem;line-height:2}header>nav ul,header>nav ol{flex-flow:wrap;place-content:space-around center;align-items:center;margin:0;padding:0;list-style-type:none;display:flex}header>nav ul li,header>nav ol li{display:inline-block}header>nav a,header>nav a:visited{border:1px solid var(--border);border-radius:var(--standard-border-radius);color:var(--text);margin:0 .5rem 1rem;padding:.1rem 1rem;text-decoration:none;display:inline-block}header>nav a:hover,header>nav a.current,header>nav a[aria-current=page]{border-color:var(--accent);color:var(--accent);cursor:pointer}@media only screen and (width<=720px){header>nav a{border:none;padding:0;line-height:1;text-decoration:underline}}aside,details,pre,progress{background-color:var(--accent-bg);border:1px solid var(--border);border-radius:var(--standard-border-radius);margin-bottom:1rem}aside{float:right;width:30%;margin-inline-start:15px;padding:0 15px;font-size:1rem}[dir=rtl] aside{float:left}@media only screen and (width<=720px){aside{float:none;width:100%;margin-inline-start:0}}article,fieldset,dialog{border:1px solid var(--border);border-radius:var(--standard-border-radius);margin-bottom:1rem;padding:1rem}article h2:first-child,section h2:first-child,article h3:first-child,section h3:first-child{margin-top:1rem}section{border-top:1px solid var(--border);border-bottom:1px solid var(--border);margin:3rem 0;padding:2rem 1rem}section+section,section:first-child{border-top:0;padding-top:0}section+section{margin-top:0}section:last-child{border-bottom:0;padding-bottom:0}details{padding:.7rem 1rem}summary{cursor:pointer;word-break:break-all;margin:-.7rem -1rem;padding:.7rem 1rem;font-weight:700}details[open]>summary+*{margin-top:0}details[open]>summary{margin-bottom:.5rem}details[open]>:last-child{margin-bottom:0}table{border-collapse:collapse;margin:1.5rem 0}figure>table{width:max-content;margin:0}td,th{border:1px solid var(--border);text-align:start;padding:.5rem}th{background-color:var(--accent-bg);font-weight:700}tr:nth-child(2n){background-color:var(--accent-bg)}table caption{margin-bottom:.5rem;font-weight:700}textarea,select,input,button,.button{font-size:inherit;border-radius:var(--standard-border-radius);box-shadow:none;max-width:100%;margin-bottom:.5rem;padding:.5rem;font-family:inherit;display:inline-block}textarea,select,input{color:var(--text);background-color:var(--bg);border:1px solid var(--border)}label{display:block}textarea:not([cols]){width:100%}select:not([multiple]){background-image:linear-gradient(45deg,transparent 49%,var(--text)51%),linear-gradient(135deg,var(--text)51%,transparent 49%);background-position:calc(100% - 15px),calc(100% - 10px);background-repeat:no-repeat;background-size:5px 5px,5px 5px;padding-inline-end:25px}[dir=rtl] select:not([multiple]){background-position:10px,15px}input[type=checkbox],input[type=radio]{vertical-align:middle;width:min-content;position:relative}input[type=checkbox]+label,input[type=radio]+label{display:inline-block}input[type=radio]{border-radius:100%}input[type=checkbox]:checked,input[type=radio]:checked{background-color:var(--accent)}input[type=checkbox]:checked:after{content:" ";border-right:solid var(--bg).08em;border-bottom:solid var(--bg).08em;background-color:#0000;border-radius:0;width:.18em;height:.32em;font-size:1.8em;position:absolute;top:.05em;left:.17em;transform:rotate(45deg)}input[type=radio]:checked:after{content:" ";background-color:var(--bg);border-radius:100%;width:.25em;height:.25em;font-size:32px;position:absolute;top:.125em;left:.125em}@media only screen and (width<=720px){textarea,select,input{width:100%}}input[type=color]{height:2.5rem;padding:.2rem}input[type=file]{border:0}hr{background:var(--border);border:none;height:1px;margin:1rem auto}mark{border-radius:var(--standard-border-radius);background-color:var(--marked);color:#000;padding:2px 5px}mark a{color:#0d47a1}img,video{border-radius:var(--standard-border-radius);max-width:100%;height:auto}figure{margin:0;display:block;overflow-x:auto}figure>img,figure>picture>img{margin-inline:auto;display:block}figcaption{text-align:center;color:var(--text-light);margin-block:1rem;font-size:.9rem}blockquote{border-inline-start:.35rem solid var(--accent);color:var(--text-light);margin-block:2rem;margin-inline:2rem 0;padding:.4rem .8rem;font-style:italic}cite{color:var(--text-light);font-size:.9rem;font-style:normal}dt{color:var(--text-light)}code,pre,pre span,kbd,samp{font-family:var(--mono-font);color:var(--code)}kbd{color:var(--preformatted);border:1px solid var(--preformatted);border-bottom:3px solid var(--preformatted);border-radius:var(--standard-border-radius);padding:.1rem .4rem}pre{color:var(--preformatted);max-width:100%;padding:1rem 1.4rem;overflow:auto}pre code{color:var(--preformatted);background:0 0;margin:0;padding:0}progress{width:100%}progress:indeterminate{background-color:var(--accent-bg)}progress::-webkit-progress-bar{border-radius:var(--standard-border-radius);background-color:var(--accent-bg)}progress::-webkit-progress-value{border-radius:var(--standard-border-radius);background-color:var(--accent)}progress::-moz-progress-bar{border-radius:var(--standard-border-radius);background-color:var(--accent);transition-property:width;transition-duration:.3s}progress:indeterminate::-moz-progress-bar{background-color:var(--accent-bg)}dialog{max-width:40rem;margin:auto}dialog::backdrop{background-color:var(--bg);opacity:.8}@media only screen and (width<=720px){dialog{max-width:100%;margin:auto 1em}}sup,sub{vertical-align:baseline;position:relative}sup{top:-.4em}sub{top:.3em}.notice{background:var(--accent-bg);border:2px solid var(--border);border-radius:var(--standard-border-radius);margin:2rem 0;padding:1.5rem} \ No newline at end of file diff --git a/public/static/js/htmx.min.js b/public/static/js/htmx.min.js new file mode 100644 index 0000000..de5f0f1 --- /dev/null +++ b/public/static/js/htmx.min.js @@ -0,0 +1 @@ +(function(e,t){if(typeof define==="function"&&define.amd){define([],t)}else if(typeof module==="object"&&module.exports){module.exports=t()}else{e.htmx=e.htmx||t()}})(typeof self!=="undefined"?self:this,function(){return function(){"use strict";var Q={onLoad:F,process:zt,on:de,off:ge,trigger:ce,ajax:Nr,find:C,findAll:f,closest:v,values:function(e,t){var r=dr(e,t||"post");return r.values},remove:_,addClass:z,removeClass:n,toggleClass:$,takeClass:W,defineExtension:Ur,removeExtension:Br,logAll:V,logNone:j,logger:null,config:{historyEnabled:true,historyCacheSize:10,refreshOnHistoryMiss:false,defaultSwapStyle:"innerHTML",defaultSwapDelay:0,defaultSettleDelay:20,includeIndicatorStyles:true,indicatorClass:"htmx-indicator",requestClass:"htmx-request",addedClass:"htmx-added",settlingClass:"htmx-settling",swappingClass:"htmx-swapping",allowEval:true,allowScriptTags:true,inlineScriptNonce:"",attributesToSettle:["class","style","width","height"],withCredentials:false,timeout:0,wsReconnectDelay:"full-jitter",wsBinaryType:"blob",disableSelector:"[hx-disable], [data-hx-disable]",useTemplateFragments:false,scrollBehavior:"smooth",defaultFocusScroll:false,getCacheBusterParam:false,globalViewTransitions:false,methodsThatUseUrlParams:["get"],selfRequestsOnly:false,ignoreTitle:false,scrollIntoViewOnBoost:true,triggerSpecsCache:null},parseInterval:d,_:t,createEventSource:function(e){return new EventSource(e,{withCredentials:true})},createWebSocket:function(e){var t=new WebSocket(e,[]);t.binaryType=Q.config.wsBinaryType;return t},version:"1.9.12"};var r={addTriggerHandler:Lt,bodyContains:se,canAccessLocalStorage:U,findThisElement:xe,filterValues:yr,hasAttribute:o,getAttributeValue:te,getClosestAttributeValue:ne,getClosestMatch:c,getExpressionVars:Hr,getHeaders:xr,getInputValues:dr,getInternalData:ae,getSwapSpecification:wr,getTriggerSpecs:it,getTarget:ye,makeFragment:l,mergeObjects:le,makeSettleInfo:T,oobSwap:Ee,querySelectorExt:ue,selectAndSwap:je,settleImmediately:nr,shouldCancel:ut,triggerEvent:ce,triggerErrorEvent:fe,withExtensions:R};var w=["get","post","put","delete","patch"];var i=w.map(function(e){return"[hx-"+e+"], [data-hx-"+e+"]"}).join(", ");var S=e("head"),q=e("title"),H=e("svg",true);function e(e,t){return new RegExp("<"+e+"(\\s[^>]*>|>)([\\s\\S]*?)<\\/"+e+">",!!t?"gim":"im")}function d(e){if(e==undefined){return undefined}let t=NaN;if(e.slice(-2)=="ms"){t=parseFloat(e.slice(0,-2))}else if(e.slice(-1)=="s"){t=parseFloat(e.slice(0,-1))*1e3}else if(e.slice(-1)=="m"){t=parseFloat(e.slice(0,-1))*1e3*60}else{t=parseFloat(e)}return isNaN(t)?undefined:t}function ee(e,t){return e.getAttribute&&e.getAttribute(t)}function o(e,t){return e.hasAttribute&&(e.hasAttribute(t)||e.hasAttribute("data-"+t))}function te(e,t){return ee(e,t)||ee(e,"data-"+t)}function u(e){return e.parentElement}function re(){return document}function c(e,t){while(e&&!t(e)){e=u(e)}return e?e:null}function L(e,t,r){var n=te(t,r);var i=te(t,"hx-disinherit");if(e!==t&&i&&(i==="*"||i.split(" ").indexOf(r)>=0)){return"unset"}else{return n}}function ne(t,r){var n=null;c(t,function(e){return n=L(t,e,r)});if(n!=="unset"){return n}}function h(e,t){var r=e.matches||e.matchesSelector||e.msMatchesSelector||e.mozMatchesSelector||e.webkitMatchesSelector||e.oMatchesSelector;return r&&r.call(e,t)}function A(e){var t=/<([a-z][^\/\0>\x20\t\r\n\f]*)/i;var r=t.exec(e);if(r){return r[1].toLowerCase()}else{return""}}function s(e,t){var r=new DOMParser;var n=r.parseFromString(e,"text/html");var i=n.body;while(t>0){t--;i=i.firstChild}if(i==null){i=re().createDocumentFragment()}return i}function N(e){return/",0);var a=i.querySelector("template").content;if(Q.config.allowScriptTags){oe(a.querySelectorAll("script"),function(e){if(Q.config.inlineScriptNonce){e.nonce=Q.config.inlineScriptNonce}e.htmxExecuted=navigator.userAgent.indexOf("Firefox")===-1})}else{oe(a.querySelectorAll("script"),function(e){_(e)})}return a}switch(r){case"thead":case"tbody":case"tfoot":case"colgroup":case"caption":return s(""+n+"
",1);case"col":return s(""+n+"
",2);case"tr":return s(""+n+"
",2);case"td":case"th":return s(""+n+"
",3);case"script":case"style":return s("
"+n+"
",1);default:return s(n,0)}}function ie(e){if(e){e()}}function I(e,t){return Object.prototype.toString.call(e)==="[object "+t+"]"}function k(e){return I(e,"Function")}function P(e){return I(e,"Object")}function ae(e){var t="htmx-internal-data";var r=e[t];if(!r){r=e[t]={}}return r}function M(e){var t=[];if(e){for(var r=0;r=0}function se(e){if(e.getRootNode&&e.getRootNode()instanceof window.ShadowRoot){return re().body.contains(e.getRootNode().host)}else{return re().body.contains(e)}}function D(e){return e.trim().split(/\s+/)}function le(e,t){for(var r in t){if(t.hasOwnProperty(r)){e[r]=t[r]}}return e}function E(e){try{return JSON.parse(e)}catch(e){b(e);return null}}function U(){var e="htmx:localStorageTest";try{localStorage.setItem(e,e);localStorage.removeItem(e);return true}catch(e){return false}}function B(t){try{var e=new URL(t);if(e){t=e.pathname+e.search}if(!/^\/$/.test(t)){t=t.replace(/\/+$/,"")}return t}catch(e){return t}}function t(e){return Tr(re().body,function(){return eval(e)})}function F(t){var e=Q.on("htmx:load",function(e){t(e.detail.elt)});return e}function V(){Q.logger=function(e,t,r){if(console){console.log(t,e,r)}}}function j(){Q.logger=null}function C(e,t){if(t){return e.querySelector(t)}else{return C(re(),e)}}function f(e,t){if(t){return e.querySelectorAll(t)}else{return f(re(),e)}}function _(e,t){e=p(e);if(t){setTimeout(function(){_(e);e=null},t)}else{e.parentElement.removeChild(e)}}function z(e,t,r){e=p(e);if(r){setTimeout(function(){z(e,t);e=null},r)}else{e.classList&&e.classList.add(t)}}function n(e,t,r){e=p(e);if(r){setTimeout(function(){n(e,t);e=null},r)}else{if(e.classList){e.classList.remove(t);if(e.classList.length===0){e.removeAttribute("class")}}}}function $(e,t){e=p(e);e.classList.toggle(t)}function W(e,t){e=p(e);oe(e.parentElement.children,function(e){n(e,t)});z(e,t)}function v(e,t){e=p(e);if(e.closest){return e.closest(t)}else{do{if(e==null||h(e,t)){return e}}while(e=e&&u(e));return null}}function g(e,t){return e.substring(0,t.length)===t}function G(e,t){return e.substring(e.length-t.length)===t}function J(e){var t=e.trim();if(g(t,"<")&&G(t,"/>")){return t.substring(1,t.length-2)}else{return t}}function Z(e,t){if(t.indexOf("closest ")===0){return[v(e,J(t.substr(8)))]}else if(t.indexOf("find ")===0){return[C(e,J(t.substr(5)))]}else if(t==="next"){return[e.nextElementSibling]}else if(t.indexOf("next ")===0){return[K(e,J(t.substr(5)))]}else if(t==="previous"){return[e.previousElementSibling]}else if(t.indexOf("previous ")===0){return[Y(e,J(t.substr(9)))]}else if(t==="document"){return[document]}else if(t==="window"){return[window]}else if(t==="body"){return[document.body]}else{return re().querySelectorAll(J(t))}}var K=function(e,t){var r=re().querySelectorAll(t);for(var n=0;n=0;n--){var i=r[n];if(i.compareDocumentPosition(e)===Node.DOCUMENT_POSITION_FOLLOWING){return i}}};function ue(e,t){if(t){return Z(e,t)[0]}else{return Z(re().body,e)[0]}}function p(e){if(I(e,"String")){return C(e)}else{return e}}function ve(e,t,r){if(k(t)){return{target:re().body,event:e,listener:t}}else{return{target:p(e),event:t,listener:r}}}function de(t,r,n){jr(function(){var e=ve(t,r,n);e.target.addEventListener(e.event,e.listener)});var e=k(r);return e?r:n}function ge(t,r,n){jr(function(){var e=ve(t,r,n);e.target.removeEventListener(e.event,e.listener)});return k(r)?r:n}var pe=re().createElement("output");function me(e,t){var r=ne(e,t);if(r){if(r==="this"){return[xe(e,t)]}else{var n=Z(e,r);if(n.length===0){b('The selector "'+r+'" on '+t+" returned no matches!");return[pe]}else{return n}}}}function xe(e,t){return c(e,function(e){return te(e,t)!=null})}function ye(e){var t=ne(e,"hx-target");if(t){if(t==="this"){return xe(e,"hx-target")}else{return ue(e,t)}}else{var r=ae(e);if(r.boosted){return re().body}else{return e}}}function be(e){var t=Q.config.attributesToSettle;for(var r=0;r0){o=e.substr(0,e.indexOf(":"));t=e.substr(e.indexOf(":")+1,e.length)}else{o=e}var r=re().querySelectorAll(t);if(r){oe(r,function(e){var t;var r=i.cloneNode(true);t=re().createDocumentFragment();t.appendChild(r);if(!Se(o,e)){t=r}var n={shouldSwap:true,target:e,fragment:t};if(!ce(e,"htmx:oobBeforeSwap",n))return;e=n.target;if(n["shouldSwap"]){Fe(o,e,e,t,a)}oe(a.elts,function(e){ce(e,"htmx:oobAfterSwap",n)})});i.parentNode.removeChild(i)}else{i.parentNode.removeChild(i);fe(re().body,"htmx:oobErrorNoTarget",{content:i})}return e}function Ce(e,t,r){var n=ne(e,"hx-select-oob");if(n){var i=n.split(",");for(var a=0;a0){var r=t.replace("'","\\'");var n=e.tagName.replace(":","\\:");var i=o.querySelector(n+"[id='"+r+"']");if(i&&i!==o){var a=e.cloneNode();we(e,i);s.tasks.push(function(){we(e,a)})}}})}function Oe(e){return function(){n(e,Q.config.addedClass);zt(e);Nt(e);qe(e);ce(e,"htmx:load")}}function qe(e){var t="[autofocus]";var r=h(e,t)?e:e.querySelector(t);if(r!=null){r.focus()}}function a(e,t,r,n){Te(e,r,n);while(r.childNodes.length>0){var i=r.firstChild;z(i,Q.config.addedClass);e.insertBefore(i,t);if(i.nodeType!==Node.TEXT_NODE&&i.nodeType!==Node.COMMENT_NODE){n.tasks.push(Oe(i))}}}function He(e,t){var r=0;while(r-1){var t=e.replace(H,"");var r=t.match(q);if(r){return r[2]}}}function je(e,t,r,n,i,a){i.title=Ve(n);var o=l(n);if(o){Ce(r,o,i);o=Be(r,o,a);Re(o);return Fe(e,r,t,o,i)}}function _e(e,t,r){var n=e.getResponseHeader(t);if(n.indexOf("{")===0){var i=E(n);for(var a in i){if(i.hasOwnProperty(a)){var o=i[a];if(!P(o)){o={value:o}}ce(r,a,o)}}}else{var s=n.split(",");for(var l=0;l0){var o=t[0];if(o==="]"){n--;if(n===0){if(a===null){i=i+"true"}t.shift();i+=")})";try{var s=Tr(e,function(){return Function(i)()},function(){return true});s.source=i;return s}catch(e){fe(re().body,"htmx:syntax:error",{error:e,source:i});return null}}}else if(o==="["){n++}if(Qe(o,a,r)){i+="(("+r+"."+o+") ? ("+r+"."+o+") : (window."+o+"))"}else{i=i+o}a=t.shift()}}}function y(e,t){var r="";while(e.length>0&&!t.test(e[0])){r+=e.shift()}return r}function tt(e){var t;if(e.length>0&&Ze.test(e[0])){e.shift();t=y(e,Ke).trim();e.shift()}else{t=y(e,x)}return t}var rt="input, textarea, select";function nt(e,t,r){var n=[];var i=Ye(t);do{y(i,Je);var a=i.length;var o=y(i,/[,\[\s]/);if(o!==""){if(o==="every"){var s={trigger:"every"};y(i,Je);s.pollInterval=d(y(i,/[,\[\s]/));y(i,Je);var l=et(e,i,"event");if(l){s.eventFilter=l}n.push(s)}else if(o.indexOf("sse:")===0){n.push({trigger:"sse",sseEvent:o.substr(4)})}else{var u={trigger:o};var l=et(e,i,"event");if(l){u.eventFilter=l}while(i.length>0&&i[0]!==","){y(i,Je);var f=i.shift();if(f==="changed"){u.changed=true}else if(f==="once"){u.once=true}else if(f==="consume"){u.consume=true}else if(f==="delay"&&i[0]===":"){i.shift();u.delay=d(y(i,x))}else if(f==="from"&&i[0]===":"){i.shift();if(Ze.test(i[0])){var c=tt(i)}else{var c=y(i,x);if(c==="closest"||c==="find"||c==="next"||c==="previous"){i.shift();var h=tt(i);if(h.length>0){c+=" "+h}}}u.from=c}else if(f==="target"&&i[0]===":"){i.shift();u.target=tt(i)}else if(f==="throttle"&&i[0]===":"){i.shift();u.throttle=d(y(i,x))}else if(f==="queue"&&i[0]===":"){i.shift();u.queue=y(i,x)}else if(f==="root"&&i[0]===":"){i.shift();u[f]=tt(i)}else if(f==="threshold"&&i[0]===":"){i.shift();u[f]=y(i,x)}else{fe(e,"htmx:syntax:error",{token:i.shift()})}}n.push(u)}}if(i.length===a){fe(e,"htmx:syntax:error",{token:i.shift()})}y(i,Je)}while(i[0]===","&&i.shift());if(r){r[t]=n}return n}function it(e){var t=te(e,"hx-trigger");var r=[];if(t){var n=Q.config.triggerSpecsCache;r=n&&n[t]||nt(e,t,n)}if(r.length>0){return r}else if(h(e,"form")){return[{trigger:"submit"}]}else if(h(e,'input[type="button"], input[type="submit"]')){return[{trigger:"click"}]}else if(h(e,rt)){return[{trigger:"change"}]}else{return[{trigger:"click"}]}}function at(e){ae(e).cancelled=true}function ot(e,t,r){var n=ae(e);n.timeout=setTimeout(function(){if(se(e)&&n.cancelled!==true){if(!ct(r,e,Wt("hx:poll:trigger",{triggerSpec:r,target:e}))){t(e)}ot(e,t,r)}},r.pollInterval)}function st(e){return location.hostname===e.hostname&&ee(e,"href")&&ee(e,"href").indexOf("#")!==0}function lt(t,r,e){if(t.tagName==="A"&&st(t)&&(t.target===""||t.target==="_self")||t.tagName==="FORM"){r.boosted=true;var n,i;if(t.tagName==="A"){n="get";i=ee(t,"href")}else{var a=ee(t,"method");n=a?a.toLowerCase():"get";if(n==="get"){}i=ee(t,"action")}e.forEach(function(e){ht(t,function(e,t){if(v(e,Q.config.disableSelector)){m(e);return}he(n,i,e,t)},r,e,true)})}}function ut(e,t){if(e.type==="submit"||e.type==="click"){if(t.tagName==="FORM"){return true}if(h(t,'input[type="submit"], button')&&v(t,"form")!==null){return true}if(t.tagName==="A"&&t.href&&(t.getAttribute("href")==="#"||t.getAttribute("href").indexOf("#")!==0)){return true}}return false}function ft(e,t){return ae(e).boosted&&e.tagName==="A"&&t.type==="click"&&(t.ctrlKey||t.metaKey)}function ct(e,t,r){var n=e.eventFilter;if(n){try{return n.call(t,r)!==true}catch(e){fe(re().body,"htmx:eventFilter:error",{error:e,source:n.source});return true}}return false}function ht(a,o,e,s,l){var u=ae(a);var t;if(s.from){t=Z(a,s.from)}else{t=[a]}if(s.changed){t.forEach(function(e){var t=ae(e);t.lastValue=e.value})}oe(t,function(n){var i=function(e){if(!se(a)){n.removeEventListener(s.trigger,i);return}if(ft(a,e)){return}if(l||ut(e,a)){e.preventDefault()}if(ct(s,a,e)){return}var t=ae(e);t.triggerSpec=s;if(t.handledFor==null){t.handledFor=[]}if(t.handledFor.indexOf(a)<0){t.handledFor.push(a);if(s.consume){e.stopPropagation()}if(s.target&&e.target){if(!h(e.target,s.target)){return}}if(s.once){if(u.triggeredOnce){return}else{u.triggeredOnce=true}}if(s.changed){var r=ae(n);if(r.lastValue===n.value){return}r.lastValue=n.value}if(u.delayed){clearTimeout(u.delayed)}if(u.throttle){return}if(s.throttle>0){if(!u.throttle){o(a,e);u.throttle=setTimeout(function(){u.throttle=null},s.throttle)}}else if(s.delay>0){u.delayed=setTimeout(function(){o(a,e)},s.delay)}else{ce(a,"htmx:trigger");o(a,e)}}};if(e.listenerInfos==null){e.listenerInfos=[]}e.listenerInfos.push({trigger:s.trigger,listener:i,on:n});n.addEventListener(s.trigger,i)})}var vt=false;var dt=null;function gt(){if(!dt){dt=function(){vt=true};window.addEventListener("scroll",dt);setInterval(function(){if(vt){vt=false;oe(re().querySelectorAll("[hx-trigger='revealed'],[data-hx-trigger='revealed']"),function(e){pt(e)})}},200)}}function pt(t){if(!o(t,"data-hx-revealed")&&X(t)){t.setAttribute("data-hx-revealed","true");var e=ae(t);if(e.initHash){ce(t,"revealed")}else{t.addEventListener("htmx:afterProcessNode",function(e){ce(t,"revealed")},{once:true})}}}function mt(e,t,r){var n=D(r);for(var i=0;i=0){var t=wt(n);setTimeout(function(){xt(s,r,n+1)},t)}};t.onopen=function(e){n=0};ae(s).webSocket=t;t.addEventListener("message",function(e){if(yt(s)){return}var t=e.data;R(s,function(e){t=e.transformResponse(t,null,s)});var r=T(s);var n=l(t);var i=M(n.children);for(var a=0;a0){ce(u,"htmx:validation:halted",i);return}t.send(JSON.stringify(l));if(ut(e,u)){e.preventDefault()}})}else{fe(u,"htmx:noWebSocketSourceError")}}function wt(e){var t=Q.config.wsReconnectDelay;if(typeof t==="function"){return t(e)}if(t==="full-jitter"){var r=Math.min(e,6);var n=1e3*Math.pow(2,r);return n*Math.random()}b('htmx.config.wsReconnectDelay must either be a function or the string "full-jitter"')}function St(e,t,r){var n=D(r);for(var i=0;i0){setTimeout(i,n)}else{i()}}function Ht(t,i,e){var a=false;oe(w,function(r){if(o(t,"hx-"+r)){var n=te(t,"hx-"+r);a=true;i.path=n;i.verb=r;e.forEach(function(e){Lt(t,e,i,function(e,t){if(v(e,Q.config.disableSelector)){m(e);return}he(r,n,e,t)})})}});return a}function Lt(n,e,t,r){if(e.sseEvent){Rt(n,r,e.sseEvent)}else if(e.trigger==="revealed"){gt();ht(n,r,t,e);pt(n)}else if(e.trigger==="intersect"){var i={};if(e.root){i.root=ue(n,e.root)}if(e.threshold){i.threshold=parseFloat(e.threshold)}var a=new IntersectionObserver(function(e){for(var t=0;t0){t.polling=true;ot(n,r,e)}else{ht(n,r,t,e)}}function At(e){if(!e.htmxExecuted&&Q.config.allowScriptTags&&(e.type==="text/javascript"||e.type==="module"||e.type==="")){var t=re().createElement("script");oe(e.attributes,function(e){t.setAttribute(e.name,e.value)});t.textContent=e.textContent;t.async=false;if(Q.config.inlineScriptNonce){t.nonce=Q.config.inlineScriptNonce}var r=e.parentElement;try{r.insertBefore(t,e)}catch(e){b(e)}finally{if(e.parentElement){e.parentElement.removeChild(e)}}}}function Nt(e){if(h(e,"script")){At(e)}oe(f(e,"script"),function(e){At(e)})}function It(e){var t=e.attributes;if(!t){return false}for(var r=0;r0){var o=n.shift();var s=o.match(/^\s*([a-zA-Z:\-\.]+:)(.*)/);if(a===0&&s){o.split(":");i=s[1].slice(0,-1);r[i]=s[2]}else{r[i]+=o}a+=Bt(o)}for(var l in r){Ft(e,l,r[l])}}}function jt(e){Ae(e);for(var t=0;tQ.config.historyCacheSize){i.shift()}while(i.length>0){try{localStorage.setItem("htmx-history-cache",JSON.stringify(i));break}catch(e){fe(re().body,"htmx:historyCacheError",{cause:e,cache:i});i.shift()}}}function Yt(e){if(!U()){return null}e=B(e);var t=E(localStorage.getItem("htmx-history-cache"))||[];for(var r=0;r=200&&this.status<400){ce(re().body,"htmx:historyCacheMissLoad",o);var e=l(this.response);e=e.querySelector("[hx-history-elt],[data-hx-history-elt]")||e;var t=Zt();var r=T(t);var n=Ve(this.response);if(n){var i=C("title");if(i){i.innerHTML=n}else{window.document.title=n}}Ue(t,e,r);nr(r.tasks);Jt=a;ce(re().body,"htmx:historyRestore",{path:a,cacheMiss:true,serverResponse:this.response})}else{fe(re().body,"htmx:historyCacheMissLoadError",o)}};e.send()}function ar(e){er();e=e||location.pathname+location.search;var t=Yt(e);if(t){var r=l(t.content);var n=Zt();var i=T(n);Ue(n,r,i);nr(i.tasks);document.title=t.title;setTimeout(function(){window.scrollTo(0,t.scroll)},0);Jt=e;ce(re().body,"htmx:historyRestore",{path:e,item:t})}else{if(Q.config.refreshOnHistoryMiss){window.location.reload(true)}else{ir(e)}}}function or(e){var t=me(e,"hx-indicator");if(t==null){t=[e]}oe(t,function(e){var t=ae(e);t.requestCount=(t.requestCount||0)+1;e.classList["add"].call(e.classList,Q.config.requestClass)});return t}function sr(e){var t=me(e,"hx-disabled-elt");if(t==null){t=[]}oe(t,function(e){var t=ae(e);t.requestCount=(t.requestCount||0)+1;e.setAttribute("disabled","")});return t}function lr(e,t){oe(e,function(e){var t=ae(e);t.requestCount=(t.requestCount||0)-1;if(t.requestCount===0){e.classList["remove"].call(e.classList,Q.config.requestClass)}});oe(t,function(e){var t=ae(e);t.requestCount=(t.requestCount||0)-1;if(t.requestCount===0){e.removeAttribute("disabled")}})}function ur(e,t){for(var r=0;r=0}function wr(e,t){var r=t?t:ne(e,"hx-swap");var n={swapStyle:ae(e).boosted?"innerHTML":Q.config.defaultSwapStyle,swapDelay:Q.config.defaultSwapDelay,settleDelay:Q.config.defaultSettleDelay};if(Q.config.scrollIntoViewOnBoost&&ae(e).boosted&&!br(e)){n["show"]="top"}if(r){var i=D(r);if(i.length>0){for(var a=0;a0?l.join(":"):null;n["scroll"]=u;n["scrollTarget"]=f}else if(o.indexOf("show:")===0){var c=o.substr(5);var l=c.split(":");var h=l.pop();var f=l.length>0?l.join(":"):null;n["show"]=h;n["showTarget"]=f}else if(o.indexOf("focus-scroll:")===0){var v=o.substr("focus-scroll:".length);n["focusScroll"]=v=="true"}else if(a==0){n["swapStyle"]=o}else{b("Unknown modifier in hx-swap: "+o)}}}}return n}function Sr(e){return ne(e,"hx-encoding")==="multipart/form-data"||h(e,"form")&&ee(e,"enctype")==="multipart/form-data"}function Er(t,r,n){var i=null;R(r,function(e){if(i==null){i=e.encodeParameters(t,n,r)}});if(i!=null){return i}else{if(Sr(r)){return mr(n)}else{return pr(n)}}}function T(e){return{tasks:[],elts:[e]}}function Cr(e,t){var r=e[0];var n=e[e.length-1];if(t.scroll){var i=null;if(t.scrollTarget){i=ue(r,t.scrollTarget)}if(t.scroll==="top"&&(r||i)){i=i||r;i.scrollTop=0}if(t.scroll==="bottom"&&(n||i)){i=i||n;i.scrollTop=i.scrollHeight}}if(t.show){var i=null;if(t.showTarget){var a=t.showTarget;if(t.showTarget==="window"){a="body"}i=ue(r,a)}if(t.show==="top"&&(r||i)){i=i||r;i.scrollIntoView({block:"start",behavior:Q.config.scrollBehavior})}if(t.show==="bottom"&&(n||i)){i=i||n;i.scrollIntoView({block:"end",behavior:Q.config.scrollBehavior})}}}function Rr(e,t,r,n){if(n==null){n={}}if(e==null){return n}var i=te(e,t);if(i){var a=i.trim();var o=r;if(a==="unset"){return null}if(a.indexOf("javascript:")===0){a=a.substr(11);o=true}else if(a.indexOf("js:")===0){a=a.substr(3);o=true}if(a.indexOf("{")!==0){a="{"+a+"}"}var s;if(o){s=Tr(e,function(){return Function("return ("+a+")")()},{})}else{s=E(a)}for(var l in s){if(s.hasOwnProperty(l)){if(n[l]==null){n[l]=s[l]}}}}return Rr(u(e),t,r,n)}function Tr(e,t,r){if(Q.config.allowEval){return t()}else{fe(e,"htmx:evalDisallowedError");return r}}function Or(e,t){return Rr(e,"hx-vars",true,t)}function qr(e,t){return Rr(e,"hx-vals",false,t)}function Hr(e){return le(Or(e),qr(e))}function Lr(t,r,n){if(n!==null){try{t.setRequestHeader(r,n)}catch(e){t.setRequestHeader(r,encodeURIComponent(n));t.setRequestHeader(r+"-URI-AutoEncoded","true")}}}function Ar(t){if(t.responseURL&&typeof URL!=="undefined"){try{var e=new URL(t.responseURL);return e.pathname+e.search}catch(e){fe(re().body,"htmx:badResponseUrl",{url:t.responseURL})}}}function O(e,t){return t.test(e.getAllResponseHeaders())}function Nr(e,t,r){e=e.toLowerCase();if(r){if(r instanceof Element||I(r,"String")){return he(e,t,null,null,{targetOverride:p(r),returnPromise:true})}else{return he(e,t,p(r.source),r.event,{handler:r.handler,headers:r.headers,values:r.values,targetOverride:p(r.target),swapOverride:r.swap,select:r.select,returnPromise:true})}}else{return he(e,t,null,null,{returnPromise:true})}}function Ir(e){var t=[];while(e){t.push(e);e=e.parentElement}return t}function kr(e,t,r){var n;var i;if(typeof URL==="function"){i=new URL(t,document.location.href);var a=document.location.origin;n=a===i.origin}else{i=t;n=g(t,document.location.origin)}if(Q.config.selfRequestsOnly){if(!n){return false}}return ce(e,"htmx:validateUrl",le({url:i,sameHost:n},r))}function he(t,r,n,i,a,e){var o=null;var s=null;a=a!=null?a:{};if(a.returnPromise&&typeof Promise!=="undefined"){var l=new Promise(function(e,t){o=e;s=t})}if(n==null){n=re().body}var M=a.handler||Mr;var X=a.select||null;if(!se(n)){ie(o);return l}var u=a.targetOverride||ye(n);if(u==null||u==pe){fe(n,"htmx:targetError",{target:te(n,"hx-target")});ie(s);return l}var f=ae(n);var c=f.lastButtonClicked;if(c){var h=ee(c,"formaction");if(h!=null){r=h}var v=ee(c,"formmethod");if(v!=null){if(v.toLowerCase()!=="dialog"){t=v}}}var d=ne(n,"hx-confirm");if(e===undefined){var D=function(e){return he(t,r,n,i,a,!!e)};var U={target:u,elt:n,path:r,verb:t,triggeringEvent:i,etc:a,issueRequest:D,question:d};if(ce(n,"htmx:confirm",U)===false){ie(o);return l}}var g=n;var p=ne(n,"hx-sync");var m=null;var x=false;if(p){var B=p.split(":");var F=B[0].trim();if(F==="this"){g=xe(n,"hx-sync")}else{g=ue(n,F)}p=(B[1]||"drop").trim();f=ae(g);if(p==="drop"&&f.xhr&&f.abortable!==true){ie(o);return l}else if(p==="abort"){if(f.xhr){ie(o);return l}else{x=true}}else if(p==="replace"){ce(g,"htmx:abort")}else if(p.indexOf("queue")===0){var V=p.split(" ");m=(V[1]||"last").trim()}}if(f.xhr){if(f.abortable){ce(g,"htmx:abort")}else{if(m==null){if(i){var y=ae(i);if(y&&y.triggerSpec&&y.triggerSpec.queue){m=y.triggerSpec.queue}}if(m==null){m="last"}}if(f.queuedRequests==null){f.queuedRequests=[]}if(m==="first"&&f.queuedRequests.length===0){f.queuedRequests.push(function(){he(t,r,n,i,a)})}else if(m==="all"){f.queuedRequests.push(function(){he(t,r,n,i,a)})}else if(m==="last"){f.queuedRequests=[];f.queuedRequests.push(function(){he(t,r,n,i,a)})}ie(o);return l}}var b=new XMLHttpRequest;f.xhr=b;f.abortable=x;var w=function(){f.xhr=null;f.abortable=false;if(f.queuedRequests!=null&&f.queuedRequests.length>0){var e=f.queuedRequests.shift();e()}};var j=ne(n,"hx-prompt");if(j){var S=prompt(j);if(S===null||!ce(n,"htmx:prompt",{prompt:S,target:u})){ie(o);w();return l}}if(d&&!e){if(!confirm(d)){ie(o);w();return l}}var E=xr(n,u,S);if(t!=="get"&&!Sr(n)){E["Content-Type"]="application/x-www-form-urlencoded"}if(a.headers){E=le(E,a.headers)}var _=dr(n,t);var C=_.errors;var R=_.values;if(a.values){R=le(R,a.values)}var z=Hr(n);var $=le(R,z);var T=yr($,n);if(Q.config.getCacheBusterParam&&t==="get"){T["org.htmx.cache-buster"]=ee(u,"id")||"true"}if(r==null||r===""){r=re().location.href}var O=Rr(n,"hx-request");var W=ae(n).boosted;var q=Q.config.methodsThatUseUrlParams.indexOf(t)>=0;var H={boosted:W,useUrlParams:q,parameters:T,unfilteredParameters:$,headers:E,target:u,verb:t,errors:C,withCredentials:a.credentials||O.credentials||Q.config.withCredentials,timeout:a.timeout||O.timeout||Q.config.timeout,path:r,triggeringEvent:i};if(!ce(n,"htmx:configRequest",H)){ie(o);w();return l}r=H.path;t=H.verb;E=H.headers;T=H.parameters;C=H.errors;q=H.useUrlParams;if(C&&C.length>0){ce(n,"htmx:validation:halted",H);ie(o);w();return l}var G=r.split("#");var J=G[0];var L=G[1];var A=r;if(q){A=J;var Z=Object.keys(T).length!==0;if(Z){if(A.indexOf("?")<0){A+="?"}else{A+="&"}A+=pr(T);if(L){A+="#"+L}}}if(!kr(n,A,H)){fe(n,"htmx:invalidPath",H);ie(s);return l}b.open(t.toUpperCase(),A,true);b.overrideMimeType("text/html");b.withCredentials=H.withCredentials;b.timeout=H.timeout;if(O.noHeaders){}else{for(var N in E){if(E.hasOwnProperty(N)){var K=E[N];Lr(b,N,K)}}}var I={xhr:b,target:u,requestConfig:H,etc:a,boosted:W,select:X,pathInfo:{requestPath:r,finalRequestPath:A,anchor:L}};b.onload=function(){try{var e=Ir(n);I.pathInfo.responsePath=Ar(b);M(n,I);lr(k,P);ce(n,"htmx:afterRequest",I);ce(n,"htmx:afterOnLoad",I);if(!se(n)){var t=null;while(e.length>0&&t==null){var r=e.shift();if(se(r)){t=r}}if(t){ce(t,"htmx:afterRequest",I);ce(t,"htmx:afterOnLoad",I)}}ie(o);w()}catch(e){fe(n,"htmx:onLoadError",le({error:e},I));throw e}};b.onerror=function(){lr(k,P);fe(n,"htmx:afterRequest",I);fe(n,"htmx:sendError",I);ie(s);w()};b.onabort=function(){lr(k,P);fe(n,"htmx:afterRequest",I);fe(n,"htmx:sendAbort",I);ie(s);w()};b.ontimeout=function(){lr(k,P);fe(n,"htmx:afterRequest",I);fe(n,"htmx:timeout",I);ie(s);w()};if(!ce(n,"htmx:beforeRequest",I)){ie(o);w();return l}var k=or(n);var P=sr(n);oe(["loadstart","loadend","progress","abort"],function(t){oe([b,b.upload],function(e){e.addEventListener(t,function(e){ce(n,"htmx:xhr:"+t,{lengthComputable:e.lengthComputable,loaded:e.loaded,total:e.total})})})});ce(n,"htmx:beforeSend",I);var Y=q?null:Er(b,n,T);b.send(Y);return l}function Pr(e,t){var r=t.xhr;var n=null;var i=null;if(O(r,/HX-Push:/i)){n=r.getResponseHeader("HX-Push");i="push"}else if(O(r,/HX-Push-Url:/i)){n=r.getResponseHeader("HX-Push-Url");i="push"}else if(O(r,/HX-Replace-Url:/i)){n=r.getResponseHeader("HX-Replace-Url");i="replace"}if(n){if(n==="false"){return{}}else{return{type:i,path:n}}}var a=t.pathInfo.finalRequestPath;var o=t.pathInfo.responsePath;var s=ne(e,"hx-push-url");var l=ne(e,"hx-replace-url");var u=ae(e).boosted;var f=null;var c=null;if(s){f="push";c=s}else if(l){f="replace";c=l}else if(u){f="push";c=o||a}if(c){if(c==="false"){return{}}if(c==="true"){c=o||a}if(t.pathInfo.anchor&&c.indexOf("#")===-1){c=c+"#"+t.pathInfo.anchor}return{type:f,path:c}}else{return{}}}function Mr(l,u){var f=u.xhr;var c=u.target;var e=u.etc;var t=u.requestConfig;var h=u.select;if(!ce(l,"htmx:beforeOnLoad",u))return;if(O(f,/HX-Trigger:/i)){_e(f,"HX-Trigger",l)}if(O(f,/HX-Location:/i)){er();var r=f.getResponseHeader("HX-Location");var v;if(r.indexOf("{")===0){v=E(r);r=v["path"];delete v["path"]}Nr("GET",r,v).then(function(){tr(r)});return}var n=O(f,/HX-Refresh:/i)&&"true"===f.getResponseHeader("HX-Refresh");if(O(f,/HX-Redirect:/i)){location.href=f.getResponseHeader("HX-Redirect");n&&location.reload();return}if(n){location.reload();return}if(O(f,/HX-Retarget:/i)){if(f.getResponseHeader("HX-Retarget")==="this"){u.target=l}else{u.target=ue(l,f.getResponseHeader("HX-Retarget"))}}var d=Pr(l,u);var i=f.status>=200&&f.status<400&&f.status!==204;var g=f.response;var a=f.status>=400;var p=Q.config.ignoreTitle;var o=le({shouldSwap:i,serverResponse:g,isError:a,ignoreTitle:p},u);if(!ce(c,"htmx:beforeSwap",o))return;c=o.target;g=o.serverResponse;a=o.isError;p=o.ignoreTitle;u.target=c;u.failed=a;u.successful=!a;if(o.shouldSwap){if(f.status===286){at(l)}R(l,function(e){g=e.transformResponse(g,f,l)});if(d.type){er()}var s=e.swapOverride;if(O(f,/HX-Reswap:/i)){s=f.getResponseHeader("HX-Reswap")}var v=wr(l,s);if(v.hasOwnProperty("ignoreTitle")){p=v.ignoreTitle}c.classList.add(Q.config.swappingClass);var m=null;var x=null;var y=function(){try{var e=document.activeElement;var t={};try{t={elt:e,start:e?e.selectionStart:null,end:e?e.selectionEnd:null}}catch(e){}var r;if(h){r=h}if(O(f,/HX-Reselect:/i)){r=f.getResponseHeader("HX-Reselect")}if(d.type){ce(re().body,"htmx:beforeHistoryUpdate",le({history:d},u));if(d.type==="push"){tr(d.path);ce(re().body,"htmx:pushedIntoHistory",{path:d.path})}else{rr(d.path);ce(re().body,"htmx:replacedInHistory",{path:d.path})}}var n=T(c);je(v.swapStyle,c,l,g,n,r);if(t.elt&&!se(t.elt)&&ee(t.elt,"id")){var i=document.getElementById(ee(t.elt,"id"));var a={preventScroll:v.focusScroll!==undefined?!v.focusScroll:!Q.config.defaultFocusScroll};if(i){if(t.start&&i.setSelectionRange){try{i.setSelectionRange(t.start,t.end)}catch(e){}}i.focus(a)}}c.classList.remove(Q.config.swappingClass);oe(n.elts,function(e){if(e.classList){e.classList.add(Q.config.settlingClass)}ce(e,"htmx:afterSwap",u)});if(O(f,/HX-Trigger-After-Swap:/i)){var o=l;if(!se(l)){o=re().body}_e(f,"HX-Trigger-After-Swap",o)}var s=function(){oe(n.tasks,function(e){e.call()});oe(n.elts,function(e){if(e.classList){e.classList.remove(Q.config.settlingClass)}ce(e,"htmx:afterSettle",u)});if(u.pathInfo.anchor){var e=re().getElementById(u.pathInfo.anchor);if(e){e.scrollIntoView({block:"start",behavior:"auto"})}}if(n.title&&!p){var t=C("title");if(t){t.innerHTML=n.title}else{window.document.title=n.title}}Cr(n.elts,v);if(O(f,/HX-Trigger-After-Settle:/i)){var r=l;if(!se(l)){r=re().body}_e(f,"HX-Trigger-After-Settle",r)}ie(m)};if(v.settleDelay>0){setTimeout(s,v.settleDelay)}else{s()}}catch(e){fe(l,"htmx:swapError",u);ie(x);throw e}};var b=Q.config.globalViewTransitions;if(v.hasOwnProperty("transition")){b=v.transition}if(b&&ce(l,"htmx:beforeTransition",u)&&typeof Promise!=="undefined"&&document.startViewTransition){var w=new Promise(function(e,t){m=e;x=t});var S=y;y=function(){document.startViewTransition(function(){S();return w})}}if(v.swapDelay>0){setTimeout(y,v.swapDelay)}else{y()}}if(a){fe(l,"htmx:responseError",le({error:"Response Status Error Code "+f.status+" from "+u.pathInfo.requestPath},u))}}var Xr={};function Dr(){return{init:function(e){return null},onEvent:function(e,t){return true},transformResponse:function(e,t,r){return e},isInlineSwap:function(e){return false},handleSwap:function(e,t,r,n){return false},encodeParameters:function(e,t,r){return null}}}function Ur(e,t){if(t.init){t.init(r)}Xr[e]=le(Dr(),t)}function Br(e){delete Xr[e]}function Fr(e,r,n){if(e==undefined){return r}if(r==undefined){r=[]}if(n==undefined){n=[]}var t=te(e,"hx-ext");if(t){oe(t.split(","),function(e){e=e.replace(/ /g,"");if(e.slice(0,7)=="ignore:"){n.push(e.slice(7));return}if(n.indexOf(e)<0){var t=Xr[e];if(t&&r.indexOf(t)<0){r.push(t)}}})}return Fr(u(e),r,n)}var Vr=false;re().addEventListener("DOMContentLoaded",function(){Vr=true});function jr(e){if(Vr||re().readyState==="complete"){e()}else{re().addEventListener("DOMContentLoaded",e)}}function _r(){if(Q.config.includeIndicatorStyles!==false){re().head.insertAdjacentHTML("beforeend","")}}function zr(){var e=re().querySelector('meta[name="htmx-config"]');if(e){return E(e.content)}else{return null}}function $r(){var e=zr();if(e){Q.config=le(Q.config,e)}}jr(function(){$r();_r();var e=re().body;zt(e);var t=re().querySelectorAll("[hx-trigger='restored'],[data-hx-trigger='restored']");e.addEventListener("htmx:abort",function(e){var t=e.target;var r=ae(t);if(r&&r.xhr){r.xhr.abort()}});const r=window.onpopstate?window.onpopstate.bind(window):null;window.onpopstate=function(e){if(e.state&&e.state.htmx){ar();oe(t,function(e){ce(e,"htmx:restored",{document:re(),triggerEvent:ce})})}else{if(r){r(e)}}};setTimeout(function(){ce(e,"htmx:load",{});e=null},0)});return Q}()}); \ No newline at end of file diff --git a/src/Controller/FoodOrderController.php b/src/Controller/FoodOrderController.php new file mode 100644 index 0000000..69e3292 --- /dev/null +++ b/src/Controller/FoodOrderController.php @@ -0,0 +1,72 @@ +render('food_order/index.html.twig', [ + 'food_orders' => $foodOrderRepository->findAll(), + ]); + } + + #[Route('/new', name: 'app_food_order_new', methods: ['GET', 'POST'])] + public function new(Request $request, EntityManagerInterface $entityManager): Response + { + $foodOrder = new FoodOrder; + $form = $this->createForm(FoodOrderType::class, $foodOrder, [ + 'action' => $this->generateUrl('app_food_order_new'), + ]); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $entityManager->persist($foodOrder); + $entityManager->flush(); + + return $this->redirectToRoute('app_food_order_index', [], Response::HTTP_SEE_OTHER); + } + + return $this->render('food_order/new.html.twig', [ + 'food_order' => $foodOrder, + 'form' => $form, + ]); + } + + #[Route('/{id}', name: 'app_food_order_show', methods: ['GET'])] + public function show(FoodOrder $foodOrder): Response + { + return $this->render('food_order/show.html.twig', [ + 'food_order' => $foodOrder, + ]); + } + + #[Route('/{id}/close', name: 'app_food_order_close', methods: ['GET'])] + public function close(FoodOrder $foodOrder, FoodOrderRepository $repository): Response + { + $repository->save($foodOrder->close()); + return $this->redirectToRoute('app_food_order_show', [ + 'id' => $foodOrder->getId(), + ], Response::HTTP_SEE_OTHER); + } + + #[Route('/{id}/open', name: 'app_food_order_open', methods: ['GET'])] + public function open(FoodOrder $foodOrder, FoodOrderRepository $repository): Response + { + $repository->save($foodOrder->open()); + return $this->redirectToRoute('app_food_order_show', [ + 'id' => $foodOrder->getId(), + ], Response::HTTP_SEE_OTHER); + } +} diff --git a/src/Controller/FoodVendorController.php b/src/Controller/FoodVendorController.php index 9fece5a..0cb790a 100644 --- a/src/Controller/FoodVendorController.php +++ b/src/Controller/FoodVendorController.php @@ -67,15 +67,4 @@ final class FoodVendorController extends AbstractController 'form' => $form, ]); } - - #[Route('/{id}', name: 'app_food_vendor_delete', methods: ['POST'])] - public function delete(Request $request, FoodVendor $foodVendor, EntityManagerInterface $entityManager): Response - { - if ($this->isCsrfTokenValid('delete' . $foodVendor->getId(), $request->getPayload()->getString('_token'))) { - $entityManager->remove($foodVendor); - $entityManager->flush(); - } - - return $this->redirectToRoute('app_food_vendor_index', [], Response::HTTP_SEE_OTHER); - } } diff --git a/src/Controller/Home.php b/src/Controller/Home.php deleted file mode 100644 index 364aea6..0000000 --- a/src/Controller/Home.php +++ /dev/null @@ -1,15 +0,0 @@ -Halloo'); - } -} diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php new file mode 100644 index 0000000..a9bd31e --- /dev/null +++ b/src/Controller/HomeController.php @@ -0,0 +1,17 @@ +generate('app_food_order_index')); + } +} diff --git a/src/Controller/OrderItemController.php b/src/Controller/OrderItemController.php new file mode 100644 index 0000000..8658048 --- /dev/null +++ b/src/Controller/OrderItemController.php @@ -0,0 +1,81 @@ +render('order_item/index.html.twig', [ + 'order_items' => $orderItemRepository->findAll(), + ]); + } + + #[Route('/new', name: 'app_order_item_new', methods: ['GET', 'POST'])] + public function new(Request $request, EntityManagerInterface $entityManager): Response + { + $orderItem = new OrderItem; + $form = $this->createForm(OrderItemType::class, $orderItem); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $entityManager->persist($orderItem); + $entityManager->flush(); + + return $this->redirectToRoute('app_order_item_index', [], Response::HTTP_SEE_OTHER); + } + + return $this->render('order_item/new.html.twig', [ + 'order_item' => $orderItem, + 'form' => $form, + ]); + } + + #[Route('/{id}', name: 'app_order_item_show', methods: ['GET'])] + public function show(OrderItem $orderItem): Response + { + return $this->render('order_item/show.html.twig', [ + 'order_item' => $orderItem, + ]); + } + + #[Route('/{id}/edit', name: 'app_order_item_edit', methods: ['GET', 'POST'])] + public function edit(Request $request, OrderItem $orderItem, EntityManagerInterface $entityManager): Response + { + $form = $this->createForm(OrderItemType::class, $orderItem); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $entityManager->flush(); + + return $this->redirectToRoute('app_order_item_index', [], Response::HTTP_SEE_OTHER); + } + + return $this->render('order_item/edit.html.twig', [ + 'order_item' => $orderItem, + 'form' => $form, + ]); + } + + #[Route('/{id}', name: 'app_order_item_delete', methods: ['POST'])] + public function delete(Request $request, OrderItem $orderItem, EntityManagerInterface $entityManager): Response + { + if ($this->isCsrfTokenValid('delete' . $orderItem->getId(), $request->getPayload()->getString('_token'))) { + $entityManager->remove($orderItem); + $entityManager->flush(); + } + + return $this->redirectToRoute('app_order_item_index', [], Response::HTTP_SEE_OTHER); + } +} diff --git a/src/Entity/FoodOrder.php b/src/Entity/FoodOrder.php new file mode 100644 index 0000000..978afa9 --- /dev/null +++ b/src/Entity/FoodOrder.php @@ -0,0 +1,128 @@ + + */ + #[ORM\OneToMany(targetEntity: OrderItem::class, mappedBy: 'foodOrder', orphanRemoval: true)] + private Collection $orderItems; + + public function __construct() + { + $this->createdAt = new DateTimeImmutable; + $this->orderItems = new ArrayCollection; + } + + public function getId(): Ulid|null + { + return $this->id; + } + + public function getCreatedAt(): DateTimeImmutable|null + { + return $this->createdAt; + } + + public function setCreatedAt(DateTimeImmutable $createdAt): static + { + $this->createdAt = $createdAt; + + return $this; + } + + public function getClosedAt(): DateTimeImmutable|null + { + return $this->closedAt; + } + + public function setClosedAt(DateTimeImmutable|null $closedAt): static + { + $this->closedAt = $closedAt; + + return $this; + } + + public function isClosed(): bool + { + return $this->closedAt instanceof DateTimeImmutable; + } + + public function close(): static + { + return $this->setClosedAt(new DateTimeImmutable); + } + + public function open(): static + { + return $this->setClosedAt(null); + } + + public function getFoodVendor(): FoodVendor|null + { + return $this->foodVendor; + } + + public function setFoodVendor(FoodVendor|null $foodVendor): static + { + $this->foodVendor = $foodVendor; + + return $this; + } + + /** + * @return Collection + */ + public function getOrderItems(): Collection + { + return $this->orderItems; + } + + public function addOrderItem(OrderItem $orderItem): static + { + if (! $this->orderItems->contains($orderItem)) { + $this->orderItems->add($orderItem); + $orderItem->setFoodOrder($this); + } + + return $this; + } + + public function removeOrderItem(OrderItem $orderItem): static + { + // set the owning side to null (unless already changed) + if ($this->orderItems->removeElement($orderItem) && $orderItem->getFoodOrder() === $this) { + $orderItem->setFoodOrder(null); + } + + return $this; + } +} diff --git a/src/Entity/FoodVendor.php b/src/Entity/FoodVendor.php index f71d784..67a8018 100644 --- a/src/Entity/FoodVendor.php +++ b/src/Entity/FoodVendor.php @@ -3,6 +3,8 @@ namespace App\Entity; use App\Repository\FoodVendorRepository; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator; use Symfony\Bridge\Doctrine\Types\UlidType; @@ -20,6 +22,17 @@ class FoodVendor #[ORM\Column(length: 50)] private string|null $name = null; + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: FoodOrder::class, mappedBy: 'foodVendor', orphanRemoval: true)] + private Collection $foodOrders; + + public function __construct() + { + $this->foodOrders = new ArrayCollection; + } + public function getId(): Ulid|null { return $this->id; @@ -36,4 +49,32 @@ class FoodVendor return $this; } + + /** + * @return Collection + */ + public function getFoodOrders(): Collection + { + return $this->foodOrders; + } + + public function addFoodOrder(FoodOrder $foodOrder): static + { + if (! $this->foodOrders->contains($foodOrder)) { + $this->foodOrders->add($foodOrder); + $foodOrder->setFoodVendor($this); + } + + return $this; + } + + public function removeFoodOrder(FoodOrder $foodOrder): static + { + // set the owning side to null (unless already changed) + if ($this->foodOrders->removeElement($foodOrder) && $foodOrder->getFoodVendor() === $this) { + $foodOrder->setFoodVendor(null); + } + + return $this; + } } diff --git a/src/Entity/OrderItem.php b/src/Entity/OrderItem.php new file mode 100644 index 0000000..4bff23a --- /dev/null +++ b/src/Entity/OrderItem.php @@ -0,0 +1,70 @@ +id; + } + + public function getName(): string|null + { + return $this->name; + } + + public function setName(string $name): static + { + $this->name = $name; + + return $this; + } + + public function getExtras(): string|null + { + return $this->extras; + } + + public function setExtras(string|null $extras): static + { + $this->extras = $extras; + + return $this; + } + + public function getFoodOrder(): FoodOrder|null + { + return $this->foodOrder; + } + + public function setFoodOrder(FoodOrder|null $foodOrder): static + { + $this->foodOrder = $foodOrder; + + return $this; + } +} diff --git a/src/Form/FoodOrderType.php b/src/Form/FoodOrderType.php new file mode 100644 index 0000000..bfe9dc4 --- /dev/null +++ b/src/Form/FoodOrderType.php @@ -0,0 +1,37 @@ +add('foodVendor', EntityType::class, [ + 'class' => FoodVendor::class, + 'choice_label' => 'name', + ]) + ; + if ($action !== null) { + $builder->setAction($action); + } + } + + #[Override] + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => FoodOrder::class, + ]); + } +} diff --git a/src/Form/OrderItemType.php b/src/Form/OrderItemType.php new file mode 100644 index 0000000..4716baf --- /dev/null +++ b/src/Form/OrderItemType.php @@ -0,0 +1,29 @@ +add('name') + ->add('extras') + ; + } + + #[Override] + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => OrderItem::class, + ]); + } +} diff --git a/src/Repository/FoodOrderRepository.php b/src/Repository/FoodOrderRepository.php new file mode 100644 index 0000000..33407c8 --- /dev/null +++ b/src/Repository/FoodOrderRepository.php @@ -0,0 +1,26 @@ + + */ +final class FoodOrderRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, FoodOrder::class); + } + + public function save(FoodOrder $order): void + { + $this->getEntityManager() + ->persist($order); + $this->getEntityManager() + ->flush(); + } +} diff --git a/src/Repository/OrderItemRepository.php b/src/Repository/OrderItemRepository.php new file mode 100644 index 0000000..dedc0d5 --- /dev/null +++ b/src/Repository/OrderItemRepository.php @@ -0,0 +1,43 @@ + + */ +final class OrderItemRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, OrderItem::class); + } + + // /** + // * @return OrderItem[] Returns an array of OrderItem objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('o') + // ->andWhere('o.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('o.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?OrderItem + // { + // return $this->createQueryBuilder('o') + // ->andWhere('o.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/templates/_form.html.twig b/templates/_form.html.twig new file mode 100644 index 0000000..bf20b98 --- /dev/null +++ b/templates/_form.html.twig @@ -0,0 +1,4 @@ +{{ form_start(form) }} + {{ form_widget(form) }} + +{{ form_end(form) }} diff --git a/templates/base.html.twig b/templates/base.html.twig index c675a2d..60b00f9 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -4,9 +4,19 @@ {% block title %}Welcome!{% endblock %} - + + +
+ + +
+
{% block body %}{% endblock %} - +
+ diff --git a/templates/food_order/edit.html.twig b/templates/food_order/edit.html.twig new file mode 100644 index 0000000..8200420 --- /dev/null +++ b/templates/food_order/edit.html.twig @@ -0,0 +1,12 @@ +{% extends 'base.html.twig' %} + +{% block title %}Edit FoodOrder{% endblock %} + +{% block body %} +

Edit FoodOrder

+ + {{ include('_form.html.twig', {'button_label': 'Update'}) }} + + back to list + +{% endblock %} diff --git a/templates/food_order/index.html.twig b/templates/food_order/index.html.twig new file mode 100644 index 0000000..1a80bb5 --- /dev/null +++ b/templates/food_order/index.html.twig @@ -0,0 +1,34 @@ +{% extends 'base.html.twig' %} + +{% block title %}FoodOrder index{% endblock %} + +{% block body %} +

FoodOrder index

+ + + + + + + + + + + + {% for food_order in food_orders %} + {{ include('food_order/table_row.html.twig') }} + {% else %} + + + + {% endfor %} + +
VendorCreatedAtClosedAtactions
no records found
+
+ +
+{% endblock %} diff --git a/templates/food_order/new.html.twig b/templates/food_order/new.html.twig new file mode 100644 index 0000000..72ed804 --- /dev/null +++ b/templates/food_order/new.html.twig @@ -0,0 +1,2 @@ +{{ include('_form.html.twig') }} + diff --git a/templates/food_order/show.html.twig b/templates/food_order/show.html.twig new file mode 100644 index 0000000..b058205 --- /dev/null +++ b/templates/food_order/show.html.twig @@ -0,0 +1,31 @@ +{% extends 'base.html.twig' %} + +{% block title %}FoodOrder{% endblock %} + +{% block body %} +

FoodOrder

+ + + + + + + + + + + + + + + + +
Vendor{{ food_order.foodVendor.name }}
CreatedAt{{ food_order.createdAt ? food_order.createdAt|date('Y-m-d H:i:s') : '' }}
ClosedAt{{ food_order.closedAt ? food_order.closedAt|date('Y-m-d H:i:s') : '' }}
+ + back to list + {% if(food_order.isClosed) %} + reopen + {% else %} + close + {% endif %} +{% endblock %} diff --git a/templates/food_order/table_row.html.twig b/templates/food_order/table_row.html.twig new file mode 100644 index 0000000..e42bcb9 --- /dev/null +++ b/templates/food_order/table_row.html.twig @@ -0,0 +1,8 @@ + + {{ food_order.foodVendor.name }} + {{ food_order.createdAt ? food_order.createdAt|date('Y-m-d H:i:s') : '' }} + {{ food_order.closedAt ? food_order.closedAt|date('Y-m-d H:i:s') : '' }} + + show + + \ No newline at end of file diff --git a/templates/food_vendor/_delete_form.html.twig b/templates/food_vendor/_delete_form.html.twig deleted file mode 100644 index cdf1262..0000000 --- a/templates/food_vendor/_delete_form.html.twig +++ /dev/null @@ -1,4 +0,0 @@ -
- - -
diff --git a/templates/food_vendor/show.html.twig b/templates/food_vendor/show.html.twig index e55fb96..a14b226 100644 --- a/templates/food_vendor/show.html.twig +++ b/templates/food_vendor/show.html.twig @@ -21,6 +21,4 @@ back to list edit - - {{ include('food_vendor/_delete_form.html.twig') }} {% endblock %} diff --git a/templates/order_item/_delete_form.html.twig b/templates/order_item/_delete_form.html.twig new file mode 100644 index 0000000..a36a5a5 --- /dev/null +++ b/templates/order_item/_delete_form.html.twig @@ -0,0 +1,4 @@ +
+ + +
diff --git a/templates/order_item/_form.html.twig b/templates/order_item/_form.html.twig new file mode 100644 index 0000000..bf20b98 --- /dev/null +++ b/templates/order_item/_form.html.twig @@ -0,0 +1,4 @@ +{{ form_start(form) }} + {{ form_widget(form) }} + +{{ form_end(form) }} diff --git a/templates/order_item/edit.html.twig b/templates/order_item/edit.html.twig new file mode 100644 index 0000000..c640aec --- /dev/null +++ b/templates/order_item/edit.html.twig @@ -0,0 +1,13 @@ +{% extends 'base.html.twig' %} + +{% block title %}Edit OrderItem{% endblock %} + +{% block body %} +

Edit OrderItem

+ + {{ include('order_item/_form.html.twig', {'button_label': 'Update'}) }} + + back to list + + {{ include('order_item/_delete_form.html.twig') }} +{% endblock %} diff --git a/templates/order_item/index.html.twig b/templates/order_item/index.html.twig new file mode 100644 index 0000000..feace1e --- /dev/null +++ b/templates/order_item/index.html.twig @@ -0,0 +1,37 @@ +{% extends 'base.html.twig' %} + +{% block title %}OrderItem index{% endblock %} + +{% block body %} +

OrderItem index

+ + + + + + + + + + + + {% for order_item in order_items %} + + + + + + + {% else %} + + + + {% endfor %} + +
IdNameExtrasactions
{{ order_item.id }}{{ order_item.name }}{{ order_item.extras }} + show + edit +
no records found
+ + Create new +{% endblock %} diff --git a/templates/order_item/new.html.twig b/templates/order_item/new.html.twig new file mode 100644 index 0000000..0e9cf7e --- /dev/null +++ b/templates/order_item/new.html.twig @@ -0,0 +1,11 @@ +{% extends 'base.html.twig' %} + +{% block title %}New OrderItem{% endblock %} + +{% block body %} +

Create new OrderItem

+ + {{ include('order_item/_form.html.twig') }} + + back to list +{% endblock %} diff --git a/templates/order_item/show.html.twig b/templates/order_item/show.html.twig new file mode 100644 index 0000000..2612685 --- /dev/null +++ b/templates/order_item/show.html.twig @@ -0,0 +1,30 @@ +{% extends 'base.html.twig' %} + +{% block title %}OrderItem{% endblock %} + +{% block body %} +

OrderItem

+ + + + + + + + + + + + + + + + +
Id{{ order_item.id }}
Name{{ order_item.name }}
Extras{{ order_item.extras }}
+ + back to list + + edit + + {{ include('order_item/_delete_form.html.twig') }} +{% endblock %} diff --git a/tests/Controller/FoodOrderControllerTest.php b/tests/Controller/FoodOrderControllerTest.php new file mode 100644 index 0000000..4e81f23 --- /dev/null +++ b/tests/Controller/FoodOrderControllerTest.php @@ -0,0 +1,114 @@ +client->request('GET', $this->path); + + self::assertResponseStatusCodeSame(200); + self::assertPageTitleContains('FoodOrder index'); + + // Use the $crawler to perform additional assertions e.g. + // self::assertSame('Some text on the page', $crawler->filter('.p')->first()); + } + + public function testNew(): void + { + $this->markTestIncomplete(); + $this->client->request('GET', sprintf('%snew', $this->path)); + + self::assertResponseStatusCodeSame(200); + + $this->client->submitForm('Save', [ + 'food_order[createdAt]' => 'Testing', + 'food_order[closedAt]' => 'Testing', + 'food_order[foodVendor]' => 'Testing', + ]); + + self::assertResponseRedirects($this->path); + + self::assertSame(1, $this->repository->count([])); + } + + public function testShow(): void + { + $this->markTestIncomplete(); + $fixture = new FoodOrder; + $fixture->setCreatedAt('My Title'); + $fixture->setClosedAt('My Title'); + $fixture->setFoodVendor('My Title'); + + $this->manager->persist($fixture); + $this->manager->flush(); + + $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId())); + + self::assertResponseStatusCodeSame(200); + self::assertPageTitleContains('FoodOrder'); + + // Use assertions to check that the properties are properly displayed. + } + + public function testEdit(): void + { + $this->markTestIncomplete(); + $fixture = new FoodOrder; + $fixture->setCreatedAt('Value'); + $fixture->setClosedAt('Value'); + $fixture->setFoodVendor('Value'); + + $this->manager->persist($fixture); + $this->manager->flush(); + + $this->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId())); + + $this->client->submitForm('Update', [ + 'food_order[createdAt]' => 'Something New', + 'food_order[closedAt]' => 'Something New', + 'food_order[foodVendor]' => 'Something New', + ]); + + self::assertResponseRedirects('/food/order/'); + + $fixture = $this->repository->findAll(); + + self::assertSame('Something New', $fixture[0]->getCreatedAt()); + self::assertSame('Something New', $fixture[0]->getClosedAt()); + self::assertSame('Something New', $fixture[0]->getFoodVendor()); + } + + public function testRemove(): void + { + $this->markTestIncomplete(); + $fixture = new FoodOrder; + $fixture->setCreatedAt('Value'); + $fixture->setClosedAt('Value'); + $fixture->setFoodVendor('Value'); + + $this->manager->persist($fixture); + $this->manager->flush(); + + $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId())); + $this->client->submitForm('Delete'); + + self::assertResponseRedirects('/food/order/'); + self::assertSame(0, $this->repository->count([])); + } +} diff --git a/tests/Controller/FoodVendorControllerTest.php b/tests/Controller/FoodVendorControllerTest.php index c923549..1c7514d 100644 --- a/tests/Controller/FoodVendorControllerTest.php +++ b/tests/Controller/FoodVendorControllerTest.php @@ -3,43 +3,15 @@ namespace App\Test\Controller; use App\Entity\FoodVendor; -use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\EntityRepository; -use Doctrine\ORM\Tools\SchemaTool; +use App\Tests\DbWebTest; use Override; -use Symfony\Bundle\FrameworkBundle\KernelBrowser; -use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use function sprintf; -final class FoodVendorControllerTest extends WebTestCase +final class FoodVendorControllerTest extends DbWebTest { - private KernelBrowser $client; - private EntityManagerInterface $manager; - private EntityRepository $repository; private string $path = '/food/vendor/'; - private function initDataBase(): void - { - (new SchemaTool($this->manager)) - ->createSchema($this->manager->getMetadataFactory()->getAllMetadata()); - } - - #[Override] - protected function setUp(): void - { - $this->client = static::createClient(); - $this->manager = static::getContainer()->get('doctrine')->getManager(); - $this->initDataBase(); - $this->repository = $this->manager->getRepository(FoodVendor::class); - - foreach ($this->repository->findAll() as $object) { - $this->manager->remove($object); - } - - $this->manager->flush(); - } - public function testIndex(): void { $this->client->request('GET', $this->path); @@ -121,4 +93,10 @@ final class FoodVendorControllerTest extends WebTestCase self::assertResponseRedirects('/food/vendor/'); self::assertSame(0, $this->repository->count([])); } + + #[Override] + public function getEntityClass(): string + { + return FoodVendor::class; + } } diff --git a/tests/Controller/HomeTest.php b/tests/Controller/HomeTest.php deleted file mode 100644 index cfae673..0000000 --- a/tests/Controller/HomeTest.php +++ /dev/null @@ -1,17 +0,0 @@ -request('GET', '/'); - - $this->assertResponseIsSuccessful(); - $this->assertSelectorTextContains('h1', 'Halloo'); - } -} diff --git a/tests/Controller/OrderItemControllerTest.php b/tests/Controller/OrderItemControllerTest.php new file mode 100644 index 0000000..32821cd --- /dev/null +++ b/tests/Controller/OrderItemControllerTest.php @@ -0,0 +1,108 @@ +client->request('GET', $this->path); + + self::assertResponseStatusCodeSame(200); + self::assertPageTitleContains('OrderItem index'); + + // Use the $crawler to perform additional assertions e.g. + // self::assertSame('Some text on the page', $crawler->filter('.p')->first()); + } + + public function testNew(): void + { + $this->markTestIncomplete(); + $this->client->request('GET', sprintf('%snew', $this->path)); + + self::assertResponseStatusCodeSame(200); + + $this->client->submitForm('Save', [ + 'order_item[name]' => 'Testing', + 'order_item[extras]' => 'Testing', + ]); + + self::assertResponseRedirects($this->path); + + self::assertSame(1, $this->repository->count([])); + } + + public function testShow(): void + { + $this->markTestIncomplete(); + $fixture = new OrderItem; + $fixture->setName('My Title'); + $fixture->setExtras('My Title'); + + $this->manager->persist($fixture); + $this->manager->flush(); + + $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId())); + + self::assertResponseStatusCodeSame(200); + self::assertPageTitleContains('OrderItem'); + + // Use assertions to check that the properties are properly displayed. + } + + public function testEdit(): void + { + $this->markTestIncomplete(); + $fixture = new OrderItem; + $fixture->setName('Value'); + $fixture->setExtras('Value'); + + $this->manager->persist($fixture); + $this->manager->flush(); + + $this->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId())); + + $this->client->submitForm('Update', [ + 'order_item[name]' => 'Something New', + 'order_item[extras]' => 'Something New', + ]); + + self::assertResponseRedirects('/order/item/'); + + $fixture = $this->repository->findAll(); + + self::assertSame('Something New', $fixture[0]->getName()); + self::assertSame('Something New', $fixture[0]->getExtras()); + } + + public function testRemove(): void + { + $this->markTestIncomplete(); + $fixture = new OrderItem; + $fixture->setName('Value'); + $fixture->setExtras('Value'); + + $this->manager->persist($fixture); + $this->manager->flush(); + + $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId())); + $this->client->submitForm('Delete'); + + self::assertResponseRedirects('/order/item/'); + self::assertSame(0, $this->repository->count([])); + } + + #[Override] + public function getEntityClass(): string + { + return OrderItem::class; + } +} diff --git a/tests/DbWebTest.php b/tests/DbWebTest.php new file mode 100644 index 0000000..c4ebc00 --- /dev/null +++ b/tests/DbWebTest.php @@ -0,0 +1,35 @@ +client = static::createClient(); + $this->manager = static::getContainer()->get('doctrine')->getManager(); + (new SchemaTool($this->manager)) + ->createSchema($this->manager->getMetadataFactory()->getAllMetadata()); + + $this->repository = $this->manager->getRepository($this->getEntityClass()); + foreach ($this->repository->findAll() as $object) { + $this->manager->remove($object); + } + + $this->manager->flush(); + } +} -- 2.39.5