Half way through app re-organisation

This commit is contained in:
Alan Rynne 2021-09-12 18:40:00 +02:00
Родитель bf6d2bb681
Коммит bcff97c8ee
12 изменённых файлов: 15792 добавлений и 160 удалений

Просмотреть файл

@ -1,7 +1,7 @@
# Replace these with the app id and app secret that you get once registering # Replace these with the app id and app secret that you get once registering
# an application on the Speckle Server! # an application on the Speckle Server!
VUE_APP_SPECKLE_ID=c2c12aaad2 VUE_APP_SPECKLE_ID=daf0e0546d
VUE_APP_SPECKLE_SECRET=3b4109dc32 VUE_APP_SPECKLE_SECRET=3c92fff425
# Make sure you change this to use the server of your choice! # Make sure you change this to use the server of your choice!
VUE_APP_SERVER_URL=https://speckle.xyz VUE_APP_SERVER_URL=https://latest.speckle.dev
VUE_APP_SPECKLE_NAME="Speckle Demo App" VUE_APP_SPECKLE_NAME="Speckle — Revit Dashboard"

15635
package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,5 +1,5 @@
{ {
"name": "speckle-demo-app", "name": "speckle-revit-dashboard-app",
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"scripts": { "scripts": {
@ -9,7 +9,7 @@
}, },
"dependencies": { "dependencies": {
"@speckle/objectloader": "^2.0.0", "@speckle/objectloader": "^2.0.0",
"@speckle/viewer": "^2.0.1", "@speckle/viewer": "^2.1.0",
"core-js": "^3.6.5", "core-js": "^3.6.5",
"debounce": "^1.2.1", "debounce": "^1.2.1",
"register-service-worker": "^1.7.1", "register-service-worker": "^1.7.1",

Просмотреть файл

@ -15,11 +15,15 @@
width="40" width="40"
height="24" height="24"
/> />
<h3>Speckle Demo App</h3> <h3>Speckle</h3>
</div> </div>
<v-spacer></v-spacer> <v-spacer></v-spacer>
<stream-search @selected="$store.dispatch('handleStreamSelection', $event)"/>
<v-spacer></v-spacer>
<div v-if="isAuthenticated" class="mr-1"> <div v-if="isAuthenticated" class="mr-1">
Welcome <b>{{ this.$store.state.user.name }}</b>! Welcome <b>{{ this.$store.state.user.name }}</b>!
</div> </div>
@ -43,8 +47,11 @@
</template> </template>
<script> <script>
import StreamSearch from "@/components/StreamSearch";
export default { export default {
name: 'App', name: 'App',
components: {StreamSearch},
computed: { computed: {
isAuthenticated() { isAuthenticated() {
return this.$store.getters.isAuthenticated return this.$store.getters.isAuthenticated

Просмотреть файл

@ -0,0 +1,13 @@
<template>
<div></div>
</template>
<script>
export default {
name: "RevitProjectInfo"
}
</script>
<style scoped>
</style>

Просмотреть файл

@ -0,0 +1,40 @@
<template>
<v-container id="revitStream" class="pa-6">
<h2 class="pt-6 primary--text">
<span v-if="stream">
{{ stream.name }} {{ stream.id }}
<v-btn outlined text small class="ml-3" :href="serverUrl+'/streams/'+stream.id">View in server</v-btn>
<v-btn outlined text small class="ml-3" color="error" @click="$store.dispatch('clearStreamSelection')">Clear selection</v-btn>
</span>
<span v-else>
<em>No stream selected. Find one using the search bar 👆🏼</em>
</span>
</h2>
</v-container>
</template>
<script>
export default {
name: "RevitStream.vue",
props: [ "streamId" ],
data(){
return {
stream: null
}
},
computed: {
isRevitCommit: () => true
},
watch: {
streamId: {
handler: (val, oldVal) => {
console.log("stream id changed")
}
}
}
}
</script>
<style scoped>
</style>

Просмотреть файл

@ -1,7 +1,7 @@
<template lang="html"> <template lang="html">
<v-container fill-height class="home flex-column justify-center align-center primary--text"> <v-container fill-height class="home flex-column justify-center align-center primary--text">
<h1>Welcome to the Speckle Demo App!</h1> <h1>Welcome to the Speckle Revit Dashboard App</h1>
<h3>This app part of our developer guide on how to create your very own Speckle App.</h3> <h3>This app allows you to analyse the data sent from Revit to a Speckle server.</h3>
<v-alert type="info" text color="primary" class="my-5 dark"> <v-alert type="info" text color="primary" class="my-5 dark">
Check out <a href="https://speckle.guide/dev/apps" target="_blank">the tutorial</a>! Check out <a href="https://speckle.guide/dev/apps" target="_blank">the tutorial</a>!
</v-alert> </v-alert>

Просмотреть файл

@ -2,6 +2,7 @@ import Vue from 'vue'
import VueRouter from 'vue-router' import VueRouter from 'vue-router'
import Home from '../views/Home.vue' import Home from '../views/Home.vue'
import store from '../store/index.js' import store from '../store/index.js'
import WelcomeView from "@/components/WelcomeView";
Vue.use(VueRouter) Vue.use(VueRouter)
@ -9,7 +10,15 @@ const routes = [
{ {
path: '/', path: '/',
name: 'Home', name: 'Home',
component: Home component: Home,
meta: {
isProtected: true
}
},
{
path: '/login',
name: 'Login',
component: WelcomeView
} }
] ]
@ -30,14 +39,14 @@ router.beforeEach( async (to, from, next) => {
// Whatever happens, go home. // Whatever happens, go home.
next("/") next("/")
} }
else if(to.meta.isProtected){
await store.dispatch("getUser")
var isAuth = store.getters.isAuthenticated
if(!isAuth) next("/login")
else next()
}
else { else {
try { next()
// Check on every route change if you still have access.
var goto = await store.dispatch("getUser")
next(goto)
} catch (err) {
next("/")
}
} }
}) })

Просмотреть файл

@ -26,6 +26,7 @@ export const streamCommitsQuery = (streamId, itemsPerPage, cursor) => `query {
} }
}` }`
export const streamSearchQuery = (search) => `query { export const streamSearchQuery = (search) => `query {
streams(query: "${search}") { streams(query: "${search}") {
totalCount totalCount

Просмотреть файл

@ -24,9 +24,6 @@ export default new Vuex.Store({
user: null, user: null,
serverInfo: null, serverInfo: null,
currentStream: null, currentStream: null,
latestCommits: null,
previousCursors: [null],
tableOptions: null
}, },
getters: { getters: {
isAuthenticated: (state) => state.user != null isAuthenticated: (state) => state.user != null
@ -40,18 +37,6 @@ export default new Vuex.Store({
}, },
setCurrentStream(state, stream) { setCurrentStream(state, stream) {
state.currentStream = stream state.currentStream = stream
},
setCommits(state, commits) {
state.latestCommits = commits
},
setTableOptions(state, options) {
state.tableOptions = options
},
resetPrevCursors(state) {
state.previousCursors = [ null ]
},
addCursorToPreviousList(state, cursor){
state.previousCursors.push(cursor)
} }
}, },
actions: { actions: {
@ -60,9 +45,6 @@ export default new Vuex.Store({
context.commit("setUser", null) context.commit("setUser", null)
context.commit("setServerInfo", null) context.commit("setServerInfo", null)
context.commit("setCurrentStream", null) context.commit("setCurrentStream", null)
context.commit("setCommits", null)
context.commit("setTableOptions", null)
context.commit("resetPrevCursors")
// Wipe the tokens // Wipe the tokens
speckleLogOut() speckleLogOut()
}, },
@ -85,20 +67,9 @@ export default new Vuex.Store({
}, },
async handleStreamSelection(context, stream) { async handleStreamSelection(context, stream) {
context.commit("setCurrentStream", stream) context.commit("setCurrentStream", stream)
context.commit("setTableOptions", { itemsPerPage: 5 })
context.commit("resetPrevCursors")
var json = await getStreamCommits(stream.id, 5, null)
context.commit("setCommits", json.data.stream.commits)
},
async getCommits(context, cursor) {
var json = await getStreamCommits(context.state.currentStream.id, 5, cursor)
context.commit("setCommits", json.data.stream.commits)
}, },
clearStreamSelection(context){ clearStreamSelection(context){
context.commit("setCurrentStream", null) context.commit("setCurrentStream", null)
context.commit("setCommits", null)
context.commit("setTableOptions", null)
context.commit("resetPrevCursors", [ null ])
} }
}, },
modules: {} modules: {}

89
src/views/CommitTable.vue Normal file
Просмотреть файл

@ -0,0 +1,89 @@
<template lang="html">
<div class="pt-6">
<v-select
v-model="selectedKeys"
:items="availableKeys"
chips
label="Select data to display"
multiple
></v-select>
<h3 class="pa-2 primary--text">Stream commits:</h3>
<v-data-table
:loading="loading"
:headers="filteredHeaders"
:items="commits ? commits.items : []"
:options.sync="options"
:server-items-length="commits ? commits.totalCount : null"
disable-sort
disable-filtering
:disable-pagination="loading"
class="elevation-1"
></v-data-table>
</div>
</template>
<script>
export default {
name: 'CommitTable',
data: () => {
return {
loading: false,
options: {
itemsPerPage: 5
},
selectedKeys: ["id", "message", "branchName", "authorName"],
}
},
mounted() {
var storedOpts = this.$store.state.tableOptions
if (storedOpts) this.options = storedOpts
},
computed: {
commits: function () {
return this.$store.state.latestCommits
},
previousCursors: function () {
return this.$store.state.previousCursors || [null]
},
availableKeys: function () {
var keys = {}
this.commits?.items.forEach(obj => {
Object.keys(obj).forEach(key => {
if (!keys[key]) {
keys[key] = true
}
})
})
return Object.keys(keys)
},
filteredHeaders: function () {
return this.selectedKeys.map(key => {
return {text: key, value: key}
})
},
},
watch: {
options: {
async handler(val, oldval) {
this.$store.commit("setTableOptions", val)
if (oldval.page && val.page != oldval.page) {
if (val.page > oldval.page) {
this.loading = true
var cursor = this.$store.state.latestCommits.cursor
await this.$store.dispatch("getCommits", cursor)
this.$store.commit("addCursorToPreviousList", cursor)
this.loading = false
} else {
console.log("page down")
this.loading = true
await this.$store.dispatch("getCommits", this.previousCursors[val.page - 1])
this.loading = false
}
}
},
deep: true
}
}
}
</script>

Просмотреть файл

@ -1,113 +1,28 @@
<template lang="html"> <template lang="html">
<WelcomeView v-if="!$store.getters.isAuthenticated"/> <v-container class="home pa-6">
<v-container v-else class="home pa-6"> <revit-stream :stream-id="selectedStream.id"/>
<stream-search @selected="$store.dispatch('handleStreamSelection', $event)"/>
<h2 class="pt-6 primary--text">
<span v-if="selectedStream">
{{ selectedStream.name }} {{ selectedStream.id }}
<v-btn outlined text small class="ml-3" :href="serverUrl+'/streams/'+selectedStream.id">View in server</v-btn>
<v-btn outlined text small class="ml-3" color="error" @click="$store.dispatch('clearStreamSelection')">Clear selection</v-btn>
</span>
<span v-else>
<em>No stream selected. Find one using the search bar 👆🏼</em>
</span>
</h2>
<div class="pt-6">
<v-select
v-model="selectedKeys"
:items="availableKeys"
chips
label="Select data to display"
multiple
></v-select>
<h3 class="pa-2 primary--text">Stream commits:</h3>
<v-data-table
:loading="loading"
:headers="filteredHeaders"
:items="commits ? commits.items : []"
:options.sync="options"
:server-items-length="commits ? commits.totalCount : null"
disable-sort
disable-filtering
:disable-pagination="loading"
class="elevation-1"
></v-data-table>
</div>
</v-container> </v-container>
</template> </template>
<script> <script>
import StreamSearch from "@/components/StreamSearch"; import StreamSearch from "@/components/StreamSearch";
import WelcomeView from "@/components/WelcomeView"; import WelcomeView from "@/components/WelcomeView";
import CommitTable from "./CommitTable";
import RevitStream from "@/components/RevitStream"
export default { export default {
name: 'Home', name: 'Home',
components: {WelcomeView, StreamSearch}, components: {RevitStream},
data: () => { data: () => {
return { return {
loading: false,
options: {
itemsPerPage: 5
},
serverUrl: process.env.VUE_APP_SERVER_URL, serverUrl: process.env.VUE_APP_SERVER_URL,
selectedKeys: ["id", "message", "branchName", "authorName"],
} }
}, },
mounted() {
var storedOpts = this.$store.state.tableOptions
if (storedOpts) this.options = storedOpts
},
methods: {}, methods: {},
computed: { computed: {
selectedStream: function () { selectedStream: function () {
return this.$store.state.currentStream return this.$store.state.currentStream
}, },
previousCursors: function () {
return this.$store.state.previousCursors || [null]
},
commits: function () {
return this.$store.state.latestCommits
},
availableKeys: function () {
var keys = {}
this.commits?.items.forEach(obj => {
Object.keys(obj).forEach(key => {
if (!keys[key]) {
keys[key] = true
}
})
})
return Object.keys(keys)
},
filteredHeaders: function () {
return this.selectedKeys.map(key => {
return {text: key, value: key}
})
}
},
watch: {
options: {
async handler(val, oldval) {
this.$store.commit("setTableOptions", val)
if (oldval.page && val.page != oldval.page) {
if (val.page > oldval.page) {
this.loading = true
var cursor = this.$store.state.latestCommits.cursor
await this.$store.dispatch("getCommits", cursor)
this.$store.commit("addCursorToPreviousList", cursor)
this.loading = false
} else {
console.log("page down")
this.loading = true
await this.$store.dispatch("getCommits", this.previousCursors[val.page - 1])
this.loading = false
}
}
},
deep: true
}
} }
} }
</script> </script>