feat(deps): ✨ Add support for more departments
This commit is contained in:
parent
bdf2fac1ad
commit
4369ebb2a5
19 changed files with 296 additions and 169 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { inject, NgModule } from '@angular/core';
|
import { inject, NgModule } from "@angular/core";
|
||||||
import {
|
import {
|
||||||
ActivatedRouteSnapshot,
|
ActivatedRouteSnapshot,
|
||||||
CanActivateFn,
|
CanActivateFn,
|
||||||
|
|
@ -6,14 +6,14 @@ import {
|
||||||
RouterModule,
|
RouterModule,
|
||||||
RouterStateSnapshot,
|
RouterStateSnapshot,
|
||||||
Routes,
|
Routes,
|
||||||
} from '@angular/router';
|
} from "@angular/router";
|
||||||
import { UserService } from './core/services/user.service';
|
import { UserService } from "./core/services/user.service";
|
||||||
import { map } from 'rxjs';
|
import { map } from "rxjs";
|
||||||
import { UserPermissions } from './core/auth/userPermissions';
|
import { UserPermissions } from "./core/auth/userPermissions";
|
||||||
|
|
||||||
const authGuard: CanActivateFn = (
|
const authGuard: CanActivateFn = (
|
||||||
route: ActivatedRouteSnapshot,
|
route: ActivatedRouteSnapshot,
|
||||||
state: RouterStateSnapshot
|
state: RouterStateSnapshot,
|
||||||
) => {
|
) => {
|
||||||
const userService: UserService = inject(UserService);
|
const userService: UserService = inject(UserService);
|
||||||
const router: Router = inject(Router);
|
const router: Router = inject(Router);
|
||||||
|
|
@ -23,12 +23,12 @@ const authGuard: CanActivateFn = (
|
||||||
if (isAuth) {
|
if (isAuth) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return router.createUrlTree(['/login'], {
|
return router.createUrlTree(["/login"], {
|
||||||
queryParams: {
|
queryParams: {
|
||||||
redirectUrl: state.url,
|
redirectUrl: state.url,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -42,21 +42,23 @@ const permissionsGuard: (
|
||||||
|
|
||||||
const user = userService.getCurrentUser();
|
const user = userService.getCurrentUser();
|
||||||
if (user == null)
|
if (user == null)
|
||||||
return router.createUrlTree(['/login'], {
|
return router.createUrlTree(["/login"], {
|
||||||
queryParams: {
|
queryParams: {
|
||||||
redirectUrl: state.url,
|
redirectUrl: state.url,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log("require following permissions", requiredPermissions);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
requiredPermissions.every((permission) =>
|
requiredPermissions.every((permission) =>
|
||||||
user.permissions.includes(permission)
|
user.permissions.includes(permission),
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return router.createUrlTree(['/unauthorized'], {
|
return router.createUrlTree(["/unauthorized"], {
|
||||||
queryParams: {
|
queryParams: {
|
||||||
redirectUrl: state.url,
|
redirectUrl: state.url,
|
||||||
},
|
},
|
||||||
|
|
@ -73,47 +75,47 @@ const loginGuard: CanActivateFn = (route: ActivatedRouteSnapshot) => {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// redirect to redirectUrl query param
|
// redirect to redirectUrl query param
|
||||||
console.log("redirectURL", route.queryParams['redirectUrl']);
|
console.log("redirectURL", route.queryParams["redirectUrl"]);
|
||||||
return router.createUrlTree([
|
return router.createUrlTree([
|
||||||
router.parseUrl(route.queryParams['redirectUrl'] ?? 'departments'),
|
router.parseUrl(route.queryParams["redirectUrl"] ?? "departments"),
|
||||||
]);
|
]);
|
||||||
// return false;
|
// return false;
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{
|
{
|
||||||
path: 'login',
|
path: "login",
|
||||||
loadComponent: () =>
|
loadComponent: () =>
|
||||||
import('./core/auth/auth.component').then((m) => m.AuthComponent),
|
import("./core/auth/auth.component").then((m) => m.AuthComponent),
|
||||||
canActivate: [loginGuard],
|
canActivate: [loginGuard],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'callback',
|
path: "callback",
|
||||||
loadComponent: () =>
|
loadComponent: () =>
|
||||||
import('./core/callback/callback.component').then(
|
import("./core/callback/callback.component").then(
|
||||||
(m) => m.CallbackComponent
|
(m) => m.CallbackComponent,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'departments',
|
path: "departments",
|
||||||
loadComponent: () =>
|
loadComponent: () =>
|
||||||
import('./core/department/department.component').then(
|
import("./core/department/department.component").then(
|
||||||
(m) => m.DepartmentComponent
|
(m) => m.DepartmentComponent,
|
||||||
),
|
),
|
||||||
canActivate: [authGuard],
|
canActivate: [authGuard],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: ':department',
|
path: ":department",
|
||||||
loadComponent: () =>
|
loadComponent: () =>
|
||||||
import('./core/layout/layout.component').then((m) => m.LayoutComponent),
|
import("./core/layout/layout.component").then((m) => m.LayoutComponent),
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: 'recipes',
|
path: "recipes",
|
||||||
loadComponent: () =>
|
loadComponent: () =>
|
||||||
import('./features/recipes/recipes.component').then(
|
import("./features/recipes/recipes.component").then(
|
||||||
(m) => m.RecipesComponent
|
(m) => m.RecipesComponent,
|
||||||
),
|
),
|
||||||
canActivate: [
|
canActivate: [
|
||||||
authGuard,
|
authGuard,
|
||||||
|
|
@ -121,10 +123,10 @@ const routes: Routes = [
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'recipe/:productCode',
|
path: "recipe/:productCode",
|
||||||
loadComponent: () =>
|
loadComponent: () =>
|
||||||
import(
|
import(
|
||||||
'./features/recipes/recipe-details/recipe-details.component'
|
"./features/recipes/recipe-details/recipe-details.component"
|
||||||
).then((m) => m.RecipeDetailsComponent),
|
).then((m) => m.RecipeDetailsComponent),
|
||||||
canActivate: [
|
canActivate: [
|
||||||
authGuard,
|
authGuard,
|
||||||
|
|
@ -132,38 +134,38 @@ const routes: Routes = [
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'log',
|
path: "log",
|
||||||
loadComponent: () =>
|
loadComponent: () =>
|
||||||
import('./features/changelog/changelog.component').then(
|
import("./features/changelog/changelog.component").then(
|
||||||
(m) => m.ChangelogComponent
|
(m) => m.ChangelogComponent,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'materials',
|
path: "materials",
|
||||||
loadComponent: () =>
|
loadComponent: () =>
|
||||||
import(
|
import(
|
||||||
'./features/material-settings/material-settings.component'
|
"./features/material-settings/material-settings.component"
|
||||||
).then((m) => m.MaterialSettingsComponent),
|
).then((m) => m.MaterialSettingsComponent),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'toppings',
|
path: "toppings",
|
||||||
loadComponent: () =>
|
loadComponent: () =>
|
||||||
import('./features/toppings/toppings.component').then(
|
import("./features/toppings/toppings.component").then(
|
||||||
(t) => t.ToppingsComponent
|
(t) => t.ToppingsComponent,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '',
|
path: "",
|
||||||
pathMatch: 'full',
|
pathMatch: "full",
|
||||||
redirectTo: 'departments',
|
redirectTo: "departments",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'unauthorized',
|
path: "unauthorized",
|
||||||
loadComponent: () =>
|
loadComponent: () =>
|
||||||
import('./core/auth/unauthorized.component').then(
|
import("./core/auth/unauthorized.component").then(
|
||||||
(m) => m.UnauthorizedComponent
|
(m) => m.UnauthorizedComponent,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
|
|
@ -172,8 +174,8 @@ const routes: Routes = [
|
||||||
// import('./core/notfound.component').then((m) => m.NotfoundComponent),
|
// import('./core/notfound.component').then((m) => m.NotfoundComponent),
|
||||||
// },
|
// },
|
||||||
{
|
{
|
||||||
path: '**',
|
path: "**",
|
||||||
redirectTo: 'departments',
|
redirectTo: "departments",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,28 @@ export enum UserPermissions {
|
||||||
VIEWER = 1 << 4,
|
VIEWER = 1 << 4,
|
||||||
EDITOR = 1 << 7,
|
EDITOR = 1 << 7,
|
||||||
|
|
||||||
|
DUBAI_PERMISSION = 1 << 8,
|
||||||
|
COUNTER_PERMISSION = 1 << 9,
|
||||||
|
SINGAPORE_PERMISSION = 1 << 10,
|
||||||
|
COCKTAIL_PERMISSION = 1 << 11,
|
||||||
|
|
||||||
// add new permission by shifting after 7. eg. 8,9,...
|
// add new permission by shifting after 7. eg. 8,9,...
|
||||||
// also do add at server
|
// also do add at server
|
||||||
|
|
||||||
SUPER_ADMIN_PERMISSION = THAI_PERMISSION | MALAY_PERMISSION | AUS_PERMISSION | ALPHA3_PERMISSION | (EDITOR | VIEWER)
|
SUPER_ADMIN_PERMISSION = THAI_PERMISSION |
|
||||||
|
MALAY_PERMISSION |
|
||||||
|
AUS_PERMISSION |
|
||||||
|
ALPHA3_PERMISSION |
|
||||||
|
COUNTER_PERMISSION |
|
||||||
|
SINGAPORE_PERMISSION |
|
||||||
|
DUBAI_PERMISSION |
|
||||||
|
COCKTAIL_PERMISSION |
|
||||||
|
(EDITOR | VIEWER),
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPermissions(perms: number) : UserPermissions[] {
|
export function getPermissions(perms: number): UserPermissions[] {
|
||||||
return Object.values(UserPermissions)
|
return Object.values(UserPermissions).filter(
|
||||||
.filter(permission => typeof permission === 'number' && (perms & permission) !== 0) as UserPermissions[];
|
(permission) =>
|
||||||
|
typeof permission === "number" && (perms & permission) !== 0,
|
||||||
|
) as UserPermissions[];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,37 +1,42 @@
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from "@angular/core";
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from "@angular/router";
|
||||||
import { UserService } from '../services/user.service';
|
import { UserService } from "../services/user.service";
|
||||||
import {getPermissions} from "../auth/userPermissions";
|
import { getPermissions } from "../auth/userPermissions";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-callback',
|
selector: "app-callback",
|
||||||
standalone: true,
|
standalone: true,
|
||||||
templateUrl: './callback.component.html',
|
templateUrl: "./callback.component.html",
|
||||||
})
|
})
|
||||||
export class CallbackComponent implements OnInit {
|
export class CallbackComponent implements OnInit {
|
||||||
constructor(
|
constructor(
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private userService: UserService
|
private userService: UserService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.route.queryParams.subscribe((params) => {
|
this.route.queryParams.subscribe((params) => {
|
||||||
console.log(params);
|
console.log(params, params["permissions"]);
|
||||||
|
|
||||||
if (params['email'] && params['name'] && params['picture'] && params['permissions']) {
|
if (
|
||||||
|
params["email"] &&
|
||||||
|
params["name"] &&
|
||||||
|
params["picture"] &&
|
||||||
|
params["permissions"]
|
||||||
|
) {
|
||||||
this.userService.setAuth({
|
this.userService.setAuth({
|
||||||
email: params['email'],
|
email: params["email"],
|
||||||
name: params['name'],
|
name: params["name"],
|
||||||
picture: params['picture'],
|
picture: params["picture"],
|
||||||
permissions: getPermissions(params['permissions']),
|
permissions: getPermissions(params["permissions"]),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params['redirect_to']) {
|
if (params["redirect_to"]) {
|
||||||
void this.router.navigate([params['redirect_to']]);
|
void this.router.navigate([params["redirect_to"]]);
|
||||||
} else {
|
} else {
|
||||||
void this.router.navigate(['/']);
|
void this.router.navigate(["/"]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import { Component } from '@angular/core';
|
import { Component } from "@angular/core";
|
||||||
import { CommonModule, NgOptimizedImage } from '@angular/common';
|
import { CommonModule, NgOptimizedImage } from "@angular/common";
|
||||||
import { Router } from '@angular/router';
|
import { Router } from "@angular/router";
|
||||||
import { UserService } from '../services/user.service';
|
import { UserService } from "../services/user.service";
|
||||||
import { UserPermissions } from '../auth/userPermissions';
|
import { UserPermissions } from "../auth/userPermissions";
|
||||||
import { NotFoundHandler } from 'src/app/shared/helpers/notFoundHandler';
|
import { NotFoundHandler } from "src/app/shared/helpers/notFoundHandler";
|
||||||
import { AsyncStorage } from 'src/app/shared/helpers/asyncStorage';
|
import { AsyncStorage } from "src/app/shared/helpers/asyncStorage";
|
||||||
import { getCountryMapSwitcher } from 'src/app/shared/helpers/recipe';
|
import { getCountryMapSwitcher } from "src/app/shared/helpers/recipe";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
standalone: true,
|
standalone: true,
|
||||||
|
|
@ -56,33 +56,43 @@ import { getCountryMapSwitcher } from 'src/app/shared/helpers/recipe';
|
||||||
</div>
|
</div>
|
||||||
`,
|
`,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
export class DepartmentComponent {
|
export class DepartmentComponent {
|
||||||
acccessibleCountries:string[] = [];
|
acccessibleCountries: string[] = [];
|
||||||
|
|
||||||
// top row country
|
// top row country
|
||||||
countries: { id: string; img: string }[] = [
|
countries: { id: string; img: string }[] = [
|
||||||
{
|
{
|
||||||
id: 'tha',
|
id: "tha",
|
||||||
img: 'assets/departments/tha_plate.png',
|
img: "assets/departments/tha_plate.png",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'mys',
|
id: "mys",
|
||||||
img: 'assets/departments/mys_plate.png',
|
img: "assets/departments/mys_plate.png",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'aus',
|
id: "aus",
|
||||||
img: 'assets/departments/aus_plate.png',
|
img: "assets/departments/aus_plate.png",
|
||||||
},
|
},
|
||||||
// add new country here!
|
// add new country here!
|
||||||
|
{
|
||||||
|
id: "sgp",
|
||||||
|
img: "assets/departments/sgp_plate.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "counter",
|
||||||
|
img: "assets/departments/counter01_plate.png",
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
// bottom row country
|
// bottom row country
|
||||||
alphas: { id: string; img: string }[] = [
|
alphas: { id: string; img: string }[] = [
|
||||||
{
|
{
|
||||||
id: 'alpha-3',
|
id: "alpha-3",
|
||||||
img: 'assets/departments/alpha-3.png',
|
img: "assets/departments/alpha-3.png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "cocktail",
|
||||||
|
img: "assets/departments/cocktail_tha.png",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -91,45 +101,66 @@ export class DepartmentComponent {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private _userService: UserService
|
private _userService: UserService,
|
||||||
) {
|
) {
|
||||||
let perms = _userService.getCurrentUser()!.permissions;
|
let perms = _userService.getCurrentUser()!.permissions;
|
||||||
console.log("GainAccesses",perms)
|
console.log("GainAccesses", perms);
|
||||||
|
|
||||||
for (let perm of perms) {
|
for (let perm of perms) {
|
||||||
switch (perm) {
|
switch (perm) {
|
||||||
case UserPermissions.THAI_PERMISSION:
|
case UserPermissions.THAI_PERMISSION:
|
||||||
this.acccessibleCountries.push('tha');
|
this.acccessibleCountries.push("tha");
|
||||||
break;
|
break;
|
||||||
case UserPermissions.MALAY_PERMISSION:
|
case UserPermissions.MALAY_PERMISSION:
|
||||||
this.acccessibleCountries.push('mys');
|
this.acccessibleCountries.push("mys");
|
||||||
break;
|
break;
|
||||||
case UserPermissions.AUS_PERMISSION:
|
case UserPermissions.AUS_PERMISSION:
|
||||||
this.acccessibleCountries.push('aus');
|
this.acccessibleCountries.push("aus");
|
||||||
break;
|
break;
|
||||||
case UserPermissions.ALPHA3_PERMISSION:
|
case UserPermissions.ALPHA3_PERMISSION:
|
||||||
this.acccessibleCountries.push('alpha-3');
|
this.acccessibleCountries.push("alpha-3");
|
||||||
|
break;
|
||||||
|
case UserPermissions.SINGAPORE_PERMISSION:
|
||||||
|
this.acccessibleCountries.push("sgp");
|
||||||
|
break;
|
||||||
|
case UserPermissions.COUNTER_PERMISSION:
|
||||||
|
this.acccessibleCountries.push("counter");
|
||||||
|
break;
|
||||||
|
case UserPermissions.DUBAI_PERMISSION:
|
||||||
|
this.acccessibleCountries.push("dubai");
|
||||||
|
break;
|
||||||
|
case UserPermissions.COCKTAIL_PERMISSION:
|
||||||
|
this.acccessibleCountries.push("cocktail");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("OK", this.acccessibleCountries);
|
||||||
}
|
}
|
||||||
|
|
||||||
onClick(id: string) {
|
onClick(id: string) {
|
||||||
// add handler for redirect
|
// add handler for redirect
|
||||||
this.notfoundHandler.handleSwitchCountry(id, async () => {
|
this.notfoundHandler.handleSwitchCountry(
|
||||||
// set country
|
id,
|
||||||
await AsyncStorage.setItem('currentRecipeCountry', getCountryMapSwitcher(id));
|
async () => {
|
||||||
// set filename, don't know which file was a target so use default
|
// set country
|
||||||
await AsyncStorage.setItem('currentRecipeFile', 'default');
|
await AsyncStorage.setItem(
|
||||||
}, async () => {
|
"currentRecipeCountry",
|
||||||
// set country to `tha`
|
getCountryMapSwitcher(id),
|
||||||
await AsyncStorage.setItem('currentRecipeCountry', 'Thailand');
|
);
|
||||||
// set filename, don't know which file was a target so use default
|
// set filename, don't know which file was a target so use default
|
||||||
await AsyncStorage.setItem('currentRecipeFile', 'default');
|
await AsyncStorage.setItem("currentRecipeFile", "default");
|
||||||
// safely return to recipes
|
},
|
||||||
});
|
async () => {
|
||||||
|
// set country to `tha`
|
||||||
|
await AsyncStorage.setItem("currentRecipeCountry", "Thailand");
|
||||||
|
// set filename, don't know which file was a target so use default
|
||||||
|
await AsyncStorage.setItem("currentRecipeFile", "default");
|
||||||
|
// safely return to recipes
|
||||||
|
},
|
||||||
|
);
|
||||||
void this.router.navigate([`/${id}/recipes`]);
|
void this.router.navigate([`/${id}/recipes`]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,6 @@ export class Debugger {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
if(cmd.startsWith("fn::")){
|
if(cmd.startsWith("fn::")){
|
||||||
|
|
@ -204,6 +203,23 @@ export class Debugger {
|
||||||
} else if(cmd.startsWith("var::")){
|
} else if(cmd.startsWith("var::")){
|
||||||
let varname = cmd.substring(5);
|
let varname = cmd.substring(5);
|
||||||
this.output.push(JSON.stringify(holdon[varname]));
|
this.output.push(JSON.stringify(holdon[varname]));
|
||||||
|
} else if(cmd.startsWith("load::")){
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// assume varname
|
||||||
|
|
||||||
|
|
||||||
|
if(cmd.endsWith("#window")){
|
||||||
|
let exposed: string = cmd.split(" ")[0];
|
||||||
|
console.log("try exposed to window "+exposed);
|
||||||
|
let estr = "window."+exposed+" = \""+holdon[exposed]+"\"";
|
||||||
|
console.log("estr", estr);
|
||||||
|
let eval_res = eval(estr);
|
||||||
|
console.log("eval_res", eval_res);
|
||||||
|
this.output.push(JSON.stringify(eval_res));
|
||||||
|
} else {
|
||||||
|
this.output.push(JSON.stringify(holdon[cmd]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -217,9 +233,9 @@ export class Debugger {
|
||||||
}
|
}
|
||||||
} else if (!line.startsWith("//") && line != ""){
|
} else if (!line.startsWith("//") && line != ""){
|
||||||
|
|
||||||
if(!line.startsWith("window") && !line.startsWith("let") && !line.startsWith("var")){
|
// if(!line.startsWith("window") && !line.startsWith("let") && !line.startsWith("var")){
|
||||||
line = "window."+line;
|
// line = "window."+line;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,10 @@ export function departmentList() {
|
||||||
'tha',
|
'tha',
|
||||||
'mys',
|
'mys',
|
||||||
'aus',
|
'aus',
|
||||||
'alpha-3'
|
'alpha-3',
|
||||||
|
'sgp',
|
||||||
|
'dubai',
|
||||||
|
'counter'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -28,7 +31,16 @@ export class NotFoundHandler {
|
||||||
handleSwitchCountry(country: string, callback: () => Promise<any>, error?: () => Promise<any>) {
|
handleSwitchCountry(country: string, callback: () => Promise<any>, error?: () => Promise<any>) {
|
||||||
let checkCondition = departmentList().includes(country);
|
let checkCondition = departmentList().includes(country);
|
||||||
if(checkCondition) {
|
if(checkCondition) {
|
||||||
callback();
|
// callback();
|
||||||
|
Promise.allSettled([
|
||||||
|
Promise.resolve(callback())
|
||||||
|
]).then((results) => {
|
||||||
|
// console.log("Resolved callback: ",results)
|
||||||
|
if(results[0].status == 'fulfilled'){
|
||||||
|
console.info("Callback executed successfully");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if(error)
|
if(error)
|
||||||
error();
|
error();
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,9 @@ export var countryMap: Tuple<string, string>[] = [
|
||||||
new Tuple<string, string>('tha', 'Thailand'),
|
new Tuple<string, string>('tha', 'Thailand'),
|
||||||
new Tuple<string, string>('mys', 'Malaysia'),
|
new Tuple<string, string>('mys', 'Malaysia'),
|
||||||
new Tuple<string, string>('aus', 'Australia'),
|
new Tuple<string, string>('aus', 'Australia'),
|
||||||
|
new Tuple<string, string>('sgp', 'Singapore'),
|
||||||
|
new Tuple<string, string>('dubai', 'UAE Dubai'),
|
||||||
|
new Tuple<string, string>('counter', 'Counter')
|
||||||
];
|
];
|
||||||
|
|
||||||
export function getCountryMapSwitcher(param: string) {
|
export function getCountryMapSwitcher(param: string) {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
export const environment = {
|
export const environment = {
|
||||||
production: false,
|
production: false,
|
||||||
api: 'http://localhost:8080',
|
api: "http://localhost:8080",
|
||||||
|
imgApi: "http://localhost:36527",
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
export const environment = {
|
export const environment = {
|
||||||
production: true,
|
production: true,
|
||||||
api: 'https://recipe.taobin.io:8090/api',
|
api: "https://recipe.taobin.io:8090/api",
|
||||||
|
imgApi: "https://recipe.taobin.io:8090/img",
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,44 +1,56 @@
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"ignore": true,
|
"ignore": true,
|
||||||
"name": "New Country in full name",
|
"name": "New Country in full name",
|
||||||
"short": "Short name",
|
"short": "Short name",
|
||||||
"permissions": "use number after 128, do not use 16 and 128"
|
"permissions": "use number after 128, do not use 16 and 128"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Thailand",
|
"name": "Thailand",
|
||||||
"short": "tha",
|
"short": "tha",
|
||||||
"permissions": 1,
|
"permissions": 1,
|
||||||
"dir": "tha"
|
"dir": "tha"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Malaysia",
|
"name": "Malaysia",
|
||||||
"short": "mys",
|
"short": "mys",
|
||||||
"permissions": 2,
|
"permissions": 2,
|
||||||
"dir": "mys"
|
"dir": "mys"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Australia",
|
"name": "Australia",
|
||||||
"short": "aus",
|
"short": "aus",
|
||||||
"permissions": 4,
|
"permissions": 4,
|
||||||
"dir": "aus"
|
"dir": "aus"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Alpha3",
|
"name": "Alpha3",
|
||||||
"short": "alpha-3",
|
"short": "alpha-3",
|
||||||
"permissions": 8,
|
"permissions": 8,
|
||||||
"dir": "alpha-3"
|
"dir": "alpha-3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "UAE Dubai",
|
"name": "UAE Dubai",
|
||||||
"short": "uae-dubai",
|
"short": "uae-dubai",
|
||||||
"permissions": 256,
|
"permissions": 256,
|
||||||
"dir": "dubai"
|
"dir": "dubai"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Counter Cafe",
|
"name": "Counter Cafe",
|
||||||
"short": "counter",
|
"short": "counter",
|
||||||
"permissions": 512,
|
"permissions": 512,
|
||||||
"dir": "counter"
|
"dir": "counter01"
|
||||||
}
|
},
|
||||||
]
|
{
|
||||||
|
"name": "Singapore",
|
||||||
|
"short": "sgp",
|
||||||
|
"permissions": 1024,
|
||||||
|
"dir": "sgp"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Cocktail",
|
||||||
|
"short": "cocktail",
|
||||||
|
"permissions": 2048,
|
||||||
|
"dir": "cocktail_tha"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
|
||||||
|
|
@ -183,6 +183,22 @@ var (
|
||||||
CountryID: "aus",
|
CountryID: "aus",
|
||||||
CountryName: "Australia",
|
CountryName: "Australia",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
CountryID: "dubai",
|
||||||
|
CountryName: "UAE Dubai",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
CountryID: "counter01",
|
||||||
|
CountryName: "Counter Cafe",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
CountryID: "sgp",
|
||||||
|
CountryName: "Singapore",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
CountryID: "cocktail_tha",
|
||||||
|
CountryName: "Cocktail",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -304,6 +320,8 @@ func NewData(taoLogger *logger.TaoLogger, redisClient *RedisCli) *Data {
|
||||||
// log.Panic("Error when read default recipe file:", err)
|
// log.Panic("Error when read default recipe file:", err)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
fmt.Println(CurrentCountryIDMap)
|
||||||
|
|
||||||
return &Data{
|
return &Data{
|
||||||
CurrentFile: currentFileMap,
|
CurrentFile: currentFileMap,
|
||||||
CurrentCountryID: CurrentCountryIDMap,
|
CurrentCountryID: CurrentCountryIDMap,
|
||||||
|
|
@ -1178,9 +1196,11 @@ func (d *Data) GetSubmenusOfRecipe(countryID, filename, productCode string) ([]m
|
||||||
func (d *Data) GetCountryNameByID(countryID string) (string, error) {
|
func (d *Data) GetCountryNameByID(countryID string) (string, error) {
|
||||||
for _, country := range d.Countries {
|
for _, country := range d.Countries {
|
||||||
if country.CountryID == countryID {
|
if country.CountryID == countryID {
|
||||||
|
fmt.Println("Found " + countryID)
|
||||||
return country.CountryName, nil
|
return country.CountryName, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fmt.Println("Not found " + countryID)
|
||||||
return "", fmt.Errorf("country ID: %s not found", countryID)
|
return "", fmt.Errorf("country ID: %s not found", countryID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
@ -31,7 +30,7 @@ func RunGitRecipeWorker() {
|
||||||
for {
|
for {
|
||||||
err := pull_request()
|
err := pull_request()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
//fmt.Println(err)
|
||||||
}
|
}
|
||||||
time.Sleep(10 * time.Minute)
|
time.Sleep(10 * time.Minute)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -140,20 +140,20 @@ type CountryNamePerms struct {
|
||||||
func LoadCountrySettingsWithPermissions() []CountryNamePerms {
|
func LoadCountrySettingsWithPermissions() []CountryNamePerms {
|
||||||
res := make([]CountryNamePerms, 0)
|
res := make([]CountryNamePerms, 0)
|
||||||
|
|
||||||
path, err := os.Getwd()
|
// path, err := os.Getwd()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
log.Println(err)
|
// log.Println(err)
|
||||||
}
|
// }
|
||||||
fmt.Println(path)
|
// fmt.Println(path)
|
||||||
|
|
||||||
files, err := os.ReadDir(path)
|
// files, err := os.ReadDir(path)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
log.Fatalln(err)
|
// log.Fatalln(err)
|
||||||
}
|
// }
|
||||||
|
|
||||||
for _, file := range files {
|
// for _, file := range files {
|
||||||
fmt.Println(file.Name(), file.IsDir())
|
// fmt.Println(file.Name(), file.IsDir())
|
||||||
}
|
// }
|
||||||
|
|
||||||
// read file country.settings.json
|
// read file country.settings.json
|
||||||
content, err := os.Open("./country.settings.json")
|
content, err := os.Open("./country.settings.json")
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,7 @@ func ValidatePermissions(p []permissions.Permission, nextRoute http.HandlerFunc)
|
||||||
for _, pm := range p {
|
for _, pm := range p {
|
||||||
if !u.Permissions.IsHavePermission(pm) {
|
if !u.Permissions.IsHavePermission(pm) {
|
||||||
// If not have permission response unauthorized
|
// If not have permission response unauthorized
|
||||||
|
fmt.Println("tried access " + fmt.Sprintf("%v", pm))
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
err := json.NewEncoder(w).Encode("Unauthorized")
|
err := json.NewEncoder(w).Encode("Unauthorized")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -106,6 +107,7 @@ func ValidateOwnerOrPermissions(p []permissions.Permission, nextRoute http.Handl
|
||||||
reqUserID := chi.URLParam(r, "id")
|
reqUserID := chi.URLParam(r, "id")
|
||||||
u := r.Context().Value("user").(*models.User)
|
u := r.Context().Value("user").(*models.User)
|
||||||
|
|
||||||
|
fmt.Println(u)
|
||||||
if reqUserID == "" {
|
if reqUserID == "" {
|
||||||
// If not have permission response unauthorized
|
// If not have permission response unauthorized
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
|
|
|
||||||
|
|
@ -155,6 +155,7 @@ func (rr *RecipeRouter) Route(r chi.Router) {
|
||||||
for k := range rr.data.AllRecipeFiles {
|
for k := range rr.data.AllRecipeFiles {
|
||||||
countryName, err := rr.data.GetCountryNameByID(k)
|
countryName, err := rr.data.GetCountryNameByID(k)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
rr.taoLogger.Log.Error("RecipeRouter.Countries", zap.Any(countryName, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
keys = append(keys, countryName)
|
keys = append(keys, countryName)
|
||||||
|
|
@ -854,7 +855,7 @@ func (rr *RecipeRouter) getImageOfProductCode(w http.ResponseWriter, r *http.Req
|
||||||
http.Error(w, err.Error(), http.StatusNotFound)
|
http.Error(w, err.Error(), http.StatusNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
rr.taoLogger.Log.Debug("GetImageFromFast", zap.Int("Code", resp.StatusCode));
|
rr.taoLogger.Log.Debug("GetImageFromFast", zap.Int("Code", resp.StatusCode))
|
||||||
|
|
||||||
img_data, err := png.Decode(resp.Body)
|
img_data, err := png.Decode(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -864,7 +865,6 @@ func (rr *RecipeRouter) getImageOfProductCode(w http.ResponseWriter, r *http.Req
|
||||||
|
|
||||||
imgResult = img_data
|
imgResult = img_data
|
||||||
|
|
||||||
|
|
||||||
// write image
|
// write image
|
||||||
png.Encode(w, imgResult)
|
png.Encode(w, imgResult)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,10 @@ func (ur *UserRouter) Route(r chi.Router) {
|
||||||
superPerm = superPerm | p.CountryPermission
|
superPerm = superPerm | p.CountryPermission
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if superPerm < 3999 {
|
||||||
|
superPerm = superPerm | permissions.Editor | permissions.Viewer
|
||||||
|
}
|
||||||
|
|
||||||
// Users
|
// Users
|
||||||
r.Route("/users", func(r chi.Router) {
|
r.Route("/users", func(r chi.Router) {
|
||||||
r.Get("/", middlewares.ValidatePermissions([]permissions.Permission{permissions.Permission(superPerm)}, ur.getUsers))
|
r.Get("/", middlewares.ValidatePermissions([]permissions.Permission{permissions.Permission(superPerm)}, ur.getUsers))
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,9 @@ func (s *Server) createHandler() {
|
||||||
for _, p := range perms {
|
for _, p := range perms {
|
||||||
superPerm = superPerm | p.CountryPermission
|
superPerm = superPerm | p.CountryPermission
|
||||||
}
|
}
|
||||||
|
if superPerm < 3999 {
|
||||||
|
superPerm = superPerm | permissions.Editor | permissions.Viewer
|
||||||
|
}
|
||||||
|
|
||||||
// Seed
|
// Seed
|
||||||
_ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "kenta420", "poomipat.c@forth.co.th", "", permissions.Permission(superPerm))
|
_ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "kenta420", "poomipat.c@forth.co.th", "", permissions.Permission(superPerm))
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ func (tl *TaoLogger) initConfig() *zap.Logger {
|
||||||
|
|
||||||
productionConfig := zap.NewProductionEncoderConfig()
|
productionConfig := zap.NewProductionEncoderConfig()
|
||||||
productionConfig.EncodeTime = zapcore.ISO8601TimeEncoder
|
productionConfig.EncodeTime = zapcore.ISO8601TimeEncoder
|
||||||
|
productionConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
||||||
|
|
||||||
// fileEncoder := zapcore.NewJSONEncoder(productionConfig)
|
// fileEncoder := zapcore.NewJSONEncoder(productionConfig)
|
||||||
consoleEncoder := zapcore.NewConsoleEncoder(productionConfig)
|
consoleEncoder := zapcore.NewConsoleEncoder(productionConfig)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue