Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll down if new action appears #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ __build__/**
# Build Artifacts #
release
.ngc
*.ngfactory.ts
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@angular/platform-server": "^2.0.0-rc.6",
"@ngrx/core": "^1.0.0",
"@ngrx/store": "^2.1.2",
"@ngrx/store-devtools": "^3.1.0",
"@types/jasmine": "^2.2.33",
"@types/node": "^6.0.38",
"awesome-typescript-loader": "^2.2.1",
Expand Down
72 changes: 46 additions & 26 deletions src/log-monitor/log-monitor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input } from '@angular/core';
import { Component, Input, AfterViewChecked, ElementRef, ViewChild } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { map } from 'rxjs/operator/map';
import { StoreDevtools } from '@ngrx/store-devtools';
Expand Down Expand Up @@ -60,7 +60,7 @@ import { LogEntryItem } from './log-entry-item';
Commit
</log-monitor-button>
</div>
<div class="elements">
<div class="elements" #scrollContainer>
<log-monitor-entry
*ngFor="let item of (items$ | async); let i = index"
[item]="item"
Expand All @@ -71,44 +71,64 @@ import { LogEntryItem } from './log-entry-item';
</div>
`
})
export class LogMonitorComponent {
export class LogMonitorComponent implements AfterViewChecked {
@ViewChild('scrollContainer') private scrollContainer: ElementRef;
@Input() expandEntries: boolean = true;

public items$: Observable<LogEntryItem[]>;
public canRevert$: Observable<boolean>;
public canSweep$: Observable<boolean>;
public canCommit$: Observable<boolean>;
private _scrollDown: boolean = false;
private _previousActions: any = [];

constructor(private devtools: StoreDevtools) {
this.canRevert$ = select.call(devtools.liftedState, s => !(s.computedStates.length > 1 ));
this.canRevert$ = select.call(devtools.liftedState, s => !(s.computedStates.length > 1));
this.canSweep$ = select.call(devtools.liftedState, s => !(s.skippedActionIds.length > 0));
this.canCommit$ = select.call(devtools.liftedState, s => !(s.computedStates.length > 1));

this.items$ = map.call(devtools.liftedState, ({ actionsById, skippedActionIds, stagedActionIds, computedStates }) => {
const actions = [];

for (let i = 0; i < stagedActionIds.length; i++) {
const actionId = stagedActionIds[i];
const action = actionsById[actionId].action;
const { state, error } = computedStates[i];
let previousState;
if (i > 0) {
previousState = computedStates[i - 1].state;
}

actions.push({
key: actionId,
collapsed: skippedActionIds.indexOf(actionId) > -1,
action,
actionId,
state,
previousState,
error
});
const actions = [];

for (let i = 0; i < stagedActionIds.length; i++) {
const actionId = stagedActionIds[i];
const action = actionsById[actionId].action;
const { state, error } = computedStates[i];
let previousState;
if (i > 0) {
previousState = computedStates[i - 1].state;
}

return actions;
});
actions.push({
key: actionId,
collapsed: skippedActionIds.indexOf(actionId) > -1,
action,
actionId,
state,
previousState,
error
});
}

// check if there are new items in the list so we can scroll down
this._scrollDown = actions.length - this._previousActions.length > 0;
this._previousActions = actions;

return actions;
});
}

ngAfterViewChecked() {
if (this._scrollDown) {
this.scrollToBottom();
this._scrollDown = false;
}
}

scrollToBottom(): void {
try {
this.scrollContainer.nativeElement.scrollTop = this.scrollContainer.nativeElement.scrollHeight;
} catch (err) { }
}

handleToggle(id: number) {
Expand Down