initial commit

This commit is contained in:
Niko Feith 2023-03-30 10:50:33 +02:00
commit 62c95bf32e
28 changed files with 6862 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/node_modules/

5
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/

12
.idea/ROSWebTemplate.iml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ROSWebTemplate.iml" filepath="$PROJECT_DIR$/.idea/ROSWebTemplate.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

52
README.md Normal file
View File

@ -0,0 +1,52 @@
# ROSWebTemplate
This template should help get you started developing with Vue 3 in Vite.
## Recommended IDE Setup
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).
## Type Support for `.vue` Imports in TS
TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types.
If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps:
1. Disable the built-in TypeScript Extension
1) Run `Extensions: Show Built-in Extensions` from VSCode's command palette
2) Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.
## Customize configuration
See [Vite Configuration Reference](https://vitejs.dev/config/).
## Project Setup
```sh
npm install
```
### Compile and Hot-Reload for Development
```sh
npm run dev
```
### Type-Check, Compile and Minify for Production
```sh
npm run build
```
### Run Unit Tests with [Vitest](https://vitest.dev/)
```sh
npm run test:unit
```
### Lint with [ESLint](https://eslint.org/)
```sh
npm run lint
```

1
env.d.ts vendored Normal file
View File

@ -0,0 +1 @@
/// <reference types="vite/client" />

13
index.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/CPS_White.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CPS ROS Web</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="src/main.ts"></script>
</body>
</html>

6361
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

44
package.json Normal file
View File

@ -0,0 +1,44 @@
{
"name": "roswebtemplate",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "vite",
"build": "run-p type-check build-only",
"preview": "vite preview",
"test:unit": "vitest",
"build-only": "vite build",
"type-check": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
"format": "prettier --write src/"
},
"dependencies": {
"@jamescoyle/vue-icon": "^0.1.2",
"@mdi/js": "^7.2.96",
"pinia": "^2.0.32",
"roslib": "^1.3.0",
"vue": "^3.2.47",
"vuetify": "^3.1.12"
},
"devDependencies": {
"@mdi/font": "^7.2.96",
"@rushstack/eslint-patch": "^1.2.0",
"@types/jsdom": "^21.1.0",
"@types/node": "^18.14.2",
"@vitejs/plugin-vue": "^4.0.0",
"@vitejs/plugin-vue-jsx": "^3.0.0",
"@vue/eslint-config-prettier": "^7.1.0",
"@vue/eslint-config-typescript": "^11.0.2",
"@vue/test-utils": "^2.3.0",
"@vue/tsconfig": "^0.1.3",
"eslint": "^8.34.0",
"eslint-plugin-vue": "^9.9.0",
"jsdom": "^21.1.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.4",
"typescript": "~4.8.4",
"vite": "^4.1.4",
"vitest": "^0.29.1",
"vue-tsc": "^1.2.0"
}
}

BIN
public/CPS_White.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

17
src/App.vue Normal file
View File

@ -0,0 +1,17 @@
<template>
<v-app class="app-class">
<v-main>
<BaseLayout/>
</v-main>
</v-app>
</template>
<script setup>
import BaseLayout from '@/components/BaseLayout.vue';
</script>
<style scoped>
.app-class{
background: rgb(64, 73, 76);
}
</style>

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

View File

@ -0,0 +1,17 @@
<template>
<TopBar/>
<SideBar/>
<SubLayout/>
<RosBar/>
</template>
<script setup>
import TopBar from '@/components/TopBar.vue';
import RosBar from '@/components/RosBar.vue';
import SideBar from '@/components/SideBar.vue';
import SubLayout from "@/components/SubLayout.vue";
</script>
<style scoped>
</style>

104
src/components/RosBar.vue Normal file
View File

@ -0,0 +1,104 @@
<template>
<v-navigation-drawer v-model="store.rosBarOpened" temporary location="right">
<v-container fluid>
<v-row justify="space-between">
<v-col cols="6" md="12">
<v-text-field
v-model="formState.ipaddress"
label="IP Address"
:disabled="connectionState"
/>
<v-text-field
v-model="formState.port"
label="Port"
:disabled="connectionState"
/>
<v-switch
@change="updateConnectionState"
true-value="connected"
false-value="not connected"
:label="`${formState.connect}`"
/>
</v-col>
</v-row>
</v-container>
</v-navigation-drawer>
</template>
<script setup>
import * as ROS from "roslib";
import { useBWStore } from "@/store/BaseWebsiteStore";
import { reactive, ref, watch } from "vue";
const store = useBWStore();
const formState = reactive({
ipaddress: "localhost",
port: "9090",
connect: "not connected",
// connectionState: computed(() => formState.connect !== 'not connected'),
});
const connectionState = ref(false);
const stateCounter = ref([0, 0, 0]);
// Open Connection to ROSBridge and subscribe the topics.
const ros = new ROS.Ros();
const ros_eval = new ROS.Ros();
ros.on("connection", () => {
stateCounter.value[0] += 1;
});
ros_eval.on("connection", () => {});
ros.on("error", (error) => {
stateCounter.value[1] += 1;
console.log(error);
});
ros_eval.on("error", () => {});
ros.on("close", () => {
stateCounter.value[2] += 1;
});
ros_eval.on("close", () => {});
function updateConnectionState() {
connectionState.value = !connectionState.value;
if (formState.connect === "not connected") {
formState.connect = "connected";
const rosUrl = `ws://${formState.ipaddress}:${formState.port}`;
ros.connect(rosUrl);
ros_eval.connect(rosUrl);
} else {
formState.connect = "not connected";
ros.close();
ros_eval.close();
}
}
const lastStateCounter = [0, 0, 0];
// ROS2 State Observer
watch(stateCounter.value, (newValue) => {
let currentState = 0;
for (let i = 0; i < lastStateCounter.length; i += 1) {
if (newValue[i] - lastStateCounter[i] === 1) {
currentState = i;
}
lastStateCounter[i] = newValue[i];
}
if (currentState === 0) {
store.setRosConState("connected");
} else if (currentState === 1) {
store.setRosConState("error");
} else if (currentState === 2) {
store.setRosConState("not connected");
}
});
</script>
<style scoped></style>

