|
| 1 | +/* |
| 2 | +Copyright 2021-Present Couchbase, Inc. |
| 3 | +
|
| 4 | +Use of this software is governed by the Business Source License included in |
| 5 | +the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that |
| 6 | +file, in accordance with the Business Source License, use of this software will |
| 7 | +be governed by the Apache License, Version 2.0, included in the file |
| 8 | +licenses/APL2.txt. |
| 9 | +*/ |
| 10 | + |
| 11 | +import {ChangeDetectionStrategy, Component} from '../web_modules/@angular/core.js'; |
| 12 | +import {MnLifeCycleHooksToStream} from './mn.core.js'; |
| 13 | +import {NgbActiveModal} from '../web_modules/@ng-bootstrap/ng-bootstrap.js'; |
| 14 | +import {ClipboardService} from '../web_modules/ngx-clipboard.js'; |
| 15 | +import {MnAlertsService} from './ajs.upgraded.providers.js'; |
| 16 | +import {MnLogsCollectInfoService} from './mn.logs.collectInfo.service.js'; |
| 17 | +import {takeUntil, filter, map} from '../web_modules/rxjs/operators.js'; |
| 18 | + |
| 19 | +export { MnClusterSummaryDialogComponent }; |
| 20 | + |
| 21 | +class MnClusterSummaryDialogComponent extends MnLifeCycleHooksToStream { |
| 22 | + |
| 23 | + static get annotations() { return [ |
| 24 | + new Component({ |
| 25 | + selector: "mn-cluster-summary-dialog", |
| 26 | + templateUrl: "/ui/app/mn.cluster.summary.dialog.html", |
| 27 | + providers: [ |
| 28 | + ClipboardService |
| 29 | + ], |
| 30 | + changeDetection: ChangeDetectionStrategy.OnPush |
| 31 | + }) |
| 32 | + ]} |
| 33 | + |
| 34 | + static get parameters() { return [ |
| 35 | + NgbActiveModal, |
| 36 | + ClipboardService, |
| 37 | + MnAlertsService, |
| 38 | + MnLogsCollectInfoService |
| 39 | + ]} |
| 40 | + |
| 41 | + constructor(activeModal, clipboardService, mnAlertsService, mnLogsCollectInfoService) { |
| 42 | + super(); |
| 43 | + |
| 44 | + this.activeModal = activeModal; |
| 45 | + this.mnAlertsService = mnAlertsService; |
| 46 | + |
| 47 | + this.clusterInfo = mnLogsCollectInfoService.stream.clusterInfo |
| 48 | + .pipe(map(v => JSON.stringify(v, null, 2))); |
| 49 | + |
| 50 | + clipboardService.copyResponse$ |
| 51 | + .pipe(filter(response => response.isSuccess), |
| 52 | + takeUntil(this.mnOnDestroy)) |
| 53 | + .subscribe(this.handleSuccessMessage.bind(this)); |
| 54 | + |
| 55 | + clipboardService.copyResponse$ |
| 56 | + .pipe(filter(response => !response.isSuccess), |
| 57 | + takeUntil(this.mnOnDestroy)) |
| 58 | + .subscribe(this.handleErrorMessage.bind(this)); |
| 59 | + } |
| 60 | + |
| 61 | + handleSuccessMessage() { |
| 62 | + this.activeModal.close(); |
| 63 | + this.mnAlertsService.formatAndSetAlerts('Text copied successfully!', |
| 64 | + 'success', |
| 65 | + 2500); |
| 66 | + } |
| 67 | + |
| 68 | + handleErrorMessage() { |
| 69 | + this.activeModal.close(); |
| 70 | + this.mnAlertsService.formatAndSetAlerts('Unable to copy text!', |
| 71 | + 'error', |
| 72 | + 2500); |
| 73 | + } |
| 74 | +} |
0 commit comments