[DEBUG] add missing files
This commit is contained in:
parent
25077eebf3
commit
58c8f77217
@ -57,7 +57,7 @@ export class HttpWrapperService {
|
||||
}
|
||||
|
||||
addTokenIfNeeded(headerOption:any): any {
|
||||
if(this.session.sessionData !== null) {
|
||||
if(!isNullOrUndefined(this.session.getToken())) {
|
||||
if(headerOption.Authorization === undefined) {
|
||||
headerOption.Authorization = `Yota ${this.session.getToken()}`;
|
||||
}
|
||||
|
19
front/src/app/utils/index.ts
Normal file
19
front/src/app/utils/index.ts
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
|
||||
import { isArray, isArrayOf, isBoolean, isNull, isNullOrUndefined, isNumber, isNumberFinite, isObject, isOptionalOf, isOptionalArrayOf, isString, isUndefined } from "./validator";
|
||||
|
||||
export {
|
||||
isNumber,
|
||||
isNumberFinite,
|
||||
isBoolean,
|
||||
isString,
|
||||
isArray,
|
||||
isNull,
|
||||
isUndefined,
|
||||
isNullOrUndefined,
|
||||
isObject,
|
||||
isArrayOf,
|
||||
isOptionalOf,
|
||||
isOptionalArrayOf,
|
||||
}
|
||||
|
52
front/src/app/utils/validator.ts
Normal file
52
front/src/app/utils/validator.ts
Normal file
@ -0,0 +1,52 @@
|
||||
|
||||
export function isNumber(data: any): data is number {
|
||||
return typeof data === "number";
|
||||
}
|
||||
export function isNumberFinite(data: any): data is number {
|
||||
return isNumber(data) && isFinite(data);
|
||||
}
|
||||
export function isBoolean(data: any): data is boolean {
|
||||
return typeof data === "boolean";
|
||||
}
|
||||
export function isString(data: any): data is string {
|
||||
return typeof data === "string";
|
||||
}
|
||||
export function isArray(data: any): data is any[] {
|
||||
return Array.isArray(data);
|
||||
}
|
||||
export function isNull(data: any): data is null {
|
||||
return data === null;
|
||||
}
|
||||
export function isUndefined(data: any): data is undefined {
|
||||
return data === undefined;
|
||||
}
|
||||
export function isNullOrUndefined(data: any): data is undefined | null {
|
||||
return data === undefined || data === null;
|
||||
}
|
||||
export function isObject(data: any): data is any {
|
||||
return !isNullOrUndefined(data)
|
||||
&& typeof data === 'object'
|
||||
&& !isArray(data);
|
||||
}
|
||||
|
||||
export function isArrayOf<TYPE>(data: any, typeChecker: (subData: any) => subData is TYPE, length?: number): data is TYPE[] {
|
||||
if (!isArray(data)) {
|
||||
return false;
|
||||
}
|
||||
if (!data.every(typeChecker)) {
|
||||
return false;
|
||||
}
|
||||
if (!isUndefined(length) && data.length != length) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function isOptionalOf<TYPE>(data: any, typeChecker: (subData: any) => subData is TYPE): data is TYPE | undefined {
|
||||
return isUndefined(data) || typeChecker(data);
|
||||
}
|
||||
|
||||
export function isOptionalArrayOf<TYPE>(data: any, typeChecker: (subData: any) => subData is TYPE): data is TYPE[] | undefined {
|
||||
return isUndefined(data) || isArrayOf(data, typeChecker);
|
||||
}
|
||||
|
@ -1,277 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2018, Edouard DUPIN, all right reserved
|
||||
* @license PROPRIETARY (see license file)
|
||||
*/
|
||||
|
||||
import { NodeData } from "../model";
|
||||
import { isArray, isNullOrUndefined, isUndefined } from "./validator";
|
||||
|
||||
export enum TypeCheck {
|
||||
EQUAL = '==',
|
||||
NOT_EQUAL = '!=',
|
||||
LESS = '<',
|
||||
LESS_EQUAL = '<=',
|
||||
GREATER = '>',
|
||||
GREATER_EQUAL = '>=',
|
||||
}
|
||||
|
||||
export interface SelectModel {
|
||||
check: TypeCheck;
|
||||
key: string;
|
||||
value?: number|string|boolean|number[]|string[];
|
||||
}
|
||||
/*
|
||||
{ check: TypeCheck.EQUAL, key: sss, value: null}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @breif Generic interface to access to the BDD (no BDD, direct file IO)
|
||||
*/
|
||||
export class DataInterface {
|
||||
constructor(
|
||||
private name: string,
|
||||
private bdd: NodeData[] ) {
|
||||
}
|
||||
|
||||
public getTableIndex(id: number) {
|
||||
for(let iii = 0; iii < this.bdd.length; iii++) {
|
||||
if(this.bdd[iii].id === id) {
|
||||
return iii;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public gets(): NodeData[] {
|
||||
console.log(`[I] gets ${ this.name}`);
|
||||
return this.bdd;
|
||||
}
|
||||
|
||||
public getsWhere(select: SelectModel[], orderBy?: string[]): NodeData[] {
|
||||
// console.log("[I] gets_where " + this.name + " select " + _select);
|
||||
let tmpList = this.getSubList(this.bdd, select);
|
||||
tmpList = this.orderBy(tmpList, orderBy);
|
||||
return tmpList;
|
||||
}
|
||||
|
||||
public get(id: number): NodeData {
|
||||
// console.log("[I] get " + this.name + " " + _id);
|
||||
for(let iii = 0; iii < this.bdd.length; iii++) {
|
||||
if(this.bdd[iii].id === id) {
|
||||
return this.bdd[iii];
|
||||
}
|
||||
}
|
||||
console.log(`[W] not found element{ ${ this.bdd.length}`);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public getNameLikeAll(name: string): NodeData[] {
|
||||
let out = undefined;
|
||||
let nameLower = name.toLowerCase();
|
||||
for(let iii = 0; iii < this.bdd.length; iii++) {
|
||||
if(this.bdd[iii].name.toLowerCase() === nameLower) {
|
||||
out.push(this.bdd[iii]);
|
||||
}
|
||||
}
|
||||
if(out.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
public getNameLike(name: string): NodeData[] {
|
||||
let out = [];
|
||||
let nameLower = name.toLowerCase();
|
||||
for(let iii = 0; iii < this.bdd.length; iii++) {
|
||||
// console.log("compare '" + _name + "' ??? '" + this.bdd[iii]['name'] + "'");
|
||||
if(this.bdd[iii].name.toLowerCase() === nameLower) {
|
||||
out.push(this.bdd[iii]);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public set(id: number, value: NodeData): void {
|
||||
console.log(`[I] Set ${ this.name } ${ id}`);
|
||||
for(let iii = 0; iii < this.bdd.length; iii++) {
|
||||
console.log(` check: ${ this.bdd[iii].id}`);
|
||||
if(this.bdd[iii].id === id) {
|
||||
console.log(` *** Set specific values: ${ id } ${ JSON.stringify(value, null, 2)}`);
|
||||
this.bdd[iii] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public delete(id: number): void {
|
||||
console.log(`[I] delete ${ this.name } ${ id}`);
|
||||
for(let iii = 0; iii < this.bdd.length; iii++) {
|
||||
if(this.bdd[iii].id === id) {
|
||||
this.bdd.splice(iii, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public find(listToken, values): NodeData[] {
|
||||
let out = [];
|
||||
for(let iii = 0; iii < this.bdd.length; iii++) {
|
||||
let find = true;
|
||||
for(let jjj = 0; jjj < listToken.length; jjj++) {
|
||||
if(this.bdd[iii][listToken[jjj]] !== values[listToken[jjj]]) {
|
||||
find = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(find === true) {
|
||||
out.push(this.bdd[iii]);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public count(select?: SelectModel[]) {
|
||||
if(isNullOrUndefined(select)) {
|
||||
return this.bdd.length;
|
||||
}
|
||||
let tmp = this.getSubList(this.bdd, select);
|
||||
return tmp.length;
|
||||
}
|
||||
|
||||
public existIn(value, listValues: number[]|string[]): boolean {
|
||||
for(let iii = 0; iii < listValues.length; iii++) {
|
||||
if(value === listValues[iii]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public getSubList(values: NodeData[], select?: SelectModel[] ): NodeData[] {
|
||||
let out = [] as NodeData[];
|
||||
for(let iiiElem = 0; iiiElem < values.length; iiiElem++) {
|
||||
let find = true;
|
||||
if(select.length === 0) {
|
||||
find = false;
|
||||
}
|
||||
// console.log("Check : " + JSON.stringify(_values[iii_elem], null, 2));
|
||||
for(let iiiSelect = 0; iiiSelect < select.length; iiiSelect++) {
|
||||
let control = select[iiiSelect];
|
||||
let valueElement = values[iiiElem][control.key]
|
||||
if(isArray(control.value)) {
|
||||
if(control.check === TypeCheck.EQUAL) {
|
||||
if(this.existIn(valueElement, control.value) === false) {
|
||||
find = false;
|
||||
break;
|
||||
}
|
||||
} else if(control.check === TypeCheck.NOT_EQUAL) {
|
||||
if(this.existIn(valueElement, control.value) === false) {
|
||||
find = false;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
console.log('[ERROR] Internal Server Error{ unknow comparing type ...');
|
||||
return undefined;
|
||||
}
|
||||
} else {
|
||||
//console.log(" [" + control.key + "] = " + valueElement);
|
||||
if(control.check === TypeCheck.EQUAL) {
|
||||
if(valueElement !== control.value) {
|
||||
find = false;
|
||||
break;
|
||||
}
|
||||
} else if(control.check === TypeCheck.NOT_EQUAL) {
|
||||
if(valueElement === control.value) {
|
||||
find = false;
|
||||
break;
|
||||
}
|
||||
} else if(control.check === TypeCheck.LESS) {
|
||||
if(valueElement >= control.value) {
|
||||
find = false;
|
||||
break;
|
||||
}
|
||||
} else if(control.check === TypeCheck.LESS_EQUAL) {
|
||||
if(valueElement > control.value) {
|
||||
find = false;
|
||||
break;
|
||||
}
|
||||
} else if(control.check === TypeCheck.GREATER) {
|
||||
if(valueElement <= control.value) {
|
||||
find = false;
|
||||
break;
|
||||
}
|
||||
} else if(control.check === TypeCheck.GREATER_EQUAL) {
|
||||
if(valueElement < control.value) {
|
||||
find = false;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
console.log('[ERROR] Internal Server Error{ unknow comparing type ...');
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(find === true) {
|
||||
// console.log(" ==> SELECTED");
|
||||
out.push(values[iiiElem]);
|
||||
} else {
|
||||
// console.log(" ==> NOT SELECTED");
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public orderBy(values: NodeData[], order: string[]): NodeData[] {
|
||||
if(isNullOrUndefined(order)) {
|
||||
return values;
|
||||
}
|
||||
if(order.length === 0) {
|
||||
return values;
|
||||
}
|
||||
let valueOrder = order[0];
|
||||
let out = [];
|
||||
let outUnclassable = [];
|
||||
for(let iii = 0; iii < values.length; iii++) {
|
||||
if(values[iii][valueOrder] === undefined) {
|
||||
outUnclassable.push(values[iii]);
|
||||
continue;
|
||||
}
|
||||
if(values[iii][valueOrder] === null) {
|
||||
outUnclassable.push(values[iii]);
|
||||
continue;
|
||||
}
|
||||
out.push(values[iii]);
|
||||
}
|
||||
// console.log("order in list by : " + value_order);
|
||||
// out = sorted(out, key=lambda x{ x[value_order])
|
||||
if(valueOrder === 'name') {
|
||||
out.sort((aaa, bbb) => {
|
||||
const name1 = aaa[valueOrder].toLowerCase();
|
||||
const name2 = bbb[valueOrder].toLowerCase();
|
||||
if(name1 > name2) {
|
||||
return 1;
|
||||
}
|
||||
if(name1 < name2) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
} else {
|
||||
out.sort((aaa, bbb) => {
|
||||
if(aaa[valueOrder] > bbb[valueOrder]) {
|
||||
return 1;
|
||||
}
|
||||
if(aaa[valueOrder] < bbb[valueOrder]) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
if(order.length > 1) {
|
||||
outUnclassable = this.orderBy(outUnclassable, order.slice(1));
|
||||
}
|
||||
for(let jjj = 0; jjj < outUnclassable.length; jjj++) {
|
||||
out.push(outUnclassable[jjj]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
|
||||
|
||||
import { DataInterface } from "./dataInterface";
|
||||
import { isArray, isArrayOf, isBoolean, isNull, isNullOrUndefined, isNumber, isNumberFinite, isObject, isOptionalOf, isOptionalArrayOf, isString, isUndefined } from "./validator";
|
||||
|
||||
export {
|
||||
@ -16,6 +15,5 @@ export {
|
||||
isArrayOf,
|
||||
isOptionalOf,
|
||||
isOptionalArrayOf,
|
||||
DataInterface,
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user