View File

@ -0,0 +1,26 @@
<template>
<v-navigation-drawer permanent width="64">
<v-container fluid>
<v-btn class="sidebar-button" @click="store.setPlay()">
<v-icon v-if="!store.getPlay">mdi-play</v-icon>
<v-icon v-else>mdi-pause</v-icon>
</v-btn>
</v-container>
</v-navigation-drawer>
</template>
<script setup>
import { useBWStore } from "@/store/BaseWebsiteStore";
const store = useBWStore();
</script>
<style scoped>
.sidebar-button {
height: 48px;
width: 48px;
left: -16px;
box-shadow: none;
border-radius: 0;
}
</style>

View File

@ -0,0 +1,23 @@
<template>
</template>
<script setup>
</script>
<style scoped>
.sub-layout {
padding: 0;
margin: 1px 0 0 0;
}
.tile {
margin: 0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
border: 1px solid #333;
}
</style>

43
src/components/TopBar.vue Normal file
View File

@ -0,0 +1,43 @@
<template>
<v-app-bar id="components-top-bar" class="elevation-1">
<v-img class="cps-image" :left="true" :src="pic" />
<v-divider vertical class="image-divider" />
<v-spacer />
<v-btn @click="store.toggleRosBar()">
<v-icon :color="changeRosColor()" large>
mdi-checkbox-blank-circle
</v-icon>
\ ROS2
</v-btn>
</v-app-bar>
</template>
<script setup>
import { useBWStore } from "@/store/BaseWebsiteStore";
import pic from "../assets/CPS_Logo_White.png";
const store = useBWStore();
const changeRosColor = () => {
const conState = store.getRosConState;
if (conState === "not connected") {
return "red";
}
if (conState === "connected") {
return "green";
}
return "grey";
};
</script>
<style scoped>
.cps-image {
left: 8px;
max-width: 48px;
max-height: 48px;
}
.image-divider {
position: absolute;
left: 64px;
}
</style>

29
src/main.ts Normal file
View File

@ -0,0 +1,29 @@
import { createApp } from "vue";
// Pinia Store
import { createPinia } from "pinia";
// Vuetify
import 'vuetify/styles'
import { createVuetify } from 'vuetify'
import * as components from 'vuetify/components'
import * as directives from 'vuetify/directives'
import '@mdi/font/css/materialdesignicons.css'
import App from "./App.vue";
const pinia = createPinia();
const vuetify = createVuetify({
theme: {
defaultTheme: 'dark',
},
components,
directives,
});
const app = createApp(App);
app.use(pinia);
app.use(vuetify);
app.mount("#app");

View File

@ -0,0 +1,27 @@
import {defineStore} from "pinia";
export const useBWStore = defineStore("Base Website Store", {
state: () => {
return {
play: false,
rosBarOpened: true,
rosConState: "not connected",
};
},
getters: {
getPlay: (state) => state.play,
getRosBarOpened: (state) => state.rosBarOpened,
getRosConState: (state) => state.rosConState,
},
actions: {
setPlay() {
this.play = !this.play;
},
toggleRosBar() {
this.rosBarOpened = !this.rosBarOpened;
},
setRosConState(value) {
this.rosConState = value;
},
},
});

12
tsconfig.app.json Normal file
View File

@ -0,0 +1,12 @@
{
"extends": "@vue/tsconfig/tsconfig.web.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
"exclude": ["src/**/__tests__/*"],
"compilerOptions": {
"composite": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}

14
tsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"files": [],
"references": [
{
"path": "./tsconfig.node.json"
},
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.vitest.json"
}
]
}

8
tsconfig.node.json Normal file
View File

@ -0,0 +1,8 @@
{
"extends": "@vue/tsconfig/tsconfig.node.json",
"include": ["vite.config.*", "vitest.config.*", "cypress.config.*", "playwright.config.*"],
"compilerOptions": {
"composite": true,
"types": ["node"]
}
}

9
tsconfig.vitest.json Normal file
View File

@ -0,0 +1,9 @@
{
"extends": "./tsconfig.app.json",
"exclude": [],
"compilerOptions": {
"composite": true,
"lib": [],
"types": ["node", "jsdom"]
}
}

15
vite.config.ts Normal file
View File

@ -0,0 +1,15 @@
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue(), vueJsx()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
})

15
vitest.config.ts Normal file
View File

@ -0,0 +1,15 @@
import { fileURLToPath } from 'node:url'
import { mergeConfig } from 'vite'
import { configDefaults, defineConfig } from 'vitest/config'
import viteConfig from './vite.config'
export default mergeConfig(
viteConfig,
defineConfig({
test: {
environment: 'jsdom',
exclude: [...configDefaults.exclude, 'e2e/*'],
root: fileURLToPath(new URL('./', import.meta.url))
}
})
)