This commit is contained in:
2024-10-05 00:15:13 +02:00
commit 0c5fb0e1c1
145 changed files with 23168 additions and 0 deletions
@@ -0,0 +1,40 @@
import { HttpClient, HttpParams } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { environment } from "src/environments/environment";
@Injectable({
providedIn: 'root',
})
export class AbstractService {
constructor(private http: HttpClient) {
}
fetch(path: string, limit: number, offset: number, sort: string, descending: boolean, filter: any | undefined) {
let httpParams = new HttpParams();
if (limit != undefined) {
httpParams = httpParams.set("limit", "" + limit);
}
if (offset) {
httpParams = httpParams.set("offset", "" + offset);
}
if (sort) {
httpParams = httpParams.set("sort", "" + sort);
}
if (descending) {
httpParams = httpParams.set("descending", "" + descending);
}
if (filter) {
for (const param in filter) {
if (filter[param]) {
httpParams = httpParams.set(param, "" + filter[param]);
}
}
}
return this.http.get(environment.apiUrl + path, { params: httpParams });
}
}
@@ -0,0 +1,40 @@
import { Injectable } from '@angular/core';
import { ReplaySubject, of } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { RequestError } from './requesterror';
import { environment } from './../../environments/environment';
@Injectable({
providedIn: 'root',
})
export class AuthService {
auth: ReplaySubject<any> = new ReplaySubject(undefined);
constructor(private http: HttpClient) {
}
getAuth() {
return this.authMe().toPromise().then((data: any) => {
this.auth.next(data);
return data;
}, error => {
throw new RequestError(error);
});
}
authMe() {
return this.http.get(environment.apiUrl + "/auth");
}
getExternal() {
return this.http.get(environment.apiUrl + "/auth/external");
}
logout() {
return this.http.post(environment.apiUrl + "/logout", {});
}
}
@@ -0,0 +1,19 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from '../../environments/environment';
@Injectable({
providedIn: 'root',
})
export class DebugService {
constructor(private http: HttpClient) {
}
random() {
return this.http.get(environment.apiUrl + "/debug/random");
}
}
@@ -0,0 +1,138 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../environments/environment';
import { MatPaginatorIntl } from '@angular/material/paginator';
import { Subject } from 'rxjs';
@Injectable({
providedIn: 'root',
})
export class I18nService {
locale: string = "de-informal";
locales: any[] = ["de-informal"];
i18n: any;
constructor(private http: HttpClient) {
}
getLocales() {
return this.locales;
}
getLocale() {
return this.locale || 'de-informal';
}
setLocale(locale) {
this.locale = locale;
}
async fetch() {
let browserLocale = navigator.language;
if (browserLocale.indexOf("-") != -1) {
browserLocale = browserLocale.split("-")[0];
}
let locale = localStorage.getItem("buntspecht.locale") || browserLocale || this.locales[0];
if (locale == 'de') {
locale = 'de-informal';
}
if (this.locales.indexOf(locale) == -1) {
locale = this.locales[0];
}
this.setLocale(locale);
this.i18n = await this.http.get("/assets/i18n/" + locale + ".json").toPromise();
console.debug("fallback to default locale");
}
get(key, args: string[]): string {
return this.getInternal(key, args, this.i18n, "", true);
}
getEmpty(key, args: string[]): string {
return this.getInternal(key, args, this.i18n, "", false);
}
getInternal(key, args: string[], from, path, empty: boolean): string {
key += '';
if (!from) {
return empty ? this.empty(key, args, path) : (key || "");
} else if (from[key]) {
if (typeof from[key] === 'object') {
if (from[key]["."]) {
return this.insertArguments(from[key]["."], args);
}
return empty ? this.empty(key, args, path) : (key || "");
}
return this.insertArguments(from[key], args);
} else {
let keys = key.split(".");
if (from[keys[0]]) {
key = keys.slice(1, keys.length).join(".");
return this.getInternal(key, args, from[keys[0]], path + keys[0] + ".", empty)
}
}
return empty ? this.empty(key, args, path) : (key || "");
}
empty(key, args: string[], path: string): string {
return (path ? path + (path.endsWith(".") ? "" : ".") : "") + key + (args && args.length > 0 ? (" [" + args + "]") : "");
}
insertArguments(label: string, args: string[]) {
if (args) {
for (let index in args) {
label = label.replace(`{${index}}`, this.get(args[index], null));
}
}
return label;
}
}
@Injectable()
export class I18nPaginatorIntl implements MatPaginatorIntl {
changes = new Subject<void>();
i18n: I18nService;
itemsPerPageLabel: string;
nextPageLabel: string;
previousPageLabel: string;
firstPageLabel: string;
lastPageLabel: string;
injectI18n(i18n: I18nService) {
this.i18n = i18n;
this.firstPageLabel = this.i18n.get('paginator.firstPage', []);
this.itemsPerPageLabel = this.i18n.get('paginator.itemsPerPage', []);
this.lastPageLabel = this.i18n.get('paginator.lastPage', []);
this.nextPageLabel = this.i18n.get('paginator.nextPage', []);
this.previousPageLabel = this.i18n.get('paginator.previousPage', []);
}
getRangeLabel(page: number, pageSize: number, length: number): string {
if (length === 0) {
return this.i18n.get('paginator.empty', []);
}
const amountPages = Math.ceil(length / pageSize);
return this.i18n.get('paginator.range', [page + 1 + "", amountPages + ""]);
}
}
@@ -0,0 +1,15 @@
export class RequestError extends Error {
response: any;
constructor(response: any) {
super(response.message);
this.response = response;
// Set the prototype explicitly.
Object.setPrototypeOf(this, RequestError.prototype);
}
getResponse(): any {
return this.response;
}
}
@@ -0,0 +1,34 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from '../../environments/environment';
import { AbstractService } from './abstract.service';
@Injectable({
providedIn: 'root',
})
export class TurnoverManagementService {
constructor(private http: HttpClient, private abstractService: AbstractService) {
}
fetch(limit: number, offset: number, sort: string, descending: boolean, filter: any | undefined) {
return this.abstractService.fetch("/turnovers/manage", limit, offset, sort, descending, filter);
}
overview(limit: number, offset: number, sort: string, descending: boolean, filter: any | undefined) {
return this.abstractService.fetch("/turnovers/manage/overview", limit, offset, sort, descending, filter);
}
get(id: number) {
return this.http.get(environment.apiUrl + "/turnovers/manage/" + id);
}
update(turnover: any) {
return this.http.patch(environment.apiUrl + "/turnovers/manage", turnover);
}
delete(id: number) {
return this.http.delete(environment.apiUrl + "/turnovers/manage/" + id);
}
}
@@ -0,0 +1,30 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from '../../environments/environment';
import { AbstractService } from './abstract.service';
@Injectable({
providedIn: 'root',
})
export class TurnoverService {
constructor(private http: HttpClient, private abstractService: AbstractService) {
}
fetch(limit: number, offset: number, sort: string, descending: boolean, filter: any | undefined) {
return this.abstractService.fetch("/turnovers", limit, offset, sort, descending, filter);
}
get(id: number) {
return this.http.get(environment.apiUrl + "/turnovers/" + id);
}
create(turnover: any) {
return this.http.post(environment.apiUrl + "/turnovers", turnover);
}
update(turnover: any) {
return this.http.patch(environment.apiUrl + "/turnovers", turnover);
}
}
@@ -0,0 +1,42 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from '../../environments/environment';
import { AbstractService } from './abstract.service';
@Injectable({
providedIn: 'root',
})
export class UserManagementService {
constructor(private http: HttpClient, private abstractService: AbstractService) {
}
fetch(limit: number, offset: number, sort: string, descending: boolean, filter: string = "") {
return this.abstractService.fetch("/users/manage", limit, offset, sort, descending, filter);
}
pick(search: string) {
return this.abstractService.fetch("/users/manage/pick", undefined, undefined, undefined, undefined, { filter: search });
}
get(username: string) {
return this.http.get(environment.apiUrl + "/users/manage/" + username);
}
create(user: any) {
return this.http.post(environment.apiUrl + "/users/manage", user);
}
update(user: any) {
return this.http.patch(environment.apiUrl + "/users/manage", user);
}
setPassword(username: string, password: string) {
return this.http.post(environment.apiUrl + "/users/manage/" + username + "/password", { password: password, password2: password });
}
deleteUser(username: string) {
return this.http.delete(environment.apiUrl + "/users/manage/" + username);
}
}
@@ -0,0 +1,25 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../environments/environment';
@Injectable({
providedIn: 'root',
})
export class UserService {
constructor(private http: HttpClient) {
}
get() {
return this.http.get(environment.apiUrl + "/users/user");
}
update(user: any) {
return this.http.patch(environment.apiUrl + "/users/user", user);
}
setPassword(old: string, password: string, password2: string) {
return this.http.post(environment.apiUrl + "/users/password", { old: old, password: password, password2: password2 });
}
}