Project

General

Profile

1
/**
2
 * Created by stefania on 7/17/17.
3
 */
4
import { Component, OnInit, Input } from '@angular/core';
5
import { ActivatedRoute, Router } from "@angular/router";
6
import { HelpContentService } from "../../services/help-content.service";
7
import { Content, PageContent } from "../../domain/page-content";
8

    
9
@Component({
10
  selector: 'help-content',
11
  template: `
12
    <ng-template [ngIf]="contents && contents.length>0">
13
      <ng-template ngFor let-content [ngForOf]="contents">
14
        <div [innerHTML]="content.content" class="uk-margin-medium-bottom"></div>
15
      </ng-template>
16
    </ng-template>
17
  `,
18
})
19

    
20
export class HelpContentComponent implements OnInit {
21

    
22
  @Input('position')
23
  position: string;
24

    
25
  contents: Content[];
26
  errorMessage: string = null;
27

    
28
  constructor(private _helpContentService: HelpContentService, private route: ActivatedRoute,private router: Router) {
29
  }
30

    
31
  ngOnInit() {
32
    this.errorMessage = null;
33
    this._helpContentService.getActivePageContent( this.router.url ).subscribe(
34
      pageContent => this.shiftThroughContent(pageContent),
35
      error => this.handleError(<any>error)
36
    );
37
  }
38

    
39
  shiftThroughContent(pageContent: PageContent) {
40
    this.contents = pageContent.content[this.position];
41
    console.log(`help-service for ${this.router.url} -> ${this.position} responded: ${JSON.stringify(this.contents)}`);
42
  }
43

    
44
  isPresent() {
45
    return (this.contents && this.contents.length>0);
46
  }
47

    
48
  handleError(error) {
49
    this.errorMessage = 'System error retrieving page content (Server responded: ' + error + ')';
50
  }
51
}
52

    
53
@Component({
54
  selector: 'aside-help-content',
55
  template: `
56
    <ng-template [ngIf]="contents && contents.length>0">
57
      <ng-template ngFor let-content [ngForOf]="contents">
58
        <div [innerHTML]="content.content" class="uk-card uk-card-body uk-card-default sidemenu uk-margin-bottom"></div>
59
      </ng-template>
60
    </ng-template>
61
  `,
62
})
63
export class AsideHelpContentComponent extends HelpContentComponent {
64

    
65
}
(3-3/7)