Skip to content
Snippets Groups Projects
Commit f9efd79c authored by Amalie Urdshals's avatar Amalie Urdshals
Browse files

(#20)

parent 202f9ec2
Branches Badges
No related tags found
1 merge request!33Issue: Admin category (#20)
<p>admin-category works!</p>
<div class="categoryForm">
<h3>Legg til kategori</h3>
<app-text-input [(inputModel)]="name" label="Kategorinavn" (blur)="checkForm()"></app-text-input>
<p>{{statusMessage}}</p>
<app-button (click)="addCategory" text="Legg til"></app-button>
</div>
\ No newline at end of file
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from 'src/app/authentication/auth.service';
import { PostService } from 'src/app/posts/post.service';
@Component({
selector: 'app-admin-category',
......@@ -6,10 +9,49 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./admin-category.component.scss']
})
export class AdminCategoryComponent implements OnInit {
user: new User();
name: string = "";
statusMessage: string = "";
constructor() { }
constructor(private postService: PostService, private authService: AuthService) { }
ngOnInit(): void {
this.user = this.authService.getCurrentUser();
if (this.user.get)
}
/**
* Validates the form
*/
checkForm(): boolean {
if (this.name == "") {
this.setStatusMessage("Brukernavn kan ikke være tom");
return false;
}
this.setStatusMessage("");
return true;
}
/**
* Publishes and registers the user if given arguments are valid
*/
registerCategory() {
if (this.checkForm()) {
// Adds user to database and redirects to the homepage afterwards
this.postService.addCategory(name).then(status => {
console.log("Category was added: " + JSON.stringify(status));
loadCategories();
}).catch(error => {
console.log("Error adding category: " + error);
});
}
}
/**
* Sets the status message for user feedback on form submit
*/
setStatusMessage(message: string) {
this.statusMessage = message;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment