This commit is contained in:
cereci5049 2024-08-16 01:49:10 +05:30
parent 85516cc1a2
commit 1d17000c0f
15 changed files with 26 additions and 182 deletions

View file

@ -11,7 +11,7 @@ proc signup*(ctx: Context): string=
var
user1 = ctx.cookies.getOrDefault("user1", "")
user = getUserFromCookie(user1)
compileTemplateFile(".." / "view" / "signup.nimja", baseDir = getScriptDir())
compileTemplateFile(".." / "view" / "signup.html", baseDir = getScriptDir())
elif ctx.httpMethod == HttpPost:
var
form = ctx.urlForm
@ -29,7 +29,6 @@ proc signup*(ctx: Context): string=
echo firstName, lastName, email, password
if firstName.len == 0 or lastName.len == 0 or email.len == 0 or phone.len == 0 or password.len == 0:
# ctx.send(parseJson("""{"ok": false, "failure": "Missing parameters"}"""))
for a, b in form:
if form[a] == "":
val.name = ""
@ -53,7 +52,7 @@ proc signup*(ctx: Context): string=
)
conn.createPost(user)
ctx &= user
ctx.redirect("/")
ctx &= initCookie("user", $(%* user))
ctx.response.headers.add("HX-Redirect", "/")
else:
ctx.send(parseJson("""{"ok": false, "failure": "Invalid method"}"""))
ctx.send(parseJson("""{"ok": false, "failure": "Invalid method"}"""))

View file

@ -1,5 +1,5 @@
import
mike,
mike,
nimja,
strutils,
json,
@ -22,44 +22,44 @@ load()
user1 = ctx.cookies.getOrDefault("user1", "")
user = getUserFromCookie(user1)
echo user.firstName
compileTemplateFile("view" / "index.nimja", baseDir = getScriptDir())
compileTemplateFile("view" / "index.html", baseDir = getScriptDir())
"/shop" -> get:
var
user1 = ctx.cookies.getOrDefault("user1", "")
user = getUserFromCookie(user1)
compileTemplateFile("view" / "shop.nimja", baseDir = getScriptDir())
compileTemplateFile("view" / "shop.html", baseDir = getScriptDir())
"/contact" -> get:
var
user1 = ctx.cookies.getOrDefault("user1", "")
user = getUserFromCookie(user1)
compileTemplateFile("view" / "contact.nimja", baseDir = getScriptDir())
compileTemplateFile("view" / "contact.html", baseDir = getScriptDir())
"/cart" -> get:
var
user1 = ctx.cookies.getOrDefault("user1", "")
user = getUserFromCookie(user1)
compileTemplateFile("view" / "cart.nimja", baseDir = getScriptDir())
compileTemplateFile("view" / "cart.html", baseDir = getScriptDir())
"/checkout" -> get:
var
user1 = ctx.cookies.getOrDefault("user1", "")
user = getUserFromCookie(user1)
compileTemplateFile("view" / "checkout.nimja", baseDir = getScriptDir())
compileTemplateFile("view" / "checkout.html", baseDir = getScriptDir())
"/shop/:id" -> get:
var
prodId = capitalizeAscii(ctx.pathParams["id"])
user1 = ctx.cookies.getOrDefault("user1", "")
user = getUserFromCookie(user1)
compileTemplateFile("view" / "shop-detail.nimja", baseDir = getScriptDir())
compileTemplateFile("view" / "shop-detail.html", baseDir = getScriptDir())
"/testimonial" -> get:
var
user1 = ctx.cookies.getOrDefault("user1", "")
user = getUserFromCookie(user1)
compileTemplateFile("view" / "testimonial.nimja", baseDir = getScriptDir())
compileTemplateFile("view" / "testimonial.html", baseDir = getScriptDir())
"/signup" -> [get, post]: ctx.signup()
@ -67,7 +67,7 @@ load()
var
user1 = ctx.cookies.getOrDefault("user1", "")
user = getUserFromCookie(user1)
compileTemplateFile("view" / "login.nimja", baseDir = getScriptDir())
compileTemplateFile("view" / "login.html", baseDir = getScriptDir())
"/htmx/login" -> post: ctx.htmxLogin()
@ -79,7 +79,7 @@ load()
var
user1 = ctx.cookies.getOrDefault("user1", "")
user = getUserFromCookie(user1)
compileTemplateFile("view" / "404.nimja", baseDir = getScriptDir())
compileTemplateFile("view" / "404.html", baseDir = getScriptDir())
# Experimental
"/hi" -> get:
@ -87,7 +87,7 @@ load()
user1 = ctx.cookies.getOrDefault("user1", "")
user = getUserFromCookie(user1)
uploadcare_pub_key = getEnv("UPLOAD_CARE_PUBLIC_KEY")
compileTemplateFile("view" / "hi.nimja", baseDir = getScriptDir())
compileTemplateFile("view" / "hi.html", baseDir = getScriptDir())
"/delete-hi" -> post:
var

View file

@ -1,4 +1,4 @@
{% extends "view/partials/_master.nimja" %}
{% extends "view/partials/_master.html" %}
{% block spheader1 %} 404 Error {% endblock %}
{% block spheader2 %} 404 {% endblock %}

View file

@ -1,4 +1,4 @@
{% extends "view/partials/_master.nimja" %}
{% extends "view/partials/_master.html" %}
{% block spheader1 %} Cart {% endblock %}
{% block spheader2 %} Cart {% endblock %}

View file

