This repository has been archived by the owner on Oct 14, 2022. It is now read-only.
generated from dalbitresb12/angular-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Job Manager v3 #30
Open
AdrianAlzamoraG
wants to merge
25
commits into
develop
Choose a base branch
from
feat/job-manager-v3
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
d4ad62a
feat(offer): added the job add dialog component
AdrianAlzamoraG 50b7ab9
feat(offer): the method is invoked in jobs to open the dialog to add …
AdrianAlzamoraG 649224e
feat(offer): the method to call the dialog to add offers is implemented
AdrianAlzamoraG d8ffbee
feat(offer): the components related to the dialog are imported
AdrianAlzamoraG 91443f6
feat(offer): generated and implemented the dialog component that adds…
AdrianAlzamoraG 946330c
style(offer): components were imported and the code was reformatted
AdrianAlzamoraG b2e9020
feat(offer): required components imported
AdrianAlzamoraG a50e1ff
feat(offer): injected data to be edited
AdrianAlzamoraG 0f1fd90
feat(offer): the initial values of the offer have been set
AdrianAlzamoraG afc1d0f
feat(offer): service methods implemented
AdrianAlzamoraG f68a6a8
feat(offer): the method is called to modify an offer with the dialog …
AdrianAlzamoraG 7abdf8e
feat(offer): method is implemented to modify an offer with the dialog
AdrianAlzamoraG 0a14408
style(offer): formatting applied to the code
AdrianAlzamoraG 13ad531
fix(offer): open dialog implemented in startedit
AdrianAlzamoraG 412e8ad
style(offer): reformat applied to clean up the code
AdrianAlzamoraG bc13851
fix(offer): subcribe function removed after afterclose
AdrianAlzamoraG fb1c58a
style(offer): problems with style properties have been corrected
AdrianAlzamoraG f7cb5ec
style(offer): reformat applied to clean up the code
AdrianAlzamoraG 081f33b
fix(offer): getDisplayableColumn method recovered
AdrianAlzamoraG 74564af
style(offer): style problems in the interface have been corrected
AdrianAlzamoraG 41c0409
fix(offer): all console logs were removed
AdrianAlzamoraG 21f370a
fix(offer): form to add offer implemented on top of the offer table h…
AdrianAlzamoraG 9fad464
fix(job-add-dialog): imported the imports variable and added the comp…
AdrianAlzamoraG 1748fee
feat(offer): reformat code to clean up
AdrianAlzamoraG 7bda13d
Merge remote-tracking branch 'origin/feat/job-manager-v3' into feat/j…
AdrianAlzamoraG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
64 changes: 64 additions & 0 deletions
64
src/app/jobs/components/job-add-dialog/job-add-dialog.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<h1 mat-dialog-title>Add a new offer</h1> | ||
<div mat-dialog-content> | ||
<form #jobsForm="ngForm" (submit)="this.handleSubmit()" class="flex flex-col"> | ||
<ng-container *ngFor="let field of this.columns"> | ||
<mat-form-field *ngIf="this.useMatFormField(field)" appearance="outline"> | ||
<mat-label>{{ field.label }}</mat-label> | ||
<input | ||
*ngIf="['text', 'number'].includes(field.type)" | ||
matInput | ||
[name]="field.key" | ||
[type]="field.type" | ||
[required]="field.required ?? false" | ||
[attr.min]="field.type === 'number' ? field.min ?? null : null" | ||
[attr.max]="field.type === 'number' ? field.max ?? null : null" | ||
[attr.minLength]=" | ||
field.type === 'text' ? field.minLength ?? null : null | ||
" | ||
[attr.maxLength]=" | ||
field.type === 'text' ? field.maxLength ?? null : null | ||
" | ||
[(ngModel)]="this.currentItem[field.key]" /> | ||
<mat-select | ||
*ngIf="field.type === 'dropdown'" | ||
[name]="field.key" | ||
[required]="field.required ?? false" | ||
[(ngModel)]="this.currentItem[field.key]"> | ||
<mat-option | ||
*ngFor="let option of field.options" | ||
[value]="option.value"> | ||
{{ option.label }} | ||
</mat-option> | ||
</mat-select> | ||
</mat-form-field> | ||
<mat-slide-toggle | ||
class="grid-flow-row" | ||
*ngIf="field.type === 'toggle'" | ||
[name]="field.key" | ||
[required]="field.required ?? false" | ||
[(ngModel)]="this.currentItem[field.key]" | ||
aria-label="Publication status"> | ||
{{ field.label }} | ||
</mat-slide-toggle> | ||
</ng-container> | ||
|
||
<div mat-dialog-actions align="end"> | ||
<button | ||
mat-raised-button | ||
color="warn" | ||
class="box-border h-12 w-28" | ||
(click)="onNoClick()"> | ||
No Thanks | ||
</button> | ||
<button | ||
mat-raised-button | ||
type="submit" | ||
color="primary" | ||
class="h-12 w-28" | ||
aria-label="Button that displays a tooltip when focused or hovered over update or add icon" | ||
matTooltip="Add new job offer"> | ||
{{ "Add" }} | ||
</button> | ||
</div> | ||
</form> | ||
</div> |
24 changes: 24 additions & 0 deletions
24
src/app/jobs/components/job-add-dialog/job-add-dialog.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ComponentFixture, TestBed } from "@angular/core/testing"; | ||
|
||
import { JobAddDialogComponent } from "./job-add-dialog.component"; | ||
|
||
describe("JobAddDialogComponent", () => { | ||
let component: JobAddDialogComponent; | ||
let fixture: ComponentFixture<JobAddDialogComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [JobAddDialogComponent], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(JobAddDialogComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it("should create", () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
122 changes: 122 additions & 0 deletions
122
src/app/jobs/components/job-add-dialog/job-add-dialog.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { Component, Inject, OnInit, ViewChild } from "@angular/core"; | ||
import { ColumnDefinition } from "../../../common/model/column-definition"; | ||
import { JobOffer } from "../../model/job-offer"; | ||
import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog"; | ||
import { NgForm } from "@angular/forms"; | ||
import { MatTableDataSource } from "@angular/material/table"; | ||
import { JobsService } from "../../services/jobs.service"; | ||
|
||
@Component({ | ||
selector: "app-job-add-dialog", | ||
templateUrl: "./job-add-dialog.component.html", | ||
styleUrls: ["./job-add-dialog.component.css"], | ||
}) | ||
export class JobAddDialogComponent implements OnInit { | ||
currentItem: Partial<JobOffer> = {}; | ||
dataSource = new MatTableDataSource<JobOffer>(); | ||
|
||
columns: ColumnDefinition<JobOffer>[] = [ | ||
{ key: "id", label: "ID", hidden: true, type: "number" }, | ||
{ | ||
key: "title", | ||
label: "Title", | ||
type: "text", | ||
required: true, | ||
styles: { | ||
cellClassName: "w-56", | ||
containerClassName: "py-2 pr-4", | ||
}, | ||
}, | ||
{ | ||
key: "description", | ||
label: "Description", | ||
type: "text", | ||
styles: { | ||
cellClassName: "w-96", | ||
containerClassName: "py-2 pr-4", | ||
}, | ||
}, | ||
{ key: "salaryRange", label: "Salary Range", type: "text", required: true }, | ||
{ | ||
key: "published", | ||
label: "Published", | ||
type: "toggle", | ||
trueLabel: "Published", | ||
falseLabel: "Unpublished", | ||
}, | ||
]; | ||
@ViewChild("jobsForm", { static: false }) | ||
jobsForm!: NgForm; | ||
|
||
constructor( | ||
public dialogRef: MatDialogRef<JobAddDialogComponent>, | ||
private jobsService: JobsService, | ||
@Inject(MAT_DIALOG_DATA) public editData: JobOffer | ||
) {} | ||
|
||
ngOnInit(): void { | ||
console.log(this.editData); | ||
if (this.editData) { | ||
this.jobsForm.form.controls["title"].setValue(this.editData.title); | ||
this.jobsForm.form.controls["description"].setValue( | ||
this.editData.description | ||
); | ||
this.jobsForm.form.controls["salaryRange"].setValue( | ||
this.editData.salaryRange | ||
); | ||
this.jobsForm.form.controls["published"].setValue( | ||
this.editData.published | ||
); | ||
} | ||
} | ||
|
||
useMatFormField(field: ColumnDefinition<JobOffer>) { | ||
return !field.hidden && ["text", "number", "dropdown"].includes(field.type); | ||
} | ||
|
||
onNoClick(): void { | ||
this.dialogRef.close(); | ||
} | ||
|
||
get isEditMode() { | ||
return !!this.currentItem.id; | ||
} | ||
|
||
createJob(item: JobOffer) { | ||
this.jobsService.create(item).subscribe(response => { | ||
this.dataSource.data = [...this.dataSource.data, response]; | ||
}); | ||
} | ||
|
||
updateJob(id: number, item: JobOffer) { | ||
this.jobsService.update(id, item).subscribe(response => { | ||
this.dataSource.data = this.dataSource.data.map(current => { | ||
if (current.id === id) return response; | ||
return current; | ||
}); | ||
}); | ||
} | ||
|
||
cancelEdit() { | ||
this.currentItem = {}; | ||
this.jobsForm.resetForm(); | ||
this.dialogRef.close(); | ||
} | ||
|
||
handleSubmit() { | ||
console.log("handling submit..."); | ||
if (!this.jobsForm.form.valid) return; | ||
console.log("passed validation..."); | ||
const job = this.currentItem as JobOffer; | ||
if (this.isEditMode) { | ||
console.log("sending update..."); | ||
this.updateJob(job.id, job); | ||
} else { | ||
console.log("sending create..."); | ||
this.createJob(job); | ||
} | ||
|
||
this.cancelEdit(); | ||
console.log("finished..."); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You forgot about the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
box-border
is already the default in Taliwind's preflight.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AdrianAlzamoraG I think you forgot about this one.