Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chart experiments #316

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Some of it's standout features:
* Media support, both locally and in S3 compatible services
* Dark mode support
* CSV exports
* Easily create custom forms
* Easily create custom forms, and display data in charts
* Works on mobile and desktop
* Use standalone, or integrate it easily with ASGI apps like FastAPI, and Starlette
* Multilingual out of box
Expand Down
20,259 changes: 56 additions & 20,203 deletions admin_ui/package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions admin_ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
"@fortawesome/vue-fontawesome": "^0.1.10",
"@types/js-cookie": "^2.2.6",
"axios": "^0.21.2",
"chart.js": "^2.9.4",
"core-js": "^3.6.5",
"flatpickr": "^4.6.9",
"is-svg": "^4.3.1",
"js-cookie": "^2.2.1",
"json-bigint": "^1.0.0",
"ssri": "^8.0.1",
"vue": "^2.7.14",
"vue-chartkick": "^0.6.1",
"vue-class-component": "^7.2.6",
"vue-flatpickr-component": "^8.1.7",
"vue-i18n": "^8.27.2",
Expand Down
114 changes: 114 additions & 0 deletions admin_ui/src/components/Chart.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<template>
<div v-if="chartConfig">
<h3>{{ chartConfig.title }}</h3>
<pie-chart
width="650px"
height="450px"
:download="{ background: '#ffffff' }"
v-if="chartConfig.chart_type == 'Pie'"
:data="chartData"
></pie-chart>
<line-chart
width="650px"
height="450px"
:download="{ background: '#ffffff' }"
v-else-if="chartConfig.chart_type == 'Line'"
:data="chartData"
></line-chart>
<column-chart
width="650px"
height="450px"
:download="{ background: '#ffffff' }"
v-else-if="chartConfig.chart_type == 'Column'"
:data="chartData"
></column-chart>
<bar-chart
width="650px"
height="450px"
:download="{ background: '#ffffff' }"
v-else-if="chartConfig.chart_type == 'Bar'"
:data="chartData"
></bar-chart>
<area-chart
width="650px"
height="450px"
:download="{ background: '#ffffff' }"
v-else-if="chartConfig.chart_type == 'Area'"
:data="chartData"
></area-chart>

<form @submit.prevent="handleSubmit($event)" v-if="chartSchema">
<NewForm :schema="chartSchema"></NewForm>
<button>Apply</button>
</form>
</div>
</template>

<script lang="ts">
import Vue from "vue"
import NewForm from "./NewForm.vue"
import { convertFormValue } from "@/utils"

export default Vue.extend({
data() {
return {
chartData: [],
chartConfig: null,
chartSchema: null,
chartSlug: null
}
},
components: { NewForm },
methods: {
async handleSubmit(event) {
const form = new FormData(event.target)

const json = {}
for (const i of form.entries()) {
const key = i[0]
let value = i[1]

json[key] = convertFormValue({
key,
value,
schema: this.chartSchema
})
}

this.chartData = (
await this.$store.dispatch("fetchChartData", {
chartSlug: this.chartSlug,
data: json
})
).data
}
},
async mounted() {
this.chartSlug = this.$router.currentRoute.params.chartSlug

this.chartData = (
await this.$store.dispatch("fetchChartData", {
chartSlug: this.chartSlug,
data: {}
})
).data

this.chartConfig = (
await this.$store.dispatch("fetchChartConfig", this.chartSlug)
).data

if (this.chartConfig.has_form) {
this.chartSchema = (
await this.$store.dispatch("fetchChartSchema", this.chartSlug)
).data
}
}
})
</script>

<style scoped lang="less">
h3 {
text-transform: capitalize;
text-align: center;
}
</style>
31 changes: 31 additions & 0 deletions admin_ui/src/components/ChartsNav.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<template>
<ul>
<li v-bind:key="chartConfig.title" v-for="chartConfig in chartConfigs">
<router-link
:to="{
name: 'chart',
params: { chartSlug: chartConfig.slug }
}"
class="subtle"
>
<font-awesome-icon icon="level-up-alt" class="rotated90" />
<span>{{ chartConfig.title }}</span>
</router-link>
</li>
</ul>
</template>

<script lang="ts">
import Vue from "vue"

export default Vue.extend({
computed: {
chartConfigs() {
return this.$store.state.chartConfigs
}
},
async mounted() {
await this.$store.dispatch("fetchChartConfigs")
}
})
</script>
22 changes: 22 additions & 0 deletions admin_ui/src/components/SidebarNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@
</span>
</p>
<FormNav v-show="!isHiddenForms" />
<p
class="opaque"
v-if="chartConfigs.length > 0"
v-on:click="isHiddenCharts = !isHiddenCharts"
>
<font-awesome-icon icon="chart-bar" />{{ $t("Charts") }}
<span style="float: right">
<font-awesome-icon
icon="angle-down"
title="Show charts"
v-if="isHiddenCharts"
/>
<font-awesome-icon icon="angle-up" title="Hide charts" v-else />
</span>
</p>
<ChartsNav v-show="!isHiddenCharts" />
<p
class="opaque"
v-if="Object.keys(customLinks).length > 0"
Expand All @@ -56,25 +72,31 @@
import Vue from "vue"
import TableNav from "./TableNav.vue"
import FormNav from "./FormNav.vue"
import ChartsNav from "./ChartsNav.vue"
import LinksNav from "./LinksNav.vue"

