Add prompt to import files when the repository is empty

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/14/head
trivernis 3 years ago
parent 2e3e55406b
commit 2e2964fcba
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -6,7 +6,10 @@
[state]="this.state"></app-files-tab-sidebar> [state]="this.state"></app-files-tab-sidebar>
</app-drawer-page-side> </app-drawer-page-side>
<app-drawer-page-content> <app-drawer-page-content>
<app-busy-indicator [blurBackground]="true" [busy]="contentLoading" [darkenBackground]="true"> <app-busy-indicator *ngIf="!this.metadata || this.metadata.file_count > 0"
[blurBackground]="true"
[busy]="contentLoading"
[darkenBackground]="true">
<app-file-multiview (fileSelectEvent)="this.onFileSelect($event)" <app-file-multiview (fileSelectEvent)="this.onFileSelect($event)"
(modeChangeEvent)="state.mode.next($event)" (modeChangeEvent)="state.mode.next($event)"
[files]="this.files" [files]="this.files"
@ -14,5 +17,9 @@
[preselectedFile]="this.getStateSelectedFile()" [preselectedFile]="this.getStateSelectedFile()"
[tabState]="this.state"></app-file-multiview> [tabState]="this.state"></app-file-multiview>
</app-busy-indicator> </app-busy-indicator>
<app-middle-centered *ngIf="this.metadata && this.metadata.file_count === 0" class="import-prompt">
<div><h1>There are no files in this repository.</h1></div>
<button (click)="this.onImportFiles()" color="primary" mat-flat-button>Import files</button>
</app-middle-centered>
</app-drawer-page-content> </app-drawer-page-content>
</app-drawer-page> </app-drawer-page>

@ -25,3 +25,12 @@ app-file-multiview {
margin: auto; margin: auto;
} }
} }
.import-prompt {
text-align: center;
button {
font-size: 1.5em;
padding: 0.5em 1em;
}
}

@ -1,6 +1,9 @@
import {Component, Input, OnInit} from "@angular/core"; import {Component, Input, OnInit} from "@angular/core";
import {File} from "../../../../api/models/File"; import {File} from "../../../../api/models/File";
import {TabState} from "../../../models/TabState"; import {TabState} from "../../../models/TabState";
import {RepositoryMetadata} from "../../../../api/api-types/repo";
import {RepositoryService} from "../../../services/repository/repository.service";
import {TabCategory} from "../../../models/TabCategory";
@Component({ @Component({
selector: "app-files-tab", selector: "app-files-tab",
@ -14,8 +17,12 @@ export class FilesTabComponent implements OnInit {
files: File[] = []; files: File[] = [];
contentLoading = false; contentLoading = false;
selectedFiles: File[] = []; selectedFiles: File[] = [];
public metadata?: RepositoryMetadata;
constructor() { constructor(
repoService: RepositoryService,
) {
repoService.metadata.subscribe(m => this.metadata = m);
} }
async ngOnInit() { async ngOnInit() {
@ -50,4 +57,8 @@ export class FilesTabComponent implements OnInit {
break; break;
} }
} }
public onImportFiles(): void {
this.state.category = TabCategory.Import;
}
} }

@ -23,6 +23,7 @@ import {DrawerPageContentComponent} from "./drawer-page/drawer-page-content/draw
import {FlexLayoutModule} from "@angular/flex-layout"; import {FlexLayoutModule} from "@angular/flex-layout";
import {MatRippleModule} from "@angular/material/core"; import {MatRippleModule} from "@angular/material/core";
import {FlapButtonComponent} from "./flap-button/flap-button.component"; import {FlapButtonComponent} from "./flap-button/flap-button.component";
import {MiddleCenteredComponent} from "./middle-centered/middle-centered.component";
@NgModule({ @NgModule({
@ -40,6 +41,7 @@ import {FlapButtonComponent} from "./flap-button/flap-button.component";
DrawerPageSideComponent, DrawerPageSideComponent,
DrawerPageContentComponent, DrawerPageContentComponent,
FlapButtonComponent, FlapButtonComponent,
MiddleCenteredComponent,
], ],
exports: [ exports: [
ConfirmDialogComponent, ConfirmDialogComponent,
@ -54,6 +56,7 @@ import {FlapButtonComponent} from "./flap-button/flap-button.component";
DrawerPageSideComponent, DrawerPageSideComponent,
DrawerPageContentComponent, DrawerPageContentComponent,
FlapButtonComponent, FlapButtonComponent,
MiddleCenteredComponent,
], ],
imports: [ imports: [
CommonModule, CommonModule,

@ -0,0 +1,7 @@
:host {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}

@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MiddleCenteredComponent } from './middle-centered.component';
describe('MiddleCenteredComponent', () => {
let component: MiddleCenteredComponent;
let fixture: ComponentFixture<MiddleCenteredComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ MiddleCenteredComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(MiddleCenteredComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

@ -0,0 +1,16 @@
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
@Component({
selector: 'app-middle-centered',
templateUrl: './middle-centered.component.html',
styleUrls: ['./middle-centered.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class MiddleCenteredComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}

@ -16,6 +16,7 @@ export class RepositoryService {
repositories = new BehaviorSubject<Repository[]>([]); repositories = new BehaviorSubject<Repository[]>([]);
public selectedRepository = new BehaviorSubject<Repository | undefined>( public selectedRepository = new BehaviorSubject<Repository | undefined>(
undefined); undefined);
public metadata = new BehaviorSubject<RepositoryMetadata | undefined>(undefined);
constructor(private errorBroker: LoggingService) { constructor(private errorBroker: LoggingService) {
this.registerListener().catch(err => console.error(err)); this.registerListener().catch(err => console.error(err));
@ -68,6 +69,7 @@ export class RepositoryService {
console.warn(err); console.warn(err);
} }
} }
this.metadata.next(undefined);
await MediarepoApi.selectRepository({ name: repo.name }); await MediarepoApi.selectRepository({ name: repo.name });
} }
@ -163,7 +165,9 @@ export class RepositoryService {
* @returns {Promise<RepositoryMetadata>} * @returns {Promise<RepositoryMetadata>}
*/ */
public async getRepositoryMetadata(): Promise<RepositoryMetadata> { public async getRepositoryMetadata(): Promise<RepositoryMetadata> {
return MediarepoApi.getRepositoryMetadata(); const metadata = await MediarepoApi.getRepositoryMetadata();
this.metadata.next(metadata);
return metadata;
} }
/** /**

Loading…
Cancel
Save