Add repository connections
Signed-off-by: trivernis <trivernis@protonmail.com>pull/4/head
parent
69c7ab7ac8
commit
68ffdc323b
@ -1,27 +1,50 @@
|
|||||||
use std::io::Error;
|
use std::error::Error;
|
||||||
|
use std::fmt::{Display, Formatter};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
pub type AppResult<T> = Result<T, AppError>;
|
pub type AppResult<T> = Result<T, AppError>;
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub enum AppError {
|
pub struct AppError {
|
||||||
Msg(String)
|
message: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AppError {
|
||||||
|
pub fn new<S: ToString>(msg: S) -> Self {
|
||||||
|
Self {
|
||||||
|
message: msg.to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for AppError {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
self.message.fmt(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Error for AppError {}
|
||||||
|
|
||||||
impl From<std::io::Error> for AppError {
|
impl From<std::io::Error> for AppError {
|
||||||
fn from(e: Error) -> Self {
|
fn from(e: std::io::Error) -> Self {
|
||||||
Self::Msg(e.to_string())
|
Self::new(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<toml::de::Error> for AppError {
|
impl From<toml::de::Error> for AppError {
|
||||||
fn from(e: toml::de::Error) -> Self {
|
fn from(e: toml::de::Error) -> Self {
|
||||||
Self::Msg(format!("Failed to deserialize toml: {:?}", e))
|
Self::new(format!("Failed to deserialize toml: {:?}", e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<toml::ser::Error> for AppError {
|
impl From<toml::ser::Error> for AppError {
|
||||||
fn from(e: toml::ser::Error) -> Self {
|
fn from(e: toml::ser::Error) -> Self {
|
||||||
Self::Msg(format!("Failed to serialize to toml: {:?}", e))
|
Self::new(format!("Failed to serialize to toml: {:?}", e))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<rmp_ipc::error::Error> for AppError {
|
||||||
|
fn from(e: rmp_ipc::error::Error) -> Self {
|
||||||
|
Self::new(format!("Daemon Error: {:?}", e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,42 @@
|
|||||||
import { Component } from '@angular/core';
|
import {Component, OnInit} from '@angular/core';
|
||||||
import {Router} from "@angular/router";
|
import {Router} from "@angular/router";
|
||||||
import {RepositoryService} from "./services/repository/repository.service";
|
import {RepositoryService} from "./services/repository/repository.service";
|
||||||
import {DataloaderService} from "./services/dataloader/dataloader.service";
|
import {DataloaderService} from "./services/dataloader/dataloader.service";
|
||||||
import {MatSnackBar} from "@angular/material/snack-bar";
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||||
|
import {ErrorBrokerService} from "./services/error-broker/error-broker.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
templateUrl: './app.component.html',
|
templateUrl: './app.component.html',
|
||||||
styleUrls: ['./app.component.scss']
|
styleUrls: ['./app.component.scss']
|
||||||
})
|
})
|
||||||
export class AppComponent {
|
export class AppComponent implements OnInit{
|
||||||
title = 'mediarepo-ui';
|
title = 'mediarepo-ui';
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private snackBar: MatSnackBar,
|
private snackBar: MatSnackBar,
|
||||||
|
private errorBroker: ErrorBrokerService,
|
||||||
private dataloaderService: DataloaderService,
|
private dataloaderService: DataloaderService,
|
||||||
private repoService: RepositoryService
|
private repoService: RepositoryService,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
this.dataloaderService.loaderError.subscribe({
|
this.errorBroker.errorCb = (err: { message: string }) => {
|
||||||
error: (err) => {
|
console.error(err);
|
||||||
this.snackBar.open(err, undefined, {panelClass: "warn"})
|
this.showError(err)
|
||||||
}
|
};
|
||||||
})
|
|
||||||
await this.dataloaderService.loadData();
|
await this.dataloaderService.loadData();
|
||||||
if (this.repoService.selectedRepository.getValue() == undefined) {
|
if (this.repoService.selectedRepository.getValue() == undefined) {
|
||||||
await this.router.navigate(["repositories"])
|
await this.router.navigate(["repositories"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private showError(err: { message: string }) {
|
||||||
|
this.snackBar.open(err.message, undefined, {
|
||||||
|
panelClass: "warn",
|
||||||
|
duration: 2000,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,20 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {RepositoryService} from "../repository/repository.service";
|
import {RepositoryService} from "../repository/repository.service";
|
||||||
import {BehaviorSubject} from "rxjs";
|
import {BehaviorSubject} from "rxjs";
|
||||||
|
import {ErrorBrokerService} from "../error-broker/error-broker.service";
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class DataloaderService {
|
export class DataloaderService {
|
||||||
|
|
||||||
loaderError = new BehaviorSubject(undefined);
|
constructor(private erroBroker: ErrorBrokerService, private repositoryService: RepositoryService) { }
|
||||||
|
|
||||||
constructor(private repositoryService: RepositoryService) { }
|
|
||||||
|
|
||||||
public async loadData() {
|
public async loadData() {
|
||||||
try {
|
try {
|
||||||
await this.repositoryService.loadRepositories();
|
await this.repositoryService.loadRepositories();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.loaderError.error(err);
|
this.erroBroker.showError(err);
|
||||||
console.error(err);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ErrorBrokerService } from './error-broker.service';
|
||||||
|
|
||||||
|
describe('ErrorBrokerService', () => {
|
||||||
|
let service: ErrorBrokerService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(ErrorBrokerService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,22 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import {BehaviorSubject} from "rxjs";
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class ErrorBrokerService {
|
||||||
|
|
||||||
|
errorCb: Function | undefined;
|
||||||
|
|
||||||
|
constructor() { }
|
||||||
|
|
||||||
|
showError(error: {message: String}) {
|
||||||
|
if (this.errorCb) {
|
||||||
|
if (!error.message) {
|
||||||
|
this.errorCb({message: error});
|
||||||
|
} else {
|
||||||
|
this.errorCb({...error});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue