Skip to content
This repository has been archived by the owner on Jan 28, 2022. It is now read-only.

Commit

Permalink
Hacked in boolean type handling for schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
Shepless committed May 12, 2020
1 parent 599b81a commit 846a89d
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 24 deletions.
12 changes: 8 additions & 4 deletions src/components/sub-menus/add-integration/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { Inject } from '../../../utilities/dependency-injection';
import { YioStore } from '../../../store';
import { ServerConnection } from '../../../server';
import { IKeyValuePair, IDropDownItem, IIntegrationSchema } from '../../../types';
import { SpotifyAuthentication } from '../../../utilities/spotify-authentication';
import ActionButton from '../../action-button/index.vue';
import ActionIconButton from '../../action-icon-button/index.vue';
import DropDown from '../../drop-down/index.vue';
import Spotify from '../../spotify/index.vue';
import { SpotifyAuthentication } from '../../../utilities/spotify-authentication';
import SwitchToggle from '../../switch-toggle/index.vue';

@Component({
name: 'AddIntegration',
Expand All @@ -24,6 +25,7 @@ import { SpotifyAuthentication } from '../../../utilities/spotify-authentication
};
},
components: {
SwitchToggle,
ActionButton,
ActionIconButton,
DropDown,
Expand All @@ -48,7 +50,7 @@ export default class AddIntegration extends Vue {
public name: string = '';
public type: string = '';
public properties: IKeyValuePair<IIntegrationSchema> = {};
public propertyValues: IKeyValuePair<string> = {};
public propertyValues: IKeyValuePair<string | boolean | number> = {};
public newDataKey: string = '';
public newDataValue: string = '';
public selectedValue: string = this.isIntegrationTypeSelectedSpotify ? 'spotify' : '';
Expand All @@ -71,11 +73,13 @@ export default class AddIntegration extends Vue {
this.properties = { ...filteredProps };
this.propertyValues = { ...Object.keys(filteredProps)
.reduce((values, propName) => {
const type = filteredProps[propName].type;

return {
...values,
[`${propName}`]: ''
[`${propName}`]: type === 'string' ? '' : false
};
}, {} as IKeyValuePair<string>) };
}, {} as IKeyValuePair<string | boolean | number>) };
}

public onAddNewIntegration() {
Expand Down
3 changes: 2 additions & 1 deletion src/components/sub-menus/add-integration/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ <h1 class="title">
{{key}}
</div>
<div class="setting-value">
<input class="setting-input" :placeholder="`example: ${property.examples[0]}`" type="text" v-model="propertyValues[key]" />
<input v-if="property.type === 'string'" class="setting-input" :placeholder="`example: ${property.examples[0]}`" type="text" v-model="propertyValues[key]" />
<switch-toggle v-if="property.type === 'boolean'" v-model="propertyValues[key]"></switch-toggle>
</div>
</div>
<action-button :text="$t('common.save')" :primary="true" @onClick="onSave"></action-button>
Expand Down
8 changes: 5 additions & 3 deletions src/components/sub-menus/integration-settings/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { Inject } from '../../../utilities/dependency-injection';
import { ServerConnection } from '../../../server';
import { IIntegrationInstance, IKeyValuePair, IIntegrationSchema } from '../../../types';
import ActionButton from '../../action-button/index.vue';
import SwitchToggle from '../../switch-toggle/index.vue';

@Component({
name: 'IntegrationSettings',
components: {
ActionButton
ActionButton,
SwitchToggle
},
subscriptions(this: IntegrationSettings) {
return {
Expand Down Expand Up @@ -44,7 +46,7 @@ export default class IntegrationSettings extends Vue {

public supportedIntegrations: IKeyValuePair<IIntegrationSchema>;
public properties: IKeyValuePair<IIntegrationSchema> = {};
public propertyValues: IKeyValuePair<string> = {};
public propertyValues: IKeyValuePair<string | number | boolean> = {};

public get name() {
return this.integration.friendly_name;
Expand All @@ -70,7 +72,7 @@ export default class IntegrationSettings extends Vue {
...values,
[`${propName}`]: this.integration.data[propName]
};
}, {} as IKeyValuePair<string>) };
}, {} as IKeyValuePair<string | number | boolean>) };
}

