update borrow + fix invite

This commit is contained in:
_Bastler
2021-10-27 17:07:44 +02:00
parent 59ac345933
commit 925a03fd46
45 changed files with 2792 additions and 398 deletions
+106
View File
@@ -0,0 +1,106 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { environment } from '../../environments/environment';
@Injectable({
providedIn: 'root',
})
export class BorrowItemsService {
constructor(private http: HttpClient) {
}
getItems(page: number, size: number, sort: string, desc: boolean, search: string, owner: boolean) {
let httpParams = new HttpParams();
if (page != undefined) {
httpParams = httpParams.set("page", "" + page);
}
if (size != undefined) {
httpParams = httpParams.set("size", "" + size);
}
if (sort != undefined) {
httpParams = httpParams.set("sort", sort);
}
if (desc != undefined) {
httpParams = httpParams.set("desc", "" + desc);
}
if (search != undefined) {
httpParams = httpParams.set("search", "" + search);
}
if (owner != undefined && owner) {
httpParams = httpParams.set("owner", "" + owner);
}
return this.http.get(environment.apiUrl + "/borrow/items", { params: httpParams });
}
getItem(id) {
return this.http.get(environment.apiUrl + "/borrow/items/" + id);
}
createOrUpdateItem(borrowItem) {
return this.http.post(environment.apiUrl + "/borrow/items", borrowItem);
}
deleteItem(id) {
return this.http.delete(environment.apiUrl + "/borrow/items/" + id);
}
}
@Injectable({
providedIn: 'root',
})
export class BorrowRequestsService {
constructor(private http: HttpClient) {
}
getRequests(page: number, size: number, sort: string, desc: boolean, owner: boolean) {
let httpParams = new HttpParams();
if (page != undefined) {
httpParams = httpParams.set("page", "" + page);
}
if (size != undefined) {
httpParams = httpParams.set("size", "" + size);
}
if (sort != undefined) {
httpParams = httpParams.set("sort", sort);
}
if (desc != undefined) {
httpParams = httpParams.set("desc", "" + desc);
}
if (owner != undefined && owner) {
httpParams = httpParams.set("owner", "" + owner);
}
return this.http.get(environment.apiUrl + "/borrow/requests", { params: httpParams });
}
createOrUpdateRequest(borrowRequest) {
return this.http.post(environment.apiUrl + "/borrow/requests", borrowRequest);
}
deleteRequest(id) {
return this.http.delete(environment.apiUrl + "/borrow/requests/" + id);
}
setRequestStatus(borrowRequest) {
return this.http.put(environment.apiUrl + "/borrow/requests", borrowRequest);
}
getRequestCode(id) {
return this.http.get(environment.apiUrl + "/borrow/requests/code/" + id);
}
verifyRequest(serialized) {
return this.http.post(environment.apiUrl + "/borrow/requests/verify", serialized);
}
}
+32 -28
View File
@@ -1,6 +1,6 @@
import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {environment} from '../../environments/environment';
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../environments/environment';
@Injectable({
providedIn: 'root',
@@ -8,7 +8,7 @@ import {environment} from '../../environments/environment';
export class I18nService {
locale: string = "de-informal";
locales: any[] = ["de-informal"];
locales: any[] = [ "de-informal" ];
i18n: any;
constructor(private http: HttpClient) {
@@ -31,13 +31,13 @@ export class I18nService {
let browserLocale = navigator.language;
if(browserLocale.indexOf("-") != -1) {
browserLocale = browserLocale.split("-")[0];
if (browserLocale.indexOf("-") != -1) {
browserLocale = browserLocale.split("-")[ 0 ];
}
let locale = localStorage.getItem("bstly.locale") || browserLocale || this.locales[0];
let locale = localStorage.getItem("bstly.locale") || browserLocale || this.locales[ 0 ];
if(locale == 'de') {
if (locale == 'de') {
locale = 'de-informal';
}
@@ -45,54 +45,58 @@ export class I18nService {
await this.http.get(environment.apiUrl + "/i18n").toPromise().then((response: any) => {
this.locales = response;
});
} catch(e) {
} catch (e) {
console.debug("fallback to default locales");
}
if(this.locales.indexOf(locale) == -1) {
locale = this.locales[0];
if (this.locales.indexOf(locale) == -1) {
locale = this.locales[ 0 ];
}
this.setLocale(locale);
try {
this.i18n = await this.http.get(environment.apiUrl + "/i18n/" + locale).toPromise();
} catch(e) {
} catch (e) {
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);
return this.getInternal(key, args, this.i18n, "");
}
getInternal(key, args: string[], from): string {
getInternal(key, args: string[], from, path): string {
key += '';
if(!from) {
return key;
} else if(from[key]) {
if(typeof from[key] === 'object') {
if(from[key]["."]) {
return this.insertArguments(from[key]["."], args);
if (!from) {
return this.empty(key, args, path);
} else if (from[ key ]) {
if (typeof from[ key ] === 'object') {
if (from[ key ][ "." ]) {
return this.insertArguments(from[ key ][ "." ], args);
}
return key;
return this.empty(key, args, path);
}
return this.insertArguments(from[key], args);
return this.insertArguments(from[ key ], args);
} else {
let keys = key.split(".");
if(from[keys[0]]) {
if (from[ keys[ 0 ] ]) {
key = keys.slice(1, keys.length).join(".");
return this.getInternal(key, args, from[keys[0]])
return this.getInternal(key, args, from[ keys[ 0 ] ], path + keys[ 0 ] + ".")
}
}
return key;
return this.empty(key, args, path);
}
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], []));
if (args) {
for (let index in args) {
label = label.replace(`{${index}}`, this.get(args[ index ], []));
}
}
return label;
+21 -4
View File
@@ -1,7 +1,7 @@
import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import {environment} from '../../environments/environment';
import { environment } from '../../environments/environment';
@Injectable({
providedIn: 'root',
@@ -19,6 +19,23 @@ export class InviteService {
return this.http.get(environment.apiUrl + "/invites" + (quota ? "?quota=" + quota + "&" : "?") + "page=" + page + "&size=" + size + "&search=" + search + (redeemed ? "&redeemed=" + redeemed : ""));
}
code(code: string) {
return this.http.get(environment.apiUrl + "/invites/" + code);
}
permissions(code: string) {
return this.http.get(environment.apiUrl + "/invites/" + code + "/permissions");
}
quotas(code: string) {
return this.http.get(environment.apiUrl + "/invites/" + code + "/quotas");
}
register(model: any) {
return this.http.post(environment.apiUrl + "/invites", model);
}
getOthers(quota: string) {
return this.http.get(environment.apiUrl + "/invites/" + quota + "/others");
}
@@ -32,7 +49,7 @@ export class InviteService {
}
update(invite: any) {
return this.http.post(environment.apiUrl + "/invites", invite);
return this.http.patch(environment.apiUrl + "/invites", invite);
}
}