Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit, TemplateRef } from '@angular/core';
- import { NotificationService } from '../../services/notification.service';
- import { UserDTO, StoryDTO, ChapterDTO, BookmarkDTO } from '../../generated-models/rest';
- import { AuthService } from '../../services/auth.service';
- import { StoryService } from '../../services/story.service';
- import { UserService } from '../../services/user.service';
- import { BsModalRef, BsModalService } from "ngx-bootstrap";
- import { Router } from "@angular/router";
- import { SharedService } from '../../services/shared.service';
- @Component({
- selector: 'sidebar',
- templateUrl: './sidebar.component.html',
- styleUrls: ['./sidebar.component.css']
- })
- export class SidebarComponent implements OnInit {
- isCollapsedStory: boolean = false;
- isCollapsedChapter: boolean = false;
- isCollapsedBookmark: boolean = false;
- user: UserDTO;
- storyList: StoryDTO[];
- chapterList: ChapterDTO[];
- bookmarkList: BookmarkDTO[];
- story: StoryDTO;
- deleteModalRef: BsModalRef;
- constructor(private notificationService: NotificationService,
- private authService: AuthService,
- private storyService: StoryService,
- private userService: UserService,
- private modalService: BsModalService,
- private router: Router,
- private sharedService: SharedService) { }
- ngOnInit() {
- this.modalService.onHide.subscribe((reason: string) => this.story = null)
- this.authService.checkLogin()
- .then(user =>
- {
- this.user = user;
- if (user) {
- setTimeout(() => this.sharedService.showDefaultSidebar());
- }
- })
- .catch(error => this.handleError(error));
- this.authService.loggedIn.subscribe(value => {
- if (value) {
- setTimeout(() => this.sharedService.showDefaultSidebar());
- }
- else {
- setTimeout(() => this.sharedService.hideDefaultSidebar());
- this.chapterList = [];
- this.storyList = [];
- this.bookmarkList = [];
- }
- });
- this.sharedService.getStoryListObservable().subscribe(storyList =>
- {
- this.storyList = storyList;
- });
- this.sharedService.getChapterListObservable().subscribe(chapterList =>
- {
- this.chapterList = chapterList;
- });
- this.sharedService.getBookmarkListObservable().subscribe(bookmarkList =>
- {
- this.bookmarkList = bookmarkList;
- });
- this.sharedService.loadSidebarData();
- }
- showDeleteModal(template: TemplateRef<any>, story) {
- this.story=story;
- this.deleteModalRef = this.modalService.show(template);
- }
- confirmDelete(confirmed: boolean = false) {
- this.deleteModalRef.hide();
- if (confirmed) {
- this.storyService.deleteStory(this.story)
- .then(() => this.router.navigate(['/']));
- }
- else
- {
- this.story=null;
- }
- }
- private handleError(error) {
- this.notificationService.error(error.message || error);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement