Skip to content

Commit

Permalink
Merge pull request #347 from cobbler/feature/deduplicate-tohtml
Browse files Browse the repository at this point in the history
Utils: Introduce static class with toHTML method
  • Loading branch information
SchoolGuy authored Nov 1, 2024
2 parents e7afcdc + 5b60175 commit ff84e5f
Show file tree
Hide file tree
Showing 31 changed files with 116 additions and 260 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { BackgroundBuildisoOptions, CobblerApiService } from 'cobbler-api';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { UserService } from '../../services/user.service';
import Utils from '../../utils';

@Component({
selector: 'cobbler-build-iso',
Expand Down Expand Up @@ -85,14 +86,8 @@ export class BuildISOComponent implements OnDestroy {
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
},
);
}

toHTML(input: string): any {
// FIXME: Deduplicate method
return new DOMParser().parseFromString(input, 'text/html').documentElement
.textContent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { CobblerApiService } from 'cobbler-api';
import { Observable, of, Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { UserService } from '../../services/user.service';
import Utils from '../../utils';

@Component({
selector: 'cobbler-check-sys',
Expand Down Expand Up @@ -63,15 +64,9 @@ export class CheckSysComponent implements OnInit, OnDestroy {
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
this.isLoading = false;
},
);
}

toHTML(input: string): any {
// FIXME: Deduplicate method
return new DOMParser().parseFromString(input, 'text/html').documentElement
.textContent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CobblerApiService } from 'cobbler-api';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { UserService } from '../../services/user.service';
import Utils from '../../utils';

@Component({
selector: 'cobbler-hardlink',
Expand Down Expand Up @@ -38,14 +39,8 @@ export class HardlinkComponent implements OnDestroy {
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
},
);
}

toHTML(input: string): any {
// FIXME: Deduplicate method
return new DOMParser().parseFromString(input, 'text/html').documentElement
.textContent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CobblerApiService, BackgroundImportOptions } from 'cobbler-api';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { UserService } from '../../services/user.service';
import Utils from '../../utils';

@Component({
selector: 'cobbler-import-dvd',
Expand Down Expand Up @@ -77,14 +78,8 @@ export class ImportDVDComponent implements OnDestroy {
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
},
);
}

toHTML(input: string): any {
// FIXME: Deduplicate method
return new DOMParser().parseFromString(input, 'text/html').documentElement
.textContent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CobblerApiService } from 'cobbler-api';
import { Subject, Subscription } from 'rxjs';
import { MatSnackBar } from '@angular/material/snack-bar';
import { MatButton } from '@angular/material/button';
import Utils from '../../utils';

@Component({
selector: 'cobbler-mkloaders',
Expand Down Expand Up @@ -38,14 +39,8 @@ export class MkloadersComponent implements OnDestroy {
},
error: (error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
},
});
}

toHTML(input: string): any {
// FIXME: Deduplicate method
return new DOMParser().parseFromString(input, 'text/html').documentElement
.textContent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { BackgroundReplicateOptions, CobblerApiService } from 'cobbler-api';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { UserService } from '../../services/user.service';
import Utils from '../../utils';

@Component({
selector: 'cobbler-replicate',
Expand Down Expand Up @@ -86,14 +87,8 @@ export class ReplicateComponent implements OnDestroy {
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
},
);
}

toHTML(input: string): any {
// FIXME: Deduplicate method
return new DOMParser().parseFromString(input, 'text/html').documentElement
.textContent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from '@angular/material/form-field';
import { MatIcon } from '@angular/material/icon';
import { MatInput, MatInputModule } from '@angular/material/input';
import Utils from '../../utils';

@Component({
selector: 'cobbler-repo-sync',
Expand Down Expand Up @@ -116,14 +117,8 @@ export class RepoSyncComponent implements OnDestroy {
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
},
);
}

toHTML(input: string): any {
// FIXME: Deduplicate method
return new DOMParser().parseFromString(input, 'text/html').documentElement
.textContent;
}
}
11 changes: 3 additions & 8 deletions projects/cobbler-frontend/src/app/actions/sync/sync.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { CobblerApiService } from 'cobbler-api';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { UserService } from '../../services/user.service';
import Utils from '../../utils';

@Component({
selector: 'cobbler-sync',
Expand Down Expand Up @@ -117,7 +118,7 @@ export class SyncComponent implements OnDestroy {
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
},
);
}
Expand Down Expand Up @@ -154,14 +155,8 @@ export class SyncComponent implements OnDestroy {
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
},
);
}

toHTML(input: string): any {
// FIXME: Deduplicate method
return new DOMParser().parseFromString(input, 'text/html').documentElement
.textContent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CobblerApiService } from 'cobbler-api';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { UserService } from '../../services/user.service';
import Utils from '../../utils';

@Component({
selector: 'cobbler-validate-autoinstalls',
Expand Down Expand Up @@ -38,14 +39,8 @@ export class ValidateAutoinstallsComponent implements OnDestroy {
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
},
);
}

toHTML(input: string): any {
// FIXME: Deduplicate method
return new DOMParser().parseFromString(input, 'text/html').documentElement
.textContent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { CobblerApiService, Distro } from 'cobbler-api';
import { KeyValueEditorComponent } from '../../../common/key-value-editor/key-value-editor.component';
import { MultiSelectComponent } from '../../../common/multi-select/multi-select.component';
import { UserService } from '../../../services/user.service';
import Utils from '../../../utils';

@Component({
selector: 'cobbler-edit',
Expand Down Expand Up @@ -229,7 +230,7 @@ export class DistroEditComponent implements OnInit {
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
},
);
}
Expand All @@ -250,7 +251,7 @@ export class DistroEditComponent implements OnInit {
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
},
);
}
Expand All @@ -269,7 +270,7 @@ export class DistroEditComponent implements OnInit {
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
},
);
}
Expand Down Expand Up @@ -347,10 +348,4 @@ export class DistroEditComponent implements OnInit {
}
return {};
}

toHTML(input: string): any {
// FIXME: Deduplicate method
return new DOMParser().parseFromString(input, 'text/html').documentElement
.textContent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { takeUntil } from 'rxjs/operators';
import { DialogBoxTextConfirmComponent } from '../../../common/dialog-box-text-confirm/dialog-box-text-confirm';
import { DialogItemRenameComponent } from '../../../common/dialog-item-rename/dialog-item-rename.component';
import { UserService } from '../../../services/user.service';
import Utils from '../../../utils';

@Component({
selector: 'cobbler-distros',
Expand Down Expand Up @@ -86,7 +87,7 @@ export class DistrosOverviewComponent implements OnInit, OnDestroy {
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
},
);
}
Expand Down Expand Up @@ -123,13 +124,13 @@ export class DistrosOverviewComponent implements OnInit, OnDestroy {
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
},
);
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
},
);
});
Expand All @@ -145,14 +146,8 @@ export class DistrosOverviewComponent implements OnInit, OnDestroy {
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
},
);
}

toHTML(input: string): any {
// FIXME: Deduplicate method
return new DOMParser().parseFromString(input, 'text/html').documentElement
.textContent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { MatTooltip } from '@angular/material/tooltip';
import { ActivatedRoute, Router } from '@angular/router';
import { CobblerApiService, File } from 'cobbler-api';
import { UserService } from '../../../services/user.service';
import Utils from '../../../utils';

@Component({
selector: 'cobbler-edit',
Expand Down Expand Up @@ -103,7 +104,7 @@ export class FileEditComponent implements OnInit {
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
},
);
}
Expand All @@ -124,7 +125,7 @@ export class FileEditComponent implements OnInit {
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
},
);
}
Expand All @@ -141,18 +142,12 @@ export class FileEditComponent implements OnInit {
},
(error) => {
// HTML encode the error message since it originates from XML
this._snackBar.open(this.toHTML(error.message), 'Close');
this._snackBar.open(Utils.toHTML(error.message), 'Close');
},
);
}

saveFile(): void {
// TODO
}

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

0 comments on commit ff84e5f

Please sign in to comment.