Skip to content

Commit

Permalink
add db switcher in header
Browse files Browse the repository at this point in the history
  • Loading branch information
mucsi96 committed Aug 25, 2024
1 parent b3ca1a6 commit 41ed8b7
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 40 deletions.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- add more details to main screen including record, tables, backups count and last backup time
8 changes: 4 additions & 4 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@angular/platform-browser": "^18.1.0",
"@angular/platform-browser-dynamic": "^18.1.0",
"@angular/router": "^18.1.0",
"@mucsi96/ui-elements": "^56.0.0",
"@mucsi96/ui-elements": "^58.0.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.3"
Expand Down
6 changes: 6 additions & 0 deletions client/src/app/app.component.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
main {
margin-top: 32px;
}

.selected-database {
display: inline-flex;
align-items: center;
gap: 20px;
}
18 changes: 16 additions & 2 deletions client/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@
<header bt>
<nav>
<a href="/" bt-logo>Postgres Backup Tool</a>
<div>
<div class="selected-database">
@if (databaseName()) {
<button bt bt-dropdown popovertarget="dropdown-menu-popover">
{{ databaseName() }}
<svg></svg>
</button>
<div popover bt id="dropdown-menu-popover">
<ul bt-dropdown-menu>
@for(database of databases(); track database) {
<li>
<a routerLink="/database/{{ database }}">{{ database }}</a>
</li>
}
</ul>
</div>
@if (time) {
<h3 bt>
Last backup <span bt-badge>{{ time | relativeTime }}</span>
</h3>
}
} }
</div>
</nav>
</header>
Expand Down
22 changes: 18 additions & 4 deletions client/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import { Component, Signal } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { Component, signal, Signal } from '@angular/core';
import { ActivatedRoute, RouterLink, RouterOutlet } from '@angular/router';
import { BackupsService } from './backups/backups.service';
import { RelativeTimePipe } from './utils/relativeTime.pipe';
import { DatabasesService } from './databases/databases.service';

@Component({
selector: 'app-root',
standalone: true,
imports: [RouterOutlet, RelativeTimePipe],
imports: [RouterOutlet, RelativeTimePipe, RouterLink],
templateUrl: './app.component.html',
styleUrl: './app.component.css',
})
export class AppComponent {
databaseName = signal<string | undefined>(undefined);
databases: Signal<string[] | undefined>;
lastBackupTime: Signal<Date | undefined>;

constructor(private readonly backupsService: BackupsService) {
constructor(
private readonly route: ActivatedRoute,
private readonly databasesService: DatabasesService,
private readonly backupsService: BackupsService
) {
this.route.params.subscribe((params) => {
if (params['name']) {
this.databaseName.set(params['name']);
}
});
this.databases = this.databasesService.getDatabases();
this.databaseName = this.databasesService.getSelectedDatabase();
this.lastBackupTime = this.backupsService.getLastBackupTime();
}
}
15 changes: 4 additions & 11 deletions client/src/app/backups/backups.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Component, signal, Signal, WritableSignal } from '@angular/core';
import { Backup } from '../../types';
import { BackupsService } from './backups.service';
import { SizePipe } from '../utils/size.pipe';
import { RetentionPipe } from '../utils/retention.pipe';
import { RelativeTimePipe } from '../utils/relativeTime.pipe';
import { TablesService } from '../tables/tables.service';
import { ActivatedRoute } from '@angular/router';
import { RelativeTimePipe } from '../utils/relativeTime.pipe';
import { RetentionPipe } from '../utils/retention.pipe';
import { SizePipe } from '../utils/size.pipe';
import { BackupsService } from './backups.service';

@Component({
selector: 'app-backups',
Expand All @@ -21,15 +20,9 @@ export class BackupsComponent {
selectedBackup: WritableSignal<string | undefined> = signal(undefined);

constructor(
private readonly route: ActivatedRoute,
private readonly backupsService: BackupsService,
private readonly tableService: TablesService
) {
this.route.params.subscribe((params) => {
if (params['name']) {
this.backupsService.setDatabaseName(params['name']);
}
});
this.backups = this.backupsService.getBackups();
this.processing = this.backupsService.isProcessing();
this.loading = this.backupsService.isLoading();
Expand Down
25 changes: 21 additions & 4 deletions client/src/app/database/database.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import { Component } from '@angular/core';
import { TablesComponent } from "../tables/tables.component";
import { BackupsComponent } from "../backups/backups.component";
import { TablesComponent } from '../tables/tables.component';
import { BackupsComponent } from '../backups/backups.component';
import { ActivatedRoute } from '@angular/router';
import { BackupsService } from '../backups/backups.service';
import { TablesService } from '../tables/tables.service';
import { DatabasesService } from '../databases/databases.service';

@Component({
selector: 'app-database',
standalone: true,
imports: [TablesComponent, BackupsComponent],
templateUrl: './database.component.html',
styleUrl: './database.component.css'
styleUrl: './database.component.css',
})
export class DatabaseComponent {

constructor(
private readonly route: ActivatedRoute,
private readonly databasesService: DatabasesService,
private readonly backupsService: BackupsService,
private readonly tablesService: TablesService
) {
this.route.params.subscribe((params) => {
if (params['name']) {
this.databasesService.setDatabaseName(params['name']);
this.tablesService.setDatabaseName(params['name']);
this.backupsService.setDatabaseName(params['name']);
}
});
}
}
15 changes: 10 additions & 5 deletions client/src/app/databases/databases.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { HttpClient } from '@angular/common/http';
import { Injectable, signal } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import {
Observable,
shareReplay,
tap
} from 'rxjs';
import { Observable, shareReplay, tap } from 'rxjs';
import { environment } from '../../environments/environment';
import { handleError } from '../utils/handleError';

Expand All @@ -14,6 +10,7 @@ import { handleError } from '../utils/handleError';
})
export class DatabasesService {
$databases: Observable<string[]>;
selectedDatabase = signal<string | undefined>(undefined);
loading = signal(true);

constructor(private readonly http: HttpClient) {
Expand All @@ -26,6 +23,14 @@ export class DatabasesService {
);
}

getSelectedDatabase() {
return this.selectedDatabase;
}

setDatabaseName(name: string) {
this.selectedDatabase.set(name);
}

getDatabases() {
return toSignal(this.$databases);
}
Expand Down
11 changes: 2 additions & 9 deletions client/src/app/tables/tables.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Component, computed, input, signal, Signal } from '@angular/core';
import { Component, computed, signal, Signal } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { Table } from '../../types';
import { BackupsService } from '../backups/backups.service';
import { TablesService } from './tables.service';
import { FormsModule } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';

@Component({
selector: 'app-tables',
Expand All @@ -20,15 +19,9 @@ export class TablesComponent {
loading: Signal<boolean>;

constructor(
private readonly route: ActivatedRoute,
private readonly tableService: TablesService,
private readonly backupsService: BackupsService
) {
this.route.params.subscribe((params) => {
if (params['name']) {
this.tableService.setDatabaseName(params['name']);
}
});
this.tables = this.tableService.getTables();
this.totalRowCount = this.tableService.getTotalRowCount();
this.loading = this.tableService.isLoading();
Expand Down
1 change: 1 addition & 0 deletions server/src/main/resources/templates/fragments.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/*<![CDATA[*/
const base = document.createElement("base");
base.href = "[[@{/}]]";
document.getElementsByTagName("base")[0].remove();
document.getElementsByTagName("head")[0].appendChild(base);
/*]]>*/
</script>
Expand Down

0 comments on commit 41ed8b7

Please sign in to comment.