[HIMA-88] finished crete process when menu item is created

This commit is contained in:
Eraldo Hasanaj
2019-02-12 16:52:02 +01:00
parent 5788777bb6
commit 3619855e2d

View File

@@ -4,6 +4,10 @@ import { Observable } from 'rxjs';
import { Process } from 'src/app/core/models/process.model';
import { Store, Select } from '@ngxs/store';
import { ProcessState } from 'src/app/core/store/state/process.state';
import { store } from '@angular/core/src/render3';
import { AddProcess } from 'src/app/core/store/actions/process.actions';
import { getRandomPic } from 'src/app/core/utils/process.util';
import { Breadcrumb } from 'src/app/core/models/breadcrumb.model';
@Component({
selector: 'app-menu',
@@ -20,10 +24,46 @@ export class MenuComponent implements OnInit {
activeMenu = '';
routeToMenu(menuPath: string, menuTag: string): void {
if (this.processes.length < 1) {
this.createProcess(menuPath);
}
this.activeMenu = menuTag;
this.router.navigate([menuPath]);
}
createProcess(menuPath: string) {
const newProcess = <Process>{
id: 1,
name: '# 1',
selected: true,
icon: getRandomPic(),
breadcrumbs: <Breadcrumb[]>[
{
name: this.nameFromPath(menuPath),
path: menuPath
}
],
currentRoute: this.routeFromPath(menuPath)
};
this.store.dispatch(new AddProcess(newProcess));
}
routeFromPath(path: string) {
return path.substring(1, path.length - 1);
}
nameFromPath(path: string) {
switch (path) {
case '/article-search':
return 'Artikelsuche';
case '/customer-search':
return 'Kundensuche';
default:
return 'Artikelsuche';
}
}
ngOnInit() {
this.processes$.subscribe(
(data: Process[]) => this.processes = data