Commit dd2608b6 authored by Vitali Stupin's avatar Vitali Stupin
Browse files

Restore scroll position for subsystem view

parent 9542926a
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subsystem } from '../subsystem';
import { MethodsService } from '../methods.service';
import { LanguagesService } from '../languages.service';
import { ActivatedRoute, Router, Scroll } from '@angular/router';
import { Subscription } from 'rxjs';
import { ViewportScroller } from '@angular/common';
......@@ -12,7 +11,7 @@ import { filter } from 'rxjs/operators';
templateUrl: './subsystem-list.component.html',
styleUrls: ['./subsystem-list.component.css']
})
export class SubsystemListComponent implements OnInit {
export class SubsystemListComponent implements OnInit, OnDestroy {
subsystems: Subsystem[]
message: string = ''
scrollPosition: [number, number]
......@@ -23,7 +22,6 @@ export class SubsystemListComponent implements OnInit {
constructor(
private methodsService: MethodsService,
private languagesService: LanguagesService,
private route: ActivatedRoute,
private router: Router,
private viewportScroller: ViewportScroller
......
import { Component, OnInit, OnDestroy } from '@angular/core';
import { MethodsService } from '../methods.service';
import { Subsystem } from '../subsystem';
import { ActivatedRoute, Router } from '@angular/router';
import { ActivatedRoute, Router, Scroll } from '@angular/router';
import { Subscription } from 'rxjs';
import { ViewportScroller } from '@angular/common';
import { filter } from 'rxjs/operators';
@Component({
selector: 'app-subsystem',
......@@ -13,6 +15,8 @@ export class SubsystemComponent implements OnInit, OnDestroy {
subsystem: Subsystem
subsystemId: string
message: string = ''
scrollPosition: [number, number]
routerScrollSubscription: Subscription
routeSubscription: Subscription
updatedSubscription: Subscription
warningsSubscription: Subscription
......@@ -20,8 +24,20 @@ export class SubsystemComponent implements OnInit, OnDestroy {
constructor(
private methodsService: MethodsService,
private route: ActivatedRoute,
private router: Router
) { }
private router: Router,
private viewportScroller: ViewportScroller
) {
// Geting previous scroll position
this.routerScrollSubscription = this.router.events.pipe(
filter(e => e instanceof Scroll)
).subscribe(e => {
if ((e as Scroll).position) {
this.scrollPosition = (e as Scroll).position;
} else {
this.scrollPosition = [0, 0];
}
});
}
private checkSubsystem() {
// Do not overwrite previous warnings
......@@ -67,7 +83,13 @@ export class SubsystemComponent implements OnInit, OnDestroy {
}
}
ngAfterViewInit() {
// Restoring scroll position
this.viewportScroller.scrollToPosition(this.scrollPosition);
}
ngOnDestroy() {
this.routerScrollSubscription.unsubscribe()
this.routeSubscription.unsubscribe()
this.updatedSubscription.unsubscribe()
this.warningsSubscription.unsubscribe()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment