Add initialization of repositories to dialog

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent ffced041d4
commit ace63ac461

@ -1581,7 +1581,7 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]] [[package]]
name = "mediarepo-api" name = "mediarepo-api"
version = "0.1.0" 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 = [ dependencies = [
"async-trait", "async-trait",
"chrono", "chrono",

@ -30,7 +30,7 @@ features = ["env-filter"]
[dependencies.mediarepo-api] [dependencies.mediarepo-api]
git = "https://github.com/Trivernis/mediarepo-api.git" git = "https://github.com/Trivernis/mediarepo-api.git"
rev = "c366f6a8ecc337790a0b5ebb18bb36267279ade8" rev = "4e0859cc08723f52057df73f16bff786be1aee43"
features = ["tauri-plugin"] features = ["tauri-plugin"]
[features] [features]

@ -43,6 +43,7 @@ import {DragDropModule} from "@angular/cdk/drag-drop";
import { ContentAwareImageComponent } from './components/content-aware-image/content-aware-image.component'; import { ContentAwareImageComponent } from './components/content-aware-image/content-aware-image.component';
import {MatSliderModule} from "@angular/material/slider"; import {MatSliderModule} from "@angular/material/slider";
import { AddRepositoryDialogComponent } from './pages/home/repositories-tab/add-repository-dialog/add-repository-dialog.component'; import { AddRepositoryDialogComponent } from './pages/home/repositories-tab/add-repository-dialog/add-repository-dialog.component';
import {MatTooltipModule} from "@angular/material/tooltip";
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -60,39 +61,40 @@ import { AddRepositoryDialogComponent } from './pages/home/repositories-tab/add-
ContentAwareImageComponent, ContentAwareImageComponent,
AddRepositoryDialogComponent, AddRepositoryDialogComponent,
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
AppRoutingModule, AppRoutingModule,
BrowserAnimationsModule, BrowserAnimationsModule,
MatCardModule, MatCardModule,
MatListModule, MatListModule,
MatButtonModule, MatButtonModule,
MatToolbarModule, MatToolbarModule,
MatSnackBarModule, MatSnackBarModule,
MatFormFieldModule, MatFormFieldModule,
MatInputModule, MatInputModule,
ReactiveFormsModule, ReactiveFormsModule,
MatSidenavModule, MatSidenavModule,
MatGridListModule, MatGridListModule,
MatProgressBarModule, MatProgressBarModule,
MatPaginatorModule, MatPaginatorModule,
ScrollingModule, ScrollingModule,
LightboxModule, LightboxModule,
MatChipsModule, MatChipsModule,
MatIconModule, MatIconModule,
MatAutocompleteModule, MatAutocompleteModule,
MatTabsModule, MatTabsModule,
FlexModule, FlexModule,
GridModule, GridModule,
MatRippleModule, MatRippleModule,
MatDialogModule, MatDialogModule,
MatSelectModule, MatSelectModule,
MatProgressSpinnerModule, MatProgressSpinnerModule,
BlockUIModule, BlockUIModule,
PanelModule, PanelModule,
DragDropModule, DragDropModule,
MatSliderModule, MatSliderModule,
], MatTooltipModule,
],
providers: [], providers: [],
bootstrap: [AppComponent] bootstrap: [AppComponent]
}) })

