SHARE
TWEET

Untitled

a guest Apr 4th, 2018 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, Input, OnDestroy, OnInit, ViewChild } from "@angular/core";
  2. import { SidenavService } from "app/core/sidenav/sidenav.service";
  3. import { IStory } from "app/core/model/story.interface";
  4. import { IStatus } from "app/shared/model/status.interface";
  5. import { StoryStatus } from "app/shared/story/story-status.constants";
  6. import { MatSelect, MatTabGroup } from "@angular/material";
  7. import { Subject } from "rxjs/Subject";
  8. import { HubSnackBarService } from "app/core/hub-snack-bar/service/hub-snack-bar.service";
  9. import { StoryFormComponent } from "app/shared/story/story-form/story-form.component";
  10.  
  11. @Component({
  12.     selector: "story-detail-overlay",
  13.     templateUrl: "./story-detail-overlay.component.html",
  14.     styleUrls: ["./story-detail-overlay.component.scss"]
  15. })
  16. export class StoryDetailOverlayComponent implements OnInit, OnDestroy {
  17.  
  18.     @Input()
  19.     story: IStory;
  20.  
  21.     public statusArray: IStatus[];
  22.  
  23.     public commentTabActive: boolean = false;
  24.  
  25.     @ViewChild("matTabGroup")
  26.     matTabGroup: MatTabGroup;
  27.  
  28.     @ViewChild("storyForm")
  29.     storyForm: StoryFormComponent;
  30.  
  31.     @ViewChild("storyStatusSelect")
  32.     storyStatusSelect: MatSelect;
  33.  
  34.     private unsubscribe: Subject<void> = new Subject<void>();
  35.  
  36.     constructor(private sidenavService: SidenavService,
  37.                 private hubSnackBarService: HubSnackBarService) {
  38.         this.statusArray = [StoryStatus.NEW, StoryStatus.READY_TO_PUBLISH, StoryStatus.PUBLISHED];
  39.     }
  40.  
  41.     ngOnInit() {
  42.         this.matTabGroup.selectedIndexChange
  43.             .takeUntil(this.unsubscribe)
  44.             .subscribe((selectedIndex: number) => {
  45.  
  46.                 // This selectedIndex needs to be updated (e.g. if a tab is inserted before the comments tab)!
  47.  
  48.                 this.commentTabActive = selectedIndex === 2;
  49.             });
  50.  
  51.         this.storyStatusSelect.setDisabledState(this.isPublished());
  52.     }
  53.  
  54.     private isPublished() {
  55.         return this.story.status === StoryStatus.PUBLISHED.id;
  56.     }
  57.  
  58.     ngOnDestroy() {
  59.         this.unsubscribe.next();
  60.         this.unsubscribe.complete();
  61.     }
  62. }
  63. ###################
  64. template
  65. <mat-tab-group #matTabGroup>
  66. (...)
  67. </mat-tab-group>
  68. <div *ngIf="!commentTabActive" class="footer-bar padding-2" fxLayoutAlign="start center">
  69.     <div class="flex-outer" fxFlexFill>
  70.         <div class="form-field-wrapper">
  71.             <label>
  72.                 {{ "APP.STORIES.STATUS.STATUS_LABEL" | translate }}
  73.             </label>
  74.             <mat-form-field floatPlaceholder="never">
  75.                 <mat-select #storyStatusSelect [(ngModel)]="story.status">
  76.                     <mat-option *ngFor="let status of statusArray" [value]="status.id">
  77.                         {{ status.title | translate }}
  78.                     </mat-option>
  79.                 </mat-select>
  80.             </mat-form-field>
  81.         </div>
  82.     </div>
  83. </div>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top