Add default keymap icon hint

This commit is contained in:
Farkas József
2016-11-22 09:37:32 +01:00
committed by József Farkas
parent 8f930092df
commit 56c386bb7b
4 changed files with 24 additions and 5 deletions
@@ -16,6 +16,7 @@
/>) />)
<i class="fa keymap__is-default" <i class="fa keymap__is-default"
[ngClass]="{'fa-star-o': !keymap.isDefault, 'fa-star': keymap.isDefault}" [ngClass]="{'fa-star-o': !keymap.isDefault, 'fa-star': keymap.isDefault}"
[title]="starTitle"
(click)="setDefault()" (click)="setDefault()"
></i> ></i>
<i class="glyphicon glyphicon-trash keymap__remove pull-right" title="" <i class="glyphicon glyphicon-trash keymap__remove pull-right" title=""
@@ -1,4 +1,4 @@
import { Component, ElementRef, Input, Renderer, ViewChild } from '@angular/core'; import { ChangeDetectionStrategy, Component, ElementRef, Input, OnChanges, Renderer, ViewChild } from '@angular/core';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
@@ -10,15 +10,22 @@ import { KeymapActions } from '../../../store/actions';
@Component({ @Component({
selector: 'keymap-header', selector: 'keymap-header',
template: require('./keymap-header.component.html'), template: require('./keymap-header.component.html'),
styles: [require('./keymap-header.component.scss')] styles: [require('./keymap-header.component.scss')],
changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class KeymapHeaderComponent { export class KeymapHeaderComponent implements OnChanges {
@Input() keymap: Keymap; @Input() keymap: Keymap;
@ViewChild('name') keymapName: ElementRef; @ViewChild('name') keymapName: ElementRef;
@ViewChild('abbr') keymapAbbr: ElementRef; @ViewChild('abbr') keymapAbbr: ElementRef;
private starTitle: string;
constructor(private store: Store<AppState>, private renderer: Renderer) { } constructor(private store: Store<AppState>, private renderer: Renderer) { }
ngOnChanges() {
this.setTitle();
}
setDefault() { setDefault() {
if (!this.keymap.isDefault) { if (!this.keymap.isDefault) {
this.store.dispatch(KeymapActions.setDefault(this.keymap.abbreviation)); this.store.dispatch(KeymapActions.setDefault(this.keymap.abbreviation));
@@ -51,4 +58,10 @@ export class KeymapHeaderComponent {
newAbbr = newAbbr.toUpperCase(); newAbbr = newAbbr.toUpperCase();
this.store.dispatch(KeymapActions.editKeymapAbbr(this.keymap.abbreviation, newAbbr)); this.store.dispatch(KeymapActions.editKeymapAbbr(this.keymap.abbreviation, newAbbr));
} }
setTitle(): void {
this.starTitle = this.keymap.isDefault
? 'This is the default keymap which gets activated when powering the keyboard.'
: 'Makes this keymap the default keymap which gets activated when powering the keyboard.';
}
} }
@@ -11,7 +11,7 @@
<li *ngFor="let keymap of keymaps$ | async" class="sidebar__level-2--item"> <li *ngFor="let keymap of keymaps$ | async" class="sidebar__level-2--item">
<div class="sidebar__level-2" [routerLinkActive]="['active']"> <div class="sidebar__level-2" [routerLinkActive]="['active']">
<a [routerLink]="['/keymap', keymap.abbreviation]">{{keymap.name}}</a> <a [routerLink]="['/keymap', keymap.abbreviation]">{{keymap.name}}</a>
<i *ngIf="keymap.isDefault" class="fa fa-star sidebar__fav"></i> <i *ngIf="keymap.isDefault" class="fa fa-star sidebar__fav" title="This is the default keymap which gets activated when powering the keyboard."></i>
</div> </div>
</li> </li>
</ul> </ul>
+6 -1
View File
@@ -62,7 +62,12 @@ export default function(state = initialState, action: Action): KeymapState {
case KeymapActions.SET_DEFAULT: case KeymapActions.SET_DEFAULT:
newState = state.entities.map((keymap: Keymap) => { newState = state.entities.map((keymap: Keymap) => {
keymap.isDefault = (keymap.abbreviation === action.payload); if (keymap.abbreviation === action.payload || keymap.isDefault) {
let newKeymap: Keymap = new Keymap();
Object.assign(newKeymap, keymap);
keymap = newKeymap;
keymap.isDefault = keymap.abbreviation === action.payload;
}
return keymap; return keymap;
}); });