Skip to content

Commit

Permalink
Add dashboard edit mode and card sorting (#63)
Browse files Browse the repository at this point in the history
- Hide buttons on small screens behind an "edit mode" that can be toggled from a button on the top toolbar
- Add trash can icon to dashboard to quickly remove sensor cards
- Add sort buttons to allow sorting dashboard sensor cards in the preferred order
- Sort button and trash can are visible on hover on desktops
  • Loading branch information
jaythomas authored Oct 21, 2021
1 parent 7b655d6 commit 7997290
Show file tree
Hide file tree
Showing 16 changed files with 422 additions and 58 deletions.
26 changes: 13 additions & 13 deletions web-app/src/components/BookmarkButton.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<template>
<div class="bookmark-button">
<div class="bookmark-button" :class="{ 'edit-mode': editMode }">
<v-btn x-small @click="toggleBookmark()">
<v-icon v-if="bookmarked">mdi-bookmark-check-outline</v-icon>
<v-icon v-if="isDashboard" small>mdi-trash-can-outline</v-icon>
<v-icon v-else-if="bookmarked">mdi-bookmark-check-outline</v-icon>
<v-icon v-else>mdi-bookmark-plus</v-icon>
</v-btn>
</div>
Expand All @@ -12,6 +13,14 @@ import { mapMutations } from 'vuex'
export default {
props: {
editMode: {
required: true,
type: Boolean
},
isDashboard: {
required: true,
type: Boolean
},
mode: {
required: true,
type: String
Expand Down Expand Up @@ -63,18 +72,9 @@ export default {
z-index: 1;
}
/* Always display the button if this is a touch device */
@media (pointer: none) {
.bookmark-button {
@media screen and (max-width: 1000px) {
.bookmark-button.edit-mode {
display: block;
}
}
/* Backwards compatibility */
@media (hover: none) {
.bookmark-button {
display: block;
}
}
</style>
30 changes: 20 additions & 10 deletions web-app/src/components/CardContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,49 @@
>
<ElevationCard
v-if="sensor.type.label === 'elevation'"
:edit-mode="editMode"
:sensor="sensor"
@change-mode="changeMode(sensor.id, $event)"
@change-mode="changeCardView(sensor.id, $event)"
@change-time-ago="changeTimeAgo(sensor.id, $event)"
class="card"
/>
<HumidityCard
v-else-if="sensor.type.label === 'humidity'"
:edit-mode="editMode"
:sensor="sensor"
@change-mode="changeMode(sensor.id, $event)"
@change-mode="changeCardView(sensor.id, $event)"
@change-time-ago="changeTimeAgo(sensor.id, $event)"
class="card"
/>
<PressureCard
v-else-if="sensor.type.label === 'pressure'"
:edit-mode="editMode"
:sensor="sensor"
@change-mode="changeMode(sensor.id, $event)"
@change-mode="changeCardView(sensor.id, $event)"
@change-time-ago="changeTimeAgo(sensor.id, $event)"
class="card"
/>
<SignalCard
v-else-if="sensor.type.label === 'signal'"
:edit-mode="editMode"
:sensor="sensor"
@change-mode="changeMode(sensor.id, $event)"
@change-mode="changeCardView(sensor.id, $event)"
@change-time-ago="changeTimeAgo(sensor.id, $event)"
class="card"
/>
<TemperatureCard
v-else-if="sensor.type.label === 'temperature'"
:edit-mode="editMode"
:sensor="sensor"
@change-mode="changeMode(sensor.id, $event)"
@change-mode="changeCardView(sensor.id, $event)"
@change-time-ago="changeTimeAgo(sensor.id, $event)"
class="card"
/>
<VoltageCard
v-else-if="sensor.type.label === 'voltage'"
:edit-mode="editMode"
:sensor="sensor"
@change-mode="changeMode(sensor.id, $event)"
@change-mode="changeCardView(sensor.id, $event)"
@change-time-ago="changeTimeAgo(sensor.id, $event)"
class="card"
/>
Expand Down Expand Up @@ -75,13 +81,18 @@ export default {
VoltageCard
},
props: {
editMode: {
default: true,
required: false,
type: Boolean
},
sensors: {
required: true,
type: Array
}
},
methods: {
changeMode(sensorId, mode) {
changeCardView(sensorId, mode) {
this.$emit('change-mode', { sensorId, mode })
},
changeTimeAgo(sensorId, timeAgo) {
Expand Down Expand Up @@ -139,8 +150,7 @@ export default {
display: block;
}
@media screen and (max-width: 640px) {
.card {
}
/deep/ .card:hover .sort-buttons {
display: block;
}
</style>
28 changes: 25 additions & 3 deletions web-app/src/components/CardHeader.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
<template>
<div class="header">
<div class="header" :class="{ 'edit-mode': editMode }">
<slot />
</div>
</template>

<script>
export default {
props: {
editMode: {
required: true,
type: Boolean
}
}
}
</script>

<style scoped>
/* Offset to account for buttons when in edit mode */
.edit-mode {
left: 12%;
}
.header {
position: absolute;
left: 12%;
font-size: 1.14em;
font-weight: bold;
z-index: 1;
text-shadow: 2px 2px var(--v-text-inverse-base);
}
</style>>
/* Buttons are always present on larger screen widths */
@media screen and not (max-width: 1000px) {
.header {
left: 12%;
}
}
</style>
2 changes: 2 additions & 0 deletions web-app/src/components/CurrentView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default {
flex-direction: row;
flex-wrap: wrap;
line-height: 1.1;
padding-top: 4px;
position: relative;
z-index: 1;
}
Expand All @@ -106,6 +107,7 @@ export default {
}
.sparkline {
padding-top: 4px;
position: absolute;
z-index: 0;
}
Expand Down
29 changes: 29 additions & 0 deletions web-app/src/components/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@

<v-spacer></v-spacer>

<v-app-bar-nav-icon
v-if="$route.name === 'dashboard'"
class="edit-button"
@click="editMode = !editMode">
<v-icon v-if="editMode">mdi-lock-open-variant</v-icon>
<v-icon v-else>mdi-lock</v-icon>
</v-app-bar-nav-icon>

<v-app-bar-nav-icon @click="preferencesDrawerOpen = !preferencesDrawerOpen">
<v-icon>mdi-cog</v-icon>
</v-app-bar-nav-icon>
Expand All @@ -39,6 +47,14 @@ export default {
PreferencesDrawer
},
computed: {
editMode: {
get() {
return this.$store.state.editMode
},
set(value) {
this.$store.commit('setEditMode', value)
}
},
navDrawerOpen: {
get() {
return this.$store.state.navDrawer
Expand All @@ -58,3 +74,16 @@ export default {
}
}
</script>

<style scoped>
/* Edit buttons only relevant for overcrowded displays */
.edit-button {
display: none;
}
@media screen and (max-width: 1000px) {
.edit-button {
display: block;
}
}
</style>
15 changes: 15 additions & 0 deletions web-app/src/components/ModeButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<v-btn
@click="switchMode()"
class="v-btn-toggle mode-button"
:class="{ 'edit-mode': editMode }"
elevation="0"
outlined
x-small
Expand All @@ -13,6 +14,10 @@
<script>
export default {
props: {
editMode: {
required: true,
type: Boolean
},
modes: {
default: () => (['current', 'chart']),
type: Array
Expand Down Expand Up @@ -46,12 +51,17 @@ export default {

<style scoped>
.mode-button {
display: none;
margin-top: 2px;
position: absolute;
left: 2px;
z-index: 1;
}
.mode-button.edit-mode {
display: block;
}
.mode-button.theme--light {
border-color: var(--v-secondary-lighten5);
}
Expand All @@ -60,4 +70,9 @@ border-color: var(--v-secondary-lighten5);
border-color: var(--v-secondary-base);
}
@media screen and not (max-width: 1000px) {
.mode-button {
display: block;
}
}
</style>
81 changes: 81 additions & 0 deletions web-app/src/components/SortButtons.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<template>
<div class="sort-buttons" :class="{ 'edit-mode': editMode }">
<v-btn x-small @click="moveCard('left')">
<v-icon class="up-arrow">mdi-arrow-up-thick</v-icon>
<v-icon class="left-arrow">mdi-arrow-left-thick</v-icon>
</v-btn>
<v-btn x-small @click="moveCard('right')">
<v-icon class="down-arrow">mdi-arrow-down-thick</v-icon>
<v-icon class="right-arrow">mdi-arrow-right-thick</v-icon>
</v-btn>
</div>
</template>

<script>
export default {
props: {
editMode: {
required: true,
type: Boolean
},
sensorId: {
required: true,
type: String
}
},
methods: {
moveCard(direction) {
this.$store.commit('moveSensorCard', {
sensorId: this.sensorId,
direction
})
}
}
}
</script>

<style scoped>
.sort-buttons {
bottom: 0;
display: none;
left: 0;
padding-bottom: 4px;
padding-left: 4px;
position: absolute;
z-index: 1;
}
.sort-buttons.edit-mode {
display: block;
}
.up-arrow {
display: none;
}
.down-arrow {
display: none;
}
.left-arrow {
display: block;
}
.right-arrow {
display: block;
}
/* Display up/down arrows instead on small displays
since we're now in a vertical layout. */
@media screen and (max-width: 640px) {
.up-arrow {
display: block;
}
.down-arrow {
display: block;
}
.left-arrow {
display: none;
}
.right-arrow {
display: none;
}
}
</style>
Loading

0 comments on commit 7997290

Please sign in to comment.