diff --git a/package.json b/package.json index 3ad52a54..845d484c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rag-2-frontend", - "version": "0.0.0", + "version": "2.1", "scripts": { "ng": "ng", "start": "ng serve", diff --git a/src/app/game/components/console/console-fieldset/console-fieldset.component.ts b/src/app/game/components/console/console-fieldset/console-fieldset.component.ts index c9dad358..1d7f5b99 100644 --- a/src/app/game/components/console/console-fieldset/console-fieldset.component.ts +++ b/src/app/game/components/console/console-fieldset/console-fieldset.component.ts @@ -7,10 +7,50 @@ import { TExchangeData } from '@gameModels/exchange-data.type'; selector: 'app-console-fieldset', standalone: true, imports: [KeyValuePipe, ExchangeDataPipe], + styles: [ + ` + .console-fieldset { + margin-top: 0px; + margin-bottom: 0px; + margin-left: 2rem; + margin-right: 0.5rem; + padding-top: 0.25rem; + padding-bottom: 0.25rem; + padding-left: 0.5rem; + border-left: 1px solid #FF6000; + } + .console-key { + font-weight: 700; + font-size: 1rem; + line-height: 1.5rem; + font-family: monospace; + position: relative; + top: -0.5rem; + } + .console-value { + font-size: 0.875rem; + line-height: 1.25rem; + color: #FFE6C7; + font-family: monospace; + position: relative; + top: -0.5rem; + } + @media (min-width: 1280px) { + .console-value { + font-size: 1rem; + line-height: 1.5rem; + } + .console-key{ + font-size: 1.125rem; + line-height: 1.75rem; + } + } + ` + ], template: ` @for (data of logData | keyvalue; track data.key) { -
- +
+ {{ data.key }}: @@ -18,7 +58,7 @@ import { TExchangeData } from '@gameModels/exchange-data.type'; } @else { - + {{ data.value }} } diff --git a/src/app/game/components/console/console.component.ts b/src/app/game/components/console/console.component.ts index a35692c1..05ee1685 100644 --- a/src/app/game/components/console/console.component.ts +++ b/src/app/game/components/console/console.component.ts @@ -1,4 +1,4 @@ -import { Component, Input } from '@angular/core'; +import { ApplicationRef, Component, ComponentFactoryResolver, ComponentRef, Injector, Input, OnDestroy } from '@angular/core'; import { TExchangeData } from '@gameModels/exchange-data.type'; import { ExchangeDataPipe } from '@utils/pipes/exchange-data.pipe'; import { ConsoleFieldsetComponent } from './console-fieldset/console-fieldset.component'; @@ -9,36 +9,78 @@ import { ConsoleFieldsetComponent } from './console-fieldset/console-fieldset.co imports: [ExchangeDataPipe, ConsoleFieldsetComponent], template: `
-
+ class="relative w-full max-h-96 transition-all ease-in-out duration-700 bg-lightGray overflow-y-scroll z-50 px-5 {{isConsoleVisible ? ' h-72 py-4' : ' h-0'}}"> + + class="items-start gap-y-6 transition-all ease-in-out duration-700 {{isConsoleVisible ? ' p-10' : ' p-0'}}" />
`, }) -export class ConsoleComponent { +export class ConsoleComponent implements OnDestroy{ @Input({ required: true }) public logData: TExchangeData = {}; public isConsoleVisible = false; + + private _newWindow: Window | null = null; + private _componentRef: ComponentRef | null = null; + public constructor( + private _componentFactoryResolver: ComponentFactoryResolver, + private _injector: Injector, + private _appRef: ApplicationRef, + ) {} - public consoleClasses: TExchangeData = { - button: `w-full bg-lightGray tracking-[0.15em] sticky z-50 top-0 transition-all ease-in-out duration-700 border-b-2 - border-mainOrange hover:border-green-500 text-center py-2 uppercase font-bold font-mono text-xl cursor-pointer`, - consoleContainer: `w-full max-h-96 transition-all ease-in-out duration-700 bg-lightGray overflow-y-scroll z-50 px-5`, - consoleFieldset: `items-start gap-y-6 transition-all ease-in-out duration-700`, - }; + public ngOnDestroy(): void { + this._newWindow?.close() + } public toggleConsole(): void { this.isConsoleVisible = !this.isConsoleVisible; } + + public externalConsoleMode(): void { + this.isConsoleVisible = false; + if (this._newWindow && !this._newWindow.closed) { + this._newWindow.focus(); + return; + } + + this._newWindow = window.open('', '_blank', 'width=1100,height=600'); + if (this._newWindow) { + this._newWindow.document.body.innerHTML = ` +

RAG-2 - External Console Mode

+
+ `; + this._newWindow.document.title = 'RAG-2 - External Console Mode'; + + const consoleStyles = document.querySelectorAll('style'); + consoleStyles.forEach((style) => { + this._newWindow?.document.head.appendChild(style.cloneNode(true)); + }); + + if (this._newWindow?.document.body) { + this._newWindow.document.body.style.backgroundColor = '#5D5D5D'; + this._newWindow.document.body.style.paddingTop = '1rem'; + } + + const componentFactory = this._componentFactoryResolver.resolveComponentFactory(ConsoleFieldsetComponent); + this._componentRef = componentFactory.create(this._injector); + + this._componentRef.instance.logData = this.logData; + + this._appRef.attachView(this._componentRef.hostView); + + const hostElement = this._componentRef.location.nativeElement; + this._newWindow.document.getElementById('consoleFieldsetRoot')?.appendChild(hostElement); + } + } } diff --git a/src/app/shared/components/error-pages/error404/error404.page.component.ts b/src/app/shared/components/error-pages/error404/error404.page.component.ts index a33f676d..bbb001e7 100644 --- a/src/app/shared/components/error-pages/error404/error404.page.component.ts +++ b/src/app/shared/components/error-pages/error404/error404.page.component.ts @@ -13,7 +13,7 @@ import { Rag2LogoComponent } from '../../common/rag-2-logo.component';
- +

Unfortunately...

diff --git a/src/app/shared/components/error-pages/error500/error500.page.component.ts b/src/app/shared/components/error-pages/error500/error500.page.component.ts index 8d7d9d28..79ee8099 100644 --- a/src/app/shared/components/error-pages/error500/error500.page.component.ts +++ b/src/app/shared/components/error-pages/error500/error500.page.component.ts @@ -13,7 +13,7 @@ import { Rag2LogoComponent } from '../../common/rag-2-logo.component';
- +

Unfortunately...

diff --git a/src/utils/helpers/errorHandler.ts b/src/utils/helpers/errorHandler.ts index 190c26bb..02413e17 100644 --- a/src/utils/helpers/errorHandler.ts +++ b/src/utils/helpers/errorHandler.ts @@ -1,4 +1,5 @@ import { HttpErrorResponse } from '@angular/common/http'; +import { environment } from '@env/environment'; export function errorHandler(error: HttpErrorResponse): string { let errorMessage = 'An error has occured'; @@ -6,6 +7,11 @@ export function errorHandler(error: HttpErrorResponse): string { errorMessage = 'Unauthorized, you have to be logged in'; } else if (error.status === 403) { errorMessage = 'Forbidden, you have no permission to do this operation'; + } else if(error.status === 500 || error.statusText === "Unknown Error") { + if (window.location.pathname !== '/error500' && environment.production) { + window.location.href = '/error500'; + } + errorMessage = error.message; } else { errorMessage = JSON.parse(error.error)['description']; }