Add Frontend

main
DustyP 4 years ago
parent e715ae40b1
commit 179a6829a3

@ -9,6 +9,7 @@ import (
"github.com/dustinpianalto/quartermaster/internal/utils" "github.com/dustinpianalto/quartermaster/internal/utils"
"github.com/dustinpianalto/quartermaster/pkg/api" "github.com/dustinpianalto/quartermaster/pkg/api"
"github.com/dustinpianalto/quartermaster/pkg/services" "github.com/dustinpianalto/quartermaster/pkg/services"
"github.com/dustinpianalto/quartermaster/pkg/ui"
"github.com/gorilla/mux" "github.com/gorilla/mux"
) )
@ -17,8 +18,9 @@ func main() {
postgres.ConnectDatabase(os.Getenv("DATABASE_URL"), migrationsVersion) postgres.ConnectDatabase(os.Getenv("DATABASE_URL"), migrationsVersion)
services.InitServices() services.InitServices()
router := mux.NewRouter().StrictSlash(true) router := mux.NewRouter()
utils.Mount(router, "/api", api.GetRouter()) utils.Mount(router, "/api", api.GetRouter())
utils.Mount(router, "/", ui.GetRouter())
log.Fatal(http.ListenAndServe(":8000", router)) log.Fatal(http.ListenAndServe(":8000", router))
} }

@ -0,0 +1,3 @@
> 1%
last 2 versions
not dead

@ -0,0 +1,23 @@
.DS_Store
node_modules
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

@ -0,0 +1,19 @@
# frontend
## Project setup
```
yarn install
```
### Compiles and hot-reloads for development
```
yarn serve
```
### Compiles and minifies for production
```
yarn build
```
### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).

@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}

