-
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added actions and reducers for repositioning windows.
- Loading branch information
Showing
9 changed files
with
116 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,25 @@ | ||
import { Action } from '@ngrx/store'; | ||
|
||
export const SET_ACTIVE_WINDOW_ID = 'SET_ACTIVE_WINDOW_ID'; | ||
export const SET_WINDOW_IDS = 'SET_WINDOW_IDS'; | ||
export const REPOSITION_WINDOW = 'REPOSITION_WINDOW'; | ||
|
||
export class SetActiveWindowIdAction implements Action { | ||
readonly type = SET_ACTIVE_WINDOW_ID; | ||
|
||
constructor(public payload: { windowId: string }) {} | ||
} | ||
|
||
export type Action = SetActiveWindowIdAction; | ||
export class SetWindowIdsAction implements Action { | ||
readonly type = SET_WINDOW_IDS; | ||
|
||
constructor(public payload: { ids: string[]}) {} | ||
} | ||
|
||
export class RepositionWindowAction implements Action { | ||
readonly type = REPOSITION_WINDOW; | ||
|
||
constructor(public payload: { currentPosition: number, newPosition: number }) { } | ||
} | ||
|
||
export type Action = SetActiveWindowIdAction | SetWindowIdsAction | RepositionWindowAction; |
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
20 changes: 10 additions & 10 deletions
20
src/app/components/window-switcher/window-switcher.component.html
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 |
---|---|---|
@@ -1,23 +1,23 @@ | ||
<div class="header-nav window-switcher__container"> | ||
<div | ||
class="nav-link nav-text window-switcher _track_me" | ||
*ngFor="let window of windows" | ||
[class.active]="window.windowId === activeWindowId" | ||
(click)="activeWindowChange.next(window.windowId)" | ||
(dblclick)="editWindowNameInput(window.windowId, wTitle)" | ||
*ngFor="let windowId of windowIds; let index = index;" | ||
[class.active]="windowId === activeWindowId" | ||
(click)="activeWindowChange.next(windowId)" | ||
(dblclick)="editWindowNameInput(windowId, wTitle)" | ||
> | ||
<div | ||
#wTitle class="window-switcher__input" | ||
[attr.contenteditable]="window.windowId === windowNameEditing" | ||
(blur)="saveWindowName(window.windowId, wTitle.innerText)" | ||
(keydown.enter)="saveWindowName(window.windowId, wTitle.innerText)" | ||
>{{ window.layout.title }}</div> | ||
<div class="window-switcher__close" *ngIf="windows.length > 1" (click)="removeWindowChange.next(window.windowId)">×</div> | ||
[attr.contenteditable]="windowId === windowNameEditing" | ||
(blur)="saveWindowName(windowId, wTitle.innerText)" | ||
(keydown.enter)="saveWindowName(windowId, wTitle.innerText)" | ||
>{{ windows[windowId].layout.title }}</div> | ||
<div class="window-switcher__close" *ngIf="windowIds.length > 1" (click)="removeWindowChange.next(windowId)">×</div> | ||
</div> | ||
<div | ||
class="nav-link nav-text window-switcher window-switcher--new-window _track_me" | ||
(click)="newWindowChange.next($event)" | ||
*ngIf="windows.length < maxWindowCount"> | ||
*ngIf="windowIds.length < maxWindowCount"> | ||
{{ 'ADD_NEW_WINDOW_TEXT' | translate }} | ||
</div> | ||
</div> |
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
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
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,28 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Store, Action } from '@ngrx/store'; | ||
import { Effect, Actions, toPayload } from '@ngrx/effects'; | ||
import { Observable } from 'rxjs/Observable'; | ||
|
||
import * as fromRoot from '../reducers'; | ||
|
||
import * as windowActions from '../actions/windows/windows'; | ||
import * as windowsMetaActions from '../actions/windows-meta/windows-meta'; | ||
|
||
@Injectable() | ||
export class WindowsEffects { | ||
|
||
@Effect() // remove, add, reposition | ||
setWindowIDs$: Observable<Action> = this.actions$ | ||
.ofType(windowActions.ADD_WINDOW, windowActions.REMOVE_WINDOW) | ||
.withLatestFrom(this.store, (action: windowActions.Action, state) => { | ||
return { windows: state.windows, action }; | ||
}).switchMap(data => { | ||
const windowIds = Object.keys(data.windows); | ||
return Observable.of(new windowsMetaActions.SetWindowIdsAction({ ids: windowIds })); | ||
}); | ||
|
||
constructor( | ||
private actions$: Actions, | ||
private store: Store<fromRoot.State> | ||
) {} | ||
} |
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