Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax highlight in /auth #138

Merged
merged 3 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This project tries to follow [SemVer 2.0.0](https://semver.org/).
- Added the ability to login. While logged in this will forward the OIDC
access token to the backend such that a secure user access control is
established. This is only performed when the following config value
is set: (#70, #137)
is set: (#70, #137, #138)

```json
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { NotificationModule } from './shared/notification/notification.module';
import { MenuModule } from 'primeng/menu';
import { TooltipModule } from 'primeng/tooltip';
import { SyntaxHighlightService } from './shared/syntax-highlight/syntax-highlight.service';
import { SharedModule } from './shared/pipes/shared.module';
import { SharedModule } from './shared/shared.module';
import { NavModule } from './nav/nav.module';
import { LicensesModule } from './licenses/licenses.module';
import { AuthModule } from './auth/auth.module';
Expand Down
2 changes: 2 additions & 0 deletions src/app/auth/auth-oidc/oidc-auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { OidcHomeComponent } from './oidc-home/oidc-home.component';
import { OidcUnauthorizedComponent } from './oidc-unauthorized/oidc-unauthorized.component';
import { OidcAutoLoginRoutesGuard } from './oidc-auto-login.guard';
import { AuthGuard } from '../auth.guard';
import { SharedModule } from 'src/app/shared/shared.module';

@NgModule({
declarations: [
Expand All @@ -22,6 +23,7 @@ import { AuthGuard } from '../auth.guard';
RouterModule,
ButtonModule,
CardModule,
SharedModule,

RouterModule.forChild([
{ path: '', component: OidcHomeComponent, canActivate: [AuthGuard] },
Expand Down
14 changes: 6 additions & 8 deletions src/app/auth/auth-oidc/oidc-home/oidc-home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
<p-button (click)="revokeRefreshToken()">Revoke refresh token</p-button>
<p-button (click)="refreshSession()">Refresh session</p-button>
<hr />
<br />
Is Authenticated: {{ isAuthenticated$|async }}
<br />
userData
<pre>{{ userData$ | async | json }}</pre>
<br />
Is Authenticated: <code>{{ isAuthenticated$|async }}</code>
<h2>User data</h2>
<wh-syntax-highlight language="json" [code]="userData$ | async | json"></wh-syntax-highlight>
</div>

<ng-template #noAuth>
<p-button (click)="login()">Login</p-button>
<hr />
</ng-template>

Configuration loaded:
<pre><code>{{ configuration | json }}</code></pre>
<h2>Configuration loaded</h2>

<wh-syntax-highlight language="json" [code]="configuration | json"></wh-syntax-highlight>
2 changes: 1 addition & 1 deletion src/app/builds/builds.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SharedModule } from '../shared/pipes/shared.module';
import { SharedModule } from '../shared/shared.module';
import { ArtifactsModule } from './../artifacts/artifacts.module';
import { TestResultsModule } from './../test-results/test-results.module';
import { BuildService, ProjectService } from 'api-client';
Expand Down
2 changes: 1 addition & 1 deletion src/app/licenses/licenses.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ProgressSpinnerModule } from 'primeng/progressspinner';
import { SharedModule } from '../shared/pipes/shared.module';
import { SharedModule } from '../shared/shared.module';
import { LicensesComponent } from './licenses.component';
import { AccordionModule } from 'primeng/accordion';
import { TooltipModule } from 'primeng/tooltip';
Expand Down
2 changes: 1 addition & 1 deletion src/app/nav/nav.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NgModule } from '@angular/core';
import { NavComponent } from './nav.component';
import { OverlayPanelModule } from 'primeng/overlaypanel';
import { CommonModule } from '@angular/common';
import { SharedModule } from '../shared/pipes/shared.module';
import { SharedModule } from '../shared/shared.module';
import { MenuModule } from 'primeng/menu';
import { TooltipModule } from 'primeng/tooltip';
import { ProgressSpinnerModule } from 'primeng/progressspinner';
Expand Down
9 changes: 2 additions & 7 deletions src/app/projects/projects.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,20 @@ import { ActionsModalComponent } from './actions-modal/actions-modal.component';
import { LocalStorageProjectsService } from './local-storage-projects.service';
import { ProjectListComponent } from './project-list/project-list.component';
import { ProvidersModule } from '../providers/providers.module';
import { WharfSpinnerAnimationComponent } from '../animations/wharf-spinner-animation/wharf-spinner-animation.component';
import { ProjectListItemComponent } from './project-list/project-list-item.component';
import {
ProjectDetailsBuildComponent,
ProjectDetailsComponent,
ProjectDetailsScheduleComponent,
ProjectDetailsConfigurationComponent,
} from './project-details';
import { SyntaxHighlightComponent } from '../shared/syntax-highlight/syntax-highlight.component';
import {
ProjectRefreshIconComponent,
ProjectRefreshButtonComponent,
} from './project-refresh';
import { ProjectFavoriteButtonComponent } from './project-favorite/project-favorite-button.component';
import { TabViewExtendedModule } from '../shared/tabview-x/tabview-x.module';
import { TimerComponent } from '../shared/timer/timer.component';
import { SharedModule } from '../shared/pipes/shared.module';
import { SharedModule } from '../shared/shared.module';

@NgModule({
declarations: [
Expand All @@ -53,9 +50,6 @@ import { SharedModule } from '../shared/pipes/shared.module';
ProjectRefreshButtonComponent,
ProjectRefreshIconComponent,
ProjectFavoriteButtonComponent,
SyntaxHighlightComponent,
TimerComponent,
WharfSpinnerAnimationComponent,
],
imports: [
BrowserAnimationsModule,
Expand All @@ -80,6 +74,7 @@ import { SharedModule } from '../shared/pipes/shared.module';
TabMenuModule,
TabViewExtendedModule,
TooltipModule,
SharedModule,
],
providers: [
ArtifactService,
Expand Down
19 changes: 0 additions & 19 deletions src/app/shared/pipes/shared.module.ts

This file was deleted.

36 changes: 36 additions & 0 deletions src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { DateFormatPipe } from './pipes/date.pipe';
import { NgModule } from '@angular/core';
import { IsValidBuildRefPipe, IsValidDatePipe, IsValidStringPipe } from './pipes/isvalid.pipe';
import { SyntaxHighlightComponent } from './syntax-highlight/syntax-highlight.component';
import { SyntaxHighlightService } from './syntax-highlight/syntax-highlight.service';
import { TimerComponent } from './timer/timer.component';
import { WharfSpinnerAnimationComponent } from './animations/wharf-spinner-animation/wharf-spinner-animation.component';
import { CommonModule } from '@angular/common';

@NgModule({
declarations: [
DateFormatPipe,
IsValidBuildRefPipe,
IsValidDatePipe,
IsValidStringPipe,
SyntaxHighlightComponent,
TimerComponent,
WharfSpinnerAnimationComponent,
],
exports: [
DateFormatPipe,
IsValidBuildRefPipe,
IsValidDatePipe,
IsValidStringPipe,
SyntaxHighlightComponent,
TimerComponent,
WharfSpinnerAnimationComponent,
],
imports: [
CommonModule,
],
providers: [
SyntaxHighlightService,
],
})
export class SharedModule { }
4 changes: 2 additions & 2 deletions src/app/shared/syntax-highlight/syntax-highlight.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export class SyntaxHighlightComponent implements AfterViewChecked, OnChanges {
@Input() language: string;
@Input() code: string;

@ViewChild('codeElem', {static: false}) codeElem: ElementRef<HTMLElement>;
@ViewChild('template', {static: true, read: TemplateRef}) template: TemplateRef<any>;
@ViewChild('codeElem', { static: false }) codeElem: ElementRef<HTMLElement>;
@ViewChild('template', { static: true, read: TemplateRef }) template: TemplateRef<any>;

private hasHighlighted = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Injectable } from '@angular/core';
import 'prismjs';
import * as Prism from 'prismjs';
import 'prismjs/components/prism-yaml';
import 'prismjs/components/prism-json';

// Based on https://auralinna.blog/post/2017/code-syntax-highlighting-with-angular-and-prismjs/
@Injectable()
Expand Down
13 changes: 11 additions & 2 deletions src/scss/code-blocks.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/* Inline code block */
code,
samp {
Expand Down Expand Up @@ -40,7 +39,7 @@ pre.code-block {
}

/* Prism classes coloring */
.token {
.language-yaml .token {
&.comment,
&.prolog,
&.doctype,
Expand All @@ -58,3 +57,13 @@ pre.code-block {
color: $wharf_code_token_keyword_color;
}
}

.language-json .token {
&.punctuation {
color: $wharf_code_token_punctuation_color;
}

&.property {
color: $wharf_code_token_keyword_color;
}
}