interactive-mining/interactive-mining-angular-.../src/app/saveprofile/saveprofile.component.ts

56 lines
2.1 KiB
TypeScript
Raw Normal View History

2018-02-28 12:41:06 +01:00
import { Component, OnInit } from '@angular/core';
import UIkit from 'uikit';
import {SaveprofileService} from './saveprofile.service';
2018-03-17 14:05:55 +01:00
import {ActivatedRoute, Router} from '@angular/router';
2018-02-28 12:41:06 +01:00
@Component({
selector: 'app-saveprofile',
templateUrl: './saveprofile.component.html',
styleUrls: ['./saveprofile.component.css']
})
export class SaveprofileComponent implements OnInit {
2018-03-23 15:02:35 +01:00
public profileId = '';
2018-02-28 12:41:06 +01:00
public profileName = 'New profile name';
public docnName = '';
public docsNumber = 0;
2018-03-17 14:05:55 +01:00
constructor(private saveprofileService: SaveprofileService, private route: ActivatedRoute, private router: Router) { }
2018-02-28 12:41:06 +01:00
ngOnInit() {
2018-03-23 15:02:35 +01:00
if (localStorage.getItem('profileid') && localStorage.getItem('profileid') !== 'undefined') {
this.profileId = localStorage.getItem('profileid');
2018-02-28 12:41:06 +01:00
}
2018-03-23 15:02:35 +01:00
// if (localStorage.getItem('profilename') && localStorage.getItem('profilename') !== 'undefined') {
// this.profileName = localStorage.getItem('profilename');
// }
2018-02-28 12:41:06 +01:00
if (localStorage.getItem('docname') && localStorage.getItem('docname') !== 'undefined') {
this.docnName = localStorage.getItem('docname');
}
if (localStorage.getItem('docsnumber') && localStorage.getItem('docsnumber') !== 'undefined') {
this.docsNumber = Number.parseInt(localStorage.getItem('docsnumber'));
}
}
2018-03-23 15:02:35 +01:00
saveCurrentProfile(): void {
this.saveprofileService.saveProfile(this.profileName, this.profileId, this.docnName, this.docsNumber)
.subscribe(() => this.router.navigate(['../manage-profiles'], {relativeTo: this.route, queryParamsHandling: 'preserve'}));
}
saveNewProfile(): void {
2018-02-28 12:41:06 +01:00
if (this.profileName === '') {
UIkit.notification({
message: 'You have to provide a name to your new profile',
status: 'danger',
pos: 'top-center',
timeout: 4000
});
return;
} else {
2018-03-23 15:02:35 +01:00
this.saveprofileService.saveProfile(this.profileName, '', this.docnName, this.docsNumber)
2018-03-19 13:44:18 +01:00
.subscribe(() => this.router.navigate(['../manage-profiles'], {relativeTo: this.route, queryParamsHandling: 'preserve'}));
2018-02-28 12:41:06 +01:00
}
}
}