diff --git a/mediarepo-ui/src-tauri/Cargo.lock b/mediarepo-ui/src-tauri/Cargo.lock index dde82b7..c5e82b9 100644 --- a/mediarepo-ui/src-tauri/Cargo.lock +++ b/mediarepo-ui/src-tauri/Cargo.lock @@ -1581,7 +1581,7 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] name = "mediarepo-api" version = "0.1.0" -source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=c366f6a8ecc337790a0b5ebb18bb36267279ade8#c366f6a8ecc337790a0b5ebb18bb36267279ade8" +source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=4e0859cc08723f52057df73f16bff786be1aee43#4e0859cc08723f52057df73f16bff786be1aee43" dependencies = [ "async-trait", "chrono", diff --git a/mediarepo-ui/src-tauri/Cargo.toml b/mediarepo-ui/src-tauri/Cargo.toml index f575f9b..54d6e87 100644 --- a/mediarepo-ui/src-tauri/Cargo.toml +++ b/mediarepo-ui/src-tauri/Cargo.toml @@ -30,7 +30,7 @@ features = ["env-filter"] [dependencies.mediarepo-api] git = "https://github.com/Trivernis/mediarepo-api.git" -rev = "c366f6a8ecc337790a0b5ebb18bb36267279ade8" +rev = "4e0859cc08723f52057df73f16bff786be1aee43" features = ["tauri-plugin"] [features] diff --git a/mediarepo-ui/src/app/app.module.ts b/mediarepo-ui/src/app/app.module.ts index b64c2b8..86daa1c 100644 --- a/mediarepo-ui/src/app/app.module.ts +++ b/mediarepo-ui/src/app/app.module.ts @@ -43,6 +43,7 @@ import {DragDropModule} from "@angular/cdk/drag-drop"; import { ContentAwareImageComponent } from './components/content-aware-image/content-aware-image.component'; import {MatSliderModule} from "@angular/material/slider"; import { AddRepositoryDialogComponent } from './pages/home/repositories-tab/add-repository-dialog/add-repository-dialog.component'; +import {MatTooltipModule} from "@angular/material/tooltip"; @NgModule({ declarations: [ @@ -60,39 +61,40 @@ import { AddRepositoryDialogComponent } from './pages/home/repositories-tab/add- ContentAwareImageComponent, AddRepositoryDialogComponent, ], - imports: [ - BrowserModule, - AppRoutingModule, - BrowserAnimationsModule, - MatCardModule, - MatListModule, - MatButtonModule, - MatToolbarModule, - MatSnackBarModule, - MatFormFieldModule, - MatInputModule, - ReactiveFormsModule, - MatSidenavModule, - MatGridListModule, - MatProgressBarModule, - MatPaginatorModule, - ScrollingModule, - LightboxModule, - MatChipsModule, - MatIconModule, - MatAutocompleteModule, - MatTabsModule, - FlexModule, - GridModule, - MatRippleModule, - MatDialogModule, - MatSelectModule, - MatProgressSpinnerModule, - BlockUIModule, - PanelModule, - DragDropModule, - MatSliderModule, - ], + imports: [ + BrowserModule, + AppRoutingModule, + BrowserAnimationsModule, + MatCardModule, + MatListModule, + MatButtonModule, + MatToolbarModule, + MatSnackBarModule, + MatFormFieldModule, + MatInputModule, + ReactiveFormsModule, + MatSidenavModule, + MatGridListModule, + MatProgressBarModule, + MatPaginatorModule, + ScrollingModule, + LightboxModule, + MatChipsModule, + MatIconModule, + MatAutocompleteModule, + MatTabsModule, + FlexModule, + GridModule, + MatRippleModule, + MatDialogModule, + MatSelectModule, + MatProgressSpinnerModule, + BlockUIModule, + PanelModule, + DragDropModule, + MatSliderModule, + MatTooltipModule, + ], providers: [], bootstrap: [AppComponent] }) diff --git a/mediarepo-ui/src/app/pages/home/repositories-tab/add-repository-dialog/add-repository-dialog.component.html b/mediarepo-ui/src/app/pages/home/repositories-tab/add-repository-dialog/add-repository-dialog.component.html index 44bc961..c31b827 100644 --- a/mediarepo-ui/src/app/pages/home/repositories-tab/add-repository-dialog/add-repository-dialog.component.html +++ b/mediarepo-ui/src/app/pages/home/repositories-tab/add-repository-dialog/add-repository-dialog.component.html @@ -2,12 +2,13 @@
- + Name - + - + Type @@ -16,13 +17,18 @@ - - + + Path - + - + Address @@ -32,8 +38,17 @@
- + + + mat-stroked-button (click)="checkRepositoryStatus()">Check Connection +
diff --git a/mediarepo-ui/src/app/pages/home/repositories-tab/add-repository-dialog/add-repository-dialog.component.ts b/mediarepo-ui/src/app/pages/home/repositories-tab/add-repository-dialog/add-repository-dialog.component.ts index 82c4968..a73b55b 100644 --- a/mediarepo-ui/src/app/pages/home/repositories-tab/add-repository-dialog/add-repository-dialog.component.ts +++ b/mediarepo-ui/src/app/pages/home/repositories-tab/add-repository-dialog/add-repository-dialog.component.ts @@ -9,13 +9,14 @@ import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; import {RepositoryService} from "../../../../services/repository/repository.service"; import {ErrorBrokerService} from "../../../../services/error-broker/error-broker.service"; import {dialog} from "@tauri-apps/api"; +import {Repository} from "../../../../models/Repository"; @Component({ selector: 'app-add-repository-dialog', templateUrl: './add-repository-dialog.component.html', styleUrls: ['./add-repository-dialog.component.scss'] }) -export class AddRepositoryDialogComponent { +export class AddRepositoryDialogComponent implements OnInit { formGroup = new FormGroup({ name: new FormControl("My Repository", [Validators.required]), @@ -24,7 +25,9 @@ export class AddRepositoryDialogComponent { address: new FormControl("", [this.validateAddress]) }); + repositories: Repository[] = []; onlineStatus = "Unknown"; + localRepoExists = false; constructor( public repoService: RepositoryService, @@ -33,6 +36,10 @@ export class AddRepositoryDialogComponent { @Inject(MAT_DIALOG_DATA) data: any) { } + ngOnInit(): void { + this.repoService.repositories.subscribe(repositories => this.repositories = repositories) + } + public async checkRepositoryStatus() { this.onlineStatus = "Checking..."; const address = this.formGroup.value.address; @@ -41,6 +48,16 @@ export class AddRepositoryDialogComponent { this.onlineStatus = running? "Online" : "Offline"; } + public async checkLocalRepoExists() { + this.localRepoExists = await this.repoService.checkLocalRepositoryExists(this.formGroup.value.path); + } + + public async initLocalRepository() { + const path = this.formGroup.value.path; + await this.repoService.initRepository(path); + await this.checkLocalRepoExists(); + } + public async addRepository() { let {name, repositoryType, path, address} = this.formGroup.value; path = repositoryType === "local"? path : undefined; @@ -63,6 +80,7 @@ export class AddRepositoryDialogComponent { multiple: false, }); this.formGroup.get("path")?.setValue(path); + await this.checkLocalRepoExists(); } public async onTypeChange(type: string) { @@ -86,6 +104,15 @@ export class AddRepositoryDialogComponent { }, 0); } + validateName() { + const control = this.formGroup.get("name"); + const value = control?.value; + + if (this.repositories.find(r => r.name === value)) { + control?.setErrors({nameAlreadyExists: value}); + } + } + validatePath(control: AbstractControl): ValidationErrors | null { const repositoryType = control.parent?.get("repositoryType")?.value ?? "local"; diff --git a/mediarepo-ui/src/app/services/repository/repository.service.ts b/mediarepo-ui/src/app/services/repository/repository.service.ts index a25c318..5e4c52a 100644 --- a/mediarepo-ui/src/app/services/repository/repository.service.ts +++ b/mediarepo-ui/src/app/services/repository/repository.service.ts @@ -41,6 +41,14 @@ export class RepositoryService { * @returns {Promise} */ public async setRepository(repo: Repository) { + const selectedRepo = this.selectedRepository.getValue() + if (selectedRepo) { + if (selectedRepo.local) { + await this.closeSelectedRepository(); + } else { + await this.disconnectSelectedRepository(); + } + } await invoke("plugin:mediarepo|select_repository", {name: repo.name}); await this.loadRepositories(); } @@ -85,6 +93,24 @@ export class RepositoryService { return await invoke("plugin:mediarepo|check_daemon_running", {address}); } + /** + * Checks if a local repository exists + * @param {string} path + * @returns {Promise} + */ + public async checkLocalRepositoryExists(path: string): Promise { + return await invoke("plugin:mediarepo|check_local_repository_exists", {path}) + } + + /** + * Removes a repository from the list of saved repositories + * @param {string} name + * @returns {Promise} + */ + public async removeRepository(name: string): Promise { + await invoke("plugin:mediarepo|remove_repository", {name}) + } + /** * Starts a daemon for the given repository path * @param {string} repoPath @@ -94,6 +120,10 @@ export class RepositoryService { await invoke("plugin:mediarepo|start_daemon", {repoPath}) } + public async initRepository(repoPath: string): Promise { + await invoke("plugin:mediarepo|init_repository", {repoPath}); + } + async loadSelectedRepository() { let active_repo = await invoke("plugin:mediarepo|get_active_repository"); this.selectedRepository.next(active_repo);