Skip to content

Commit

Permalink
updated translations, add sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
niels committed Sep 1, 2020
1 parent 7ef9086 commit 22be280
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 72 deletions.
102 changes: 51 additions & 51 deletions dist/scheduler-card.js

Large diffs are not rendered by default.

17 changes: 13 additions & 4 deletions src/config-parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { defaults, forEach, each, find, has, pick, omit, filter, flatten, map, mapValues, keyBy, pickBy } from "lodash-es";
import { defaults, forEach, each, find, has, pick, omit, filter, flatten, map, mapValues, keyBy, pickBy, sortBy } from "lodash-es";

import { IDictionary, IEntityConfigEntry, IGroupConfigEntry, IButtonEntry, IActionConfigEntry, IConfig } from './types'
import { defaultDomainConfig, getIconForDomain, getIconForAction, getNameForDomain, getNameForService } from './default-config'
Expand Down Expand Up @@ -152,9 +152,12 @@ export class Config {
}

GetGroups(): IDictionary<IButtonEntry> {
return mapValues(this.groups, el => {
let output = mapValues(this.groups, el => {
return pick(el, ['name', 'icon']) as IButtonEntry
});
each(output, (item, key) => { Object.assign(item, { key: key }) });
output = sortBy(output, 'name');
return output;
}

GetEntities(group_id: string): IDictionary<IButtonEntry> {
Expand All @@ -170,9 +173,12 @@ export class Config {
});
}

return mapValues(entities, el => {
let output = mapValues(entities, el => {
return pick(el, ['name', 'icon']);
});
each(output, (item, key) => { Object.assign(item, { key: key }) });
output = sortBy(output, 'name');
return output;
}

GetEntity(entity_id: string): IEntityConfigEntry {
Expand All @@ -183,9 +189,12 @@ export class Config {
let entityCfg = this.entities[entity_id];
let actions = keyBy(entityCfg['actions'], 'id');

return mapValues(actions, el => {
let output = mapValues(actions, el => {
return pick(el, ['name', 'icon']) as IButtonEntry
});
each(output, (item, key) => { Object.assign(item, { key: key }) });
output = sortBy(output, 'name');
return output;
}

GetAction(entity_id: string, action_id: string): IActionConfigEntry | null {
Expand Down
1 change: 0 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export function CreateSlug(input: IDictionary<any>) {
return slugify(JSON.stringify(values(obj)).replace(/\W/g, ' '), '_');
}


export function IsSchedulerEntity(entity_id: string) {
return entity_id.match(/^switch.schedule_[0-9a-f]{6}$/);
}
Expand Down
4 changes: 3 additions & 1 deletion src/localize/languages/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"scheduler": "Scheduler",
"actions": {
"add": "add item",
"cancel": "cancel",
Expand All @@ -23,7 +24,8 @@
"options": "Options",
"day_type_daily": "every day",
"day_type_weekdays": "weekdays",
"day_type_custom": "custom"
"day_type_custom": "custom",
"shift_with_sun": "automatically adjust time to sunrise/sunset"
},
"days_short": {
"mon": "mon",
Expand Down
4 changes: 3 additions & 1 deletion src/localize/languages/nl.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"scheduler": "Scheduler",
"actions": {
"add": "Nieuw item",
"cancel": "annuleren",
Expand All @@ -23,7 +24,8 @@
"options": "Opties",
"day_type_daily": "Dagelijks",
"day_type_weekdays": "Werkdagen",
"day_type_custom": "Anders"
"day_type_custom": "Anders",
"shift_with_sun": "Automatisch aanpassen aan zonsopgang/zonsondergang"
},
"days_short": {
"mon": "ma",
Expand Down
28 changes: 14 additions & 14 deletions src/scheduler-card.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import { LitElement, html, customElement, property, CSSResult, TemplateResult } from 'lit-element';
import { HomeAssistant } from 'custom-card-helpers';
import { find, filter, pick, extend, map, pull, size } from "lodash-es";
import { find, filter, pick, extend, pull } from "lodash-es";


import { Config } from './config-parser';
Expand Down Expand Up @@ -78,7 +78,7 @@ export class SchedulerCard extends LitElement {
if (!this.selection.newItem && !this.selection.editItem) {
return html`
<ha-card>
<div class="card-header">Scheduler</div>
<div class="card-header">${localize('scheduler')}</div>
<div class="card-section first">
${this.getEntries()}
</div>
Expand All @@ -91,7 +91,7 @@ export class SchedulerCard extends LitElement {
} else if (this.selection.newItem && !this.selection.actionConfirmed) {
return html`
<ha-card>
<div class="card-header">Scheduler</div>
<div class="card-header">${localize('scheduler')}</div>
<div class="card-section first">
<div class="header">${localize('fields.group')}</div>
<div class="option-list">
Expand All @@ -116,7 +116,7 @@ export class SchedulerCard extends LitElement {
else {
return html`
<ha-card>
<div class="card-header">Scheduler</div>
<div class="card-header">${localize('scheduler')}</div>
${this.showEditor()}
</ha-card>
`;
Expand Down Expand Up @@ -209,10 +209,10 @@ export class SchedulerCard extends LitElement {

getGroups(): TemplateResult[] {
let groups = this.Config.GetGroups();
if (!size(groups)) return [html`<div class="text-field">${localize('instructions.no_groups_defined')}</div>`];
return map(groups, (el: IButtonEntry, key: string) => {
if (!groups.length) return [html`<div class="text-field">${localize('instructions.no_groups_defined')}</div>`];
return groups.map((el: IButtonEntry) => {
return html`
<mwc-button class="${this.selection.group == key ? ' active' : ''}" @click="${() => { this.selectGroup(key) }}">
<mwc-button class="${this.selection.group == el.key ? ' active' : ''}" @click="${() => { this.selectGroup(el.key) }}">
${el.icon ? html`<ha-icon icon="hass:${el.icon}" class="padded-right"></ha-icon>` : ''}
${PrettyPrintName(el.name)}
</mwc-button>
Expand All @@ -232,10 +232,10 @@ export class SchedulerCard extends LitElement {
getEntities(): TemplateResult[] {
if (!this.selection.group) return [html`<div class="text-field">${localize('instructions.no_group_selected')}</div>`];
let entities = this.Config.GetEntities(this.selection.group);
if (!size(entities)) return [html`<div class="text-field">${localize('instructions.no_entities_for_group')}</div>`];
return map(entities, (el: IButtonEntry, key: string) => {
if (!entities.length) return [html`<div class="text-field">${localize('instructions.no_entities_for_group')}</div>`];
return entities.map((el: IButtonEntry) => {
return html`
<mwc-button class="${this.selection.entity == key ? ' active' : ''}" @click="${() => { this.selectEntity(key) }}">
<mwc-button class="${this.selection.entity == el.key ? ' active' : ''}" @click="${() => { this.selectEntity(el.key) }}">
${el.icon ? html`<ha-icon icon="hass:${el.icon}" class="padded-right"></ha-icon>` : ''}
${PrettyPrintName(el.name)}
</mwc-button>
Expand All @@ -254,10 +254,10 @@ export class SchedulerCard extends LitElement {
getActions(): TemplateResult[] {
if (!this.selection.entity) return [html`<div class="text-field">${localize('instructions.no_entity_selected')}</div>`];
let actions = this.Config.GetActions(this.selection.entity);
if (!size(actions)) return [html`<div class="text-field">${localize('instructions.no_actions_for_entity')}</div>`];
return map(actions, (el: IButtonEntry, key: string) => {
if (!actions.length) return [html`<div class="text-field">${localize('instructions.no_actions_for_entity')}</div>`];
return actions.map((el: IButtonEntry) => {
return html`
<mwc-button class="${this.selection.action == key ? ' active' : ''}" @click="${() => { this.selectAction(key) }}">
<mwc-button class="${this.selection.action == el.key ? ' active' : ''}" @click="${() => { this.selectAction(el.key) }}">
${el.icon ? html`<ha-icon icon="hass:${el.icon}" class="padded-right"></ha-icon>` : ''}
${PrettyPrintName(el.name)}
</mwc-button>
Expand Down Expand Up @@ -361,7 +361,7 @@ export class SchedulerCard extends LitElement {
<div class="card-section">
<div class="header">${localize('fields.options')}</div>
<div class="option-item">
${this.selection.sun ? html`<paper-checkbox checked name="option-item-sun" @change="${(e) => this.toggleSun(e.target.checked)}">automatically adjust time to sunrise/sunset</paper-checkbox>` : html`<paper-checkbox name="option-item-sun" @change="${(e) => this.toggleSun(e.target)}">automatically adjust time to sunrise/sunset</paper-checkbox>`}
${this.selection.sun ? html`<paper-checkbox checked name="option-item-sun" @change="${(e) => this.toggleSun(e.target.checked)}">${localize('fields.shift_with_sun')}</paper-checkbox>` : html`<paper-checkbox name="option-item-sun" @change="${(e) => this.toggleSun(e.target)}">${localize('fields.shift_with_sun')}</paper-checkbox>`}
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface IDictionary<TValue> {
export interface IButtonEntry {
icon?: string,
name: string,
key: string,
}

export interface IActionConfigEntry {
Expand Down

0 comments on commit 22be280

Please sign in to comment.