export default Vue.extend({
data() {
return {
isHiddenTables: false,
isHiddenForms: false,
isHiddenCharts: false,
isHiddenLinks: false
}
},
components: {
TableNav,
FormNav,
ChartsNav,
LinksNav
},
computed: {
formConfigs() {
return this.$store.state.formConfigs
},
chartConfigs() {
return this.$store.state.chartConfigs
},
customLinks() {
return this.$store.state.customLinks
}
Expand Down
2 changes: 1 addition & 1 deletion admin_ui/src/components/TableNav.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div>
<div class="sidebar_wrapper">
<ul class="table_list">
<TableNavItem
v-bind:key="tableName"
Expand Down
2 changes: 2 additions & 0 deletions admin_ui/src/fontawesome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
faBars,
faCaretUp,
faCaretDown,
faChartBar,
faCheck,
faCircleNotch,
faCogs,
Expand Down Expand Up @@ -55,6 +56,7 @@ library.add(
faBars,
faCaretUp,
faCaretDown,
faChartBar,
faCheck,
faCircleNotch,
faCogs,
Expand Down
7 changes: 7 additions & 0 deletions admin_ui/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,10 @@ export interface FormConfig {
slug: string
description: string
}

export interface ChartConfig {
title: string
slug: string
chart_type: string
data: any
}
5 changes: 4 additions & 1 deletion admin_ui/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import router from "./router"
import store from "./store"
import i18n from "./i18n"
import "./fontawesome"
import Chartkick from 'vue-chartkick'
import Chart from 'chart.js'

/*****************************************************************************/

Expand All @@ -30,7 +32,7 @@ axios.defaults.transformResponse = [
if (typeof data === "string") {
try {
data = JSONBig.parse(data)
} catch (e) {}
} catch (e) { }
}
return data
}
Expand All @@ -45,6 +47,7 @@ Vue.filter("readable", function (value) {
/*****************************************************************************/

Vue.config.productionTip = false
Vue.use(Chartkick.use(Chart))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// charts font color and gridlines in dark mode
if (localStorage.getItem('darkMode')) {
Chart.defaults.global.defaultFontColor = "#ffffff"
Chart.defaults.scale.gridLines.color = "#ffffff"
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a way to change Chart.js colors in dark mode, but unfortunately it doesn't work without refreshing the page. I'm sorry I didn't check before posting the suggested change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, it's still useful - there might be a way to reload the chart without reloading the entire page.

new Vue({
i18n,
Expand Down
55 changes: 31 additions & 24 deletions admin_ui/src/router.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,64 @@
import Vue from 'vue'
import Router from 'vue-router'
import Vue from "vue"
import Router from "vue-router"

import AddRow from './views/AddRow.vue'
import EditRow from './views/EditRow.vue'
import Home from './views/Home.vue'
import Login from './views/Login.vue'
import ChangePassword from './views/ChangePassword.vue'
import RowListing from './views/RowListing.vue'
import AddForm from './views/AddForm.vue'
import AddRow from "./views/AddRow.vue"
import EditRow from "./views/EditRow.vue"
import Home from "./views/Home.vue"
import Login from "./views/Login.vue"
import ChangePassword from "./views/ChangePassword.vue"
import RowListing from "./views/RowListing.vue"
import AddForm from "./views/AddForm.vue"
import ChartView from "./views/ChartView.vue"

Vue.use(Router)

export default new Router({
mode: 'hash',
mode: "hash",
base: process.env.BASE_URL,
routes: [
{
path: '/',
name: 'home',
path: "/",
name: "home",
component: Home
},
{
path: '/login/',
name: 'login',
path: "/login/",
name: "login",
component: Login
},
{
path: '/change-password/',
name: 'changePassword',
path: "/change-password/",
name: "changePassword",
component: ChangePassword,
props: true
},
{
path: '/forms/:formSlug/',
name: 'addForm',
path: "/forms/:formSlug/",
name: "addForm",
component: AddForm,
props: true
},
{
path: '/:tableName/',
name: 'rowListing',
path: "/charts/:chartSlug",
name: "chart",
component: ChartView,
props: true
},
{
path: "/:tableName/",
name: "rowListing",
component: RowListing,
props: true
},
{
path: '/:tableName/add/',
name: 'addRow',
path: "/:tableName/add/",
name: "addRow",
component: AddRow,
props: true
},
{
path: '/:tableName/:rowID/',
name: 'editRow',
path: "/:tableName/:rowID/",
name: "editRow",
component: EditRow,
props: true
}
Expand Down
Loading