Skip to content

Commit

Permalink
add subscription for hardlink component
Browse files Browse the repository at this point in the history
  • Loading branch information
00Kadie00 committed Jul 19, 2024
1 parent 909f513 commit 9ae3788
Showing 1 changed file with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@
import { Component } from '@angular/core';
import { Component, OnDestroy } from '@angular/core';
import { MatButton } from '@angular/material/button';
import { MatSnackBar } from '@angular/material/snack-bar';
import { CobblerApiService } from 'cobbler-api';
import { UserService } from '../../services/user.service';
import { Subscription } from 'rxjs';

@Component({
selector: 'cobbler-hardlink',
standalone: true,
imports: [
MatButton
],
imports: [MatButton],
templateUrl: './hardlink.component.html',
styleUrl: './hardlink.component.scss'
styleUrl: './hardlink.component.scss',
})
export class HardlinkComponent {
export class HardlinkComponent implements OnDestroy {
private subs: Subscription = new Subscription();

constructor(
public userService: UserService,
private cobblerApiService: CobblerApiService,
private _snackBar: MatSnackBar
) {
) {}

ngOnDestroy(): void {
this.subs.unsubscribe();
}

runHardlink(): void {
this.cobblerApiService.background_hardlink(this.userService.token).subscribe(
value => {
// TODO
},
error => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
});
this.subs.add(
this.cobblerApiService
.background_hardlink(this.userService.token)
.subscribe({
next: (value) => {
// TODO
},
error: (error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
},
})
);
}

toHTML(input: string): any {
// FIXME: Deduplicate method
return new DOMParser().parseFromString(input, 'text/html').documentElement.textContent;
return new DOMParser().parseFromString(input, 'text/html').documentElement
.textContent;
}

}

0 comments on commit 9ae3788

Please sign in to comment.