aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/modal/instance-config-warning-modal.component.ts
blob: 08d83f383456d1a14eea258a78ae3d3a606b08e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Component, ElementRef, ViewChild } from '@angular/core'
import { Notifier } from '@app/core'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { About } from '@shared/models/server'
import { UserService } from '@app/shared'

@Component({
  selector: 'my-instance-config-warning-modal',
  templateUrl: './instance-config-warning-modal.component.html',
  styleUrls: [ './instance-config-warning-modal.component.scss' ]
})
export class InstanceConfigWarningModalComponent {
  @ViewChild('modal', { static: true }) modal: ElementRef

  stopDisplayModal = false
  about: About

  constructor (
    private userService: UserService,
    private modalService: NgbModal,
    private notifier: Notifier
  ) { }

  show (about: About) {
    this.about = about

    const ref = this.modalService.open(this.modal)

    ref.result.finally(() => {
      if (this.stopDisplayModal === true) this.doNotOpenAgain()
    })
  }

  private doNotOpenAgain () {
    this.userService.updateMyProfile({ noInstanceConfigWarningModal: true })
        .subscribe(
          () => console.log('We will not open the instance config warning modal again.'),

          err => this.notifier.error(err.message)
        )
  }
}