Add frontend.

This commit is contained in:
Florian THIERRY
2021-07-31 12:26:51 +02:00
parent ef04d3dbea
commit c281df00c7
56 changed files with 32276 additions and 1 deletions

View File

@@ -0,0 +1,14 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { CreateApplicationComponent } from './applications/create-application/create-application.component';
import { UiKitComponent } from './ui-kit/ui-kit.component';
const routes: Routes = [
{path: '', component: CreateApplicationComponent}
];
@NgModule({
imports: [RouterModule.forRoot(routes, { onSameUrlNavigation: 'reload' })],
exports: [RouterModule]
})
export class AppRoutingModule { }

View File

@@ -0,0 +1 @@
<router-outlet></router-outlet>

View File

View File

@@ -0,0 +1,35 @@
import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
RouterTestingModule
],
declarations: [
AppComponent
],
}).compileComponents();
});
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
it(`should have as title 'cerberus'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('cerberus');
});
it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement;
expect(compiled.querySelector('.content span').textContent).toContain('cerberus app is running!');
});
});

View File

@@ -0,0 +1,10 @@
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'cerberus';
}

View File

@@ -0,0 +1,33 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { UiKitComponent } from './ui-kit/ui-kit.component';
import { CreateApplicationComponent } from './applications/create-application/create-application.component';
import { SelectComponent } from './core/components/select/select.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {MatIconModule} from '@angular/material/icon';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
declarations: [
AppComponent,
UiKitComponent,
CreateApplicationComponent,
SelectComponent,
],
imports: [
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule,
MatIconModule,
FormsModule,
ReactiveFormsModule,
HttpClientModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }

View File

@@ -0,0 +1,23 @@
<div class="card">
<h1>Add a new application</h1>
<form [formGroup]="form" (ngSubmit)="onSubmit()" ngNativeValidate>
<div class="row">
<input formControlName="name" placeholder="Application name" required/>
</div>
<div class="row">
<input formControlName="serviceName" placeholder="Service name" required/>
</div>
<div class="row">
<label for="service-type">Type:</label>
<select formControlName="serviceType">
<option *ngFor="let type of serviceTypes" [value]="type.value">
{{type.label}}
</option>
</select>
</div>
<div class="row action">
<button type="button" class="secondary">Cancel</button>
<button type="submit">Save</button>
</div>
</form>
</div>

View File

@@ -0,0 +1,3 @@
.card {
margin: auto;
}

View File

@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CreateApplicationComponent } from './create-application.component';
describe('CreateApplicationComponent', () => {
let component: CreateApplicationComponent;
let fixture: ComponentFixture<CreateApplicationComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ CreateApplicationComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(CreateApplicationComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,43 @@
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Application } from 'src/app/core/entities/Application';
import { ReferentialData } from 'src/app/core/entities/ReferentialData';
import { ApplicationService } from 'src/app/core/services/application.service';
import { ReferentialDataService } from 'src/app/core/services/referential-data.service';
@Component({
selector: 'app-create-application',
templateUrl: './create-application.component.html',
styleUrls: ['./create-application.component.scss']
})
export class CreateApplicationComponent implements OnInit {
form: FormGroup = this._formBuilder.group({
name: [undefined, Validators.required],
serviceName: [undefined, Validators.required],
serviceType: [undefined, Validators.required]
});
serviceTypes: ReferentialData[] = [];
constructor(
private _formBuilder: FormBuilder,
private _referentialDataService: ReferentialDataService,
private _applicationService: ApplicationService
) { }
ngOnInit(): void {
this._referentialDataService.getServiceTypes()
.then(serviceTypes => this.serviceTypes = serviceTypes)
.catch(error => console.error('An error occured while loading service types.'));
}
onSubmit(): void {
if (this.form.valid) {
const appToAdd: Application = this.form.value as Application;
this._applicationService.add(appToAdd)
.then(applicationAdded => console.log('Application added.'))
.catch(error => console.error('An error occured while adding the new application.'));
} else {
console.error('Form is invalid');
}
}
}

View File

@@ -0,0 +1,9 @@
<div class="container">
<select #select>
<option>Option 1</option>
<option>Option 2</option>
</select>
<div class="icon">
<mat-icon (click)="select.focus()">unfold_more</mat-icon>
</div>
</div>

View File

@@ -0,0 +1,39 @@
$btn-primary-background-top: #4ca4f6;
$btn-primary-background-bottom: #0073f7;
$select-icon-radius: 4px;
.container {
position: relative;
display: flex;
justify-content: center;
align-items: center;
select {
}
.icon {
position: absolute;
top: 0;
right: 0;
width: 1.5rem;
background-image: linear-gradient($btn-primary-background-top, $btn-primary-background-bottom);
color: white;
height: 23px;
top: 3px;
right: 0;
border-radius: 0 $select-icon-radius $select-icon-radius 0;
mat-icon {
font-size: 19px;
display: flex;
justify-content: center;
align-items: center;
&:hover {
cursor: default;
}
}
}
}

View File

@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SelectComponent } from './select.component';
describe('SelectComponent', () => {
let component: SelectComponent;
let fixture: ComponentFixture<SelectComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ SelectComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(SelectComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-select',
templateUrl: './select.component.html',
styleUrls: ['./select.component.scss']
})
export class SelectComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}

View File

@@ -0,0 +1,6 @@
export interface Application {
id: string;
name: string;
serviceName: string;
serviceType: string;
}

View File

@@ -0,0 +1,4 @@
export interface ReferentialData {
value: string,
label: string
}

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { ApplicationService } from './application.service';
describe('ApplicationService', () => {
let service: ApplicationService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ApplicationService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@@ -0,0 +1,17 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Application } from '../entities/Application';
@Injectable({
providedIn: 'root'
})
export class ApplicationService {
constructor(
private _httpClient: HttpClient
) {}
add(application: Application): Promise<Application> {
return this._httpClient.post<Application>('/api/applications', application).toPromise();
}
}

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { ReferentialDataService } from './referential-data.service';
describe('ReferentialDataService', () => {
let service: ReferentialDataService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ReferentialDataService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@@ -0,0 +1,16 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { ReferentialData } from '../entities/ReferentialData';
@Injectable({
providedIn: 'root'
})
export class ReferentialDataService {
constructor(
private _httpClient: HttpClient
) {}
getServiceTypes(): Promise<ReferentialData[]> {
return this._httpClient.get<ReferentialData[]>('/api/referentialData/serviceTypes').toPromise();
}
}

View File

@@ -0,0 +1,46 @@
<button>Test1</button>
<input type="checkbox" />
<div class="login-form card">
<div class="row">
<input type="text" placeholder="Login"/>
</div>
<div class="row">
<input type="password" placeholder="Password"/>
</div>
<div class="row action">
<button>Login</button>
</div>
</div>
<div class="card">
<div class="row">
<input type="checkbox"/>
Log out after
<input type="number" value="5"/>
minutes
</div>
<div class="row">
<input type="checkbox"/>
Require an administrator password
</div>
<div class="row">
<div class="select">
<select>
<option>Option 1</option>
<option>Option 2</option>
</select>
</div>
</div>
<div class="row">
<input type="text" class="max-width" placeholder="Rechercher"/>
</div>
<div class="row action">
<button class="help">?</button>
<div class="row">
<button class="secondary">Annuler</button>
<button>Ok</button>
</div>
</div>
</div>

View File

@@ -0,0 +1,11 @@
.login-form {
width: 15rem;
div, div input {
width: 100%;
}
div.action {
justify-content: right;
}
}

View File

@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { UiKitComponent } from './ui-kit.component';
describe('UiKitComponent', () => {
let component: UiKitComponent;
let fixture: ComponentFixture<UiKitComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ UiKitComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(UiKitComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-ui-kit',
templateUrl: './ui-kit.component.html',
styleUrls: ['./ui-kit.component.scss']
})
export class UiKitComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}

View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,3 @@
export const environment = {
production: true
};

View File

@@ -0,0 +1,16 @@
// This file can be replaced during build by using the `fileReplacements` array.
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.
export const environment = {
production: false
};
/*
* For easier debugging in development mode, you can import the following file
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
*
* This import should be commented out in production mode because it will have a negative impact
* on performance if an error is thrown.
*/
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.

BIN
cerberus/src/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 948 B

16
cerberus/src/index.html Normal file
View File

@@ -0,0 +1,16 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Cerberus</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body>
<app-root></app-root>
</body>
</html>

12
cerberus/src/main.ts Normal file
View File

@@ -0,0 +1,12 @@
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));

65
cerberus/src/polyfills.ts Normal file
View File

@@ -0,0 +1,65 @@
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/guide/browser-support
*/
/***************************************************************************************************
* BROWSER POLYFILLS
*/
/**
* IE11 requires the following for NgClass support on SVG elements
*/
// import 'classlist.js'; // Run `npm install --save classlist.js`.
/**
* Web Animations `@angular/platform-browser/animations`
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
* Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
*/
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
/**
* By default, zone.js will patch all possible macroTask and DomEvents
* user can disable parts of macroTask/DomEvents patch by setting following flags
* because those flags need to be set before `zone.js` being loaded, and webpack
* will put import in the top of bundle, so user need to create a separate file
* in this directory (for example: zone-flags.ts), and put the following flags
* into that file, and then add the following code before importing zone.js.
* import './zone-flags';
*
* The flags allowed in zone-flags.ts are listed here.
*
* The following flags will work for all browsers.
*
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
*
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
* with the following flag, it will bypass `zone.js` patch for IE/Edge
*
* (window as any).__Zone_enable_cross_context_check = true;
*
*/
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
import 'zone.js/dist/zone'; // Included with Angular CLI.
/***************************************************************************************************
* APPLICATION IMPORTS
*/

156
cerberus/src/styles.scss Normal file
View File

@@ -0,0 +1,156 @@
/* You can add global styles to this file, and also import other style files */
@font-face {
font-family: helvetica;
src: url(assets/fonts/Helvetica.ttf);
}
$blue: #017aff;
$btn-primary-border: #2f8df9;
$btn-primary-background-top: #4ca4f6;
$btn-primary-background-bottom: #0073f7;
$btn-primary-active-border: #007cf8;
$btn-primary-active-background-top: #0093f8;
$btn-primary-active-background-bottom: #0064dd;
$btn-secondary-border: #c3c5c6;
$btn-secondary-background: #ffffff;
$btn-secondary-active-border: #c8c8c8;
$btn-secondary-active-background: #f0f0f0;
$font-size: 14px;
body {
font-size: $font-size;
font-family: helvetica;
}
button {
// background-color: $blue;
background-image: linear-gradient($btn-primary-background-top, $btn-primary-background-bottom);
color: white;
border: solid 1px $btn-primary-background-bottom;
display: flex;
justify-content: center;
align-items: center;
min-width: 5rem;
border-radius: .3rem;
padding: .15rem 1rem;
font-weight: 600;
margin: .2rem .5rem;
&:active {
border-color: $btn-primary-active-border;
background-image: linear-gradient($btn-primary-active-background-top, $btn-primary-active-background-bottom);
}
&.secondary {
background-image: none;
background-color: $btn-secondary-background;
border-color: $btn-secondary-border;
color: #222;
font-weight: 500;
&:active {
background-color: $btn-secondary-active-background;
border-color: $btn-secondary-active-border;
}
}
&.help {
border-radius: 10em;
padding: 0;
background-image: none;
background-color: #eeeeee;
color: #333;
border-color: #bbb;
min-width: min-content;
width: 1.5rem;
height: 1.5rem;
&:hover {
background-color: #dddddd;
}
}
}
div.card {
width: max-content;
padding: .5rem 1rem;
box-shadow: 0px 13px 28px 4px rgba(0,0,0,0.2);
border-radius: .4rem;
margin: 2rem;
}
label {
display: flex;
flex: 0 !important;
margin-right: .5rem;
}
input {
margin: 0 .5rem;
border: none;
box-shadow: 0px 1px 2px 1px rgba(0,0,0,0.1);
padding: .2rem .5rem;
border-radius: .2rem;
width: 3rem;
}
select {
// A reset of styles, including removing the default dropdown arrow
appearance: none;
// Additional resets for further consistency
border: none;
box-shadow: 0px 1px 2px 1px rgba(0,0,0,0.1);
color: #333;
border-radius: .3rem;
padding: .15rem .5rem;
font-weight: 600;
margin: .2rem .5rem;
font-size: $font-size;
width: 10em;
&::-ms-expand {
display: none;
}
}
.select {
display: grid;
grid-template-areas: "select";
align-items: center;
}
// Utilitary classes
.max-width {
width: 100%;
}
div.row {
display: flex;
flex-direction: row;
align-items: center;
margin: .5rem 0;
max-width: 100%;
&.action {
margin-top: 1.5rem;
justify-content: space-between;
}
& > * {
display: flex;
flex: 1 0;
}
& > input, select {
margin-left: 0;
margin-right: 0;
}
}
html, body { height: 100%; }
body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }

25
cerberus/src/test.ts Normal file
View File

@@ -0,0 +1,25 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare const require: {
context(path: string, deep?: boolean, filter?: RegExp): {
keys(): string[];
<T>(id: string): T;
};
};
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);