public onSave() {
Expand Down
3 changes: 2 additions & 1 deletion src/components/sub-menus/integration-settings/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ <h2 class="integration-title">{{name}}</h2>
{{key}}
</div>
<div class="setting-value">
<input class="setting-input" :placeholder="`example: ${property.examples[0]}`" type="text" v-model="propertyValues[key]" />
<input v-if="property.type === 'string'" class="setting-input" :placeholder="`example: ${property.examples[0]}`" type="text" v-model="propertyValues[key]" />
<switch-toggle v-if="property.type === 'boolean'" v-model="propertyValues[key]"></switch-toggle>
</div>
</div>
<action-button text="Save" :primary="true" @onClick="onSave"></action-button>
Expand Down
13 changes: 9 additions & 4 deletions src/components/switch-toggle/script.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import Vue from 'vue';
import {Component, Model} from 'vue-property-decorator';
import {Component, Prop} from 'vue-property-decorator';

@Component({
name: 'SwitchToggle'
})
export default class SwitchToggle extends Vue {
@Model('onToggle', {
type: Boolean
@Prop({
type: Boolean,
required: true
})
public readonly checked!: boolean;
public readonly value: boolean;

public get hasSlotContent() {
return !!(this.$slots.default || this.$scopedSlots.default);
}
}
4 changes: 2 additions & 2 deletions src/components/switch-toggle/template.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="container">
<div class="label">
<div class="label" v-if="hasSlotContent">
<slot></slot>
</div>
<input class="toggle" type="checkbox" :checked="checked" />
<input class="toggle" type="checkbox" :checked="value" @change="$emit('input', $event.target.checked)" />
</div>
4 changes: 0 additions & 4 deletions src/pages/settings/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,4 @@ export default class SettingsPage extends Vue {
public updateAutoBrightness(value: boolean) {
this.server.setAutoBrightness(value);
}

public updateAutoSoftwareUpdate(value: boolean) {
alert('TODO: API ENDPOINT NEEDED');
}
}
4 changes: 2 additions & 2 deletions src/pages/settings/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ <h1 class="title">
<div class="row">
<card :title="$t('pages.settings.darkMode.title')" class="settings-item" @onClick="updateDarkMode(!darkMode)">
<template v-slot:rightIcon>
<switch-toggle v-model="darkMode" @onToggle="updateDarkMode"></switch-toggle>
<switch-toggle v-model="darkMode"></switch-toggle>
</template>
</card>
</div>
<div class="row">
<card :title="$t('pages.settings.autoBrightness.title')" class="settings-item" @onClick="updateAutoBrightness(!autoBrightness)">
<template v-slot:rightIcon>
<switch-toggle v-model="autoBrightness" @onToggle="updateAutoBrightness"></switch-toggle>
<switch-toggle v-model="autoBrightness"></switch-toggle>
</template>
</card>
<div class="settings-description">
Expand Down
2 changes: 1 addition & 1 deletion src/pages/software-update/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h1 class="title">
<div class="row">
<card :title="$t('pages.softwareUpdate.autoUpdate')" class="item" @onClick="updateAutoSoftwareUpdate(!autoSoftwareUpdate)">
<template v-slot:rightIcon>
<switch-toggle v-model="autoSoftwareUpdate" @onToggle="updateAutoSoftwareUpdate"></switch-toggle>
<switch-toggle v-model="autoSoftwareUpdate"></switch-toggle>
</template>
</card>
<div class="description">
Expand Down
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class ServerConnection {
private requestId: number;

constructor() {
this.host = window.location.hostname;
this.host = '192.168.12.131'; // window.location.hostname;
this.port = 946;
this.requestId = 0;
this.configPollingRequestId = 1316134911;
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export interface IIntegrationInstance {
type: string;
friendly_name: string;
friendly_name_search_term: string;
data: IKeyValuePair<string>;
data: IKeyValuePair<string | boolean | number>;
}

export interface IIntegration {
Expand Down

0 comments on commit 846a89d

Please sign in to comment.