@ -2,12 +2,13 @@
<div mat-dialog-content> <div mat-dialog-content>
<form [formGroup]="formGroup"> <form [formGroup]="formGroup">
<mat-form-field> <mat-form-field matTooltipShowDelay="1000" matTooltip="A unique name for the repository">
<mat-label>Name</mat-label> <mat-label>Name</mat-label>
<input matInput formControlName="name"> <input matInput formControlName="name" (change)="validateName()" (input)="validateName()" (blur)="validateName()">
</mat-form-field> </mat-form-field>
<mat-form-field> <mat-form-field matTooltipShowDelay="1000"
matTooltip="Type of repository if it's on the local system or somewhere else">
<mat-label>Type</mat-label> <mat-label>Type</mat-label>
<mat-select #repoTypeSelect formControlName="repositoryType" <mat-select #repoTypeSelect formControlName="repositoryType"
(selectionChange)="onTypeChange(repoTypeSelect.value)"> (selectionChange)="onTypeChange(repoTypeSelect.value)">
@ -16,13 +17,18 @@
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
<mat-form-field *ngIf="repoTypeSelect.value === 'local'"> <mat-form-field *ngIf="repoTypeSelect.value === 'local'"
<button class="button-folder-select" mat-button (click)="openFolderDialog()"><mat-icon>folder</mat-icon></button> matTooltipShowDelay="1000"
matTooltip="Path where the repository is located or should be created">
<button class="button-folder-select" mat-button (click)="openFolderDialog()">
<mat-icon>folder</mat-icon>
</button>
<mat-label>Path</mat-label> <mat-label>Path</mat-label>
<input matInput formControlName="path"> <input matInput formControlName="path" (change)="this.checkLocalRepoExists()">
</mat-form-field> </mat-form-field>
<mat-form-field *ngIf="repoTypeSelect.value === 'remote'"> <mat-form-field *ngIf="repoTypeSelect.value === 'remote'" matTooltipShowDelay="1000"
matTooltip="IP address and port of the remote repository">
<mat-label>Address</mat-label> <mat-label>Address</mat-label>
<input matInput formControlName="address"> <input matInput formControlName="address">
</mat-form-field> </mat-form-field>
@ -32,8 +38,17 @@
</div> </div>
</div> </div>
<div class="dialog-buttons" mat-dialog-actions> <div class="dialog-buttons" mat-dialog-actions>
<button mat-flat-button [disabled]="!formGroup.valid" color="primary" (click)="addRepository()">Add</button> <button mat-flat-button *ngIf="repoTypeSelect.value === 'remote' || this.localRepoExists"
[disabled]="!formGroup.valid" matTooltip="Add the existing repository" color="primary"
(click)="addRepository()">Add
</button>
<button mat-flat-button *ngIf="repoTypeSelect.value === 'local' && !this.localRepoExists"
[disabled]="!formGroup.valid"
matTooltip="Initialize the repository in the specified path" color="accent"
(click)="this.initLocalRepository()">Init
</button>
<button mat-stroked-button color="accent" (click)="closeDialog()">Cancel</button> <button mat-stroked-button color="accent" (click)="closeDialog()">Cancel</button>
<button class="check-connection-button" *ngIf="repoTypeSelect.value === 'remote'" [disabled]="!formGroup.valid" <button class="check-connection-button" *ngIf="repoTypeSelect.value === 'remote'" [disabled]="!formGroup.valid"
mat-stroked-button (click)="checkRepositoryStatus()">Check Connection</button> mat-stroked-button (click)="checkRepositoryStatus()">Check Connection
</button>
</div> </div>