@ -1,4 +1,4 @@
{% extends "view/partials/_master.nimja" %}
{% extends "view/partials/_master.html" %}
{% block spheader1 %} checkout {% endblock %}
{% block spheader2 %} checkout {% endblock %}

View file

@ -1,4 +1,4 @@
{% extends "view/partials/_master.nimja" %}
{% extends "view/partials/_master.html" %}
{% block contact %} active {% endblock %}
{% block spheader1 %} contact {% endblock %}

View file

@ -1,155 +0,0 @@
{% extends "view/partials/_master.nimja" %}
{% block css %}
<link rel="stylesheet" href="/static/css/hi.css">
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@uploadcare/blocks@0.48.0/web/lr-file-uploader-regular.min.css"
/>
{% endblock %}
{% block content %}
<div class="container">
<div class="row">
<div class="col">
<h1>Upload Product Image</h1>
<script type="module">
import * as LR from "https://cdn.jsdelivr.net/npm/@uploadcare/blocks@0.48.0/web/lr-file-uploader-regular.min.js";
LR.registerBlocks(LR);
</script>
<lr-config
ctx-name="my-uploader"
pubkey="{{uploadcare_pub_key}}"
max-local-file-size-bytes="10000000"
multiple="false"
img-only="true"
source-list="local, camera, dropbox, gdrive, gphotos"
></lr-config>
<lr-file-uploader-regular
ctx-name="my-uploader"
class="my-config"
>
</lr-file-uploader-regular>
<!-- The provider node is used to listen to the change event -->
<lr-upload-ctx-provider
ctx-name="my-uploader"
id="my-uploader-provider"
></lr-upload-ctx-provider>
<div id="previews"></div>
<script>
const providerNode = document.getElementById('my-uploader-provider');
const previewsNode = document.getElementById('previews');
providerNode.addEventListener('change', event => {
renderFiles(event.detail.allEntries.filter((file) => file.status === 'success'));
});
let url = "";
let uuid = "";
function renderFiles(files) {
const renderedFiles = files.map(file => {
const imgNode = document.createElement('img');
console.log(file);
imgNode.setAttribute('src', file.cdnUrl);
imgNode.setAttribute('alt', file.fileInfo.originalFilename);
imgNode.setAttribute('width', '100');
imgNode.setAttribute('height', '100');
url = file.cdnUrl;
uuid = file.uuid;
return imgNode;
});
console.log(...renderedFiles);
let formData = new FormData();
formData.append('img', url);
formData.append('img1', uuid);
console.log(formData);
let data = new URLSearchParams(formData);
// data.append('img', url);
// data.append('img1', uuid);
console.log(data);
let btnNode = document.createElement('button');
btnNode.setAttribute('id', 'b4');
btnNode.setAttribute('type', 'submit');
btnNode.setAttribute('class', 'btn btn-primary');
btnNode.addEventListener('click', function() {
console.log('Delete');
console.log(url);
console.log(uuid);
fetch('/delete-hi', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: data,
})
.then((response) => response.json())
.then((data) => {
console.log('Success:', data);
// remove the image and the buttons from the preview
previewsNode.replaceChildren();
})
.catch((error) => {
console.error('Error:', error);
});
});
// btnNode.addEventListener('click', function() {
// console.log('Delete');
// console.log(url);
// console.log(uuid);
// });
// btnNode.addEventListener('click', function() {
// console.log('Submit');
// console.log(url);
// console.log(uuid);
// });
btnNode.innerHTML = 'Delete';
let btnNode1 = document.createElement('button');
btnNode1.setAttribute('id', 'b4');
btnNode1.setAttribute('type', 'submit');
btnNode1.setAttribute('class', 'btn btn-primary');
btnNode1.innerHTML = 'Submit';
btnNode1.addEventListener('click', function() {
console.log('Submit');
console.log(url);
console.log(uuid);
fetch('/jj', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
img: url,
}),
})
.then((response) => response.json())
.then((data) => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
});
previewsNode.replaceChildren(...renderedFiles, btnNode, btnNode1);
}
// TODO: Add a button to delete the image from the server
// TODO: Add a button to submit the image url to the server
</script>
</div>
</div>
</div>
{% endblock %}

View file

@ -1,4 +1,4 @@
{% extends "view/partials/_master.nimja" %}
{% extends "view/partials/_master.html" %}
{% block index %} active {% endblock %}

View file

@ -1,4 +1,4 @@
{% extends "view/partials/_master.nimja" %}
{% extends "view/partials/_master.html" %}
{% block content %}

View file

@ -1,4 +1,4 @@
{% extends "view/partials/_master.nimja" %}
{% extends "view/partials/_master.html" %}
{% block content %}

View file

@ -1,4 +1,4 @@
{% extends "view/partials/_master.nimja" %}
{% extends "view/partials/_master.html" %}
{% block shop %} active {% endblock %}
{% block spheader1 %} Shop-Details {% endblock %}

View file

@ -1,4 +1,4 @@
{% extends "view/partials/_master.nimja" %}
{% extends "view/partials/_master.html" %}
{% block shop %} active {% endblock %}
{% block spheader1 %} Shop {% endblock %}

View file

@ -1,4 +1,4 @@
{% extends "../view/partials/_master.nimja" %}
{% extends "../view/partials/_master.html" %}
{% block spheader1 %} Sign Up {% endblock %}
{% block spheader2 %} Sign Up {% endblock %}

View file

@ -1,4 +1,4 @@
{% extends "view/partials/_master.nimja" %}
{% extends "view/partials/_master.html" %}
{% block content %}