]>
Commit | Line | Data |
---|---|---|
9929fbd6 | 1 | import { Location } from '@angular/common' |
43d0ea7f | 2 | import { Component, ElementRef, ViewChild } from '@angular/core' |
67ed6552 | 3 | import { Notifier, UserService } from '@app/core' |
43d0ea7f | 4 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
9929fbd6 | 5 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' |
589d9f55 | 6 | import { About } from '@shared/models/server' |
43d0ea7f C |
7 | |
8 | @Component({ | |
9 | selector: 'my-instance-config-warning-modal', | |
10 | templateUrl: './instance-config-warning-modal.component.html', | |
11 | styleUrls: [ './instance-config-warning-modal.component.scss' ] | |
12 | }) | |
13 | export class InstanceConfigWarningModalComponent { | |
14 | @ViewChild('modal', { static: true }) modal: ElementRef | |
15 | ||
589d9f55 C |
16 | stopDisplayModal = false |
17 | about: About | |
18 | ||
9929fbd6 C |
19 | private LOCAL_STORAGE_KEYS = { |
20 | NO_INSTANCE_CONFIG_WARNING_MODAL: 'no_instance_config_warning_modal' | |
21 | } | |
22 | ||
43d0ea7f | 23 | constructor ( |
589d9f55 | 24 | private userService: UserService, |
9929fbd6 | 25 | private location: Location, |
43d0ea7f | 26 | private modalService: NgbModal, |
589d9f55 | 27 | private notifier: Notifier |
43d0ea7f C |
28 | ) { } |
29 | ||
589d9f55 | 30 | show (about: About) { |
9929fbd6 C |
31 | const result = peertubeLocalStorage.getItem(this.LOCAL_STORAGE_KEYS.NO_INSTANCE_CONFIG_WARNING_MODAL) |
32 | if (result === 'true') return | |
33 | ||
34 | if (this.location.path().startsWith('/admin/config/edit-custom')) return | |
35 | ||
589d9f55 C |
36 | this.about = about |
37 | ||
24e7916c | 38 | const ref = this.modalService.open(this.modal, { centered: true }) |
589d9f55 C |
39 | |
40 | ref.result.finally(() => { | |
41 | if (this.stopDisplayModal === true) this.doNotOpenAgain() | |
42 | }) | |
43 | } | |
44 | ||
592c735c | 45 | isDefaultShortDescription (description: string) { |
51de2c7f | 46 | return description === 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.' |
592c735c C |
47 | } |
48 | ||
589d9f55 | 49 | private doNotOpenAgain () { |
9929fbd6 C |
50 | peertubeLocalStorage.setItem(this.LOCAL_STORAGE_KEYS.NO_INSTANCE_CONFIG_WARNING_MODAL, 'true') |
51 | ||
589d9f55 C |
52 | this.userService.updateMyProfile({ noInstanceConfigWarningModal: true }) |
53 | .subscribe( | |
54 | () => console.log('We will not open the instance config warning modal again.'), | |
55 | ||
56 | err => this.notifier.error(err.message) | |
57 | ) | |
43d0ea7f C |
58 | } |
59 | } |