Code cleaning about publication edition component.

This commit is contained in:
Florian THIERRY
2024-09-06 10:20:05 +02:00
parent 5804d8cc9f
commit 00945de270
14 changed files with 5 additions and 5 deletions

View File

@@ -0,0 +1,32 @@
<button type="button" class="close" (click)="closeDialog()">
<mat-icon>close</mat-icon>
</button>
<header>
<h1>Add a code block</h1>
</header>
<form [formGroup]="formGroup" (submit)="closeAndValidate()" ngNativeValidate>
<div class="form-content">
<mat-form-field>
<mat-label>Programming language</mat-label>
<mat-select #programmingLanguageSelect formControlName="programmingLanguage">
@for(programmingLanguage of programmingLanguages; track programmingLanguage) {
<mat-option [value]="programmingLanguage.code">
{{programmingLanguage.label}}
</mat-option>
}
</mat-select>
</mat-form-field>
<mat-form-field>
<mat-label>Code block</mat-label>
<textarea matInput formControlName="codeBlock"></textarea>
</mat-form-field>
</div>
<div class="actions">
<button type="submit">
Validate
</button>
<button type="button" (click)="closeDialog()" class="secondary">
Cancel
</button>
</div>
</form>

View File

@@ -0,0 +1,78 @@
:host {
display: flex;
flex-direction: column;
padding: 1em;
gap: 1em;
position: relative;
max-height: 90vh;
.close {
position: absolute;
top: 1em;
right: 1em;
width: 2.5em;
height: 2.5em;
border-radius: 10em;
border: none;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
}
header {
flex: 1;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
form {
div {
&.form-content {
mat-form-field {
width: 100%;
textarea {
height: 30vh;
}
}
}
&.actions {
display: flex;
flex-direction: row-reverse;
justify-content: space-between;
align-items: center;
button {
padding: .8em 1.2em;
border-radius: 10em;
border: none;
background-color: #3f51b5;
color: white;
transition: background-color .2s ease-in-out;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
&:hover {
background-color: #5b6ed8;
}
&.secondary {
color: #3f51b5;
background-color: white;
&:hover {
background-color: #f2f4ff;
cursor: pointer;
}
}
}
}
}
}
}

View File

@@ -0,0 +1,116 @@
import { Component, inject } from "@angular/core";
import { FormBuilder, FormControl, ReactiveFormsModule, Validators } from "@angular/forms";
import { MatDialogRef } from "@angular/material/dialog";
import { MatFormFieldModule } from "@angular/material/form-field";
import { MatIcon } from "@angular/material/icon";
import { MatInputModule } from "@angular/material/input";
import { MatSelectModule } from '@angular/material/select';
export interface ProgramingLanguage {
code: string;
label: string;
}
export const PROGRAMMING_LANGUAGES: ProgramingLanguage[] = [
{
code: 'bash',
label: 'Bash'
},
{
code: 'c',
label: 'C'
},
{
code: 'cpp',
label: 'C++'
},
{
code: 'cs',
label: 'C#'
},
{
code: 'lua',
label: 'Lua'
},
{
code: 'java',
label: 'Java'
},
{
code: 'json5',
label: 'JSON'
},
{
code: 'kt',
label: 'Kotlin'
},
{
code: 'markup',
label: 'html/xml'
},
{
code: 'php',
label: 'PHP'
},
{
code: 'plsql',
label: 'PL/SQL'
},
{
code: 'python',
label: 'Python'
},
{
code: 'powershell',
label: 'PowerShell'
},
{
code: 'rust',
label: 'Rust'
},
{
code: 'sql',
label: 'SQL'
},
{
code: 'ts',
label: 'Typescript'
},
{
code: 'yml',
label: 'YAML'
},
];
@Component({
selector: 'app-code-block-dialog',
standalone: true,
templateUrl: './code-block-dialog.component.html',
styleUrl: './code-block-dialog.component.scss',
imports: [
MatFormFieldModule,
MatIcon,
MatInputModule,
MatSelectModule,
ReactiveFormsModule,
]
})
export class CodeBlockDialog {
private readonly dialogRef = inject(MatDialogRef<CodeBlockDialog>);
private formBuilder = inject(FormBuilder);
programmingLanguages = PROGRAMMING_LANGUAGES;
formGroup = this.formBuilder.group({
programmingLanguage: new FormControl('', Validators.required),
codeBlock: new FormControl('', Validators.required)
});
closeAndValidate(): void {
if (this.formGroup.valid) {
this.dialogRef.close(this.formGroup.value);
}
}
closeDialog(): void {
this.dialogRef.close();
}
}