Own files for i18n and router + fix some of markdown warnings

This commit is contained in:
Adam Stachowicz 2021-09-12 19:23:51 +02:00
parent 2d7767c905
commit 54ffef8b7a
6 changed files with 149 additions and 164 deletions

View file

@ -2,7 +2,7 @@
First of all, thank you everyone who made pull requests for Uptime Kuma, I never thought GitHub Community can be that nice! And also because of this, I also never thought other people actually read my code and edit my code. It is not structed and commented so well, lol. Sorry about that.
The project was created with vite.js (vue3). Then I created a sub-directory called "server" for server part. Both frontend and backend share the same package.json.
The project was created with vite.js (vue3). Then I created a sub-directory called "server" for server part. Both frontend and backend share the same package.json.
The frontend code build into "dist" directory. The server uses "dist" as root. This is how production is working.
@ -20,13 +20,13 @@ If you are not sure, feel free to create an empty pull request draft first.
- Add a chart
- Fix a bug
### *️⃣ Requires one more reviewer
### *️⃣ Requires one more reviewer
I do not have such knowledge to test it.
- Add k8s supports
- Add k8s supports
### *️⃣ Low Priority
### *️⃣ Low Priority
It changed my current workflow and require further studies.
@ -41,9 +41,9 @@ It changed my current workflow and require further studies.
# Project Styles
I personally do not like something need to learn so much and need to config so much before you can finally start the app.
I personally do not like something need to learn so much and need to config so much before you can finally start the app.
For example, recently, because I am not a python expert, I spent a 2 hours to resolve all problems in order to install and use the Apprise cli. Apprise requires so many hidden requirements, I have to figure out myself how to solve the problems by Google search for my OS. That is painful. I do not want Uptime Kuma to be like this way, so:
For example, recently, because I am not a python expert, I spent a 2 hours to resolve all problems in order to install and use the Apprise cli. Apprise requires so many hidden requirements, I have to figure out myself how to solve the problems by Google search for my OS. That is painful. I do not want Uptime Kuma to be like this way, so:
- Easy to install for non-Docker users, no native build dependency is needed (at least for x86_64), no extra config, no extra effort to get it run
- Single container for Docker users, no very complex docker-composer file. Just map the volume and expose the port, then good to go
@ -52,8 +52,8 @@ For example, recently, because I am not a python expert, I spent a 2 hours to re
# Coding Styles
- Follow .editorconfig
- Follow eslint
- Follow `.editorconfig`
- Follow ESLint
## Name convention
@ -62,12 +62,13 @@ For example, recently, because I am not a python expert, I spent a 2 hours to re
- CSS/SCSS: dash-type
# Tools
- Node.js >= 14
- Git
- IDE that supports .editorconfig and eslint (I am using Intellji Idea)
- IDE that supports EditorConfig and ESLint (I am using Intellji Idea)
- A SQLite tool (I am using SQLite Expert Personal)
# Install dependencies
# Install dependencies
```bash
npm install --dev
@ -75,7 +76,7 @@ npm install --dev
For npm@7, you need --legacy-peer-deps
```
```bash
npm install --legacy-peer-deps --dev
```
@ -84,23 +85,22 @@ npm install --legacy-peer-deps --dev
```bash
npm run start-server
# Or
# Or
node server/server.js
```
It binds to 0.0.0.0:3001 by default.
It binds to `0.0.0.0:3001` by default.
## Backend Details
It is mainly a socket.io app + express.js.
express.js is just used for serving the frontend built files (index.html, .js and .css etc.)
express.js is just used for serving the frontend built files (index.html, .js and .css etc.)
# Frontend Dev
Start frontend dev server. Hot-reload enabled in this way. It binds to 0.0.0.0:3000.
Start frontend dev server. Hot-reload enabled in this way. It binds to `0.0.0.0:3000` by default.
```bash
npm run dev
@ -108,7 +108,7 @@ npm run dev
PS: You can ignore those scss warnings, those warnings are from Bootstrap that I cannot fix.
You can use Vue Devtool Chrome extension for debugging.
You can use Vue.js devtools Chrome extension for debugging.
After the frontend server started. It cannot connect to the websocket server even you have started the server. You need to tell the frontend that is a dev env by running this in DevTool console and refresh:
@ -118,8 +118,7 @@ localStorage.dev = "dev";
So that the frontend will try to connect websocket server in 3001.
Alternately, you can specific NODE_ENV to "development".
Alternately, you can specific `NODE_ENV` to "development".
## Build the frontend
@ -131,22 +130,17 @@ npm run build
Uptime Kuma Frontend is a single page application (SPA). Most paths are handled by Vue Router.
The router in "src/main.js"
The router is in `src/router.js`
As you can see, most data in frontend is stored in root level, even though you changed the current router to any other pages.
The data and socket logic in "src/mixins/socket.js"
The data and socket logic are in `src/mixins/socket.js`.
# Database Migration
1. create `patch{num}.sql` in `./db/`
1. update `latestVersion` in `./server/database.js`
1. Create `patch{num}.sql` in `./db/`
2. Update `latestVersion` in `./server/database.js`
# Unit Test
Yes, no unit test for now. I know it is very important, but at the same time my spare time is very limited. I want to implement my ideas first. I will go back to this in some points.

View file

@ -20,12 +20,11 @@ It is a 5 minutes live demo, all data will be deleted after that. The server is
VPS is sponsored by Uptime Kuma sponsors on [Open Collective](https://opencollective.com/uptime-kuma)! Thank you so much!
## ⭐ Features
* Monitoring uptime for HTTP(s) / TCP / Ping / DNS Record.
* Fancy, Reactive, Fast UI/UX.
* Notifications via Telegram, Discord, Gotify, Slack, Pushover, Email (SMTP), and [70+ notification services, click here for the full list](https://github.com/louislam/uptime-kuma/issues/284).
* Notifications via Telegram, Discord, Gotify, Slack, Pushover, Email (SMTP), and [70+ notification services, click here for the full list](https://github.com/louislam/uptime-kuma/issues/284).
* 20 seconds interval.
* [Multi Languages](https://github.com/louislam/uptime-kuma/tree/master/src/languages)
@ -65,7 +64,6 @@ If you need more options or need to browse via a reserve proxy, please read:
https://github.com/louislam/uptime-kuma/wiki/%F0%9F%94%A7-How-to-Install
## 🆙 How to Update
Please read:
@ -107,15 +105,13 @@ Telegram Notification Sample:
If you love this project, please consider giving me a ⭐.
## 🗣️ Discussion
You can also discuss or ask for help in [Issues](https://github.com/louislam/uptime-kuma/issues).
Alternatively, you can discuss in my original post on reddit: https://www.reddit.com/r/selfhosted/comments/oi7dc7/uptime_kuma_a_fancy_selfhosted_monitoring_tool_an/
I think the real "Discussion" tab is hard to use, as it is reddit-like flow, I always missed new comments.
I think the real "Discussion" tab is hard to use, as it is reddit-like flow, I always missed new comments.
## Contribute
@ -126,4 +122,3 @@ If you want to translate Uptime Kuma into your langauge, please read: https://gi
If you want to modify Uptime Kuma, this guideline may be useful for you: https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md
English proofreading is needed too because my grammar is not that great sadly. Feel free to correct my grammar in this readme, source code, or wiki.

46
src/i18n.js Normal file
View file

@ -0,0 +1,46 @@
import { createI18n } from "vue-i18n";
import daDK from "./languages/da-DK";
import deDE from "./languages/de-DE";
import en from "./languages/en";
import esEs from "./languages/es-ES";
import etEE from "./languages/et-EE";
import frFR from "./languages/fr-FR";
import itIT from "./languages/it-IT";
import ja from "./languages/ja";
import koKR from "./languages/ko-KR";
import nlNL from "./languages/nl-NL";
import pl from "./languages/pl";
import ruRU from "./languages/ru-RU";
import sr from "./languages/sr";
import srLatn from "./languages/sr-latn";
import svSE from "./languages/sv-SE";
import zhCN from "./languages/zh-CN";
import zhHK from "./languages/zh-HK";
const languageList = {
en,
"zh-HK": zhHK,
"de-DE": deDE,
"nl-NL": nlNL,
"es-ES": esEs,
"fr-FR": frFR,
"it-IT": itIT,
"ja": ja,
"da-DK": daDK,
"sr": sr,
"sr-latn": srLatn,
"sv-SE": svSE,
"ko-KR": koKR,
"ru-RU": ruRU,
"zh-CN": zhCN,
"pl": pl,
"et-EE": etEE,
};
export const i18n = createI18n({
locale: localStorage.locale || "en",
fallbackLocale: "en",
silentFallbackWarn: true,
silentTranslationWarn: false,
messages: languageList,
});

View file

@ -3,16 +3,12 @@
1. Fork this repo.
2. Create a language file. (e.g. `zh-TW.js`) The filename must be ISO language code: http://www.lingoes.net/en/translator/langcode.htm
3. `npm run update-language-files --base-lang=de-DE`
6. Your language file should be filled in. You can translate now.
7. Translate `src/pages/Settings.vue` (search for a `Confirm` component with `rel="confirmDisableAuth"`).
8. Import your language file in `src/main.js` and add it to `languageList` constant.
9. Make a [pull request](https://github.com/louislam/uptime-kuma/pulls) when you have done.
4. Your language file should be filled in. You can translate now.
5. Translate `src/pages/Settings.vue` (search for a `Confirm` component with `rel="confirmDisableAuth"`).
6. Import your language file in `src/i18n.js` and add it to `languageList` constant.
7. Make a [pull request](https://github.com/louislam/uptime-kuma/pulls) when you have done.
One of good examples:
https://github.com/louislam/uptime-kuma/pull/316/files
If you do not have programming skills, let me know in [Issues section](https://github.com/louislam/uptime-kuma/issues). I will assist you. 😏

View file

@ -1,135 +1,18 @@
import "bootstrap";
import { createApp, h } from "vue";
import { createI18n } from "vue-i18n"
import { createRouter, createWebHistory } from "vue-router";
import Toast from "vue-toastification";
import "vue-toastification/dist/index.css";
import App from "./App.vue";
import "./assets/app.scss";
import { i18n } from "./i18n";
import { FontAwesomeIcon } from "./icon.js";
import EmptyLayout from "./layouts/EmptyLayout.vue";
import Layout from "./layouts/Layout.vue";
import datetime from "./mixins/datetime";
import mobile from "./mixins/mobile";
import socket from "./mixins/socket";
import theme from "./mixins/theme";
import mobile from "./mixins/mobile";
import datetime from "./mixins/datetime";
import Dashboard from "./pages/Dashboard.vue";
import DashboardHome from "./pages/DashboardHome.vue";
import Details from "./pages/Details.vue";
import EditMonitor from "./pages/EditMonitor.vue";
import Settings from "./pages/Settings.vue";
import Setup from "./pages/Setup.vue";
import List from "./pages/List.vue";
import { router } from "./router";
import { appName } from "./util.ts";
import en from "./languages/en";
import zhHK from "./languages/zh-HK";
import deDE from "./languages/de-DE";
import nlNL from "./languages/nl-NL";
import esEs from "./languages/es-ES";
import frFR from "./languages/fr-FR";
import itIT from "./languages/it-IT";
import ja from "./languages/ja";
import daDK from "./languages/da-DK";
import sr from "./languages/sr";
import srLatn from "./languages/sr-latn";
import svSE from "./languages/sv-SE";
import koKR from "./languages/ko-KR";
import ruRU from "./languages/ru-RU";
import zhCN from "./languages/zh-CN";
import pl from "./languages/pl"
import etEE from "./languages/et-EE"
const routes = [
{
path: "/",
component: Layout,
children: [
{
name: "root",
path: "",
component: Dashboard,
children: [
{
name: "DashboardHome",
path: "/dashboard",
component: DashboardHome,
children: [
{
path: "/dashboard/:id",
component: EmptyLayout,
children: [
{
path: "",
component: Details,
},
{
path: "/edit/:id",
component: EditMonitor,
},
],
},
{
path: "/add",
component: EditMonitor,
},
{
path: "/list",
component: List,
},
],
},
{
path: "/settings",
component: Settings,
},
],
},
],
},
{
path: "/setup",
component: Setup,
},
]
const router = createRouter({
linkActiveClass: "active",
history: createWebHistory(),
routes,
})
const languageList = {
en,
"zh-HK": zhHK,
"de-DE": deDE,
"nl-NL": nlNL,
"es-ES": esEs,
"fr-FR": frFR,
"it-IT": itIT,
"ja": ja,
"da-DK": daDK,
"sr": sr,
"sr-latn": srLatn,
"sv-SE": svSE,
"ko-KR": koKR,
"ru-RU": ruRU,
"zh-CN": zhCN,
"pl": pl,
"et-EE": etEE,
};
const i18n = createI18n({
locale: localStorage.locale || "en",
fallbackLocale: "en",
silentFallbackWarn: true,
silentTranslationWarn: true,
messages: languageList
});
const app = createApp({
mixins: [
socket,

71
src/router.js Normal file
View file

@ -0,0 +1,71 @@
import { createRouter, createWebHistory } from "vue-router";
import EmptyLayout from "./layouts/EmptyLayout.vue";
import Layout from "./layouts/Layout.vue";
import Dashboard from "./pages/Dashboard.vue";
import DashboardHome from "./pages/DashboardHome.vue";
import Details from "./pages/Details.vue";
import EditMonitor from "./pages/EditMonitor.vue";
import List from "./pages/List.vue";
import Settings from "./pages/Settings.vue";
import Setup from "./pages/Setup.vue";
const routes = [
{
path: "/",
component: Layout,
children: [
{
name: "root",
path: "",
component: Dashboard,
children: [
{
name: "DashboardHome",
path: "/dashboard",
component: DashboardHome,
children: [
{
path: "/dashboard/:id",
component: EmptyLayout,
children: [
{
path: "",
component: Details,
},
{
path: "/edit/:id",
component: EditMonitor,
},
],
},
{
path: "/add",
component: EditMonitor,
},
{
path: "/list",
component: List,
},
],
},
{
path: "/settings",
component: Settings,
},
],
},
],
},
{
path: "/setup",
component: Setup,
},
]
export const router = createRouter({
linkActiveClass: "active",
history: createWebHistory(),
routes,
});