2019-07-16 08:38:11 +03:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { of as observableOf, Observable } from 'rxjs';
|
|
|
|
|
import { map } from 'rxjs/operators';
|
|
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
|
|
|
|
|
|
|
export interface Product {
|
|
|
|
|
id: string;
|
|
|
|
|
imageUrl: string;
|
|
|
|
|
storeUrl: string;
|
|
|
|
|
tags: string[];
|
|
|
|
|
title: string;
|
|
|
|
|
description: string;
|
|
|
|
|
variants: ProductVariant[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ProductVariant {
|
|
|
|
|
available: boolean;
|
|
|
|
|
compare_at_price: string;
|
|
|
|
|
price: string;
|
|
|
|
|
title: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const BUNDLE_LICENSE = {
|
2020-02-07 10:28:24 +03:00
|
|
|
personal: 'personal',
|
|
|
|
|
developer: 'developer',
|
2019-07-16 08:38:11 +03:00
|
|
|
};
|
|
|
|
|
|
2020-05-15 11:01:19 +03:00
|
|
|
export const STORE_PRODUCTS_URL = {
|
|
|
|
|
base: 'https://store.akveo.com/collections/frontpage/products.json',
|
|
|
|
|
material: 'https://store.akveo.com/collections/material-bundles/products.json',
|
|
|
|
|
};
|
|
|
|
|
|
2019-07-16 08:38:11 +03:00
|
|
|
export class Feature {
|
|
|
|
|
text: string;
|
|
|
|
|
availableInPersonalLicence: boolean;
|
|
|
|
|
availableInCommercialLicence: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class BundlesService {
|
|
|
|
|
|
2020-04-14 19:41:53 +03:00
|
|
|
private readonly STORE: string = 'https://store.akveo.com/products';
|
2019-07-16 08:38:11 +03:00
|
|
|
|
|
|
|
|
private features: Feature[] = [
|
|
|
|
|
{
|
|
|
|
|
text: 'ngx-admin template with 100+ UI components integrated with Backend Services',
|
|
|
|
|
availableInPersonalLicence: true,
|
|
|
|
|
availableInCommercialLicence: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text: 'Backend Services and Repository layers with data access',
|
|
|
|
|
availableInPersonalLicence: true,
|
|
|
|
|
availableInCommercialLicence: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text: 'JWT Authentication setup for UI and Backend',
|
|
|
|
|
availableInPersonalLicence: true,
|
|
|
|
|
availableInCommercialLicence: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text: 'Running instructions and code documentation',
|
|
|
|
|
availableInPersonalLicence: true,
|
|
|
|
|
availableInCommercialLicence: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text: 'Commercial Usage',
|
|
|
|
|
availableInPersonalLicence: true,
|
|
|
|
|
availableInCommercialLicence: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text: 'Create multiple end products using bundle',
|
|
|
|
|
availableInPersonalLicence: false,
|
|
|
|
|
availableInCommercialLicence: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text: 'Bug fixes and questions according to license terms',
|
|
|
|
|
availableInPersonalLicence: false,
|
|
|
|
|
availableInCommercialLicence: true,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
constructor(private http: HttpClient) {}
|
|
|
|
|
|
|
|
|
|
getFeatures(): Observable<Feature[]> {
|
|
|
|
|
return observableOf(this.features);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 11:01:19 +03:00
|
|
|
getProducts(url: string): Observable<Product[]> {
|
|
|
|
|
return this.http.get(url)
|
2019-07-16 08:38:11 +03:00
|
|
|
.pipe(map((result: any) => {
|
|
|
|
|
return result.products.map((item: any) => {
|
|
|
|
|
return {
|
|
|
|
|
id: item.id,
|
|
|
|
|
imageUrl: this.getDefaultImage(item.images),
|
|
|
|
|
storeUrl: `${this.STORE}/${item.handle}`,
|
|
|
|
|
tags: item.tags,
|
|
|
|
|
title: item.title,
|
2019-11-14 17:25:14 +03:00
|
|
|
description: (item.body_html as string).trim().replace(/<(?:.|\n)*?>/gm, ' ').replace(/ +/gm, ' '),
|
2019-07-16 08:38:11 +03:00
|
|
|
variants: item.variants.map(variant => {
|
|
|
|
|
return {
|
|
|
|
|
available: variant.available,
|
|
|
|
|
compare_at_price: variant.compare_at_price,
|
|
|
|
|
price: variant.price,
|
|
|
|
|
title: variant.title,
|
|
|
|
|
};
|
|
|
|
|
}),
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getDefaultImage(images: any[]): any {
|
|
|
|
|
const defaultImage = images.reduce((value, current) => {
|
|
|
|
|
if (!value) {
|
|
|
|
|
value = current;
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
});
|
|
|
|
|
return defaultImage ? this.trimImageUrl(defaultImage.src) : undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trimImageUrl(url: string): string {
|
|
|
|
|
return url.substring(0, url.indexOf('?'));
|
|
|
|
|
}
|
|
|
|
|
}
|