@ -9,13 +9,14 @@ import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
import {RepositoryService} from "../../../../services/repository/repository.service"; import {RepositoryService} from "../../../../services/repository/repository.service";
import {ErrorBrokerService} from "../../../../services/error-broker/error-broker.service"; import {ErrorBrokerService} from "../../../../services/error-broker/error-broker.service";
import {dialog} from "@tauri-apps/api"; import {dialog} from "@tauri-apps/api";
import {Repository} from "../../../../models/Repository";
@Component({ @Component({
selector: 'app-add-repository-dialog', selector: 'app-add-repository-dialog',
templateUrl: './add-repository-dialog.component.html', templateUrl: './add-repository-dialog.component.html',
styleUrls: ['./add-repository-dialog.component.scss'] styleUrls: ['./add-repository-dialog.component.scss']
}) })
export class AddRepositoryDialogComponent { export class AddRepositoryDialogComponent implements OnInit {
formGroup = new FormGroup({ formGroup = new FormGroup({
name: new FormControl("My Repository", [Validators.required]), name: new FormControl("My Repository", [Validators.required]),
@ -24,7 +25,9 @@ export class AddRepositoryDialogComponent {
address: new FormControl("", [this.validateAddress]) address: new FormControl("", [this.validateAddress])
}); });
repositories: Repository[] = [];
onlineStatus = "Unknown"; onlineStatus = "Unknown";
localRepoExists = false;
constructor( constructor(
public repoService: RepositoryService, public repoService: RepositoryService,
@ -33,6 +36,10 @@ export class AddRepositoryDialogComponent {
@Inject(MAT_DIALOG_DATA) data: any) { @Inject(MAT_DIALOG_DATA) data: any) {
} }
ngOnInit(): void {
this.repoService.repositories.subscribe(repositories => this.repositories = repositories)
}
public async checkRepositoryStatus() { public async checkRepositoryStatus() {
this.onlineStatus = "Checking..."; this.onlineStatus = "Checking...";
const address = this.formGroup.value.address; const address = this.formGroup.value.address;
@ -41,6 +48,16 @@ export class AddRepositoryDialogComponent {
this.onlineStatus = running? "Online" : "Offline"; 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() { public async addRepository() {
let {name, repositoryType, path, address} = this.formGroup.value; let {name, repositoryType, path, address} = this.formGroup.value;
path = repositoryType === "local"? path : undefined; path = repositoryType === "local"? path : undefined;
@ -63,6 +80,7 @@ export class AddRepositoryDialogComponent {
multiple: false, multiple: false,
}); });
this.formGroup.get("path")?.setValue(path); this.formGroup.get("path")?.setValue(path);
await this.checkLocalRepoExists();
} }
public async onTypeChange(type: string) { public async onTypeChange(type: string) {
@ -86,6 +104,15 @@ export class AddRepositoryDialogComponent {
}, 0); }, 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 { validatePath(control: AbstractControl): ValidationErrors | null {
const repositoryType = control.parent?.get("repositoryType")?.value ?? "local"; const repositoryType = control.parent?.get("repositoryType")?.value ?? "local";

@ -41,6 +41,14 @@ export class RepositoryService {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
public async setRepository(repo: Repository) { 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 invoke("plugin:mediarepo|select_repository", {name: repo.name});
await this.loadRepositories(); await this.loadRepositories();
} }
@ -85,6 +93,24 @@ export class RepositoryService {
return await invoke<boolean>("plugin:mediarepo|check_daemon_running", {address}); return await invoke<boolean>("plugin:mediarepo|check_daemon_running", {address});
} }
/**
* Checks if a local repository exists
* @param {string} path
* @returns {Promise<boolean>}
*/
public async checkLocalRepositoryExists(path: string): Promise<boolean> {
return await invoke<boolean>("plugin:mediarepo|check_local_repository_exists", {path})
}
/**
* Removes a repository from the list of saved repositories
* @param {string} name
* @returns {Promise<void>}
*/
public async removeRepository(name: string): Promise<void> {
await invoke("plugin:mediarepo|remove_repository", {name})
}
/** /**
* Starts a daemon for the given repository path * Starts a daemon for the given repository path
* @param {string} repoPath * @param {string} repoPath
@ -94,6 +120,10 @@ export class RepositoryService {
await invoke("plugin:mediarepo|start_daemon", {repoPath}) await invoke("plugin:mediarepo|start_daemon", {repoPath})
} }
public async initRepository(repoPath: string): Promise<void> {
await invoke("plugin:mediarepo|init_repository", {repoPath});
}
async loadSelectedRepository() { async loadSelectedRepository() {
let active_repo = await invoke<Repository | undefined>("plugin:mediarepo|get_active_repository"); let active_repo = await invoke<Repository | undefined>("plugin:mediarepo|get_active_repository");
this.selectedRepository.next(active_repo); this.selectedRepository.next(active_repo);

Loading…
Cancel
Save