@ -0,0 +1,28 @@
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"watch": "vue-cli-service build --watch"
},
"dependencies": {
"core-js": "^3.6.5",
"vue": "^2.6.11",
"vue-router": "^3.2.0",
"vuetify": "^2.5.14",
"vuex": "^3.4.0"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-router": "~4.5.0",
"@vue/cli-plugin-vuex": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"sass": "~1.32.0",
"sass-loader": "^10.0.0",
"vue-cli-plugin-vuetify": "~2.4.3",
"vue-template-compiler": "^2.6.11",
"vuetify-loader": "^1.7.0"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css">
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

@ -0,0 +1,31 @@
<template>
<v-app id="App">
<Drawer />
<SystemBar />
<AppBar />
<v-main dark app class="grey darken-4">
<router-view />
</v-main>
<StaticFab />
</v-app>
</template>
<script>
import SystemBar from "./components/SystemBar.vue"
import AppBar from "./components/AppBar.vue"
import Drawer from "./components/Drawer.vue"
import StaticFab from "./components/StaticFab.vue"
export default {
name: "App",
components: {
SystemBar,
AppBar,
Drawer,
StaticFab,
},
}
</script>

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

@ -0,0 +1 @@
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 87.5 100"><defs><style>.cls-1{fill:#1697f6;}.cls-2{fill:#7bc6ff;}.cls-3{fill:#1867c0;}.cls-4{fill:#aeddff;}</style></defs><title>Artboard 46</title><polyline class="cls-1" points="43.75 0 23.31 0 43.75 48.32"/><polygon class="cls-2" points="43.75 62.5 43.75 100 0 14.58 22.92 14.58 43.75 62.5"/><polyline class="cls-3" points="43.75 0 64.19 0 43.75 48.32"/><polygon class="cls-4" points="64.58 14.58 87.5 14.58 43.75 100 43.75 62.5 64.58 14.58"/></svg>

After

Width:  |  Height:  |  Size: 539 B

@ -0,0 +1,18 @@
<template>
<v-app-bar app dark flat>
<v-app-bar-nav-icon @click="toggleDrawer()"></v-app-bar-nav-icon>
<v-toolbar-title>Application</v-toolbar-title>
</v-app-bar>
</template>
<script>
export default {
name: "AppBar",
methods: {
toggleDrawer () {
this.$store.commit("toggleDrawer");
}
}
};
</script>

@ -0,0 +1,66 @@
<template>
<v-navigation-drawer
:value="drawer"
@input="toggleDrawer"
app
dark
>
<v-list-item>
<v-list-item-content>
<v-list-item-title class="text-h6">
Menu
</v-list-item-title>
<v-list-item-subtitle>
to get you where you want to go
</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-divider></v-divider>
<v-list
dense
nav
>
<v-list-item
v-for="item in items"
:key="item.title"
link
:to="{ name: item.to }"
>
<v-list-item-icon>
<v-icon>{{ item.icon }}</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>{{ item.title }}</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
</v-navigation-drawer>
</template>
<script>
export default {
name: "Drawer",
data () {
return {
items: [
{ title: 'Dashboard', icon: 'mdi-view-dashboard', to: 'Dashboard' },
{ title: 'About', icon: 'mdi-help-box', to: 'About' },
],
right: null,
}
},
computed: {
drawer() {
return this.$store.state.drawer
}
},
methods: {
toggleDrawer(event) {
this.$store.commit("updateDrawer", event)
}
}
};
</script>

@ -0,0 +1,151 @@
<template>
<v-container>
<v-row class="text-center">
<v-col cols="12">
<v-img
:src="require('../assets/logo.png')"
class="my-3"
contain
height="200"
/>
</v-col>
<v-col class="mb-4">
<h1 class="display-2 font-weight-bold mb-3">
Welcome to Vuetify
</h1>
<p class="subheading font-weight-regular">
For help and collaboration with other Vuetify developers,
<br>please join our online
<a
href="https://community.vuetifyjs.com"
target="_blank"
>Discord Community</a>
</p>
</v-col>
<v-col
class="mb-5"
cols="12"
>
<h2 class="headline font-weight-bold mb-3">
What's next?
</h2>
<v-row justify="center">
<a
v-for="(next, i) in whatsNext"
:key="i"
:href="next.href"
class="subheading mx-3"
target="_blank"
>
{{ next.text }}
</a>
</v-row>
</v-col>
<v-col
class="mb-5"
cols="12"
>
<h2 class="headline font-weight-bold mb-3">
Important Links
</h2>
<v-row justify="center">
<a
v-for="(link, i) in importantLinks"
:key="i"
:href="link.href"
class="subheading mx-3"
target="_blank"
>
{{ link.text }}
</a>
</v-row>
</v-col>
<v-col
class="mb-5"
cols="12"
>
<h2 class="headline font-weight-bold mb-3">
Ecosystem
</h2>
<v-row justify="center">
<a
v-for="(eco, i) in ecosystem"
:key="i"
:href="eco.href"
class="subheading mx-3"
target="_blank"
>
{{ eco.text }}
</a>
</v-row>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
name: 'HelloWorld',
data: () => ({
ecosystem: [
{
text: 'vuetify-loader',
href: 'https://github.com/vuetifyjs/vuetify-loader',
},
{
text: 'github',
href: 'https://github.com/vuetifyjs/vuetify',
},
{
text: 'awesome-vuetify',
href: 'https://github.com/vuetifyjs/awesome-vuetify',
},
],
importantLinks: [
{
text: 'Documentation',
href: 'https://vuetifyjs.com',
},
{
text: 'Chat',
href: 'https://community.vuetifyjs.com',
},
{
text: 'Made with Vuetify',
href: 'https://madewithvuejs.com/vuetify',
},
{
text: 'Twitter',
href: 'https://twitter.com/vuetifyjs',
},
{
text: 'Articles',
href: 'https://medium.com/vuetify',
},
],
whatsNext: [
{
text: 'Explore components',
href: 'https://vuetifyjs.com/components/api-explorer',
},
{
text: 'Select a layout',
href: 'https://vuetifyjs.com/getting-started/pre-made-layouts',
},
{
text: 'Frequently Asked Questions',
href: 'https://vuetifyjs.com/getting-started/frequently-asked-questions',
},
],
}),
}
</script>

