Skip to content

Commit

Permalink
Check auth
Browse files Browse the repository at this point in the history
  • Loading branch information
b263 committed Jan 4, 2024
1 parent f1146d2 commit a492ae5
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/dev.b263.time-tracker.sdPlugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"Description": "Time tracker using the Tracking Time platform. Requires a free account.",
"Icon": "assets/category",
"URL": "https://github.com/b263/stream-deck-time-tracker/issues",
"Version": "0.5.0",
"Version": "0.6.0",
"CodePath": "app/app.html",
"Software": {
"MinimumVersion": "5.0"
Expand Down
2 changes: 1 addition & 1 deletion src/ui/projects/action-track-pi/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

<hr />

<app-kimai></app-kimai>
<app-kimai [isAuthenticated]="isKimaiAuthenticated"></app-kimai>
</div>
8 changes: 8 additions & 0 deletions src/ui/projects/action-track-pi/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CommonModule } from '@angular/common';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ViewChild,
inject,
Expand Down Expand Up @@ -35,6 +36,9 @@ export const DEFAULT_SETTINGS: PluginSettings = {
})
export class AppComponent {
private readonly state = inject(STATE);
private readonly cdr = inject(ChangeDetectorRef);

public isKimaiAuthenticated = false;

@ViewChild(KimaiComponent)
private kimaiComponent!: KimaiComponent;
Expand Down Expand Up @@ -66,8 +70,12 @@ export class AppComponent {
settings.backendProviderConfig?.['kimai']?.authenticationState ===
AuthenticationState.loggedIn
) {
this.isKimaiAuthenticated = true;
this.kimaiComponent.loadProjects();
} else {
this.isKimaiAuthenticated = false;
}
this.cdr.detectChanges();
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form [formGroup]="form">
<form [formGroup]="form" *ngIf="isAuthenticated; else notAuthenticated">
<div class="sdpi-item">
<div class="sdpi-item-label">Project</div>
<select
Expand Down Expand Up @@ -37,3 +37,7 @@
</select>
</div>
</form>

<ng-template #notAuthenticated>
<p class="wrap">Sign in to load projects/activities</p>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ChangeDetectionStrategy,
Component,
DestroyRef,
Input,
NgZone,
inject,
} from '@angular/core';
Expand Down Expand Up @@ -34,6 +35,9 @@ export class KimaiComponent {
private readonly zone = inject(NgZone);
private readonly api = inject(ApiFactoryService);

@Input()
public isAuthenticated = false;

public readonly form = new FormGroup({
projectId: new FormControl(0),
activityId: new FormControl(0),
Expand Down
2 changes: 1 addition & 1 deletion src/ui/projects/external/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class AppComponent {
}

async onKimaiLogin() {
let authenticationState: keyof typeof AuthenticationState =
let authenticationState: (typeof AuthenticationState)[keyof typeof AuthenticationState] =
AuthenticationState.error;
const { url, user, token } =
this.patchedFormValue.backendProviderConfig!.kimai!;
Expand Down
4 changes: 0 additions & 4 deletions src/ui/projects/external/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import { ApplicationConfig, InjectionToken } from '@angular/core';
import { GlobalSettings } from '../../../../../js/src/lib/types';
import { BehaviorSubject } from 'rxjs';

declare var $SD: any;
declare var $PI: any;
declare var Utils: any;

export const INITIAL_GLOBAL_SETTINGS = new InjectionToken<
BehaviorSubject<GlobalSettings>
>('Initial global settings');
Expand Down
4 changes: 4 additions & 0 deletions src/ui/projects/external/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { AppComponent } from './app/app.component';

declare var $SD: any;
declare var $PI: any;
declare var Utils: any;

bootstrapApplication(AppComponent, appConfig).catch((err) =>
console.error(err)
);
8 changes: 2 additions & 6 deletions src/ui/projects/external/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
"outDir": "../../out-tsc/app",
"types": []
},
"files": [
"src/main.ts"
],
"include": [
"src/**/*.d.ts"
]
"files": ["src/main.ts"],
"include": ["src/**/*.d.ts", "../../types/**/*.d.ts"]
}

0 comments on commit a492ae5

Please sign in to comment.