Now able to do scoped client schemas showing on vue

v1
Andrew Sellers 5 years ago
parent 46b0c1fca8
commit 759350077c
  1. 3
      homunculus/api/api.go
  2. 3
      homunculus/api/index.go
  3. 16
      homunculus/context/context.go
  4. 3
      homunculus/frontend/package.json
  5. 4
      homunculus/frontend/src/App.vue
  6. 44
      homunculus/frontend/src/components/AdminIndex.vue
  7. 0
      homunculus/frontend/src/components/AdminNew.vue
  8. 3
      homunculus/frontend/src/store/index.js
  9. 30
      homunculus/frontend/src/store/mutations.js
  10. 5
      homunculus/setup/clients.go
  11. 17
      homunculus/web/server.go

@ -17,7 +17,8 @@ func Compile(apie map[string][]Endpoint, g *echo.Group) {
ng = g.Group("/" + namespace)
}
for _, ep := range ends {
for i := range ends {
ep := ends[i]
ng.GET("/"+ep.URL, ep.Index)
ng.GET("/"+ep.URL+"/:id", ep.Show)
ng.POST("/"+ep.URL, ep.Create)

@ -1,6 +1,8 @@
package api
import (
"fmt"
"github.com/acsellers/faust/homunculus/context"
"github.com/acsellers/faust/homunculus/db"
"github.com/labstack/echo"
@ -40,6 +42,7 @@ func (ae *Endpoint) Index(e echo.Context) error {
// TODO: maybe pass a context to the query?
// TODO: sort stuff
// TODO: more stuff here around filtering
fmt.Println(q.GenerateSelect())
results, err := q.Execute()
if err != nil {
return err

@ -4,6 +4,7 @@ import (
"database/sql"
"net/http"
"strconv"
"strings"
"github.com/acsellers/faust/homunculus/db"
"github.com/acsellers/faust/homunculus/user"
@ -17,6 +18,19 @@ type Context struct {
User user.UserInfo
}
func StripPort(hostport string) string {
colon := strings.IndexByte(hostport, ':')
if colon == -1 {
return hostport
}
if i := strings.IndexByte(hostport, ']'); i != -1 {
return strings.TrimPrefix(hostport[:i], "[")
}
return hostport[:colon]
}
var ClientHosts = make(map[string]string)
func NewContext(e echo.Context) (*Context, error) {
ctx := &Context{
Context: e,
@ -42,5 +56,5 @@ func LoadUser(e echo.Context) (user.UserInfo, error) {
}
func LoadSchema(e echo.Context) string {
return "schema_placeholder"
return ClientHosts[StripPort(e.Request().Host)]
}

@ -17,7 +17,8 @@
"vue": "^2.5.16",
"vue-router": "^3.0.1",
"vuetify": "^1.0.12",
"vuex": "^3.0.1"
"vuex": "^3.0.1",
"axios": "^0.17.1"
},
"devDependencies": {
"autoprefixer": "^7.1.2",

@ -39,10 +39,8 @@
</v-toolbar>
<v-content>
<v-container fluid>
<router-view></router-view>
</v-container>
<v-btn fixed dark fab bottom right color="red">
<v-icon>add</v-icon>
</v-btn>
</v-content>
</v-app>
</template>

@ -8,7 +8,7 @@
<v-data-table
v-model="selected"
:headers="headers"
:items="items"
:items="viewitems"
select-all
item-key="name"
class="elevation-1"
@ -28,7 +28,6 @@
v-for="header in props.headers"
:key="header.text"
:class="['column sortable', pagination.descending ? 'desc' : 'asc', header.value === pagination.sortBy ? 'active' : '']"
@click="changeSort(header.value)"
>
<v-icon small>arrow_upward</v-icon>
{{ header.text }}
@ -44,12 +43,16 @@
:input-value="props.selected"
></v-checkbox>
</td>
<td>{{ props.item.first_name }} {{ props.item.last_name }}</td>
<td>{{ props.item.first_name }}</td>
<td>{{ props.item.last_name }}</td>
<td>{{ props.item.email}}</td>
<td class="text-xs-right">{{ props.item.id }}</td>
</tr>
</template>
</v-data-table>
<v-btn fixed dark fab bottom right color="red">
<v-icon>add</v-icon>
</v-btn>
</v-flex>
</v-layout>
</template>
@ -62,12 +65,19 @@ export default {
return {
selected: [],
pagination: {
sortBy: 'name'
sortBy: 'last_name'
}
}
},
mounted () {
this.$store.dispatch('loadAdminItems', 'users')
},
computed: {
...mapGetters(['users']),
...mapGetters(['items']),
viewitems () {
return this.items
},
title () {
var title = 'Unknown Model'
switch (this.$route.params.modeltype) {
@ -86,24 +96,22 @@ export default {
headers () {
return [
{
text: 'Name',
value: 'name'
text: 'First Name',
value: 'first_name'
},
{
text: 'Last Name',
value: 'last_name'
},
{
text: 'Email',
value: 'email'
},
{
text: 'ID',
value: 'id'
}
]
},
items () {
switch (this.$route.params.modeltype) {
case 'users':
return this.users
case 'announcements':
return this.announcments
case 'roles':
return this.roles
}
}
}
}

@ -1,6 +1,6 @@
import Vue from 'vue'
import Vuex from 'vuex'
import { state, mutations, getters } from './mutations'
import { actions, state, mutations, getters } from './mutations'
import plugins from './plugins'
Vue.use(Vuex)
@ -8,6 +8,7 @@ Vue.use(Vuex)
export default new Vuex.Store({
state,
getters,
actions,
mutations,
plugins
})

@ -1,16 +1,38 @@
import axios from 'axios'
export const STORAGE_KEY = 'homunculus'
export const actions = {
loadAdminItems ({ commit }, payload) {
axios
.get('http://spacey.lvh.me:8087/api/' + payload)
.then(r => r.data)
.then(items => {
commit('set_admin_items', items)
})
},
saveAdminItem ({ commit, args }) {
axios.post('http://spacey.lvh.me:8087/api/' + args.modeltype, args.data).then(item => {
commit('add_admin_item', item)
})
}
}
export const state = {
users: JSON.parse(window.localStorage.getItem(STORAGE_KEY + '_users') || '[{"id":123,"first_name":"Andrew","last_name":"Sellers"}]')
items: []
}
export const getters = {
users: state => state.users
items: state => state.items
}
export const mutations = {
addUser (state, { user }) {
state.users.push(user)
set_admin_items (state, items) {
console.log(items)
state.items = items
},
add_admin_item (state, { user }) {
state.items.push(user)
},
deleteUser (state, {user}) {
state.users.splice(state.users.indexOf(user), 1)

@ -1,6 +1,9 @@
package setup
import (
"fmt"
"github.com/acsellers/faust/homunculus/context"
"github.com/acsellers/faust/homunculus/db"
"github.com/acsellers/faust/homunculus/extend"
)
@ -10,7 +13,9 @@ func BuildClients() map[string]*extend.SiteConfig {
clients := db.GetClients(DB)
for _, client := range clients {
site := extend.BuildSite(client)
context.ClientHosts[client.Host] = client.Schema
sites[site.Host] = site
}
fmt.Println(context.ClientHosts)
return sites
}

@ -10,8 +10,8 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/acsellers/faust/homunculus/context"
"github.com/acsellers/faust/homunculus/extend"
"github.com/GeertJohan/go.rice"
@ -42,16 +42,6 @@ func init() {
var appConfig = `{"api":"{"host":"localhost:8089"}}`
func stripPort(hostport string) string {
colon := strings.IndexByte(hostport, ':')
if colon == -1 {
return hostport
}
if i := strings.IndexByte(hostport, ']'); i != -1 {
return strings.TrimPrefix(hostport[:i], "[")
}
return hostport[:colon]
}
func ServeAPI(sites map[string]*extend.SiteConfig) {
if !runAPI {
return
@ -63,7 +53,7 @@ func ServeAPI(sites map[string]*extend.SiteConfig) {
r.Any("/api/*", func(e echo.Context) error {
req := e.Request()
res := e.Response()
host := sites[stripPort(req.Host)]
host := sites[context.StripPort(req.Host)]
if host == nil {
return echo.ErrNotFound
@ -136,5 +126,8 @@ func DefaultServer() *echo.Echo {
r := echo.New()
r.Use(middleware.Logger())
r.Use(middleware.Recover())
r.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
}))
return r
}

Loading…
Cancel
Save