Skip to content

Commit

Permalink
update html and some text
Browse files Browse the repository at this point in the history
  • Loading branch information
fankaiLiu committed Dec 28, 2023
1 parent 0f6ee1a commit 0921581
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 187 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "salvo-cli"
version = "0.1.36"
version = "0.1.37"
edition = "2021"
authors = ["Fankai Liu [email protected]","mrxiaozhuox [email protected]"]
keywords = ["salvo", "cli","template"]
Expand Down
37 changes: 18 additions & 19 deletions locales/code_comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -437,25 +437,24 @@ add_user:
th: เพิ่มผู้ใช้
el: Προσθήκη χρήστη
da: Tilføj bruger
swagger_api_page:
en: Swagger API Page
zh_CN: Swagger API页面
zh_TW: Swagger API頁面
fr: Page API Swagger
ja: Swagger APIページ
es: Página API de Swagger
de: Swagger-API-Seite
ru: Страница Swagger API
it: Pagina API Swagger
pt: Página API Swagger
ko: Swagger API 페이지
no: Swagger API-side
is: Swagger API síða
uk: Сторінка Swagger API
th: หน้า Swagger API
el: Σελίδα Swagger API
da: Swagger API-side

open_api_page:
en: Open API Page
zh_CN: Open API页面
zh_TW: Open API頁面
fr: Page Open API
ja: Open APIページ
es: Página Open API
de: Open-API-Seite
ru: Страница Open API
it: Pagina Open API
pt: Página Open API
ko: Open API 페이지
no: Open API-side
is: Open API síða
uk: Сторінка Open API
th: หน้า Open API
el: Σελίδα Open API
da: Open API-side
login_page:
en: Login Page
zh_CN: 登录页面
Expand Down
4 changes: 2 additions & 2 deletions src/template/src/main_template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async fn main() {
match CFG.server.ssl {
true => {
println!(
"📖 {{swagger_api_page}}: https://{}/swagger-ui",
"📖 {{open_api_page}}: https://{}/swagger-ui",
&CFG.server.address.replace("0.0.0.0", "127.0.0.1")
);
{{#if is_web_site}}
Expand All @@ -100,7 +100,7 @@ async fn main() {
}
false => {
println!(
"📖 {{swagger_api_page}}: http://{}/swagger-ui",
"📖 {{open_api_page}}: http://{}/swagger-ui",
&CFG.server.address.replace("0.0.0.0", "127.0.0.1")
);
{{#if is_web_site}}
Expand Down
222 changes: 70 additions & 152 deletions src/template/templates/login.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand All @@ -12,63 +11,71 @@
<div
class="flex min-h-full items-center justify-center py-12 px-4 sm:px-6 lg:px-8"
>
<div class="w-full max-w-md space-y-8">
<div
class="w-full max-w-md space-y-8 bg-white p-10 rounded-2xl shadow-xl"
>
<div>
<h2
class="mt-6 text-center text-3xl font-bold tracking-tight text-gray-900"
>
<h2 class="text-center text-4xl font-extrabold text-gray-700">
{{login}}
</h2>
</div>
<form class="mt-8 space-y-6" @submit.prevent="submit">
<input type="hidden" name="remember" value="true" />
<div class="-space-y-px rounded-md shadow-sm">
<div class="rounded-md shadow-sm -space-y-px">
<div>
<label for="username" class="sr-only">{{username}}</label>
<label for="username" class="sr-only">Username</label>
<input
x-model="username"
id="username"
name="username"
type="text"
autocomplete="username"
required
class="relative block w-full appearance-none rounded-none rounded-t-md border border-gray-300 px-3 py-2 text-gray-900 placeholder-gray-500 focus:z-10 focus:border-sky-500 focus:outline-none focus:ring-sky-500 sm:text-sm"
class="relative block w-full appearance-none rounded-t-2xl border border-gray-300 px-4 py-3 mb-3 text-gray-900 placeholder-gray-500 focus:z-10 focus:border-sky-500 focus:outline-none focus:ring-sky-500 sm:text-sm"
placeholder="{{username}}"
/>
</div>
<div>
<label for="password" class="sr-only">{{password}}</label>
<label for="password" class="sr-only">Password</label>
<input
x-model="password"
id="password"
name="password"
type="password"
autocomplete="current-password"
required
class="relative block w-full appearance-none rounded-none rounded-b-md border border-gray-300 px-3 py-2 text-gray-900 placeholder-gray-500 focus:z-10 focus:border-sky-500 focus:outline-none focus:ring-sky-500 sm:text-sm"
class="relative block w-full appearance-none rounded-b-2xl border border-gray-300 px-4 py-3 mb-3 text-gray-900 placeholder-gray-500 focus:z-10 focus:border-sky-500 focus:outline-none focus:ring-sky-500 sm:text-sm"
placeholder="{{password}}"
/>
</div>
</div>

{{! <div class="flex items-center justify-between">
<div class="flex items-center">
<input
id="remember-me"
name="remember-me"
type="checkbox"
class="h-4 w-4 text-sky-600 focus:ring-sky-500 border-gray-300 rounded-full"
/>
<label for="remember-me" class="ml-2 block text-sm text-gray-900">
Remember me
</label>
</div>
<div class="text-sm">
<a href="#" class="font-medium text-sky-600 hover:text-sky-500">
Forgot your password?
</a>
</div>
</div> }}

<div>
<button
type="submit"
class="group relative flex w-full justify-center rounded-md border border-transparent bg-sky-600 py-2 px-4 text-sm font-medium text-white hover:bg-sky-700 focus:outline-none focus:ring-2 focus:ring-sky-500 focus:ring-offset-2"
class="group relative w-full flex justify-center py-3 px-4 border border-transparent text-sm font-medium rounded-full text-white bg-sky-600 hover:bg-sky-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-sky-500"
>
<span
class="absolute inset-y-0 left-0 flex items-center pl-3"
>
<svg
class="h-5 w-5 text-sky-500 group-hover:text-sky-400"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
aria-hidden="true"
>
<path
fill-rule="evenodd"
d="M10 1a4.5 4.5 0 00-4.5 4.5V9H5a2 2 0 00-2 2v6a2 2 0 002 2h10a2 2 0 002-2v-6a2 2 0 00-2-2h-.5V5.5A4.5 4.5 0 0010 1zm3 8V5.5a3 3 0 10-6 0V9h6z"
clip-rule="evenodd"
/>
</svg>
</span>
{{login}}
{{login}}
</button>
</div>
</form>
Expand All @@ -84,127 +91,38 @@
<script src="assets/js/sweetalert2.js"></script>
<script src="assets/js/alpinejs.js" defer></script>
<script>
function loginForm() {
return {
username: "",
password: "",
isLoggedIn: false,
userList: "",
async submit() {
try {
const response = await fetch("/api/login", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
username: this.username,
password: this.password,
}),
});
if (!response.ok) {
const data = await response.json();
throw new Error(`${data.msg}`);
}
this.isLoggedIn = true;
const userListResponse = await fetch("/users", {
headers: {
"X-Fragment-Header": "true",
},
});
this.userList = await userListResponse.text();
history.pushState(null, '', '/users');
} catch (error) {
Swal.fire({
title: "Error!",
text: error.message,
icon: "error",
confirmButtonText: "OK",
});
}
},
};
}
function userForm() {
return {
users: [],
fetchData() {
fetch("/api/users")
.then((response) => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
})
.then((data) => {
this.users = data.data;
})
.catch((error) => {
console.error(
"There has been a problem with your fetch operation:",
error
);
});
},
addUser() {
Swal.fire({
title: "Add User",
showCancelButton: true,
html: `
<input id="swal-input1" class="swal2-input" placeholder="username">
<input id="swal-input2" class="swal2-input" placeholder="password">
`,
preConfirm: () => {
return fetch("/api/users", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
username: document.getElementById("swal-input1").value,
password: document.getElementById("swal-input2").value,
}),
})
.then((response) => {
if (!response.ok) {
throw new Error(response.statusText);
}
this.fetchData();
return;
})
.catch((error) => {
Swal.showValidationMessage(`Request failed: ${error}`);
});
},
allowOutsideClick: () => !Swal.isLoading(),
});
},
deleteUser(id) {
Swal.fire({
title: "Are you sure?",
text: "You won't be able to revert this!",
icon: "warning",
showCancelButton: true,
confirmButtonText: "Yes, delete it!",
preConfirm: () => {
return fetch(`/api/users/${id}`, {
method: "DELETE",
})
.then((response) => {
if (!response.ok) {
throw new Error(response.statusText);
}
this.fetchData();
return;
})
.catch((error) => {
Swal.showValidationMessage(`Request failed: ${error}`);
});
},
allowOutsideClick: () => !Swal.isLoading(),
}).then((result) => {});
},
};
}
function loginForm() { return { username: "", password: "", isLoggedIn:
false, userList: "", async submit() { try { const response = await
fetch("/api/login", { method: "POST", headers: { "Content-Type":
"application/json", }, body: JSON.stringify({ username: this.username,
password: this.password, }), }); if (!response.ok) { const data = await
response.json(); throw new Error(`${data.msg}`); } this.isLoggedIn = true;
const userListResponse = await fetch("/users", { headers: {
"X-Fragment-Header": "true", }, }); this.userList = await
userListResponse.text(); history.pushState(null, '', '/users'); } catch
(error) { Swal.fire({ title: "Error!", text: error.message, icon: "error",
confirmButtonText: "OK", }); } }, }; } function userForm() { return { users:
[], fetchData() { fetch("/api/users") .then((response) => { if
(!response.ok) { throw new Error("Network response was not ok"); } return
response.json(); }) .then((data) => { this.users = data.data; })
.catch((error) => { console.error( "There has been a problem with your fetch
operation:", error ); }); }, addUser() { Swal.fire({ title: "Add User",
showCancelButton: true, html: ` <input id="swal-input1" class="swal2-input"
placeholder="username"> <input id="swal-input2" class="swal2-input"
placeholder="password"> `, preConfirm: () => { return fetch("/api/users", {
method: "POST", headers: { "Content-Type": "application/json", }, body:
JSON.stringify({ username: document.getElementById("swal-input1").value,
password: document.getElementById("swal-input2").value, }), })
.then((response) => { if (!response.ok) { throw new
Error(response.statusText); } this.fetchData(); return; }) .catch((error) =>
{ Swal.showValidationMessage(`Request failed: ${error}`); }); },
allowOutsideClick: () => !Swal.isLoading(), }); }, deleteUser(id) {
Swal.fire({ title: "Are you sure?", text: "You won't be able to revert
this!", icon: "warning", showCancelButton: true, confirmButtonText: "Yes,
delete it!", preConfirm: () => { return fetch(`/api/users/${id}`, { method:
"DELETE", }) .then((response) => { if (!response.ok) { throw new
Error(response.statusText); } this.fetchData(); return; }) .catch((error) =>
{ Swal.showValidationMessage(`Request failed: ${error}`); }); },
allowOutsideClick: () => !Swal.isLoading(), }).then((result) => {}); }, }; }
</script>
</html>
</html>
Loading

0 comments on commit 0921581

Please sign in to comment.