-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start feature to control donation alert based on amounts
Planning on adding images as a possibility besides sounds but not done yet.
- Loading branch information
Showing
12 changed files
with
392 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"id": { | ||
"type": "string" | ||
}, | ||
"threshold": { | ||
"type": "number" | ||
}, | ||
"sound": { | ||
"description": "This stores a reference based on the 'name' of the asset.", | ||
"oneOf": [ | ||
{ | ||
"type": "string" | ||
}, | ||
{ | ||
"type": "null" | ||
} | ||
] | ||
}, | ||
"volume": { | ||
"type": "number" | ||
}, | ||
"graphic": { | ||
"description": "This stores a reference based on the 'name' of the asset.", | ||
"oneOf": [ | ||
{ | ||
"type": "string" | ||
}, | ||
{ | ||
"type": "null" | ||
} | ||
] | ||
}, | ||
"graphicDisplayTime": { | ||
"type": "number" | ||
} | ||
}, | ||
"required": [ | ||
"id", | ||
"threshold", | ||
"sound", | ||
"volume", | ||
"graphic", | ||
"graphicDisplayTime" | ||
] | ||
}, | ||
"default": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
src/dashboard/donation-alert-control/components/Alert.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<template> | ||
<media-card | ||
class="d-flex align-center px-2" | ||
:style="{ 'text-align': 'unset', height: '40px', 'margin-top': index > 0 ? '10px' : 0 }" | ||
> | ||
<v-dialog v-model="dialog"> | ||
<v-card> | ||
<v-card-text class="pa-4 pb-0"> | ||
<v-form v-model="isFormValid"> | ||
<v-text-field | ||
v-model="thresholdEdit" | ||
label="Amount Threshold in Dollars" | ||
prepend-icon="mdi-cash" | ||
autocomplete="off" | ||
:rules="[isRequired, isNumber, isZeroOrBigger]" | ||
filled | ||
dense | ||
/> | ||
<v-text-field | ||
v-model="soundEdit" | ||
label="Sound Asset Name" | ||
prepend-icon="mdi-music-box" | ||
autocomplete="off" | ||
:rules="[isRequired, isValidAsset]" | ||
filled | ||
dense | ||
/> | ||
<v-text-field | ||
v-model="volumeEdit" | ||
label="Volume in dB" | ||
prepend-icon="mdi-volume-high" | ||
autocomplete="off" | ||
:rules="[isRequired, isNumber, isZeroOrSmaller]" | ||
filled | ||
dense | ||
/> | ||
</v-form> | ||
</v-card-text> | ||
<v-card-actions> | ||
<v-spacer /> | ||
<v-btn @click="save" :disabled="!isFormValid">Save</v-btn> | ||
<v-btn @click="dialog = false">Cancel</v-btn> | ||
</v-card-actions> | ||
</v-card> | ||
</v-dialog> | ||
<v-icon class="mr-2" @click="test"> | ||
mdi-play | ||
</v-icon> | ||
<div class="flex-grow-1"> | ||
${{ alert.threshold }} - {{ alert.sound || 'N/A' }} ({{ alert.volume }} dB) | ||
<!-- {{ alert.graphic || 'N/A' }} ({{ alert.graphicDisplayTime }}s) --> | ||
</div> | ||
<v-icon @click="edit"> | ||
mdi-pencil | ||
</v-icon> | ||
<v-icon @click="remove"> | ||
mdi-delete | ||
</v-icon> | ||
</media-card> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { replicantNS } from '@esa-layouts/browser_shared/replicant_store'; | ||
import MediaCard from '@esa-layouts/dashboard/_misc/components/MediaCard.vue'; | ||
import { DonationAlerts } from '@esa-layouts/types/schemas'; | ||
import type NodeCGTypes from '@nodecg/types'; | ||
import { Component, Prop, Vue } from 'vue-property-decorator'; | ||
import { storeModule } from '../store'; | ||
@Component({ | ||
components: { | ||
MediaCard, | ||
}, | ||
}) | ||
export default class extends Vue { | ||
@Prop({ type: Object, required: true }) readonly alert!: DonationAlerts[0]; | ||
@Prop({ type: Number, required: true }) readonly index!: number; | ||
@replicantNS.State( | ||
(s) => s.reps.assetsDonationAlertAssets, | ||
) readonly assets!: NodeCGTypes.AssetFile[]; | ||
dialog = false; | ||
thresholdEdit = '0'; | ||
soundEdit = ''; | ||
volumeEdit = '0'; | ||
isFormValid = false; | ||
isRequired(val: string): boolean | string { | ||
return !!val || 'Required'; | ||
} | ||
isNumber(val: string): boolean | string { | ||
return !Number.isNaN(Number(val)) || 'Must be a number'; | ||
} | ||
isZeroOrBigger(val: string): boolean | string { | ||
const num = Number(val); | ||
return (num >= 0) || 'Must be equal to or bigger than 0'; | ||
} | ||
isZeroOrSmaller(val: string): boolean | string { | ||
const num = Number(val); | ||
return (num <= 0) || 'Must be equal to or smaller than 0'; | ||
} | ||
isValidAsset(val: string): boolean | string { | ||
const soundAsset = this.assets.find((v) => v.name === val); | ||
return !!soundAsset || 'Asset name must match a file uploaded'; | ||
} | ||
test(): void { | ||
nodecg.sendMessage('omnibarPlaySound', { amount: this.alert.threshold }); | ||
} | ||
edit(): void { | ||
this.dialog = true; | ||
this.thresholdEdit = this.alert.threshold.toString() ?? '0'; | ||
this.soundEdit = this.alert.sound ?? ''; | ||
this.volumeEdit = this.alert.volume.toString() ?? '0'; | ||
} | ||
save(): void { | ||
const item: DonationAlerts[0] = { | ||
id: this.alert.id, | ||
threshold: Number(this.thresholdEdit), | ||
sound: this.soundEdit, | ||
volume: Number(this.volumeEdit), | ||
graphic: this.alert.graphic, // TODO | ||
graphicDisplayTime: this.alert.graphicDisplayTime, // TODO | ||
}; | ||
storeModule.editItem(item); | ||
this.dialog = false; | ||
} | ||
remove(): void { | ||
storeModule.removeItem(this.alert.id); | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* eslint no-new: off, @typescript-eslint/explicit-function-return-type: off */ | ||
|
||
import { setUpReplicants } from '@esa-layouts/browser_shared/replicant_store'; | ||
import Vue from 'vue'; | ||
import vuetify from '../_misc/vuetify'; | ||
import App from './main.vue'; | ||
import store from './store'; | ||
|
||
setUpReplicants(store).then(() => { | ||
new Vue({ | ||
vuetify, | ||
store, | ||
el: '#App', | ||
render: (h) => h(App), | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<template> | ||
<v-app> | ||
<v-btn @click="addBlank">Add New Donation Alert Tier</v-btn> | ||
<div v-if="!donationAlerts.length" class="pa-3 font-italic"> | ||
No donation alert tiers created, add a new one with the button above. | ||
</div> | ||
<div v-else :style="{ 'margin-top': '10px' }"> | ||
<alert v-for="(alert, i) in donationAlerts" :key="alert.id" :alert="alert" :index="i" /> | ||
</div> | ||
</v-app> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { replicantNS } from '@esa-layouts/browser_shared/replicant_store'; | ||
import { DonationAlerts } from '@esa-layouts/types/schemas'; | ||
import { Component, Vue } from 'vue-property-decorator'; | ||
import Alert from './components/Alert.vue'; | ||
import { storeModule } from './store'; | ||
@Component({ | ||
components: { | ||
Alert, | ||
}, | ||
}) | ||
export default class DonationAlertControl extends Vue { | ||
@replicantNS.State((s) => s.reps.donationAlerts) readonly donationAlerts!: DonationAlerts; | ||
addBlank(): void { | ||
storeModule.addBlankItem(); | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { ReplicantModule, ReplicantTypes, replicantModule } from '@esa-layouts/browser_shared/replicant_store'; | ||
import { DonationAlerts } from '@esa-layouts/types/schemas'; | ||
import clone from 'clone'; | ||
import { v4 as uuid } from 'uuid'; | ||
import Vue from 'vue'; | ||
import Vuex, { Store } from 'vuex'; | ||
import { Module, Mutation, VuexModule, getModule } from 'vuex-module-decorators'; | ||
|
||
Vue.use(Vuex); | ||
|
||
@Module({ name: 'OurModule' }) | ||
class OurModule extends VuexModule { | ||
// Helper getter to return all replicants. | ||
get reps(): ReplicantTypes { | ||
return this.context.rootState.ReplicantModule.reps; | ||
} | ||
|
||
@Mutation | ||
addBlankItem(): void { | ||
const items = clone(replicantModule.repsTyped.donationAlerts); | ||
items.push({ | ||
id: uuid(), | ||
threshold: 0, | ||
sound: null, | ||
volume: 50, | ||
graphic: null, | ||
graphicDisplayTime: 5, | ||
}); | ||
replicantModule.setReplicant({ name: 'donationAlerts', val: items }); | ||
} | ||
|
||
@Mutation | ||
editItem(data: DonationAlerts[0]): void { | ||
const items = clone(replicantModule.repsTyped.donationAlerts); | ||
const itemIndex = items.findIndex((i) => i.id === data.id); | ||
if (itemIndex >= 0) { | ||
items[itemIndex] = clone(data); | ||
replicantModule.setReplicant({ name: 'donationAlerts', val: items }); | ||
} | ||
} | ||
|
||
@Mutation | ||
removeItem(id: string): void { | ||
const items = clone(replicantModule.repsTyped.donationAlerts); | ||
const itemIndex = items.findIndex((i) => i.id === id); | ||
if (itemIndex >= 0) { | ||
items.splice(itemIndex, 1); | ||
replicantModule.setReplicant({ name: 'donationAlerts', val: items }); | ||
} | ||
} | ||
} | ||
|
||
const store = new Store({ | ||
strict: process.env.NODE_ENV !== 'production', | ||
state: {}, | ||
modules: { ReplicantModule, OurModule }, | ||
}); | ||
export default store; | ||
export const storeModule = getModule(OurModule, store); |
Oops, something went wrong.