-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7e0989
commit 15c547a
Showing
15 changed files
with
263 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
<span class="createdAt">{{note.createdAt | timeago}}</span> | ||
|
||
<div #card class="note-card"> | ||
<div class="content"> | ||
<h1 class="title">{{ title }}</h1> | ||
<h1 class="title" (click)="goToNote('update', note)">{{ note.title }}</h1> | ||
|
||
<div #bodyText class="body"> | ||
<p>{{ description }}</p> | ||
<p>{{ note.description }}</p> | ||
|
||
<div #truncator class="fade-out-truncation"></div> | ||
</div> | ||
</div> | ||
|
||
<div class="delete-btn"> | ||
<div class="delete-btn" (click)="onDeleteNote()"> | ||
<i class="fas fa-times"></i> | ||
</div> | ||
</div> |
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
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 |
---|---|---|
|
@@ -7,6 +7,10 @@ | |
padding-top: 50px; | ||
|
||
.actions { | ||
.btn-save { | ||
width: 65px; | ||
} | ||
|
||
button { | ||
border-radius: 5px; | ||
} | ||
|
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 |
---|---|---|
@@ -1,33 +1,135 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; | ||
import { Note } from '../../_shared/models/note.model'; | ||
import { Router } from '@angular/router'; | ||
import { NotesService } from '../../_shared/services/notes.service'; | ||
|
||
@Component({ | ||
selector: 'app-note-details', | ||
templateUrl: './note-details.component.html', | ||
styleUrls: ['./note-details.component.scss'] | ||
}) | ||
export class NoteDetailsComponent implements OnInit { | ||
action = ''; | ||
note: Note; | ||
firstTime = true; | ||
loading = false; | ||
noteForm: FormGroup; | ||
|
||
constructor(private formBuilder: FormBuilder) { } | ||
constructor( | ||
private router: Router, | ||
private formBuilder: FormBuilder, | ||
private notesService: NotesService, | ||
) { } | ||
|
||
ngOnInit(): void { | ||
this.noteForm = this.formBuilder.group({ | ||
title: ['', Validators.required], | ||
description: [''] | ||
}); | ||
console.log(this.f.title); | ||
if (window.history.state.action !== undefined && window.history.state.note !== undefined) { | ||
this.action = window.history.state.action; | ||
this.note = window.history.state.note; | ||
|
||
this.noteForm = this.formBuilder.group({ | ||
title: [this.note.title, Validators.required], | ||
description: [this.note.description] | ||
}); | ||
} else { | ||
this.action = 'add'; | ||
this.note = { | ||
id: '', | ||
title: '', | ||
description: '' | ||
}; | ||
|
||
this.noteForm = this.formBuilder.group({ | ||
title: ['', Validators.required], | ||
description: [''] | ||
}); | ||
} | ||
} | ||
|
||
get f(): any { | ||
return this.noteForm.controls; | ||
} | ||
|
||
onSubmit(): void { | ||
this.firstTime = false; | ||
console.log(this.noteForm, this.f.title); | ||
if (this.firstTime) { | ||
this.firstTime = false; // to hide the error message when the page is loaded | ||
} | ||
|
||
this.loading = true; | ||
if (this.noteForm.valid) { | ||
switch (this.action) { | ||
case 'add': | ||
this.addNote(); | ||
break; | ||
case 'update': | ||
this.updateNote(); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
onClickCancel(): void { | ||
this.router.navigate( | ||
['/'], { | ||
state: { | ||
action: this.action, | ||
result: 'canceled' | ||
} | ||
}); | ||
} | ||
|
||
addNote(): void { | ||
this.notesService.addNote({ | ||
title: this.noteForm.value.title, | ||
description: this.noteForm.value.description, | ||
createdAt: new Date().toString() | ||
}) | ||
.then(r => { | ||
this.loading = false; | ||
this.router.navigate( | ||
['/'], { | ||
state: { | ||
action: this.action, | ||
result: 'success' | ||
} | ||
}); | ||
}) | ||
.catch(err => { | ||
this.router.navigate( | ||
['/'], { | ||
state: { | ||
action: this.action, | ||
result: 'error' | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
updateNote(): void { | ||
this.notesService.updateNote({ | ||
id: this.note.id, | ||
title: this.noteForm.value.title, | ||
description: this.noteForm.value.description, | ||
}) | ||
.then(r => { | ||
this.loading = false; | ||
this.router.navigate( | ||
['/'], { | ||
state: { | ||
action: this.action, | ||
result: 'success' | ||
} | ||
}); | ||
}) | ||
.catch(err => { | ||
console.log(err.message); | ||
this.router.navigate( | ||
['/'], { | ||
state: { | ||
action: this.action, | ||
result: 'error' | ||
} | ||
}); | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.