@ -0,0 +1,52 @@
<template>
<div id="static-fab">
<v-speed-dial
v-model="fab"
bottom
right
direction="top"
fixed
transition="scale-transition"
>
<template v-slot:activator>
<v-btn v-model="fab" color="blue darken-2" dark fab>
<v-icon v-if="fab"> mdi-close </v-icon>
<v-icon v-else> mdi-plus </v-icon>
</v-btn>
</template>
<v-tooltip left>
<template v-slot:activator="{ on, attrs }">
<v-btn fab dark small color="blue" v-bind="attrs" v-on="on">
<v-icon>mdi-plus</v-icon>
</v-btn>
</template>
<span>Add Item</span>
</v-tooltip>
<v-tooltip left>
<template v-slot:activator="{ on, attrs }">
<v-btn fab dark small color="red" v-bind="attrs" v-on="on">
<v-icon>mdi-close</v-icon>
</v-btn>
</template>
<span>Remove Item</span>
</v-tooltip>
<v-tooltip left>
<template v-slot:activator="{ on, attrs }">
<v-btn fab dark small color="green" v-bind="attrs" v-on="on">
<v-icon>mdi-map-marker</v-icon>
</v-btn>
</template>
<span>Add Location</span>
</v-tooltip>
</v-speed-dial>
</div>
</template>
<script>
export default {
name: "StaticFab",
data: () => ({
fab: false,
}),
};
</script>

@ -0,0 +1,19 @@
<template>
<v-system-bar app dark>
<v-spacer></v-spacer>
<v-tooltip small bottom>
<template v-slot:activator="{ on, attrs }">
<router-link tag="span" to="/about">
<v-icon v-bind="attrs" v-on="on">mdi-information</v-icon>
</router-link>
</template>
<span>About</span>
</v-tooltip>
</v-system-bar>
</template>
<script>
export default {
name: "SystemBar",
};
</script>

@ -0,0 +1,14 @@
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import vuetify from './plugins/vuetify'
import store from './store'
Vue.config.productionTip = false
new Vue({
router,
vuetify,
store,
render: h => h(App)
}).$mount('#app')

@ -0,0 +1,7 @@
import Vue from 'vue';
import Vuetify from 'vuetify/lib/framework';
Vue.use(Vuetify);
export default new Vuetify({
});

@ -0,0 +1,28 @@
import Vue from 'vue'
import VueRouter from 'vue-router'
import Dashboard from '../views/Dashboard.vue'
Vue.use(VueRouter)
const routes = [
{
path: '/dashboard',
name: 'Dashboard',
component: Dashboard
},
{
path: '/about',
name: 'About',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
}
]
const router = new VueRouter({
base: process.env.BASE_URL,
routes
})
export default router

@ -0,0 +1,27 @@
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
drawer: null,
},
getters: {
},
mutations: {
toggleDrawer (state, payload) {
if (state.drawer === null) {
state.drawer = false;
}
state.drawer = !state.drawer
},
updateDrawer (state, payload) {
state.drawer = payload
}
},
actions: {
},
modules: {
}
})

@ -0,0 +1,5 @@
<template>
<div class="about">
<h1 class="grey--text lighten-4">This is an about page</h1>
</div>
</template>

@ -0,0 +1,35 @@
<template>
<v-container>
<v-row>
<template v-for="n in 4">
<v-col
:key="n"
class="mt-2"
cols="12"
>
<strong class="grey--text lighten-4">Category {{ n }}</strong>
</v-col>
<v-col
v-for="j in 6"
:key="`${n}${j}`"
cols="6"
md="2"
>
<v-sheet height="150"></v-sheet>
</v-col>
</template>
</v-row>
</v-container>
</template>
<script>
export default {
name: 'Dashboard',
components: {
},
}
</script>

@ -0,0 +1,5 @@
module.exports = {
transpileDependencies: [
'vuetify'
]
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,13 @@
//go:build !prod
// +build !prod
package ui
import (
"io/fs"
"os"
)
func getFrontendAssets() fs.FS {
return os.DirFS("pkg/ui/frontend/dist")
}

@ -0,0 +1,21 @@
//go:build prod
// +build prod
package ui
import (
"embed"
"io/fs"
)
//go:embed frontend/dist
var embedFrontend embed.FS
func getFrontendAssets() fs.FS {
f, err := fs.Sub(embedFrontend, "frontend/dist")
if err != nil {
panic(err)
}
return f
}

@ -0,0 +1,17 @@
package ui
import (
"net/http"
"github.com/gorilla/mux"
)
func GetRouter() *mux.Router {
frontend := getFrontendAssets()
frontendHandler := http.FileServer(http.FS(frontend))
router := mux.NewRouter()
router.Handle("/", frontendHandler)
router.NotFoundHandler = frontendHandler
return router
}
Loading…
Cancel
Save