added service categories
This commit is contained in:
@@ -1,44 +1,35 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {Sort} from '@angular/material/sort';
|
||||
import {ServiceService} from '../../services/service.service';
|
||||
import {I18nService} from '../../services/i18n.service';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Sort } from '@angular/material/sort';
|
||||
import { ServiceService } from '../../services/service.service';
|
||||
import { I18nService } from '../../services/i18n.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-services',
|
||||
templateUrl: './services.component.html',
|
||||
styleUrls: ['./services.component.scss']
|
||||
styleUrls: [ './services.component.scss' ]
|
||||
})
|
||||
export class ServicesComponent implements OnInit {
|
||||
|
||||
services;
|
||||
serviceColumns = ["icon", "name", "text"];
|
||||
baseServices: Array<any>;
|
||||
serviceCategory: any = {};
|
||||
|
||||
constructor(private serviceService: ServiceService, private i18n: I18nService) {}
|
||||
constructor(private serviceService: ServiceService, private i18n: I18nService) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.serviceService.services().subscribe((data: any) => {
|
||||
this.services = data;
|
||||
this.sortData({"active": "name", "direction": "asc"});
|
||||
this.serviceService.services().subscribe((data: Array<any>) => {
|
||||
let that = this;
|
||||
that.baseServices = [];
|
||||
data.forEach(function (service) {
|
||||
if (!service.category || service.category == "") {
|
||||
that.baseServices.push(service);
|
||||
} else {
|
||||
if (!that.serviceCategory[ service.category ]) {
|
||||
that.serviceCategory[ service.category ] = [];
|
||||
}
|
||||
that.serviceCategory[ service.category ].push(service);
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
sortData(sort: Sort) {
|
||||
const data = this.services.slice();
|
||||
if(!sort.active || sort.direction === '') {
|
||||
this.services = data;
|
||||
return;
|
||||
}
|
||||
|
||||
this.services = data.sort((a, b) => {
|
||||
const isAsc = sort.direction === 'asc';
|
||||
switch(sort.active) {
|
||||
case 'name': return this.compare(this.i18n.get('services.' + a.name + '.title', []), this.i18n.get('services.' + b.name + '.title', []), isAsc);
|
||||
default: return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
compare(a: number | string | String, b: number | string | String, isAsc: boolean) {
|
||||
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user