Add edit dialog for repositories
TG-10 #ready-for-test Signed-off-by: trivernis <trivernis@protonmail.com>pull/4/head
parent
579a5a43be
commit
41be1b63f4
@ -0,0 +1,24 @@
|
|||||||
|
<h1 mat-dialog-title>Edit {{this.selectedRepository.name}}</h1>
|
||||||
|
<div mat-dialog-content>
|
||||||
|
<app-repository-form #repoForm [name]="selectedRepository.name" [address]="selectedRepository.address ?? ''"
|
||||||
|
[repositoryType]="selectedRepository.local? 'local' : 'remote'"
|
||||||
|
[path]="selectedRepository.path ?? ''" [validateNameDuplicate]="false"></app-repository-form>
|
||||||
|
</div>
|
||||||
|
<div class="dialog-buttons" mat-dialog-actions>
|
||||||
|
<button (click)="closeDialog()" color="accent" mat-stroked-button>Cancel</button>
|
||||||
|
<button (click)="addRepository()"
|
||||||
|
*ngIf="repoForm.formGroup.get('repositoryType')?.value === 'remote' || repoForm.localRepoExists"
|
||||||
|
[disabled]="!repoForm.formGroup.valid" color="primary" mat-flat-button
|
||||||
|
matTooltip="Save the existing repository">Save
|
||||||
|
</button>
|
||||||
|
<button (click)="this.initLocalRepository()"
|
||||||
|
*ngIf="repoForm.formGroup.get('repositoryType')?.value === 'local' && !repoForm.localRepoExists"
|
||||||
|
[disabled]="!repoForm.formGroup.valid"
|
||||||
|
color="accent" mat-flat-button
|
||||||
|
matTooltip="Initialize the repository in the specified path">Init
|
||||||
|
</button>
|
||||||
|
<button (click)="repoForm.checkRepositoryStatus()"
|
||||||
|
*ngIf="repoForm.formGroup.get('repositoryType')?.value === 'remote'" [disabled]="!repoForm.formGroup.valid"
|
||||||
|
class="check-connection-button" mat-stroked-button>Check Connection
|
||||||
|
</button>
|
||||||
|
</div>
|
@ -0,0 +1,20 @@
|
|||||||
|
app-repository-form {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-buttons {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
button {
|
||||||
|
margin-left: 1em;
|
||||||
|
float: right
|
||||||
|
}
|
||||||
|
|
||||||
|
.check-connection-button {
|
||||||
|
justify-self: right;
|
||||||
|
margin: 0;
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { EditRepositoryDialogComponent } from './edit-repository-dialog.component';
|
||||||
|
|
||||||
|
describe('EditRepositoryDialogComponent', () => {
|
||||||
|
let component: EditRepositoryDialogComponent;
|
||||||
|
let fixture: ComponentFixture<EditRepositoryDialogComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ EditRepositoryDialogComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(EditRepositoryDialogComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,82 @@
|
|||||||
|
import {Component, Inject, OnInit, ViewChild} from "@angular/core";
|
||||||
|
import {
|
||||||
|
RepositoryFormComponent
|
||||||
|
} from "../repository-form/repository-form.component";
|
||||||
|
import {
|
||||||
|
RepositoryService
|
||||||
|
} from "../../../../services/repository/repository.service";
|
||||||
|
import {
|
||||||
|
ErrorBrokerService
|
||||||
|
} from "../../../../services/error-broker/error-broker.service";
|
||||||
|
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
||||||
|
import {
|
||||||
|
AddRepositoryDialogComponent
|
||||||
|
} from "../add-repository-dialog/add-repository-dialog.component";
|
||||||
|
import {Repository} from "../../../../models/Repository";
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: "app-edit-repository-dialog",
|
||||||
|
templateUrl: "./edit-repository-dialog.component.html",
|
||||||
|
styleUrls: ["./edit-repository-dialog.component.scss"]
|
||||||
|
})
|
||||||
|
export class EditRepositoryDialogComponent {
|
||||||
|
|
||||||
|
@ViewChild(RepositoryFormComponent) repositoryForm!: RepositoryFormComponent;
|
||||||
|
|
||||||
|
public selectedRepository: Repository;
|
||||||
|
public originalName: string;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
public repoService: RepositoryService,
|
||||||
|
public errorBroker: ErrorBrokerService,
|
||||||
|
public dialogRef: MatDialogRef<AddRepositoryDialogComponent>,
|
||||||
|
@Inject(MAT_DIALOG_DATA) data: any) {
|
||||||
|
this.selectedRepository = data.repository;
|
||||||
|
this.originalName = this.selectedRepository.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async checkLocalRepoExists() {
|
||||||
|
this.repositoryForm.localRepoExists = await this.repoService.checkLocalRepositoryExists(
|
||||||
|
this.repositoryForm.formGroup.value.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async initLocalRepository() {
|
||||||
|
const path = this.repositoryForm.formGroup.value.path;
|
||||||
|
try {
|
||||||
|
await this.repoService.initRepository(path);
|
||||||
|
} catch (err) {
|
||||||
|
this.errorBroker.showError(err);
|
||||||
|
}
|
||||||
|
await this.checkLocalRepoExists();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async addRepository() {
|
||||||
|
let {name, repositoryType, path, address} = this.repositoryForm.formGroup.value;
|
||||||
|
path = repositoryType === "local" ? path : undefined;
|
||||||
|
address = repositoryType === "remote" ? address : undefined;
|
||||||
|
|
||||||
|
if (this.originalName === this.repoService.selectedRepository.getValue()?.name) {
|
||||||
|
await this.repoService.closeSelectedRepository();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (name != this.originalName) {
|
||||||
|
await this.repoService.removeRepository(this.originalName);
|
||||||
|
}
|
||||||
|
await this.repoService.addRepository(name, path, address,
|
||||||
|
repositoryType === "local");
|
||||||
|
this.selectedRepository.name = name;
|
||||||
|
this.selectedRepository.local = repositoryType === "local";
|
||||||
|
this.selectedRepository.path = path;
|
||||||
|
this.selectedRepository.address = address;
|
||||||
|
|
||||||
|
this.dialogRef.close();
|
||||||
|
} catch (err) {
|
||||||
|
this.errorBroker.showError(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public closeDialog() {
|
||||||
|
this.dialogRef.close();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue